diff options
Diffstat (limited to 'plugins/af_readability/init.php')
-rwxr-xr-x | plugins/af_readability/init.php | 103 |
1 files changed, 63 insertions, 40 deletions
diff --git a/plugins/af_readability/init.php b/plugins/af_readability/init.php index c44ad89ef..8bb368389 100755 --- a/plugins/af_readability/init.php +++ b/plugins/af_readability/init.php @@ -38,24 +38,30 @@ class Af_Readability extends Plugin { $host->add_hook($host::HOOK_PREFS_EDIT_FEED, $this); $host->add_hook($host::HOOK_PREFS_SAVE_FEED, $this); + // Note: we have to install the hook even if disabled because init() is being run before plugin data has loaded + // so we can't check for our storage-set options here + $host->add_hook($host::HOOK_GET_FULL_TEXT, $this); + $host->add_filter_action($this, "action_inline", __("Inline content")); } function hook_prefs_tab($args) { if ($args != "prefFeeds") return; - print "<div dojoType=\"dijit.layout.AccordionPane\" + print "<div dojoType='dijit.layout.AccordionPane' title=\"<i class='material-icons'>extension</i> ".__('Readability settings (af_readability)')."\">"; if (version_compare(PHP_VERSION, '5.6.0', '<')) { print_error("This plugin requires PHP version 5.6."); - } + } else { + + print "<h2>" . __("Global settings") . "</h2>"; - print_notice("Enable the plugin for specific feeds in the feed editor."); + print_notice("Enable for specific feeds in the feed editor."); - print "<form dojoType=\"dijit.form.Form\">"; + print "<form dojoType='dijit.form.Form'>"; - print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> + print "<script type='dojo/method' event='onSubmit' args='evt'> evt.preventDefault(); if (this.validate()) { console.log(dojo.objectToQuery(this.getValues())); @@ -69,43 +75,48 @@ class Af_Readability extends Plugin { } </script>"; - print_hidden("op", "pluginhandler"); - print_hidden("method", "save"); - print_hidden("plugin", "af_readability"); + print_hidden("op", "pluginhandler"); + print_hidden("method", "save"); + print_hidden("plugin", "af_readability"); - $enable_share_anything = $this->host->get($this, "enable_share_anything"); + $enable_share_anything = $this->host->get($this, "enable_share_anything"); - print_checkbox("enable_share_anything", $enable_share_anything); - print " <label for=\"enable_share_anything\">" . __("Use Readability for pages shared via bookmarklet.") . "</label>"; + print "<fieldset>"; + print "<label class='checkbox'> "; + print_checkbox("enable_share_anything", $enable_share_anything); + print " " . __("Provide full-text services to core code (bookmarklets) and other plugins"); + print "</label>"; + print "</fieldset>"; - print "<p>"; print_button("submit", __("Save")); - print "</form>"; + print print_button("submit", __("Save"), "class='alt-primary'"); + print "</form>"; - $enabled_feeds = $this->host->get($this, "enabled_feeds"); - if (!is_array($enabled_feeds)) $enabled_feeds = array(); + $enabled_feeds = $this->host->get($this, "enabled_feeds"); + if (!is_array($enabled_feeds)) $enabled_feeds = array(); - $enabled_feeds = $this->filter_unknown_feeds($enabled_feeds); - $this->host->set($this, "enabled_feeds", $enabled_feeds); + $enabled_feeds = $this->filter_unknown_feeds($enabled_feeds); + $this->host->set($this, "enabled_feeds", $enabled_feeds); - if (count($enabled_feeds) > 0) { - print "<h3>" . __("Currently enabled for (click to edit):") . "</h3>"; + if (count($enabled_feeds) > 0) { + print "<h3>" . __("Currently enabled for (click to edit):") . "</h3>"; - print "<ul class='panel panel-scrollable list list-unstyled'>"; - foreach ($enabled_feeds as $f) { - print "<li>" . - "<i class='material-icons'>rss_feed</i> <a href='#' + print "<ul class='panel panel-scrollable list list-unstyled'>"; + foreach ($enabled_feeds as $f) { + print "<li><i class='material-icons'>rss_feed</i> <a href='#' onclick='CommonDialogs.editFeed($f)'>". - Feeds::getFeedTitle($f) . "</a></li>"; + Feeds::getFeedTitle($f) . "</a></li>"; + } + print "</ul>"; } - print "</ul>"; + } print "</div>"; } function hook_prefs_edit_feed($feed_id) { - print "<div class=\"dlgSec\">".__("Readability")."</div>"; - print "<div class=\"dlgSecCont\">"; + print "<header>".__("Readability")."</header>"; + print "<section>"; $enabled_feeds = $this->host->get($this, "enabled_feeds"); if (!is_array($enabled_feeds)) $enabled_feeds = array(); @@ -115,13 +126,12 @@ class Af_Readability extends Plugin { print "<fieldset>"; - print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"af_readability_enabled\" - name=\"af_readability_enabled\" - $checked> ".__('Inline article content')."</label>"; + print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' id='af_readability_enabled' + name='af_readability_enabled' $checked> ".__('Inline article content')."</label>"; print "</fieldset>"; - print "</div>"; + print "</section>"; } function hook_prefs_save_feed($feed_id) { @@ -163,17 +173,13 @@ class Af_Readability extends Plugin { if ($tmp && mb_strlen($tmp) < 1024 * 500) { $tmpdoc = new DOMDocument("1.0", "UTF-8"); - if (!$tmpdoc->loadHTML($tmp)) + if (!@$tmpdoc->loadHTML($tmp)) return false; + // this is the worst hack yet :( if (strtolower($tmpdoc->encoding) != 'utf-8') { - $tmpxpath = new DOMXPath($tmpdoc); - - foreach ($tmpxpath->query("//meta") as $elem) { - $elem->parentNode->removeChild($elem); - } - - $tmp = $tmpdoc->saveHTML(); + $tmp = preg_replace("/<meta.*?charset.*?\/>/i", "", $tmp); + $tmp = mb_convert_encoding($tmp, 'utf-8', $tmpdoc->encoding); } try { @@ -204,7 +210,6 @@ class Af_Readability extends Plugin { } catch (Exception $e) { return false; } - } return false; @@ -236,6 +241,24 @@ class Af_Readability extends Plugin { } + function hook_get_full_text($link) + { + $enable_share_anything = $this->host->get($this, "enable_share_anything"); + + if ($enable_share_anything) { + $extracted_content = $this->extract_content($link); + + # let's see if there's anything of value in there + $content_test = trim(strip_tags(sanitize($extracted_content))); + + if ($content_test) { + return $extracted_content; + } + } + + return false; + } + function api_version() { return 2; } |