static function __init($id = false) { global $globals, $db; self::$info = false; if ($id > 0) { self::$id = $id; } elseif (!isset($globals['site_id'])) { if (empty($globals['site_shortname'])) { echo "Error, site_shortname not found, check your global['site_shortname']: " . $globals['site_shortname']; } self::$info = $db->get_row("select * from subs where name = '" . $globals['site_shortname'] . "'"); if (self::$info) { self::$id = self::$info->id; } else { self::$id = 0; return; } } else { self::$id = $globals['site_id']; } if (self::$info == false) { self::$info = $db->get_row("select * from subs where id = " . self::$id); } self::$parent = self::$info->created_from; if (self::$id > 0) { $db->query('set @site_id = ' . self::$id); } }
function do_posts($link) { global $globals; $info = SitesMgr::get_info(); $properties = SitesMgr::get_extended_properties(); syslog(LOG_INFO, "Meneame, posting {$link->uri}"); $url = $link->get_permalink($info->sub); echo "Posting {$url}: " . $globals['server_name'] . "\n"; // NEW format $image = false; if ($link->has_thumb()) { $media = $link->get_media(); if ($media && file_exists($media->pathname())) { $image = $media->pathname(); } } if ($globals['url_shortener']) { $short_url = $link->get_short_permalink(); } else { $short_url = $url; } if (!empty($properties['twitter_token']) && !empty($properties['twitter_token_secret']) && !empty($properties['twitter_consumer_key']) && !empty($properties['twitter_consumer_secret'])) { $r = false; $tries = 0; while (!$r && $tries < 4) { $r = twitter_post($properties, $link->title, $url, $image); $tries++; if (!$r) { sleep(4); } } } if (!empty($properties['facebook_token']) && !empty($properties['facebook_key']) && !empty($properties['facebook_secret'])) { $r = false; $tries = 0; while (!$r && $tries < 4) { $r = facebook_post($properties, $link); $tries++; if (!$r) { sleep(4); } } } /* if ($globals['pubsub']) { pubsub_post(); } */ }
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; }
static function __init($id = false) { global $globals, $db; if ($id > 0) { self::$id = $id; } elseif (!isset($globals['site_id'])) { $res = $db->get_row("select id, parent from subs where name = '" . $globals['site_shortname'] . "'"); self::$id = $res->id; self::$parent = $res->parent; if (!self::$id) { echo "Error, site_shortname not found, check your global['site_shortname']: " . $globals['site_shortname']; } } else { self::$id = $globals['site_id']; } if (self::$parent === false && self::$id > 0) { self::$parent = (int) $db->get_var("select parent from subs where id = " . self::$id); } }
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"; }
static function insert($type, $ref_id, $user_id = 0, $annotation = false) { global $db, $globals; if ($globals['behind_load_balancer'] && $globals['form_user_ip']) { // If the page stored the "real IP" in a form $ip = $globals['form_user_ip']; $ip_int = inet_ptod($globals['form_user_ip']); } else { $ip = $globals['user_ip']; $ip_int = $globals['user_ip_int']; } $sub = SitesMgr::my_parent(); // 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; }
// 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 ****/
#! /usr/bin/env php <?php // Check which hostname server we run for, for example: mnm, emnm, etc. $site_name = $argv[2]; include dirname(__FILE__) . '/../www/config.php'; include mnminclude . 'external_post.php'; $my_id = SitesMgr::get_id($site_name); if (!$my_id > 0) { syslog(LOG_INFO, "Meneame, " . basename(__FILE__) . " site not found {$site_name}"); echo "No site id found\n"; die; } 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 = 1; } $key = "post_best_comment_{$my_id}"; $previous = Annotation::get_text($key); if ($previous) { $extra = "AND comment_id not in ({$previous})"; } $now = intval(time() / 60) * 60; $coef = 0.8; $min_karma = $globals['comment_highlight_karma'] * 2; $min_value = $globals['comment_highlight_karma']; $min_length = 400;
<?php $path = $globals['path']; $globals['submnm'] = preg_replace('/[^\\p{L}\\d_]/u', ':', $path[1]); include_once 'config.php'; $forbidden_routes = array('m', 'user', 'legal', 'notame', 'mobile', 'register', 'login', 'trends'); if (in_array($path[2], $forbidden_routes)) { // syslog(LOG_INFO, "Forbidden in subs: ".$path[2]); // Redirect to the root $uri = preg_split('/\\/+/', $_SERVER['REQUEST_URI'], 10, PREG_SPLIT_NO_EMPTY); $uri = array_slice($uri, 2); $uri = '/' . implode('/', $uri); header("Location: {$uri}"); die; } $globals['site_shortname'] = $globals['submnm']; if (empty($globals['submnm']) || !($info = SitesMgr::get_info())) { not_found(); } $globals['path'] = array_slice($path, 2); $globals['base_url'] .= $path[0] . '/' . $path[1] . '/'; if (!empty($routes[$path[2]])) { $res = (include './' . $routes[$path[2]]); if ($res === FALSE) { not_found($path[1]); } } else { // Try with story include './story.php'; }
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')); }
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; } } }
<?php // This script is to add the statuses values of previous links for multisite support // It must be run for every subsite you have created include '../config.php'; $links = $db->object_iterator("SELECT link_id as id, link_status as status, link_karma as karma, link_category as category, UNIX_TIMESTAMP(link_date) as date, UNIX_TIMESTAMP(link_sent_date) as sent_date, UNIX_TIMESTAMP(link_published_date) as published_date FROM links order by link_id desc", "Link"); if ($links) { $c = 0; $db->transaction(); foreach ($links as $link) { if ($c % 1000 == 0) { echo "{$link->id}, {$link->category}\n"; $db->commit(); usleep(100000); $db->transaction(); } SitesMgr::deploy($link, true); // Force to copy to all receivers $c++; } $db->commit(); }
#! /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}");
<?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.php'; $globals['ads'] = false; promote_style(); do_header(_('promote') . ' | ' . _('menéame')); echo '<div id="singlewrap">' . "\n"; $site_id = SitesMgr::my_parent(); $annotation = new Annotation("promote-{$site_id}"); $annotation->text = $output; if ($annotation->read()) { echo $annotation->text; } echo '</div>' . "\n"; do_footer_menu(); do_footer(); function promote_style() { global $globals; $globals['extra_head'] = ' <style type="text/css"> p { font-family: Bitstream Vera Sans, Arial, Helvetica, sans-serif; font-size: 90%;
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 do_save($link) { global $dblang, $globals, $current_user, $db; $link->status = $link->sub_status; $site_properties = SitesMgr::get_extended_properties(); // Store previous value for the log $link_old = new stdClass(); $link_old->url = $link->url; $link_old->title = $link->title; $link_old->content = $link->content; $link_old->tags = $link->tags; $link_old->status = $link->status; $link_old->sub_id = $link->sub_id; $link->read_content_type_buttons($_POST['type']); $link->sub_id = intval($_POST['sub_id']); if ($link->sub_id != $link_old->sub_id) { $link->sub_changed = true; // To force to delete old statuses with another origin } if ($current_user->admin || $current_user->user_level == 'blogger' || SitesMgr::is_owner()) { if (!empty($_POST['url'])) { $link->url = clean_input_url($_POST['url']); } if ($_POST['thumb_delete']) { $link->delete_thumb(); } if ($_POST['uri_update']) { $link->get_uri(); } if ($_POST['thumb_get']) { $link->get_thumb(); } elseif (!empty($_POST['thumb_url'])) { $url = clean_input_url($_POST['thumb_url']); $link->get_thumb(false, $url); } } $link->title = $_POST['title']; $link->content = $_POST['bodytext']; $link->tags = tags_normalize_string($_POST['tags']); $errors = link_edit_errors($link); // change the status if ($_POST['status'] != $link->status && ($_POST['status'] == 'autodiscard' || $current_user->admin || SitesMgr::is_owner()) && preg_match('/^[a-z]{4,}$/', $_POST['status']) && (!$link->is_discarded() || $current_user->admin || SitesMgr::is_owner())) { if (preg_match('/discard|abuse|duplicated|autodiscard/', $_POST['status'])) { // Insert a log entry if the link has been manually discarded $insert_discard_log = true; } $link->status = $_POST['status']; } if (!$errors) { if (empty($link->uri)) { $link->get_uri(); } // Check the blog_id $blog_id = Blog::find_blog($link->url, $link->id); if ($blog_id > 0 && $blog_id != $link->blog) { $link->blog = $blog_id; } $db->transaction(); $link->store(); // Disabled table tags // tags_insert_string($link->id, $dblang, $link->tags, $link->date); // Insert edit log/event if the link it's newer than 15 days if ($globals['now'] - $link->date < 86400 * 15) { if ($insert_discard_log) { // Insert always a link and discard event if the status has been changed to discard Log::insert('link_discard', $link->id, $current_user->user_id); if ($link->author == $current_user->user_id) { // Don't save edit log if it's discarded by an admin Log::insert('link_edit', $link->id, $current_user->user_id); } } elseif ($link->votes > 0) { Log::conditional_insert('link_edit', $link->id, $current_user->user_id, 60, serialize($link_old)); } } // Check this one is a draft, allows the user to save and send it to the queue if ($link->votes == 0 && $link->status != 'queued' && $link->author == $current_user->user_id) { $link->enqueue(); } $db->commit(); } $link->read(); $link->permalink = $link->get_permalink(); Haanga::Load('link/edit_result.html', compact('link', 'errors')); }
} //avoid abuses } else { $rows = 500; } // Bug in FeedBurner, it needs all items if (preg_match('/feedburner/i', $_SERVER['HTTP_USER_AGENT'])) { $if_modified = 0; } else { $if_modified = get_if_modified(); if ($if_modified < time() - 3 * 86400) { $if_modified = 0; } } $site_id = SitesMgr::my_id(); $site_info = SitesMgr::get_info(); if ($site_info->sub && $site_info->owner > 0) { $globals['site_name'] = $site_info->name; } $individual_user = false; if ($_REQUEST['q']) { include mnminclude . 'search.php'; if ($if_modified) { $_REQUEST['t'] = $if_modified; } $_REQUEST['w'] = 'comments'; $search_ids = do_search(true); if (!empty($search_ids['ids'])) { $ids = implode(",", $search_ids['ids']); $sql = "SELECT comment_id FROM comments WHERE comment_id in ({$ids}) ORDER BY comment_id DESC LIMIT {$rows}"; $last_modified = $db->get_var("SELECT UNIX_TIMESTAMP(comment_date) FROM comments WHERE comment_id in ({$ids}) ORDER BY comment_id DESC LIMIT 1");
function print_shakeit_tabs($option = -1) { global $globals, $current_user, $db; $items = array(); if ($current_user->has_personal) { $items[] = array('id' => 7, 'url' => 'shakeit.php', 'title' => _('personal')); } $items[] = array('id' => 1, 'url' => 'shakeit.php' . $globals['meta_skip'], 'title' => _('todas')); if (!$globals['mobile']) { $metas = SitesMgr::get_metas(); if ($metas) { foreach ($metas as $meta) { $items[] = array('id' => 9999, 'url' => 'shakeit.php?meta=' . $meta->uri, 'selected' => $meta->id == $globals['meta_current'], 'title' => $meta->name); } } } $items[] = array('id' => 3, 'url' => 'shakeit.php?meta=_popular', 'title' => _('candidatas')); if ($current_user->user_id > 0) { $items[] = array('id' => 2, 'url' => 'shakeit.php?meta=_friends', 'title' => _('amigos')); } if (!$globals['bot']) { $items[] = array('id' => 5, 'url' => 'shakeit.php?meta=_discarded', 'title' => _('descartadas')); } // Print RSS teasers if (!$globals['mobile']) { switch ($option) { case 7: // Personalised, queued $feed = array("url" => "?status=queued&personal=" . $current_user->user_id, "title" => ""); break; default: $feed = array("url" => "?status=queued&meta=" . $globals['meta_current'], "title" => ""); break; } } $vars = compact('items', 'option', 'feed'); return Haanga::Load('print_tabs.html', $vars); }
function save_sub($id, &$errors) { global $current_user, $db; // Double check $owner = intval($_POST['owner']); if (!SitesMgr::can_edit($id)) { array_push($errors, _('usuario no autorizado a editar')); return false; } $site = SitesMgr::get_info(); $extended = SitesMgr::get_extended_properties($id); if ($_POST['created_from'] != $site->id) { array_push($errors, _('sitio erróneo')); } if ($owner != $current_user->user_id && !$current_user->admin) { array_push($errors, _('propietario erróneo')); } $name = mb_substr(clean_input_string($_POST['name']), 0, 12); if (mb_strlen($name) < 3 || !preg_match('/^\\p{L}[\\p{L}\\d_]+$/u', $name)) { array_push($errors, _('nombre erróneo') . ' ' . $_POST['name']); } $name_long = mb_substr(clean_text($_POST['name_long']), 0, 40); if (mb_strlen($name_long) < 6) { array_push($errors, _('título erróneo')); } $name = $db->escape($name); $name_long = $db->escape($name_long); if ($db->get_var("select count(*) from subs where name = '{$name}' and id != {$id}") > 0) { array_push($errors, _('nombre duplicado')); } $page_mode = $db->escape($_POST['page_mode']); if ($current_user->admin) { $enabled = intval($_POST['enabled']); $allow_main_link = intval($_POST['allow_main_link']); } else { // Keep the values $enabled = $site->enabled; $allow_main_link = $site->allow_main_link; $_POST['post_html'] = $extended['post_html']; } $nsfw = intval($_POST['nsfw']); $private = intval($_POST['private']); // Check the extended info foreach (array('no_link', 'no_anti_spam', 'allow_local_links', 'intro_max_len', 'intro_min_len') as $k) { if (isset($_POST[$k]) && $_POST[$k] !== '') { $_POST[$k] = intval($_POST[$k]); } } if ($_POST['intro_max_len'] > 5000) { $_POST['intro_max_len'] = 5000; } if (empty($errors)) { $db->transaction(); if ($id > 0) { $r = $db->query("update subs set owner = {$owner}, enabled = {$enabled}, allow_main_link = {$allow_main_link}, nsfw = {$nsfw}, name = '{$name}', name_long = '{$name_long}', private = {$private}, page_mode = '{$page_mode}' where id = {$id}"); } else { $r = $db->query("insert into subs (created_from, owner, nsfw, name, name_long, sub, private) values ({$site->id}, {$owner}, {$nsfw}, '{$name}', '{$name_long}', 1, {$private})"); $id = $db->insert_id; } if ($r && $id > 0) { // Copy values from first site $r = $db->query("update subs as a join subs as b on a.id = {$id} and b.id={$site->id} set a.server_name = b.server_name, a.base_url = b.base_url"); // Update copy_from if ($current_user->admin) { sub_copy_from($id, $_POST['copy_from']); } // Update colors $color_regex = '/^#[a-f0-9]{6}/i'; if (preg_match($color_regex, $_POST['color1'])) { $color1 = $db->escape($_POST['color1']); } else { $color1 = ''; } if (preg_match($color_regex, $_POST['color2'])) { $color2 = $db->escape($_POST['color2']); } else { $color2 = ''; } $db->query("update subs set color1 = '{$color1}', color2 = '{$color2}' where id = {$id}"); } if ($r && $id > 0) { SitesMgr::store_extended_properties($id, $_POST); $db->commit(); store_image($id); return $id; } else { array_push($errors, _('error actualizando la base de datos')); $db->rollback(); } } return false; }
function do_sub_message_right() { global $db, $globals; if ($globals['mobile'] || !$globals['submnm']) { return; } $properties = SitesMgr::get_extended_properties(); if (empty($properties['message'])) { return; } $message = LCPBase::html($properties['message']); Haanga::Load('message_right.html', compact('message')); return; }
function print_index_tabs($option = -1) { global $globals, $db, $current_user; if ($globals['mobile'] && !$current_user->has_subs || !empty($globals['submnm']) && !$current_user->user_id) { return; } $items = array(); $items[] = array('id' => 0, 'url' => $globals['meta_skip'], 'title' => _('Todas')); if (isset($current_user->has_subs)) { $items[] = array('id' => 7, 'url' => $globals['meta_subs'], 'title' => _('Suscripciones')); } if (!$globals['mobile'] && empty($globals['submnm']) && ($subs = SitesMgr::get_sub_subs())) { foreach ($subs as $sub) { $items[] = array('id' => 9999, 'url' => 'm/' . $sub->name, 'selected' => false, 'title' => $sub->name); } } // RSS teasers switch ($option) { case 7: // Personalised, published $feed = array("url" => "?subs=" . $current_user->user_id, "title" => _('Suscripciones')); break; default: $feed = array("url" => '', "title" => ""); break; } if ($current_user->user_id > 0) { $items[] = array('id' => 1, 'url' => '?meta=_friends', 'title' => _('Amigos')); } $vars = compact('items', 'option', 'feed'); return Haanga::Load('print_tabs.html', $vars); }
// 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 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; } }
function do_subs() { global $db, $user, $current_user; $sql = "select subs.* from subs, prefs where pref_user_id = {$user->id} and pref_key = 'sub_follow' and subs.id = pref_value order by name asc"; $subs = $db->get_results($sql); if ($subs) { $title = _('suscripciones'); Haanga::Load('subs_simple.html', compact('title', 'subs')); } if ($current_user->admin && $user->id == $current_user->user_id) { $sql = "select subs.* from subs where subs.sub = 1 and (subs.owner = {$user->id} or subs.owner = 0)"; } else { $sql = "select subs.* from subs where subs.sub = 1 and subs.owner = {$user->id}"; } $subs = $db->get_results($sql); if ($subs) { $title = _('subs de') . " {$user->username}"; if ($current_user->user_id > 0 && $user->id == $current_user->user_id && SitesMgr::can_edit(0)) { $can_edit = true; } else { $can_edit = false; } Haanga::Load('subs.html', compact('title', 'subs', 'can_edit')); } }
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 depublish($site_id) { // send back to queue links with too many negatives global $db, $globals; $days = 4; echo "STARTING depublish for {$site_id}\n"; $site_info = SitesMgr::get_info($site_id); $links = $db->get_col("select SQL_NO_CACHE link_id as id from links, sub_statuses where id = {$site_id} and status = 'published' and date > date_sub(now(), interval {$days} day) and date < date_sub(now(), interval 14 minute) and link = link_id and link_negatives > link_votes / 5"); if ($links) { $votes_clicks = $db->get_col("select SQL_NO_CACHE link_votes/counter from links, sub_statuses, link_clicks where sub_statuses.id = {$site_id} and status = 'published' and date > date_sub(now(), interval {$days} day) and link = link_id and link_clicks.id = link"); sort($votes_clicks); foreach ($links as $link) { $l = Link::from_db($link); $vc = $l->votes / $l->clicks; $prob = cdf($votes_clicks, $vc); // Count only those votes with karma > 6 to avoid abuses with new accounts with new accounts $negatives = (int) $db->get_var("select SQL_NO_CACHE sum(user_karma) from votes, users where vote_type='links' and vote_link_id={$l->id} and vote_date > from_unixtime({$l->date}) and vote_date > date_sub(now(), interval 24 hour) and vote_value < 0 and vote_user_id > 0 and user_id = vote_user_id and user_karma > " . $globals['depublish_negative_karma']); $positives = (int) $db->get_var("select SQL_NO_CACHE sum(user_karma) from votes, users where vote_type='links' and vote_link_id={$l->id} and vote_date > from_unixtime({$l->date}) and vote_value > 0 and vote_date > date_sub(now(), interval 24 hour) and vote_user_id > 0 and user_id = vote_user_id and user_karma > " . $globals['depublish_positive_karma']); echo "Candidate {$l->uri}\n karma: {$l->sub_karma} ({$l->karma}) negative karma: {$negatives} positive karma: {$positives}\n"; // Adjust positives to the probability of votes/clicks $c = 1 + (1 - $prob) * 0.5; $positives = $positives * $c; echo " probability: {$prob} New positives: {$positives} ({$c})\n"; if ($negatives > 10 && $negatives > $c * $l->sub_karma / 6 && $l->negatives > $c * $l->votes / 6 && $l->negatives > 5 && ($negatives > $positives || $negatives > $c * $l->sub_karma / 2 && $negatives > $positives / 2)) { echo "Queued again: {$l->id} negative karma: {$negatives} positive karma: {$positives}\n"; $karma_old = $l->sub_karma; $karma_new = intval($l->sub_karma / $globals['depublish_karma_divisor']); $l->status = 'queued'; $l->sub_karma = $l->karma = $karma_new; $db->query("update links set link_status='queued', link_date = link_sent_date, link_karma={$karma_new} where link_id = {$l->id}"); SitesMgr::deploy($l); // Add an annotation to show it in the logs $l->karma_old = $karma_old; $l->karma = $karma_new; $l->annotation = _('Retirada de portada'); $l->save_annotation('link-karma'); Log::insert('link_depublished', $l->id, $l->author); if (!$site_info->sub) { // Add the discard to log/event $user = new User($l->author); if ($user->read) { echo "{$user->username}: {$user->karma}\n"; $user->add_karma(-$globals['instant_karma_per_depublished'], _('Retirada de portada')); } // Increase karma to users that voted negative $ids = $db->get_col("select vote_user_id from votes where vote_type = 'links' and vote_link_id = {$l->id} and vote_user_id > 0 and vote_value < 0"); foreach ($ids as $id) { $u = new User($id); if ($u->read) { // Avoid abuse of users voting negative just to get more karma $voted = $db->get_var("select count(*) from logs where log_type = 'user_depublished_vote' and log_user_id = {$id} and log_date > date_sub(now(), interval 48 hour)"); if ($voted < 5) { $u->add_karma(0.2, _('Negativo a retirada de portada')); Log::insert('user_depublished_vote', $l->id, $id); } } } } /*********** * TODO: call for every site (as in promote) if ($globals['twitter_token'] || $globals['jaiku_user']) { if ($globals['url_shortener']) { $short_url = $l->get_short_permalink(); } else { $short_url = fon_gs($l->get_permalink()); } $text = _('Retirada de portada') . ': ' . $l->title; if ($globals['twitter_user'] && $globals['twitter_token']) { twitter_post($text, $short_url); } if ($globals['jaiku_user'] && $globals['jaiku_key']) { jaiku_post($text, $short_url); } } *******/ } } } }
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}"); } }
$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']) . ')';
$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';