function fb_close() { $theme = get_pref('theme'); $root_path = get_pref('root'); require 'themes/' . $theme . '/page_footer.fbt'; mysql_close; }
function hook_article_button($line) { if (!get_pref($this->link, "COMBINED_DISPLAY_MODE")) { $rv = "<img src=\"" . theme_image($this->link, 'plugins/close_button/button.png') . "\"\n\t\t\t\tclass='tagsPic' style=\"cursor : pointer\"\n\t\t\t\tonclick=\"closeArticlePanel()\"\n\t\t\t\ttitle='" . __('Close article') . "'>"; } return $rv; }
function plugin_list($message = '') { global $event; pagetop(gTxt('tab_plugins'), $message); echo '<h1 class="txp-heading">' . gTxt('tab_plugins') . '</h1>'; echo '<div id="' . $event . '_control" class="txp-control-panel">'; echo n . plugin_form() . n . '</div>'; extract(gpsa(array('sort', 'dir'))); if ($sort === '') { $sort = get_pref('plugin_sort_column', 'name'); } if ($dir === '') { $dir = get_pref('plugin_sort_dir', 'asc'); } $dir = $dir == 'desc' ? 'desc' : 'asc'; if (!in_array($sort, array('name', 'status', 'author', 'version', 'modified', 'load_order'))) { $sort = 'name'; } $sort_sql = $sort . ' ' . $dir; set_pref('plugin_sort_column', $sort, 'plugin', 2, '', 0, PREF_PRIVATE); set_pref('plugin_sort_dir', $dir, 'plugin', 2, '', 0, PREF_PRIVATE); $switch_dir = $dir == 'desc' ? 'asc' : 'desc'; $rs = safe_rows_start('name, status, author, author_uri, version, description, length(help) as help, abs(strcmp(md5(code),code_md5)) as modified, load_order, flags', 'txp_plugin', '1 order by ' . $sort_sql); if ($rs and numRows($rs) > 0) { echo n . '<div id="' . $event . '_container" class="txp-container">'; echo '<form action="index.php" id="plugin_form" class="multi_edit_form" method="post" name="longform">' . n . '<div class="txp-listtables">' . n . startTable('', '', 'txp-list') . n . '<thead>' . tr(n . hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' title="' . gTxt('toggle_all_selected') . '" class="multi-edit"') . n . column_head('plugin', 'name', 'plugin', true, $switch_dir, '', '', ('name' == $sort ? "{$dir} " : '') . 'name') . n . column_head('author', 'author', 'plugin', true, $switch_dir, '', '', ('author' == $sort ? "{$dir} " : '') . 'author') . n . column_head('version', 'version', 'plugin', true, $switch_dir, '', '', ('version' == $sort ? "{$dir} " : '') . 'version') . n . column_head('plugin_modified', 'modified', 'plugin', true, $switch_dir, '', '', ('modified' == $sort ? "{$dir} " : '') . 'modified') . n . hCell(gTxt('description'), '', ' class="description"') . n . column_head('active', 'status', 'plugin', true, $switch_dir, '', '', ('status' == $sort ? "{$dir} " : '') . 'status') . n . column_head('order', 'load_order', 'plugin', true, $switch_dir, '', '', ('load_order' == $sort ? "{$dir} " : '') . 'load-order') . n . hCell(gTxt('manage'), '', ' class="manage actions"')) . n . '</thead>'; echo '<tbody>'; while ($a = nextRow($rs)) { foreach ($a as $key => $value) { ${$key} = txpspecialchars($value); } // Fix up the description for clean cases $description = preg_replace(array('#<br />#', '#<(/?(a|b|i|em|strong))>#', '#<a href="(https?|\\.|\\/|ftp)([A-Za-z0-9:/?.=_]+?)">#'), array('<br />', '<$1>', '<a href="$1$2">'), $description); $help = !empty($help) ? '<a class="plugin-help" href="?event=plugin' . a . 'step=plugin_help' . a . 'name=' . urlencode($name) . '">' . gTxt('help') . '</a>' : ''; $plugin_prefs = $flags & PLUGIN_HAS_PREFS ? '<a class="plugin-prefs" href="?event=plugin_prefs.' . urlencode($name) . '">' . gTxt('plugin_prefs') . '</a>' : ''; $manage = array(); if ($help) { $manage[] = $help; } if ($plugin_prefs) { $manage[] = $plugin_prefs; } $manage_items = $manage ? join(tag(sp . '|' . sp, 'span'), $manage) : '-'; $edit_url = eLink('plugin', 'plugin_edit', 'name', $name, $name); echo tr(n . td(fInput('checkbox', 'selected[]', $name), '', 'multi-edit') . td($edit_url, '', 'name') . td(href($author, $author_uri, ' rel="external"'), '', 'author') . td($version, '', 'version') . td($modified ? '<span class="warning">' . gTxt('yes') . '</span>' : '', '', 'modified') . td($description, '', 'description') . td(status_link($status, $name, yes_no($status)), '', 'status') . td($load_order, '', 'load-order') . td($manage_items, '', 'manage'), $status ? ' class="active"' : ''); unset($name, $page, $deletelink); } echo '</tbody>', n, endTable(), n, '</div>', n, plugin_multiedit_form('', $sort, $dir, '', ''), n, tInput(), n, '</form>', n, '</div>'; // Show/hide "Options" link by setting the appropriate class on the plugins TR echo script_js(<<<EOS textpattern.Relay.register('txpAsyncHref.success', function(event, data) { \t\$(data['this']).closest('tr').toggleClass('active'); }); EOS ); } }
/** * The main panel listing all installed plugins. * * @param string|array $message The activity message */ function plugin_list($message = '') { global $event; pagetop(gTxt('tab_plugins'), $message); extract(gpsa(array('sort', 'dir'))); if ($sort === '') { $sort = get_pref('plugin_sort_column', 'name'); } else { if (!in_array($sort, array('name', 'status', 'author', 'version', 'modified', 'load_order'))) { $sort = 'name'; } set_pref('plugin_sort_column', $sort, 'plugin', 2, '', 0, PREF_PRIVATE); } if ($dir === '') { $dir = get_pref('plugin_sort_dir', 'asc'); } else { $dir = $dir == 'desc' ? "desc" : "asc"; set_pref('plugin_sort_dir', $dir, 'plugin', 2, '', 0, PREF_PRIVATE); } $sort_sql = "{$sort} {$dir}"; $switch_dir = $dir == 'desc' ? 'asc' : 'desc'; echo n . tag(hed(gTxt('tab_plugins'), 1, array('class' => 'txp-heading')), 'div', array('class' => 'txp-layout-2col-cell-1')) . n . tag_start('div', array('class' => 'txp-layout-1col', 'id' => $event . '_container')) . n . tag(plugin_form(), 'div', array('class' => 'txp-control-panel')); $rs = safe_rows_start("name, status, author, author_uri, version, description, length(help) AS help, ABS(STRCMP(MD5(code), code_md5)) AS modified, load_order, flags", 'txp_plugin', "1 = 1 ORDER BY {$sort_sql}"); if ($rs and numRows($rs) > 0) { echo n . tag_start('form', array('class' => 'multi_edit_form', 'id' => 'plugin_form', 'name' => 'longform', 'method' => 'post', 'action' => 'index.php')) . n . tag_start('div', array('class' => 'txp-listtables')) . n . tag_start('table', array('class' => 'txp-list')) . n . tag_start('thead') . tr(hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' class="txp-list-col-multi-edit" scope="col" title="' . gTxt('toggle_all_selected') . '"') . column_head('plugin', 'name', 'plugin', true, $switch_dir, '', '', ('name' == $sort ? "{$dir} " : '') . 'txp-list-col-name') . column_head('author', 'author', 'plugin', true, $switch_dir, '', '', ('author' == $sort ? "{$dir} " : '') . 'txp-list-col-author') . column_head('version', 'version', 'plugin', true, $switch_dir, '', '', ('version' == $sort ? "{$dir} " : '') . 'txp-list-col-version') . column_head('plugin_modified', 'modified', 'plugin', true, $switch_dir, '', '', ('modified' == $sort ? "{$dir} " : '') . 'txp-list-col-modified') . hCell(gTxt('description'), '', ' class="txp-list-col-description" scope="col"') . column_head('active', 'status', 'plugin', true, $switch_dir, '', '', ('status' == $sort ? "{$dir} " : '') . 'txp-list-col-status') . column_head('order', 'load_order', 'plugin', true, $switch_dir, '', '', ('load_order' == $sort ? "{$dir} " : '') . 'txp-list-col-load-order') . hCell(gTxt('manage'), '', ' class="txp-list-col-manage" scope="col"')) . n . tag_end('thead') . n . tag_start('tbody'); while ($a = nextRow($rs)) { foreach ($a as $key => $value) { ${$key} = txpspecialchars($value); } // Fix up the description for clean cases. $description = preg_replace(array('#<br />#', '#<(/?(a|b|i|em|strong))>#', '#<a href="(https?|\\.|\\/|ftp)([A-Za-z0-9:/?.=_]+?)">#'), array('<br />', '<$1>', '<a href="$1$2">'), $description); if (!empty($help)) { $help = href(gTxt('help'), array('event' => 'plugin', 'step' => 'plugin_help', 'name' => $name), array('class' => 'plugin-help')); } if ($flags & PLUGIN_HAS_PREFS) { $plugin_prefs = href(gTxt('plugin_prefs'), array('event' => 'plugin_prefs.' . $name), array('class' => 'plugin-prefs')); } else { $plugin_prefs = ''; } $manage = array(); if ($help) { $manage[] = $help; } if ($plugin_prefs) { $manage[] = $plugin_prefs; } $manage_items = $manage ? join(tag(sp . '|' . sp, 'span'), $manage) : '-'; $edit_url = eLink('plugin', 'plugin_edit', 'name', $name, $name); echo tr(td(fInput('checkbox', 'selected[]', $name), '', 'txp-list-col-multi-edit') . hCell($edit_url, '', ' class="txp-list-col-name" scope="row"') . td(href($author, $a['author_uri'], array('rel' => 'external')), '', 'txp-list-col-author') . td($version, '', 'txp-list-col-version') . td($modified ? span(gTxt('yes'), array('class' => 'warning')) : '', '', 'txp-list-col-modified') . td($description, '', 'txp-list-col-description') . td(status_link($status, $name, yes_no($status)), '', 'txp-list-col-status') . td($load_order, '', 'txp-list-col-load-order') . td($manage_items, '', 'txp-list-col-manage'), $status ? ' class="active"' : ''); unset($name, $page, $deletelink); } echo n . tag_end('tbody') . n . tag_end('table') . n . tag_end('div') . plugin_multiedit_form('', $sort, $dir, '', '') . tInput() . n . tag_end('form'); } echo n . tag_end('div'); }
/** * Parses content in a restricted mode. * * @param string|null $text The input document in textile format * @param bool|null $lite Optional flag to switch the parser into lite mode * @param bool|null $noimage Optional flag controlling the conversion of images into HTML img tags * @param string|null $rel Relationship to apply to all generated links * @return string The text from the input document */ public function textileRestricted($text, $lite = null, $noimage = null, $rel = null) { if ($lite === null) { $lite = get_pref('comments_use_fat_textile', 1); } if ($noimage === null) { $noimage = get_pref('comments_disallow_images', 1); } if ($rel === null && get_pref('comment_nofollow', 1)) { $rel = 'nofollow'; } return parent::textileRestricted($text, $lite, $noimage, $rel); }
/** * Constructor. * * Creates core Textfilters according to a preference and registers all * available filters with the core. * * This method triggers 'textfilter.register' callback * event. */ public function __construct() { if ($filters = get_pref('admin_textfilter_classes')) { foreach (do_list($filters) as $filter) { new $filter(); } } else { new Plain(); new Nl2Br(); new Textile(); } $this->filters = array(); callback_event('textfilter', 'register', 0, $this); }
function opml_export($link, $owner_uid, $hide_private_feeds = False) { header("Content-type: application/xml+opml"); print "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; print "<opml version=\"1.0\">"; print "<head>\n\t\t\t<dateCreated>" . date("r", time()) . "</dateCreated>\n\t\t\t<title>Tiny Tiny RSS Feed Export</title>\n\t\t</head>"; print "<body>"; $cat_mode = false; $select = "SELECT * "; $where = "WHERE owner_uid = '{$owner_uid}'"; $orderby = "ORDER BY title"; if ($hide_private_feeds) { $where = "WHERE owner_uid = '{$owner_uid}' AND private IS false"; } if (get_pref($link, 'ENABLE_FEED_CATS')) { $cat_mode = true; $select = "SELECT \n\t\t\t\ttitle, feed_url, site_url,\n\t\t\t\t(SELECT title FROM ttrss_feed_categories WHERE id = cat_id) as cat_title"; $orderby = "ORDER BY cat_title, title"; } $result = db_query($link, $select . " FROM ttrss_feeds " . $where . " " . $orderby); $old_cat_title = ""; while ($line = db_fetch_assoc($result)) { $title = htmlspecialchars($line["title"]); $url = htmlspecialchars($line["feed_url"]); $site_url = htmlspecialchars($line["site_url"]); if ($cat_mode) { $cat_title = htmlspecialchars($line["cat_title"]); if ($old_cat_title != $cat_title) { if ($old_cat_title) { print "</outline>\n"; } if ($cat_title) { print "<outline title=\"{$cat_title}\">\n"; } $old_cat_title = $cat_title; } } if ($site_url) { $html_url_qpart = "htmlUrl=\"{$site_url}\""; } else { $html_url_qpart = ""; } print "<outline text=\"{$title}\" xmlUrl=\"{$url}\" {$html_url_qpart}/>\n"; } if ($cat_mode && $old_cat_title) { print "</outline>\n"; } print "</body></opml>"; }
function ccache_update_all($owner_uid) { if (get_pref('ENABLE_FEED_CATS', $owner_uid)) { $result = db_query("SELECT feed_id FROM ttrss_cat_counters_cache\n WHERE feed_id > 0 AND owner_uid = '{$owner_uid}'"); while ($line = db_fetch_assoc($result)) { ccache_update($line["feed_id"], $owner_uid, true); } /* We have to manually include category 0 */ ccache_update(0, $owner_uid, true); } else { $result = db_query("SELECT feed_id FROM ttrss_counters_cache\n WHERE feed_id > 0 AND owner_uid = '{$owner_uid}'"); while ($line = db_fetch_assoc($result)) { print ccache_update($line["feed_id"], $owner_uid); } } }
function sed_das_article($evt, $stp, $data, $rs) { global $step; $js = ''; if (in_array($step, array('', 'create'))) { $level = get_pref(sed_das_prefix . '_default_status', '4'); $js = <<<EOJS <script type="text/javascript"> jQuery(function() { \tjQuery('input[id="status-{$level}"]').prop('checked', true); }); </script> EOJS; } return $data . $js; }
function init($name = '') { static $instance; if ($name === '') { $name = pluggable_ui('admin_side', 'theme_name', get_pref('theme_name', 'classic')); } if ($instance && is_object($instance) && $name == $instance->name) { return $instance; } else { $instance = null; } $instance = theme::factory($name); if (!$instance) { set_pref('theme_name', 'classic'); die(gTxt('cannot_instantiate_theme', array('{name}' => $name, '{class}' => "{$name}_theme", '{path}' => theme::path($name)))); } return $instance; }
function page_edit($message = '') { global $event, $step; pagetop(gTxt('edit_pages'), $message); extract(gpsa(array('name', 'newname', 'copy', 'savenew'))); if ($step == 'page_delete' || empty($name) && $step != 'page_new' && !$savenew) { $name = safe_field('page', 'txp_section', "name = 'default'"); } elseif (($copy || $savenew) && trim(preg_replace('/[<>&"\']/', '', $newname))) { $name = $newname; } // Format of each entry is popTagLink -> array ( gTxt() string, class/ID) $tagbuild_items = array('page_article' => array('page_article_hed', 'article-tags'), 'page_article_nav' => array('page_article_nav_hed', 'article-nav-tags'), 'page_nav' => array('page_nav_hed', 'nav-tags'), 'page_xml' => array('page_xml_hed', 'xml-tags'), 'page_misc' => array('page_misc_hed', 'misc-tags'), 'page_file' => array('page_file_hed', 'file-tags')); $tagbuild_options = ''; foreach ($tagbuild_items as $tb => $item) { $tagbuild_options .= n . n . '<div class="' . $item[1] . '">' . hed('<a href="#' . $item[1] . '">' . gTxt($item[0]) . '</a>', 3, ' class="plain lever' . (get_pref('pane_page_' . $item[1] . '_visible') ? ' expanded' : '') . '"') . n . '<div id="' . $item[1] . '" class="toggle" style="display:' . (get_pref('pane_page_' . $item[1] . '_visible') ? 'block' : 'none') . '">' . taglinks($tb) . '</div></div>'; } echo '<div id="' . $event . '_container" class="txp-container txp-edit">' . startTable('edit', '', 'edit-pane') . tr(tda('<div id="tagbuild_links">' . n . hed(gTxt('tagbuilder'), 2) . $tagbuild_options . n . '</div>', ' class="column"') . tda(page_edit_form($name), ' class="column"') . tda('<div id="content_switcher">' . hed(gTxt('all_pages'), 2) . graf(sLink('page', 'page_new', gTxt('create_new_page')), ' class="action-create smallerbox"') . page_list($name) . '</div>', ' class="column"')) . endTable() . '</div>'; }
function plugin_list($message = '') { global $event; pagetop(gTxt('edit_plugins'), $message); echo '<div id="' . $event . '_control" class="txp-control-panel">'; echo n . n . startTable('edit', '', 'plugin-install') . tr(tda(plugin_form(), ' colspan="8" style="height: 30px; border: none;"')) . endTable() . '</div>'; extract(gpsa(array('sort', 'dir'))); if ($sort === '') { $sort = get_pref('plugin_sort_column', 'name'); } if ($dir === '') { $dir = get_pref('plugin_sort_dir', 'asc'); } $dir = $dir == 'desc' ? 'desc' : 'asc'; if (!in_array($sort, array('name', 'status', 'author', 'version', 'modified', 'load_order'))) { $sort = 'name'; } $sort_sql = $sort . ' ' . $dir; set_pref('plugin_sort_column', $sort, 'plugin', 2, '', 0, PREF_PRIVATE); set_pref('plugin_sort_dir', $dir, 'plugin', 2, '', 0, PREF_PRIVATE); $switch_dir = $dir == 'desc' ? 'asc' : 'desc'; $rs = safe_rows_start('name, status, author, author_uri, version, description, length(help) as help, abs(strcmp(md5(code),code_md5)) as modified, load_order, flags', 'txp_plugin', '1 order by ' . $sort_sql); if ($rs and numRows($rs) > 0) { echo n . '<div id="' . $event . '_container" class="txp-container txp-list">'; echo '<form action="index.php" id="plugin_form" method="post" name="longform" onsubmit="return verify(\'' . gTxt('are_you_sure') . '\')">' . startTable('list', '', 'list') . n . '<thead>' . tr(column_head('plugin', 'name', 'plugin', true, $switch_dir, '', '', ('name' == $sort ? "{$dir} " : '') . 'name') . column_head('author', 'author', 'plugin', true, $switch_dir, '', '', ('author' == $sort ? "{$dir} " : '') . 'author') . column_head('version', 'version', 'plugin', true, $switch_dir, '', '', ('version' == $sort ? "{$dir} " : '') . 'version') . column_head('plugin_modified', 'modified', 'plugin', true, $switch_dir, '', '', ('modified' == $sort ? "{$dir} " : '') . 'modified') . hCell(gTxt('description'), '', ' class="description"') . column_head('active', 'status', 'plugin', true, $switch_dir, '', '', ('status' == $sort ? "{$dir} " : '') . 'status') . column_head('order', 'load_order', 'plugin', true, $switch_dir, '', '', ('load_order' == $sort ? "{$dir} " : '') . 'load-order') . hCell(gTxt('manage'), '', ' class="manage actions"') . hCell('', '', ' class="multi-edit"')) . n . '</thead>'; $tfoot = n . '<tfoot>' . tr(tda(select_buttons() . plugin_multiedit_form('', $sort, $dir, '', ''), ' class="multi-edit" colspan="10" style="text-align: right; border: none;"')) . n . '</tfoot>'; echo $tfoot; echo '<tbody>'; $ctr = 1; while ($a = nextRow($rs)) { foreach ($a as $key => $value) { ${$key} = htmlspecialchars($value); } // Fix up the description for clean cases $description = preg_replace(array('#<br />#', '#<(/?(a|b|i|em|strong))>#', '#<a href="(https?|\\.|\\/|ftp)([A-Za-z0-9:/?.=_]+?)">#'), array('<br />', '<$1>', '<a href="$1$2">'), $description); $help = !empty($help) ? n . t . '<li class="action-view"><a href="?event=plugin' . a . 'step=plugin_help' . a . 'name=' . urlencode($name) . '">' . gTxt('help') . '</a></li>' : ''; $plugin_prefs = $flags & PLUGIN_HAS_PREFS && $status ? n . t . '<li class="action-options"><a href="?event=plugin_prefs.' . urlencode($name) . '">' . gTxt('plugin_prefs') . '</a></li>' : ''; echo tr(n . td($name, '', 'name') . td(href($author, $author_uri), '', 'author') . td($version, 10, 'version') . td($modified ? gTxt('yes') : '', '', 'modified') . td($description, 260, 'description') . td(status_link($status, $name, yes_no($status)), 30, 'status') . td($load_order, '', 'load-order') . td(n . '<ul class="actions">' . $help . n . t . '<li class="action-edit">' . eLink('plugin', 'plugin_edit', 'name', $name, gTxt('edit')) . '</li>' . $plugin_prefs . n . '</ul>', '', 'manage') . td(fInput('checkbox', 'selected[]', $name), 30, 'multi-edit'), ' class="' . ($ctr % 2 == 0 ? 'even' : 'odd') . '"'); $ctr++; unset($name, $page, $deletelink); } echo '</tbody>' . n . endTable() . n . '</form>' . n . '</div>'; } }
function init($name = '') { static $instance; if (empty($name)) { $name = pluggable_ui('admin_side', 'theme_name', get_pref('theme_name', 'classic')); } if ($instance && is_object($instance) && $name == $instance->name) { return $instance; } else { $instance = null; } $path = txpath . DS . THEME . DS . $name . DS . $name . '.php'; if (is_file($path)) { require_once $path; } else { $name = 'classic'; set_pref('theme_name', $name); require_once txpath . DS . THEME . DS . $name . DS . $name . '.php'; } $t = "{$name}_theme"; $instance = new $t($name); return $instance; }
function module_pref_prefs($link) { global $access_level_names; $subop = $_REQUEST["subop"]; $prefs_blacklist = array("HIDE_FEEDLIST", "SYNC_COUNTERS", "ENABLE_LABELS", "ENABLE_SEARCH_TOOLBAR", "HIDE_READ_FEEDS"); $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS", "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP", "BLACKLISTED_TAGS", "ENABLE_FEED_ICONS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE", "DEFAULT_UPDATE_INTERVAL", "MARK_UNREAD_ON_UPDATE"); if (FORCE_ARTICLE_PURGE != 0) { array_push($prefs_blacklist, "PURGE_OLD_DAYS"); array_push($prefs_blacklist, "PURGE_UNREAD_ARTICLES"); } if ($subop == "change-password") { $old_pw = $_POST["OLD_PASSWORD"]; $new_pw = $_POST["NEW_PASSWORD"]; $con_pw = $_POST["CONFIRM_PASSWORD"]; if ($old_pw == "") { print "ERROR: " . __("Old password cannot be blank."); return; } if ($new_pw == "") { print "ERROR: " . __("New password cannot be blank."); return; } if ($new_pw != $con_pw) { print "ERROR: " . __("Entered passwords do not match."); return; } $old_pw_hash1 = encrypt_password($_POST["OLD_PASSWORD"]); $old_pw_hash2 = encrypt_password($_POST["OLD_PASSWORD"], $_SESSION["name"]); $new_pw_hash = encrypt_password($_POST["NEW_PASSWORD"], $_SESSION["name"]); $active_uid = $_SESSION["uid"]; if ($old_pw && $new_pw) { $login = db_escape_string($_SERVER['PHP_AUTH_USER']); $result = db_query($link, "SELECT id FROM ttrss_users WHERE \n\t\t\t\t\tid = '{$active_uid}' AND (pwd_hash = '{$old_pw_hash1}' OR \n\t\t\t\t\t\tpwd_hash = '{$old_pw_hash2}')"); if (db_num_rows($result) == 1) { db_query($link, "UPDATE ttrss_users SET pwd_hash = '{$new_pw_hash}' \n\t\t\t\t\t\tWHERE id = '{$active_uid}'"); $_SESSION["pwd_hash"] = $new_pw_hash; print __("Password has been changed."); } else { print "ERROR: " . __('Old password is incorrect.'); } } return; } else { if ($subop == "save-config") { # $_SESSION["prefs_op_result"] = "save-config"; $_SESSION["prefs_cache"] = false; // print_r($_POST); $orig_theme = get_pref($link, "_THEME_ID"); foreach (array_keys($_POST) as $pref_name) { $pref_name = db_escape_string($pref_name); $value = db_escape_string($_POST[$pref_name]); set_pref($link, $pref_name, $value); } if ($orig_theme != get_pref($link, "_THEME_ID")) { print "PREFS_THEME_CHANGED"; } else { print __("The configuration was saved."); } return; } else { if ($subop == "getHelp") { $pref_name = db_escape_string($_REQUEST["pn"]); $result = db_query($link, "SELECT help_text FROM ttrss_prefs\n\t\t\t\tWHERE pref_name = '{$pref_name}'"); if (db_num_rows($result) > 0) { $help_text = db_fetch_result($result, 0, "help_text"); print $help_text; } else { printf(__("Unknown option: %s"), $pref_name); } } else { if ($subop == "change-email") { $email = db_escape_string($_POST["email"]); $active_uid = $_SESSION["uid"]; db_query($link, "UPDATE ttrss_users SET email = '{$email}' \n\t\t\t\tWHERE id = '{$active_uid}'"); print __("E-mail has been changed."); return; } else { if ($subop == "reset-config") { $_SESSION["prefs_op_result"] = "reset-to-defaults"; if ($_SESSION["profile"]) { $profile_qpart = "profile = '" . $_SESSION["profile"] . "'"; } else { $profile_qpart = "profile IS NULL"; } db_query($link, "DELETE FROM ttrss_user_prefs \n\t\t\t\tWHERE {$profile_qpart} AND owner_uid = " . $_SESSION["uid"]); initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]); print "PREFS_THEME_CHANGED"; // print __("The configuration was reset to defaults."); return; } else { set_pref($link, "_PREFS_ACTIVE_TAB", "genConfig"); if ($_SESSION["profile"]) { print_notice("Some preferences are only available in default profile."); } if (!SINGLE_USER_MODE) { $result = db_query($link, "SELECT id FROM ttrss_users\n\t\t\t\t\tWHERE id = " . $_SESSION["uid"] . " AND pwd_hash \n\t\t\t\t\t= 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'"); if (db_num_rows($result) != 0) { print format_warning(__("Your password is at default value, \n\t\t\t\t\t\tplease change it."), "default_pass_warning"); } /* if ($_SESSION["pwd_change_result"] == "failed") { print format_warning("Could not change the password."); } if ($_SESSION["pwd_change_result"] == "ok") { print format_notice("Password was changed."); } $_SESSION["pwd_change_result"] = ""; */ /* if ($_SESSION["prefs_op_result"] == "reset-to-defaults") { print format_notice(__("The configuration was reset to defaults.")); } */ # if ($_SESSION["prefs_op_result"] == "save-config") { # print format_notice(__("The configuration was saved.")); # } $_SESSION["prefs_op_result"] = ""; print "<form onsubmit='return false' id='change_email_form'>"; print "<table width=\"100%\" class=\"prefPrefsList\">"; print "<tr><td colspan='3'><h3>" . __("Personal data") . "</h3></tr></td>"; $result = db_query($link, "SELECT email,access_level FROM ttrss_users\n\t\t\t\t\tWHERE id = " . $_SESSION["uid"]); $email = db_fetch_result($result, 0, "email"); print "<tr><td width=\"40%\">" . __('E-mail') . "</td>"; print "<td class=\"prefValue\"><input class=\"editbox\" name=\"email\" \n\t\t\t\t\tonfocus=\"javascript:disableHotkeys();\" \n\t\t\t\t\tonblur=\"javascript:enableHotkeys();\"\n\t\t\t\t\tonkeypress=\"return filterCR(event, changeUserEmail)\"\n\t\t\t\t\tvalue=\"{$email}\"></td></tr>"; if (!SINGLE_USER_MODE) { $access_level = db_fetch_result($result, 0, "access_level"); print "<tr><td width=\"40%\">" . __('Access level') . "</td>"; print "<td>" . $access_level_names[$access_level] . "</td></tr>"; } print "</table>"; print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; print "<input type=\"hidden\" name=\"subop\" value=\"change-email\">"; print "</form>"; print "<p><button onclick=\"return changeUserEmail()\">" . __("Change e-mail") . "</button>"; print "<form onsubmit=\"return false\" \n\t\t\t\t\tname=\"change_pass_form\" id=\"change_pass_form\">"; print "<table width=\"100%\" class=\"prefPrefsList\">"; print "<tr><td colspan='3'><h3>" . __("Authentication") . "</h3></tr></td>"; print "<tr><td width=\"40%\">" . __("Old password") . "</td>"; print "<td class=\"prefValue\"><input class=\"editbox\" type=\"password\"\n\t\t\t\t\tonfocus=\"javascript:disableHotkeys();\" \n\t\t\t\t\tonblur=\"javascript:enableHotkeys();\"\n\t\t\t\t\tonkeypress=\"return filterCR(event, changeUserPassword)\"\n\t\t\t\t\tname=\"OLD_PASSWORD\"></td></tr>"; print "<tr><td width=\"40%\">" . __("New password") . "</td>"; print "<td class=\"prefValue\"><input class=\"editbox\" type=\"password\"\n\t\t\t\t\tonfocus=\"javascript:disableHotkeys();\" \n\t\t\t\t\tonblur=\"javascript:enableHotkeys();\"\n\t\t\t\t\tonkeypress=\"return filterCR(event, changeUserPassword)\"\n\t\t\t\t\tname=\"NEW_PASSWORD\"></td></tr>"; print "<tr><td width=\"40%\">" . __("Confirm password") . "</td>"; print "<td class=\"prefValue\"><input class=\"editbox\" type=\"password\"\n\t\t\t\t\tonfocus=\"javascript:disableHotkeys();\" \n\t\t\t\t\tonblur=\"javascript:enableHotkeys();\"\n\t\t\t\t\tonkeypress=\"return filterCR(event, changeUserPassword)\"\n\t\t\t\t\tname=\"CONFIRM_PASSWORD\"></td></tr>"; print "</table>"; print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; print "<input type=\"hidden\" name=\"subop\" value=\"change-password\">"; print "</form>"; print "<p><button\tonclick=\"return changeUserPassword()\">" . __("Change password") . "</button>"; } if ($_SESSION["profile"]) { initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]); $profile_qpart = "profile = '" . $_SESSION["profile"] . "'"; } else { initialize_user_prefs($link, $_SESSION["uid"]); $profile_qpart = "profile IS NULL"; } $result = db_query($link, "SELECT \n\t\t\t\tttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,\n\t\t\t\tsection_name,def_value,section_id\n\t\t\t\tFROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs\n\t\t\t\tWHERE type_id = ttrss_prefs_types.id AND \n\t\t\t\t\t{$profile_qpart} AND\n\t\t\t\t\tsection_id = ttrss_prefs_sections.id AND\n\t\t\t\t\tttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND\n\t\t\t\t\tshort_desc != '' AND\n\t\t\t\t\towner_uid = " . $_SESSION["uid"] . "\n\t\t\t\tORDER BY section_id,short_desc"); print "<form onsubmit='return false' action=\"backend.php\" \n\t\t\t\tmethod=\"POST\" id=\"pref_prefs_form\">"; $lnum = 0; $active_section = ""; while ($line = db_fetch_assoc($result)) { if (in_array($line["pref_name"], $prefs_blacklist)) { continue; } if ($_SESSION["profile"] && in_array($line["pref_name"], $profile_blacklist)) { continue; } if ($active_section != $line["section_name"]) { if ($active_section != "") { print "</table>"; } print "<p><table width=\"100%\" class=\"prefPrefsList\">"; $active_section = $line["section_name"]; print "<tr><td colspan=\"3\"><h3>" . __($active_section) . "</h3></td></tr>"; if ($line["section_id"] == 2) { print "<tr><td width=\"40%\">" . __("Select theme") . "</td>"; $user_theme = get_pref($link, "_THEME_ID"); $themes = get_all_themes(); print "<td><select name=\"_THEME_ID\">"; print "<option value=''>" . __('Default') . "</option>"; print "<option disabled>--------</option>"; foreach ($themes as $t) { $base = $t['base']; $name = $t['name']; if ($base == $user_theme) { $selected = "selected=\"1\""; } else { $selected = ""; } print "<option {$selected} value='{$base}'>{$name}</option>"; } print "</select></td></tr>"; } // print "<tr class=\"title\"> // <td width=\"25%\">Option</td><td>Value</td></tr>"; $lnum = 0; } // $class = ($lnum % 2) ? "even" : "odd"; print "<tr>"; $type_name = $line["type_name"]; $pref_name = $line["pref_name"]; $value = $line["value"]; $def_value = $line["def_value"]; $help_text = $line["help_text"]; print "<td width=\"40%\" class=\"prefName\" id=\"{$pref_name}\">" . __($line["short_desc"]); if ($help_text) { print "<div class=\"prefHelp\">" . __($help_text) . "</div>"; } print "</td>"; print "<td class=\"prefValue\">"; if ($pref_name == "DEFAULT_UPDATE_INTERVAL") { global $update_intervals_nodefault; print_select_hash($pref_name, $value, $update_intervals_nodefault); } else { if ($type_name == "bool") { // print_select($pref_name, $value, array("true", "false")); if ($value == "true") { $value = __("Yes"); } else { $value = __("No"); } print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No"))); } else { print "<input class=\"editbox\"\n\t\t\t\t\t\tonfocus=\"javascript:disableHotkeys();\" \n\t\t\t\t\t\tonblur=\"javascript:enableHotkeys();\" \n\t\t\t\t\t\tname=\"{$pref_name}\" value=\"{$value}\">"; } } print "</td>"; print "</tr>"; $lnum++; } print "</table>"; print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; print "<p><button onclick=\"return validatePrefsSave()\">" . __('Save configuration') . "</button> "; print "<button onclick=\"return editProfiles()\">" . __('Manage profiles') . "</button> "; print "<button onclick=\"return validatePrefsReset()\">" . __('Reset to defaults') . "</button></p>"; print "</form>"; } } } } } }
function update_rss_feed($feed, $ignore_daemon = false, $no_cache = false) { $debug_enabled = defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']; _debug("start", $debug_enabled); $result = db_query("SELECT id,update_interval,auth_login,\n\t\t\tfeed_url,auth_pass,cache_images,last_updated,\n\t\t\tmark_unread_on_update, owner_uid,\n\t\t\tpubsub_state, auth_pass_encrypted,\n\t\t\t(SELECT max(date_entered) FROM\n\t\t\t\tttrss_entries, ttrss_user_entries where ref_id = id AND feed_id = '{$feed}') AS last_article_timestamp\n\t\t\tFROM ttrss_feeds WHERE id = '{$feed}'"); if (db_num_rows($result) == 0) { _debug("feed {$feed} NOT FOUND/SKIPPED", $debug_enabled); return false; } $last_updated = db_fetch_result($result, 0, "last_updated"); $last_article_timestamp = @strtotime(db_fetch_result($result, 0, "last_article_timestamp")); if (defined('_DISABLE_HTTP_304')) { $last_article_timestamp = 0; } $owner_uid = db_fetch_result($result, 0, "owner_uid"); $mark_unread_on_update = sql_bool_to_bool(db_fetch_result($result, 0, "mark_unread_on_update")); $pubsub_state = db_fetch_result($result, 0, "pubsub_state"); $auth_pass_encrypted = sql_bool_to_bool(db_fetch_result($result, 0, "auth_pass_encrypted")); db_query("UPDATE ttrss_feeds SET last_update_started = NOW()\n\t\t\tWHERE id = '{$feed}'"); $auth_login = db_fetch_result($result, 0, "auth_login"); $auth_pass = db_fetch_result($result, 0, "auth_pass"); if ($auth_pass_encrypted) { require_once "crypt.php"; $auth_pass = decrypt_string($auth_pass); } $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images")); $fetch_url = db_fetch_result($result, 0, "feed_url"); $feed = db_escape_string($feed); $date_feed_processed = date('Y-m-d H:i'); $cache_filename = CACHE_DIR . "/simplepie/" . sha1($fetch_url) . ".xml"; $pluginhost = new PluginHost(); $pluginhost->set_debug($debug_enabled); $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); $pluginhost->load(PLUGINS, PluginHost::KIND_ALL); $pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); $pluginhost->load_data(); $rss = false; $rss_hash = false; $force_refetch = isset($_REQUEST["force_refetch"]); if (file_exists($cache_filename) && is_readable($cache_filename) && !$auth_login && !$auth_pass && filemtime($cache_filename) > time() - 30) { _debug("using local cache.", $debug_enabled); @($feed_data = file_get_contents($cache_filename)); if ($feed_data) { $rss_hash = sha1($feed_data); } } else { _debug("local cache will not be used for this feed", $debug_enabled); } if (!$rss) { foreach ($pluginhost->get_hooks(PluginHost::HOOK_FETCH_FEED) as $plugin) { $feed_data = $plugin->hook_fetch_feed($feed_data, $fetch_url, $owner_uid, $feed); } if (!$feed_data) { _debug("fetching [{$fetch_url}]...", $debug_enabled); _debug("If-Modified-Since: " . gmdate('D, d M Y H:i:s \\G\\M\\T', $last_article_timestamp), $debug_enabled); $feed_data = fetch_file_contents($fetch_url, false, $auth_login, $auth_pass, false, $no_cache ? FEED_FETCH_NO_CACHE_TIMEOUT : FEED_FETCH_TIMEOUT, $force_refetch ? 0 : $last_article_timestamp); global $fetch_curl_used; if (!$fetch_curl_used) { $tmp = @gzdecode($feed_data); if ($tmp) { $feed_data = $tmp; } } $feed_data = trim($feed_data); _debug("fetch done.", $debug_enabled); /* if ($feed_data) { $error = verify_feed_xml($feed_data); if ($error) { _debug("error verifying XML, code: " . $error->code, $debug_enabled); if ($error->code == 26) { _debug("got error 26, trying to decode entities...", $debug_enabled); $feed_data = html_entity_decode($feed_data, ENT_COMPAT, 'UTF-8'); $error = verify_feed_xml($feed_data); if ($error) $feed_data = ''; } } } */ } if (!$feed_data) { global $fetch_last_error; global $fetch_last_error_code; _debug("unable to fetch: {$fetch_last_error} [{$fetch_last_error_code}]", $debug_enabled); $error_escaped = ''; // If-Modified-Since if ($fetch_last_error_code != 304) { $error_escaped = db_escape_string($fetch_last_error); } else { _debug("source claims data not modified, nothing to do.", $debug_enabled); } db_query("UPDATE ttrss_feeds SET last_error = '{$error_escaped}',\n\t\t\t\t\t\tlast_updated = NOW() WHERE id = '{$feed}'"); return; } } foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_FETCHED) as $plugin) { $feed_data = $plugin->hook_feed_fetched($feed_data, $fetch_url, $owner_uid, $feed); } // set last update to now so if anything *simplepie* crashes later we won't be // continuously failing on the same feed //db_query("UPDATE ttrss_feeds SET last_updated = NOW() WHERE id = '$feed'"); if (!$rss) { $rss = new FeedParser($feed_data); $rss->init(); } // print_r($rss); $feed = db_escape_string($feed); if (!$rss->error()) { // cache data for later if (!$auth_pass && !$auth_login && is_writable(CACHE_DIR . "/simplepie")) { $new_rss_hash = sha1($rss_data); if ($new_rss_hash != $rss_hash && count($rss->get_items()) > 0) { _debug("saving {$cache_filename}", $debug_enabled); @file_put_contents($cache_filename, $feed_data); } } // We use local pluginhost here because we need to load different per-user feed plugins $pluginhost->run_hooks(PluginHost::HOOK_FEED_PARSED, "hook_feed_parsed", $rss); _debug("processing feed data...", $debug_enabled); // db_query("BEGIN"); if (DB_TYPE == "pgsql") { $favicon_interval_qpart = "favicon_last_checked < NOW() - INTERVAL '12 hour'"; } else { $favicon_interval_qpart = "favicon_last_checked < DATE_SUB(NOW(), INTERVAL 12 HOUR)"; } $result = db_query("SELECT title,site_url,owner_uid,favicon_avg_color,\n\t\t\t\t(favicon_last_checked IS NULL OR {$favicon_interval_qpart}) AS\n\t\t\t\t\t\tfavicon_needs_check\n\t\t\t\tFROM ttrss_feeds WHERE id = '{$feed}'"); $registered_title = db_fetch_result($result, 0, "title"); $orig_site_url = db_fetch_result($result, 0, "site_url"); $favicon_needs_check = sql_bool_to_bool(db_fetch_result($result, 0, "favicon_needs_check")); $favicon_avg_color = db_fetch_result($result, 0, "favicon_avg_color"); $owner_uid = db_fetch_result($result, 0, "owner_uid"); $site_url = db_escape_string(mb_substr(rewrite_relative_url($fetch_url, $rss->get_link()), 0, 245)); _debug("site_url: {$site_url}", $debug_enabled); _debug("feed_title: " . $rss->get_title(), $debug_enabled); if ($favicon_needs_check || $force_refetch) { /* terrible hack: if we crash on floicon shit here, we won't check * the icon avgcolor again (unless the icon got updated) */ $favicon_file = ICONS_DIR . "/{$feed}.ico"; $favicon_modified = @filemtime($favicon_file); _debug("checking favicon...", $debug_enabled); check_feed_favicon($site_url, $feed); $favicon_modified_new = @filemtime($favicon_file); if ($favicon_modified_new > $favicon_modified) { $favicon_avg_color = ''; } if (file_exists($favicon_file) && function_exists("imagecreatefromstring") && $favicon_avg_color == '') { require_once "colors.php"; db_query("UPDATE ttrss_feeds SET favicon_avg_color = 'fail' WHERE\n\t\t\t\t\t\t\tid = '{$feed}'"); $favicon_color = db_escape_string(calculate_avg_color($favicon_file)); $favicon_colorstring = ",favicon_avg_color = '" . $favicon_color . "'"; } else { if ($favicon_avg_color == 'fail') { _debug("floicon failed on this file, not trying to recalculate avg color", $debug_enabled); } } db_query("UPDATE ttrss_feeds SET favicon_last_checked = NOW()\n\t\t\t\t\t{$favicon_colorstring}\n\t\t\t\t\tWHERE id = '{$feed}'"); } if (!$registered_title || $registered_title == "[Unknown]") { $feed_title = db_escape_string($rss->get_title()); if ($feed_title) { _debug("registering title: {$feed_title}", $debug_enabled); db_query("UPDATE ttrss_feeds SET\n\t\t\t\t\t\ttitle = '{$feed_title}' WHERE id = '{$feed}'"); } } if ($site_url && $orig_site_url != $site_url) { db_query("UPDATE ttrss_feeds SET\n\t\t\t\t\tsite_url = '{$site_url}' WHERE id = '{$feed}'"); } _debug("loading filters & labels...", $debug_enabled); $filters = load_filters($feed, $owner_uid); $labels = get_all_labels($owner_uid); _debug("" . count($filters) . " filters loaded.", $debug_enabled); $items = $rss->get_items(); if (!is_array($items)) { _debug("no articles found.", $debug_enabled); db_query("UPDATE ttrss_feeds\n\t\t\t\t\tSET last_updated = NOW(), last_error = '' WHERE id = '{$feed}'"); return; // no articles } if ($pubsub_state != 2 && PUBSUBHUBBUB_ENABLED) { _debug("checking for PUSH hub...", $debug_enabled); $feed_hub_url = false; $links = $rss->get_links('hub'); if ($links && is_array($links)) { foreach ($links as $l) { $feed_hub_url = $l; break; } } _debug("feed hub url: {$feed_hub_url}", $debug_enabled); if ($feed_hub_url && function_exists('curl_init') && !ini_get("open_basedir")) { require_once 'lib/pubsubhubbub/subscriber.php'; $callback_url = get_self_url_prefix() . "/public.php?op=pubsub&id={$feed}"; $s = new Subscriber($feed_hub_url, $callback_url); $rc = $s->subscribe($fetch_url); _debug("feed hub url found, subscribe request sent.", $debug_enabled); db_query("UPDATE ttrss_feeds SET pubsub_state = 1\n\t\t\t\t\t\tWHERE id = '{$feed}'"); } } _debug("processing articles...", $debug_enabled); foreach ($items as $item) { if ($_REQUEST['xdebug'] == 3) { print_r($item); } $entry_guid = $item->get_id(); if (!$entry_guid) { $entry_guid = $item->get_link(); } if (!$entry_guid) { $entry_guid = make_guid_from_title($item->get_title()); } _debug("f_guid {$entry_guid}", $debug_enabled); if (!$entry_guid) { continue; } $entry_guid = "{$owner_uid},{$entry_guid}"; $entry_guid_hashed = db_escape_string('SHA1:' . sha1($entry_guid)); _debug("guid {$entry_guid} / {$entry_guid_hashed}", $debug_enabled); $entry_timestamp = ""; $entry_timestamp = $item->get_date(); _debug("orig date: " . $item->get_date(), $debug_enabled); if ($entry_timestamp == -1 || !$entry_timestamp || $entry_timestamp > time()) { $entry_timestamp = time(); $no_orig_date = 'true'; } else { $no_orig_date = 'false'; } $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); _debug("date {$entry_timestamp} [{$entry_timestamp_fmt}]", $debug_enabled); // $entry_title = html_entity_decode($item->get_title(), ENT_COMPAT, 'UTF-8'); // $entry_title = decode_numeric_entities($entry_title); $entry_title = $item->get_title(); $entry_link = rewrite_relative_url($site_url, $item->get_link()); _debug("title {$entry_title}", $debug_enabled); _debug("link {$entry_link}", $debug_enabled); if (!$entry_title) { $entry_title = date("Y-m-d H:i:s", $entry_timestamp); } $entry_content = $item->get_content(); if (!$entry_content) { $entry_content = $item->get_description(); } if ($_REQUEST["xdebug"] == 2) { print "content: "; print $entry_content; print "\n"; } $entry_comments = $item->get_comments_url(); $entry_author = $item->get_author(); $entry_guid = db_escape_string(mb_substr($entry_guid, 0, 245)); $entry_comments = db_escape_string(mb_substr(trim($entry_comments), 0, 245)); $entry_author = db_escape_string(mb_substr(trim($entry_author), 0, 245)); $num_comments = (int) $item->get_comments_count(); _debug("author {$entry_author}", $debug_enabled); _debug("num_comments: {$num_comments}", $debug_enabled); _debug("looking for tags...", $debug_enabled); // parse <category> entries into tags $additional_tags = array(); $additional_tags_src = $item->get_categories(); if (is_array($additional_tags_src)) { foreach ($additional_tags_src as $tobj) { array_push($additional_tags, $tobj); } } $entry_tags = array_unique($additional_tags); for ($i = 0; $i < count($entry_tags); $i++) { $entry_tags[$i] = mb_strtolower($entry_tags[$i], 'utf-8'); } _debug("tags found: " . join(",", $entry_tags), $debug_enabled); _debug("done collecting data.", $debug_enabled); // TODO: less memory-hungry implementation _debug("applying plugin filters..", $debug_enabled); // FIXME not sure if owner_uid is a good idea here, we may have a base entry without user entry (?) $result = db_query("SELECT plugin_data,title,content,link,tag_cache,author FROM ttrss_entries, ttrss_user_entries\n\t\t\t\t\tWHERE ref_id = id AND (guid = '" . db_escape_string($entry_guid) . "' OR guid = '{$entry_guid_hashed}') AND owner_uid = {$owner_uid}"); if (db_num_rows($result) != 0) { $entry_plugin_data = db_fetch_result($result, 0, "plugin_data"); $stored_article = array("title" => db_fetch_result($result, 0, "title"), "content" => db_fetch_result($result, 0, "content"), "link" => db_fetch_result($result, 0, "link"), "tags" => explode(",", db_fetch_result($result, 0, "tag_cache")), "author" => db_fetch_result($result, 0, "author")); } else { $entry_plugin_data = ""; $stored_article = array(); } $article = array("owner_uid" => $owner_uid, "guid" => $entry_guid, "title" => $entry_title, "content" => $entry_content, "link" => $entry_link, "tags" => $entry_tags, "plugin_data" => $entry_plugin_data, "author" => $entry_author, "stored" => $stored_article); foreach ($pluginhost->get_hooks(PluginHost::HOOK_ARTICLE_FILTER) as $plugin) { $article = $plugin->hook_article_filter($article); } $entry_tags = $article["tags"]; $entry_guid = db_escape_string($entry_guid); $entry_title = db_escape_string($article["title"]); $entry_author = db_escape_string($article["author"]); $entry_link = db_escape_string($article["link"]); $entry_plugin_data = db_escape_string($article["plugin_data"]); $entry_content = $article["content"]; // escaped below _debug("plugin data: {$entry_plugin_data}", $debug_enabled); if ($cache_images && is_writable(CACHE_DIR . '/images')) { cache_images($entry_content, $site_url, $debug_enabled); } $entry_content = db_escape_string($entry_content, false); $content_hash = "SHA1:" . sha1($entry_content); db_query("BEGIN"); $result = db_query("SELECT id FROM\tttrss_entries\n\t\t\t\t\tWHERE (guid = '{$entry_guid}' OR guid = '{$entry_guid_hashed}')"); if (db_num_rows($result) == 0) { _debug("base guid [{$entry_guid}] not found", $debug_enabled); // base post entry does not exist, create it $result = db_query("INSERT INTO ttrss_entries\n\t\t\t\t\t\t\t(title,\n\t\t\t\t\t\t\tguid,\n\t\t\t\t\t\t\tlink,\n\t\t\t\t\t\t\tupdated,\n\t\t\t\t\t\t\tcontent,\n\t\t\t\t\t\t\tcontent_hash,\n\t\t\t\t\t\t\tno_orig_date,\n\t\t\t\t\t\t\tdate_updated,\n\t\t\t\t\t\t\tdate_entered,\n\t\t\t\t\t\t\tcomments,\n\t\t\t\t\t\t\tnum_comments,\n\t\t\t\t\t\t\tplugin_data,\n\t\t\t\t\t\t\tauthor)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t('{$entry_title}',\n\t\t\t\t\t\t\t'{$entry_guid_hashed}',\n\t\t\t\t\t\t\t'{$entry_link}',\n\t\t\t\t\t\t\t'{$entry_timestamp_fmt}',\n\t\t\t\t\t\t\t'{$entry_content}',\n\t\t\t\t\t\t\t'{$content_hash}',\n\t\t\t\t\t\t\t{$no_orig_date},\n\t\t\t\t\t\t\tNOW(),\n\t\t\t\t\t\t\t'{$date_feed_processed}',\n\t\t\t\t\t\t\t'{$entry_comments}',\n\t\t\t\t\t\t\t'{$num_comments}',\n\t\t\t\t\t\t\t'{$entry_plugin_data}',\n\t\t\t\t\t\t\t'{$entry_author}')"); $article_labels = array(); } else { // we keep encountering the entry in feeds, so we need to // update date_updated column so that we don't get horrible // dupes when the entry gets purged and reinserted again e.g. // in the case of SLOW SLOW OMG SLOW updating feeds $base_entry_id = db_fetch_result($result, 0, "id"); db_query("UPDATE ttrss_entries SET date_updated = NOW()\n\t\t\t\t\t\tWHERE id = '{$base_entry_id}'"); $article_labels = get_article_labels($base_entry_id, $owner_uid); } // now it should exist, if not - bad luck then $result = db_query("SELECT\n\t\t\t\t\t\tid,content_hash,no_orig_date,title,plugin_data,guid,\n\t\t\t\t\t\t" . SUBSTRING_FOR_DATE . "(date_updated,1,19) as date_updated,\n\t\t\t\t\t\t" . SUBSTRING_FOR_DATE . "(updated,1,19) as updated,\n\t\t\t\t\t\tnum_comments\n\t\t\t\t\tFROM\n\t\t\t\t\t\tttrss_entries\n\t\t\t\t\tWHERE guid = '{$entry_guid}' OR guid = '{$entry_guid_hashed}'"); $entry_ref_id = 0; $entry_int_id = 0; if (db_num_rows($result) == 1) { _debug("base guid found, checking for user record", $debug_enabled); // this will be used below in update handler $orig_content_hash = db_fetch_result($result, 0, "content_hash"); $orig_title = db_fetch_result($result, 0, "title"); $orig_num_comments = db_fetch_result($result, 0, "num_comments"); $orig_date_updated = strtotime(db_fetch_result($result, 0, "date_updated")); $orig_plugin_data = db_fetch_result($result, 0, "plugin_data"); $ref_id = db_fetch_result($result, 0, "id"); $entry_ref_id = $ref_id; /* $stored_guid = db_fetch_result($result, 0, "guid"); if ($stored_guid != $entry_guid_hashed) { if ($debug_enabled) _debug("upgrading compat guid to hashed one", $debug_enabled); db_query("UPDATE ttrss_entries SET guid = '$entry_guid_hashed' WHERE id = '$ref_id'"); } */ // check for user post link to main table // do we allow duplicate posts with same GUID in different feeds? if (get_pref("ALLOW_DUPLICATE_POSTS", $owner_uid, false)) { $dupcheck_qpart = "AND (feed_id = '{$feed}' OR feed_id IS NULL)"; } else { $dupcheck_qpart = ""; } /* Collect article tags here so we could filter by them: */ $article_filters = get_article_filters($filters, $entry_title, $entry_content, $entry_link, $entry_timestamp, $entry_author, $entry_tags); if ($debug_enabled) { _debug("article filters: ", $debug_enabled); if (count($article_filters) != 0) { print_r($article_filters); } } if (find_article_filter($article_filters, "filter")) { db_query("COMMIT"); // close transaction in progress continue; } $score = calculate_article_score($article_filters); _debug("initial score: {$score}", $debug_enabled); $query = "SELECT ref_id, int_id FROM ttrss_user_entries WHERE\n\t\t\t\t\t\t\tref_id = '{$ref_id}' AND owner_uid = '{$owner_uid}'\n\t\t\t\t\t\t\t{$dupcheck_qpart}"; // if ($_REQUEST["xdebug"]) print "$query\n"; $result = db_query($query); // okay it doesn't exist - create user entry if (db_num_rows($result) == 0) { _debug("user record not found, creating...", $debug_enabled); if ($score >= -500 && !find_article_filter($article_filters, 'catchup')) { $unread = 'true'; $last_read_qpart = 'NULL'; } else { $unread = 'false'; $last_read_qpart = 'NOW()'; } if (find_article_filter($article_filters, 'mark') || $score > 1000) { $marked = 'true'; } else { $marked = 'false'; } if (find_article_filter($article_filters, 'publish')) { $published = 'true'; } else { $published = 'false'; } // N-grams if (DB_TYPE == "pgsql" and defined('_NGRAM_TITLE_DUPLICATE_THRESHOLD')) { $result = db_query("SELECT COUNT(*) AS similar FROM\n\t\t\t\t\t\t\t\t\tttrss_entries,ttrss_user_entries\n\t\t\t\t\t\t\t\tWHERE ref_id = id AND updated >= NOW() - INTERVAL '7 day'\n\t\t\t\t\t\t\t\t\tAND similarity(title, '{$entry_title}') >= " . _NGRAM_TITLE_DUPLICATE_THRESHOLD . "\n\t\t\t\t\t\t\t\t\tAND owner_uid = {$owner_uid}"); $ngram_similar = db_fetch_result($result, 0, "similar"); _debug("N-gram similar results: {$ngram_similar}", $debug_enabled); if ($ngram_similar > 0) { $unread = 'false'; } } $last_marked = $marked == 'true' ? 'NOW()' : 'NULL'; $last_published = $published == 'true' ? 'NOW()' : 'NULL'; $result = db_query("INSERT INTO ttrss_user_entries\n\t\t\t\t\t\t\t\t(ref_id, owner_uid, feed_id, unread, last_read, marked,\n\t\t\t\t\t\t\t\tpublished, score, tag_cache, label_cache, uuid,\n\t\t\t\t\t\t\t\tlast_marked, last_published)\n\t\t\t\t\t\t\tVALUES ('{$ref_id}', '{$owner_uid}', '{$feed}', {$unread},\n\t\t\t\t\t\t\t\t{$last_read_qpart}, {$marked}, {$published}, '{$score}', '', '',\n\t\t\t\t\t\t\t\t'', {$last_marked}, {$last_published})"); if (PUBSUBHUBBUB_HUB && $published == 'true') { $rss_link = get_self_url_prefix() . "/public.php?op=rss&id=-2&key=" . get_feed_access_key(-2, false, $owner_uid); $p = new Publisher(PUBSUBHUBBUB_HUB); $pubsub_result = $p->publish_update($rss_link); } $result = db_query("SELECT int_id FROM ttrss_user_entries WHERE\n\t\t\t\t\t\t\t\tref_id = '{$ref_id}' AND owner_uid = '{$owner_uid}' AND\n\t\t\t\t\t\t\t\tfeed_id = '{$feed}' LIMIT 1"); if (db_num_rows($result) == 1) { $entry_int_id = db_fetch_result($result, 0, "int_id"); } } else { _debug("user record FOUND", $debug_enabled); $entry_ref_id = db_fetch_result($result, 0, "ref_id"); $entry_int_id = db_fetch_result($result, 0, "int_id"); } _debug("RID: {$entry_ref_id}, IID: {$entry_int_id}", $debug_enabled); $post_needs_update = false; $update_insignificant = false; if ($orig_num_comments != $num_comments) { $post_needs_update = true; $update_insignificant = true; } if ($entry_plugin_data != $orig_plugin_data) { $post_needs_update = true; $update_insignificant = true; } if ($content_hash != $orig_content_hash) { $post_needs_update = true; $update_insignificant = false; } if (db_escape_string($orig_title) != $entry_title) { $post_needs_update = true; $update_insignificant = false; } // if post needs update, update it and mark all user entries // linking to this post as updated if ($post_needs_update) { if (defined('DAEMON_EXTENDED_DEBUG')) { _debug("post {$entry_guid_hashed} needs update...", $debug_enabled); } // print "<!-- post $orig_title needs update : $post_needs_update -->"; db_query("UPDATE ttrss_entries\n\t\t\t\t\t\t\tSET title = '{$entry_title}', content = '{$entry_content}',\n\t\t\t\t\t\t\t\tcontent_hash = '{$content_hash}',\n\t\t\t\t\t\t\t\tupdated = '{$entry_timestamp_fmt}',\n\t\t\t\t\t\t\t\tnum_comments = '{$num_comments}',\n\t\t\t\t\t\t\t\tplugin_data = '{$entry_plugin_data}'\n\t\t\t\t\t\t\tWHERE id = '{$ref_id}'"); if (!$update_insignificant) { if ($mark_unread_on_update) { db_query("UPDATE ttrss_user_entries\n\t\t\t\t\t\t\t\t\tSET last_read = null, unread = true WHERE ref_id = '{$ref_id}'"); } } } } db_query("COMMIT"); _debug("assigning labels...", $debug_enabled); assign_article_to_label_filters($entry_ref_id, $article_filters, $owner_uid, $article_labels); _debug("looking for enclosures...", $debug_enabled); // enclosures $enclosures = array(); $encs = $item->get_enclosures(); if (is_array($encs)) { foreach ($encs as $e) { $e_item = array($e->link, $e->type, $e->length); array_push($enclosures, $e_item); } } if ($debug_enabled) { _debug("article enclosures:", $debug_enabled); print_r($enclosures); } db_query("BEGIN"); foreach ($enclosures as $enc) { $enc_url = db_escape_string($enc[0]); $enc_type = db_escape_string($enc[1]); $enc_dur = db_escape_string($enc[2]); $result = db_query("SELECT id FROM ttrss_enclosures\n\t\t\t\t\t\tWHERE content_url = '{$enc_url}' AND post_id = '{$entry_ref_id}'"); if (db_num_rows($result) == 0) { db_query("INSERT INTO ttrss_enclosures\n\t\t\t\t\t\t\t(content_url, content_type, title, duration, post_id) VALUES\n\t\t\t\t\t\t\t('{$enc_url}', '{$enc_type}', '', '{$enc_dur}', '{$entry_ref_id}')"); } } db_query("COMMIT"); // check for manual tags (we have to do it here since they're loaded from filters) foreach ($article_filters as $f) { if ($f["type"] == "tag") { $manual_tags = trim_array(explode(",", $f["param"])); foreach ($manual_tags as $tag) { if (tag_is_valid($tag)) { array_push($entry_tags, $tag); } } } } // Skip boring tags $boring_tags = trim_array(explode(",", mb_strtolower(get_pref('BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8'))); $filtered_tags = array(); $tags_to_cache = array(); if ($entry_tags && is_array($entry_tags)) { foreach ($entry_tags as $tag) { if (array_search($tag, $boring_tags) === false) { array_push($filtered_tags, $tag); } } } $filtered_tags = array_unique($filtered_tags); if ($debug_enabled) { _debug("filtered article tags:", $debug_enabled); print_r($filtered_tags); } // Save article tags in the database if (count($filtered_tags) > 0) { db_query("BEGIN"); foreach ($filtered_tags as $tag) { $tag = sanitize_tag($tag); $tag = db_escape_string($tag); if (!tag_is_valid($tag)) { continue; } $result = db_query("SELECT id FROM ttrss_tags\n\t\t\t\t\t\t\tWHERE tag_name = '{$tag}' AND post_int_id = '{$entry_int_id}' AND\n\t\t\t\t\t\t\towner_uid = '{$owner_uid}' LIMIT 1"); if ($result && db_num_rows($result) == 0) { db_query("INSERT INTO ttrss_tags\n\t\t\t\t\t\t\t\t\t(owner_uid,tag_name,post_int_id)\n\t\t\t\t\t\t\t\t\tVALUES ('{$owner_uid}','{$tag}', '{$entry_int_id}')"); } array_push($tags_to_cache, $tag); } /* update the cache */ $tags_to_cache = array_unique($tags_to_cache); $tags_str = db_escape_string(join(",", $tags_to_cache)); db_query("UPDATE ttrss_user_entries\n\t\t\t\t\t\tSET tag_cache = '{$tags_str}' WHERE ref_id = '{$entry_ref_id}'\n\t\t\t\t\t\tAND owner_uid = {$owner_uid}"); db_query("COMMIT"); } if (get_pref("AUTO_ASSIGN_LABELS", $owner_uid, false)) { _debug("auto-assigning labels...", $debug_enabled); foreach ($labels as $label) { $caption = preg_quote($label["caption"]); if ($caption && preg_match("/\\b{$caption}\\b/i", "{$tags_str} " . strip_tags($entry_content) . " {$entry_title}")) { if (!labels_contains_caption($article_labels, $caption)) { label_add_article($entry_ref_id, $caption, $owner_uid); } } } } _debug("article processed", $debug_enabled); } _debug("purging feed...", $debug_enabled); purge_feed($feed, 0, $debug_enabled); db_query("UPDATE ttrss_feeds\n\t\t\t\tSET last_updated = NOW(), last_error = '' WHERE id = '{$feed}'"); // db_query("COMMIT"); } else { $error_msg = db_escape_string(mb_substr($rss->error(), 0, 245)); _debug("error fetching feed: {$error_msg}", $debug_enabled); db_query("UPDATE ttrss_feeds SET last_error = '{$error_msg}',\n\t\t\t\t\tlast_updated = NOW() WHERE id = '{$feed}'"); } unset($rss); _debug("done", $debug_enabled); }
function log_list($message = '') { global $event, $log_list_pageby, $expire_logs_after; pagetop(gTxt('visitor_logs'), $message); extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method'))); if ($sort === '') { $sort = get_pref('log_sort_column', 'time'); } if ($dir === '') { $dir = get_pref('log_sort_dir', 'desc'); } $dir = $dir == 'asc' ? 'asc' : 'desc'; $expire_logs_after = assert_int($expire_logs_after); safe_delete('txp_log', "time < date_sub(now(), interval {$expire_logs_after} day)"); switch ($sort) { case 'ip': $sort_sql = 'ip ' . $dir; break; case 'host': $sort_sql = 'host ' . $dir; break; case 'page': $sort_sql = 'page ' . $dir; break; case 'refer': $sort_sql = 'refer ' . $dir; break; case 'method': $sort_sql = 'method ' . $dir; break; case 'status': $sort_sql = 'status ' . $dir; break; default: $sort = 'time'; $sort_sql = 'time ' . $dir; break; } set_pref('log_sort_column', $sort, 'log', 2, '', 0, PREF_PRIVATE); set_pref('log_sort_dir', $dir, 'log', 2, '', 0, PREF_PRIVATE); $switch_dir = $dir == 'desc' ? 'asc' : 'desc'; $criteria = 1; if ($search_method and $crit) { $crit_escaped = doSlash(str_replace(array('\\', '%', '_', '\''), array('\\\\', '\\%', '\\_', '\\\''), $crit)); $critsql = array('ip' => "ip like '%{$crit_escaped}%'", 'host' => "host like '%{$crit_escaped}%'", 'page' => "page like '%{$crit_escaped}%'", 'refer' => "refer like '%{$crit_escaped}%'", 'method' => "method like '%{$crit_escaped}%'", 'status' => "status like '%{$crit_escaped}%'"); if (array_key_exists($search_method, $critsql)) { $criteria = $critsql[$search_method]; $limit = 500; } else { $search_method = ''; $crit = ''; } } else { $search_method = ''; $crit = ''; } $total = safe_count('txp_log', "{$criteria}"); echo '<div id="' . $event . '_control" class="txp-control-panel">'; if ($total < 1) { if ($criteria != 1) { echo n . log_search_form($crit, $search_method) . n . graf(gTxt('no_results_found'), ' class="indicator"') . '</div>'; } else { echo graf(gTxt('no_refers_recorded'), ' class="indicator"') . '</div>'; } return; } $limit = max($log_list_pageby, 15); list($page, $offset, $numPages) = pager($total, $limit, $page); echo n . log_search_form($crit, $search_method) . '</div>'; $rs = safe_rows_start('*, unix_timestamp(time) as uTime', 'txp_log', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}"); if ($rs) { echo n . '<div id="' . $event . '_container" class="txp-container txp-list">'; echo n . n . '<form action="index.php" id="log_form" method="post" name="longform" onsubmit="return verify(\'' . gTxt('are_you_sure') . '\')">' . startTable('list', '', 'list', '', '90%') . n . '<thead>' . n . tr(n . column_head('time', 'time', 'log', true, $switch_dir, $crit, $search_method, ('time' == $sort ? "{$dir} " : '') . 'date time') . column_head('IP', 'ip', 'log', true, $switch_dir, $crit, $search_method, ('ip' == $sort ? "{$dir} " : '') . 'log_detail ip') . column_head('host', 'host', 'log', true, $switch_dir, $crit, $search_method, ('host' == $sort ? "{$dir} " : '') . 'host') . column_head('page', 'page', 'log', true, $switch_dir, $crit, $search_method, ('page' == $sort ? "{$dir} " : '') . 'page') . column_head('referrer', 'refer', 'log', true, $switch_dir, $crit, $search_method, ('refer' == $sort ? "{$dir} " : '') . 'refer') . column_head('method', 'method', 'log', true, $switch_dir, $crit, $search_method, ('method' == $sort ? "{$dir} " : '') . 'log_detail method') . column_head('status', 'status', 'log', true, $switch_dir, $crit, $search_method, ('status' == $sort ? "{$dir} " : '') . 'log_detail status') . hCell('', '', ' class="multi-edit"')) . n . '</thead>'; $tfoot = n . '<tfoot>' . tr(tda(toggle_box('log_detail'), ' class="detail-toggle" colspan="2" style="text-align: left; border: none;"') . tda(select_buttons() . log_multiedit_form($page, $sort, $dir, $crit, $search_method), ' class="multi-edit" colspan="6" style="text-align: right; border: none;"')) . n . '</tfoot>'; echo $tfoot; echo '<tbody>'; $ctr = 1; while ($a = nextRow($rs)) { extract($a, EXTR_PREFIX_ALL, 'log'); if ($log_refer) { $log_refer = 'http://' . $log_refer; $log_refer = '<a href="' . htmlspecialchars($log_refer) . '" target="_blank">' . htmlspecialchars(soft_wrap($log_refer, 30)) . '</a>'; } if ($log_page) { $log_anchor = preg_replace('/\\/$/', '', $log_page); $log_anchor = soft_wrap(substr($log_anchor, 1), 30); $log_page = '<a href="' . htmlspecialchars($log_page) . '" target="_blank">' . htmlspecialchars($log_anchor) . '</a>'; if ($log_method == 'POST') { $log_page = '<strong>' . $log_page . '</strong>'; } } echo tr(n . td(gTime($log_uTime), 85, 'date time') . td($log_ip, 20, 'log_detail ip') . td(soft_wrap($log_host, 30), '', 'host') . td($log_page, '', 'page') . td($log_refer, '', 'refer') . td(htmlspecialchars($log_method), 60, 'log_detail method') . td($log_status, 60, 'log_detail status') . td(fInput('checkbox', 'selected[]', $log_id), '', 'multi-edit'), ' class="' . ($ctr % 2 == 0 ? 'even' : 'odd') . '"'); $ctr++; } echo '</tbody>' . n . endTable() . n . '</form>' . n . '<div id="' . $event . '_navigation" class="txp-navigation">' . n . nav_form('log', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit) . n . pageby_form('log', $log_list_pageby) . n . '</div>' . n . '</div>'; } }
function print_feed_select($id, $default_id = "", $attributes = "", $include_all_feeds = true, $root_id = false, $nest_level = 0) { if (!$root_id) { print "<select id=\"{$id}\" name=\"{$id}\" {$attributes}>"; if ($include_all_feeds) { $is_selected = "0" == $default_id ? "selected=\"1\"" : ""; print "<option {$is_selected} value=\"0\">" . __('All feeds') . "</option>"; } } if (get_pref('ENABLE_FEED_CATS')) { if ($root_id) { $parent_qpart = "parent_cat = '{$root_id}'"; } else { $parent_qpart = "parent_cat IS NULL"; } $result = db_query("SELECT id,title,\n\t\t\t\t(SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE\n\t\t\t\t\tc2.parent_cat = ttrss_feed_categories.id) AS num_children\n\t\t\t\tFROM ttrss_feed_categories\n\t\t\t\tWHERE owner_uid = " . $_SESSION["uid"] . " AND {$parent_qpart} ORDER BY title"); while ($line = db_fetch_assoc($result)) { for ($i = 0; $i < $nest_level; $i++) { $line["title"] = " - " . $line["title"]; } $is_selected = "CAT:" . $line["id"] == $default_id ? "selected=\"1\"" : ""; printf("<option {$is_selected} value='CAT:%d'>%s</option>", $line["id"], htmlspecialchars($line["title"])); if ($line["num_children"] > 0) { print_feed_select($id, $default_id, $attributes, $include_all_feeds, $line["id"], $nest_level + 1); } $feed_result = db_query("SELECT id,title FROM ttrss_feeds\n\t\t\t\t\tWHERE cat_id = '" . $line["id"] . "' AND owner_uid = " . $_SESSION["uid"] . " ORDER BY title"); while ($fline = db_fetch_assoc($feed_result)) { $is_selected = $fline["id"] == $default_id ? "selected=\"1\"" : ""; $fline["title"] = " + " . $fline["title"]; for ($i = 0; $i < $nest_level; $i++) { $fline["title"] = " - " . $fline["title"]; } printf("<option {$is_selected} value='%d'>%s</option>", $fline["id"], htmlspecialchars($fline["title"])); } } if (!$root_id) { $default_is_cat = $default_id == "CAT:0"; $is_selected = $default_is_cat ? "selected=\"1\"" : ""; printf("<option {$is_selected} value='CAT:0'>%s</option>", __("Uncategorized")); $feed_result = db_query("SELECT id,title FROM ttrss_feeds\n\t\t\t\t\tWHERE cat_id IS NULL AND owner_uid = " . $_SESSION["uid"] . " ORDER BY title"); while ($fline = db_fetch_assoc($feed_result)) { $is_selected = $fline["id"] == $default_id && !$default_is_cat ? "selected=\"1\"" : ""; $fline["title"] = " + " . $fline["title"]; for ($i = 0; $i < $nest_level; $i++) { $fline["title"] = " - " . $fline["title"]; } printf("<option {$is_selected} value='%d'>%s</option>", $fline["id"], htmlspecialchars($fline["title"])); } } } else { $result = db_query("SELECT id,title FROM ttrss_feeds\n\t\t\t\tWHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY title"); while ($line = db_fetch_assoc($result)) { $is_selected = $line["id"] == $default_id ? "selected=\"1\"" : ""; printf("<option {$is_selected} value='%d'>%s</option>", $line["id"], htmlspecialchars($line["title"])); } } if (!$root_id) { print "</select>"; } }
@set_pref('limit', false); } head('browse'); ?> <div id="main"> <h2><?php print _("Browse"); ?> </h2> <p><?php print _("You may browse through the loci and retrieve all related information."); ?> </p> <?php $sql = sql_connect($config['db']); $result = sql_query('SELECT a.prefix, a.id, a.name, a.functions, a.status, b.status FROM locus AS a, status AS b WHERE b.lang=\'' . get_pref('language') . '\' AND a.status=b.id' . (get_pref('limit') ? ' AND a.status>0 AND a.status<=' . get_pref('limit') : '') . ' ORDER BY a.name ASC;', $sql); if (!strlen($r = sql_last_error($sql)) && sql_num_rows($result) > 0) { print " <ul class=\"result locus\">\n"; while ($row = sql_fetch_row($result)) { if (!empty($row[4])) { print ' <li><a href="' . $config['server'] . '/locus/L' . decoct($row[0]) . '.' . decoct($row[1]) . '" title="L' . decoct($row[0]) . '.' . decoct($row[1]) . '" class="locus"><span class="name">' . $row[2] . '</span><span class="date"><img src="' . $config['server'] . '/images/status_' . $row[4] . '.png" height="8" width="8" alt="' . $row[5] . '" /></span><span class="description">' . (strlen($row[3]) > 53 ? substr($row[3], 0, 50) . '...' : $row[3]) . "</span></a></li>\n"; } else { print ' <li><span class="name">L' . decoct($row[0]) . '.' . decoct($row[1]) . '</span><span class="description"><em>' . _("Waiting for analyse, GeneID:") . ' ' . $row[2] . "</em></span></li>\n"; } } print " </ul>\n"; } else { print ' <p>' . _("no result.") . "</p>\n"; } ?> </div>
function atom() { global $thisarticle; set_error_handler('feedErrorHandler'); ob_clean(); extract($GLOBALS['prefs']); define("t_texthtml", ' type="text/html"'); define("t_text", ' type="text"'); define("t_html", ' type="html"'); define("t_xhtml", ' type="xhtml"'); define('t_appxhtml', ' type="xhtml"'); define("r_relalt", ' rel="alternate"'); define("r_relself", ' rel="self"'); $last = fetch('unix_timestamp(val)', 'txp_prefs', 'name', 'lastmod'); extract(doSlash(gpsa(array('limit', 'area')))); // build filter criteria from a comma-separated list of sections and categories $feed_filter_limit = get_pref('feed_filter_limit', 10); $section = gps('section'); $section = $section ? array_slice(array_unique(do_list($section)), 0, $feed_filter_limit) : array(); $category = gps('category'); $category = $category ? array_slice(array_unique(do_list($category)), 0, $feed_filter_limit) : array(); $st = array(); foreach ($section as $s) { $st[] = fetch_section_title($s); } $ct = array(); foreach ($category as $c) { $ct[] = fetch_category_title($c); } $sitename .= $section ? ' - ' . join(' - ', $st) : ''; $sitename .= $category ? ' - ' . join(' - ', $ct) : ''; $pub = safe_row("RealName, email", "txp_users", "privs=1"); // feed header $out[] = tag(htmlspecialchars($sitename), 'title', t_text); $out[] = tag(htmlspecialchars($site_slogan), 'subtitle', t_text); $out[] = '<link' . r_relself . ' href="' . pagelinkurl(array('atom' => 1, 'area' => $area, 'section' => $section, 'category' => $category, 'limit' => $limit)) . '" />'; $out[] = '<link' . r_relalt . t_texthtml . ' href="' . hu . '" />'; //Atom feeds with mail or domain name $dn = explode('/', $siteurl); $mail_or_domain = $use_mail_on_feeds_id ? eE($blog_mail_uid) : $dn[0]; $out[] = tag('tag:' . $mail_or_domain . ',' . $blog_time_uid . ':' . $blog_uid . ($section ? '/' . join(',', $section) : '') . ($category ? '/' . join(',', $category) : ''), 'id'); $out[] = tag('Textpattern', 'generator', ' uri="http://textpattern.com/" version="' . $version . '"'); $out[] = tag(safe_strftime("w3cdtf", $last), 'updated'); $auth[] = tag($pub['RealName'], 'name'); $auth[] = $include_email_atom ? tag(eE($pub['email']), 'email') : ''; $auth[] = tag(hu, 'uri'); $out[] = tag(n . t . t . join(n . t . t, $auth) . n, 'author'); $out[] = callback_event('atom_head'); // feed items $articles = array(); $section = doSlash($section); $category = doSlash($category); if (!$area or $area == 'article') { $sfilter = !empty($section) ? "and Section in ('" . join("','", $section) . "')" : ''; $cfilter = !empty($category) ? "and (Category1 in ('" . join("','", $category) . "') or Category2 in ('" . join("','", $category) . "'))" : ''; $limit = $limit ? $limit : $rss_how_many; $limit = intval(min($limit, max(100, $rss_how_many))); $frs = safe_column("name", "txp_section", "in_rss != '1'"); $query = array(); foreach ($frs as $f) { $query[] = "and Section != '" . doSlash($f) . "'"; } $query[] = $sfilter; $query[] = $cfilter; $expired = $publish_expired_articles ? '' : ' and (now() <= Expires or Expires = ' . NULLDATETIME . ') '; $rs = safe_rows_start("*,\n\t\t\t\tID as thisid,\n\t\t\t\tunix_timestamp(Posted) as uPosted,\n\t\t\t\tunix_timestamp(Expires) as uExpires,\n\t\t\t\tunix_timestamp(LastMod) as uLastMod", "textpattern", "Status=4 and Posted <= now() {$expired}" . join(' ', $query) . "order by Posted desc limit {$limit}"); if ($rs) { while ($a = nextRow($rs)) { extract($a); populateArticleData($a); $cb = callback_event('atom_entry'); $e = array(); $a['posted'] = $uPosted; if ($show_comment_count_in_feed) { $count = $comments_count > 0 ? ' [' . $comments_count . ']' : ''; } else { $count = ''; } $thisauthor = get_author_name($AuthorID); $e['thisauthor'] = tag(n . t . t . t . tag(htmlspecialchars($thisauthor), 'name') . n . t . t, 'author'); $e['issued'] = tag(safe_strftime('w3cdtf', $uPosted), 'published'); $e['modified'] = tag(safe_strftime('w3cdtf', $uLastMod), 'updated'); $escaped_title = htmlspecialchars($Title); $e['title'] = tag($escaped_title . $count, 'title', t_html); $permlink = permlinkurl($a); $e['link'] = '<link' . r_relalt . t_texthtml . ' href="' . $permlink . '" />'; $e['id'] = tag('tag:' . $mail_or_domain . ',' . $feed_time . ':' . $blog_uid . '/' . $uid, 'id'); $e['category1'] = trim($Category1) ? '<category term="' . htmlspecialchars($Category1) . '" />' : ''; $e['category2'] = trim($Category2) ? '<category term="' . htmlspecialchars($Category2) . '" />' : ''; $summary = trim(replace_relative_urls(parse($thisarticle['excerpt']), $permlink)); $content = trim(replace_relative_urls(parse($thisarticle['body']), $permlink)); if ($syndicate_body_or_excerpt) { # short feed: use body as summary if there's no excerpt if (!trim($summary)) { $summary = $content; } $content = ''; } if (trim($content)) { $e['content'] = tag(n . escape_cdata($content) . n, 'content', t_html); } if (trim($summary)) { $e['summary'] = tag(n . escape_cdata($summary) . n, 'summary', t_html); } $articles[$ID] = tag(n . t . t . join(n . t . t, $e) . n . $cb, 'entry'); $etags[$ID] = strtoupper(dechex(crc32($articles[$ID]))); $dates[$ID] = $uLastMod; } } } elseif ($area == 'link') { $cfilter = $category ? "category='" . $category . "'" : '1'; $limit = $limit ? $limit : $rss_how_many; $limit = intval(min($limit, max(100, $rss_how_many))); $rs = safe_rows_start("*", "txp_link", "{$cfilter} order by date desc, id desc limit {$limit}"); if ($rs) { while ($a = nextRow($rs)) { extract($a); $e['title'] = tag(htmlspecialchars($linkname), 'title', t_html); $e['content'] = tag(n . htmlspecialchars($description) . n, 'content', t_html); $url = preg_replace("/^\\/(.*)/", "https?://{$siteurl}/\$1", $url); $url = preg_replace("/&((?U).*)=/", "&\\1=", $url); $e['link'] = '<link' . r_relalt . t_texthtml . ' href="' . $url . '" />'; $e['issued'] = tag(safe_strftime('w3cdtf', strtotime($date)), 'published'); $e['modified'] = tag(gmdate('Y-m-d\\TH:i:s\\Z', strtotime($date)), 'updated'); $e['id'] = tag('tag:' . $mail_or_domain . ',' . safe_strftime('%Y-%m-%d', strtotime($date)) . ':' . $blog_uid . '/' . $id, 'id'); $articles[$id] = tag(n . t . t . join(n . t . t, $e) . n, 'entry'); $etags[$id] = strtoupper(dechex(crc32($articles[$id]))); $dates[$id] = $date; } } } if (!$articles) { if ($section) { if (safe_field('name', 'txp_section', "name in ('" . join("','", $section) . "')") == false) { txp_die(gTxt('404_not_found'), '404'); } } elseif ($category) { switch ($area) { case 'link': if (safe_field('id', 'txp_category', "name = '{$category}' and type = 'link'") == false) { txp_die(gTxt('404_not_found'), '404'); } break; case 'article': default: if (safe_field('id', 'txp_category', "name in ('" . join("','", $category) . "') and type = 'article'") == false) { txp_die(gTxt('404_not_found'), '404'); } break; } } } else { //turn on compression if we aren't using it already if (extension_loaded('zlib') && ini_get("zlib.output_compression") == 0 && ini_get('output_handler') != 'ob_gzhandler' && !headers_sent()) { // make sure notices/warnings/errors don't fudge up the feed // when compression is used $buf = ''; while ($b = @ob_get_clean()) { $buf .= $b; } @ob_start('ob_gzhandler'); echo $buf; } handle_lastmod(); $hims = serverset('HTTP_IF_MODIFIED_SINCE'); $imsd = $hims ? strtotime($hims) : 0; if (is_callable('apache_request_headers')) { $headers = apache_request_headers(); if (isset($headers["A-IM"])) { $canaim = strpos($headers["A-IM"], "feed"); } else { $canaim = false; } } else { $canaim = false; } $hinm = stripslashes(serverset('HTTP_IF_NONE_MATCH')); $cutarticles = false; if ($canaim !== false) { foreach ($articles as $id => $thing) { if (strpos($hinm, $etags[$id])) { unset($articles[$id]); $cutarticles = true; $cut_etag = true; } if ($dates[$id] < $imsd) { unset($articles[$id]); $cutarticles = true; $cut_time = true; } } } if (isset($cut_etag) && isset($cut_time)) { header("Vary: If-None-Match, If-Modified-Since"); } else { if (isset($cut_etag)) { header("Vary: If-None-Match"); } else { if (isset($cut_time)) { header("Vary: If-Modified-Since"); } } } $etag = @join("-", $etags); if (strstr($hinm, $etag)) { txp_status_header('304 Not Modified'); exit(0); } if ($etag) { header('ETag: "' . $etag . '"'); } if ($cutarticles) { //header("HTTP/1.1 226 IM Used"); //This should be used as opposed to 200, but Apache doesn't like it. //http://intertwingly.net/blog/2004/09/11/Vary-ETag/ says that the status code should be 200. header("Cache-Control: no-store, im"); header("IM: feed"); } } $out = array_merge($out, $articles); header('Content-type: application/atom+xml; charset=utf-8'); return chr(60) . '?xml version="1.0" encoding="UTF-8"?' . chr(62) . n . '<feed xml:lang="' . $language . '" xmlns="http://www.w3.org/2005/Atom">' . join(n, $out) . '</feed>'; }
<div id="headlines-toolbar" dojoType="dijit.layout.ContentPane" region="top"> </div> <div id="headlines-frame" dojoType="dijit.layout.ContentPane" onscroll="headlines_scroll_handler(this)" region="center"> <div id="headlinesInnerContainer"> <div class="whiteBox"><?php echo __('Loading, please wait...'); ?> </div> </div> </div> <?php if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) { ?> <div id="content-insert" dojoType="dijit.layout.ContentPane" region="bottom" style="height : 50%" splitter="true"></div> <?php } ?> </div> </div> </div> </div> <?php db_close($link); ?>
/** * The main author list. * * @param string|array $message The activity message */ function author_list($message = '') { global $txp_user, $author_list_pageby; pagetop(gTxt('tab_site_admin'), $message); if (is_disabled('mail')) { echo graf(span(null, array('class' => 'ui-icon ui-icon-alert')) . ' ' . gTxt('warn_mail_unavailable'), array('class' => 'alert-block warning')); } echo hed(gTxt('tab_site_admin'), 1, array('class' => 'txp-heading')); echo n . '<div id="users_control" class="txp-control-panel">'; $buttons = array(); // Change password button. $buttons[] = sLink('admin', 'new_pass_form', gTxt('change_password')); if (!has_privs('admin.edit')) { // Change email address button. $buttons[] = sLink('admin', 'change_email_form', gTxt('change_email_address')); } else { // New author button. $buttons[] = sLink('admin', 'author_edit', gTxt('add_new_author')); } echo graf(join(n, $buttons), array('class' => 'txp-buttons')); // User list. if (has_privs('admin.list')) { extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method'))); if ($sort === '') { $sort = get_pref('admin_sort_column', 'name'); } if ($dir === '') { $dir = get_pref('admin_sort_dir', 'asc'); } $dir = $dir == 'desc' ? 'desc' : 'asc'; if (!in_array($sort, array('name', 'RealName', 'email', 'privs', 'last_login'))) { $sort = 'name'; } $sort_sql = $sort . ' ' . $dir; set_pref('admin_sort_column', $sort, 'admin', 2, '', 0, PREF_PRIVATE); set_pref('admin_sort_dir', $dir, 'admin', 2, '', 0, PREF_PRIVATE); $switch_dir = $dir == 'desc' ? 'asc' : 'desc'; $criteria = 1; if ($search_method and $crit != '') { $verbatim = preg_match('/^"(.*)"$/', $crit, $m); $crit_escaped = $verbatim ? doSlash($m[1]) : doLike($crit); $critsql = $verbatim ? array('id' => "user_id in ('" . join("','", do_list($crit_escaped)) . "')", 'login' => "name = '{$crit_escaped}'", 'real_name' => "RealName = '{$crit_escaped}'", 'email' => "email = '{$crit_escaped}'", 'privs' => "convert(privs, char) in ('" . join("','", do_list($crit_escaped)) . "')") : array('id' => "user_id in ('" . join("','", do_list($crit_escaped)) . "')", 'login' => "name like '%{$crit_escaped}%'", 'real_name' => "RealName like '%{$crit_escaped}%'", 'email' => "email like '%{$crit_escaped}%'", 'privs' => "convert(privs, char) in ('" . join("','", do_list($crit_escaped)) . "')"); if (array_key_exists($search_method, $critsql)) { $criteria = $critsql[$search_method]; } else { $search_method = ''; $crit = ''; } } else { $search_method = ''; $crit = ''; } $criteria .= callback_event('admin_criteria', 'author_list', 0, $criteria); $total = getCount('txp_users', $criteria); if ($total < 1) { if ($criteria != 1) { echo n . author_search_form($crit, $search_method) . graf(gTxt('no_results_found'), ' class="indicator"') . '</div>'; } return; } $limit = max($author_list_pageby, 15); list($page, $offset, $numPages) = pager($total, $limit, $page); $use_multi_edit = has_privs('admin.edit') && safe_count('txp_users', '1=1') > 1; echo author_search_form($crit, $search_method) . '</div>'; $rs = safe_rows_start('*, unix_timestamp(last_access) as last_login', 'txp_users', "{$criteria} order by {$sort_sql} limit {$offset}, {$limit}"); if ($rs) { echo n . tag_start('div', array('id' => 'users_container', 'class' => 'txp-container')) . n . tag_start('form', array('action' => 'index.php', 'id' => 'users_form', 'class' => 'multi_edit_form', 'method' => 'post', 'name' => 'longform')) . n . tag_start('div', array('class' => 'txp-listtables')) . n . tag_start('table', array('class' => 'txp-list')) . n . tag_start('thead') . tr(($use_multi_edit ? hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' scope="col" title="' . gTxt('toggle_all_selected') . '" class="txp-list-col-multi-edit"') : hCell('', '', ' scope="col" class="txp-list-col-multi-edit"')) . column_head('login_name', 'name', 'admin', true, $switch_dir, '', '', ('name' == $sort ? "{$dir} " : '') . 'txp-list-col-login-name name') . column_head('real_name', 'RealName', 'admin', true, $switch_dir, '', '', ('RealName' == $sort ? "{$dir} " : '') . 'txp-list-col-real-name name') . column_head('email', 'email', 'admin', true, $switch_dir, '', '', ('email' == $sort ? "{$dir} " : '') . 'txp-list-col-email') . column_head('privileges', 'privs', 'admin', true, $switch_dir, '', '', ('privs' == $sort ? "{$dir} " : '') . 'txp-list-col-privs') . column_head('last_login', 'last_login', 'admin', true, $switch_dir, '', '', ('last_login' == $sort ? "{$dir} " : '') . 'txp-list-col-last-login date')) . n . tag_end('thead') . n . tag_start('tbody'); while ($a = nextRow($rs)) { extract(doSpecial($a)); echo tr(td((has_privs('admin.edit') and $txp_user != $a['name']) ? fInput('checkbox', 'selected[]', $a['name'], 'checkbox') : '', '', 'txp-list-col-multi-edit') . hCell(has_privs('admin.edit') ? eLink('admin', 'author_edit', 'user_id', $user_id, $name) : $name, '', ' scope="row" class="txp-list-col-login-name name"') . td($RealName, '', 'txp-list-col-real-name name') . td(href($email, 'mailto:' . $email), '', 'txp-list-col-email') . td(get_priv_level($privs), '', 'txp-list-col-privs') . td($last_login ? safe_strftime('%b %Y', $last_login) : '', '', 'txp-list-col-last-login date')); } echo n . tag_end('tbody') . n . tag_end('table') . n . tag_end('div') . ($use_multi_edit ? author_multiedit_form($page, $sort, $dir, $crit, $search_method) : '') . tInput() . n . tag_end('form') . n . tag_start('div', array('id' => 'users_navigation', 'class' => 'txp-navigation')) . pageby_form('admin', $author_list_pageby) . nav_form('admin', $page, $numPages, $sort, $dir, $crit, $search_method) . n . tag_end('div') . n . tag_end('div'); } } else { echo n . tag_end('div'); } }
function rss() { global $prefs, $thisarticle; set_error_handler('feedErrorHandler'); ob_clean(); extract($prefs); extract(doSlash(gpsa(array('limit', 'area')))); // build filter criteria from a comma-separated list of sections and categories $feed_filter_limit = get_pref('feed_filter_limit', 10); $section = gps('section'); $category = gps('category'); if (!is_scalar($section) || !is_scalar($category)) { txp_die('Not Found', 404); } $section = $section ? array_slice(array_unique(do_list($section)), 0, $feed_filter_limit) : array(); $category = $category ? array_slice(array_unique(do_list($category)), 0, $feed_filter_limit) : array(); $st = array(); foreach ($section as $s) { $st[] = fetch_section_title($s); } $ct = array(); foreach ($category as $c) { $ct[] = fetch_category_title($c); } $sitename .= $section ? ' - ' . join(' - ', $st) : ''; $sitename .= $category ? ' - ' . join(' - ', $ct) : ''; $dn = explode('/', $siteurl); $mail_or_domain = $use_mail_on_feeds_id ? eE($blog_mail_uid) : $dn[0]; // feed header $out[] = tag('http://textpattern.com/?v=' . $version, 'generator'); $out[] = tag(doSpecial($sitename), 'title'); $out[] = tag(hu, 'link'); $out[] = '<atom:link href="' . pagelinkurl(array('rss' => 1, 'area' => $area, 'section' => $section, 'category' => $category, 'limit' => $limit)) . '" rel="self" type="application/rss+xml" />'; $out[] = tag(doSpecial($site_slogan), 'description'); $last = fetch('unix_timestamp(val)', 'txp_prefs', 'name', 'lastmod'); $out[] = tag(safe_strftime('rfc822', $last), 'pubDate'); $out[] = callback_event('rss_head'); // feed items $articles = array(); $section = doSlash($section); $category = doSlash($category); if (!$area or $area == 'article') { $sfilter = !empty($section) ? "and Section in ('" . join("','", $section) . "')" : ''; $cfilter = !empty($category) ? "and (Category1 in ('" . join("','", $category) . "') or Category2 in ('" . join("','", $category) . "'))" : ''; $limit = $limit ? $limit : $rss_how_many; $limit = intval(min($limit, max(100, $rss_how_many))); $frs = safe_column("name", "txp_section", "in_rss != '1'"); if ($frs) { foreach ($frs as $f) { $query[] = "and Section != '" . doSlash($f) . "'"; } } $query[] = $sfilter; $query[] = $cfilter; $expired = $publish_expired_articles ? '' : ' and (now() <= Expires or Expires = ' . NULLDATETIME . ') '; $rs = safe_rows_start("*, unix_timestamp(Posted) as uPosted, unix_timestamp(LastMod) as uLastMod, unix_timestamp(Expires) as uExpires, ID as thisid", "textpattern", "Status = 4 " . join(' ', $query) . "and Posted < now()" . $expired . "order by Posted desc limit {$limit}"); if ($rs) { while ($a = nextRow($rs)) { extract($a); populateArticleData($a); $cb = callback_event('rss_entry'); $a['posted'] = $uPosted; $permlink = permlinkurl($a); $summary = trim(replace_relative_urls(parse($thisarticle['excerpt']), $permlink)); $content = trim(replace_relative_urls(parse($thisarticle['body']), $permlink)); if ($syndicate_body_or_excerpt) { # short feed: use body as summary if there's no excerpt if (!trim($summary)) { $summary = $content; } $content = ''; } if ($show_comment_count_in_feed) { $count = $comments_count > 0 ? ' [' . $comments_count . ']' : ''; } else { $count = ''; } $Title = escape_title(strip_tags($Title)) . $count; $thisauthor = get_author_name($AuthorID); $item = tag($Title, 'title') . n . (trim($summary) ? tag(n . escape_cdata($summary) . n, 'description') . n : '') . (trim($content) ? tag(n . escape_cdata($content) . n, 'content:encoded') . n : '') . tag($permlink, 'link') . n . tag(safe_strftime('rfc822', $a['posted']), 'pubDate') . n . tag(htmlspecialchars($thisauthor), 'dc:creator') . n . tag('tag:' . $mail_or_domain . ',' . $feed_time . ':' . $blog_uid . '/' . $uid, 'guid', ' isPermaLink="false"') . n . $cb; $articles[$ID] = tag($item, 'item'); $etags[$ID] = strtoupper(dechex(crc32($articles[$ID]))); $dates[$ID] = $uPosted; } } } elseif ($area == 'link') { $cfilter = $category ? "category in ('" . join("','", $category) . "')" : '1'; $limit = $limit ? $limit : $rss_how_many; $limit = intval(min($limit, max(100, $rss_how_many))); $rs = safe_rows_start("*, unix_timestamp(date) as uDate", "txp_link", "{$cfilter} order by date desc limit {$limit}"); if ($rs) { while ($a = nextRow($rs)) { extract($a); $item = tag(doSpecial($linkname), 'title') . n . tag(doSpecial($description), 'description') . n . tag(doSpecial($url), 'link') . n . tag(safe_strftime('rfc822', $uDate), 'pubDate'); $articles[$id] = tag($item, 'item'); $etags[$id] = strtoupper(dechex(crc32($articles[$id]))); $dates[$id] = $date; } } } if (!$articles) { if ($section) { if (safe_field('name', 'txp_section', "name in ('" . join("','", $section) . "')") == false) { txp_die(gTxt('404_not_found'), '404'); } } elseif ($category) { switch ($area) { case 'link': if (safe_field('id', 'txp_category', "name = '{$category}' and type = 'link'") == false) { txp_die(gTxt('404_not_found'), '404'); } break; case 'article': default: if (safe_field('id', 'txp_category', "name in ('" . join("','", $category) . "') and type = 'article'") == false) { txp_die(gTxt('404_not_found'), '404'); } break; } } } else { //turn on compression if we aren't using it already if (extension_loaded('zlib') && ini_get("zlib.output_compression") == 0 && ini_get('output_handler') != 'ob_gzhandler' && !headers_sent()) { // make sure notices/warnings/errors don't fudge up the feed // when compression is used $buf = ''; while ($b = @ob_get_clean()) { $buf .= $b; } @ob_start('ob_gzhandler'); echo $buf; } handle_lastmod(); $hims = serverset('HTTP_IF_MODIFIED_SINCE'); $imsd = $hims ? strtotime($hims) : 0; if (is_callable('apache_request_headers')) { $headers = apache_request_headers(); if (isset($headers["A-IM"])) { $canaim = strpos($headers["A-IM"], "feed"); } else { $canaim = false; } } else { $canaim = false; } $hinm = stripslashes(serverset('HTTP_IF_NONE_MATCH')); $cutarticles = false; if ($canaim !== false) { foreach ($articles as $id => $thing) { if (strpos($hinm, $etags[$id]) !== false) { unset($articles[$id]); $cutarticles = true; $cut_etag = true; } if ($dates[$id] < $imsd) { unset($articles[$id]); $cutarticles = true; $cut_time = true; } } } if (isset($cut_etag) && isset($cut_time)) { header("Vary: If-None-Match, If-Modified-Since"); } else { if (isset($cut_etag)) { header("Vary: If-None-Match"); } else { if (isset($cut_time)) { header("Vary: If-Modified-Since"); } } } $etag = @join("-", $etags); if (strstr($hinm, $etag)) { txp_status_header('304 Not Modified'); exit(0); } if ($cutarticles) { //header("HTTP/1.1 226 IM Used"); //This should be used as opposed to 200, but Apache doesn't like it. //http://intertwingly.net/blog/2004/09/11/Vary-ETag/ says that the status code should be 200. header("Cache-Control: no-store, im"); header("IM: feed"); } } $out = array_merge($out, $articles); header("Content-Type: application/rss+xml; charset=utf-8"); if (isset($etag)) { header('ETag: "' . $etag . '"'); } return '<?xml version="1.0" encoding="utf-8"?>' . n . '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom">' . n . tag(join(n, $out), 'channel') . n . '</rss>'; }
function render_article($link, $id, $feed_id, $cat_id) { $query = "SELECT title,link,content,feed_id,comments,int_id,\n\t\t\tmarked,unread,published,\n\t\t\t" . SUBSTRING_FOR_DATE . "(updated,1,16) as updated,\n\t\t\tauthor\n\t\t\tFROM ttrss_entries,ttrss_user_entries\n\t\t\tWHERE\tid = '{$id}' AND ref_id = id AND owner_uid = " . $_SESSION["uid"]; $result = db_query($link, $query); if (db_num_rows($result) != 0) { $line = db_fetch_assoc($result); $tmp_result = db_query($link, "UPDATE ttrss_user_entries \n\t\t\t\tSET unread = false,last_read = NOW() \n\t\t\t\tWHERE ref_id = '{$id}'\n\t\t\t\tAND owner_uid = " . $_SESSION["uid"]); if (get_pref($link, 'HEADLINES_SMART_DATE')) { $updated_fmt = smart_date_time(strtotime($line["updated"])); } else { $short_date = get_pref($link, 'SHORT_DATE_FORMAT'); $updated_fmt = date($short_date, strtotime($line["updated"])); } $title = $line["title"]; $article_link = $line["link"]; $feed_title = getFeedTitle($link, $feed_id, false); print "<div class=\"panel\" id=\"article-{$id}\" title=\"{$title}\" \n\t\t\t\tselected=\"true\"\n\t\t\t\tmyBackLabel='{$feed_title}' myBackHref='feed.php?id={$feed_id}&cat={$cat_id}'>"; print "<h2><a target='_blank' href='{$article_link}'>{$title}</a></h2>"; print "<fieldset>"; /* print "<div class=\"row\">"; print "<label id='title'><a target='_blank' href='$article_link'>$title</a></label>"; print "</div>"; */ $is_starred = sql_bool_to_bool($line["marked"]) ? "true" : "false"; $is_published = sql_bool_to_bool($line["published"]) ? "true" : "false"; print "<div class=\"row\">"; print "<label id='updated'>Updated:</label>"; print "<input enabled='false' name='updated' disabled value='{$updated_fmt}'/>"; print "</div>"; print "</fieldset>"; $content = sanitize_rss($link, $line["content"]); $content = preg_replace("/href=/i", "target=\"_blank\" href=", $content); if (!mobile_get_pref($link, "SHOW_IMAGES")) { $content = preg_replace('/<img[^>]+>/is', '', $content); } print "<p>{$content}</p>"; print "<fieldset>"; print "<div class=\"row\">\n\t <label>Starred</label>\n\t <div class=\"toggle\" onclick=\"toggleMarked({$id}, this)\" toggled=\"{$is_starred}\"><span class=\"thumb\"></span><span class=\"toggleOn\">ON</span><span class=\"toggleOff\">OFF</span></div>\n\t </div>"; print "<div class=\"row\">\n\t <label>Published</label>\n\t <div class=\"toggle\" onclick=\"togglePublished({$id}, this)\" toggled=\"{$is_published}\"><span class=\"thumb\"></span><span class=\"toggleOn\">ON</span><span class=\"toggleOff\">OFF</span></div>\n\t </div>"; print "</fieldset>"; print "</div>"; } }
/** * Generates a <table> of every language that Textpattern supports. * * If requested with HTTP POST parameter 'force' set anything other than 'file', * outputs any errors in RPC server connection. * * @param string|array $message The activity message */ function list_languages($message = '') { require_once txpath . '/lib/IXRClass.php'; $active_lang = safe_field("val", 'txp_prefs', "name = 'language'"); $lang_form = tag(form(tag(gTxt('active_language'), 'label', array('for' => 'language')) . languages('language', $active_lang) . eInput('lang') . sInput('save_language')), 'div', array('class' => 'txp-control-panel')); $client = new IXR_Client(RPC_SERVER); // $client->debug = true; $available_lang = array(); $rpc_connect = false; $show_files = false; // Get items from RPC. @set_time_limit(90); // TODO: 90 seconds: seriously? if ($client->query('tups.listLanguages', get_pref('blog_uid'))) { $rpc_connect = true; $response = $client->getResponse(); foreach ($response as $language) { $available_lang[$language['language']]['rpc_lastmod'] = gmmktime($language['lastmodified']->hour, $language['lastmodified']->minute, $language['lastmodified']->second, $language['lastmodified']->month, $language['lastmodified']->day, $language['lastmodified']->year); } } elseif (gps('force') != 'file') { $msg = gTxt('rpc_connect_error') . "<!--" . $client->getErrorCode() . ' ' . $client->getErrorMessage() . "-->"; } // Get items from Filesystem. $files = get_lang_files(); if (is_array($files) && !empty($files)) { foreach ($files as $file) { if ($fp = @fopen(txpath . DS . 'lang' . DS . $file, 'r')) { $name = preg_replace('/\\.(txt|textpack)$/i', '', $file); $firstline = fgets($fp, 4069); fclose($fp); if (strpos($firstline, '#@version') !== false) { @(list($fversion, $ftime) = explode(';', trim(substr($firstline, strpos($firstline, ' ', 1))))); } else { $fversion = $ftime = null; } $available_lang[$name]['file_note'] = isset($fversion) ? $fversion : 0; $available_lang[$name]['file_lastmod'] = isset($ftime) ? $ftime : 0; } } } // Get installed items from the database. // We need a value here for the language itself, not for each one of the rows. $rows = safe_rows("lang, UNIX_TIMESTAMP(MAX(lastmod)) AS lastmod", 'txp_lang', "1 = 1 GROUP BY lang ORDER BY lastmod DESC"); $installed_lang = array(); foreach ($rows as $language) { $available_lang[$language['lang']]['db_lastmod'] = $language['lastmod']; if ($language['lang'] != $active_lang) { $installed_lang[] = $language['lang']; } } $list = ''; // Create the language table components. foreach ($available_lang as $langname => $langdat) { $file_updated = isset($langdat['db_lastmod']) && @$langdat['file_lastmod'] > $langdat['db_lastmod']; $rpc_updated = @$langdat['rpc_lastmod'] > @$langdat['db_lastmod']; $rpc_install = tda($rpc_updated ? strong(eLink('lang', 'get_language', 'lang_code', $langname, isset($langdat['db_lastmod']) ? gTxt('update') : gTxt('install'), 'updating', isset($langdat['db_lastmod']), '')) . n . span(safe_strftime('%d %b %Y %X', @$langdat['rpc_lastmod']), array('class' => 'date modified')) : (isset($langdat['rpc_lastmod']) ? gTxt('up_to_date') : '-') . (isset($langdat['db_lastmod']) ? n . span(safe_strftime('%d %b %Y %X', $langdat['db_lastmod']), array('class' => 'date modified')) : ''), isset($langdat['db_lastmod']) && $rpc_updated ? ' class="highlight lang-value"' : ' class="lang-value"'); $lang_file = tda(isset($langdat['file_lastmod']) ? strong(eLink('lang', 'get_language', 'lang_code', $langname, $file_updated ? gTxt('update') : gTxt('install'), 'force', 'file', '')) . n . span(safe_strftime(get_pref('archive_dateformat'), $langdat['file_lastmod']), array('class' => 'date ' . ($file_updated ? 'created' : 'modified'))) : '-', ' class="lang-value languages_detail' . (isset($langdat['db_lastmod']) && $rpc_updated ? ' highlight' : '') . '"'); $list .= tr(hCell(gTxt($langname), '', isset($langdat['db_lastmod']) && $rpc_updated ? ' class="highlight lang-label" scope="row"' : ' class="lang-label" scope="row"') . n . $rpc_install . n . $lang_file . tda(in_array($langname, $installed_lang) ? dLink('lang', 'remove_language', 'lang_code', $langname, 1) : '-', ' class="languages_detail' . (isset($langdat['db_lastmod']) && $rpc_updated ? ' highlight' : '') . '"')) . n; } // Output table and content. pagetop(gTxt('tab_languages'), $message); echo n . tag(hed(gTxt('tab_languages'), 1, array('class' => 'txp-heading')), 'div', array('class' => 'txp-layout-2col-cell-1')) . n . tag_start('div', array('class' => 'txp-layout-1col', 'id' => 'language_container')); if (isset($msg) && $msg) { echo graf('<span class="ui-icon ui-icon-closethick"></span> ' . $msg, array('class' => 'alert-block error')); } echo $lang_form, n . tag(toggle_box('languages_detail'), 'div', array('class' => 'txp-list-options')) . n . tag_start('div', array('class' => 'txp-listtables')) . n . tag_start('table', array('class' => 'txp-list')) . n . tag_start('thead') . tr(hCell(gTxt('language'), '', ' scope="col"') . hCell(gTxt('from_server') . popHelp('install_lang_from_server'), '', ' scope="col"') . hCell(gTxt('from_file') . popHelp('install_lang_from_file'), '', ' class="languages_detail" scope="col"') . hCell(gTxt('remove_lang') . popHelp('remove_lang'), '', ' class="languages_detail" scope="col"')) . n . tag_end('thead') . n . tag_start('tbody') . $list . n . tag_end('tbody') . n . tag_end('table') . n . tag_end('div') . hed(gTxt('install_from_textpack'), 2) . n . tag(form('<label for="textpack-install">' . gTxt('install_textpack') . '</label>' . popHelp('get_textpack') . n . '<textarea class="code" id="textpack-install" name="textpack" cols="' . INPUT_LARGE . '" rows="' . TEXTAREA_HEIGHT_SMALL . '" dir="ltr"></textarea>' . fInput('submit', 'install_new', gTxt('upload')) . eInput('lang') . sInput('get_textpack'), '', '', 'post', '', '', 'text_uploader'), 'div', array('class' => 'txp-control-panel')) . n . tag_end('div'); }
function getPref() { $pref_name = $this->dbh->escape_string($_REQUEST["pref_name"]); $this->wrap(self::STATUS_OK, array("value" => get_pref($pref_name))); }
function togglepref() { $key = db_escape_string($_REQUEST["key"]); set_pref($this->link, $key, !get_pref($this->link, $key)); $value = get_pref($this->link, $key); print json_encode(array("param" => $key, "value" => $value)); }
function install_textpack($textpack, $add_new_langs = false) { global $prefs; $textpack = explode(n, $textpack); if (empty($textpack)) { return 0; } // presume site language equals textpack language $language = get_pref('language', 'en-gb'); $installed_langs = safe_column('lang', 'txp_lang', "1 = 1 group by lang"); $doit = true; $done = 0; foreach ($textpack as $line) { $line = trim($line); // A line starting with #, not followed by @ is a simple comment if (preg_match('/^#[^@]/', $line, $m)) { continue; } // A line matching "#@language xx-xx" establishes the designated language for all subsequent lines if (preg_match('/^#@language\\s+(.+)$/', $line, $m)) { $language = doSlash($m[1]); // May this Textpack introduce texts for this language? $doit = $add_new_langs || in_array($language, $installed_langs); continue; } // A line matching "#@event_name" establishes the event value for all subsequent lines if (preg_match('/^#@([a-zA-Z0-9_-]+)$/', $line, $m)) { $event = doSlash($m[1]); continue; } // Data lines match a "name => value" pattern. Some white space allowed. if ($doit && preg_match('/^(\\w+)\\s*=>\\s*(.+)$/', $line, $m)) { if (!empty($m[1]) && !empty($m[2])) { $name = doSlash($m[1]); $value = doSlash($m[2]); $where = "lang='{$language}' AND name='{$name}'"; // Store text; do *not* tamper with last modification date from RPC but use a well-known date in the past if (safe_count('txp_lang', $where)) { safe_update('txp_lang', "lastmod='2005-08-14', data='{$value}', event='{$event}'", $where); } else { safe_insert('txp_lang', "lastmod='2005-08-14', data='{$value}', event='{$event}', lang='{$language}', name='{$name}'"); } ++$done; } } } return $done; }
function view() { $timing_info = getmicrotime(); $reply = array(); if ($_REQUEST["debug"]) { $timing_info = print_checkpoint("0", $timing_info); } $omode = db_escape_string($_REQUEST["omode"]); $feed = db_escape_string($_REQUEST["feed"]); $method = db_escape_string($_REQUEST["m"]); $view_mode = db_escape_string($_REQUEST["view_mode"]); $limit = (int) get_pref($this->link, "DEFAULT_ARTICLE_LIMIT"); @($cat_view = $_REQUEST["cat"] == "true"); @($next_unread_feed = db_escape_string($_REQUEST["nuf"])); @($offset = db_escape_string($_REQUEST["skip"])); @($vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"])); $order_by = db_escape_string($_REQUEST["order_by"]); $include_children = $_REQUEST["include_children"] == "true"; if (is_numeric($feed)) { $feed = (int) $feed; } /* Feed -5 is a special case: it is used to display auxiliary information * when there's nothing to load - e.g. no stuff in fresh feed */ if ($feed == -5) { print json_encode(generate_dashboard_feed($this->link)); return; } $result = false; if ($feed < -10) { $label_feed = -11 - $feed; $result = db_query($this->link, "SELECT id FROM ttrss_labels2 WHERE\r\n\t\t\t\t\t\t\tid = '{$label_feed}' AND owner_uid = " . $_SESSION['uid']); } else { if (!$cat_view && is_numeric($feed) && $feed > 0) { $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE\r\n\t\t\t\t\t\t\tid = '{$feed}' AND owner_uid = " . $_SESSION['uid']); } else { if ($cat_view && is_numeric($feed) && $feed > 0) { $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE\r\n\t\t\t\t\t\t\tid = '{$feed}' AND owner_uid = " . $_SESSION['uid']); } } } if ($result && db_num_rows($result) == 0) { print json_encode(generate_error_feed($this->link, __("Feed not found."))); return; } /* Updating a label ccache means recalculating all of the caches * so for performance reasons we don't do that here */ if ($feed >= 0) { ccache_update($this->link, $feed, $_SESSION["uid"], $cat_view); } set_pref($this->link, "_DEFAULT_VIEW_MODE", $view_mode); set_pref($this->link, "_DEFAULT_VIEW_LIMIT", $limit); set_pref($this->link, "_DEFAULT_VIEW_ORDER_BY", $order_by); set_pref($this->link, "_DEFAULT_INCLUDE_CHILDREN", $include_children); if (!$cat_view && is_numeric($feed) && $feed > 0) { db_query($this->link, "UPDATE ttrss_feeds SET last_viewed = NOW()\r\n\t\t\t\t\t\t\tWHERE id = '{$feed}' AND owner_uid = " . $_SESSION["uid"]); } $reply['headlines'] = array(); if (!$next_unread_feed) { $reply['headlines']['id'] = $feed; } else { $reply['headlines']['id'] = $next_unread_feed; } $reply['headlines']['is_cat'] = (bool) $cat_view; $override_order = false; if (get_pref($this->link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) { $date_sort_field = "updated"; } else { $date_sort_field = "date_entered"; } switch ($order_by) { case "date": if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) { $override_order = "{$date_sort_field}"; } else { $override_order = "{$date_sort_field} DESC"; } break; case "title": if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) { $override_order = "title DESC, {$date_sort_field}"; } else { $override_order = "title, {$date_sort_field} DESC"; } break; case "score": if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) { $override_order = "score, {$date_sort_field}"; } else { $override_order = "score DESC, {$date_sort_field} DESC"; } break; } if ($_REQUEST["debug"]) { $timing_info = print_checkpoint("04", $timing_info); } $ret = $this->format_headlines_list($feed, $method, $view_mode, $limit, $cat_view, $next_unread_feed, $offset, $vgroup_last_feed, $override_order, $include_children); $topmost_article_ids = $ret[0]; $headlines_count = $ret[1]; $returned_feed = $ret[2]; $disable_cache = $ret[3]; $vgroup_last_feed = $ret[4]; $reply['headlines']['content'] =& $ret[5]['content']; $reply['headlines']['toolbar'] =& $ret[5]['toolbar']; if ($_REQUEST["debug"]) { $timing_info = print_checkpoint("05", $timing_info); } $reply['headlines-info'] = array("count" => (int) $headlines_count, "vgroup_last_feed" => $vgroup_last_feed, "disable_cache" => (bool) $disable_cache); if ($_REQUEST["debug"]) { $timing_info = print_checkpoint("20", $timing_info); } if (is_array($topmost_article_ids) && !get_pref($this->link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) { $articles = array(); foreach ($topmost_article_ids as $id) { array_push($articles, format_article($this->link, $id, false)); } $reply['articles'] = $articles; } if ($_REQUEST["debug"]) { $timing_info = print_checkpoint("30", $timing_info); } $reply['runtime-info'] = make_runtime_info($this->link); print json_encode($reply); }
function batchSubscribe() { print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">"; print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"batchaddfeeds\">"; print "<table width='100%'><tr><td>\n\t\t\t" . __("Add one valid RSS feed per line (no feed detection is done)") . "\n\t\t</td><td align='right'>"; if (get_pref('ENABLE_FEED_CATS')) { print __('Place in category:') . " "; print_feed_cat_select("cat", false, 'dojoType="dijit.form.Select"'); } print "</td></tr><tr><td colspan='2'>"; print "<textarea\n\t\t\tstyle='font-size : 12px; width : 98%; height: 200px;'\n\t\t\tplaceHolder=\"" . __("Feeds to subscribe, One per line") . "\"\n\t\t\tdojoType=\"dijit.form.SimpleTextarea\" required=\"1\" name=\"feeds\"></textarea>"; print "</td></tr><tr><td colspan='2'>"; print "<div id='feedDlg_loginContainer' style='display : none'>\n\t\t\t\t" . " <input dojoType=\"dijit.form.TextBox\" name='login'\"\n\t\t\t\t\tplaceHolder=\"" . __("Login") . "\"\n\t\t\t\t\tstyle=\"width : 10em;\"> " . " <input\n\t\t\t\t\tplaceHolder=\"" . __("Password") . "\"\n\t\t\t\t\tdojoType=\"dijit.form.TextBox\" type='password'\n\t\t\t\t\tstyle=\"width : 10em;\" name='pass'\">" . "</div>"; print "</td></tr><tr><td colspan='2'>"; print "<div style=\"clear : both\">\n\t\t\t<input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\"\n\t\t\t\t\tonclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'>\n\t\t\t\t<label for=\"feedDlg_loginCheck\">" . __('Feeds require authentication.') . "</div>"; print "</form>"; print "</td></tr></table>"; print "<div class=\"dlgButtons\">\n\t\t\t<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').execute()\">" . __('Subscribe') . "</button>\n\t\t\t<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').hide()\">" . __('Cancel') . "</button>\n\t\t\t</div>"; }
/** * The main panel listing all log hits. * * @param string|array $message The activity message */ function log_list($message = '') { global $event, $log_list_pageby, $expire_logs_after; pagetop(gTxt('tab_logs'), $message); extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method'))); if ($sort === '') { $sort = get_pref('log_sort_column', 'time'); } else { if (!in_array($sort, array('ip', 'host', 'page', 'refer', 'method', 'status'))) { $sort = 'time'; } set_pref('log_sort_column', $sort, 'log', 2, '', 0, PREF_PRIVATE); } if ($dir === '') { $dir = get_pref('log_sort_dir', 'desc'); } else { $dir = $dir == 'asc' ? "asc" : "desc"; set_pref('log_sort_dir', $dir, 'log', 2, '', 0, PREF_PRIVATE); } $expire_logs_after = assert_int($expire_logs_after); safe_delete('txp_log', "time < DATE_SUB(NOW(), INTERVAL {$expire_logs_after} DAY)"); switch ($sort) { case 'ip': $sort_sql = "ip {$dir}"; break; case 'host': $sort_sql = "host {$dir}"; break; case 'page': $sort_sql = "page {$dir}"; break; case 'refer': $sort_sql = "refer {$dir}"; break; case 'method': $sort_sql = "method {$dir}"; break; case 'status': $sort_sql = "status {$dir}"; break; default: $sort = 'time'; $sort_sql = "time {$dir}"; break; } $switch_dir = $dir == 'desc' ? 'asc' : 'desc'; $search = new Filter($event, array('ip' => array('column' => 'txp_log.ip', 'label' => gTxt('IP')), 'host' => array('column' => 'txp_log.host', 'label' => gTxt('host')), 'page' => array('column' => 'txp_log.page', 'label' => gTxt('page')), 'refer' => array('column' => 'txp_log.refer', 'label' => gTxt('referrer')), 'method' => array('column' => 'txp_log.method', 'label' => gTxt('method')), 'status' => array('column' => 'txp_log.status', 'label' => gTxt('status'), 'type' => 'integer'))); list($criteria, $crit, $search_method) = $search->getFilter(array('status' => array('can_list' => true))); $search_render_options = array('placeholder' => 'search_logs'); $total = safe_count('txp_log', "{$criteria}"); echo n . tag(hed(gTxt('tab_logs'), 1, array('class' => 'txp-heading')), 'div', array('class' => 'txp-layout-2col-cell-1')); $searchBlock = n . tag($search->renderForm('log_list', $search_render_options), 'div', array('class' => 'txp-layout-2col-cell-2', 'id' => $event . '_control')); $contentBlockStart = n . tag_start('div', array('class' => 'txp-layout-1col', 'id' => $event . '_container')); if ($total < 1) { if ($criteria != 1) { echo $searchBlock . $contentBlockStart . graf(span(null, array('class' => 'ui-icon ui-icon-info')) . ' ' . gTxt('no_results_found'), array('class' => 'alert-block information')); } else { echo $contentBlockStart . graf(span(null, array('class' => 'ui-icon ui-icon-info')) . ' ' . gTxt('no_refers_recorded'), array('class' => 'alert-block information')); } echo n . tag_end('div'); return; } $limit = max($log_list_pageby, 15); list($page, $offset, $numPages) = pager($total, $limit, $page); echo $searchBlock . $contentBlockStart; $rs = safe_rows_start("*, UNIX_TIMESTAMP(time) AS uTime", 'txp_log', "{$criteria} ORDER BY {$sort_sql} LIMIT {$offset}, {$limit}"); if ($rs) { echo n . tag(toggle_box('log_detail'), 'div', array('class' => 'txp-list-options')) . n . tag_start('form', array('class' => 'multi_edit_form', 'id' => 'log_form', 'name' => 'longform', 'method' => 'post', 'action' => 'index.php')) . n . tag_start('div', array('class' => 'txp-listtables')) . n . tag_start('table', array('class' => 'txp-list')) . n . tag_start('thead') . tr(hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' class="txp-list-col-multi-edit" scope="col" title="' . gTxt('toggle_all_selected') . '"') . column_head('time', 'time', 'log', true, $switch_dir, $crit, $search_method, ('time' == $sort ? "{$dir} " : '') . 'txp-list-col-time') . column_head('IP', 'ip', 'log', true, $switch_dir, $crit, $search_method, ('ip' == $sort ? "{$dir} " : '') . 'txp-list-col-ip') . column_head('host', 'host', 'log', true, $switch_dir, $crit, $search_method, ('host' == $sort ? "{$dir} " : '') . 'txp-list-col-host log_detail') . column_head('page', 'page', 'log', true, $switch_dir, $crit, $search_method, ('page' == $sort ? "{$dir} " : '') . 'txp-list-col-page') . column_head('referrer', 'refer', 'log', true, $switch_dir, $crit, $search_method, ('refer' == $sort ? "{$dir} " : '') . 'txp-list-col-refer') . column_head('method', 'method', 'log', true, $switch_dir, $crit, $search_method, ('method' == $sort ? "{$dir} " : '') . 'txp-list-col-method log_detail') . column_head('status', 'status', 'log', true, $switch_dir, $crit, $search_method, ('status' == $sort ? "{$dir} " : '') . 'txp-list-col-status log_detail')) . n . tag_end('thead') . n . tag_start('tbody'); while ($a = nextRow($rs)) { extract($a, EXTR_PREFIX_ALL, 'log'); if ($log_refer) { $log_refer = href(txpspecialchars(soft_wrap(preg_replace('#^http://#', '', $log_refer), 30)), txpspecialchars($log_refer), ' target="_blank"'); } if ($log_page) { $log_anchor = preg_replace('/\\/$/', '', $log_page); $log_anchor = soft_wrap(substr($log_anchor, 1), 30); $log_page = href(txpspecialchars($log_anchor), txpspecialchars($log_page), ' target="_blank"'); if ($log_method == 'POST') { $log_page = strong($log_page); } } echo tr(td(fInput('checkbox', 'selected[]', $log_id), '', 'txp-list-col-multi-edit') . hCell(gTime($log_uTime), '', ' class="txp-list-col-time" scope="row"') . td(href(txpspecialchars($log_ip), 'https://whois.domaintools.com/' . rawurlencode($log_ip), array('rel' => 'external', 'target' => '_blank')), '', 'txp-list-col-ip') . td(txpspecialchars($log_host), '', 'txp-list-col-host log_detail') . td($log_page, '', 'txp-list-col-page') . td($log_refer, '', 'txp-list-col-refer') . td(txpspecialchars($log_method), '', 'txp-list-col-method log_detail') . td($log_status, '', 'txp-list-col-status log_detail')); } echo n . tag_end('tbody') . n . tag_end('table') . n . tag_end('div') . log_multiedit_form($page, $sort, $dir, $crit, $search_method) . tInput() . n . tag_end('form') . n . tag_start('div', array('class' => 'txp-navigation', 'id' => $event . '_navigation')) . pageby_form('log', $log_list_pageby) . nav_form('log', $page, $numPages, $sort, $dir, $crit, $search_method, $total, $limit) . n . tag_end('div'); } echo n . tag_end('div'); }