function remove_link_tags($content) { $old_xml_err = libxml_use_internal_errors(true); $dom = new DOMDocument(); $dom->loadHtml(mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8")); foreach ($dom->getElementsByTagName('link') as $link) { $link->parentNode->removeChild($link); } $content_out = ''; $node = $dom->firstChild; while ($node) { $content_out .= $dom->saveHTML($node); /* repeat for all nodes at this level */ $node = $node->nextSibling; } foreach (libxml_get_errors() as $error) { /* just ignore warnings */ if ($error->level === LIBXML_ERR_WARNING) { continue; } fof_log(__FUNCTION__ . ': ' . $error->message); } libxml_clear_errors(); libxml_use_internal_errors($old_xml_err); return $content_out; }
function fof_item_targets($content) { /* quiet warnings */ $old_xml_err = libxml_use_internal_errors(true); $dom = new DOMDocument(); /* Load content into DOM, within a div wrapper. Wrapper div will be stripped before returning altered content. Without doing this, any bare text content would get wrapped in p elements while being parsed in. */ $dom->loadHtml('<div>' . mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8") . '</div>'); /* strip <!DOCTYPE> which DOMDocument adds */ $dom->removeChild($dom->firstChild); /* strip <html><body> which DOMDocument adds */ $dom->replaceChild($dom->firstChild->firstChild->firstChild, $dom->firstChild); /* replace or add link targets */ $xpath = new DOMXpath($dom); foreach ($xpath->query('//a') as $node) { $node->setAttribute('target', '_blank'); } $content_out = ''; /* emit the updated contents inside our div */ /* start at the first node inside first div.. */ $node = $dom->firstChild->firstChild; while ($node) { $content_out .= $dom->saveHTML($node); /* repeat for all nodes at this level */ $node = $node->nextSibling; } foreach (libxml_get_errors() as $error) { /* just ignore warnings */ if ($error->level === LIBXML_ERR_WARNING) { continue; } fof_log(__FUNCTION__ . ': ' . $error->message); } libxml_clear_errors(); libxml_use_internal_errors($old_xml_err); return $content_out; }
function fof_images_on_demand($content) { // AJAX refresh: we don't apply this filter, because images are // probably already loaded if ($_REQUEST['no_img_filter']) { return $content; } /* quiet warnings */ $old_xml_err = libxml_use_internal_errors(true); $dom = new DOMDocument(); // hack borrowed from http://beerpla.net/projects/smartdomdocument-a-smarter-php-domdocument-class/ $dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8")); foreach ($dom->getElementsByTagName('img') as $img) { if ($img->hasAttribute('src')) { $img->setAttribute('data-fof-ondemand-src', $img->getAttribute('src')); $img->removeAttribute('src'); } if ($img->hasAttribute('srcset')) { $img->setAttribute('data-fof-ondemand-srcset', $img->getAttribute('srcset')); $img->removeAttribute('srcset'); } } $content_out = ''; $node = $dom->firstChild; while ($node) { $content_out .= $dom->saveHTML($node); /* repeat for all nodes at this level */ $node = $node->nextSibling; } foreach (libxml_get_errors() as $error) { /* just ignore warnings */ if ($error->level === LIBXML_ERR_WARNING) { continue; } fof_log(__FUNCTION__ . ': ' . $error->message); } libxml_clear_errors(); libxml_use_internal_errors($old_xml_err); return $content_out; }
<br> <?php } ?> <input type=submit name=prefs value="Save Preferences"> </form> <br><h1 id="plugins">Feed on Feeds - Plugin Preferences</h1> <form method="post" action="prefs.php#plugins" style="border: 1px solid black; margin: 10px; padding: 10px;"> <?php $plugins = array(); $dirlist = opendir(FOF_DIR . "/plugins"); while ($file = readdir($dirlist)) { if (preg_match('/\\.php$/', $file)) { fof_log("considering " . $file); $plugins[] = substr($file, 0, -4); } } closedir(); foreach ($plugins as $plugin) { echo '<input type=checkbox name=\'' . htmlentities($plugin) . '\''; if (!$prefs->get('plugin_' . $plugin)) { echo ' checked'; } echo '> Enable plugin <tt>' . $plugin . "</tt>?<br>\n"; } ?> <br> <?php
function fof_db_mark_feed_unread($user_id, $feed, $what) { global $FOF_ITEM_TAG_TABLE; fof_log("fof_db_mark_feed_unread({$user_id}, {$feed}, {$what})"); if ($what == "all") { $result = fof_db_get_items($user_id, $feed, "all"); } if ($what == "today") { $result = fof_db_get_items($user_id, $feed, "all", "today"); } foreach ((array) $result as $r) { $items[] = $r['item_id']; } fof_db_tag_items($user_id, 1, $items); }
function fof_db_authenticate_hash($user_name, $user_password_hash) { global $FOF_USER_TABLE; global $fof_connection, $fof_user_id, $fof_user_name, $fof_user_level; fof_trace(); $query = "SELECT * FROM {$FOF_USER_TABLE} WHERE user_name = :user_name AND user_password_hash = :user_password_hash"; $statement = $fof_connection->prepare($query); $statement->bindValue(':user_name', $user_name); $statement->bindValue(':user_password_hash', $user_password_hash); $result = $statement->execute(); $row = fof_db_get_row($statement, NULL, TRUE); if (!$row) { $fof_user_id = NULL; $fof_user_name = NULL; $fof_user_level = NULL; fof_log("u:'{$user_name}' uph:'{$user_password_hash}' FAIL", 'auth'); return false; } $fof_user_id = $row['user_id']; $fof_user_name = $row['user_name']; $fof_user_level = $row['user_level']; fof_log("u:'{$user_name}' uph:'{$user_password_hash}' OK ui:'{$fof_user_id}' un:'{$fof_user_name}' ul:'{$fof_user_level}'", 'auth'); return true; }
* * Distributed under the GPL - see LICENSE * */ ob_start(); $fof_no_login = true; $fof_user_id = 1; include_once "fof-main.php"; set_time_limit(FOF_UPDATE_TIME_LIMIT); $p =& FoF_Prefs::instance(); $fof_admin_prefs = $p->prefs; fof_log("=== update started, timeout = {$fof_admin_prefs['autotimeout']}, purge = {$fof_admin_prefs['purge']} ===", "update"); $result = fof_db_get_feeds_needing_attempt(); $feeds = array(); $now = time(); while (($feed = fof_db_get_row($result)) !== false) { if ($now - $feed['feed_cache_date'] > $fof_admin_prefs['autotimeout'] * 60 && $now > $feed['feed_cache_next_attempt']) { $feeds[] = $feed; } else { fof_log("skipping {$feed['feed_id']} {$feed['feed_url']}", 'update'); } } $feeds = fof_multi_sort($feeds, 'feed_cache_attempt_date', false); foreach ($feeds as $feed) { fof_log("updating {$feed['feed_id']} {$feed['feed_url']}", 'update'); fof_update_feed($feed['feed_id']); } fof_log("optimizing database", "update"); fof_db_optimize(); fof_log("=== update complete ===", "update"); ob_end_clean();
<br> <?php if (isset($_POST['password']) && isset($_POST['password2'])) { if ($_POST['password'] == $_POST['password2']) { fof_db_add_user_all(1, 'admin', $_POST['password'], 'admin'); fof_log("admin user created"); echo '<center><b>OK! Setup complete! <a href=".">Login as admin</a>, and start subscribing!</center></b>'; echo '</div></body></html>'; exit; } else { echo "<center><span class='fail'>Passwords do not match!</span></center><br><br>"; } } else { fof_log("install started"); ?> <h2>Checking compatibility...</h2> <?php $compat_fatal = 0; $php_ok = function_exists('version_compare') && version_compare(phpversion(), VERSION_REQUIRED_PHP, '>='); $compat_fatal |= fof_install_compat_notice($php_ok, "PHP", "Your PHP version is too old!", "Feed on Feeds requires at least PHP version " . VERSION_REQUIRED_PHP, 1); $compat_fatal |= fof_install_compat_notice(extension_loaded('xml'), "XML", "Your PHP installation is missing the XML extension!", "This is required by Feed on Feeds.", 1); $compat_fatal |= fof_install_compat_notice(extension_loaded('pcre'), "PCRE", "Your PHP installation is missing the PCRE extension!", "This is required by Feed on Feeds.", 1); $compat_fatal |= fof_install_compat_notice(extension_loaded('pdo'), "PDO", "Your PHP installation is missing the PDO extension!", "This is required by Feed on Feeds.", 1); $mysql_ok = extension_loaded('pdo_mysql'); $sqlite_ok = extension_loaded('pdo_sqlite'); $compat_fatal |= fof_install_compat_notice($sqlite_ok, "SQLite", "Your PHP installation does not support the SQLite database" . (defined('USE_SQLITE') ? ", but you have configured Feed on Feeds to use this database!" : "."), defined('USE_SQLITE') ? "PHP will need to support this database, or you must configure a different one." : "This is not required if another database is available.", defined('USE_SQLITE')); $compat_fatal |= fof_install_compat_notice($mysql_ok, "MySQL", "Your PHP installation does not support the MySQL database" . (defined('USE_MYSQL') ? ", but you have configured Feed on Feeds to use this database!" : "."), defined('USE_MYSQL') ? "PHP will need to support this database, or you must configure a different one." : "This is not required if another database is available.", defined('USE_MYSQL')); $compat_fatal |= fof_install_compat_notice($sqlite_ok || $mysql_ok, "PDO database", "Your PHP installation is missing a supported PDO database extension!", "This is required by Feed on Feeds.", 1); $curl_ok = extension_loaded('curl') && version_compare(get_curl_version(), VERSION_REQUIRED_CURL, '>=');
function fof_init_plugins() { global $fof_item_filters, $fof_item_prefilters, $fof_tag_prefilters, $fof_plugin_prefs; $fof_item_filters = array(); $fof_item_prefilters = array(); $fof_plugin_prefs = array(); $fof_tag_prefilters = array(); $p =& FoF_Prefs::instance(); $dirlist = opendir(FOF_DIR . "/plugins"); while ($file = readdir($dirlist)) { fof_log("considering " . $file); if (ereg('\\.php$', $file) && !$p->get('plugin_' . substr($file, 0, -4))) { fof_log("including " . $file); include FOF_DIR . "/plugins/" . $file; } } closedir(); }
/** Fetch the favicon for a url, cache it, and return its cached name. */ function fof_get_favicon($url) { include_once 'classes/favicon.php'; /* gather up notices from favicon and reroute to fof log */ set_error_handler('fof_favicon_log'); $favicon = new FavIcon($url); $favicon = $favicon->getIcon(); restore_error_handler(); if (empty($favicon)) { fof_log('FavIcon resolution failed for ' . $url); return false; } return fof_cache_image_data($favicon['href'], $favicon['type'], $favicon['data']); }