Beispiel #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);
}
Beispiel #2
0
function save_comment($comment, $link)
{
    global $db, $current_user, $globals, $site_key;
    $data = array();
    if ($comment->id == 0) {
        $res = Comment::save_from_post($link, false);
        // New comment
    } else {
        $res = check_and_save($comment, $link);
        // Edit, others requirements
    }
    if (is_a($res, "Comment", false)) {
        $comment = Comment::from_db($res->id);
        $comment->link_object = $link;
        $data['html'] = $comment->print_summary(null, true, true);
        $data['error'] = '';
    } else {
        $data['html'] = '';
        $data['error'] = $res;
    }
    echo json_encode($data);
}
Beispiel #3
0
function get_comment($id)
{
    global $globals;
    $comment = Comment::from_db($id);
    if (!$comment) {
        return false;
    }
    $obj = array();
    $obj['id'] = (int) $comment->id;
    $obj['date'] = (int) $comment->date;
    $obj['votes'] = intval($comment->votes);
    $obj['karma'] = intval($comment->karma);
    $obj['link_id'] = (int) $comment->link_id;
    $obj['order'] = (int) $comment->order;
    $obj['user'] = $comment->username;
    //$obj['content'] = $comment->to_html($comment->content);
    $obj['content'] = html_entity_decode($comment->content);
    return $obj;
}
Beispiel #4
0
echo '<div id="newswrap">'."\n";
$link->print_summary();

switch ($tab_option) {
case 1:
case 2:
	echo '<div class="comments">';

	if($tab_option == 1) do_comment_pages($link->comments, $current_page);

	$comments = $db->get_col("SELECT SQL_CACHE comment_id FROM comments WHERE comment_link_id=$link->id ORDER BY $order_field $limit");
	if ($comments) {
		echo '<ol class="comments-list">';
		foreach($comments as $comment_id) {
			if (($comment = Comment::from_db($comment_id))) {
				echo '<li>';
				$comment->print_summary($link, 2500, true);
				echo '</li>';
			}
			echo "\n";
		}
		echo "</ol>\n";
	}

	if($tab_option == 1) do_comment_pages($link->comments, $current_page);
	Comment::print_form($link);
	echo '</div>' . "\n";

	// Highlight a comment if it is referenced by the URL.
	// currently double border, width must be 3 at least
Beispiel #5
0
function print_answers($id, $level, $visited = false)
{
    // Print answers to the comment
    global $db, $page_size;
    if (!$visited) {
        $visited = array();
        $visited[] = $id;
    }
    $printed = array();
    $sql = "SELECT conversation_from FROM conversations, comments WHERE conversation_type='comment' and conversation_to = {$id} and comment_id = conversation_from ORDER BY conversation_from asc LIMIT {$page_size}";
    $answers = $db->get_col($sql);
    if ($answers) {
        $type = 'comment';
        echo '<div style="padding-left: 6%">' . "\n";
        echo '<ol class="comments-list">';
        foreach ($answers as $dbanswer) {
            if (in_array($dbanswer, $visited)) {
                continue;
            }
            $answer = Comment::from_db($dbanswer);
            $answer->url = $answer->get_relative_individual_permalink();
            echo '<li>';
            $answer->print_summary($link);
            if ($level > 0) {
                $res = print_answers($answer->id, $level - 1, array_merge($visited, $answers));
                $visited = array_merge($visited, $res);
            }
            $printed[] = $answer->id;
            $visited[] = $answer->id;
            echo '</li>';
        }
        echo "</ol>\n";
        echo '</div>' . "\n";
        if ($level == 0) {
            $ids = implode(',', $printed);
            Haanga::Load('get_total_answers_by_ids.html', compact('type', 'ids'));
        }
    }
    return $printed;
}
Beispiel #6
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;
}
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;
$sql_value = "comment_karma*(1-({$now}-unix_timestamp(comment_date))*{$coef}/({$hours}*3600)) as value";
$where_value = "comment_karma*(1-({$now}-unix_timestamp(comment_date))*{$coef}/({$hours}*3600)) > {$min_value}";
$sql = "select comment_id, karma, {$sql_value} from comments, sub_statuses where id = {$my_id} AND status in ('published') AND comment_date > date_sub(now(), interval {$hours} hour) and LENGTH(comment_content) > {$min_length} and comment_karma > {$min_karma} AND {$where_value} AND comment_link_id = link {$extra} order by value desc limit 1";
$res = $db->get_row($sql);
if (!$res) {
    exit(0);
}
$comment = Comment::from_db($res->comment_id);
if (!$comment) {
    exit(2);
}
$image = false;
if ($comment->media_size > 0) {
    $media = new Upload('comment', $comment->id);
    if ($media->read()) {
        $image = $media->pathname();
        $maxlen -= 24;
    }
}
$url = $globals[scheme] . '//' . get_server_name() . $comment->get_relative_individual_permalink();
syslog(LOG_INFO, "Meneame, posting comment {$url}");
//  Store in cache
if ($previous) {
Beispiel #8
0
     if (isset($all[$id])) {
         foreach ($all[$id] as $e) {
             $leaves[$e] = true;
         }
     }
 }
 if (isset($leaves[$id])) {
     unset($leaves[$id]);
 }
 //$obj->basic_summary = true;
 switch ($type) {
     case 'posts':
         $obj = Post::from_db($id);
         break;
     case 'comments':
         $obj = Comment::from_db($id);
         break;
 }
 if (!$obj || $obj->type == 'admin' && !$current_user->admin) {
     continue;
 }
 if ($obj->author == $id1) {
     echo '<div style="margin-top: -10;margin-left: 10px; width:70%">';
 } else {
     echo '<div style="margin-top: -10;margin-left:30%">';
 }
 $obj->print_summary();
 echo "</div>\n";
 $thread[] = $id;
 if ($show_thread) {
     continue;
}
if (!empty($_GET['id'])) {
    $keys = preg_split('/-/', $_GET['id'], -1, PREG_SPLIT_NO_EMPTY);
    if (count($keys) == 2) {
        $link = intval($keys[0]);
        $order = intval($keys[1]);
        $id = $db->get_var("select comment_id from comments where comment_link_id={$link} and comment_order={$order}");
        if (!$id > 0) {
            die;
        }
    } else {
        $id = intval($keys[0]);
    }
} else {
    die;
}
$comment = Comment::from_db($id);
if (!$comment) {
    die;
}
echo '<div class="comment-body">';
if ($comment->type != 'admin') {
    if ($comment->avatar) {
        echo '<img class="avatar" src="' . get_avatar_url($comment->author, $comment->avatar, 40) . '" width="40" height="40" alt="avatar" style="float:left; margin: 0 5px 4px 0;"/>';
    }
    echo '<strong><span style="color:#3D72C3">' . $comment->username . '</span></strong>, karma: ' . $comment->karma . '<br/>';
} else {
    echo '<strong>' . get_server_name() . '</strong><br/>';
}
$comment->print_text(1000);
echo '</div>';
Beispiel #10
0
if (!$search) {
    check_redirect_to_feedburner();
}
/****
	END WARNING ******/
if (!empty($sql)) {
    $comments = $db->get_col($sql);
}
if (!$comments && $if_modified) {
    header('HTTP/1.1 304 Not Modified');
    exit;
}
do_header($title);
if ($comments) {
    foreach ($comments as $comment_id) {
        $comment = Comment::from_db($comment_id);
        if (!$comment) {
            continue;
        }
        $link = Link::from_db($comment->link);
        if (!$link) {
            continue;
        }
        $comment->link_permalink = $link->get_permalink();
        if ($comment->type == 'admin') {
            if ($individual_user) {
                continue;
            } else {
                $comment->username = get_server_name();
            }
        }
<?php

// The source code packaged with this file is Free Software, Copyright (C) 2005-2011 by
// Ricardo Galli <gallir at gmail dot com>and Menéame Comunicacions
// 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".
// Use the alternate server for api, if it exists
//$globals['alternate_db_server'] = 'backend';
include '../config.php';
$id = intval($_GET['id']);
if (!$id) {
    die;
}
// Print answers to the comment
$sql = "SELECT conversation_from as comment_id FROM conversations, comments WHERE conversation_type='comment' and conversation_to = {$id} and comment_id = conversation_from ORDER BY conversation_from asc";
$res = $db->get_col($sql);
if ($res) {
    header('Content-Type: text/html; charset=UTF-8');
    foreach ($res as $answer) {
        $comment = Comment::from_db($answer);
        $comment->basic_summary = true;
        $comment->not_ignored = true;
        $comment->prefix_id = "{$id}-";
        // This a trick in order not to confuse with other ids
        $comment->print_summary(false, 2500);
        echo "\n";
    }
}
Beispiel #12
0
function get_highlighted_comment($obj)
{
    // Read the object for printing the summary
    $self = Comment::from_db($obj->id);
    $self->link_id = $obj->link_id;
    $self->link_permalink = $obj->link_url;
    // Simplify text of the comment
    $self->prepare_summary_text(1000);
    if ($self->is_truncated) {
        $self->txt_content .= '...';
        $self->is_truncated = false;
    }
    $self->media_size = 0;
    $self->vote = $obj->vote;
    $self->can_edit = false;
    return $self;
}
Beispiel #13
0
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";
    }
Beispiel #14
0
$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) {
    if (!in_array($f, $forbidden) && property_exists($object, $f)) {
        $output->{$f} = $object->{$f};
    }
}
Beispiel #15
0
function get_qanda($link)
{
    include_once mnminclude . 'commenttree.php';
    global $db;
    $results = array();
    $a_ids = $db->get_col("select comment_id from comments where comment_link_id = {$link->id} and comment_user_id = {$link->author} order by comment_id asc");
    if ($a_ids) {
        foreach ($a_ids as $a_id) {
            $a = Comment::from_db($a_id);
            $qa = new CommentQA($a);
            $q_ids = $db->get_col("select conversation_to from conversations where conversation_type = 'comment' and conversation_from = {$a_id} and conversation_to > 0 order by conversation_to asc");
            if ($q_ids) {
                foreach ($q_ids as $q_id) {
                    $q = Comment::from_db($q_id);
                    $qa->add_question($q);
                }
            }
            $results[] = $qa;
        }
    }
    return $results;
}
Beispiel #16
0
<?php

// The source code packaged with this file is Free Software, Copyright (C) 2010 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';
include mnminclude . 'html1.php';
include_once mnminclude . 'commenttree.php';
$page_size = $globals['page_size'] * 3;
$comment = Comment::from_db(intval($globals['path'][1]));
if (!$comment) {
    do_error(_('comentario no encontrado'), 404);
}
$link = Link::from_db($comment->link, null, false);
if ($link->is_discarded()) {
    $globals['ads'] = false;
    $globals['noindex'] = true;
} elseif ($comment->karma < 50 || mb_strlen($comment->content) < 100) {
    $globals['noindex'] = true;
}
$globals['link'] = $link;
$globals['permalink'] = $globals['scheme'] . '//' . 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') {