Exemple #1
0
 function getInfo()
 {
     //retrieve Data from the DB
     $id = db_escape_string($_REQUEST['id']);
     $result = db_query("SELECT title, link\n\t\t\t\tFROM ttrss_entries, ttrss_user_entries\n\t\t\t\tWHERE id = '{$id}' AND ref_id = id AND owner_uid = " . $_SESSION['uid']);
     if (db_num_rows($result) != 0) {
         $title = truncate_string(strip_tags(db_fetch_result($result, 0, 'title')), 100, '...');
         $article_link = db_fetch_result($result, 0, 'link');
     }
     $consumer_key = $this->host->get($this, "pocket_consumer_key");
     $pocket_access_token = $this->host->get($this, "pocket_access_token");
     //Call Pocket API
     if (function_exists('curl_init')) {
         $postfields = array('consumer_key' => $consumer_key, 'access_token' => $pocket_access_token, 'url' => $article_link, 'title' => $title);
         $cURL = curl_init();
         curl_setopt($cURL, CURLOPT_URL, 'https://getpocket.com/v3/add');
         curl_setopt($cURL, CURLOPT_HEADER, 1);
         curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded;charset=UTF-8'));
         curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($cURL, CURLOPT_TIMEOUT, 5);
         curl_setopt($cURL, CURLOPT_POST, 4);
         curl_setopt($cURL, CURLOPT_POSTFIELDS, http_build_query($postfields));
         $apicall = curl_exec($cURL);
         curl_close($cURL);
         //Store error code in $status
         $status = preg_match('/^X-Error: .*$/m', $apicall, $matches) ? $matches[0] : 1;
     } else {
         $status = 'For the plugin to work you need to <strong>enable PHP extension CURL</strong>!';
     }
     //Return information on article and status
     print json_encode(array("title" => $title, "link" => $article_link, "id" => $id, "status" => $status));
 }
 function shareArticle()
 {
     $param = db_escape_string($_REQUEST['param']);
     $result = db_query($this->link, "SELECT uuid, ref_id FROM ttrss_user_entries WHERE int_id = '{$param}'\n\t\t\tAND owner_uid = " . $_SESSION['uid']);
     if (db_num_rows($result) == 0) {
         print "Article not found.";
     } else {
         $uuid = db_fetch_result($result, 0, "uuid");
         $ref_id = db_fetch_result($result, 0, "ref_id");
         if (!$uuid) {
             $uuid = db_escape_string(sha1(uniqid(rand(), true)));
             db_query($this->link, "UPDATE ttrss_user_entries SET uuid = '{$uuid}' WHERE int_id = '{$param}'\n\t\t\t\t\tAND owner_uid = " . $_SESSION['uid']);
         }
         print __("You can share this article by the following unique URL:");
         $url_path = get_self_url_prefix();
         $url_path .= "/public.php?op=share&key={$uuid}";
         print "<div class=\"tagCloudContainer\">";
         print "<a id='pub_opml_url' href='{$url_path}' target='_blank'>{$url_path}</a>";
         print "</div>";
         /* if (!label_find_id($this->link, __('Shared'), $_SESSION["uid"]))
         				label_create($this->link, __('Shared'), $_SESSION["uid"]);
         
         			label_add_article($this->link, $ref_id, __('Shared'), $_SESSION['uid']); */
     }
     print "<div align='center'>";
     print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').hide()\">" . __('Close this window') . "</button>";
     print "</div>";
 }
 function find_user_by_login($login)
 {
     $login = db_escape_string($login);
     $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE\n\t\t\tlogin = '******'");
     if (db_num_rows($result) > 0) {
         return db_fetch_result($result, 0, "id");
     } else {
         return false;
     }
 }
 function getInfo()
 {
     $id = db_escape_string($_REQUEST['id']);
     $result = db_query($this->link, "SELECT title, link\n\t\t\t\tFROM ttrss_entries, ttrss_user_entries\n\t\t\t\tWHERE id = '{$id}' AND ref_id = id AND owner_uid = " . $_SESSION['uid']);
     if (db_num_rows($result) != 0) {
         $title = truncate_string(strip_tags(db_fetch_result($result, 0, 'title')), 100, '...');
         $article_link = db_fetch_result($result, 0, 'link');
     }
     print json_encode(array("title" => $title, "link" => $article_link, "id" => $id));
 }
Exemple #5
0
 function getUrl()
 {
     $id = db_escape_string($_REQUEST['id']);
     $result = db_query("SELECT link\n\t\t\t\tFROM ttrss_entries, ttrss_user_entries\n\t\t\t\tWHERE id = '{$id}' AND ref_id = id AND owner_uid = " . $_SESSION['uid']);
     $url = "";
     if (db_num_rows($result) != 0) {
         $url = db_fetch_result($result, 0, "link");
     }
     print json_encode(array("url" => $url, "id" => $id));
 }
Exemple #6
0
 function getShaarli()
 {
     $id = db_escape_string($_REQUEST['id']);
     $result = $this->dbh->query("SELECT title, link\n                      FROM ttrss_entries, ttrss_user_entries\n                      WHERE id = '{$id}' AND ref_id = id AND owner_uid = " . $_SESSION['uid']);
     if (db_num_rows($result) != 0) {
         $title = truncate_string(strip_tags(db_fetch_result($result, 0, 'title')), 100, '...');
         $article_link = db_fetch_result($result, 0, 'link');
     }
     $shaarli_url = $this->host->get($this, "shaarli");
     print json_encode(array("title" => $title, "link" => $article_link, "id" => $id, "shaarli_url" => $shaarli_url));
 }
 function digestgetcontents()
 {
     $article_id = db_escape_string($_REQUEST['article_id']);
     $result = db_query($this->link, "SELECT content,title,link,marked,published\n\t\t\tFROM ttrss_entries, ttrss_user_entries\n\t\t\tWHERE 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)));
 }
Exemple #8
0
 function get_login_by_ssl_certificate()
 {
     $cert_serial = db_escape_string(get_ssl_certificate_id());
     if ($cert_serial) {
         $result = db_query("SELECT login FROM ttrss_user_prefs, ttrss_users\n\t\t\t\tWHERE pref_name = 'SSL_CERT_SERIAL' AND value = '{$cert_serial}' AND\n\t\t\t\towner_uid = ttrss_users.id");
         if (db_num_rows($result) != 0) {
             return db_escape_string(db_fetch_result($result, 0, "login"));
         }
     }
     return "";
 }
Exemple #9
0
 function redirect()
 {
     $id = db_escape_string($_REQUEST['id']);
     $result = db_query($this->link, "SELECT link FROM ttrss_entries, ttrss_user_entries\r\n\t\t\t\t\t\tWHERE id = '{$id}' AND id = ref_id AND owner_uid = '" . $_SESSION['uid'] . "'\r\n\t\t\t\t\t\tLIMIT 1");
     if (db_num_rows($result) == 1) {
         $article_url = db_fetch_result($result, 0, 'link');
         $article_url = str_replace("\n", "", $article_url);
         header("Location: {$article_url}");
         return;
     } else {
         print_error(__("Article not found."));
     }
 }
function import_article($link, $data)
{
    print "<p>Article: <b>" . $data["title"] . "</b> (" . $data["feed_title"] . ")<br>";
    $owner_uid = $_SESSION["uid"];
    db_query($link, "BEGIN");
    $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE feed_url = '" . db_escape_string($data["feed_url"]) . "' AND owner_uid = '{$owner_uid}'");
    if (db_num_rows($result) == 0) {
        return false;
    }
    $feed_id = db_fetch_result($result, 0, "id");
    $result = db_query($link, "SELECT id FROM ttrss_entries WHERE\n\t\t\tguid = '" . $data["guid"] . "'");
    if (db_num_rows($result) == 0) {
        print "Adding base entry...<br>";
        $entry_title = db_escape_string($data["title"]);
        $entry_guid = db_escape_string($data["guid"]);
        $entry_link = db_escape_string($data["link"]);
        $updated = db_escape_string($data["updated"]);
        $date_entered = db_escape_string($data["date_entered"]);
        $entry_content = db_escape_string($data["content"]);
        $content_hash = "SHA1:" . sha1(strip_tags($entry_content));
        $entry_comments = db_escape_string($data["comments"]);
        $result = db_query($link, "INSERT INTO ttrss_entries \n\t\t\t\t\t(title,\n\t\t\t\t\tguid,\n\t\t\t\t\tlink,\n\t\t\t\t\tupdated,\n\t\t\t\t\tcontent,\n\t\t\t\t\tcontent_hash,\n\t\t\t\t\tno_orig_date,\n\t\t\t\t\tdate_entered,\n\t\t\t\t\tcomments)\n\t\t\t\tVALUES\n\t\t\t\t\t('{$entry_title}', \n\t\t\t\t\t'{$entry_guid}', \n\t\t\t\t\t'{$entry_link}',\n\t\t\t\t\t'{$updated}', \n\t\t\t\t\t'{$entry_content}', \n\t\t\t\t\t'{$content_hash}',\n\t\t\t\t\tfalse, \n\t\t\t\t\t'{$date_entered}', \n\t\t\t\t\t'{$entry_comments}')");
    }
    $result = db_query($link, "SELECT id FROM ttrss_entries WHERE\n\t\t\tguid = '" . $data["guid"] . "'");
    if (db_num_rows($result) == 0) {
        return false;
    }
    $entry_id = db_fetch_result($result, 0, "id");
    print "Found base ID: {$entry_id}<br>";
    $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE\n\t\t\tref_id = '{$entry_id}' AND owner_uid = '{$owner_uid}'");
    if (db_num_rows($result) == 0) {
        print "User table entry not found, creating...<br>";
        $unread = sql_bool_to_string(db_escape_string($data["unread"]));
        $marked = sql_bool_to_string(db_escape_string($data["marked"]));
        $last_read = db_escape_string($data["last_read"]);
        if (!$last_read) {
            $last_read_qpart = 'NULL';
        } else {
            $last_read_qpart = "'{$last_read}'";
        }
        $result = db_query($link, "INSERT INTO ttrss_user_entries \n\t\t\t\t\t(ref_id, owner_uid, feed_id, unread, marked, last_read) \n\t\t\t\tVALUES ('{$entry_id}', '{$owner_uid}', '{$feed_id}', {$unread}, {$marked},\n\t\t\t\t\t{$last_read_qpart})");
    } else {
        print "User table entry already exists, nothing to do.<br>";
    }
    db_query($link, "COMMIT");
}
 function edit()
 {
     $param = db_escape_string($_REQUEST['param']);
     $result = db_query("SELECT note FROM ttrss_user_entries WHERE\n\t\t\tref_id = '{$param}' AND owner_uid = " . $_SESSION['uid']);
     $note = db_fetch_result($result, 0, "note");
     print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"{$param}\">";
     print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">";
     print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setNote\">";
     print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"note\">";
     print "<table width='100%'><tr><td>";
     print "<textarea dojoType=\"dijit.form.SimpleTextarea\"\n\t\t\tstyle='font-size : 12px; width : 100%; height: 100px;'\n\t\t\tplaceHolder='body#ttrssMain { font-size : 14px; };'\n\t\t\tname='note'>{$note}</textarea>";
     print "</td></tr></table>";
     print "<div class='dlgButtons'>";
     print "<button dojoType=\"dijit.form.Button\"\n\t\t\tonclick=\"dijit.byId('editNoteDlg').execute()\">" . __('Save') . "</button> ";
     print "<button dojoType=\"dijit.form.Button\"\n\t\t\tonclick=\"dijit.byId('editNoteDlg').hide()\">" . __('Cancel') . "</button>";
     print "</div>";
 }
Exemple #12
0
 function getQr()
 {
     $id = db_escape_string($_REQUEST['id']);
     $article_link = '';
     $result = db_query("SELECT title, link\n\t\t\t\tFROM ttrss_entries, ttrss_user_entries\n\t\t\t\tWHERE id = '{$id}' AND ref_id = id AND owner_uid = " . $_SESSION['uid']);
     if (db_num_rows($result) != 0) {
         $article_link = db_fetch_result($result, 0, 'link');
     }
     $pngPath = dirname(__FILE__) . '/cache/' . $id . '.png';
     if (!file_exists($pngPath)) {
         require_once dirname(__FILE__) . '/phpqrcode/qrlib.php';
         QRcode::png($article_link, $pngPath);
     }
     echo '<div><img src="plugins/qrcodegen/cache/' . $id . '.png" style="display: block; margin: 0 auto;"></div>';
     echo "<div style='text-align : center'>";
     print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('qrCodeArticleDlg').hide()\">" . __('Close this dialog') . "</button>";
     print "</div>";
 }
Exemple #13
0
 function getInfo()
 {
     $id = db_escape_string($_REQUEST['id']);
     $result = db_query("SELECT title, link\r\n\t\t\t\tFROM ttrss_entries, ttrss_user_entries\r\n\t\t\t\tWHERE id = '{$id}' AND ref_id = id AND owner_uid = " . $_SESSION['uid']);
     if (db_num_rows($result) != 0) {
         $title = truncate_string(strip_tags(db_fetch_result($result, 0, 'title')), 100, '...');
         $article_link = db_fetch_result($result, 0, 'link');
     }
     $yourls_url = $this->host->get($this, "Yourls_URL");
     $yourls_api = $this->host->get($this, "Yourls_API");
     curl_setopt($curl_yourls, CURLOPT_URL, "{$yourls_url}/yourls-api.php?signature={$yourls_api}&action=shorturl&format=simple&url=" . urlencode($article_link) . "&title=" . urlencode($title));
     curl_setopt($curl_yourls, CURLOPT_RETURNTRANSFER, true);
     if (!ini_get('safe_mode') && !ini_get('open_basedir')) {
         curl_setopt($curl_yourls, CURLOPT_FOLLOWLOCATION, true);
     }
     $short_url = curl_exec($curl_yourls);
     curl_setopt($this->curl_yourls, CURLOPT_URL, "{$yourls_url}/yourls-api.php?signature={$yourls_api}&action=shorturl&format=simple&url=" . urlencode($article_link) . "&title=" . urlencode($title));
     $short_url = curl_exec($this->curl_yourls);
     print json_encode(array("title" => $title, "link" => $article_link, "id" => $id, "yourlsurl" => $yourls_url, "yourlsapi" => $yourls_api, "shorturl" => $short_url));
 }
Exemple #14
0
 function edit()
 {
     $id = db_escape_string($_REQUEST["id"]);
     $result = db_query($this->link, "SELECT * FROM ttrss_linked_instances WHERE\n\t\t\tid = '{$id}'");
     print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\"  name=\"id\" value=\"{$id}\">";
     print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\"  name=\"op\" value=\"pref-instances\">";
     print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\"  name=\"method\" value=\"editSave\">";
     print "<div class=\"dlgSec\">" . __("Instance") . "</div>";
     print "<div class=\"dlgSecCont\">";
     /* URL */
     $access_url = htmlspecialchars(db_fetch_result($result, 0, "access_url"));
     print __("URL:") . " ";
     print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"\n\t\t\tplaceHolder=\"" . __("Instance URL") . "\"\n\t\t\tregExp='^(http|https)://.*'\n\t\t\tstyle=\"font-size : 16px; width: 20em\" name=\"access_url\"\n\t\t\tvalue=\"{$access_url}\">";
     print "<hr/>";
     $access_key = htmlspecialchars(db_fetch_result($result, 0, "access_key"));
     /* Access key */
     print __("Access key:") . " ";
     print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"\n\t\t\tplaceHolder=\"" . __("Access key") . "\" regExp='\\w{40}'\n\t\t\tstyle=\"width: 20em\" name=\"access_key\" id=\"instance_edit_key\"\n\t\t\tvalue=\"{$access_key}\">";
     print "<p class='insensitive'>" . __("Use one access key for both linked instances.");
     print "</div>";
     print "<div class=\"dlgButtons\">\n\t\t\t<div style='float : left'>\n\t\t\t\t<button dojoType=\"dijit.form.Button\"\n\t\t\t\t\tonclick=\"return dijit.byId('instanceEditDlg').regenKey()\">" . __('Generate new key') . "</button>\n\t\t\t</div>\n\t\t\t<button dojoType=\"dijit.form.Button\"\n\t\t\t\tonclick=\"return dijit.byId('instanceEditDlg').execute()\">" . __('Save') . "</button>\n\t\t\t<button dojoType=\"dijit.form.Button\"\n\t\t\t\tonclick=\"return dijit.byId('instanceEditDlg').hide()\"\">" . __('Cancel') . "</button></div>";
 }
 function hook_article_filter($article)
 {
     $wpm = 180;
     // arbitrary value, based on adult averages
     $word_count = str_word_count($article["content"]);
     $minutes = round($word_count / $wpm);
     $minimum_time_bucket = 5;
     // minutes
     $time_label = $this->minutes_to_time_label($minutes, $minimum_time_bucket);
     _debug("estimated reading time: {$minutes} min ({$time_label}), based on {$word_count} words at {$wpm} WPM");
     $owner_uid = $article["owner_uid"];
     if (!label_find_id($time_label, $owner_uid)) {
         label_create($time_label);
     }
     $guid = $article["guid"];
     $result = db_query("SELECT id FROM ttrss_entries WHERE guid = '{$guid}'");
     if (db_num_rows($result) != 0) {
         $ref_id = db_fetch_result($result, 0, "id");
         label_add_article($ref_id, $time_label, $owner_uid);
     }
     return $article;
 }
 function quickAddCat()
 {
     $cat = db_escape_string($_REQUEST["cat"]);
     add_feed_category($this->link, $cat);
     $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE\n\t\t\ttitle = '{$cat}' AND owner_uid = " . $_SESSION["uid"]);
     if (db_num_rows($result) == 1) {
         $id = db_fetch_result($result, 0, "id");
     } else {
         $id = 0;
     }
     print_feed_cat_select($this->link, "cat_id", $id);
 }
Exemple #17
0
 function edit()
 {
     $filter_id = db_escape_string($_REQUEST["id"]);
     $result = db_query($this->link, "SELECT * FROM ttrss_filters WHERE id = '{$filter_id}' AND owner_uid = " . $_SESSION["uid"]);
     $reg_exp = htmlspecialchars(db_fetch_result($result, 0, "reg_exp"));
     $filter_type = db_fetch_result($result, 0, "filter_type");
     $feed_id = db_fetch_result($result, 0, "feed_id");
     $cat_id = db_fetch_result($result, 0, "cat_id");
     $action_id = db_fetch_result($result, 0, "action_id");
     $action_param = db_fetch_result($result, 0, "action_param");
     $filter_param = db_fetch_result($result, 0, "filter_param");
     $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
     $inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse"));
     $cat_filter = sql_bool_to_bool(db_fetch_result($result, 0, "cat_filter"));
     print "<form id=\"filter_edit_form\" onsubmit='return false'>";
     print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">";
     print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"{$filter_id}\">";
     print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"editSave\">";
     print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"csrf_token\" value=\"" . $_SESSION['csrf_token'] . "\">";
     $result = db_query($this->link, "SELECT id,description\n\t\t\tFROM ttrss_filter_types ORDER BY description");
     $filter_types = array();
     while ($line = db_fetch_assoc($result)) {
         //array_push($filter_types, $line["description"]);
         $filter_types[$line["id"]] = __($line["description"]);
     }
     print "<div class=\"dlgSec\">" . __("Match") . "</div>";
     print "<div class=\"dlgSecCont\">";
     if ($filter_type != 5) {
         $date_ops_invisible = 'style="display : none"';
     }
     print "<span id=\"filterDlg_dateModBox\" {$date_ops_invisible}>";
     print __("Date") . " ";
     $filter_params = array("before" => __("before"), "after" => __("after"));
     print_select_hash("filter_date_modifier", $filter_param, $filter_params, 'dojoType="dijit.form.Select"');
     print "&nbsp;</span>";
     print "<input dojoType=\"dijit.form.ValidationTextBox\"\n\t\t\t\t required=\"1\"\n\t\t\t\t name=\"reg_exp\" style=\"font-size : 16px;\" value=\"{$reg_exp}\">";
     print "<span id=\"filterDlg_dateChkBox\" {$date_ops_invisible}>";
     print "&nbsp;<button dojoType=\"dijit.form.Button\" onclick=\"return filterDlgCheckDate()\">" . __('Check it') . "</button>";
     print "</span>";
     print "<hr/> " . __("on field") . " ";
     print_select_hash("filter_type", $filter_type, $filter_types, 'onchange="filterDlgCheckType(this)" dojoType="dijit.form.Select"');
     print "<hr/>";
     print __("in") . " ";
     $hidden = $cat_filter ? "style='display:none'" : "";
     print "<span id='filterDlg_feeds' {$hidden}>";
     print_feed_select($this->link, "feed_id", $feed_id, 'dojoType="dijit.form.FilteringSelect"');
     print "</span>";
     $hidden = $cat_filter ? "" : "style='display:none'";
     print "<span id='filterDlg_cats' {$hidden}>";
     print_feed_cat_select($this->link, "cat_id", $cat_id, 'dojoType="dijit.form.FilteringSelect"');
     print "</span>";
     print "</div>";
     print "<div class=\"dlgSec\">" . __("Perform Action") . "</div>";
     print "<div class=\"dlgSecCont\">";
     print "<select name=\"action_id\" dojoType=\"dijit.form.Select\"\n\t\t\tonchange=\"filterDlgCheckAction(this)\">";
     $result = db_query($this->link, "SELECT id,description FROM ttrss_filter_actions\n\t\t\tORDER BY name");
     while ($line = db_fetch_assoc($result)) {
         $is_sel = $line["id"] == $action_id ? "selected=\"1\"" : "";
         printf("<option value='%d' {$is_sel}>%s</option>", $line["id"], __($line["description"]));
     }
     print "</select>";
     $param_hidden = $action_id == 4 || $action_id == 6 || $action_id == 7 ? "" : "display : none";
     print "<span id=\"filterDlg_paramBox\" style=\"{$param_hidden}\">";
     print " " . __("with parameters:") . " ";
     $param_int_hidden = $action_id != 7 ? "" : "display : none";
     print "<input style=\"{$param_int_hidden}\"\n\t\t\t\tdojoType=\"dijit.form.TextBox\" id=\"filterDlg_actionParam\"\n\t\t\t\tname=\"action_param\" value=\"{$action_param}\">";
     $param_int_hidden = $action_id == 7 ? "" : "display : none";
     print_label_select($this->link, "action_param_label", $action_param, "style=\"{$param_int_hidden}\"" . 'id="filterDlg_actionParamLabel" dojoType="dijit.form.Select"');
     print "</span>";
     print "&nbsp;";
     // tiny layout hack
     print "</div>";
     print "<div class=\"dlgSec\">" . __("Options") . "</div>";
     print "<div class=\"dlgSecCont\">";
     print "<div style=\"line-height : 100%\">";
     if ($enabled) {
         $checked = "checked=\"1\"";
     } else {
         $checked = "";
     }
     print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" {$checked}>\n\t\t\t\t<label for=\"enabled\">" . __('Enabled') . "</label><hr/>";
     if ($inverse) {
         $checked = "checked=\"1\"";
     } else {
         $checked = "";
     }
     print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\" {$checked}>\n\t\t\t<label for=\"inverse\">" . __('Inverse match') . "</label><hr/>";
     if ($cat_filter) {
         $checked = "checked=\"1\"";
     } else {
         $checked = "";
     }
     print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"cat_filter\" id=\"cat_filter\" onchange=\"filterDlgCheckCat(this)\" {$checked}>\n\t\t\t\t<label for=\"cat_filter\">" . __('Apply to category') . "</label><hr/>";
     print "</div>";
     print "</div>";
     print "<div class=\"dlgButtons\">";
     print "<div style=\"float : left\">";
     print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').removeFilter()\">" . __('Remove') . "</button>";
     print "</div>";
     print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">" . __('Test') . "</button> ";
     print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">" . __('Save') . "</button> ";
     print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">" . __('Cancel') . "</button>";
     print "</div>";
 }
Exemple #18
0
function getFeedTitle($id, $cat = false)
{
    if ($cat) {
        return getCategoryTitle($id);
    } else {
        if ($id == -1) {
            return __("Starred articles");
        } else {
            if ($id == -2) {
                return __("Published articles");
            } else {
                if ($id == -3) {
                    return __("Fresh articles");
                } else {
                    if ($id == -4) {
                        return __("All articles");
                    } else {
                        if ($id === 0 || $id === "0") {
                            return __("Archived articles");
                        } else {
                            if ($id == -6) {
                                return __("Recently read");
                            } else {
                                if ($id < LABEL_BASE_INDEX) {
                                    $label_id = feed_to_label_id($id);
                                    $result = db_query("SELECT caption FROM ttrss_labels2 WHERE id = '{$label_id}'");
                                    if (db_num_rows($result) == 1) {
                                        return db_fetch_result($result, 0, "caption");
                                    } else {
                                        return "Unknown label ({$label_id})";
                                    }
                                } else {
                                    if (is_numeric($id) && $id > 0) {
                                        $result = db_query("SELECT title FROM ttrss_feeds WHERE id = '{$id}'");
                                        if (db_num_rows($result) == 1) {
                                            return db_fetch_result($result, 0, "title");
                                        } else {
                                            return "Unknown feed ({$id})";
                                        }
                                    } else {
                                        return $id;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
function update_rss_feed($feed, $ignore_daemon = false, $no_cache = false)
{
    $debug_enabled = defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug'];
    _debug("start", $debug_enabled);
    $result = db_query("SELECT id,update_interval,auth_login,\n\t\t\tfeed_url,auth_pass,cache_images,last_updated,\n\t\t\tmark_unread_on_update, owner_uid,\n\t\t\tpubsub_state, auth_pass_encrypted,\n\t\t\t(SELECT max(date_entered) FROM\n\t\t\t\tttrss_entries, ttrss_user_entries where ref_id = id AND feed_id = '{$feed}') AS last_article_timestamp\n\t\t\tFROM ttrss_feeds WHERE id = '{$feed}'");
    if (db_num_rows($result) == 0) {
        _debug("feed {$feed} NOT FOUND/SKIPPED", $debug_enabled);
        return false;
    }
    $last_updated = db_fetch_result($result, 0, "last_updated");
    $last_article_timestamp = @strtotime(db_fetch_result($result, 0, "last_article_timestamp"));
    if (defined('_DISABLE_HTTP_304')) {
        $last_article_timestamp = 0;
    }
    $owner_uid = db_fetch_result($result, 0, "owner_uid");
    $mark_unread_on_update = sql_bool_to_bool(db_fetch_result($result, 0, "mark_unread_on_update"));
    $pubsub_state = db_fetch_result($result, 0, "pubsub_state");
    $auth_pass_encrypted = sql_bool_to_bool(db_fetch_result($result, 0, "auth_pass_encrypted"));
    db_query("UPDATE ttrss_feeds SET last_update_started = NOW()\n\t\t\tWHERE id = '{$feed}'");
    $auth_login = db_fetch_result($result, 0, "auth_login");
    $auth_pass = db_fetch_result($result, 0, "auth_pass");
    if ($auth_pass_encrypted) {
        require_once "crypt.php";
        $auth_pass = decrypt_string($auth_pass);
    }
    $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
    $fetch_url = db_fetch_result($result, 0, "feed_url");
    $feed = db_escape_string($feed);
    $date_feed_processed = date('Y-m-d H:i');
    $cache_filename = CACHE_DIR . "/simplepie/" . sha1($fetch_url) . ".xml";
    $pluginhost = new PluginHost();
    $pluginhost->set_debug($debug_enabled);
    $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
    $pluginhost->load(PLUGINS, PluginHost::KIND_ALL);
    $pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid);
    $pluginhost->load_data();
    $rss = false;
    $rss_hash = false;
    $force_refetch = isset($_REQUEST["force_refetch"]);
    if (file_exists($cache_filename) && is_readable($cache_filename) && !$auth_login && !$auth_pass && filemtime($cache_filename) > time() - 30) {
        _debug("using local cache.", $debug_enabled);
        @($feed_data = file_get_contents($cache_filename));
        if ($feed_data) {
            $rss_hash = sha1($feed_data);
        }
    } else {
        _debug("local cache will not be used for this feed", $debug_enabled);
    }
    if (!$rss) {
        foreach ($pluginhost->get_hooks(PluginHost::HOOK_FETCH_FEED) as $plugin) {
            $feed_data = $plugin->hook_fetch_feed($feed_data, $fetch_url, $owner_uid, $feed);
        }
        if (!$feed_data) {
            _debug("fetching [{$fetch_url}]...", $debug_enabled);
            _debug("If-Modified-Since: " . gmdate('D, d M Y H:i:s \\G\\M\\T', $last_article_timestamp), $debug_enabled);
            $feed_data = fetch_file_contents($fetch_url, false, $auth_login, $auth_pass, false, $no_cache ? FEED_FETCH_NO_CACHE_TIMEOUT : FEED_FETCH_TIMEOUT, $force_refetch ? 0 : $last_article_timestamp);
            global $fetch_curl_used;
            if (!$fetch_curl_used) {
                $tmp = @gzdecode($feed_data);
                if ($tmp) {
                    $feed_data = $tmp;
                }
            }
            $feed_data = trim($feed_data);
            _debug("fetch done.", $debug_enabled);
            /* if ($feed_data) {
            					$error = verify_feed_xml($feed_data);
            
            					if ($error) {
            						_debug("error verifying XML, code: " . $error->code, $debug_enabled);
            
            						if ($error->code == 26) {
            							_debug("got error 26, trying to decode entities...", $debug_enabled);
            
            							$feed_data = html_entity_decode($feed_data, ENT_COMPAT, 'UTF-8');
            
            							$error = verify_feed_xml($feed_data);
            
            							if ($error) $feed_data = '';
            						}
            					}
            				} */
        }
        if (!$feed_data) {
            global $fetch_last_error;
            global $fetch_last_error_code;
            _debug("unable to fetch: {$fetch_last_error} [{$fetch_last_error_code}]", $debug_enabled);
            $error_escaped = '';
            // If-Modified-Since
            if ($fetch_last_error_code != 304) {
                $error_escaped = db_escape_string($fetch_last_error);
            } else {
                _debug("source claims data not modified, nothing to do.", $debug_enabled);
            }
            db_query("UPDATE ttrss_feeds SET last_error = '{$error_escaped}',\n\t\t\t\t\t\tlast_updated = NOW() WHERE id = '{$feed}'");
            return;
        }
    }
    foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_FETCHED) as $plugin) {
        $feed_data = $plugin->hook_feed_fetched($feed_data, $fetch_url, $owner_uid, $feed);
    }
    // set last update to now so if anything *simplepie* crashes later we won't be
    // continuously failing on the same feed
    //db_query("UPDATE ttrss_feeds SET last_updated = NOW() WHERE id = '$feed'");
    if (!$rss) {
        $rss = new FeedParser($feed_data);
        $rss->init();
    }
    //		print_r($rss);
    $feed = db_escape_string($feed);
    if (!$rss->error()) {
        // cache data for later
        if (!$auth_pass && !$auth_login && is_writable(CACHE_DIR . "/simplepie")) {
            $new_rss_hash = sha1($rss_data);
            if ($new_rss_hash != $rss_hash && count($rss->get_items()) > 0) {
                _debug("saving {$cache_filename}", $debug_enabled);
                @file_put_contents($cache_filename, $feed_data);
            }
        }
        // We use local pluginhost here because we need to load different per-user feed plugins
        $pluginhost->run_hooks(PluginHost::HOOK_FEED_PARSED, "hook_feed_parsed", $rss);
        _debug("processing feed data...", $debug_enabled);
        //			db_query("BEGIN");
        if (DB_TYPE == "pgsql") {
            $favicon_interval_qpart = "favicon_last_checked < NOW() - INTERVAL '12 hour'";
        } else {
            $favicon_interval_qpart = "favicon_last_checked < DATE_SUB(NOW(), INTERVAL 12 HOUR)";
        }
        $result = db_query("SELECT title,site_url,owner_uid,favicon_avg_color,\n\t\t\t\t(favicon_last_checked IS NULL OR {$favicon_interval_qpart}) AS\n\t\t\t\t\t\tfavicon_needs_check\n\t\t\t\tFROM ttrss_feeds WHERE id = '{$feed}'");
        $registered_title = db_fetch_result($result, 0, "title");
        $orig_site_url = db_fetch_result($result, 0, "site_url");
        $favicon_needs_check = sql_bool_to_bool(db_fetch_result($result, 0, "favicon_needs_check"));
        $favicon_avg_color = db_fetch_result($result, 0, "favicon_avg_color");
        $owner_uid = db_fetch_result($result, 0, "owner_uid");
        $site_url = db_escape_string(mb_substr(rewrite_relative_url($fetch_url, $rss->get_link()), 0, 245));
        _debug("site_url: {$site_url}", $debug_enabled);
        _debug("feed_title: " . $rss->get_title(), $debug_enabled);
        if ($favicon_needs_check || $force_refetch) {
            /* terrible hack: if we crash on floicon shit here, we won't check
             * the icon avgcolor again (unless the icon got updated) */
            $favicon_file = ICONS_DIR . "/{$feed}.ico";
            $favicon_modified = @filemtime($favicon_file);
            _debug("checking favicon...", $debug_enabled);
            check_feed_favicon($site_url, $feed);
            $favicon_modified_new = @filemtime($favicon_file);
            if ($favicon_modified_new > $favicon_modified) {
                $favicon_avg_color = '';
            }
            if (file_exists($favicon_file) && function_exists("imagecreatefromstring") && $favicon_avg_color == '') {
                require_once "colors.php";
                db_query("UPDATE ttrss_feeds SET favicon_avg_color = 'fail' WHERE\n\t\t\t\t\t\t\tid = '{$feed}'");
                $favicon_color = db_escape_string(calculate_avg_color($favicon_file));
                $favicon_colorstring = ",favicon_avg_color = '" . $favicon_color . "'";
            } else {
                if ($favicon_avg_color == 'fail') {
                    _debug("floicon failed on this file, not trying to recalculate avg color", $debug_enabled);
                }
            }
            db_query("UPDATE ttrss_feeds SET favicon_last_checked = NOW()\n\t\t\t\t\t{$favicon_colorstring}\n\t\t\t\t\tWHERE id = '{$feed}'");
        }
        if (!$registered_title || $registered_title == "[Unknown]") {
            $feed_title = db_escape_string($rss->get_title());
            if ($feed_title) {
                _debug("registering title: {$feed_title}", $debug_enabled);
                db_query("UPDATE ttrss_feeds SET\n\t\t\t\t\t\ttitle = '{$feed_title}' WHERE id = '{$feed}'");
            }
        }
        if ($site_url && $orig_site_url != $site_url) {
            db_query("UPDATE ttrss_feeds SET\n\t\t\t\t\tsite_url = '{$site_url}' WHERE id = '{$feed}'");
        }
        _debug("loading filters & labels...", $debug_enabled);
        $filters = load_filters($feed, $owner_uid);
        $labels = get_all_labels($owner_uid);
        _debug("" . count($filters) . " filters loaded.", $debug_enabled);
        $items = $rss->get_items();
        if (!is_array($items)) {
            _debug("no articles found.", $debug_enabled);
            db_query("UPDATE ttrss_feeds\n\t\t\t\t\tSET last_updated = NOW(), last_error = '' WHERE id = '{$feed}'");
            return;
            // no articles
        }
        if ($pubsub_state != 2 && PUBSUBHUBBUB_ENABLED) {
            _debug("checking for PUSH hub...", $debug_enabled);
            $feed_hub_url = false;
            $links = $rss->get_links('hub');
            if ($links && is_array($links)) {
                foreach ($links as $l) {
                    $feed_hub_url = $l;
                    break;
                }
            }
            _debug("feed hub url: {$feed_hub_url}", $debug_enabled);
            if ($feed_hub_url && function_exists('curl_init') && !ini_get("open_basedir")) {
                require_once 'lib/pubsubhubbub/subscriber.php';
                $callback_url = get_self_url_prefix() . "/public.php?op=pubsub&id={$feed}";
                $s = new Subscriber($feed_hub_url, $callback_url);
                $rc = $s->subscribe($fetch_url);
                _debug("feed hub url found, subscribe request sent.", $debug_enabled);
                db_query("UPDATE ttrss_feeds SET pubsub_state = 1\n\t\t\t\t\t\tWHERE id = '{$feed}'");
            }
        }
        _debug("processing articles...", $debug_enabled);
        foreach ($items as $item) {
            if ($_REQUEST['xdebug'] == 3) {
                print_r($item);
            }
            $entry_guid = $item->get_id();
            if (!$entry_guid) {
                $entry_guid = $item->get_link();
            }
            if (!$entry_guid) {
                $entry_guid = make_guid_from_title($item->get_title());
            }
            _debug("f_guid {$entry_guid}", $debug_enabled);
            if (!$entry_guid) {
                continue;
            }
            $entry_guid = "{$owner_uid},{$entry_guid}";
            $entry_guid_hashed = db_escape_string('SHA1:' . sha1($entry_guid));
            _debug("guid {$entry_guid} / {$entry_guid_hashed}", $debug_enabled);
            $entry_timestamp = "";
            $entry_timestamp = $item->get_date();
            _debug("orig date: " . $item->get_date(), $debug_enabled);
            if ($entry_timestamp == -1 || !$entry_timestamp || $entry_timestamp > time()) {
                $entry_timestamp = time();
                $no_orig_date = 'true';
            } else {
                $no_orig_date = 'false';
            }
            $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
            _debug("date {$entry_timestamp} [{$entry_timestamp_fmt}]", $debug_enabled);
            //				$entry_title = html_entity_decode($item->get_title(), ENT_COMPAT, 'UTF-8');
            //				$entry_title = decode_numeric_entities($entry_title);
            $entry_title = $item->get_title();
            $entry_link = rewrite_relative_url($site_url, $item->get_link());
            _debug("title {$entry_title}", $debug_enabled);
            _debug("link {$entry_link}", $debug_enabled);
            if (!$entry_title) {
                $entry_title = date("Y-m-d H:i:s", $entry_timestamp);
            }
            $entry_content = $item->get_content();
            if (!$entry_content) {
                $entry_content = $item->get_description();
            }
            if ($_REQUEST["xdebug"] == 2) {
                print "content: ";
                print $entry_content;
                print "\n";
            }
            $entry_comments = $item->get_comments_url();
            $entry_author = $item->get_author();
            $entry_guid = db_escape_string(mb_substr($entry_guid, 0, 245));
            $entry_comments = db_escape_string(mb_substr(trim($entry_comments), 0, 245));
            $entry_author = db_escape_string(mb_substr(trim($entry_author), 0, 245));
            $num_comments = (int) $item->get_comments_count();
            _debug("author {$entry_author}", $debug_enabled);
            _debug("num_comments: {$num_comments}", $debug_enabled);
            _debug("looking for tags...", $debug_enabled);
            // parse <category> entries into tags
            $additional_tags = array();
            $additional_tags_src = $item->get_categories();
            if (is_array($additional_tags_src)) {
                foreach ($additional_tags_src as $tobj) {
                    array_push($additional_tags, $tobj);
                }
            }
            $entry_tags = array_unique($additional_tags);
            for ($i = 0; $i < count($entry_tags); $i++) {
                $entry_tags[$i] = mb_strtolower($entry_tags[$i], 'utf-8');
            }
            _debug("tags found: " . join(",", $entry_tags), $debug_enabled);
            _debug("done collecting data.", $debug_enabled);
            // TODO: less memory-hungry implementation
            _debug("applying plugin filters..", $debug_enabled);
            // FIXME not sure if owner_uid is a good idea here, we may have a base entry without user entry (?)
            $result = db_query("SELECT plugin_data,title,content,link,tag_cache,author FROM ttrss_entries, ttrss_user_entries\n\t\t\t\t\tWHERE ref_id = id AND (guid = '" . db_escape_string($entry_guid) . "' OR guid = '{$entry_guid_hashed}') AND owner_uid = {$owner_uid}");
            if (db_num_rows($result) != 0) {
                $entry_plugin_data = db_fetch_result($result, 0, "plugin_data");
                $stored_article = array("title" => db_fetch_result($result, 0, "title"), "content" => db_fetch_result($result, 0, "content"), "link" => db_fetch_result($result, 0, "link"), "tags" => explode(",", db_fetch_result($result, 0, "tag_cache")), "author" => db_fetch_result($result, 0, "author"));
            } else {
                $entry_plugin_data = "";
                $stored_article = array();
            }
            $article = array("owner_uid" => $owner_uid, "guid" => $entry_guid, "title" => $entry_title, "content" => $entry_content, "link" => $entry_link, "tags" => $entry_tags, "plugin_data" => $entry_plugin_data, "author" => $entry_author, "stored" => $stored_article);
            foreach ($pluginhost->get_hooks(PluginHost::HOOK_ARTICLE_FILTER) as $plugin) {
                $article = $plugin->hook_article_filter($article);
            }
            $entry_tags = $article["tags"];
            $entry_guid = db_escape_string($entry_guid);
            $entry_title = db_escape_string($article["title"]);
            $entry_author = db_escape_string($article["author"]);
            $entry_link = db_escape_string($article["link"]);
            $entry_plugin_data = db_escape_string($article["plugin_data"]);
            $entry_content = $article["content"];
            // escaped below
            _debug("plugin data: {$entry_plugin_data}", $debug_enabled);
            if ($cache_images && is_writable(CACHE_DIR . '/images')) {
                cache_images($entry_content, $site_url, $debug_enabled);
            }
            $entry_content = db_escape_string($entry_content, false);
            $content_hash = "SHA1:" . sha1($entry_content);
            db_query("BEGIN");
            $result = db_query("SELECT id FROM\tttrss_entries\n\t\t\t\t\tWHERE (guid = '{$entry_guid}' OR guid = '{$entry_guid_hashed}')");
            if (db_num_rows($result) == 0) {
                _debug("base guid [{$entry_guid}] not found", $debug_enabled);
                // base post entry does not exist, create it
                $result = db_query("INSERT INTO ttrss_entries\n\t\t\t\t\t\t\t(title,\n\t\t\t\t\t\t\tguid,\n\t\t\t\t\t\t\tlink,\n\t\t\t\t\t\t\tupdated,\n\t\t\t\t\t\t\tcontent,\n\t\t\t\t\t\t\tcontent_hash,\n\t\t\t\t\t\t\tno_orig_date,\n\t\t\t\t\t\t\tdate_updated,\n\t\t\t\t\t\t\tdate_entered,\n\t\t\t\t\t\t\tcomments,\n\t\t\t\t\t\t\tnum_comments,\n\t\t\t\t\t\t\tplugin_data,\n\t\t\t\t\t\t\tauthor)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t('{$entry_title}',\n\t\t\t\t\t\t\t'{$entry_guid_hashed}',\n\t\t\t\t\t\t\t'{$entry_link}',\n\t\t\t\t\t\t\t'{$entry_timestamp_fmt}',\n\t\t\t\t\t\t\t'{$entry_content}',\n\t\t\t\t\t\t\t'{$content_hash}',\n\t\t\t\t\t\t\t{$no_orig_date},\n\t\t\t\t\t\t\tNOW(),\n\t\t\t\t\t\t\t'{$date_feed_processed}',\n\t\t\t\t\t\t\t'{$entry_comments}',\n\t\t\t\t\t\t\t'{$num_comments}',\n\t\t\t\t\t\t\t'{$entry_plugin_data}',\n\t\t\t\t\t\t\t'{$entry_author}')");
                $article_labels = array();
            } else {
                // we keep encountering the entry in feeds, so we need to
                // update date_updated column so that we don't get horrible
                // dupes when the entry gets purged and reinserted again e.g.
                // in the case of SLOW SLOW OMG SLOW updating feeds
                $base_entry_id = db_fetch_result($result, 0, "id");
                db_query("UPDATE ttrss_entries SET date_updated = NOW()\n\t\t\t\t\t\tWHERE id = '{$base_entry_id}'");
                $article_labels = get_article_labels($base_entry_id, $owner_uid);
            }
            // now it should exist, if not - bad luck then
            $result = db_query("SELECT\n\t\t\t\t\t\tid,content_hash,no_orig_date,title,plugin_data,guid,\n\t\t\t\t\t\t" . SUBSTRING_FOR_DATE . "(date_updated,1,19) as date_updated,\n\t\t\t\t\t\t" . SUBSTRING_FOR_DATE . "(updated,1,19) as updated,\n\t\t\t\t\t\tnum_comments\n\t\t\t\t\tFROM\n\t\t\t\t\t\tttrss_entries\n\t\t\t\t\tWHERE guid = '{$entry_guid}' OR guid = '{$entry_guid_hashed}'");
            $entry_ref_id = 0;
            $entry_int_id = 0;
            if (db_num_rows($result) == 1) {
                _debug("base guid found, checking for user record", $debug_enabled);
                // this will be used below in update handler
                $orig_content_hash = db_fetch_result($result, 0, "content_hash");
                $orig_title = db_fetch_result($result, 0, "title");
                $orig_num_comments = db_fetch_result($result, 0, "num_comments");
                $orig_date_updated = strtotime(db_fetch_result($result, 0, "date_updated"));
                $orig_plugin_data = db_fetch_result($result, 0, "plugin_data");
                $ref_id = db_fetch_result($result, 0, "id");
                $entry_ref_id = $ref_id;
                /* $stored_guid = db_fetch_result($result, 0, "guid");
                					if ($stored_guid != $entry_guid_hashed) {
                						if ($debug_enabled) _debug("upgrading compat guid to hashed one", $debug_enabled);
                
                						db_query("UPDATE ttrss_entries SET guid = '$entry_guid_hashed' WHERE
                							id = '$ref_id'");
                					} */
                // check for user post link to main table
                // do we allow duplicate posts with same GUID in different feeds?
                if (get_pref("ALLOW_DUPLICATE_POSTS", $owner_uid, false)) {
                    $dupcheck_qpart = "AND (feed_id = '{$feed}' OR feed_id IS NULL)";
                } else {
                    $dupcheck_qpart = "";
                }
                /* Collect article tags here so we could filter by them: */
                $article_filters = get_article_filters($filters, $entry_title, $entry_content, $entry_link, $entry_timestamp, $entry_author, $entry_tags);
                if ($debug_enabled) {
                    _debug("article filters: ", $debug_enabled);
                    if (count($article_filters) != 0) {
                        print_r($article_filters);
                    }
                }
                if (find_article_filter($article_filters, "filter")) {
                    db_query("COMMIT");
                    // close transaction in progress
                    continue;
                }
                $score = calculate_article_score($article_filters);
                _debug("initial score: {$score}", $debug_enabled);
                $query = "SELECT ref_id, int_id FROM ttrss_user_entries WHERE\n\t\t\t\t\t\t\tref_id = '{$ref_id}' AND owner_uid = '{$owner_uid}'\n\t\t\t\t\t\t\t{$dupcheck_qpart}";
                //					if ($_REQUEST["xdebug"]) print "$query\n";
                $result = db_query($query);
                // okay it doesn't exist - create user entry
                if (db_num_rows($result) == 0) {
                    _debug("user record not found, creating...", $debug_enabled);
                    if ($score >= -500 && !find_article_filter($article_filters, 'catchup')) {
                        $unread = 'true';
                        $last_read_qpart = 'NULL';
                    } else {
                        $unread = 'false';
                        $last_read_qpart = 'NOW()';
                    }
                    if (find_article_filter($article_filters, 'mark') || $score > 1000) {
                        $marked = 'true';
                    } else {
                        $marked = 'false';
                    }
                    if (find_article_filter($article_filters, 'publish')) {
                        $published = 'true';
                    } else {
                        $published = 'false';
                    }
                    // N-grams
                    if (DB_TYPE == "pgsql" and defined('_NGRAM_TITLE_DUPLICATE_THRESHOLD')) {
                        $result = db_query("SELECT COUNT(*) AS similar FROM\n\t\t\t\t\t\t\t\t\tttrss_entries,ttrss_user_entries\n\t\t\t\t\t\t\t\tWHERE ref_id = id AND updated >= NOW() - INTERVAL '7 day'\n\t\t\t\t\t\t\t\t\tAND similarity(title, '{$entry_title}') >= " . _NGRAM_TITLE_DUPLICATE_THRESHOLD . "\n\t\t\t\t\t\t\t\t\tAND owner_uid = {$owner_uid}");
                        $ngram_similar = db_fetch_result($result, 0, "similar");
                        _debug("N-gram similar results: {$ngram_similar}", $debug_enabled);
                        if ($ngram_similar > 0) {
                            $unread = 'false';
                        }
                    }
                    $last_marked = $marked == 'true' ? 'NOW()' : 'NULL';
                    $last_published = $published == 'true' ? 'NOW()' : 'NULL';
                    $result = db_query("INSERT INTO ttrss_user_entries\n\t\t\t\t\t\t\t\t(ref_id, owner_uid, feed_id, unread, last_read, marked,\n\t\t\t\t\t\t\t\tpublished, score, tag_cache, label_cache, uuid,\n\t\t\t\t\t\t\t\tlast_marked, last_published)\n\t\t\t\t\t\t\tVALUES ('{$ref_id}', '{$owner_uid}', '{$feed}', {$unread},\n\t\t\t\t\t\t\t\t{$last_read_qpart}, {$marked}, {$published}, '{$score}', '', '',\n\t\t\t\t\t\t\t\t'', {$last_marked}, {$last_published})");
                    if (PUBSUBHUBBUB_HUB && $published == 'true') {
                        $rss_link = get_self_url_prefix() . "/public.php?op=rss&id=-2&key=" . get_feed_access_key(-2, false, $owner_uid);
                        $p = new Publisher(PUBSUBHUBBUB_HUB);
                        $pubsub_result = $p->publish_update($rss_link);
                    }
                    $result = db_query("SELECT int_id FROM ttrss_user_entries WHERE\n\t\t\t\t\t\t\t\tref_id = '{$ref_id}' AND owner_uid = '{$owner_uid}' AND\n\t\t\t\t\t\t\t\tfeed_id = '{$feed}' LIMIT 1");
                    if (db_num_rows($result) == 1) {
                        $entry_int_id = db_fetch_result($result, 0, "int_id");
                    }
                } else {
                    _debug("user record FOUND", $debug_enabled);
                    $entry_ref_id = db_fetch_result($result, 0, "ref_id");
                    $entry_int_id = db_fetch_result($result, 0, "int_id");
                }
                _debug("RID: {$entry_ref_id}, IID: {$entry_int_id}", $debug_enabled);
                $post_needs_update = false;
                $update_insignificant = false;
                if ($orig_num_comments != $num_comments) {
                    $post_needs_update = true;
                    $update_insignificant = true;
                }
                if ($entry_plugin_data != $orig_plugin_data) {
                    $post_needs_update = true;
                    $update_insignificant = true;
                }
                if ($content_hash != $orig_content_hash) {
                    $post_needs_update = true;
                    $update_insignificant = false;
                }
                if (db_escape_string($orig_title) != $entry_title) {
                    $post_needs_update = true;
                    $update_insignificant = false;
                }
                // if post needs update, update it and mark all user entries
                // linking to this post as updated
                if ($post_needs_update) {
                    if (defined('DAEMON_EXTENDED_DEBUG')) {
                        _debug("post {$entry_guid_hashed} needs update...", $debug_enabled);
                    }
                    //						print "<!-- post $orig_title needs update : $post_needs_update -->";
                    db_query("UPDATE ttrss_entries\n\t\t\t\t\t\t\tSET title = '{$entry_title}', content = '{$entry_content}',\n\t\t\t\t\t\t\t\tcontent_hash = '{$content_hash}',\n\t\t\t\t\t\t\t\tupdated = '{$entry_timestamp_fmt}',\n\t\t\t\t\t\t\t\tnum_comments = '{$num_comments}',\n\t\t\t\t\t\t\t\tplugin_data = '{$entry_plugin_data}'\n\t\t\t\t\t\t\tWHERE id = '{$ref_id}'");
                    if (!$update_insignificant) {
                        if ($mark_unread_on_update) {
                            db_query("UPDATE ttrss_user_entries\n\t\t\t\t\t\t\t\t\tSET last_read = null, unread = true WHERE ref_id = '{$ref_id}'");
                        }
                    }
                }
            }
            db_query("COMMIT");
            _debug("assigning labels...", $debug_enabled);
            assign_article_to_label_filters($entry_ref_id, $article_filters, $owner_uid, $article_labels);
            _debug("looking for enclosures...", $debug_enabled);
            // enclosures
            $enclosures = array();
            $encs = $item->get_enclosures();
            if (is_array($encs)) {
                foreach ($encs as $e) {
                    $e_item = array($e->link, $e->type, $e->length);
                    array_push($enclosures, $e_item);
                }
            }
            if ($debug_enabled) {
                _debug("article enclosures:", $debug_enabled);
                print_r($enclosures);
            }
            db_query("BEGIN");
            foreach ($enclosures as $enc) {
                $enc_url = db_escape_string($enc[0]);
                $enc_type = db_escape_string($enc[1]);
                $enc_dur = db_escape_string($enc[2]);
                $result = db_query("SELECT id FROM ttrss_enclosures\n\t\t\t\t\t\tWHERE content_url = '{$enc_url}' AND post_id = '{$entry_ref_id}'");
                if (db_num_rows($result) == 0) {
                    db_query("INSERT INTO ttrss_enclosures\n\t\t\t\t\t\t\t(content_url, content_type, title, duration, post_id) VALUES\n\t\t\t\t\t\t\t('{$enc_url}', '{$enc_type}', '', '{$enc_dur}', '{$entry_ref_id}')");
                }
            }
            db_query("COMMIT");
            // check for manual tags (we have to do it here since they're loaded from filters)
            foreach ($article_filters as $f) {
                if ($f["type"] == "tag") {
                    $manual_tags = trim_array(explode(",", $f["param"]));
                    foreach ($manual_tags as $tag) {
                        if (tag_is_valid($tag)) {
                            array_push($entry_tags, $tag);
                        }
                    }
                }
            }
            // Skip boring tags
            $boring_tags = trim_array(explode(",", mb_strtolower(get_pref('BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8')));
            $filtered_tags = array();
            $tags_to_cache = array();
            if ($entry_tags && is_array($entry_tags)) {
                foreach ($entry_tags as $tag) {
                    if (array_search($tag, $boring_tags) === false) {
                        array_push($filtered_tags, $tag);
                    }
                }
            }
            $filtered_tags = array_unique($filtered_tags);
            if ($debug_enabled) {
                _debug("filtered article tags:", $debug_enabled);
                print_r($filtered_tags);
            }
            // Save article tags in the database
            if (count($filtered_tags) > 0) {
                db_query("BEGIN");
                foreach ($filtered_tags as $tag) {
                    $tag = sanitize_tag($tag);
                    $tag = db_escape_string($tag);
                    if (!tag_is_valid($tag)) {
                        continue;
                    }
                    $result = db_query("SELECT id FROM ttrss_tags\n\t\t\t\t\t\t\tWHERE tag_name = '{$tag}' AND post_int_id = '{$entry_int_id}' AND\n\t\t\t\t\t\t\towner_uid = '{$owner_uid}' LIMIT 1");
                    if ($result && db_num_rows($result) == 0) {
                        db_query("INSERT INTO ttrss_tags\n\t\t\t\t\t\t\t\t\t(owner_uid,tag_name,post_int_id)\n\t\t\t\t\t\t\t\t\tVALUES ('{$owner_uid}','{$tag}', '{$entry_int_id}')");
                    }
                    array_push($tags_to_cache, $tag);
                }
                /* update the cache */
                $tags_to_cache = array_unique($tags_to_cache);
                $tags_str = db_escape_string(join(",", $tags_to_cache));
                db_query("UPDATE ttrss_user_entries\n\t\t\t\t\t\tSET tag_cache = '{$tags_str}' WHERE ref_id = '{$entry_ref_id}'\n\t\t\t\t\t\tAND owner_uid = {$owner_uid}");
                db_query("COMMIT");
            }
            if (get_pref("AUTO_ASSIGN_LABELS", $owner_uid, false)) {
                _debug("auto-assigning labels...", $debug_enabled);
                foreach ($labels as $label) {
                    $caption = preg_quote($label["caption"]);
                    if ($caption && preg_match("/\\b{$caption}\\b/i", "{$tags_str} " . strip_tags($entry_content) . " {$entry_title}")) {
                        if (!labels_contains_caption($article_labels, $caption)) {
                            label_add_article($entry_ref_id, $caption, $owner_uid);
                        }
                    }
                }
            }
            _debug("article processed", $debug_enabled);
        }
        _debug("purging feed...", $debug_enabled);
        purge_feed($feed, 0, $debug_enabled);
        db_query("UPDATE ttrss_feeds\n\t\t\t\tSET last_updated = NOW(), last_error = '' WHERE id = '{$feed}'");
        //			db_query("COMMIT");
    } else {
        $error_msg = db_escape_string(mb_substr($rss->error(), 0, 245));
        _debug("error fetching feed: {$error_msg}", $debug_enabled);
        db_query("UPDATE ttrss_feeds SET last_error = '{$error_msg}',\n\t\t\t\t\tlast_updated = NOW() WHERE id = '{$feed}'");
    }
    unset($rss);
    _debug("done", $debug_enabled);
}
Exemple #20
0
 function hook_article_filter($article)
 {
     if (DB_TYPE != "pgsql") {
         return $article;
     }
     $result = db_query("select 'similarity'::regproc");
     if (db_num_rows($result) == 0) {
         return $article;
     }
     $enable_globally = $this->host->get($this, "enable_globally");
     if (!$enable_globally) {
         $enabled_feeds = $this->host->get($this, "enabled_feeds");
         $key = array_search($article["feed"]["id"], $enabled_feeds);
         if ($key === FALSE) {
             return $article;
         }
     }
     $similarity = (double) $this->host->get($this, "similarity");
     if ($similarity < 0.01) {
         return $article;
     }
     $min_title_length = (int) $this->host->get($this, "min_length");
     if (mb_strlen($article["title"]) < $min_title_length) {
         return $article;
     }
     $owner_uid = $article["owner_uid"];
     $feed_id = $article["feed"]["id"];
     $title_escaped = db_escape_string($article["title"]);
     // trgm does not return similarity=1 for completely equal strings
     $result = db_query("SELECT COUNT(id) AS nequal\n\t\t  FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id AND\n\t\t  date_entered >= NOW() - interval '1 day' AND\n\t\t  title = '{$title_escaped}' AND\n\t\t  feed_id != '{$feed_id}' AND\n\t\t  owner_uid = {$owner_uid}");
     $nequal = db_fetch_result($result, 0, "nequal");
     _debug("af_psql_trgm: num equals: {$nequal}");
     if ($nequal != 0) {
         $article["force_catchup"] = true;
         return $article;
     }
     $result = db_query("SELECT MAX(SIMILARITY(title, '{$title_escaped}')) AS ms\n\t\t  FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id AND\n\t\t  date_entered >= NOW() - interval '1 day' AND\n\t\t  feed_id != '{$feed_id}' AND\n\t\t  owner_uid = {$owner_uid}");
     $similarity_result = db_fetch_result($result, 0, "ms");
     _debug("af_psql_trgm: similarity result: {$similarity_result}");
     if ($similarity_result >= $similarity) {
         $article["force_catchup"] = true;
     }
     return $article;
 }
Exemple #21
0
 function write($pref_name, $value, $user_id = false, $strip_tags = true)
 {
     $pref_name = db_escape_string($pref_name);
     $value = db_escape_string($value, $strip_tags);
     if (!$user_id) {
         $user_id = $_SESSION["uid"];
         @($profile = $_SESSION["profile"]);
     } else {
         $user_id = sprintf("%d", $user_id);
         $prefs_cache = false;
     }
     if ($profile) {
         $profile_qpart = "AND profile = '{$profile}'";
     } else {
         $profile_qpart = "AND profile IS NULL";
     }
     if (get_schema_version() < 63) {
         $profile_qpart = "";
     }
     $type_name = "";
     $current_value = "";
     if (isset($this->cache[$pref_name])) {
         $type_name = $this->cache[$pref_name]["type"];
         $current_value = $this->cache[$pref_name]["value"];
     }
     if (!$type_name) {
         $result = db_query("SELECT type_name\n                FROM ttrss_prefs,ttrss_prefs_types\n                WHERE pref_name = '{$pref_name}' AND type_id = ttrss_prefs_types.id");
         if (db_num_rows($result) > 0) {
             $type_name = db_fetch_result($result, 0, "type_name");
         }
     } elseif ($current_value == $value) {
         return;
     }
     if ($type_name) {
         if ($type_name == "bool") {
             if ($value == "1" || $value == "true") {
                 $value = "true";
             } else {
                 $value = "false";
             }
         } elseif ($type_name == "integer") {
             $value = sprintf("%d", $value);
         }
         if ($pref_name == 'USER_TIMEZONE' && $value == '') {
             $value = 'UTC';
         }
         db_query("UPDATE ttrss_user_prefs SET\n                value = '{$value}' WHERE pref_name = '{$pref_name}'\n                    {$profile_qpart}\n                    AND owner_uid = " . $_SESSION["uid"]);
         if ($user_id == $_SESSION["uid"]) {
             $this->cache[$pref_name]["type"] = $type_name;
             $this->cache[$pref_name]["value"] = $value;
         }
     }
 }
Exemple #22
0
            if ($v == $version + 1) {
                print "<p>" . T_sprintf("Updating to version %d...", $v) . "</p>";
                $fp = fopen($update_versions[$v], "r");
                if ($fp) {
                    while (!feof($fp)) {
                        $query = trim(getline($fp, ";"));
                        if ($query != "") {
                            print "<p class='query'>{$query}</p>";
                            db_query($link, $query);
                        }
                    }
                }
                fclose($fp);
                print "<p>" . __("Checking version... ");
                $result = db_query($link, "SELECT schema_version FROM ttirc_version");
                $version = db_fetch_result($result, 0, "schema_version");
                if ($version == $v) {
                    print __("OK!");
                } else {
                    print "<b>" . __("ERROR!") . "</b>";
                    return;
                }
                $num_updates++;
            }
        }
        print "<p>" . T_sprintf("Finished. Performed <b>%d</b> update(s) up to schema\n\t\t\tversion <b>%d</b>.", $num_updates, $version) . "</p>";
        print "<form method=\"GET\" action=\"logout.php\">\n\t\t\t<input type=\"submit\" value=\"" . __("Return to Tiny Tiny RSS") . "\">\n\t\t\t</form>";
    }
}
?>
Exemple #23
0
 private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view, $next_unread_feed, $offset, $vgr_last_feed = false, $override_order = false, $include_children = false)
 {
     $disable_cache = false;
     $reply = array();
     $timing_info = getmicrotime();
     $topmost_article_ids = array();
     if (!$offset) {
         $offset = 0;
     }
     if ($method == "undefined") {
         $method = "";
     }
     $method_split = explode(":", $method);
     if ($method == "ForceUpdate" && $feed && is_numeric($feed) > 0) {
         include "rssfuncs.php";
         update_rss_feed($this->link, $feed, true);
     }
     if ($method_split[0] == "MarkAllReadGR") {
         catchup_feed($this->link, $method_split[1], false);
     }
     // FIXME: might break tag display?
     if (is_numeric($feed) && $feed > 0 && !$cat_view) {
         $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE id = '{$feed}' LIMIT 1");
         if (db_num_rows($result) == 0) {
             $reply['content'] = "<div align='center'>" . __('Feed not found.') . "</div>";
         }
     }
     if (is_numeric($feed) && $feed > 0) {
         $result = db_query($this->link, "SELECT rtl_content FROM ttrss_feeds\r\n\t\t\t\tWHERE id = '{$feed}' AND owner_uid = " . $_SESSION["uid"]);
         if (db_num_rows($result) == 1) {
             $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
         } else {
             $rtl_content = false;
         }
         if ($rtl_content) {
             $rtl_tag = "dir=\"RTL\"";
         } else {
             $rtl_tag = "";
         }
     } else {
         $rtl_tag = "";
         $rtl_content = false;
     }
     @($search = db_escape_string($_REQUEST["query"]));
     if ($search) {
         $disable_cache = true;
     }
     @($search_mode = db_escape_string($_REQUEST["search_mode"]));
     @($match_on = db_escape_string($_REQUEST["match_on"]));
     if (!$match_on) {
         $match_on = "both";
     }
     if ($_REQUEST["debug"]) {
         $timing_info = print_checkpoint("H0", $timing_info);
     }
     //		error_log("format_headlines_list: [" . $feed . "] method [" . $method . "]");
     if ($search_mode == '' && $method != '') {
         $search_mode = $method;
     }
     //		error_log("search_mode: " . $search_mode);
     $qfh_ret = queryFeedHeadlines($this->link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on, $override_order, $offset, 0, false, 0, $include_children);
     if ($_REQUEST["debug"]) {
         $timing_info = print_checkpoint("H1", $timing_info);
     }
     $result = $qfh_ret[0];
     $feed_title = $qfh_ret[1];
     $feed_site_url = $qfh_ret[2];
     $last_error = $qfh_ret[3];
     $vgroup_last_feed = $vgr_last_feed;
     //		if (!$offset) {
     if (db_num_rows($result) > 0) {
         $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url, $feed_title, $feed, $cat_view, $search, $match_on, $search_mode, $view_mode, $last_error);
     }
     //		}
     $headlines_count = db_num_rows($result);
     if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
         $button_plugins = array();
         foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) {
             $pclass = trim("button_{$p}");
             if (class_exists($pclass)) {
                 $plugin = new $pclass($link);
                 array_push($button_plugins, $plugin);
             }
         }
     }
     if (db_num_rows($result) > 0) {
         $lnum = $offset;
         $num_unread = 0;
         $cur_feed_title = '';
         $fresh_intl = get_pref($this->link, "FRESH_ARTICLE_MAX_AGE") * 60 * 60;
         if ($_REQUEST["debug"]) {
             $timing_info = print_checkpoint("PS", $timing_info);
         }
         while ($line = db_fetch_assoc($result)) {
             $class = $lnum % 2 ? "even" : "odd";
             $id = $line["id"];
             $feed_id = $line["feed_id"];
             $label_cache = $line["label_cache"];
             $labels = false;
             if ($label_cache) {
                 $label_cache = json_decode($label_cache, true);
                 if ($label_cache) {
                     if ($label_cache["no-labels"] == 1) {
                         $labels = array();
                     } else {
                         $labels = $label_cache;
                     }
                 }
             }
             if (!is_array($labels)) {
                 $labels = get_article_labels($this->link, $id);
             }
             $labels_str = "<span id=\"HLLCTR-{$id}\">";
             $labels_str .= format_article_labels($labels, $id);
             $labels_str .= "</span>";
             if (count($topmost_article_ids) < 3) {
                 array_push($topmost_article_ids, $id);
             }
             if ($line["last_read"] == "" && !sql_bool_to_bool($line["unread"])) {
                 $update_pic = "<img id='FUPDPIC-{$id}' src=\"" . theme_image($this->link, 'images/updated.png') . "\"\r\n\t\t\t\t\t\talt=\"Updated\">";
             } else {
                 $update_pic = "<img id='FUPDPIC-{$id}' src=\"images/blank_icon.gif\"\r\n\t\t\t\t\t\talt=\"Updated\">";
             }
             if (sql_bool_to_bool($line["unread"]) && time() - strtotime($line["updated_noms"]) < $fresh_intl) {
                 $update_pic = "<img id='FUPDPIC-{$id}' src=\"" . theme_image($this->link, 'images/fresh_sign.png') . "\" alt=\"Fresh\">";
             }
             if ($line["unread"] == "t" || $line["unread"] == "1") {
                 $class .= " Unread";
                 ++$num_unread;
                 $is_unread = true;
             } else {
                 $is_unread = false;
             }
             if ($line["marked"] == "t" || $line["marked"] == "1") {
                 $marked_pic = "<img id=\"FMPIC-{$id}\"\r\n\t\t\t\t\t\tsrc=\"" . theme_image($this->link, 'images/mark_set.png') . "\"\r\n\t\t\t\t\t\tclass=\"markedPic\" alt=\"Unstar article\"\r\n\t\t\t\t\t\tonclick='javascript:toggleMark({$id})'>";
             } else {
                 $marked_pic = "<img id=\"FMPIC-{$id}\"\r\n\t\t\t\t\t\tsrc=\"" . theme_image($this->link, 'images/mark_unset.png') . "\"\r\n\t\t\t\t\t\tclass=\"markedPic\" alt=\"Star article\"\r\n\t\t\t\t\t\tonclick='javascript:toggleMark({$id})'>";
             }
             if ($line["published"] == "t" || $line["published"] == "1") {
                 $published_pic = "<img id=\"FPPIC-{$id}\" src=\"" . theme_image($this->link, 'images/pub_set.png') . "\"\r\n\t\t\t\t\t\tclass=\"markedPic\"\r\n\t\t\t\t\t\talt=\"Unpublish article\" onclick='javascript:togglePub({$id})'>";
             } else {
                 $published_pic = "<img id=\"FPPIC-{$id}\" src=\"" . theme_image($this->link, 'images/pub_unset.png') . "\"\r\n\t\t\t\t\t\tclass=\"markedPic\"\r\n\t\t\t\t\t\talt=\"Publish article\" onclick='javascript:togglePub({$id})'>";
             }
             #				$content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
             #					$line["title"] . "</a>";
             #				$content_link = "<a
             #					href=\"" . htmlspecialchars($line["link"]) . "\"
             #					onclick=\"view($id,$feed_id);\">" .
             #					$line["title"] . "</a>";
             #				$content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
             #					$line["title"] . "</a>";
             $updated_fmt = make_local_datetime($this->link, $line["updated_noms"], false);
             if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {
                 $content_preview = truncate_string(strip_tags($line["content_preview"]), 100);
             }
             $score = $line["score"];
             $score_pic = theme_image($this->link, "images/" . get_score_pic($score));
             /*				$score_title = __("(Click to change)");
             				$score_pic = "<img class='hlScorePic' src=\"images/$score_pic\"
             					onclick=\"adjustArticleScore($id, $score)\" title=\"$score $score_title\">"; */
             $score_pic = "<img class='hlScorePic' src=\"{$score_pic}\"\r\n\t\t\t\t\ttitle=\"{$score}\">";
             if ($score > 500) {
                 $hlc_suffix = "H";
             } else {
                 if ($score < -100) {
                     $hlc_suffix = "L";
                 } else {
                     $hlc_suffix = "";
                 }
             }
             $entry_author = $line["author"];
             if ($entry_author) {
                 $entry_author = " - {$entry_author}";
             }
             $has_feed_icon = feed_has_icon($feed_id);
             if ($has_feed_icon) {
                 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/{$feed_id}.ico\" alt=\"\">";
             } else {
                 $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/feed-icon-12x12.png\" alt=\"\">";
             }
             if (!get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
                 if (get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {
                     if ($feed_id != $vgroup_last_feed && $line["feed_title"]) {
                         $cur_feed_title = $line["feed_title"];
                         $vgroup_last_feed = $feed_id;
                         $cur_feed_title = htmlspecialchars($cur_feed_title);
                         $vf_catchup_link = "(<a onclick='catchupFeedInGroup({$feed_id});' href='#'>" . __('mark as read') . "</a>)";
                         $reply['content'] .= "<div class='cdmFeedTitle'>" . "<div style=\"float : right\">{$feed_icon_img}</div>" . "<a href=\"#\" onclick=\"viewfeed({$feed_id})\">" . $line["feed_title"] . "</a> {$vf_catchup_link}</div>";
                     }
                 }
                 $mouseover_attrs = "onmouseover='postMouseIn({$id})'\r\n\t\t\t\t\t\tonmouseout='postMouseOut({$id})'";
                 $reply['content'] .= "<div class='{$class}' id='RROW-{$id}' {$mouseover_attrs}>";
                 $reply['content'] .= "<div class='hlUpdPic'>{$update_pic}</div>";
                 $reply['content'] .= "<div class='hlLeft'>";
                 $reply['content'] .= "<input type=\"checkbox\" onclick=\"tSR(this)\"\r\n\t\t\t\t\t\t\tid=\"RCHK-{$id}\">";
                 $reply['content'] .= "{$marked_pic}";
                 $reply['content'] .= "{$published_pic}";
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "<div onclick='return hlClicked(event, {$id})'\r\n\t\t\t\t\t\tclass=\"hlTitle\"><span class='hlContent{$hlc_suffix}'>";
                 $reply['content'] .= "<a id=\"RTITLE-{$id}\"\r\n\t\t\t\t\t\thref=\"" . htmlspecialchars($line["link"]) . "\"\r\n\t\t\t\t\t\tonclick=\"\">" . truncate_string($line["title"], 200);
                 if (get_pref($this->link, 'SHOW_CONTENT_PREVIEW')) {
                     if ($content_preview) {
                         $reply['content'] .= "<span class=\"contentPreview\"> - {$content_preview}</span>";
                     }
                 }
                 $reply['content'] .= "</a></span>";
                 $reply['content'] .= $labels_str;
                 if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') && defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
                     if (@$line["feed_title"]) {
                         $reply['content'] .= "<span class=\"hlFeed\">\r\n\t\t\t\t\t\t\t\t(<a href=\"#\" onclick=\"viewfeed({$feed_id})\">" . $line["feed_title"] . "</a>)\r\n\t\t\t\t\t\t\t</span>";
                     }
                 }
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "<span class=\"hlUpdated\">{$updated_fmt}</span>";
                 $reply['content'] .= "<div class=\"hlRight\">";
                 $reply['content'] .= $score_pic;
                 if ($line["feed_title"] && !get_pref($this->link, 'VFEED_GROUP_BY_FEED')) {
                     $reply['content'] .= "<span onclick=\"viewfeed({$feed_id})\"\r\n\t\t\t\t\t\t\tstyle=\"cursor : pointer\"\r\n\t\t\t\t\t\t\ttitle=\"" . htmlspecialchars($line['feed_title']) . "\">\r\n\t\t\t\t\t\t\t{$feed_icon_img}<span>";
                 }
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "</div>";
             } else {
                 if (get_pref($this->link, 'VFEED_GROUP_BY_FEED') && $line["feed_title"]) {
                     if ($feed_id != $vgroup_last_feed) {
                         $cur_feed_title = $line["feed_title"];
                         $vgroup_last_feed = $feed_id;
                         $cur_feed_title = htmlspecialchars($cur_feed_title);
                         $vf_catchup_link = "(<a onclick='javascript:catchupFeedInGroup({$feed_id});' href='#'>" . __('mark as read') . "</a>)";
                         $has_feed_icon = feed_has_icon($feed_id);
                         if ($has_feed_icon) {
                             $feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/{$feed_id}.ico\" alt=\"\">";
                         } else {
                             //$feed_icon_img = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\" alt=\"\">";
                         }
                         $reply['content'] .= "<div class='cdmFeedTitle'>" . "<div style=\"float : right\">{$feed_icon_img}</div>" . "<a href=\"#\" onclick=\"viewfeed({$feed_id})\">" . $line["feed_title"] . "</a> {$vf_catchup_link}</div>";
                     }
                 }
                 $expand_cdm = get_pref($this->link, 'CDM_EXPANDED');
                 $mouseover_attrs = "onmouseover='postMouseIn({$id})'\r\n\t\t\t\t\t\tonmouseout='postMouseOut({$id})'";
                 $reply['content'] .= "<div class=\"{$class}\"\r\n\t\t\t\t\t\tid=\"RROW-{$id}\" {$mouseover_attrs}'>";
                 $reply['content'] .= "<div class=\"cdmHeader\">";
                 $reply['content'] .= "<div>";
                 $reply['content'] .= "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,\r\n\t\t\t\t\t\t\t'RROW-{$id}')\" id=\"RCHK-{$id}\"/>";
                 $reply['content'] .= "{$marked_pic}";
                 $reply['content'] .= "{$published_pic}";
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "<div id=\"PTITLE-FULL-{$id}\" style=\"display : none\">" . strip_tags($line['title']) . "</div>";
                 $reply['content'] .= "<span id=\"RTITLE-{$id}\"\r\n\t\t\t\t\t\tonclick=\"return cdmClicked(event, {$id});\"\r\n\t\t\t\t\t\tclass=\"titleWrap{$hlc_suffix}\">\r\n\t\t\t\t\t\t<a class=\"title\"\r\n\t\t\t\t\t\ttitle=\"" . htmlspecialchars($line['title']) . "\"\r\n\t\t\t\t\t\ttarget=\"_blank\" href=\"" . htmlspecialchars($line["link"]) . "\">" . truncate_string($line["title"], 100) . " {$entry_author}</a>";
                 $reply['content'] .= $labels_str;
                 if (!get_pref($this->link, 'VFEED_GROUP_BY_FEED') && defined('_SHOW_FEED_TITLE_IN_VFEEDS')) {
                     if (@$line["feed_title"]) {
                         $reply['content'] .= "<span class=\"hlFeed\">\r\n\t\t\t\t\t\t\t\t(<a href=\"#\" onclick=\"viewfeed({$feed_id})\">" . $line["feed_title"] . "</a>)\r\n\t\t\t\t\t\t\t</span>";
                     }
                 }
                 if (!$expand_cdm) {
                     $content_hidden = "style=\"display : none\"";
                 } else {
                     $excerpt_hidden = "style=\"display : none\"";
                 }
                 $reply['content'] .= "<span {$excerpt_hidden}\r\n\t\t\t\t\t\tid=\"CEXC-{$id}\" class=\"cdmExcerpt\"> - {$content_preview}</span>";
                 $reply['content'] .= "</span>";
                 $reply['content'] .= "<div>";
                 $reply['content'] .= "<span class='updated'>{$updated_fmt}</span>";
                 $reply['content'] .= "{$score_pic}";
                 if (!get_pref($this->link, "VFEED_GROUP_BY_FEED") && $line["feed_title"]) {
                     $reply['content'] .= "<span style=\"cursor : pointer\"\r\n\t\t\t\t\t\t\ttitle=\"" . htmlspecialchars($line["feed_title"]) . "\"\r\n\t\t\t\t\t\t\tonclick=\"viewfeed({$feed_id})\">{$feed_icon_img}</span>";
                 }
                 $reply['content'] .= "<div class=\"updPic\">{$update_pic}</div>";
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "<div class=\"cdmContent\" {$content_hidden}\r\n\t\t\t\t\t\tonclick=\"return cdmClicked(event, {$id});\"\r\n\t\t\t\t\t\tid=\"CICD-{$id}\">";
                 $reply['content'] .= "<div class=\"cdmContentInner\">";
                 if ($line["orig_feed_id"]) {
                     $tmp_result = db_query($this->link, "SELECT * FROM ttrss_archived_feeds\r\n\t\t\t\t\tWHERE id = " . $line["orig_feed_id"]);
                     if (db_num_rows($tmp_result) != 0) {
                         $reply['content'] .= "<div clear='both'>";
                         $reply['content'] .= __("Originally from:");
                         $reply['content'] .= "&nbsp;";
                         $tmp_line = db_fetch_assoc($tmp_result);
                         $reply['content'] .= "<a target='_blank'\r\n\t\t\t\t\t\t\t\thref=' " . htmlspecialchars($tmp_line['site_url']) . "'>" . $tmp_line['title'] . "</a>";
                         $reply['content'] .= "&nbsp;";
                         $reply['content'] .= "<a target='_blank' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
                         $reply['content'] .= "<img title='" . __('Feed URL') . "'class='tinyFeedIcon' src='images/pub_set.png'></a>";
                         $reply['content'] .= "</div>";
                     }
                 }
                 $feed_site_url = $line["site_url"];
                 $article_content = sanitize($this->link, $line["content_preview"], false, false, $feed_site_url);
                 $reply['content'] .= "<div id=\"POSTNOTE-{$id}\">";
                 if ($line['note']) {
                     $reply['content'] .= format_article_note($id, $line['note']);
                 }
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "<span id=\"CWRAP-{$id}\">";
                 $reply['content'] .= $expand_cdm ? $article_content : '';
                 $reply['content'] .= "</span>";
                 /*					$tmp_result = db_query($this->link, "SELECT always_display_enclosures FROM
                 						ttrss_feeds WHERE id = ".
                 						(($line['feed_id'] == null) ? $line['orig_feed_id'] :
                 							$line['feed_id'])." AND owner_uid = ".$_SESSION["uid"]);
                 
                 					$always_display_enclosures = sql_bool_to_bool(db_fetch_result($tmp_result,
                 						0, "always_display_enclosures")); */
                 $always_display_enclosures = sql_bool_to_bool($line["always_display_enclosures"]);
                 $reply['content'] .= format_article_enclosures($this->link, $id, $always_display_enclosures, $article_content);
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "<div class=\"cdmFooter\">";
                 $tag_cache = $line["tag_cache"];
                 $tags_str = format_tags_string(get_article_tags($this->link, $id, $_SESSION["uid"], $tag_cache), $id);
                 $reply['content'] .= "<img src='" . theme_image($this->link, 'images/tag.png') . "' alt='Tags' title='Tags'>\r\n\t\t\t\t\t\t<span id=\"ATSTR-{$id}\">{$tags_str}</span>\r\n\t\t\t\t\t\t<a title=\"" . __('Edit tags for this article') . "\"\r\n\t\t\t\t\t\thref=\"#\" onclick=\"editArticleTags({$id}, {$feed_id}, true)\">(+)</a>";
                 $num_comments = $line["num_comments"];
                 $entry_comments = "";
                 if ($num_comments > 0) {
                     if ($line["comments"]) {
                         $comments_url = $line["comments"];
                     } else {
                         $comments_url = $line["link"];
                     }
                     $entry_comments = "<a target='_blank' href=\"{$comments_url}\">{$num_comments} comments</a>";
                 } else {
                     if ($line["comments"] && $line["link"] != $line["comments"]) {
                         $entry_comments = "<a target='_blank' href=\"" . $line["comments"] . "\">comments</a>";
                     }
                 }
                 if ($entry_comments) {
                     $reply['content'] .= "&nbsp;({$entry_comments})";
                 }
                 $reply['content'] .= "<div style=\"float : right\">";
                 $reply['content'] .= "<img src=\"images/art-zoom.png\"\r\n\t\t\t\t\t\tonclick=\"zoomToArticle(event, {$id})\"\r\n\t\t\t\t\t\tstyle=\"cursor : pointer\"\r\n\t\t\t\t\t\talt='Zoom'\r\n\t\t\t\t\t\ttitle='" . __('Open article in new tab') . "'>";
                 //$note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);
                 foreach ($button_plugins as $p) {
                     $reply['content'] .= $p->render($id, $line);
                 }
                 $reply['content'] .= "<img src=\"images/digest_checkbox.png\"\r\n\t\t\t\t\t\tstyle=\"cursor : pointer\" style=\"cursor : pointer\"\r\n\t\t\t\t\t\tonclick=\"dismissArticle({$id})\"\r\n\t\t\t\t\t\ttitle='" . __('Close article') . "'>";
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "</div>";
                 $reply['content'] .= "</div>";
             }
             ++$lnum;
         }
         if ($_REQUEST["debug"]) {
             $timing_info = print_checkpoint("PE", $timing_info);
         }
     } else {
         $message = "";
         switch ($view_mode) {
             case "unread":
                 $message = __("No unread articles found to display.");
                 break;
             case "updated":
                 $message = __("No updated articles found to display.");
                 break;
             case "marked":
                 $message = __("No starred articles found to display.");
                 break;
             default:
                 if ($feed < -10) {
                     $message = __("No articles found to display. You can assign articles to labels manually (see the Actions menu above) or use a filter.");
                 } else {
                     $message = __("No articles found to display.");
                 }
         }
         if (!$offset && $message) {
             $reply['content'] .= "<div class='whiteBox'>{$message}";
             $reply['content'] .= "<p class=\"small\"><span class=\"insensitive\">";
             $result = db_query($this->link, "SELECT " . SUBSTRING_FOR_DATE . "(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds\r\n\t\t\t\t\tWHERE owner_uid = " . $_SESSION['uid']);
             $last_updated = db_fetch_result($result, 0, "last_updated");
             $last_updated = make_local_datetime($this->link, $last_updated, false);
             $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated);
             $result = db_query($this->link, "SELECT COUNT(id) AS num_errors\r\n\t\t\t\t\tFROM ttrss_feeds WHERE last_error != '' AND owner_uid = " . $_SESSION["uid"]);
             $num_errors = db_fetch_result($result, 0, "num_errors");
             if ($num_errors > 0) {
                 $reply['content'] .= "<br/>";
                 $reply['content'] .= "<a class=\"insensitive\" href=\"#\" onclick=\"showFeedsWithErrors()\">" . __('Some feeds have update errors (click for details)') . "</a>";
             }
             $reply['content'] .= "</span></p></div>";
         }
     }
     if ($_REQUEST["debug"]) {
         $timing_info = print_checkpoint("H2", $timing_info);
     }
     return array($topmost_article_ids, $headlines_count, $feed, $disable_cache, $vgroup_last_feed, $reply);
 }
function getFeedCategory($link, $feed)
{
    $result = db_query($link, "SELECT cat_id FROM ttrss_feeds\n\t\t\tWHERE id = '{$feed}'");
    if (db_num_rows($result) > 0) {
        return db_fetch_result($result, 0, "cat_id");
    } else {
        return false;
    }
}
Exemple #25
0
 static function api_get_headlines($feed_id, $limit, $offset, $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order, $include_attachments, $since_id, $search = "", $include_nested = false, $sanitize_content = true, $force_update = false, $excerpt_length = 100, $check_first_id = false)
 {
     if ($force_update && $feed_id > 0 && is_numeric($feed_id)) {
         // Update the feed if required with some basic flood control
         $result = db_query("SELECT cache_images," . SUBSTRING_FOR_DATE . "(last_updated,1,19) AS last_updated\n\t\t\t\t\t\tFROM ttrss_feeds WHERE id = '{$feed_id}'");
         if (db_num_rows($result) != 0) {
             $last_updated = strtotime(db_fetch_result($result, 0, "last_updated"));
             $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
             if (!$cache_images && time() - $last_updated > 120) {
                 include "rssfuncs.php";
                 update_rss_feed($feed_id, true, true);
             } else {
                 db_query("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01'\n\t\t\t\t\t\t\tWHERE id = '{$feed_id}'");
             }
         }
     }
     /*$qfh_ret = queryFeedHeadlines($feed_id, $limit,
     		$view_mode, $is_cat, $search, false,
     		$order, $offset, 0, false, $since_id, $include_nested);*/
     //function queryFeedHeadlines($feed, $limit,
     // $view_mode, $cat_view, $search, $search_mode,
     // $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false,
     // $ignore_vfeed_group = false, $override_strategy = false, $override_vfeed = false, $start_ts = false, $check_top_id = false) {
     $params = array("feed" => $feed_id, "limit" => $limit, "view_mode" => $view_mode, "cat_view" => $is_cat, "search" => $search, "override_order" => $order, "offset" => $offset, "since_id" => $since_id, "include_children" => $include_nested, "check_first_id" => $check_first_id, "api_request" => true);
     $qfh_ret = queryFeedHeadlines($params);
     $result = $qfh_ret[0];
     $feed_title = $qfh_ret[1];
     $first_id = $qfh_ret[6];
     $headlines = array();
     $headlines_header = array('id' => $feed_id, 'first_id' => $first_id, 'is_cat' => $is_cat);
     if (!is_numeric($result)) {
         while ($line = db_fetch_assoc($result)) {
             $line["content_preview"] = truncate_string(strip_tags($line["content"]), $excerpt_length);
             foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
                 $line = $p->hook_query_headlines($line, $excerpt_length, true);
             }
             $is_updated = $line["last_read"] == "" && ($line["unread"] != "t" && $line["unread"] != "1");
             $tags = explode(",", $line["tag_cache"]);
             $label_cache = $line["label_cache"];
             $labels = false;
             if ($label_cache) {
                 $label_cache = json_decode($label_cache, true);
                 if ($label_cache) {
                     if ($label_cache["no-labels"] == 1) {
                         $labels = array();
                     } else {
                         $labels = $label_cache;
                     }
                 }
             }
             if (!is_array($labels)) {
                 $labels = get_article_labels($line["id"]);
             }
             //if (!$tags) $tags = get_article_tags($line["id"]);
             //if (!$labels) $labels = get_article_labels($line["id"]);
             $headline_row = array("id" => (int) $line["id"], "unread" => sql_bool_to_bool($line["unread"]), "marked" => sql_bool_to_bool($line["marked"]), "published" => sql_bool_to_bool($line["published"]), "updated" => (int) strtotime($line["updated"]), "is_updated" => $is_updated, "title" => $line["title"], "link" => $line["link"], "feed_id" => $line["feed_id"], "tags" => $tags);
             if ($include_attachments) {
                 $headline_row['attachments'] = get_article_enclosures($line['id']);
             }
             if ($show_excerpt) {
                 $headline_row["excerpt"] = $line["content_preview"];
             }
             if ($show_content) {
                 if ($sanitize_content) {
                     $headline_row["content"] = sanitize($line["content"], sql_bool_to_bool($line['hide_images']), false, $line["site_url"], false, $line["id"]);
                 } else {
                     $headline_row["content"] = $line["content"];
                 }
             }
             // unify label output to ease parsing
             if ($labels["no-labels"] == 1) {
                 $labels = array();
             }
             $headline_row["labels"] = $labels;
             $headline_row["feed_title"] = $line["feed_title"] ? $line["feed_title"] : $feed_title;
             $headline_row["comments_count"] = (int) $line["num_comments"];
             $headline_row["comments_link"] = $line["comments"];
             $headline_row["always_display_attachments"] = sql_bool_to_bool($line["always_display_enclosures"]);
             $headline_row["author"] = $line["author"];
             $headline_row["score"] = (int) $line["score"];
             $headline_row["note"] = $line["note"];
             $headline_row["lang"] = $line["lang"];
             foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_API) as $p) {
                 $headline_row = $p->hook_render_article_api(array("headline" => $headline_row));
             }
             array_push($headlines, $headline_row);
         }
     } else {
         if (is_numeric($result) && $result == -1) {
             $headlines_header['first_id_changed'] = true;
         }
     }
     return array($headlines, $headlines_header);
 }
Exemple #26
0
 static function remove_feed($id, $owner_uid)
 {
     if ($id > 0) {
         /* save starred articles in Archived feed */
         db_query("BEGIN");
         /* prepare feed if necessary */
         $result = db_query("SELECT feed_url FROM ttrss_feeds WHERE id = {$id}\n\t\t\t\tAND owner_uid = {$owner_uid}");
         $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
         $result = db_query("SELECT id FROM ttrss_archived_feeds\n\t\t\t\tWHERE feed_url = '{$feed_url}' AND owner_uid = {$owner_uid}");
         if (db_num_rows($result) == 0) {
             $result = db_query("SELECT MAX(id) AS id FROM ttrss_archived_feeds");
             $new_feed_id = (int) db_fetch_result($result, 0, "id") + 1;
             db_query("INSERT INTO ttrss_archived_feeds\n\t\t\t\t\t(id, owner_uid, title, feed_url, site_url)\n\t\t\t\tSELECT {$new_feed_id}, owner_uid, title, feed_url, site_url from ttrss_feeds\n\t\t\t\tWHERE id = '{$id}'");
             $archive_id = $new_feed_id;
         } else {
             $archive_id = db_fetch_result($result, 0, "id");
         }
         db_query("UPDATE ttrss_user_entries SET feed_id = NULL,\n\t\t\t\torig_feed_id = '{$archive_id}' WHERE feed_id = '{$id}' AND\n\t\t\t\t\tmarked = true AND owner_uid = {$owner_uid}");
         /* Remove access key for the feed */
         db_query("DELETE FROM ttrss_access_keys WHERE\n\t\t\t\tfeed_id = '{$id}' AND owner_uid = {$owner_uid}");
         /* remove the feed */
         db_query("DELETE FROM ttrss_feeds\n\t\t\t\t\tWHERE id = '{$id}' AND owner_uid = {$owner_uid}");
         db_query("COMMIT");
         if (file_exists(ICONS_DIR . "/{$id}.ico")) {
             unlink(ICONS_DIR . "/{$id}.ico");
         }
         ccache_remove($id, $owner_uid);
     } else {
         label_remove(feed_to_label_id($id), $owner_uid);
         //ccache_remove($id, $owner_uid); don't think labels are cached
     }
 }
Exemple #27
0
function render_categories_list($link)
{
    $owner_uid = $_SESSION["uid"];
    print '<ul id="home" title="' . __('Home') . '" selected="true"
			myBackLabel="' . __('Logout') . '" myBackHref="logout.php" myBackTarget="_self">';
    //		print "<li><a href='#searchForm'>Search...</a></li>";
    foreach (array(-1, -2) as $id) {
        $title = getCategoryTitle($link, $id);
        $unread = getFeedUnread($link, $id, true);
        if ($unread > 0) {
            $title = $title . " ({$unread})";
            $class = '';
        } else {
            $class = 'oldItem';
        }
        print "<li class='{$class}'><a href='cat.php?id={$id}'>{$title}</a></li>";
    }
    $result = db_query($link, "SELECT \n\t\t\t\tttrss_feed_categories.id, \n\t\t\t\tttrss_feed_categories.title, \n\t\t\t\tCOUNT(ttrss_feeds.id) AS num_feeds \n\t\t\tFROM ttrss_feed_categories, ttrss_feeds\n\t\t\tWHERE ttrss_feed_categories.owner_uid = {$owner_uid} \n\t\t\t\tAND ttrss_feed_categories.id = cat_id\t\n\t\t\t\tGROUP BY ttrss_feed_categories.id, \n\t\t\t\t\tttrss_feed_categories.title\n\t\t\t\tORDER BY ttrss_feed_categories.title");
    while ($line = db_fetch_assoc($result)) {
        if ($line["num_feeds"] > 0) {
            $unread = getFeedUnread($link, $line["id"], true);
            $id = $line["id"];
            if ($unread > 0) {
                $line["title"] = $line["title"] . " ({$unread})";
                $class = '';
            } else {
                $class = 'oldItem';
            }
            if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
                print "<li class='{$class}'><a href='cat.php?id={$id}'>" . $line["title"] . "</a></li>";
            }
        }
    }
    $result = db_query($link, "SELECT COUNT(*) AS nf FROM ttrss_feeds WHERE\n\t\t\tcat_id IS NULL and owner_uid = '{$owner_uid}'");
    $num_feeds = db_fetch_result($result, 0, "nf");
    if ($num_feeds > 0) {
        $unread = getFeedUnread($link, 0, true);
        $title = "Uncategorized";
        if ($unread > 0) {
            $title = "{$title} ({$unread})";
            $class = '';
        } else {
            $class = 'oldItem';
        }
        if ($unread > 0 || !mobile_get_pref($link, "HIDE_READ")) {
            print "<li class='{$class}'><a href='cat.php?id=0'>{$title}</a></li>";
        }
    }
    print "</ul>";
}
Exemple #28
0
 function batchAddFeeds()
 {
     $cat_id = db_escape_string($_REQUEST['cat']);
     $feeds = explode("\n", db_escape_string($_REQUEST['feeds']));
     $login = db_escape_string($_REQUEST['login']);
     $pass = db_escape_string($_REQUEST['pass']);
     $need_auth = db_escape_string($_REQUEST['need_auth']) != "";
     $result = db_query($this->link, "SELECT twitter_oauth FROM ttrss_users\nWHERE id = " . $_SESSION['uid']);
     $has_oauth = db_fetch_result($result, 0, 'twitter_oauth') != "";
     foreach ($feeds as $feed) {
         $feed = trim($feed);
         if (validate_feed_url($feed)) {
             db_query($this->link, "BEGIN");
             if (!$need_auth || !$has_oauth || strpos($url, '://api.twitter.com') === false) {
                 $update_method = 0;
             } else {
                 $update_method = 3;
             }
             if ($cat_id == "0" || !$cat_id) {
                 $cat_qpart = "NULL";
             } else {
                 $cat_qpart = "'{$cat_id}'";
             }
             $result = db_query($this->link, "SELECT id FROM ttrss_feeds\n\t\t\t\t\tWHERE feed_url = '{$feed}' AND owner_uid = " . $_SESSION["uid"]);
             if (db_num_rows($result) == 0) {
                 $result = db_query($this->link, "INSERT INTO ttrss_feeds\n\t\t\t\t\t\t\t(owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method)\n\t\t\t\t\t\tVALUES ('" . $_SESSION["uid"] . "', '{$feed}',\n\t\t\t\t\t\t\t'[Unknown]', {$cat_qpart}, '{$login}', '{$pass}', '{$update_method}')");
             }
             db_query($this->link, "COMMIT");
         }
     }
 }
Exemple #29
0
 private function opml_import_filter($doc, $node, $owner_uid)
 {
     $attrs = $node->attributes;
     $filter_type = db_escape_string($attrs->getNamedItem('filter-type')->nodeValue);
     if ($filter_type == '2') {
         $filter = json_decode($node->nodeValue, true);
         if ($filter) {
             $match_any_rule = bool_to_sql_bool($filter["match_any_rule"]);
             $enabled = bool_to_sql_bool($filter["enabled"]);
             db_query($this->link, "BEGIN");
             db_query($this->link, "INSERT INTO ttrss_filters2 (match_any_rule,enabled,owner_uid)\n\t\t\t\t\tVALUES ({$match_any_rule}, {$enabled}," . $_SESSION["uid"] . ")");
             $result = db_query($this->link, "SELECT MAX(id) AS id FROM ttrss_filters2 WHERE\n\t\t\t\t\towner_uid = " . $_SESSION["uid"]);
             $filter_id = db_fetch_result($result, 0, "id");
             if ($filter_id) {
                 $this->opml_notice(T_sprintf("Adding filter..."));
                 foreach ($filter["rules"] as $rule) {
                     $feed_id = "NULL";
                     $cat_id = "NULL";
                     if (!$rule["cat_filter"]) {
                         $tmp_result = db_query($this->link, "SELECT id FROM ttrss_feeds\n\t\t\t\t\t\t\t\tWHERE title = '" . db_escape_string($rule["feed"]) . "' AND owner_uid = " . $_SESSION["uid"]);
                         if (db_num_rows($tmp_result) > 0) {
                             $feed_id = db_fetch_result($tmp_result, 0, "id");
                         }
                     } else {
                         $tmp_result = db_query($this->link, "SELECT id FROM ttrss_feed_categories\n\t\t\t\t\t\t\t\tWHERE title = '" . db_escape_string($rule["feed"]) . "' AND owner_uid = " . $_SESSION["uid"]);
                         if (db_num_rows($tmp_result) > 0) {
                             $cat_id = db_fetch_result($tmp_result, 0, "id");
                         }
                     }
                     $cat_filter = bool_to_sql_bool($rule["cat_filter"]);
                     $reg_exp = db_escape_string($rule["reg_exp"]);
                     $filter_type = (int) $rule["filter_type"];
                     db_query($this->link, "INSERT INTO ttrss_filters2_rules (feed_id,cat_id,filter_id,filter_type,reg_exp,cat_filter)\n\t\t\t\t\t\t\tVALUES ({$feed_id}, {$cat_id}, {$filter_id}, {$filter_type}, '{$reg_exp}', {$cat_filter})");
                 }
                 foreach ($filter["actions"] as $action) {
                     $action_id = (int) $action["action_id"];
                     $action_param = db_escape_string($action["action_param"]);
                     db_query($this->link, "INSERT INTO ttrss_filters2_actions (filter_id,action_id,action_param)\n\t\t\t\t\t\t\tVALUES ({$filter_id}, {$action_id}, '{$action_param}')");
                 }
             }
             db_query($this->link, "COMMIT");
         }
     }
 }
function module_pref_prefs($link)
{
    global $access_level_names;
    $subop = $_REQUEST["subop"];
    $prefs_blacklist = array("HIDE_FEEDLIST", "SYNC_COUNTERS", "ENABLE_LABELS", "ENABLE_SEARCH_TOOLBAR", "HIDE_READ_FEEDS");
    $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS", "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP", "BLACKLISTED_TAGS", "ENABLE_FEED_ICONS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE", "DEFAULT_UPDATE_INTERVAL", "MARK_UNREAD_ON_UPDATE");
    if (FORCE_ARTICLE_PURGE != 0) {
        array_push($prefs_blacklist, "PURGE_OLD_DAYS");
        array_push($prefs_blacklist, "PURGE_UNREAD_ARTICLES");
    }
    if ($subop == "change-password") {
        $old_pw = $_POST["OLD_PASSWORD"];
        $new_pw = $_POST["NEW_PASSWORD"];
        $con_pw = $_POST["CONFIRM_PASSWORD"];
        if ($old_pw == "") {
            print "ERROR: " . __("Old password cannot be blank.");
            return;
        }
        if ($new_pw == "") {
            print "ERROR: " . __("New password cannot be blank.");
            return;
        }
        if ($new_pw != $con_pw) {
            print "ERROR: " . __("Entered passwords do not match.");
            return;
        }
        $old_pw_hash1 = encrypt_password($_POST["OLD_PASSWORD"]);
        $old_pw_hash2 = encrypt_password($_POST["OLD_PASSWORD"], $_SESSION["name"]);
        $new_pw_hash = encrypt_password($_POST["NEW_PASSWORD"], $_SESSION["name"]);
        $active_uid = $_SESSION["uid"];
        if ($old_pw && $new_pw) {
            $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
            $result = db_query($link, "SELECT id FROM ttrss_users WHERE \n\t\t\t\t\tid = '{$active_uid}' AND (pwd_hash = '{$old_pw_hash1}' OR \n\t\t\t\t\t\tpwd_hash = '{$old_pw_hash2}')");
            if (db_num_rows($result) == 1) {
                db_query($link, "UPDATE ttrss_users SET pwd_hash = '{$new_pw_hash}' \n\t\t\t\t\t\tWHERE id = '{$active_uid}'");
                $_SESSION["pwd_hash"] = $new_pw_hash;
                print __("Password has been changed.");
            } else {
                print "ERROR: " . __('Old password is incorrect.');
            }
        }
        return;
    } else {
        if ($subop == "save-config") {
            #			$_SESSION["prefs_op_result"] = "save-config";
            $_SESSION["prefs_cache"] = false;
            //			print_r($_POST);
            $orig_theme = get_pref($link, "_THEME_ID");
            foreach (array_keys($_POST) as $pref_name) {
                $pref_name = db_escape_string($pref_name);
                $value = db_escape_string($_POST[$pref_name]);
                set_pref($link, $pref_name, $value);
            }
            if ($orig_theme != get_pref($link, "_THEME_ID")) {
                print "PREFS_THEME_CHANGED";
            } else {
                print __("The configuration was saved.");
            }
            return;
        } else {
            if ($subop == "getHelp") {
                $pref_name = db_escape_string($_REQUEST["pn"]);
                $result = db_query($link, "SELECT help_text FROM ttrss_prefs\n\t\t\t\tWHERE pref_name = '{$pref_name}'");
                if (db_num_rows($result) > 0) {
                    $help_text = db_fetch_result($result, 0, "help_text");
                    print $help_text;
                } else {
                    printf(__("Unknown option: %s"), $pref_name);
                }
            } else {
                if ($subop == "change-email") {
                    $email = db_escape_string($_POST["email"]);
                    $active_uid = $_SESSION["uid"];
                    db_query($link, "UPDATE ttrss_users SET email = '{$email}' \n\t\t\t\tWHERE id = '{$active_uid}'");
                    print __("E-mail has been changed.");
                    return;
                } else {
                    if ($subop == "reset-config") {
                        $_SESSION["prefs_op_result"] = "reset-to-defaults";
                        if ($_SESSION["profile"]) {
                            $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
                        } else {
                            $profile_qpart = "profile IS NULL";
                        }
                        db_query($link, "DELETE FROM ttrss_user_prefs \n\t\t\t\tWHERE {$profile_qpart} AND owner_uid = " . $_SESSION["uid"]);
                        initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
                        print "PREFS_THEME_CHANGED";
                        //			print __("The configuration was reset to defaults.");
                        return;
                    } else {
                        set_pref($link, "_PREFS_ACTIVE_TAB", "genConfig");
                        if ($_SESSION["profile"]) {
                            print_notice("Some preferences are only available in default profile.");
                        }
                        if (!SINGLE_USER_MODE) {
                            $result = db_query($link, "SELECT id FROM ttrss_users\n\t\t\t\t\tWHERE id = " . $_SESSION["uid"] . " AND pwd_hash \n\t\t\t\t\t= 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
                            if (db_num_rows($result) != 0) {
                                print format_warning(__("Your password is at default value, \n\t\t\t\t\t\tplease change it."), "default_pass_warning");
                            }
                            /*				if ($_SESSION["pwd_change_result"] == "failed") {
                            					print format_warning("Could not change the password.");
                            				}
                            
                            				if ($_SESSION["pwd_change_result"] == "ok") {
                            					print format_notice("Password was changed.");
                            				}
                            
                            				$_SESSION["pwd_change_result"] = ""; */
                            /*				if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
                            					print format_notice(__("The configuration was reset to defaults."));
                            } */
                            #				if ($_SESSION["prefs_op_result"] == "save-config") {
                            #					print format_notice(__("The configuration was saved."));
                            #				}
                            $_SESSION["prefs_op_result"] = "";
                            print "<form onsubmit='return false' id='change_email_form'>";
                            print "<table width=\"100%\" class=\"prefPrefsList\">";
                            print "<tr><td colspan='3'><h3>" . __("Personal data") . "</h3></tr></td>";
                            $result = db_query($link, "SELECT email,access_level FROM ttrss_users\n\t\t\t\t\tWHERE id = " . $_SESSION["uid"]);
                            $email = db_fetch_result($result, 0, "email");
                            print "<tr><td width=\"40%\">" . __('E-mail') . "</td>";
                            print "<td class=\"prefValue\"><input class=\"editbox\" name=\"email\" \n\t\t\t\t\tonfocus=\"javascript:disableHotkeys();\" \n\t\t\t\t\tonblur=\"javascript:enableHotkeys();\"\n\t\t\t\t\tonkeypress=\"return filterCR(event, changeUserEmail)\"\n\t\t\t\t\tvalue=\"{$email}\"></td></tr>";
                            if (!SINGLE_USER_MODE) {
                                $access_level = db_fetch_result($result, 0, "access_level");
                                print "<tr><td width=\"40%\">" . __('Access level') . "</td>";
                                print "<td>" . $access_level_names[$access_level] . "</td></tr>";
                            }
                            print "</table>";
                            print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
                            print "<input type=\"hidden\" name=\"subop\" value=\"change-email\">";
                            print "</form>";
                            print "<p><button onclick=\"return changeUserEmail()\">" . __("Change e-mail") . "</button>";
                            print "<form onsubmit=\"return false\" \n\t\t\t\t\tname=\"change_pass_form\" id=\"change_pass_form\">";
                            print "<table width=\"100%\" class=\"prefPrefsList\">";
                            print "<tr><td colspan='3'><h3>" . __("Authentication") . "</h3></tr></td>";
                            print "<tr><td width=\"40%\">" . __("Old password") . "</td>";
                            print "<td class=\"prefValue\"><input class=\"editbox\" type=\"password\"\n\t\t\t\t\tonfocus=\"javascript:disableHotkeys();\" \n\t\t\t\t\tonblur=\"javascript:enableHotkeys();\"\n\t\t\t\t\tonkeypress=\"return filterCR(event, changeUserPassword)\"\n\t\t\t\t\tname=\"OLD_PASSWORD\"></td></tr>";
                            print "<tr><td width=\"40%\">" . __("New password") . "</td>";
                            print "<td class=\"prefValue\"><input class=\"editbox\" type=\"password\"\n\t\t\t\t\tonfocus=\"javascript:disableHotkeys();\" \n\t\t\t\t\tonblur=\"javascript:enableHotkeys();\"\n\t\t\t\t\tonkeypress=\"return filterCR(event, changeUserPassword)\"\n\t\t\t\t\tname=\"NEW_PASSWORD\"></td></tr>";
                            print "<tr><td width=\"40%\">" . __("Confirm password") . "</td>";
                            print "<td class=\"prefValue\"><input class=\"editbox\" type=\"password\"\n\t\t\t\t\tonfocus=\"javascript:disableHotkeys();\" \n\t\t\t\t\tonblur=\"javascript:enableHotkeys();\"\n\t\t\t\t\tonkeypress=\"return filterCR(event, changeUserPassword)\"\n\t\t\t\t\tname=\"CONFIRM_PASSWORD\"></td></tr>";
                            print "</table>";
                            print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
                            print "<input type=\"hidden\" name=\"subop\" value=\"change-password\">";
                            print "</form>";
                            print "<p><button\tonclick=\"return changeUserPassword()\">" . __("Change password") . "</button>";
                        }
                        if ($_SESSION["profile"]) {
                            initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]);
                            $profile_qpart = "profile = '" . $_SESSION["profile"] . "'";
                        } else {
                            initialize_user_prefs($link, $_SESSION["uid"]);
                            $profile_qpart = "profile IS NULL";
                        }
                        $result = db_query($link, "SELECT \n\t\t\t\tttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,\n\t\t\t\tsection_name,def_value,section_id\n\t\t\t\tFROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs\n\t\t\t\tWHERE type_id = ttrss_prefs_types.id AND \n\t\t\t\t\t{$profile_qpart} AND\n\t\t\t\t\tsection_id = ttrss_prefs_sections.id AND\n\t\t\t\t\tttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND\n\t\t\t\t\tshort_desc != '' AND\n\t\t\t\t\towner_uid = " . $_SESSION["uid"] . "\n\t\t\t\tORDER BY section_id,short_desc");
                        print "<form onsubmit='return false' action=\"backend.php\" \n\t\t\t\tmethod=\"POST\" id=\"pref_prefs_form\">";
                        $lnum = 0;
                        $active_section = "";
                        while ($line = db_fetch_assoc($result)) {
                            if (in_array($line["pref_name"], $prefs_blacklist)) {
                                continue;
                            }
                            if ($_SESSION["profile"] && in_array($line["pref_name"], $profile_blacklist)) {
                                continue;
                            }
                            if ($active_section != $line["section_name"]) {
                                if ($active_section != "") {
                                    print "</table>";
                                }
                                print "<p><table width=\"100%\" class=\"prefPrefsList\">";
                                $active_section = $line["section_name"];
                                print "<tr><td colspan=\"3\"><h3>" . __($active_section) . "</h3></td></tr>";
                                if ($line["section_id"] == 2) {
                                    print "<tr><td width=\"40%\">" . __("Select theme") . "</td>";
                                    $user_theme = get_pref($link, "_THEME_ID");
                                    $themes = get_all_themes();
                                    print "<td><select name=\"_THEME_ID\">";
                                    print "<option value=''>" . __('Default') . "</option>";
                                    print "<option disabled>--------</option>";
                                    foreach ($themes as $t) {
                                        $base = $t['base'];
                                        $name = $t['name'];
                                        if ($base == $user_theme) {
                                            $selected = "selected=\"1\"";
                                        } else {
                                            $selected = "";
                                        }
                                        print "<option {$selected} value='{$base}'>{$name}</option>";
                                    }
                                    print "</select></td></tr>";
                                }
                                //					print "<tr class=\"title\">
                                //						<td width=\"25%\">Option</td><td>Value</td></tr>";
                                $lnum = 0;
                            }
                            //				$class = ($lnum % 2) ? "even" : "odd";
                            print "<tr>";
                            $type_name = $line["type_name"];
                            $pref_name = $line["pref_name"];
                            $value = $line["value"];
                            $def_value = $line["def_value"];
                            $help_text = $line["help_text"];
                            print "<td width=\"40%\" class=\"prefName\" id=\"{$pref_name}\">" . __($line["short_desc"]);
                            if ($help_text) {
                                print "<div class=\"prefHelp\">" . __($help_text) . "</div>";
                            }
                            print "</td>";
                            print "<td class=\"prefValue\">";
                            if ($pref_name == "DEFAULT_UPDATE_INTERVAL") {
                                global $update_intervals_nodefault;
                                print_select_hash($pref_name, $value, $update_intervals_nodefault);
                            } else {
                                if ($type_name == "bool") {
                                    //					print_select($pref_name, $value, array("true", "false"));
                                    if ($value == "true") {
                                        $value = __("Yes");
                                    } else {
                                        $value = __("No");
                                    }
                                    print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")));
                                } else {
                                    print "<input class=\"editbox\"\n\t\t\t\t\t\tonfocus=\"javascript:disableHotkeys();\" \n\t\t\t\t\t\tonblur=\"javascript:enableHotkeys();\"  \n\t\t\t\t\t\tname=\"{$pref_name}\" value=\"{$value}\">";
                                }
                            }
                            print "</td>";
                            print "</tr>";
                            $lnum++;
                        }
                        print "</table>";
                        print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
                        print "<p><button onclick=\"return validatePrefsSave()\">" . __('Save configuration') . "</button> ";
                        print "<button onclick=\"return editProfiles()\">" . __('Manage profiles') . "</button> ";
                        print "<button onclick=\"return validatePrefsReset()\">" . __('Reset to defaults') . "</button></p>";
                        print "</form>";
                    }
                }
            }
        }
    }
}