move digest to a separate plugin

This commit is contained in:
Andrew Dolgov 2012-12-24 10:16:01 +04:00
parent 68d539ceef
commit ac22075182
9 changed files with 120 additions and 88 deletions

View File

@ -594,60 +594,6 @@ class RPC extends Handler_Protected {
} }
} }
function digestgetcontents() {
$article_id = db_escape_string($_REQUEST['article_id']);
$result = db_query($this->link, "SELECT content,title,link,marked,published
FROM ttrss_entries, ttrss_user_entries
WHERE id = '$article_id' AND ref_id = id AND owner_uid = ".$_SESSION['uid']);
$content = sanitize($this->link, db_fetch_result($result, 0, "content"));
$title = strip_tags(db_fetch_result($result, 0, "title"));
$article_url = htmlspecialchars(db_fetch_result($result, 0, "link"));
$marked = sql_bool_to_bool(db_fetch_result($result, 0, "marked"));
$published = sql_bool_to_bool(db_fetch_result($result, 0, "published"));
print json_encode(array("article" =>
array("id" => $article_id, "url" => $article_url,
"tags" => get_article_tags($this->link, $article_id),
"marked" => $marked, "published" => $published,
"title" => $title, "content" => $content)));
}
function digestupdate() {
$feed_id = db_escape_string($_REQUEST['feed_id']);
$offset = db_escape_string($_REQUEST['offset']);
$seq = db_escape_string($_REQUEST['seq']);
if (!$feed_id) $feed_id = -4;
if (!$offset) $offset = 0;
$reply = array();
$reply['seq'] = $seq;
$headlines = api_get_headlines($this->link, $feed_id, 30, $offset,
'', ($feed_id == -4), true, false, "unread", "updated DESC", 0, 0);
$reply['headlines'] = array();
$reply['headlines']['title'] = getFeedTitle($this->link, $feed_id);
$reply['headlines']['content'] = $headlines;
print json_encode($reply);
}
function digestinit() {
$tmp_feeds = api_get_feeds($this->link, -4, true, false, 0);
$feeds = array();
foreach ($tmp_feeds as $f) {
if ($f['id'] > 0 || $f['id'] == -4) array_push($feeds, $f);
}
print json_encode(array("feeds" => $feeds));
}
function catchupFeed() { function catchupFeed() {
$feed_id = db_escape_string($_REQUEST['feed_id']); $feed_id = db_escape_string($_REQUEST['feed_id']);
$is_cat = db_escape_string($_REQUEST['is_cat']) == "true"; $is_cat = db_escape_string($_REQUEST['is_cat']) == "true";

View File

@ -18,9 +18,15 @@
$mobile = new Mobile_Detect(); $mobile = new Mobile_Detect();
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (!init_connection($link)) return;
global $pluginhost;
if (!$_REQUEST['mobile']) { if (!$_REQUEST['mobile']) {
if ($mobile->isTablet()) { if ($mobile->isTablet() && $pluginhost->get_plugin("digest")) {
header('Location: digest.php'); header('Location: backend.php?op=digest');
exit; exit;
} else if ($mobile->isMobile()) { } else if ($mobile->isMobile()) {
header('Location: mobile/index.php'); header('Location: mobile/index.php');
@ -28,9 +34,6 @@
} }
} }
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (!init_connection($link)) return;
login_sequence($link); login_sequence($link);
@ -208,7 +211,9 @@
<div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcCatchupAll')"><?php echo __('Mark as read') ?></div> <div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcCatchupAll')"><?php echo __('Mark as read') ?></div>
<div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcShowOnlyUnread')"><?php echo __('(Un)hide read feeds') ?></div> <div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcShowOnlyUnread')"><?php echo __('(Un)hide read feeds') ?></div>
<div dojoType="dijit.MenuItem" disabled="1"><?php echo __('Other actions:') ?></div> <div dojoType="dijit.MenuItem" disabled="1"><?php echo __('Other actions:') ?></div>
<?php if ($pluginhost->get_plugin("digest")) { ?>
<div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcDigest')"><?php echo __('Switch to digest...') ?></div> <div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcDigest')"><?php echo __('Switch to digest...') ?></div>
<?php } ?>
<div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcTagCloud')"><?php echo __('Show tag cloud...') ?></div> <div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcTagCloud')"><?php echo __('Show tag cloud...') ?></div>
<div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcTagSelect')"><?php echo __('Select by tags...') ?></div> <div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcTagSelect')"><?php echo __('Select by tags...') ?></div>
<div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcAddLabel')"><?php echo __('Create label...') ?></div> <div dojoType="dijit.MenuItem" onclick="quickMenuGo('qmcAddLabel')"><?php echo __('Create label...') ?></div>

View File

@ -391,7 +391,7 @@ function quickMenuGo(opid) {
} }
if (opid == "qmcDigest") { if (opid == "qmcDigest") {
window.location.href = "digest.php"; window.location.href = "backend.php?op=digest";
return; return;
} }

View File

@ -169,7 +169,7 @@ function update(callback) {
window.clearTimeout(_update_timeout); window.clearTimeout(_update_timeout);
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: "?op=rpc&method=digestinit", parameters: "?op=digest&method=digestinit",
onComplete: function(transport) { onComplete: function(transport) {
fatal_error_check(transport); fatal_error_check(transport);
parse_feeds(transport); parse_feeds(transport);
@ -220,7 +220,7 @@ function view(article_id) {
}, 500); }, 500);
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: "?op=rpc&method=digestgetcontents&article_id=" + parameters: "?op=digest&method=digestgetcontents&article_id=" +
article_id, article_id,
onComplete: function(transport) { onComplete: function(transport) {
fatal_error_check(transport); fatal_error_check(transport);
@ -312,7 +312,7 @@ function viewfeed(feed_id, offset, replace, no_effects, no_indicator, callback)
if (!offset) $("headlines").scrollTop = 0; if (!offset) $("headlines").scrollTop = 0;
var query = "backend.php?op=rpc&method=digestupdate&feed_id=" + var query = "backend.php?op=digest&method=digestupdate&feed_id=" +
param_escape(feed_id) + "&offset=" + offset + param_escape(feed_id) + "&offset=" + offset +
"&seq=" + _update_seq; "&seq=" + _update_seq;
@ -647,7 +647,7 @@ function parse_headlines(transport, replace, no_effects) {
function init_second_stage() { function init_second_stage() {
try { try {
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: "backend.php?op=rpc&method=digestinit", parameters: "backend.php?op=digest&method=digestinit",
onComplete: function(transport) { onComplete: function(transport) {
parse_feeds(transport); parse_feeds(transport);
Element.hide("overlay"); Element.hide("overlay");

100
plugins/digest/digest.php Normal file
View File

@ -0,0 +1,100 @@
<?
class Digest extends Plugin implements IHandler {
private $link;
private $host;
function __construct($host) {
$this->link = $host->get_link();
$this->host = $host;
$host->add_handler("digest", "*", $this);
//$host->add_handler("rpc", "digestinit", $this);
//$host->add_handler("rpc", "digestupdate", $this);
//$host->add_handler("rpc", "digestgetcontents", $this);
}
function index() {
header("Content-type: text/html; charset=utf-8");
login_sequence($this->link);
global $link;
$link = $this->link;
require_once dirname(__FILE__) . "/digest_body.php";
}
/* function get_js() {
return file_get_contents(dirname(__FILE__) . "/digest.js");
} */
function csrf_ignore($method) {
return in_array($method, array("index"));
}
function before($method) {
return true;
}
function after() {
}
function digestgetcontents() {
$article_id = db_escape_string($_REQUEST['article_id']);
$result = db_query($this->link, "SELECT content,title,link,marked,published
FROM ttrss_entries, ttrss_user_entries
WHERE id = '$article_id' AND ref_id = id AND owner_uid = ".$_SESSION['uid']);
$content = sanitize($this->link, db_fetch_result($result, 0, "content"));
$title = strip_tags(db_fetch_result($result, 0, "title"));
$article_url = htmlspecialchars(db_fetch_result($result, 0, "link"));
$marked = sql_bool_to_bool(db_fetch_result($result, 0, "marked"));
$published = sql_bool_to_bool(db_fetch_result($result, 0, "published"));
print json_encode(array("article" =>
array("id" => $article_id, "url" => $article_url,
"tags" => get_article_tags($this->link, $article_id),
"marked" => $marked, "published" => $published,
"title" => $title, "content" => $content)));
}
function digestupdate() {
$feed_id = db_escape_string($_REQUEST['feed_id']);
$offset = db_escape_string($_REQUEST['offset']);
$seq = db_escape_string($_REQUEST['seq']);
if (!$feed_id) $feed_id = -4;
if (!$offset) $offset = 0;
$reply = array();
$reply['seq'] = $seq;
$headlines = api_get_headlines($this->link, $feed_id, 30, $offset,
'', ($feed_id == -4), true, false, "unread", "updated DESC", 0, 0);
$reply['headlines'] = array();
$reply['headlines']['title'] = getFeedTitle($this->link, $feed_id);
$reply['headlines']['content'] = $headlines;
print json_encode($reply);
}
function digestinit() {
$tmp_feeds = api_get_feeds($this->link, -4, true, false, 0);
$feeds = array();
foreach ($tmp_feeds as $f) {
if ($f['id'] > 0 || $f['id'] == -4) array_push($feeds, $f);
}
print json_encode(array("feeds" => $feeds));
}
}
?>

View File

@ -0,0 +1 @@
Digest mode for tt-rss (tablet friendly UI)

View File

@ -1,25 +1,5 @@
<?php <?php global $link; ?>
set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR .
get_include_path());
require_once "functions.php";
require_once "sessions.php";
require_once "sanity_check.php";
require_once "version.php";
require_once "config.php";
require_once "db-prefs.php";
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
login_sequence($link);
$dt_add = time();
no_cache_incantation();
header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@ -28,7 +8,7 @@
<title>Tiny Tiny RSS</title> <title>Tiny Tiny RSS</title>
<link rel="stylesheet" type="text/css" href="lib/dijit/themes/claro/claro.css"/> <link rel="stylesheet" type="text/css" href="lib/dijit/themes/claro/claro.css"/>
<link rel="stylesheet" type="text/css" href="digest.css?<?php echo $dt_add ?>"/> <link rel="stylesheet" type="text/css" href="plugins/digest/digest.css?<?php echo $dt_add ?>"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
@ -43,7 +23,7 @@
<script type="text/javascript" charset="utf-8" src="localized_js.php?<?php echo $dt_add ?>"></script> <script type="text/javascript" charset="utf-8" src="localized_js.php?<?php echo $dt_add ?>"></script>
<script type="text/javascript" charset="utf-8" src="errors.php?mode=js"></script> <script type="text/javascript" charset="utf-8" src="errors.php?mode=js"></script>
<script type="text/javascript" charset="utf-8" src="js/functions.js?<?php echo $dt_add ?>"></script> <script type="text/javascript" charset="utf-8" src="js/functions.js?<?php echo $dt_add ?>"></script>
<script type="text/javascript" src="js/digest.js"></script> <script type="text/javascript" src="plugins/digest/digest.js"></script>
<script type="text/javascript"> <script type="text/javascript">
Event.observe(window, 'load', function() { Event.observe(window, 'load', function() {

View File

Before

Width:  |  Height:  |  Size: 958 B

After

Width:  |  Height:  |  Size: 958 B