/**
 * Fetches and prints a listing of comments by author
 */
function serendipity_printCommentsByAuthor()
{
    global $serendipity;
    $type = serendipity_db_escape_string($serendipity['GET']['commentMode']);
    if ($type == 'comments' || empty($type)) {
        $type = 'NORMAL';
    } elseif ($type == 'trackbacks') {
        $type = 'TRACKBACK';
    } elseif ($type == 'comments_and_trackbacks') {
        $type = '%';
    }
    if (!empty($serendipity['GET']['viewCommentAuthor'])) {
        $sql_where = " AND co.author = '" . serendipity_db_escape_string($serendipity['GET']['viewCommentAuthor']) . "'";
        $group_by = "GROUP BY co.author";
    } else {
        $sql_where = " AND 1";
        // Required fake 'where' condition
        $group_by = "";
    }
    if (!empty($serendipity['GET']['commentStartTime'])) {
        $sql_where .= " AND co.timestamp >= " . (int) $serendipity['GET']['commentStartTime'];
    }
    if (!empty($serendipity['GET']['commentEndTime'])) {
        $sql_where .= " AND co.timestamp <= " . (int) $serendipity['GET']['commentEndTime'];
    }
    if (empty($serendipity['GET']['page'])) {
        $serendipity['GET']['page'] = 1;
    }
    $sql_limit = $serendipity['fetchLimit'] * ($serendipity['GET']['page'] - 1) . ',' . $serendipity['fetchLimit'];
    $c = serendipity_fetchComments(null, $sql_limit, 'co.entry_id DESC, co.id ASC', false, $type, $sql_where);
    $entry_comments = array();
    foreach ($c as $i => $comment) {
        if (!isset($entry_comments[$comment['entry_id']])) {
            $comment['link'] = serendipity_archiveURL($comment['entry_id'], $comment['title'], 'serendipityHTTPPath', true, array('timestamp' => $comment['entrytimestamp']));
            $entry_comments[$comment['entry_id']] = $comment;
        }
        $entry_comments[$comment['entry_id']]['comments'][] = $comment;
    }
    foreach ($entry_comments as $entry_id => $_data) {
        $entry_comments[$entry_id]['tpl_comments'] =& serendipity_printComments($_data['comments'], VIEWMODE_LINEAR, 0, null, 'COMMENTS', 'comments.tpl');
    }
    $serendipity['smarty']->assign_by_ref('comments_by_authors', $entry_comments);
    if (!empty($id)) {
        $and .= " AND co.entry_id = '" . (int) $id . "'";
    }
    if (!$showAll) {
        $and .= ' AND co.status = \'approved\'';
    }
    $fc = "SELECT count(co.id) AS counter\n                                  FROM {$serendipity['dbPrefix']}comments AS co\n                                 WHERE co.entry_id > 0\n                                   AND co.type LIKE '" . $type . "'\n                                   AND co.status = 'approved' " . $sql_where . " " . $group_by;
    $cc = serendipity_db_query($fc, true, 'assoc');
    if (!isset($cc['counter'])) {
        $totalComments = 0;
    } else {
        $totalComments = $cc['counter'];
    }
    serendipity_printEntryFooter('', $totalComments);
    serendipity_smarty_fetch('ENTRIES', 'comments_by_author.tpl');
    return true;
}
Exemplo n.º 2
0
        if (!isset($serendipity['POST']['preview'])) {
            $comment = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}comments WHERE id = " . (int) $serendipity['GET']['id']);
            $codata['name'] = $comment[0]['author'];
            $codata['email'] = $comment[0]['email'];
            $codata['url'] = $comment[0]['url'];
            $codata['replyTo'] = $comment[0]['parent_id'];
            $codata['comment'] = $comment[0]['body'];
            /* If we are in preview, we get comment data from our form */
        } elseif (isset($serendipity['POST']['preview'])) {
            $codata['name'] = $serendipity['POST']['name'];
            $codata['email'] = $serendipity['POST']['email'];
            $codata['url'] = $serendipity['POST']['url'];
            $codata['replyTo'] = $serendipity['POST']['replyTo'];
            $codata['comment'] = $serendipity['POST']['comment'];
            $pc_data = array(array('email' => $serendipity['POST']['email'], 'author' => $serendipity['POST']['name'], 'body' => $serendipity['POST']['comment'], 'url' => $serendipity['POST']['url'], 'timestamp' => time()));
            serendipity_printComments($pc_data);
            $serendipity['smarty']->display(serendipity_getTemplateFile('comments.tpl', 'serendipityPath'));
        }
    }
    if (!empty($codata['url']) && substr($codata['url'], 0, 7) != 'http://' && substr($codata['url'], 0, 8) != 'https://') {
        $codata['url'] = 'http://' . $codata['url'];
    }
    serendipity_displayCommentForm($serendipity['GET']['entry_id'], $target_url, NULL, $codata, false, false);
    $serendipity['smarty']->display(serendipity_getTemplateFile('commentform.tpl', 'serendipityPath'));
    return true;
}
/* Searchable fields */
$filters = array('author', 'email', 'ip', 'url', 'body', 'referer');
/* Compress the filters into an "AND" SQL query, and a querystring */
foreach ($filters as $filter) {
    $and .= !empty($serendipity['GET']['filter'][$filter]) ? "AND c." . $filter . " LIKE '%" . serendipity_db_escape_string($serendipity['GET']['filter'][$filter]) . "%'" : "";
/**
 * Smarty Function: Show Trackbacks
 *
 * @access public
 * @param   array       Smarty parameter input array:
 *                          entry: The $entry data for the trackbacks
 * @param   object  Smarty object
 * @return
 */
function &serendipity_smarty_printTrackbacks($params, &$smarty)
{
    if (!isset($params['entry'])) {
        trigger_error("Smarty Error: " . __FUNCTION__ . ": missing 'entry' parameter", E_USER_WARNING);
        return;
    }
    $trackbacks =& serendipity_fetchTrackbacks($params['entry']);
    if (empty($params['depth'])) {
        $params['depth'] = 0;
    }
    if (empty($params['trace'])) {
        $params['trace'] = null;
    }
    if (empty($params['block'])) {
        $params['block'] = 'TRACKBACKS';
    }
    if (empty($params['template'])) {
        $params['template'] = 'trackbacks.tpl';
    }
    $out = serendipity_printComments($trackbacks, VIEWMODE_LINEAR, $params['depth'], $params['trace'], $params['block'], $params['template']);
    return $out;
}
 function event_hook($event, &$bag, &$eventData, $addData = null)
 {
     global $serendipity;
     $hooks =& $bag->get('event_hooks');
     if (isset($hooks[$event])) {
         switch ($event) {
             case 'external_plugin':
                 switch ($eventData) {
                     case 'rtcomments.js':
                         header('Content-Type: text/javascript');
                         echo file_get_contents(dirname(__FILE__) . '/rtcomments.js');
                         break;
                     case 'rtcomments_pull':
                         $entry_id = $_REQUEST['entryId'];
                         if ($this->hasNewComment($entry_id, time())) {
                             $comments = $this->getNewComments($entry_id);
                             $old_raw_mode = $serendipity['smarty_raw_mode'];
                             $serendipity['smarty_raw_mode'] = true;
                             // Force output of Smarty stuff
                             serendipity_smarty_init();
                             #existing parent_id crashes the smarty-fetch
                             $comments_code = serendipity_printComments($comments, VIEWMODE_LINEAR);
                             $serendipity['smarty_raw_mode'] = $old_raw_mode;
                             echo $comments_code;
                         }
                         break;
                 }
                 return true;
                 break;
             case 'frontend_comment':
                 if (!empty($path) && $path != 'default' && $path != 'none' && $path != 'empty') {
                     $path_defined = true;
                 } else {
                     $path_defined = false;
                 }
                 #it should be enough to set this only here, since
                 #it's the first thing happening on the site concerning the plugin
                 $this->interval = $this->get_config('interval', 10);
                 if ($path_defined) {
                     echo '<script type="text/javascript" src="' . $path . 'rtcomments.js"></script>' . "\n";
                     echo '<script>var rtcbase = "' . $serendipity['baseURL'] . 'index.php?/plugin/";
                     var rtcinterval = ' . $this->interval . ';
                     var rtcreply = ' . REPLY . ';</script>';
                 } else {
                     echo '<script type="text/javascript" src="' . $serendipity['baseURL'] . 'index.php?/plugin/rtcomments.js"></script>' . "\n";
                     echo '<script>var rtcbase = "' . $serendipity['baseURL'] . 'index.php?/plugin/";
                     var rtcinterval = ' . $this->interval . ';
                     var rtcreply = "' . REPLY . '";</script>';
                 }
                 return true;
                 break;
             case 'frontend_saveComment_finish':
                 $this->addNewComment($eventData['id'], $addData['comment_cid'], time());
                 return true;
                 break;
             default:
                 return false;
         }
     } else {
         return false;
     }
 }