static function insert($type, $ref_id, $user_id = 0, $annotation = false) { global $db, $globals; $ip = $globals['user_ip']; $ip_int = $globals['user_ip_int']; $sub = SitesMgr::my_id(); // Get this subsite's parent id (or itself if it's a parent) $res = $db->query("insert into logs (log_sub, log_date, log_type, log_ref_id, log_user_id, log_ip_int, log_ip) values ({$sub}, now(), '{$type}', {$ref_id}, {$user_id}, {$ip_int}, '{$ip}')"); if ($res && $annotation) { $a = new Annotation('log-' . $db->insert_id); $a->text = $annotation; $a->store(time() + 86400 * 30); // Valid for one month } return $res; }
function print_tabs($option) { global $current_user; if (SitesMgr::my_id() == 1 && SitesMgr::can_edit(0)) { $can_edit = true; } else { $can_edit = false; } $items = array(); if ($current_user->user_id) { $items[] = array('id' => 0, 'url' => 'subs', 'title' => _('suscripciones')); } $items[] = array('id' => 1, 'url' => 'subs?active', 'title' => _('más activos')); $items[] = array('id' => 2, 'url' => 'subs?all', 'title' => _('todos')); if ($can_edit) { $items[] = array('id' => 3, 'url' => 'subedit', 'title' => _('crear sub')); } $vars = compact('items', 'option'); return Haanga::Load('print_tabs.html', $vars); }
function do_last_published() { global $globals, $db; $sql = "SELECT SQL_NO_CACHE link_uri from links, sub_statuses where id = " . SitesMgr::my_id() . " and link_id = link and status='published' and date > date_sub(now(), interval 60 day) order by date desc"; $result = $db->get_col($sql); if (!$result) { return; } if (isset($globals['canonical_server_name']) && !empty($globals['canonical_server_name'])) { $server = $globals['canonical_server_name']; } else { $server = get_server_name(); } echo '<urlset xmlns="' . $globals['scheme'] . '//www.sitemaps.org/schemas/sitemap/0.9">' . "\n"; foreach ($result as $uri) { echo '<url>' . "\n"; echo '<loc>' . $globals['scheme'] . '//' . $server . $globals['base_url'] . 'story/' . $uri . '</loc>' . "\n"; echo '</url>' . "\n"; } echo '</urlset>' . "\n"; }
function publish($link) { global $globals, $db; //return; if (DEBUG) { return; } // Calculate votes average // it's used to calculate and check future averages $votes_avg = (double) $db->get_var("select SQL_NO_CACHE avg(vote_value) from votes, users where vote_type='links' AND vote_link_id={$link->id} and vote_user_id > 0 and vote_value > 0 and vote_user_id = user_id and user_level !='disabled'"); if ($votes_avg < $globals['users_karma_avg']) { $link->votes_avg = max($votes_avg, $globals['users_karma_avg'] * 0.97); } else { $link->votes_avg = $votes_avg; } $link->status = 'published'; $link->date = $link->published_date = time(); $db->query("update links set link_status='published', link_date=now(), link_votes_avg={$link->votes_avg} where link_id={$link->id}"); SitesMgr::deploy($link); // Increase user's karma $user = new User($link->author); if ($user->read) { $user->add_karma($globals['instant_karma_per_published'], _('noticia publicada')); } // Add the publish event/log Log::insert('link_publish', $link->id, $link->author); $link->annotation .= _('publicación') . "<br/>"; $link->save_annotation('link-karma'); // Publish to all sub sites: this and children who import the link category $my_id = SitesMgr::my_id(); // Get all sites that are "children" and try to post links // And that "import" the link->category $sites = array_intersect(SitesMgr::get_children($my_id), SitesMgr::get_receivers($link->category)); // Add my own $sites[] = $my_id; foreach ($sites as $s) { $server_name = SitesMgr::get_info($s)->server_name; syslog(LOG_INFO, "Meneame, calling: " . dirname(__FILE__) . "/post_link.php {$server_name} {$link->id}"); passthru(dirname(__FILE__) . "/post_link.php {$server_name} {$link->id}"); } }
function metas_coef_get() { global $globals; if (empty($globals['sub_balance_metas']) || !in_array(SitesMgr::my_id(), $globals['sub_balance_metas'])) { return false; } $log = new Annotation("metas-coef-" . SitesMgr::my_id()); if (!$log->read()) { return false; } $dict = unserialize($log->text); if (!$dict || !is_array($dict)) { return false; } // Failed to unserialize return $dict; // Asked for the whole dict }
function do_most_clicked_stories() { global $db, $globals, $dblang; if ($globals['mobile']) { return; } $key = 'most_clicked_' . $globals['site_shortname'] . $globals['v']; if (memcache_mprint($key)) { return; } echo '<!-- Calculating ' . __FUNCTION__ . ' -->'; $title = _('más visitadas'); $min_date = date("Y-m-d H:i:00", $globals['now'] - 172800); // 48 hours // The order is not exactly the votes // but a time-decreasing function applied to the number of votes $res = $db->get_results("select link_id, counter*(1-(unix_timestamp(now())-unix_timestamp(link_date))*0.5/172800) as value from links, link_clicks, sub_statuses where sub_statuses.id = " . SitesMgr::my_id() . " AND link_id = link AND status='published' and date > '{$min_date}' and link_clicks.id = link order by value desc limit 5"); if ($res) { $links = array(); $url = $globals['base_url'] . 'top_visited'; $link = new Link(); foreach ($res as $l) { $link = Link::from_db($l->link_id); $link->url = $link->get_relative_permalink(); $link->thumb = $link->has_thumb(); $link->total_votes = $link->votes + $link->anonymous; if ($link->thumb) { $link->thumb_x = round($link->thumb_x / 2); $link->thumb_y = round($link->thumb_y / 2); } $link->check_warn(); $links[] = $link; } $vars = compact('links', 'title', 'url'); $output = Haanga::Load('most_clicked_stories.html', $vars, true); echo $output; memcache_madd($key, $output, 180); } }
function print_categories_checkboxes($user) { global $db, $current_user; // Get selected categories $selected_set = $db->get_col("SELECT pref_value FROM prefs WHERE pref_user_id = {$user->id} and pref_key = 'category_" . SitesMgr::my_id() . "'"); $selected = array(); if ($selected_set) { foreach ($selected_set as $cat) { $selected[$cat] = true; } } $metas = SitesMgr::get_metas(); $categories = array(); foreach ($metas as $meta) { $categories[$meta->id] = SitesMgr::get_categories($meta->id); if ($selected) { // Check if all categories are selected for the current meta $all = true; foreach ($categories[$meta->id] as $sel) { if (!isset($selected[$sel->id])) { $all = false; } } if ($all) { $selected[$meta->id] = true; } } } Haanga::Load('user/categories.html', compact('user', 'metas', 'categories', 'selected')); }
$memcache_key = 'topstories_' . $globals['site_shortname'] . $from . '_' . $current_page; } if ($range_values[$from] > 0) { // we use this to allow sql caching $from_time = '"' . date("Y-m-d H:i:00", time() - 86400 * $range_values[$from]) . '"'; $sql = "SELECT SQL_CACHE link_id, link_votes-link_negatives as votes FROM links, sub_statuses WHERE id = " . SitesMgr::my_id() . " AND date > {$from_time} AND status = 'published' AND link_id = link ORDER BY votes DESC "; $time_link = "date > {$from_time} AND"; } else { // Default $sql = "SELECT SQL_CACHE link_id, link_votes-link_negatives as votes FROM links, sub_statuses WHERE id = " . SitesMgr::my_id() . " AND status = 'published' AND link = link_id ORDER BY votes DESC "; $time_link = ''; } } if (!($memcache_key && ($rows = memcache_mget($memcache_key . 'rows')) && ($links = unserialize(memcache_mget($memcache_key))))) { // It's not in cache, or memcache is disabled $rows = $db->get_var("SELECT count(*) FROM sub_statuses WHERE id = " . SitesMgr::my_id() . " AND {$time_link} status = 'published'"); if ($rows > 0) { $links = $db->get_results("{$sql} LIMIT {$offset},{$page_size}"); if ($memcache_key) { if ($range_values[$from] > 2) { $ttl = 86400; } else { $ttl = 1800; } memcache_madd($memcache_key . 'rows', $rows, $ttl); memcache_madd($memcache_key, serialize($links), $ttl); } } } do_header(_('más votadas') . ' | ' . $globals['site_name'], _('populares')); $globals['tag_status'] = 'published';
if ($from >= count($range_values) || $from < 0) { $from = 0; } // Use memcache if available if ($globals['memcache_host'] && $current_page < 4) { $memcache_key = 'topclicked_' . $globals['site_shortname'] . $from . '_' . $current_page; } if ($range_values[$from] > 0) { // we use this to allow sql caching $from_time = '"' . date("Y-m-d H:i:00", time() - 86400 * $range_values[$from]) . '"'; if ($from > 0) { $status = "AND status = 'published'"; } else { $status = "AND status in ('published', 'queued')"; } $sql = "SELECT link_id, counter FROM sub_statuses, links, link_clicks WHERE sub_statuses.id = " . SitesMgr::my_id() . " AND date > {$from_time} {$status} AND link = link_id AND link_clicks.id = link_id ORDER BY counter DESC "; $time_link = "date > {$from_time}"; } } if (!($memcache_key && ($rows = memcache_mget($memcache_key . 'rows')) && ($links = unserialize(memcache_mget($memcache_key))))) { // It's not in cache, or memcache is disabled $rows = $db->get_var("SELECT count(*) FROM sub_statuses WHERE {$time_link} {$status}"); $rows = min(4 * $page_size, $rows); // Only up to 4 pages if ($rows > 0) { $links = $db->get_results("{$sql} LIMIT {$offset},{$page_size}"); if ($memcache_key) { $ttl = 1800; memcache_madd($memcache_key . 'rows', $rows, $ttl); memcache_madd($memcache_key, serialize($links), $ttl); }
function check_field_errors() { global $globals; $errors = array(); if (!$this->sub_id > 0) { $errors[] = _("sub no seleccionado"); $site_id = SitesMgr::my_id(); } else { $site_id = $this->sub_id; } $properties = SitesMgr::get_extended_properties($site_id); if (empty($this->url) && empty($properties['no_link'])) { $errors[] = _("falta url enlace"); } // Filter content and title // It also deletes punctuaction marks at the end $this->title = clean_text(preg_replace('/(\\w) *[.,] *$/', "\$1", $this->title), 50, true, 120); if ($properties['allow_paragraphs']) { $replace_nl = false; } else { $replace_nl = true; } $this->content = clean_text_with_tags($this->content, 0, $replace_nl, $properties['intro_max_len']); if (mb_strlen($this->title) < 8) { $errors[] = _("título incompleto"); } if (get_uppercase_ratio($this->title) > 0.5) { $errors[] = "demasiadas mayúsculas en el título"; } /* The length is already constrained in clean_text() if(mb_strlen(html_entity_decode($this->title, ENT_COMPAT, 'UTF-8'), 'UTF-8') > 120) { $errors[] = ("título demasiado largo"); } */ if ($properties['intro_max_len'] > 0 && $properties['intro_min_len'] > 0 && mb_strlen($this->content) < $properties['intro_min_len']) { $errors[] = _("texto incompleto"); } if (get_uppercase_ratio($this->content) > 0.3) { $errors[] = "demasiadas mayúsculas en el texto"; } /* Already constrained in clean_text_with_tags() if( $properties['intro_max_len'] > 0 && mb_strlen(html_entity_decode($this->content, ENT_COMPAT, 'UTF-8'), 'UTF-8') > $properties['intro_max_len'] ) { $errors[] = ("texto demasiado largo"); } */ if (strlen($this->tags) < 3) { $errors[] = "no has puesto etiquetas"; } if (preg_match('/.*http:\\//', $this->title)) { $errors[] = "no pongas URLs en el título, no ofrece información"; } return $errors; }
// Show only discarded in four days $globals['noindex'] = true; $globals['ads'] = false; $from_time = '"' . date("Y-m-d H:00:00", $globals['now'] - 86400 * 4) . '"'; $where = "sub_statuses.id = " . SitesMgr::my_id() . " AND status in ('discard', 'abuse', 'autodiscard') "; $order_by = "ORDER BY date DESC "; $tab = 5; $globals['tag_status'] = 'discard'; $rows = Link::count('discard') + Link::count('autodiscard') + Link::count('abuse'); break; case '_all': default: $globals['tag_status'] = 'queued'; $order_by = "ORDER BY date DESC"; $rows = Link::count('queued'); $where = "sub_statuses.id = " . SitesMgr::my_id() . " AND status='queued' "; $tab = 1; break; } $pagetitle = _('noticias pendientes'); if ($page > 1) { $pagetitle .= " ({$page})"; } do_header($pagetitle, _('nuevas')); print_shakeit_tabs($tab); /*** SIDEBAR ****/ echo '<div id="sidebar">'; do_sub_message_right(); do_banner_right(); if ($globals['show_popular_queued']) { do_best_queued();
<?php // Don't check the user is logged $globals['no_auth'] = true; $globals['no_lounge'] = true; include 'config.php'; header("Content-Type: text/plain"); // Chech for cache typical dirs for ($i = 0; $i < 10; $i++) { if (is_dir($globals['cache_dir'] . '/0' . $i)) { if (empty($globals['maintenance'])) { echo "pong (" . SitesMgr::my_id() . ")\n"; // Force a DB access } else { echo "pong\n"; } die; } } header('HTTP/1.1 500 Server error');
} SitesMgr::__init($my_id); syslog(LOG_INFO, "Meneame, running " . basename(__FILE__) . " for {$site_name}"); $info = SitesMgr::get_info(); $properties = SitesMgr::get_extended_properties(); if (intval($argv[1]) > 0) { $hours = intval($argv[1]); } else { $hours = 24; } // Get most voted link $link_sqls[_('Más votada')] = "select vote_link_id as id, count(*) as n from sub_statuses, links, votes use index (vote_type_4) where id = " . SitesMgr::my_id() . " AND link_id = link AND link_status = 'published' AND vote_link_id = link AND vote_type='links' and vote_date > date_sub(now(), interval {$hours} hour) and vote_user_id > 0 and vote_value > 0 group by vote_link_id order by n desc limit 1"; // Most commented $link_sqls[_('Más comentada')] = "select comment_link_id as id, count(*) as n from sub_statuses, comments use index (comment_date) where id = " . SitesMgr::my_id() . " AND sub_statuses.status in ('published', 'metapublished') AND comment_link_id = link AND comment_date > date_sub(now(), interval {$hours} hour) group by comment_link_id order by n desc limit 1"; if ($globals['click_counter'] && $hours > 20) { $link_sqls[_('Más leída')] = "select sub_statuses.link as id, counter as n from sub_statuses, link_clicks where sub_statuses.id = " . SitesMgr::my_id() . " AND sub_statuses.status in ('published', 'metapublished') AND date > date_sub(now(), interval {$hours} hour) and link_clicks.id = sub_statuses.link order by n desc limit 1"; } foreach ($link_sqls as $key => $sql) { $res = $db->get_row($sql); if (!$res) { continue; } $link = new Link(); $link->id = $res->id; if ($link->read()) { $url = $link->get_permalink($info->sub); if ($globals['url_shortener']) { $short_url = $link->get_short_permalink(); } else { //$short_url = fon_gs($link->get_permalink()); $short_url = $url;
} else { $option = _('todos'); } // Haanga::Load('sneak/tabs.html', compact('option')); } ////// // Start html $globals['extra_css'][] = 'es/sneak.css'; if (!empty($_REQUEST['friends'])) { do_header(_('amigos en la fisgona'), _('fisgona'), sneak_menu_items($option)); } elseif ($current_user->user_id > 0 && !empty($_REQUEST['admin']) && $current_user->admin) { do_header(_('admin'), _('fisgona'), sneak_menu_items($option)); } else { do_header(_('fisgona'), _('fisgona'), sneak_menu_items($option)); } $globals['site_id'] = SitesMgr::my_id(); Haanga::Load('sneak/base.html'); $globals['sneak_telnet'] = false; Haanga::Load('sneak/form.html', compact('max_items')); do_footer(); function sneak_menu_items($id) { global $globals, $current_user; $items = array(); $items[] = new MenuOption(_('todos'), $globals['base_url'] . 'sneak', $id, _('todos')); $items[] = new MenuOption(_('amigos'), $globals['base_url'] . 'sneak?friends=1', $id, _('amigos')); if ($current_user->admin) { $items[] = new MenuOption(_('admin'), $globals['base_url'] . 'sneak?admin=1', $id, _('admin')); } $items[] = new MenuOption(_('consola'), $globals['base_url'] . 'telnet', $id, _('consola')); return $items;
<?php // The source code packaged with this file is Free Software, Copyright (C) 2005 by // Ricardo Galli <gallir at uib dot es>. // It's licensed under the AFFERO GENERAL PUBLIC LICENSE unless stated otherwise. // You can get copies of the licenses here: // http://www.affero.org/oagpl.html // AFFERO GENERAL PUBLIC LICENSE is also included in the file called "COPYING". include 'config.php'; include mnminclude . 'html1-mobile.php'; include mnminclude . 'linkmobile.php'; $page_size = 20; $offset = (get_current_page() - 1) * $page_size; do_header(_('pendientes') . ' | ' . $globals['site_name']); do_tabs("main", "shakeit"); echo '<div id="newswrap">' . "\n"; $rows = Link::count('queued'); $links = $db->object_iterator("SELECT" . Link::SQL . "INNER JOIN (SELECT link FROM sub_statuses {$from} WHERE sub_statuses.id = " . SitesMgr::my_id() . " AND status = 'queued' ORDER by date desc LIMIT {$offset},{$page_size}) as ids ON (ids.link = link_id)", "LinkMobile"); if ($links) { foreach ($links as $link) { $link->print_summary(); } } do_pages($rows, $page_size); echo '</div>' . "\n"; do_footer();
function get_subs_coef($site_id, $days = 3) { global $globals, $db, $output; if (empty($globals['sub_balance_metas']) || !in_array(SitesMgr::my_id(), $globals['sub_balance_metas'])) { return array(); } /// Coeficients to balance metacategories $imported = $db->get_col("select src from subs_copy where dst = {$site_id}"); if (empty($imported)) { return array(); } $imported = implode(',', $imported); $totals = $db->get_results("select SQL_NO_CACHE origen, status, subs.name as name from sub_statuses, subs where sub_statuses.id = {$site_id} and status in ('queued', 'published') and date > date_sub(now(), interval {$days} day) and origen in ({$imported}) and origen = subs.id"); $totals_sent = array(); $totals_published = array(); $names = array(); $subs = array(); $total_published = 0; $total_sent = 0; foreach ($totals as $sub) { $names[$sub->origen] = $sub->name; switch ($sub->status) { case 'published': $total_published++; $totals_published[$sub->origen]++; default: $total_sent++; $totals_sent[$sub->origen]++; } if (!in_array($sub->origen, $subs)) { $subs[] = $sub->origen; } } $average = $total_published / $total_sent; $subs_coef = array(); foreach ($subs as $s) { $x = $totals_published[$s]; $y = $totals_sent[$s]; if ($y == 0) { $y = 1; } $c = $x / $y; $subs_coef[$s] = 0.7 * $c + 0.3 * $x / $total_published / count($subs); $output .= "{$days} days stats for <b>{$names[$s]}</b> (queued/published/total): {$y}/{$x}/{$total_published} -> {$subs_coef[$s]}<br/>"; } foreach ($subs_coef as $s => $v) { $subs_coef[$s] = max(min($average / $v, 1.5), 0.7); $output .= "Karma coefficient for <b>{$names[$s]}</b>: {$subs_coef[$s]}<br/>"; } // Store current coef in DB $log = new Annotation("subs-coef-{$site_id}"); $log->text = serialize($subs_coef); $log->store(); echo "DONE META SUBS\n"; return $subs_coef; }
do_tabs("main", "shakeit"); print_shakeit_tabs($tab); /*** SIDEBAR ****/ echo '<div id="sidebar">'; do_banner_right(); if ($globals['show_popular_queued']) { do_best_queued(); } do_last_blogs(); //do_best_comments(); //do_categories_cloud('queued', 24); do_vertical_tags('queued'); echo '</div>' . "\n"; /*** END SIDEBAR ***/ echo '<div id="newswrap">' . "\n"; $sql = "SELECT" . Link::SQL . "INNER JOIN (SELECT link FROM sub_statuses {$from} WHERE sub_statuses.id = " . SitesMgr::my_id() . " AND {$where} {$order_by} LIMIT {$offset},{$page_size}) as ids on (ids.link = link_id)"; $links = $db->object_iterator($sql, "Link"); if ($links) { foreach ($links as $link) { if ($link->votes == 0 && $link->author != $current_user->user_id) { continue; } if ($offset < 1000) { $link->print_summary('full', 16); } else { $link->print_summary('full'); } } } do_pages($rows, $page_size); echo '</div>' . "\n";
include mnminclude . 'html1.php'; $min_pts = 10; $max_pts = 50; $words_limit = 100; $line_height = $max_pts * 0.75; //$range_names = array(_('24 horas'), _('48 horas'), _('una semana'), _('un mes'), _('un año'), _('todas')); //$range_values = array(1, 2, 7, 30, 365, 0); $range_names = array(_('24 horas'), _('48 horas'), _('una semana')); $range_values = array(1, 2, 7); $from = check_integer('range'); if ($from > count($range_values) || !$range_values[$from]) { $from = 0; } // we use this to allow sql caching $from_time = '"' . date("Y-m-d H:00:00", time() - 86400 * $range_values[$from]) . '"'; $from_where = "FROM links, sub_statuses WHERE id = " . SitesMgr::my_id() . " AND link_id = link AND link_date > {$from_time} and link_status != 'discard'"; do_header(_('nube de etiquetas') . ' | ' . _('menéame')); do_tabs('main', _('etiquetas'), true); print_period_tabs(); /*** SIDEBAR ****/ echo '<div id="sidebar">'; do_banner_right(); do_best_stories(); echo '</div>' . "\n"; /*** END SIDEBAR ***/ echo '<div id="newswrap">' . "\n"; echo '<div class="topheading"><h2>+ ' . $words_limit . '</h2></div>'; echo '<div style="margin: 0px 0 20px 0; line-height: ' . $line_height . 'pt; margin-left: 25px;">'; $res = $db->get_col("select link_tags {$from_where}"); if ($res) { $max = 0;
#! /usr/bin/env php <?php // This file post the indicated link to ever twitter o facebook account // Argument required: hostname, link_id if (count($argv) != 3) { syslog(LOG_INFO, "Usage: " . basename(__FILE__) . " site_id hostname link_id"); echo "Usage: " . basename(__FILE__) . " site_id hostname link_id\n"; die; } $hostname = $argv[1]; $link_id = (int) $argv[2]; $_SERVER['SERVER_NAME'] = $hostname; include dirname(__FILE__) . '/../config.php'; include mnminclude . 'external_post.php'; $my_id = SitesMgr::my_id(); if (!$my_id) { syslog(LOG_INFO, "Meneame, post_link.php, site not found {$hostname}"); echo "No site id found\n"; die; } $link = Link::from_db($link_id); if (!$link) { syslog(LOG_INFO, "Meneame, post_link.php, link not found {$link_id}"); echo "Link {$link_id} not found\n"; die; } do_posts($link); function do_posts($link) { global $globals; syslog(LOG_INFO, "Meneame, posting {$link->uri}");
function sphinx_do_search($by_date = false, $start = 0, $count = 10, $proximity = true) { global $globals; $response = array(); $queries = array(); $recorded = array(); $start_time = microtime(true); $indices = $_REQUEST['w'] . ' ' . $_REQUEST['w'] . '_delta'; $cl = sphinx_client(); if (!$cl) { return $response; } $cl->SetLimits($start, $count); if ($_REQUEST['w'] == 'links') { $cl->SetFieldWeights(array('title' => 3, 'tags' => 3, 'url' => 1, 'content' => 1)); } else { $cl->SetFieldWeights(array('content' => 1)); } // Function to filter by sub site if ($_REQUEST['w'] == 'links' && $globals['submnm']) { $subs = array(); $subs[] = SitesMgr::my_id(); $subs = array_merge($subs, SitesMgr::get_sub_subs_ids()); $cl->SetFilter('sub', $subs); } $response['rows'] = 0; $response['time'] = 0; if (empty($_REQUEST['words'])) { return $response; } $words_array = preg_split('/\\s+/', $_REQUEST['words'], -1, PREG_SPLIT_NO_EMPTY); $words_count = count($words_array); $words = $_REQUEST['words']; if ($_REQUEST['t']) { $max_date = time(); $min_date = intval($_REQUEST['t']); $cl->SetFilterRange('date', $min_date, $max_date); } if ($_REQUEST['h']) { $max_date = time(); $min_date = $max_date - intval($_REQUEST['h']) * 3600; $cl->SetFilterRange('date', $min_date, $max_date); } if ($_REQUEST['yymm']) { $yymm = intval($_REQUEST['yymm']); $yy = intval($yymm / 100); $mm = $yymm - $yy * 100; $min_date = mktime(0, 0, 0, $mm, 1, $yy); if ($mm == 12) { $mm = 1; $yy++; } else { $mm++; } $max_date = mktime(0, 0, 0, $mm, 1, $yy); $cl->SetFilterRange('date', $min_date, $max_date); } if ($_REQUEST['w'] == 'links' && $_REQUEST['s']) { if (preg_match('/^ *! */', $_REQUEST['s'])) { // Allows to reject a status $_REQUEST['s'] = preg_replace('/^ *! */', '', $_REQUEST['s']); $s_reject = true; } else { $s_reject = false; } // Allow multiple statuses $statuses = preg_split('/\\s+/', $_REQUEST['s'], -1, PREG_SPLIT_NO_EMPTY); $s_id = array(); foreach ($statuses as $s) { if (isset($globals['status_values'][$s])) { array_push($s_id, $globals['status_values'][$s]); } } if (count($s_id) > 0) { $cl->SetFilter('status', $s_id, $s_reject); } } if ($_REQUEST['u']) { $u = new User(); $u->username = $_REQUEST['u']; $u->read(); $cl->SetFilterRange('user', $u->id, $u->id); } if ($_REQUEST['w'] == 'links' && $_REQUEST['p']) { $f = '@' . $_REQUEST['p']; } else { $f = '@*'; } if ($by_date || $_REQUEST['o'] == 'date' || $_REQUEST['p'] == 'url') { $cl->SetSortMode(SPH_SORT_ATTR_DESC, 'date'); } elseif ($_REQUEST['o'] == 'pure') { $cl->SetSortMode(SPH_SORT_RELEVANCE); } else { // If "root_time", it will center the search on that timestamp if ($_REQUEST['root_time'] > 0) { $now = intval($_REQUEST['root_time']); } else { $now = time(); } // expressions to decrease weights logarimically if ($_REQUEST['w'] == 'links') { $p = $globals['status_values']['published']; $q = $globals['status_values']['queued']; $b = log(0.9) / 720; $fp = "@weight * max(0.4, exp({$b}*abs({$now}-date)/3600))"; $b = log(0.5) / 720; $fq = "@weight * max(0.25, exp({$b}*abs({$now}-date)/3600))"; $b = log(0.2) / 720; $fo = "@weight * max(0.1, exp({$b}*abs({$now}-date)/3600))"; $exp = "if (status-{$p} = 0, {$fp} , if (status-{$q} = 0, {$fq}, {$fo}))"; } else { $b = log(0.95) / 720; $exp = "@weight * max(0.5, exp({$b}*abs({$now}-date)/3600))"; } $cl->SetSortMode(SPH_SORT_EXPR, $exp); } $cl->SetMatchMode(SPH_MATCH_EXTENDED); // TODO: Alert, deprecated in 2.2 if ($words_count == 1 || $_REQUEST['p'] == 'url') { $cl->SetRankingMode(SPH_RANK_NONE); } elseif ($proximity) { $cl->SetRankingMode(SPH_RANK_PROXIMITY_BM25); } else { $cl->SetRankingMode(SPH_RANK_BM25); } // Used for related links if ($_REQUEST['p'] == 'url') { // It allows to search for several domains/url for ($i = 0; $i < count($words_array); $i++) { $words_array[$i] = '="' . $cl->EscapeString($words_array[$i]) . '"'; } $query = implode(" | ", $words_array); // Add the "OR" for several domain $q = $cl->AddQuery("{$f} {$query}", $indices); array_push($queries, $q); } else { if ($words_count < 5) { $q = $cl->AddQuery("{$f} {$words}", $indices); array_push($queries, $q); } } // If there are no boolean opertions, add a new search for ANY of the terms // Take in account phrases in between " and ' if (!preg_match('/( and | or | [\\-\\+\\&\\|])/i', $words) && $words_count > 1 && $_REQUEST['p'] != 'url') { $words = ''; $quotes = 0; $c = 0; foreach ($words_array as $w) { if ($c > 0 && $quotes == 0) { $words .= ' | '; } if ($quotes == 0 && preg_match('/^["\']/', $w)) { $quotes++; } if ($quotes > 0 && preg_match('/["\'](\\~{0,1}\\d+){0,1}$/', $w)) { $quotes--; } $words .= " {$w}"; $c++; } $q = $cl->AddQuery("{$f} {$words}", $indices); array_push($queries, $q); } $results = $cl->RunQueries(); $n = 0; $response['error'] = $results['error']; foreach ($queries as $q) { $res = $results[$q]; if (is_array($res["matches"])) { $response['rows'] += $res["total_found"]; foreach ($res["matches"] as $doc => $docinfo) { if (!$recorded[$doc]) { $response['ids'][$n] = $doc; $response['weights']["{$doc}"] = $docinfo['weight']; $recorded[$doc] = true; $n++; } else { $response['rows']--; } } } } $response['time'] = microtime(true) - $start_time; return $response; }
include mnminclude . 'html1.php'; $page_size = $globals['page_size']; $range_names = array(_('24 horas'), _('48 horas'), _('una semana'), _('un mes')); $range_values = array(1, 2, 7, 30); $offset = (get_current_page() - 1) * $page_size; $from = intval($_GET['range']); if ($from >= count($range_values) || $from < 0) { $from = 0; } if ($range_values[$from] > 0) { // we use this to allow sql caching $from_time = '"' . date("Y-m-d H:00:00", time() - 86400 * $range_values[$from]) . '"'; $sql = "SELECT link_id, link_comments as comments FROM links, sub_statuses WHERE id = " . SitesMgr::my_id() . " AND status = 'published' AND date > {$from_time} AND link_id = link ORDER BY link_comments DESC "; $time_link = "date > FROM_UNIXTIME({$from_time})"; } else { $sql = "SELECT link_id, link_comments as comments FROM links, sub_statuses WHERE id = " . SitesMgr::my_id() . " AND status = 'published' AND link_id = link ORDER BY link_comments DESC "; $time_link = ''; } do_header(_('más comentadas') . ' | ' . $globals['site_name']); do_tabs('main', _('más comentadas'), true); print_period_tabs(); /*** SIDEBAR ****/ echo '<div id="sidebar">'; do_banner_right(); do_best_stories(); do_best_comments(); do_vertical_tags('published'); echo '</div>' . "\n"; /*** END SIDEBAR ***/ echo '<div id="newswrap">' . "\n"; echo '<div class="topheading"><h2>' . _('noticias más comentadas') . '</h2></div>';
function check_redirect_to_feedburner($status) { global $globals; $regex = '/' . $globals['rss_redirect_user_agent'] . '|pubsub|meneame|burner/i'; if (SitesMgr::my_id() > 1 || isset($_REQUEST['local']) || isset($_REQUEST['nohtml']) || $globals['bot'] || !$globals['rss_redirect_user_agent'] || preg_match($regex, htmlspecialchars($_SERVER['PHP_SELF'])) || preg_match($regex, $_SERVER['HTTP_USER_AGENT'])) { return; } /*|| preg_match('/technoratibot/i', $_SERVER['HTTP_USER_AGENT']) */ if (!empty($globals['rss_redirect_' . $status])) { header('Location: ' . $globals['rss_redirect_' . $status]); exit; } }
// The source code packaged with this file is Free Software, Copyright (C) 2005 by // Ricardo Galli <gallir at uib dot es>. // It's licensed under the AFFERO GENERAL PUBLIC LICENSE unless stated otherwise. // You can get copies of the licenses here: // http://www.affero.org/oagpl.html // AFFERO GENERAL PUBLIC LICENSE is also included in the file called "COPYING". include 'config.php'; include mnminclude . 'html1.php'; $min_pts = 10; $max_pts = 44; $limit = 200; $line_height = $max_pts * 0.75; $range_names = array(_('24 horas'), _('48 horas'), _('una semana'), _('un mes'), _('un año'), _('todas')); $range_values = array(1, 2, 7, 30, 365, 0); $site_id = SitesMgr::my_id(); if (($from = check_integer('range')) >= 0 && $from < count($range_values) && $range_values[$from] > 0) { // we use this to allow sql caching $from_time = '"' . date("Y-m-d H:00:00", time() - 86400 * $range_values[$from]) . '"'; $from_where = "FROM blogs, links, sub_statuses WHERE id = {$site_id} and date > {$from_time} and status = 'published' and link = link_id and link_blog = blog_id"; } else { $from_where = "FROM blogs, links, sub_statuses WHERE id = {$site_id} and status = 'published' and link = link_id and link_blog = blog_id"; } $from_where .= " GROUP BY blog_id"; $max = max($db->get_var("select count(*) as count {$from_where} order by count desc limit 1"), 2); //echo "MAX= $max\n"; $coef = ($max_pts - $min_pts) / ($max - 1); do_header(_('nube de sitios web') . ' | ' . _('menéame')); do_tabs("main", _('+ webs'), true); print_period_tabs(); /*** SIDEBAR ****/
// The source code packaged with this file is Free Software, Copyright (C) 2005 by // Ricardo Galli <gallir at uib dot es>. // It's licensed under the AFFERO GENERAL PUBLIC LICENSE unless stated otherwise. // You can get copies of the licenses here: // http://www.affero.org/oagpl.html // AFFERO GENERAL PUBLIC LICENSE is also included in the file called "COPYING". include_once 'config.php'; include mnminclude . 'html1-mobile.php'; include mnminclude . 'linkmobile.php'; $page_size = 10; $page = get_current_page(); $offset = ($page - 1) * $page_size; $cat = $_REQUEST['category']; do_header($globals['site_name']); do_tabs('main', 'published'); echo '<div id="newswrap">' . "\n"; if ($page == 1 && ($top = Link::top())) { $vars = array('self' => $top); Haanga::Load("mobile/link_top.html", $vars); } $rows = Link::count('published'); $sql = "SELECT" . Link::SQL . "INNER JOIN (SELECT link FROM sub_statuses {$from} WHERE sub_statuses.id = " . SitesMgr::my_id() . " AND status = 'published' ORDER by date desc LIMIT {$offset},{$page_size}) as ids ON (ids.link = link_id)"; $links = $db->object_iterator($sql, "LinkMobile"); if ($links) { foreach ($links as $link) { $link->print_summary(); } } do_pages($rows, $page_size); echo '</div>' . "\n"; do_footer();
function get_votes($dbtime) { global $db, $events, $last_timestamp, $foo_link, $max_items, $current_user; $res = $db->get_results("select vote_id, unix_timestamp(vote_date) as timestamp, vote_value, INET_NTOA(vote_ip_int) as vote_ip, vote_user_id, link_id, link_title, link_uri, link_status, link_date, link_votes, link_anonymous, link_comments from votes, links, sub_statuses where sub_statuses.id = " . SitesMgr::my_id() . " and vote_type='links' and vote_date > {$dbtime} and link_id = sub_statuses.link and sub_statuses.link = vote_link_id and vote_user_id != link_author order by vote_date desc limit {$max_items}"); if (!$res) { return; } foreach ($res as $event) { if ($current_user->user_id > 0) { if (!empty($_REQUEST['friends']) && $event->vote_user_id != $current_user->user_id) { // Check the user is a friend if (User::friend_exists($current_user->user_id, $event->vote_user_id) <= 0) { continue; } elseif ($event->vote_value < 0) { // If the vote is negative, verify also the other user has selected as friend to the current one if (User::friend_exists($event->vote_user_id, $current_user->user_id) <= 0) { continue; } } } elseif (!empty($_REQUEST['admin']) && $current_user->admin) { $user_level = $db->get_var("select user_level from users where user_id={$event->vote_user_id}"); if ($user_level != 'admin' && $user_level != 'god') { continue; } } } if ($event->vote_value >= 0) { if ($_REQUEST['novote']) { continue; } if ($event->link_status == 'published' && $_REQUEST['nopubvotes']) { continue; } } else { if ($_REQUEST['noproblem']) { continue; } } $foo_link->id = $event->link_id; $foo_link->uri = $event->link_uri; $foo_link->get_relative_permalink(); $uid = $event->vote_user_id; if ($event->vote_user_id > 0) { $res = $db->get_row("select user_login from users where user_id = {$event->vote_user_id}"); $user = $res->user_login; } else { $user = preg_replace('/\\.[0-9]+$/', '', $event->vote_ip); } if ($event->vote_value >= 0) { $type = 'vote'; $who = $user; } else { $type = 'problem'; $who = get_negative_vote($event->vote_value); // Show user_login if she voted more than N negatives in one minute if ($current_user->user_id > 0 && $current_user->admin) { $negatives_last_minute = $db->get_var("select count(*) from votes where vote_type='links' and vote_user_id={$event->vote_user_id} and vote_date > date_sub(now(), interval 30 second) and vote_value < 0"); if ($negatives_last_minute > 2) { $who .= "<br>({$user})"; } } } $json['status'] = get_status($event->link_status); $json['type'] = $type; $json['ts'] = $event->timestamp; $json['votes'] = $event->link_votes + $event->link_anonymous; $json['com'] = $event->link_comments; $json['link'] = $foo_link->get_relative_permalink(); $json['title'] = $event->link_title; $json['who'] = $who; $json['uid'] = $event->vote_user_id; $json['id'] = $event->link_id; if ($event->vote_user_id > 0) { $json['icon'] = get_avatar_url($event->vote_user_id, -1, 20); } $key = $event->timestamp . ':votes:' . $event->vote_id; $events[$key] = $json; if ($event->timestamp > $last_timestamp) { $last_timestamp = $event->timestamp; } } }
if (!$current_user->user_id > 0) { do_error(_('debe autentificarse'), 401); } // Check authenticated users $from_time = '"' . date("Y-m-d H:00:00", $globals['now'] - 86400 * 4) . '"'; $from = ", friends, links"; $where = "sub_statuses.id = " . SitesMgr::my_id() . " AND date > {$from_time} and status='published' and friend_type='manual' and friend_from = {$current_user->user_id} and friend_to=link_author and friend_value > 0 and link_id = link"; $rows = -1; print_index_tabs(1); // Friends break; default: print_index_tabs(0); // All $rows = Link::count('published'); $where = "sub_statuses.id = " . SitesMgr::my_id() . " AND status='published' "; } /*** SIDEBAR ****/ echo '<div id="sidebar" class="col-sm-3 col-md-3 col-lg-3">'; do_sub_message_right(); do_banner_right(); if ($globals['show_popular_published']) { do_active_stories(); } // do_banner_promotions(); if ($globals['show_popular_published']) { do_most_clicked_stories(); do_best_stories(); } do_banner_promotions(); // do_best_sites();
$top = new Annotation('top-actives-' . $globals['site_shortname']); if ($top->read()) { $links = explode(',', $top->text); } } elseif (isset($_REQUEST['popular'])) { $min_date = date("Y-m-d H:i:00", $globals['now'] - 129600); // 36 hours // The order is not exactly the votes // but a time-decreasing function applied to the number of votes $sql = "select link_id, (link_votes-link_negatives*2)*(1-(unix_timestamp(now())-unix_timestamp(link_date))*0.8/129600) as value from links, sub_statuses where id = " . SitesMgr::my_id() . " AND link_id = link AND status='published' and date > '{$min_date}' order by value desc limit 25"; } elseif (isset($_REQUEST['top_visited'])) { $min_date = date("Y-m-d H:i:00", $globals['now'] - 172800); // 48 hours // The order is not exactly the votes // but a time-decreasing function applied to the number of votes $sql = "select link_id, counter*(1-(unix_timestamp(now())-unix_timestamp(link_date))*0.5/172800) as value from links, link_clicks, sub_statuses where sub_statuses.id = " . SitesMgr::my_id() . " AND link_id = link AND status='published' and date > '{$min_date}' and link_clicks.id = link order by value desc limit 25"; } else { ///// // All the others ///// // The link_status to search if (!empty($_REQUEST['status'])) { $status = $db->escape(clean_input_string(trim($_REQUEST['status']))); } else { // By default it searches on all if ($_REQUEST['q']) { $status = 'all'; include mnminclude . 'search.php'; $search_ids = do_search(true); if ($search_ids['ids']) { $search = ' link_id in (' . implode(',', $search_ids['ids']) . ')';
$time = intval($time_f); $dbtime = date("YmdHis", intval($time)); $last_timestamp = $time_f; if (!empty($_REQUEST['site_id']) && $_REQUEST['site_id'] > 0) { $globals['site_id'] = intval($_REQUEST['site_id']); } if (!empty($_REQUEST['items']) && intval($_REQUEST['items']) > 0) { $max_items = intval($_REQUEST['items']); } if ($max_items < 1 || $max_items > 100) { $max_items = 100; // Avoid abuse } // Get the logs by sub, if it's a sub if ($globals['submnm']) { $subs = array_merge(array(SitesMgr::my_id()), SitesMgr::get_senders(), SitesMgr::get_receivers()); $globals['subs'] = $subs = implode(',', $subs); $site_filter = "and log_sub in ({$subs})"; } else { $site_filter = ''; } if (empty($_REQUEST['novote']) || empty($_REQUEST['noproblem'])) { get_votes($dbtime); } $logs = $db->get_results("select UNIX_TIMESTAMP(log_date) as time, log_type, log_ref_id, log_user_id from logs where log_type != 'login_failed' and log_date > {$dbtime} {$site_filter} order by log_date desc limit {$max_items}"); if ($logs) { foreach ($logs as $log) { if ($current_user->user_id > 0) { if (!empty($_REQUEST['friends']) && $log->log_user_id != $current_user->user_id) { // Check the user is a friend if (User::friend_exists($current_user->user_id, $log->log_user_id) <= 0) {