]> git.wh0rd.org Git - tt-rss.git/commitdiff
Changes to add a new hook: HOOK_QUERY_HEADLINES. An example is provided.
authorjustauser <justausr@hotmail.com>
Thu, 27 Jun 2013 15:18:23 +0000 (11:18 -0400)
committerjustauser <justausr@hotmail.com>
Thu, 27 Jun 2013 15:18:23 +0000 (11:18 -0400)
classes/api.php
classes/feeds.php
classes/handler/public.php
classes/pluginhost.php
classes/pref/filters.php
include/functions.php
plugins/query_headlines/init.js [new file with mode: 0644]
plugins/query_headlines/init.php [new file with mode: 0644]

index 23866072fef5973371c2ba395690c25060ecda81..139a486ee6eccfca2d9c5d966352c68a69577b1d 100644 (file)
@@ -636,8 +636,13 @@ class API extends Handler {
                        $feed_title = $qfh_ret[1];
 
                        $headlines = array();
-
+                       
                        while ($line = db_fetch_assoc($result)) {
+                               
+                               foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
+                                       $line = $p->hook_query_headlines($line, 100, true);
+                               }
+                               
                                $is_updated = ($line["last_read"] == "" &&
                                        ($line["unread"] != "t" && $line["unread"] != "1"));
 
@@ -664,24 +669,27 @@ class API extends Handler {
                                                $headline_row['attachments'] = get_article_enclosures(
                                                        $line['id']);
 
-                               if ($show_excerpt) {
-                                       $excerpt = truncate_string(strip_tags($line["content_preview"]), 100);
+                               if ($show_excerpt ){
+                                       if(isset($line["modified_preview"])) 
+                                               $excerpt = strip_tags($line["content_preview"]);
+                                       else
+                                               $excerpt = truncate_string(strip_tags($line["content_preview"]), 100);
                                        $headline_row["excerpt"] = $excerpt;
                                }
 
                                if ($show_content) {
 
                                        if ($line["cached_content"] != "") {
-                                               $line["content_preview"] =& $line["cached_content"];
+                                               $line["content"] =& $line["cached_content"];
                                        }
 
                                        if ($sanitize_content) {
                                                $headline_row["content"] = sanitize(
-                                                       $line["content_preview"],
+                                                       $line["content"],
                                                        sql_bool_to_bool($line['hide_images']),
                                                        false, $line["site_url"]);
                                        } else {
-                                               $headline_row["content"] = $line["content_preview"];
+                                               $headline_row["content"] = $line["content"];
                                        }
                                }
 
@@ -699,6 +707,7 @@ class API extends Handler {
                                $headline_row["always_display_attachments"] = sql_bool_to_bool($line["always_display_enclosures"]);
 
                                $headline_row["author"] = $line["author"];
+                               
                                $headline_row["score"] = (int)$line["score"];
 
                                foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_API) as $p) {
index 83736925c8a7a58b75c45c0182567341e36e1b15..fd4c7fe533ea605f57f423baf05a48afd47b3a9b 100644 (file)
@@ -288,6 +288,9 @@ class Feeds extends Handler_Protected {
                        $expand_cdm = get_pref('CDM_EXPANDED');
 
                        while ($line = $this->dbh->fetch_assoc($result)) {
+                               foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
+                                       $line = $p->hook_query_headlines($line, 250);
+                               }
                                $id = $line["id"];
                                $feed_id = $line["feed_id"];
                                $label_cache = $line["label_cache"];
@@ -360,9 +363,12 @@ class Feeds extends Handler_Protected {
                                $date_entered_fmt = T_sprintf("Imported at %s",
                                        make_local_datetime($line["date_entered"], false));
 
-                               if (get_pref('SHOW_CONTENT_PREVIEW')) {
-                                       $content_preview = truncate_string(strip_tags($line["content_preview"]),
-                                               250);
+                               if (get_pref('SHOW_CONTENT_PREVIEW') ) {
+                                       if(isset($line["modified_preview"]))
+                                               $content_preview = strip_tags($line["content_preview"]);
+                                       else
+                                               $content_preview = truncate_string(strip_tags($line["content_preview"]),
+                                                       250);
                                }
 
                                $score = $line["score"];
@@ -502,7 +508,7 @@ class Feeds extends Handler_Protected {
                                        else
                                                $tags = false;
 
-                                       $line["content"] = sanitize($line["content_preview"],
+                                       $line["content"] = sanitize($line["content"],
                                                        sql_bool_to_bool($line['hide_images']), false, $entry_site_url);
 
                                        foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_CDM) as $p) {
@@ -575,7 +581,7 @@ class Feeds extends Handler_Protected {
                                                $excerpt_hidden = "style=\"display : none\"";
 
                                        $reply['content'] .= "<span $excerpt_hidden
-                                               id=\"CEXC-$id\" class=\"cdmExcerpt\"> - $content_preview</span>";
+                                               id=\"CEXC-$id\" class=\"cdmExcerpt\"> -" . $content_preview . "</span>";
                                        $reply['content'] .= "</span>";
 
                                        if (!get_pref('VFEED_GROUP_BY_FEED')) {
index f05beafd21f1783f37b804b28182cedee3269b67..825ea5e2e6a9ea705fb9a139ba3ef0ab7086d362 100644 (file)
@@ -87,14 +87,20 @@ class Handler_Public extends Handler {
                        $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
 
                        while ($line = $this->dbh->fetch_assoc($result)) {
+                               foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
+                                       $line = $p->hook_query_headlines($line);
+                               }
 
                                $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']), true);
                                $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
                                $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
-                               $tpl->setVariable('ARTICLE_EXCERPT',
-                                       truncate_string(strip_tags($line["content_preview"]), 100, '...'), true);
+                               if(isset($line["modified_preview"]))
+                                       $tpl->setVariable('ARTICLE_EXCERPT', strip_tags($line["content_preview"]), true);
+                               else
+                                       $tpl->setVariable('ARTICLE_EXCERPT',
+                                               truncate_string(strip_tags($line["content_preview"]), 100, '...'), true);
 
-                               $content = sanitize($line["content_preview"], false, $owner_uid);
+                               $content = sanitize($line["content"], false, $owner_uid);
 
                                if ($line['note']) {
                                        $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
@@ -164,13 +170,19 @@ class Handler_Public extends Handler {
                        $feed['articles'] = array();
 
                        while ($line = $this->dbh->fetch_assoc($result)) {
+                               foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
+                                       $line = $p->hook_query_headlines($line, 100);
+                               }
                                $article = array();
 
                                $article['id'] = $line['link'];
                                $article['link']        = $line['link'];
                                $article['title'] = $line['title'];
-                               $article['excerpt'] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
-                               $article['content'] = sanitize($line["content_preview"], false, $owner_uid);
+                               if(isset($line["modified_preview"]))
+                                       $article['excerpt'] = strip_tags($line["content_preview"]);
+                               else
+                                       $article['excerpt'] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
+                               $article['content'] = sanitize($line["content"], false, $owner_uid);
                                $article['updated'] = date('c', strtotime($line["updated"]));
 
                                if ($line['note']) $article['note'] = $line['note'];
index 53adf01f9ff8b098c32602c474c732ee37eb0061..a1bd1b36400a195c341e3399be5c7ba5fe8907fd 100644 (file)
@@ -37,6 +37,7 @@ class PluginHost {
        const HOOK_PREFS_EDIT_FEED = 20;
        const HOOK_PREFS_SAVE_FEED = 21;
        const HOOK_FETCH_FEED = 22;
+       const HOOK_QUERY_HEADLINES = 23;
 
        const KIND_ALL = 1;
        const KIND_SYSTEM = 2;
index bcc7b5aec424abbbf53a9447dc6fae386dbc3483..099c88252163a910fd7899214b7b4cfc4e55e798 100644 (file)
@@ -97,12 +97,17 @@ class Pref_Filters extends Handler_Protected {
                print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
 
                while ($line = $this->dbh->fetch_assoc($result)) {
+                       foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) {
+                                       $line = $p->hook_query_headlines($line, 100);
+                               }
 
                        $entry_timestamp = strtotime($line["updated"]);
                        $entry_tags = get_article_tags($line["id"], $_SESSION["uid"]);
 
-                       $content_preview = truncate_string(
-                               strip_tags($line["content_preview"]), 100, '...');
+                       if(isset($line["modified_preview"]))
+                               $content_preview = strip_tags($line["content_preview"]);
+                       else
+                               $content_preview = truncate_string(strip_tags($line["content_preview"]), 100, '...');
 
                        if ($line["feed_title"])
                                $feed_title = $line["feed_title"];
index 355eec2cd09fd16123a6c47e136d2b42f1583f3f..eb011b6db3c3d0b05a2ac3ecf360767fdd59abbe 100644 (file)
@@ -71,7 +71,6 @@
                                        "hu_HU" => "Magyar (Hungarian)",
                                        "it_IT" => "Italiano",
                                        "ja_JP" => "日本語 (Japanese)",
-                                       "ko_KR" => "한국어 (Korean)",
                                        "lv_LV" => "Latviešu",
                                        "nb_NO" => "Norwegian bokmål",
                                        "nl_NL" => "Dutch",
                                        $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 WEEK) ";
                                }
                                break;
-                       case "2week":
+                       case "2weeks":
                                if (DB_TYPE == "pgsql") {
                                        $date_qpart = "date_entered < NOW() - INTERVAL '2 week' ";
                                } else {
                                }
                        }
 
-                       $content_query_part = "content as content_preview, cached_content, ";
+                       $content_query_part = "content, content AS content_preview, cached_content, ";
 
                        if (is_numeric($feed)) {
 
 
                        if ($site_url) {
 
-                               if ($entry->hasAttribute('href')) {
+                               if ($entry->hasAttribute('href'))
                                        $entry->setAttribute('href',
                                                rewrite_relative_url($site_url, $entry->getAttribute('href')));
 
-                                       $entry->setAttribute('rel', 'noreferrer');
-                               }
-
                                if ($entry->hasAttribute('src')) {
                                        $src = rewrite_relative_url($site_url, $entry->getAttribute('src'));
 
diff --git a/plugins/query_headlines/init.js b/plugins/query_headlines/init.js
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/plugins/query_headlines/init.php b/plugins/query_headlines/init.php
new file mode 100644 (file)
index 0000000..2c8a402
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+class Query_Headlines extends Plugin {
+       // example of the use of the HOOK_QUERY_HEADLINES
+       // this example will change the author and tags to be empty string so they don't display
+       // the arguements are:
+       //      -        the array of elements that are returned by queryFeedHeadlines
+       //      -       the length that the caller wants to truncate the content preview to
+       //      -       a boolean that indicates if the caller is from an API call
+       //NOTE:****  You have to make this a system plugin if you want it to also work
+       //              on API calls.  If you just make it a user plugin it will work on web page output
+       //              but not on API calls
+       private $host;
+
+       function about() {
+               return array(1.0,
+                       "Example of use of HOOK_QUERY_HEADLINES",
+                       "justauser" );
+       }
+
+       function init($host) {
+               $this->host = $host;
+               $host->add_hook($host::HOOK_QUERY_HEADLINES, $this);
+       }
+
+       // passes in the array for an item
+       // second argument is the length of the preview the caller is using
+       // create a key called "modified_preview" if you change the preview and don't want
+       //              caller to override with their default
+
+       function hook_query_headlines($line, $preview_length = 100,$api_call=false) {
+               //make the author field empty
+               $line["author"] = "";
+               
+               // and toss tags, since I don't use
+               $line["tag_cache"] = "";
+               return $line;
+               
+               
+       }
+       
+
+       function api_version() {
+               return 2;
+       }
+
+}
+?>