summaryrefslogtreecommitdiff
path: root/init.php
diff options
context:
space:
mode:
Diffstat (limited to 'init.php')
-rw-r--r--init.php200
1 files changed, 50 insertions, 150 deletions
diff --git a/init.php b/init.php
index d324bad..ed7c64b 100644
--- a/init.php
+++ b/init.php
@@ -1,6 +1,6 @@
<?php
-class Af_Feedmod extends Plugin implements IHandler
+class YAFPP extends Plugin implements IHandler
{
private $host;
@@ -8,9 +8,8 @@ class Af_Feedmod extends Plugin implements IHandler
{
return array(
1.0, // version
- 'Replace feed contents by contents from the linked page', // description
- 'mbirth', // author
- false, // is_system
+ 'Replace feed contents by contents from the linked page using full-text-rss', // description
+ 'schneefux' // author
);
}
@@ -23,8 +22,7 @@ class Af_Feedmod extends Plugin implements IHandler
{
$this->host = $host;
- $host->add_hook($host::HOOK_PREFS_TABS, $this);
-# only allowed for system plugins: $host->add_handler('pref-feedmod', '*', $this);
+ $host->add_hook($host::HOOK_PREFS_TAB, $this);
$host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
}
@@ -49,168 +47,70 @@ class Af_Feedmod extends Plugin implements IHandler
function hook_article_filter($article)
{
- global $fetch_last_content_type;
+ $ftr = $this->host->get($this, "ftr_url");
+ $url = trim($article['link']);
+ $request = $ftr.'makefulltextfeed.php?format=json&url='.urlencode($url);
- $json_conf = $this->host->get($this, 'json_conf');
- $owner_uid = $article['owner_uid'];
- $data = json_decode($json_conf, true);
+ if (version_compare(VERSION, '1.7.9', '>=')) {
+ $result = fetch_file_contents($request);
+ } else {
+ // fallback to file_get_contents()
+ $result = file_get_contents($request);
+ }
+ $result = json_decode($result, true);
+ $content = $result['rss']['channel']['item']['description'];
- if (!is_array($data)) {
- // no valid JSON or no configuration at all
- return $article;
+ if (!(strcmp($content, "[unable to retrieve full-text content]") == 0)) {
+ $article['title'] = $result['rss']['channel']['item']['title'];
+ $article['content'] = $content;
}
+ return $article;
+ }
- foreach ($data as $urlpart=>$config) {
- if (strpos($article['link'], $urlpart) === false) continue; // skip this config if URL not matching
- if (strpos($article['plugin_data'], "feedmod,$owner_uid:") !== false) {
- // do not process an article more than once
- if (isset($article['stored']['content'])) $article['content'] = $article['stored']['content'];
- break;
- }
-
- switch ($config['type']) {
- case 'xpath':
- $doc = new DOMDocument();
- $link = trim($article['link']);
-
- if (version_compare(VERSION, '1.7.9', '>=')) {
- $html = fetch_file_contents($link);
- $content_type = $fetch_last_content_type;
- } else {
- // fallback to file_get_contents()
- $html = file_get_contents($link);
-
- // try to fetch charset from HTTP headers
- $headers = $http_response_header;
- $content_type = false;
- foreach ($headers as $h) {
- if (substr(strtolower($h), 0, 13) == 'content-type:') {
- $content_type = substr($h, 14);
- // don't break here to find LATEST (if redirected) entry
- }
- }
- }
-
- $charset = false;
- if (!isset($config['force_charset'])) {
- if ($content_type) {
- preg_match('/charset=(\S+)/', $content_type, $matches);
- if (isset($matches[1]) && !empty($matches[1])) $charset = $matches[1];
- }
- } else {
- // use forced charset
- $charset = $config['force_charset'];
- }
-
- if ($charset && isset($config['force_unicode']) && $config['force_unicode']) {
- $html = iconv($charset, 'utf-8', $html);
- $charset = 'utf-8';
- }
-
- if ($charset) {
- $html = '<?xml encoding="' . $charset . '">' . $html;
- }
-
-
-
-
+ function hook_prefs_tab($args) {
+ if ($args != "prefPrefs") return;
- @$doc->loadHTML($html);
+ print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__("YAFPP: full-text-rss")."\">";
- if ($doc) {
- $basenode = false;
- $xpath = new DOMXPath($doc);
- $entries = $xpath->query('(//'.$config['xpath'].')'); // find main DIV according to config
+ print "<br/>";
- if ($entries->length > 0) $basenode = $entries->item(0);
+ $ftr_url = $this->host->get($this, "ftr_url");
+ print "<form dojoType=\"dijit.form.Form\">";
- if ($basenode) {
- // remove nodes from cleanup configuration
- if (isset($config['cleanup'])) {
- if (!is_array($config['cleanup'])) {
- $config['cleanup'] = array($config['cleanup']);
- }
- foreach ($config['cleanup'] as $cleanup) {
- $nodelist = $xpath->query('//'.$cleanup, $basenode);
- foreach ($nodelist as $node) {
- if ($node instanceof DOMAttr) {
- $node->ownerElement->removeAttributeNode($node);
- }
- else {
- $node->parentNode->removeChild($node);
- }
- }
+ print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
+ evt.preventDefault();
+ if (this.validate()) {
+ console.log(dojo.objectToQuery(this.getValues()));
+ new Ajax.Request('backend.php', {
+ parameters: dojo.objectToQuery(this.getValues()),
+ onComplete: function(transport) {
+ notify_info(transport.responseText);
}
- }
- $article['content'] = $doc->saveXML($basenode);
- $article['plugin_data'] = "feedmod,$owner_uid:" . $article['plugin_data'];
- }
- }
- break;
+ });
+ }
+ </script>";
- default:
- // unknown type or invalid config
- continue;
- }
+ 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=\"save\">";
+ print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"yafpp\">";
+ print "<table width=\"100%\" class=\"prefPrefsList\">";
+ print "<tr><td width=\"40%\">".__("URL to full-text-rss")."</td>";
+ print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\" name=\"ftr_url\" regExp='^(http|https)://.*' value=\"$ftr_url\"></td></tr>";
+ print "</table>";
+ print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".__("Save")."</button>";
- break; // if we got here, we found the correct entry in $data, do not process more
- }
+ print "</form>";
- return $article;
- }
+ print "</div>"; #pane
- function hook_prefs_tabs($args)
- {
- print '<div id="feedmodConfigTab" dojoType="dijit.layout.ContentPane"
- href="backend.php?op=af_feedmod"
- title="' . __('FeedMod') . '"></div>';
}
- function index()
- {
- $pluginhost = PluginHost::getInstance();
- $json_conf = $pluginhost->get($this, 'json_conf');
-
- print "<form dojoType=\"dijit.form.Form\">";
-
- print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
- evt.preventDefault();
- if (this.validate()) {
- new Ajax.Request('backend.php', {
- parameters: dojo.objectToQuery(this.getValues()),
- onComplete: function(transport) {
- if (transport.responseText.indexOf('error')>=0) notify_error(transport.responseText);
- else notify_info(transport.responseText);
- }
- });
- //this.reset();
- }
- </script>";
-
- 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=\"save\">";
- print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"af_feedmod\">";
-
- print "<table width='100%'><tr><td>";
- print "<textarea dojoType=\"dijit.form.SimpleTextarea\" name=\"json_conf\" style=\"font-size: 12px; width: 99%; height: 500px;\">$json_conf</textarea>";
- print "</td></tr></table>";
-
- print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".__("Save")."</button>";
-
- print "</form>";
- }
function save()
{
- $json_conf = $_POST['json_conf'];
-
- if (is_null(json_decode($json_conf))) {
- echo __("error: Invalid JSON!");
- return false;
- }
-
- $this->host->set($this, 'json_conf', $json_conf);
- echo __("Configuration saved.");
+ $ftr_url = db_escape_string($_POST["ftr_url"]);
+ $this->host->set($this, "ftr_url", $ftr_url);
+ echo __("YAFPP configuration saved.");
}
}