From c3d7d830b4989c9ec4d56ec49b6b3ca3c44a9d20 Mon Sep 17 00:00:00 2001 From: schneefux Date: Tue, 2 Sep 2014 13:49:17 +0200 Subject: first commit --- init.php | 214 +++++++++++++++++---------------------------------------------- 1 file changed, 57 insertions(+), 157 deletions(-) (limited to 'init.php') diff --git a/init.php b/init.php index d324bad..ed7c64b 100644 --- a/init.php +++ b/init.php @@ -1,6 +1,6 @@ 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); + + 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 (!(strcmp($content, "[unable to retrieve full-text content]") == 0)) { + $article['title'] = $result['rss']['channel']['item']['title']; + $article['content'] = $content; + } + return $article; + } - $json_conf = $this->host->get($this, 'json_conf'); - $owner_uid = $article['owner_uid']; - $data = json_decode($json_conf, true); + function hook_prefs_tab($args) { + if ($args != "prefPrefs") return; - if (!is_array($data)) { - // no valid JSON or no configuration at all - return $article; - } + print "
"; - 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 = '' . $html; - } - - - - - - @$doc->loadHTML($html); - - if ($doc) { - $basenode = false; - $xpath = new DOMXPath($doc); - $entries = $xpath->query('(//'.$config['xpath'].')'); // find main DIV according to config - - if ($entries->length > 0) $basenode = $entries->item(0); - - 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 "
"; + + $ftr_url = $this->host->get($this, "ftr_url"); + print "
"; + + print ""; - return $article; - } + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print "
".__("URL to full-text-rss")."
"; + print "

"; - function hook_prefs_tabs($args) - { - print '

'; - } + print "
"; + + print "
"; #pane - function index() - { - $pluginhost = PluginHost::getInstance(); - $json_conf = $pluginhost->get($this, 'json_conf'); - - print "
"; - - print ""; - - print ""; - print ""; - print ""; - - print "
"; - print ""; - print "
"; - - print "

"; - - print "

"; } + 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."); } } -- cgit v1.3.1