コード例 #1
0
ファイル: html1.php プロジェクト: brainsqueezer/fffff
function do_best_posts()
{
    global $db, $globals, $dblang;
    if ($globals['mobile']) {
        return;
    }
    $output = '';
    $key = 'best_posts_' . $globals['css_main'];
    if (memcache_mprint($key)) {
        return;
    }
    $min_date = date("Y-m-d H:i:00", $globals['now'] - 86400);
    // about 24 hours
    $res = $db->get_results("select post_id from posts, users where post_date > '{$min_date}' and  post_user_id = user_id and post_karma > 0 order by post_karma desc limit 10");
    if ($res) {
        $output .= '<div class="sidebox"><div class="header"><h4><a href="' . post_get_base_url('_best') . '">' . _('mejores notas') . '</a></h4></div><div class="comments"><ul>' . "\n";
        foreach ($res as $p) {
            $post = new Post();
            $post->id = $p->post_id;
            $post->read();
            $output .= '<li><img src="' . get_avatar_url($post->author, $post->avatar, 20) . '" alt="" width="20" height="20" class="avatar"/>';
            $output .= '<p><strong>' . $post->username . '</strong>: <a onmouseout="tooltip.clear(event);"  onclick="tooltip.clear(this);" onmouseover="return tooltip.ajax_delayed(event, \'get_post_tooltip.php\', \'' . $post->id . '\', 10000);" href="' . post_get_base_url($post->username) . '/' . $post->id . '"><em>' . text_to_summary($post->clean_content(), 80) . '</em></a></p></li>' . "\n";
        }
        $output .= '</ul></div></div>';
        echo $output;
        memcache_madd($key, $output, 300);
    }
}
コード例 #2
0
ファイル: html1.php プロジェクト: manelio/woolr
function do_last_blogs()
{
    global $db, $globals, $dblang;
    if ($globals['mobile'] || $globals['submnm']) {
        return;
    }
    $output = '';
    $key = 'last_blogs_' . $globals['v'];
    if (memcache_mprint($key)) {
        return;
    }
    echo '<!-- Calculating ' . __FUNCTION__ . ' -->';
    $entries = $db->get_results("select rss.blog_id, rss.user_id, title, url, user_login, user_avatar from rss, users where rss.user_id = users.user_id order by rss.date desc limit 10");
    if ($entries) {
        $objects = array();
        $title = _('apuntes de blogs');
        $url = $globals['base_url'] . 'rsss';
        foreach ($entries as $entry) {
            $obj = new stdClass();
            $obj->user_id = $entry->user_id;
            $obj->avatar = $entry->user_avatar;
            $obj->title = text_to_summary($entry->title, 75);
            $obj->link = $entry->url;
            $obj->username = $entry->user_login;
            $objects[] = $obj;
        }
        $vars = compact('objects', 'title', 'url');
        $output = Haanga::Load('last_blogs.html', $vars, true);
        echo $output;
        memcache_madd($key, $output, 300);
    }
}
コード例 #3
0
ファイル: url.php プロジェクト: brainsqueezer/fffff
    $json = true;
    $dict = array();
    header('Content-Type: application/json; charset=utf-8');
    if ($_GET['jsonp']) {
        $jsonp = preg_replace('/[^\\w\\d\\.\\-]/', '', $_GET['jsonp']);
        echo $jsonp . '(';
        $ending = ')';
    } else {
        $ending = '';
    }
} else {
    $json = false;
    header('Content-Type: text/plain; charset=UTF-8');
}
$cache_key = 'api_url' . $json . $_GET['url'];
if (memcache_mprint($cache_key)) {
    exit(0);
}
stats_increment('api', true);
$url = $db->escape($_GET['url']);
if (strlen($url) < 8 || !preg_match('/^https{0,1}:\\/\\//', $url) || !($parsed = parse_url($url)) || mb_strlen($parsed['host']) < 5) {
    if ($json) {
        $dict['status'] = 'KO';
        echo @json_encode($dict);
        echo $ending;
    } else {
        echo 'KO';
    }
    die;
}
if (mb_strlen($parsed['path']) > 30) {
コード例 #4
0
ファイル: html1.php プロジェクト: brainsqueezer/fffff
function do_best_comments()
{
    global $db, $globals, $dblang;
    $foo_link = new Link();
    if (memcache_mprint('best_comments')) {
        return;
    }
    $min_date = date("Y-m-d H:i:00", $globals['now'] - 22000);
    // about 6 hours
    $res = $db->get_results("select comment_id, comment_order, user_login, link_id, link_uri, link_title, link_comments from comments, links, users  where comment_date > '{$min_date}' and comment_karma > 10 and comment_link_id = link_id and comment_user_id = user_id order by comment_karma desc limit 12");
    if ($res) {
        $output = '<div class="vertical-box">';
        $output .= '<h4><a href="' . $globals['base_url'] . 'topcomments.php">' . _('mejores comentarios') . '</a></h4><ul>' . "\n";
        foreach ($res as $comment) {
            $foo_link->uri = $comment->link_uri;
            $link = $foo_link->get_relative_permalink() . get_comment_page_suffix($globals['comments_page_size'], $comment->comment_order, $comment->link_comments) . '#comment-' . $comment->comment_order;
            $output .= '<li>' . $comment->user_login . ' ' . _('en') . ' <a  onmouseout="tooltip.clear(event);"  onclick="tooltip.clear(this);" onmouseover="return tooltip.ajax_delayed(event, \'get_comment_tooltip.php\', \'' . $comment->comment_id . '\', 10000);" href="' . $link . '">' . $comment->link_title . '</a></li>' . "\n";
        }
        $output .= '</ul></div>';
        echo $output;
        memcache_madd('best_comments', $output, 300);
    }
}
コード例 #5
0
ファイル: html1.php プロジェクト: GallardoAlba/Meneame
function do_last_subs($status = 'published', $count = 10, $order = 'date')
{
    global $db, $globals, $dblang;
    if ($globals['mobile'] || $globals['submnm']) {
        return;
    }
    $key = "last_subs_{$status}-{$count}-{$order_}" . $globals['v'];
    if (memcache_mprint($key)) {
        return;
    }
    $output = ' ';
    $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);
            if (!$link) {
                continue;
            }
            $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);
}
コード例 #6
0
ファイル: story.php プロジェクト: manelio/woolr
function print_relevant_comments($link, $no_page)
{
    global $globals, $db;
    if ($globals['bot'] || $link->comments < 10) {
        return;
    }
    if ($link->comments > 30 && $globals['now'] - $link->date < 86400 * 4) {
        $do_cache = true;
    } else {
        $do_cache = false;
    }
    if ($do_cache) {
        $key = 'relevant_story_comments_' . $globals['v'] . '_' . $link->id;
        if (memcache_mprint($key)) {
            return;
        }
    }
    $karma = intval($globals['comment_highlight_karma'] / 2);
    $limit = min(15, intval($link->comments / 10));
    // For the SQL
    $extra_limit = $limit * 2;
    $min_len = 32;
    $min_karma = max(20, $karma / 2);
    $min_votes = 4;
    $check_vote = $link->date - ($globals['now'] - $globals['time_enabled_votes']);
    $now = intval($globals['now'] / 60) * 60;
    $res = $db->get_results("select comment_id, comment_order, comment_karma, comment_karma + comment_order * 0.7 as val, length(comment_content) as comment_len, user_id, user_avatar, vote_value from comments LEFT JOIN votes ON ({$check_vote} > 0 and vote_type = 'links' and vote_link_id = comment_link_id and vote_user_id = comment_user_id), users where comment_link_id = {$link->id} and comment_votes >= {$min_votes} and comment_karma > {$min_karma} and length(comment_content) > {$min_len} and comment_user_id = user_id order by val desc limit {$extra_limit}");
    function cmp_comment_val($a, $b)
    {
        if ($a->val == $b->val) {
            return 0;
        }
        return $a->val < $b->val ? 1 : -1;
    }
    if ($res) {
        $objects = array();
        $self = false;
        $link_url = $link->get_relative_permalink();
        foreach ($res as $comment) {
            // The commenter has voted negative
            if ($comment->vote_value < 0 && $comment->comment_len > 60) {
                $comment->val *= 2;
                // If the link has many negatives ("warned"), add little more weight to criticism
                if ($link->has_warning) {
                    $comment->val *= 1.5;
                }
            }
            // Gives a little advantage to larger comments
            $comment->val *= min(1.5, log($comment->comment_len, 10) / 1.8);
        }
        usort($res, "cmp_comment_val");
        foreach ($res as $comment) {
            $obj = new stdClass();
            $obj->id = $comment->comment_id;
            $obj->order = $comment->comment_order;
            $obj->link_id = $link->id;
            $obj->link_url = $link_url;
            $obj->user_id = $comment->user_id;
            $obj->avatar = $comment->user_avatar;
            $obj->vote = $comment->vote_value;
            $obj->val = $comment->val;
            $obj->karma = $comment->comment_karma;
            $objects[] = $obj;
            if ($no_page && !$self && $obj->vote < 0 && $link->negatives < $link->votes * 0.5 && (count($objects) < 6 || $comment->comment_karma > $globals['comment_highlight_karma']) && count($res) >= count($objects) * 2) {
                $self = get_highlighted_comment($obj);
                $obj->summary = true;
            }
            if (count($objects) > $limit) {
                break;
            }
        }
        if ($no_page && !$self && count($objects) > 5 && $objects[0]->val > $globals['comment_highlight_karma'] * 1.5) {
            $self = get_highlighted_comment($objects[0]);
            $objects[0]->summary = true;
        }
        $output = Haanga::Load('relevant_comments.html', compact('objects', 'link_url', 'self'), true);
        echo $output;
        if ($do_cache) {
            memcache_madd($key, $output, 300);
        }
    }
}