Exemplo n.º 1
0
function print_result()
{
    global $response, $page_size;
    if ($response['ids']) {
        $rows = min($response['rows'], 1000);
        foreach ($response['ids'] as $id) {
            switch ($_REQUEST['w']) {
                case 'posts':
                    $obj = Post::from_db($id);
                    break;
                case 'comments':
                    $obj = Comment::from_db($id);
                    break;
                case 'links':
                default:
                    $obj = Link::from_db($id);
            }
            if (!$obj) {
                continue;
            }
            $obj->basic_summary = true;
            switch ($_REQUEST['w']) {
                case 'posts':
                    $obj->print_summary(800);
                    break;
                case 'comments':
                    if ($obj->type == 'admin' && !$current_user->admin) {
                        continue;
                    }
                    // link_object
                    $obj->print_summary(800);
                    break;
                case 'links':
                default:
                    $obj->print_summary();
            }
        }
    }
    do_pages($rows, $page_size);
}
Exemplo n.º 2
0
    }
}
$url_db = $url;
if (!$unique) {
    $url_db = addcslashes($url, '%_');
    $url_db = preg_replace('/\\/$/', '', $url_db);
    $links = $db->get_col("select SQL_NO_CACHE link_id from links where link_url like '{$url_db}%' order by link_date DESC limit 100");
} else {
    $url_db = preg_replace('/\\/$/', '', $url_db);
    $links = $db->get_col("select SQL_NO_CACHE link_id from links where link_url in ('{$url_db}', '{$url_db}/')");
}
if ($links) {
    $dict['status'] = 'OK';
    $dict['data'] = array();
    foreach ($links as $link_id) {
        $link = Link::from_db($link_id, null, false);
        if ($json) {
            $data = array();
            $data['id'] = $link_id;
            $data['url'] = $link->get_canonical_permalink();
            $data['status'] = $link->status;
            $data['votes'] = intval($link->votes);
            $data['anonymous'] = intval($link->anonymous);
            $data['karma'] = intval($link->karma);
            array_push($dict['data'], $data);
        } else {
            $response = 'OK ' . $link->get_canonical_permalink() . " {$link->total_votes} {$link->status} {$link_id}\n";
        }
    }
} else {
    if ($json) {
Exemplo n.º 3
0
function promote($site_id)
{
    global $db, $globals, $output;
    SitesMgr::__init($site_id);
    $output = '';
    $min_karma_coef = $globals['min_karma_coef'];
    $links_queue = $db->get_var("SELECT SQL_NO_CACHE count(*) from sub_statuses WHERE id = {$site_id} and date > date_sub(now(), interval 24 hour) and status in ('published', 'queued')");
    $links_queue_all = $db->get_var("SELECT SQL_NO_CACHE count(*) from sub_statuses, links WHERE id = {$site_id} and date > date_sub(now(), interval 24 hour) and link_id = link and link_votes > 0");
    $pub_estimation = intval(max(min($links_queue * PUB_PERC, PUB_MAX), PUB_MIN));
    $interval = intval(86400 / $pub_estimation);
    $now = time();
    echo "BEGIN\n";
    $output .= "<p><b>BEGIN</b>: " . get_date_time($now) . "<br/>\n";
    $hours = intval($globals['time_enabled_votes'] / 3600);
    $from_time = "date_sub(now(), interval {$hours} hour)";
    $last_published = $db->get_var("SELECT SQL_NO_CACHE UNIX_TIMESTAMP(max(date)) from sub_statuses WHERE id = {$site_id} and status='published'");
    if (!$last_published) {
        $last_published = $now - 24 * 3600 * 30;
    }
    $links_published = (int) $db->get_var("select SQL_NO_CACHE count(*) from sub_statuses where id = {$site_id} and status = 'published' and date > date_sub(now(), interval 24 hour)");
    $links_published_projection = 4 * (int) $db->get_var("select SQL_NO_CACHE count(*) from sub_statuses where id = {$site_id} and status = 'published' and date > date_sub(now(), interval 6 hour)");
    $diff = $now - $last_published;
    // If published and estimation are lower than projection then
    // fasten decay
    if ($diff < $interval && ($links_published_projection < $pub_estimation * 0.9 && $links_published < $pub_estimation * 0.9)) {
        $diff = max($diff * 2, $interval);
    }
    $decay = min(MAX, MAX - $diff / $interval * (MAX - MIN));
    $decay = max($min_karma_coef, $decay);
    if ($diff > $interval * 2) {
        $must_publish = true;
        $output .= "Delayed! <br/>";
    }
    $output .= "Last published at: " . get_date_time($last_published) . "<br/>\n";
    $output .= "24hs queue: {$links_queue}/{$links_queue_all}, Published: {$links_published} -> {$links_published_projection} Published goal: {$pub_estimation}, Interval: {$interval} secs, difference: " . intval($now - $last_published) . " secs, Decay: {$decay}<br/>\n";
    $continue = true;
    $published = 0;
    $past_karma_long = intval($db->get_var("SELECT SQL_NO_CACHE avg(karma) from sub_statuses WHERE id = {$site_id} and date >= date_sub(now(), interval 7 day) and status='published'"));
    $past_karma_short = intval($db->get_var("SELECT SQL_NO_CACHE avg(karma) from sub_statuses WHERE id = {$site_id} and date >= date_sub(now(), interval 12 hour) and status='published'"));
    $past_karma = 0.5 * max(40, $past_karma_long) + 0.5 * max(20, $past_karma_short);
    $min_past_karma = (int) ($past_karma * $min_karma_coef);
    $last_resort_karma = (int) $past_karma * 0.8;
    //////////////
    $min_karma = round(max($past_karma * $decay, 20));
    if ($decay >= 1) {
        $max_to_publish = 3;
    } else {
        $max_to_publish = 1;
    }
    $min_votes = 3;
    /////////////
    $limit_karma = round(min($past_karma, $min_karma) * 0.4);
    $bonus_karma = round(min($past_karma, $min_karma) * 0.35);
    /// Get common votes links' averages
    $days = 7;
    // Balance metas
    if (empty($globals['sub_balance_metas']) || !in_array(SitesMgr::my_id(), $globals['sub_balance_metas'])) {
        $db_metas = array();
    } else {
        $db_metas = $db->get_results("select category, category_name, calculated_coef from sub_categories, categories where id = {$site_id} and category_id = category and category_parent = 0 and category_id in (select category_parent from sub_categories, categories where id = {$site_id} and category_id = category and category_parent > 0)");
    }
    $subs_coef = get_subs_coef($site_id, 2);
    $globals['users_karma_avg'] = (double) $db->get_var("select SQL_NO_CACHE avg(link_votes_avg) from links, sub_statuses where id = {$site_id} and status = 'published' and date > date_sub(now(), interval 72 hour) and link_id = link");
    $output .= "Karma average for each link: " . $globals['users_karma_avg'] . ", Past karma. Long term: {$past_karma_long}, Short term: {$past_karma_short}, Average: <b>{$past_karma}</b><br/>\n";
    $output .= "<b>Current MIN karma: {$min_karma}</b>, absolute min karma: {$min_past_karma}, analizing from {$limit_karma}<br/>\n";
    $output .= "</p>\n";
    $where = "id = {$site_id} AND date > {$from_time} AND status = 'queued' AND link_id = link AND link_votes>={$min_votes} AND (link_karma > {$limit_karma} or (date > date_sub(now(), interval 2 hour) and link_karma > {$bonus_karma})) and user_id = link_author ";
    $sort = "ORDER BY link_karma DESC, link_votes DESC";
    $thumbs_queue = array();
    $links = $db->get_results("SELECT SQL_NO_CACHE link_id, link_karma as karma from sub_statuses, links, users  where {$where} {$sort} LIMIT 30");
    $rows = $db->affected_rows;
    echo "SELECTED {$rows} ARTICLES\n";
    if (!$rows) {
        $output .= "There are no articles<br/>\n";
        $output .= "--------------------------<br/>\n";
        echo strip_tags($output) . "\n";
        if (!DEBUG) {
            $annotation = new Annotation("promote-{$site_id}");
            $annotation->text = $output;
            $annotation->store();
        } else {
            echo "OUTPUT:\n. " . strip_tags($output) . "\n";
        }
        return;
    }
    $max_karma_found = 0;
    $best_link = 0;
    $best_karma = 0;
    $output .= "<table>\n";
    if ($links) {
        $output .= "<tr class='thead'><th>votes</th><th>anon</th><th>neg.</th><th>coef</th><th>karma</th><th>sub</th><th>title</th><th>changes</th></tr>\n";
        $i = 0;
        foreach ($links as $dblink) {
            $link = Link::from_db($dblink->link_id);
            $changes = update_link_karma($site_id, $link);
            if (!DEBUG && $link->thumb_status == 'unknown' && $link->karma > $limit_karma) {
                echo "Adding {$link->id} to thumb queue\n";
                array_push($thumbs_queue, $link->id);
            }
            if (!empty($link->coef) && $link->coef > 1) {
                if ($decay > 1) {
                    $karma_threshold = $past_karma;
                } else {
                    $karma_threshold = $min_karma;
                }
            } else {
                // Otherwise use normal decayed min_karma
                $karma_threshold = $min_karma;
            }
            if ($link->votes >= $min_votes && $link->karma >= $karma_threshold && $published < $max_to_publish) {
                $published++;
                publish($site_id, $link);
                $changes = 3;
                // to show a "published" later
            } else {
                if (($must_publish || $link->karma > $min_past_karma) && $link->karma > $limit_karma && $link->karma > $last_resort_karma && $link->votes > $link->negatives * 20) {
                    $last_resort_id = $link->id;
                    $last_resort_karma = $link->karma;
                }
            }
            $output .= print_row($link, $changes);
            usleep(10000);
            $i++;
        }
        if (!DEBUG && $published == 0 && $links_published_projection < $pub_estimation * 0.9 && $must_publish && $last_resort_id > 0) {
            // Publish last resort
            $link = new Link();
            $link->id = $last_resort_id;
            if ($link->read()) {
                $link->message = "Last resort: selected with the best karma";
                $output .= print_row($link, 3);
                publish($site_id, $link);
                // Recheck for images, some sites add images after the article has been published
                if (!$link->has_thumb() && $link->thumb_status != 'deleted' && !in_array($link->id, $thumbs_queue)) {
                    echo "Adding {$link->id} to thumb queue\n";
                    array_push($thumbs_queue, $link->id);
                }
            }
        }
        //////////
    }
    $output .= "</table>\n";
    echo strip_tags($output) . "\n";
    if (!DEBUG) {
        $annotation = new Annotation("promote-{$site_id}");
        $annotation->text = $output;
        $annotation->store();
    } else {
        echo "OUTPUT:\n" . strip_tags($output) . "\n";
    }
    // Get THUMBS
    foreach ($thumbs_queue as $id) {
        $link = Link::from_db($id, null, false);
        if ($link && !$link->has_thumb() && $link->thumb_status != 'deleted') {
            echo "GETTING THUMB {$link->id}\n";
            $link->get_thumb(true);
            echo "DONE GETTING THUMB\n";
        }
    }
}
Exemplo n.º 4
0
 case 'friends':
     $url = get_user_uri($current_user->user_login, 'friends_new');
     do_redirection($url);
     exit(0);
 case 'post':
     $url = $globals['scheme'] . '//' . get_server_name() . post_get_base_url($id);
     do_redirection($url);
     exit(0);
 case 'comment':
     $c = new Comment();
     $c->id = $id;
     $url = $globals['scheme'] . '//' . get_server_name() . $c->get_relative_individual_permalink();
     do_redirection($url);
     exit(0);
 default:
     $l = Link::from_db($id, null, false);
     if (!$l) {
         exit(0);
     }
     if (!$globals['mobile'] && !$globals['mobile_version'] && !empty($l->url) && $current_user->user_id > 0 && (empty($globals['https']) || preg_match('/^https:/', $l->url)) && User::get_pref($current_user->user_id, 'use_bar') && $db->get_var("select blog_type from blogs where blog_id = {$l->blog}") != 'noiframe') {
         $url = $globals['scheme'] . '//' . get_server_name() . $globals['base_url'] . 'b/' . $id;
         // we use always http to load no https pages
         do_redirection($url, 307);
     } else {
         if (empty($l->url)) {
             $url = $l->get_permalink();
         } else {
             $url = $l->url;
         }
         do_redirection($url);
     }
Exemplo n.º 5
0
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);
                					}
                				}
                *******/
            }
        }
    }
}
Exemplo n.º 6
0
    // The first element is always a "/"
    $comment->id = intval($url_args[0]);
} else {
    $url_args = preg_split('/\\/+/', $_REQUEST['id']);
    $comment->id = intval($url_args[0]);
    if ($comment->id > 0 && $globals['base_comment_url']) {
        // Redirect to the right URL if the link has a "semantic" uri
        header('HTTP/1.1 301 Moved Permanently');
        header('Location: ' . $comment->get_relative_individual_permalink());
        die;
    }
}
if (!$comment->read()) {
    do_error(_('comentario no encontrado'), 404);
}
$link = Link::from_db($comment->link, null, false);
if ($link->is_discarded()) {
    $globals['ads'] = false;
    $globals['noindex'] = true;
}
$globals['link'] = $link;
$globals['permalink'] = 'http://' . get_server_name() . $comment->get_relative_individual_permalink();
// Change to a min_value is times is changed for the current link_status
if ($globals['time_enabled_comments_status'][$link->status]) {
    $globals['time_enabled_comments'] = min($globals['time_enabled_comments_status'][$link->status], $globals['time_enabled_comments']);
}
// Check for comment post
if ($_POST['process'] == 'newcomment') {
    $new = new Comment();
    $new_comment_error = $new->save_from_post($link);
}
Exemplo n.º 7
0
function print_comment_list($comments, $user)
{
    global $globals, $current_user;
    $comment = new Comment();
    $timestamp_read = 0;
    $last_link = 0;
    $ids = array();
    foreach ($comments as $dbcomment) {
        $comment = Comment::from_db($dbcomment->comment_id);
        // Don't show admin comment if it's her own profile.
        if ($comment->type == 'admin' && !$current_user->admin && $user->id == $comment->author) {
            continue;
        }
        if ($last_link != $dbcomment->link_id) {
            $link = Link::from_db($dbcomment->link_id, null, false);
            // Read basic
            echo '<h4>';
            echo '<a href="' . $link->get_permalink() . '">' . $link->title . '</a>';
            echo ' [' . $link->comments . ']';
            echo '</h4>';
            $last_link = $link->id;
        }
        if ($comment->date > $timestamp_read) {
            $timestamp_read = $comment->date;
        }
        echo '<ol class="comments-list">';
        echo '<li>';
        $comment->link_object = $link;
        $comment->print_summary(2000, false);
        echo '</li>';
        echo "</ol>\n";
        $ids[] = $comment->id;
    }
    Haanga::Load('get_total_answers_by_ids.html', array('type' => 'comment', 'ids' => implode(',', $ids)));
    // Return the timestamp of the most recent comment
    return $timestamp_read;
}
Exemplo n.º 8
0
<?php

// The source code packaged with this file is Free Software, Copyright (C) 2011 by
// Ricardo Galli <gallir at gmail dot com>.
// 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';
$globals['force_ssl'] = False;
// We open the bar always as http to allow loading no https pages
include mnminclude . 'html1.php';
$url_args = $globals['path'];
$id = intval($globals['path'][1]);
if (!$id > 0 || !($link = Link::from_db($id))) {
    do_error(_('enlace no encontrado'), 404);
}
// Mark as read, add click if necessary
$link->add_click();
if ($globals['https'] && !preg_match('/^https:/', $link->url)) {
    redirect($link->url);
    die;
}
$link->title = text_to_summary($link->title, 80);
// From libs/html1.php do_header()
header('Content-Type: text/html; charset=utf-8');
$globals['security_key'] = get_security_key();
setcookie('k', $globals['security_key'], 0, $globals['base_url']);
// From libks/link.php print_summary()
$link->is_votable();
$link->permalink = $link->get_permalink();
Exemplo n.º 9
0
     if ($media->create_thumbs($parts[0])) {
         header("HTTP/1.0 200 OK");
         header('Content-Type: image/jpeg');
         $media->thumb->output();
         $globals['access_log'] = false;
         die;
     }
     $errn = 404;
     break;
 case "thumb":
 case "thumb_2x":
 case "thumb_medium":
     // Links' thumbnails
     $base = $parts[0];
     if (count($parts) == 2 && $parts[1] > 0) {
         $link = Link::from_db($parts[1]);
         if ($link && ($pathname = $link->try_thumb($base))) {
             header("HTTP/1.0 200 OK");
             header('Content-Type: image/jpeg');
             readfile($pathname);
             $globals['access_log'] = false;
             die;
         }
     }
     $errn = 404;
     break;
 case "tmp_thumb":
     // Temporal filenames
     $name = preg_replace('/^tmp_thumb\\-/', '', $filename);
     $path = Upload::get_cache_dir() . '/tmp/';
     $pathname = $path . $name;
Exemplo n.º 10
0
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>' . _('comentarios más valorados 24 horas') . '</h2></div>';
$last_link = 0;
$counter = 0;
echo '<div class="comments">';
$min_date = date("Y-m-d H:00:00", time() - 86000);
//  about 24 hours
$comments = $db->get_results("SELECT comment_id, link_id FROM comments, links WHERE comment_date > '{$min_date}' and link_id=comment_link_id ORDER BY comment_karma desc, link_id asc limit 25");
if ($comments) {
    foreach ($comments as $dbcomment) {
        $link = Link::from_db($dbcomment->link_id, null, false);
        $comment = Comment::from_db($dbcomment->comment_id);
        if ($last_link != $link->id) {
            echo '<h3>';
            echo '<a href="' . $link->get_relative_permalink() . '">' . $link->title . '</a>';
            echo '</h3>';
        }
        echo '<ol class="comments-list">';
        echo '<li>';
        $comment->print_summary($link, 2000, false);
        echo '</li>';
        if ($last_link != $link->id) {
            $last_link = $link->id;
            $counter++;
        }
        echo "</ol>\n";
Exemplo n.º 11
0
function do_most_clicked_stories()
{
    global $db, $globals, $dblang;
    if ($globals['mobile']) {
        return;
    }
    $key = 'most_clicked_' . $globals['site_shortname'] . $globals['v'] . '_' . $globals['meta_current'];
    if (memcache_mprint($key)) {
        return;
    }
    echo '<!-- Calculating ' . __FUNCTION__ . ' -->';
    if ($globals['meta_current'] && $globals['meta_categories']) {
        $category_list = 'and link_category in (' . $globals['meta_categories'] . ')';
        $title = sprintf(_('más visitadas «%s»'), $globals['meta_current_name']);
    } else {
        $category_list = '';
        $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' {$category_list} and date > '{$min_date}' and link_clicks.id = link order by value desc limit 5");
    if ($res) {
        $links = array();
        $url = $globals['base_url'] . 'topclicked.php';
        $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);
            }
            if ($link->negatives >= $link->votes / 10) {
                $link->warn = true;
            }
            $links[] = $link;
        }
        $vars = compact('links', 'title', 'url');
        $output = Haanga::Load('most_clicked_stories.html', $vars, true);
        echo $output;
        memcache_madd($key, $output, 180);
    }
}
Exemplo n.º 12
0
if (empty($_GET['id']) || empty($_GET['fields'])) {
    die;
}
$id = intval($_GET['id']);
$fields = clean_input_string($_GET['fields']);
// It has to remove parenthesis
if (empty($_GET['what'])) {
    $what = 'link';
} else {
    $what = $_GET['what'];
}
$object = false;
switch ($what) {
    case 'link':
    case 'links':
        $object = Link::from_db($id, null, false);
        break;
    case 'comment':
    case 'comments':
        $object = Comment::from_db($id);
        break;
    case 'post':
    case 'posts':
        $object = Post::from_db($id);
        break;
}
if (!$object) {
    die;
}
$output = new stdClass();
foreach (preg_split('/,/', $fields, 10, PREG_SPLIT_NO_EMPTY) as $f) {
Exemplo n.º 13
0
 function get_related($max = 10)
 {
     global $globals, $db;
     $related = array();
     $phrases = 0;
     // Only work with sphinx
     if (!$globals['sphinx_server']) {
         return $related;
     }
     require mnminclude . 'search.php';
     $maxid = $db->get_var("select max(link_id) from links");
     if ($this->status == 'published') {
         $_REQUEST['s'] = '! abuse discard autodiscard';
     }
     $words = array();
     $freqs = array();
     $hits = array();
     $freq_min = 1;
     // Filter title
     $a = preg_split('/[\\s,\\.;:“”–\\"\'\\-\\(\\)\\[\\]«»<>\\/\\?¿¡!]+/u', preg_replace('/[\\[\\(] *\\w{1,6} *[\\)\\]] */', ' ', htmlspecialchars_decode($this->title, ENT_QUOTES)), -1, PREG_SPLIT_NO_EMPTY);
     $i = 0;
     $n = count($a);
     foreach ($a as $w) {
         $w = unaccent($w);
         $wlower = mb_strtolower($w);
         $len = mb_strlen($w);
         if (!isset($words[$wlower]) && ($len > 3 || preg_match('/^[A-Z]{2,}$/', $w)) && !preg_match('/^\\d{1,3}\\D{0,1}$/', $w)) {
             $h = sphinx_doc_hits($wlower);
             $hits[$wlower] = $h;
             if ($h < 1 || $h > $maxid / 10) {
                 continue;
             }
             // If 0 or 1 it won't help to the search, too frequents neither
             // Store the frequency
             $freq = $h / $maxid;
             if (!isset($freqs[$wlower]) || $freqs[$wlower] > $freq) {
                 $freqs[$wlower] = $freq;
             }
             if ($freq < $freq_min) {
                 $freq_min = max(0.0001, $freq);
             }
             if (preg_match('/^[A-Z]/', $w) && $len > 2) {
                 $coef = 2 * log10($maxid / $h);
             } else {
                 $coef = 2;
             }
             // Increase coefficient if a name appears also in tags
             // s{0,1} is a trick for plurals, until we use stemmed words
             if (preg_match('/(^|[ ,])' . preg_quote($w) . 's{0,1}([ ,]|$)/ui', $this->tags)) {
                 $coef *= 2;
                 if ($i == 0 || $i == $n - 1) {
                     $coef *= 2;
                 }
                 // It's the first or last word
             }
             $words[$wlower] = intval($h / $coef);
         }
         $i++;
     }
     // Filter tags
     $a = preg_split('/,+/', $this->tags, -1, PREG_SPLIT_NO_EMPTY);
     foreach ($a as $w) {
         $w = trim($w);
         $wlower = mb_strtolower(unaccent($w));
         $len = mb_strlen($w);
         if (isset($words[$wlower])) {
             continue;
         }
         if (preg_match('/\\s/', $w)) {
             $wlower = "\"{$wlower}\"";
             $phrases++;
         }
         $h = sphinx_doc_hits($wlower);
         $hits[$wlower] = $h;
         if ($h < 1 || $h > $maxid / 10) {
             continue;
         }
         // If 0 or 1 it won't help to the search, too frequents neither
         // Store the frequency
         $freq = $h / $maxid;
         if (!isset($freqs[$wlower]) || $freqs[$wlower] > $freq) {
             $freqs[$wlower] = $freq;
         }
         if ($freq < $freq_min) {
             $freq_min = max(0.0001, $freq);
         }
         $words[$wlower] = intval($h / 2);
     }
     // Filter content, check length and that it's begin con capital
     $a = preg_split('/[\\s,\\.;:“”–\\"\'\\-\\(\\)\\[\\]«»<>\\/\\?¿¡!]+/u', preg_replace('/https{0,1}:\\/\\/\\S+|[\\[\\(] *\\w{1,6} *[\\)\\]]/i', '', $this->sanitize($this->content)), -1, PREG_SPLIT_NO_EMPTY);
     foreach ($a as $w) {
         $wlower = mb_strtolower(unaccent($w));
         if (!preg_match('/^[A-Z][a-zA-Z]{2,}/', $w)) {
             continue;
         }
         $len = mb_strlen($w);
         if (!isset($words[$wlower]) && ($len > 2 || preg_match('/^[A-Z]{2,}$/', $w)) && !preg_match('/^\\d{1,3}\\D{0,1}$/', $w)) {
             $h = sphinx_doc_hits($wlower);
             $hits[$wlower] = $h;
             if ($h < 1 || $h > $maxid / 50) {
                 continue;
             }
             // If 0 or 1 it won't help to the search, too frequents neither
             if (preg_match('/^[A-Z]/', $w) && $h < $maxid / 1000) {
                 $coef = max(log10($maxid / $h) - 1, 1);
             } else {
                 $coef = 1;
             }
             $words[$wlower] = intval($h / $coef);
         }
     }
     // Increase "hits" proportional to word's lenght
     // because longer words tends to appear less
     foreach ($words as $w => $v) {
         $len = mb_strlen($w);
         if ($len > 6 && !preg_match('/ /', $w)) {
             $words[$w] = $v * $len / 6;
         }
     }
     asort($words);
     $i = 0;
     $text = '';
     foreach ($words as $w => $v) {
         // Filter words if we got good candidates
         // echo "<!-- $w: ".$freqs[$w]." coef: ".$words[$w]."-->\n";
         if ($i > 4 && $freq_min < 0.005 && strlen($w) > 3 && (empty($freqs[$w]) || $freqs[$w] > 0.01 || $freqs[$w] > $freq_min * 100)) {
             continue;
         }
         $i++;
         if ($i > 14 or $i > 8 && $v > $maxid / 2000) {
             break;
         }
         $text .= "{$w} ";
     }
     echo "\n<!-- Search terms: {$text} Phrases: {$phrases} -->\n";
     $_REQUEST['q'] = $text;
     // Center the date about the the link's date
     $_REQUEST['root_time'] = $this->date;
     if ($globals['now'] - $this->date > 86400 * 5) {
         $this->old = true;
     } else {
         $this->old = false;
     }
     $response = do_search(false, 0, $max + 1, false);
     if ($response && isset($response['ids'])) {
         foreach ($response['ids'] as $id) {
             if ($id == $this->id) {
                 continue;
             }
             $l = Link::from_db($id);
             if (!$l) {
                 continue;
             }
             if (empty($l->permalink)) {
                 $l->permalink = $l->get_permalink();
             }
             $related[] = $l;
         }
     }
     return $related;
 }
Exemplo n.º 14
0
if (!isset($_REQUEST['id']) && $globals['base_bar_url'] && $_SERVER['PATH_INFO']) {
    $url_args = preg_split('/\\/+/', $_SERVER['PATH_INFO']);
    array_shift($url_args);
    // The first element is always a "/"
    $id = intval($url_args[0]);
} else {
    $url_args = preg_split('/\\/+/', $_REQUEST['id']);
    $id = intval($url_args[0]);
    if ($id > 0 && $globals['base_bar_url']) {
        // Redirect to the right URL if the link has a "semantic" uri
        header('HTTP/1.1 301 Moved Permanently');
        header('Location: ' . $globals['base_url'] . $globals['base_bar_url'] . $id);
        die;
    }
}
if (!($link = Link::from_db($id))) {
    do_error(_('enlace no encontrado'), 404);
}
// Mark as read, add click if necessary
$link->add_click();
$link->title = text_to_summary($link->title, 80);
// From libs/html1.php do_header()
header('Content-Type: text/html; charset=utf-8');
$globals['security_key'] = get_security_key();
setcookie('k', $globals['security_key'], 0, $globals['base_url']);
// From libks/link.php print_summary()
$link->is_votable();
$link->permalink = $link->get_permalink();
$link->can_vote_negative = !$link->voted && $link->votes_enabled && $link->negatives_allowed(true);
$link->get_box_class();
$vars = compact('type');
Exemplo n.º 15
0
$info = SitesMgr::get_info();
$properties = SitesMgr::get_extended_properties();
$a_tops = new Annotation('top-link-' . $site_name);
echo 'top-link-' . $site_name . "\n";
if (!$a_tops->read()) {
    exit;
}
$tops = explode(',', $a_tops->text);
$a_history = new Annotation('top-link-history-' . $site_name);
if ($a_history->read()) {
    $history = explode(',', $a_history->text);
} else {
    $history = array();
}
if (!in_array($tops[0], $history)) {
    if (!($link = Link::from_db($tops[0]))) {
        echo "Error reading link " . $tops[0] . "\n";
        exit;
    }
    $url = $link->get_permalink($info->sub);
    if ($globals['url_shortener']) {
        $short_url = $link->get_short_permalink();
    } else {
        $short_url = $url;
    }
    $intro = '#' . _('destacada');
    $text = "{$intro} {$link->title}";
    // Save the history
    array_push($history, intval($tops[0]));
    while (count($history) > 10) {
        array_shift($history);
Exemplo n.º 16
0
    // Discard "story", TODO: but it should be discarded in dispatch and submnm
}
$argc = 0;
if (!isset($_REQUEST['id']) && $url_args[0] && !ctype_digit($url_args[0])) {
    // Compatibility with story.php?id=x and /story/x
    $link = Link::from_db($url_args[0], 'uri');
    if (!$link) {
        do_error(_('noticia no encontrada'), 404);
    }
} else {
    if (isset($_REQUEST['id'])) {
        $id = intval($_REQUEST['id']);
    } else {
        $id = intval($url_args[0]);
    }
    if ($id > 0 && ($link = Link::from_db($id))) {
        // Redirect to the right URL if the link has a "semantic" uri
        if (!empty($link->uri)) {
            header('HTTP/1.1 301 Moved Permanently');
            header('Location: ' . $link->get_permalink());
            die;
        }
    } else {
        do_error(_('noticia no encontrada'), 404);
    }
}
// Check the link belong to the current site
$site_id = SitesMgr::my_id();
if ($link->is_sub && $site_id != $link->sub_id && empty($link->sub_status)) {
    // The link does not correspond to the current site, find one
    header('HTTP/1.1 301 Moved Permanently');
Exemplo n.º 17
0
print_period_tabs();
/*** SIDEBAR ****/
echo '<div id="sidebar">';
do_banner_right();
do_active_stories();
do_banner_promotions();
do_last_subs('published', 5, 'link_votes');
do_best_comments();
do_vertical_tags('published');
echo '</div>' . "\n";
/*** END SIDEBAR ***/
echo '<div id="newswrap">' . "\n";
if ($links) {
    $counter = 0;
    foreach ($links as $dblink) {
        $link = Link::from_db($dblink->link_id);
        $link->show_clicks = true;
        $link->print_summary();
        $counter++;
        Haanga::Safe_Load('private/ad-interlinks.html', compact('counter', 'page_size'));
    }
}
do_pages($rows, $page_size);
echo '</div>' . "\n";
do_footer_menu();
do_footer();
function print_period_tabs()
{
    global $globals, $current_user, $range_values, $range_names, $month, $year;
    if (!($current_range = check_integer('range')) || $current_range < 1 || $current_range >= count($range_values)) {
        $current_range = 0;
Exemplo n.º 18
0
 function print_summary($length = 0, $single_link = true, $return_string = false)
 {
     global $current_user, $globals;
     if (!$this->read) {
         return;
     }
     if ((!$this->link_object || $this->link_object->id != $this->link) && $this->link > 0) {
         $this->link_object = Link::from_db($this->link);
     }
     $link = $this->link_object;
     if ($link) {
         if (!empty($link->relative_permalink)) {
             $this->link_permalink = $link->relative_permalink;
         } else {
             $this->link_permalink = $link->get_relative_permalink();
         }
     } elseif (!empty($globals['permalink'])) {
         $this->link_permalink = $globals['permalink'];
     }
     $this->single_link = $single_link;
     $this->check_visibility();
     /* pickup the correct css for comments */
     if ($this->hidden || $this->ignored) {
         $this->comment_meta_class = 'comment-meta hidden';
         $this->comment_class = 'comment-body hidden';
     } else {
         $this->comment_meta_class = 'comment-meta';
         $this->comment_class = 'comment-body';
         if ($this->type == 'admin') {
             $this->comment_class .= ' admin';
         } else {
             if ($globals['comment_highlight_karma'] > 0 && $this->karma > $globals['comment_highlight_karma']) {
                 $this->comment_class .= ' high';
             }
             if ($link && $link->author == $this->author) {
                 $this->comment_class .= ' author';
             }
         }
     }
     if ($this->author == $current_user->user_id) {
         $this->comment_class .= ' user';
     }
     $this->prepare_summary_text($length);
     $this->can_vote = $current_user->user_id > 0 && $this->author != $current_user->user_id && $this->date > $globals['now'] - $globals['time_enabled_comments'] && $this->user_level != 'disabled';
     $this->user_can_vote = $current_user->user_karma > $globals['min_karma_for_comment_votes'] && !$this->voted;
     $this->modified_time = txt_time_diff($this->date, $this->modified);
     $this->has_votes_info = $this->votes > 0 && $this->date > $globals['now'] - 30 * 86400;
     // Show votes if newer than 30 days
     $this->can_reply = $current_user->user_id > 0 && $this->date > $globals['now'] - $globals['time_enabled_comments'];
     $vars = array('self' => $this);
     return Haanga::Load('comment_summary.html', $vars, $return_string);
 }
Exemplo n.º 19
0
function do_last_subs($status = 'published', $count = 10, $order = 'date')
{
    global $db, $globals, $dblang;
    if ($globals['mobile'] || $globals['submnm']) {
        return;
    }
    $output = ' ';
    $key = "last_subs_{$status}-{$count}-{$order_}" . $globals['v'];
    //if(memcache_mprint($key)) return;
    echo '<!-- Calculating ' . __FUNCTION__ . ' -->';
    $ids = $db->get_col("select link from sub_statuses, subs, links where date > date_sub(now(), interval 48 hour) and status = '{$status}' and sub_statuses.id = origen and subs.id = sub_statuses.id and owner > 0 and not nsfw and link_id = link order by {$order} desc limit {$count}");
    if ($ids) {
        $links = array();
        $title = _('en subs de usuarios');
        foreach ($ids as $id) {
            $link = Link::from_db($id);
            $link->print_subname = true;
            $link->url = $link->get_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);
            }
            $links[] = $link;
        }
        $subclass = 'brown';
        $url = $globals['base_url_general'] . 'subs';
        $vars = compact('links', 'title', 'subclass', 'url');
        $output = Haanga::Load('best_stories.html', $vars, true);
        echo $output;
    }
    memcache_madd($key, $output, 300);
}
Exemplo n.º 20
0
<?php

// The source code packaged with this file is Free Software, Copyright (C) 2005 by
// Ricardo Galli <gallir at uib dot es> and
// Beldar <beldar.cat at gmail dot com>
// 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".
// The code below was made by Beldar <beldar at gmail dot com>
if (!defined('mnmpath')) {
    include_once '../config.php';
    header('Content-Type: text/html; charset=utf-8');
}
include_once mnminclude . 'commentmobile.php';
if (empty($_GET['id'])) {
    die;
}
$id = intval($_GET['id']);
$comment = new CommentMobile();
$comment->id = $id;
$comment->read();
if (!$comment->read) {
    die;
}
$link = Link::from_db($comment->link);
$comment->link_permalink = $link->get_relative_permalink();
$comment->print_text(0);
Exemplo n.º 21
0
// Beldar <beldar.cat at gmail dot com>
// 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".
// The code below was made by Beldar <beldar at gmail dot com>
if (!defined('mnmpath')) {
    include_once '../config.php';
    header('Content-Type: text/html; charset=utf-8');
    header('Cache-Control: public, s-maxage=300');
}
if (empty($_GET['id'])) {
    die;
}
$id = intval($_GET['id']);
$link = Link::from_db($id);
if (!$link) {
    die;
}
$user_login = $link->username;
echo '<p>';
if ($link->avatar) {
    echo '<img class="avatar" src="' . get_avatar_url($link->author, $link->avatar, 40) . '" width="40" height="40" alt="avatar"  style="float:left; margin: 0 5px 0 0;"/>';
}
echo '<strong>' . $link->title . '</strong><br/>';
echo _('por') . ' <strong>' . $user_login . '</strong><br/>';
echo '<strong>' . $link->sub_name . '&nbsp;|&nbsp;karma:&nbsp;' . intval($link->karma) . '&nbsp;|&nbsp;' . _('negativos') . ':&nbsp;' . $link->negatives . '</strong></p>';
echo '<p style="margin-top: 4px">';
if ($image = $link->has_thumb()) {
    echo "<img src='{$image}' width='{$link->thumb_x}' height='{$link->thumb_y}' alt='' class='thumbnail'/>";
}
Exemplo n.º 22
0
function do_friends_shaken () {
	global $db, $rows, $user, $offset, $page_size, $globals;

	if ($globals['bot']) return;

	do_user_subheader(array(_('envíos propios') => get_user_uri($user->username, 'history'), _('votados') => get_user_uri($user->username, 'shaken'), _('favoritos') => get_user_uri($user->username, 'favorites'), _('votados por amigos') => get_user_uri($user->username, 'friends_shaken')), 3);

	$friends = $db->get_col("select friend_to from friends where friend_type = 'manual' and friend_from = $user->id and friend_value > 0");
	if ($friends) {
		$friends_list = implode(',', $friends);
		$sql = "select distinct vote_link_id as link_id from votes where vote_type = 'links' and vote_user_id in ($friends_list) and vote_value > 0 order by vote_link_id desc";

		$links = $db->get_results("$sql LIMIT $offset,$page_size");
	}

	if ($links) {
		foreach($links as $dblink) {
			$link = Link::from_db($dblink->link_id);
			$link->do_inline_friend_votes = true;
			$link->print_summary();
		}
	}

}
Exemplo n.º 23
0
function get_story($time, $type, $linkid, $userid)
{
    global $db, $events, $last_timestamp, $foo_link;
    $link = Link::from_db($linkid, null, false);
    if (!$link) {
        return;
    }
    $json['link'] = $link->get_relative_permalink();
    $json['id'] = $linkid;
    $json['status'] = get_status($link->status);
    $json['ts'] = $time;
    $json['type'] = $type;
    $json['votes'] = $link->total_votes;
    $json['com'] = $link->comments;
    $json['title'] = $link->title;
    $json['thumb'] = $link->has_thumb();
    $json['who'] = $link->username;
    $json['uid'] = $userid;
    if ($userid > 0) {
        $json['icon'] = get_avatar_url($userid, -1, 20);
    }
    if ($link->author != $userid && $userid > 0) {
        $user = new User($userid);
        $user->read();
        if ($user->admin) {
            // Edited by admin, don't show the author
            $json['uid'] = 0;
            $json['who'] = 'admin';
            $json['icon'] = '';
        }
    }
    $key = $time . ':' . $type . ':' . $linkid;
    $events[$key] = $json;
    if ($time > $last_timestamp) {
        $last_timestamp = $time;
    }
}
Exemplo n.º 24
0
    $last_modified = $db->get_var("SELECT UNIX_TIMESTAMP({$order_field}) {$from_where} {$order_by} LIMIT 1");
    if ($if_modified > 0) {
        $from_where .= " AND {$order_field} > FROM_UNIXTIME({$if_modified})";
    }
    $sql = "SELECT link_id {$from_where} {$order_by} LIMIT {$rows}";
}
do_header($title);
// Don't allow banned IPs o proxies
if (!check_ban($globals['user_ip'], 'ip', true) && !check_ban_proxy()) {
    $links = $db->get_col($sql);
} else {
    $links = false;
}
if ($links) {
    foreach ($links as $link_id) {
        $link = Link::from_db($link_id);
        if (!$link) {
            continue;
        }
        $category_name = $db->get_var("SELECT category_name FROM categories WHERE category_id = {$link->category} AND category_lang='{$dblang}'");
        $content = text_to_html(htmlentities2unicodeentities($link->content));
        $permalink = $link->get_short_permalink();
        /*
        if (isset($_REQUEST['local']) || $globals['bot']) {
        	$permalink = $link->get_permalink();
        } else {
        	$permalink = $link->get_short_permalink();
        }
        */
        echo "\t<item>\n";
        // Meneame own namespace
Exemplo n.º 25
0
	// If the first argument are only numbers, redirect to the story with that id
	if (is_numeric($url_args[0]) && $url_args[0] > 0) {
			$link = Link::from_db(intval($url_args[0]));
			if ($link) {
				header('Location: ' . $link->get_permalink());
				die;
			}
	}

	$link = Link::from_db($db->escape($url_args[0]));
	if (! $link ) {
		do_error(_('noticia no encontrada'), 404);
	}
} else {
	$url_args = preg_split('/\/+/', $_REQUEST['id']);
	if(is_numeric($url_args[0]) && $url_args[0] > 0 && ($link = Link::from_db(intval($url_args[0]))) ) {
		// Redirect to the right URL if the link has a "semantic" uri
		if (!empty($link->uri) && !empty($globals['base_story_url'])) {
			header ('HTTP/1.1 301 Moved Permanently');
			if (!empty($url_args[1])) $extra_url = '/' . urlencode($url_args[1]);
			header('Location: ' . $link->get_permalink(). $extra_url);
			die;
		}
	} else {
		do_error(_('argumentos no reconocidos'), 404);
	}
}


if ($link->is_discarded()) {
	// Dont allow indexing of discarded links
Exemplo n.º 26
0
<?php

// The source code packaged with this file is Free Software, Copyright (C) 2009 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".
// Don't check the user is logged
$globals['no_auth'] = true;
include '../config.php';
$url_args = preg_split('/\\/+/', $_SERVER['PATH_INFO']);
// If the first argument are only numbers, redirect to the story with that id
if (preg_match('/^[\\da-z]+$/', $url_args[1])) {
    $link = Link::from_db(intval(base_convert($url_args[1], 36, 10)), null, false);
    if ($link) {
        header('HTTP/1.1 301 Moved');
        header('Location: ' . $link->get_canonical_permalink());
        die;
    }
}
not_found('Link not found');
die;
Exemplo n.º 27
0
function get_link($link_id)
{
    global $globals;
    $link = Link::from_db($link_id);
    if (!$link) {
        return false;
    }
    $obj = array();
    $obj['id'] = (int) $link->id;
    $obj['permalink'] = $link->get_permalink();
    $obj['go'] = $globals['scheme'] . '//' . get_server_name() . $globals['base_url'] . 'go?id=' . $link->id;
    $obj['url'] = $link->url;
    $obj['from'] = parse_url($link->url, PHP_URL_HOST);
    $obj['sub'] = $link->sub_name;
    $obj['status'] = $link->status;
    $obj['user'] = $link->username;
    $obj['clicks'] = (int) $link->clicks;
    $obj['votes'] = intval($link->votes + $link->anonymous);
    $obj['negatives'] = (int) $link->negatives;
    $obj['karma'] = intval($link->karma);
    $obj['comments'] = (int) $link->comments;
    $obj['title'] = html_entity_decode($link->title);
    $obj['tags'] = html_entity_decode($link->tags);
    $obj['sent_date'] = (int) $link->sent_date;
    if ($link->status == 'published') {
        $obj['date'] = (int) $link->date;
    } else {
        $obj['date'] = (int) $link->sent_date;
    }
    // $obj['content'] = $link->to_html($link->content);
    $obj['content'] = html_entity_decode($link->content);
    if ($link->has_thumb()) {
        $obj['thumb'] = $globals['scheme'] . '//' . get_server_name() . $globals['base_url'] . 'backend/media?type=link&id=' . $link->id;
    }
    return $obj;
}
Exemplo n.º 28
0
function get_comment($time, $type, $commentid, $userid)
{
    global $db, $events, $last_timestamp, $max_items, $globals;
    $event = $db->get_row("select user_login, comment_user_id, comment_link_id, comment_type, comment_order, media.size as media_size from comments LEFT JOIN media ON (media.type='comment' and media.id = comments.comment_id and media.version = 0), users where comment_id = {$commentid} and user_id={$userid} ");
    if (!$event) {
        return;
    }
    $link = Link::from_db($event->comment_link_id, null, false);
    // Read simple
    if (!$link) {
        syslog(LOG_INFO, "Warn, link doesn't exist: {$type} {$commentid} {$userid} (sneaker2)");
        return;
    }
    $json['link'] = $link->get_relative_permalink() . "/c0{$event->comment_order}#c-{$event->comment_order}";
    $json['id'] = $commentid;
    $json['status'] = get_status($link->get_a_status());
    $json['ts'] = $time;
    $json['type'] = $type;
    $json['votes'] = $link->total_votes;
    $json['com'] = $link->comments;
    $json['title'] = $link->title;
    $json['sub_name'] = $link->sub_name;
    if ($event->comment_type == 'admin') {
        $json['who'] = get_server_name();
        $userid = 0;
    } else {
        $json['who'] = $event->user_login;
    }
    $json['uid'] = $userid;
    if ($userid > 0) {
        $json['icon'] = get_avatar_url($userid, -1, 20);
    }
    if ($event->media_size > 0) {
        $json['thumb'] = $globals['base_static'] . Upload::get_cache_relative_dir($commentid) . "/media_thumb-comment-{$commentid}.jpg";
    }
    $key = $time . ':' . $type . ':' . $commentid;
    $events[$key] = $json;
    if ($time > $last_timestamp) {
        $last_timestamp = $time;
    }
}