Esempio n. 1
0
* @author   Jason Whittenburg
* @author   Tony Bibbs, tonyAT tonybibbs DOT com
* @author   Vincent Furia, vinny01 AT users DOT sourceforge DOT net
* @author   Jared Wenerd, wenerd87 AT gmail DOT com
*
*/
/**
* Geeklog common function library
*/
require_once 'lib-common.php';
/**
 * Geeklog comment function library
 */
require_once $_CONF['path_system'] . 'lib-comment.php';
// Uncomment the line below if you need to debug the HTTP variables being passed
// to the script.  This will sometimes cause errors but it will allow you to see
// the data being passed in a POST operation
// echo COM_debug($_POST);
// MAIN
CMT_updateCommentcodes();
$display = '';
// If reply specified, force comment submission form
if (isset($_REQUEST['reply'])) {
    $_REQUEST['mode'] = '';
}
$mode = '';
if (!empty($_REQUEST['mode'])) {
    $mode = COM_applyFilter($_REQUEST['mode']);
}
$display .= CMT_handleComment($mode);
COM_output($display);
Esempio n. 2
0
/**
* This function displays the comments in a high level format.
*
* Begins displaying user comments for an item
*
* @param    string      $sid       ID for item to show comments for
* @param    string      $title     Title of item
* @param    string      $type      Type of item (article, polls, etc.)
* @param    string      $order     How to order the comments 'ASC' or 'DESC'
* @param    string      $mode      comment mode (nested, flat, etc.)
* @param    int         $pid       id of parent comment
* @param    int         $page      page number of comments to display
* @param    boolean     $cid       true if $pid should be interpreted as a cid instead
* @param    boolean     $delete_option   if current user can delete comments
* @param    int         $ccode     Comment code: -1=no comments, 0=allowed, 1=closed
* @return   string  HTML Formated Comments
* @see CMT_commentBar
*
*/
function CMT_userComments($sid, $title, $type = 'article', $order = '', $mode = '', $pid = 0, $page = 1, $cid = false, $delete_option = false, $ccode = 0)
{
    global $_CONF, $_TABLES, $_USER, $LANG01;
    $retval = '';
    if (!COM_isAnonUser()) {
        $result = DB_query("SELECT commentorder,commentmode,commentlimit FROM {$_TABLES['usercomment']} WHERE uid = '{$_USER['uid']}'");
        $U = DB_fetchArray($result);
        if (empty($order)) {
            $order = $U['commentorder'];
        }
        if (empty($mode)) {
            $mode = $U['commentmode'];
        }
        $limit = $U['commentlimit'];
    }
    if ($order != 'ASC' && $order != 'DESC') {
        $order = $_CONF['comment_order'];
    }
    if (empty($mode)) {
        $mode = $_CONF['comment_mode'];
    }
    if (empty($limit)) {
        $limit = $_CONF['comment_limit'];
    }
    if (!is_numeric($page) || $page < 1) {
        $page = 1;
    }
    $start = $limit * ($page - 1);
    $template = COM_newTemplate($_CONF['path_layout'] . 'comment');
    $template->set_file(array('commentarea' => 'startcomment.thtml'));
    $template->set_var('commentbar', CMT_commentBar($sid, $title, $type, $order, $mode, $ccode));
    $template->set_var('sid', $sid);
    $template->set_var('comment_type', $type);
    $template->set_var('area_id', 'commentarea');
    if ($mode == 'nested' || $mode == 'threaded' || $mode == 'flat') {
        // build query
        switch ($mode) {
            case 'flat':
                if ($cid) {
                    $count = 1;
                    $q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, " . "UNIX_TIMESTAMP(c.date) AS nice_date " . "FROM {$_TABLES['comments']} AS c, {$_TABLES['users']} AS u " . "WHERE c.uid = u.uid AND c.cid = {$pid} AND type='{$type}'";
                } else {
                    $count = DB_count($_TABLES['comments'], array('sid', 'type'), array($sid, $type));
                    $q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, " . "UNIX_TIMESTAMP(c.date) AS nice_date " . "FROM {$_TABLES['comments']} AS c, {$_TABLES['users']} AS u " . "WHERE c.uid = u.uid AND c.sid = '{$sid}' AND type='{$type}' " . "ORDER BY date {$order} LIMIT {$start}, {$limit}";
                }
                break;
            case 'nested':
            case 'threaded':
            default:
                if ($order == 'DESC') {
                    $cOrder = 'c.rht DESC';
                } else {
                    $cOrder = 'c.lft ASC';
                }
                // We can simplify the query, and hence increase performance
                // when pid = 0 (when fetching all the comments for a given sid)
                if ($cid) {
                    // pid refers to commentid rather than parentid
                    // count the total number of applicable comments
                    $q2 = "SELECT COUNT(*) " . "FROM {$_TABLES['comments']} AS c, {$_TABLES['comments']} AS c2 " . "WHERE c.sid = '{$sid}' AND (c.lft >= c2.lft AND c.lft <= c2.rht) " . "AND c2.cid = {$pid} AND c.type='{$type}'";
                    $result = DB_query($q2);
                    list($count) = DB_fetchArray($result);
                    $q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, c2.indent AS pindent, " . "UNIX_TIMESTAMP(c.date) AS nice_date " . "FROM {$_TABLES['comments']} AS c, {$_TABLES['comments']} AS c2, " . "{$_TABLES['users']} AS u " . "WHERE c.sid = '{$sid}' AND (c.lft >= c2.lft AND c.lft <= c2.rht) " . "AND c2.cid = {$pid} AND c.uid = u.uid AND c.type='{$type}' " . "ORDER BY {$cOrder} LIMIT {$start}, {$limit}";
                } else {
                    // pid refers to parentid rather than commentid
                    if ($pid == 0) {
                        // the simple, fast case
                        // count the total number of applicable comments
                        $count = DB_count($_TABLES['comments'], array('sid', 'type'), array($sid, $type));
                        $q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, 0 AS pindent, " . "UNIX_TIMESTAMP(c.date) AS nice_date " . "FROM {$_TABLES['comments']} AS c, {$_TABLES['users']} AS u " . "WHERE c.sid = '{$sid}' AND c.uid = u.uid  AND type='{$type}' " . "ORDER BY {$cOrder} LIMIT {$start}, {$limit}";
                    } else {
                        // count the total number of applicable comments
                        $q2 = "SELECT COUNT(*) " . "FROM {$_TABLES['comments']} AS c, {$_TABLES['comments']} AS c2 " . "WHERE c.sid = '{$sid}' AND (c.lft > c2.lft AND c.lft < c2.rht) " . "AND c2.cid = {$pid} AND c.type='{$type}'";
                        $result = DB_query($q2);
                        list($count) = DB_fetchArray($result);
                        $q = "SELECT c.*, u.username, u.fullname, u.photo, u.email, c2.indent + 1 AS pindent, " . "UNIX_TIMESTAMP(c.date) AS nice_date " . "FROM {$_TABLES['comments']} AS c, {$_TABLES['comments']} AS c2, " . "{$_TABLES['users']} AS u " . "WHERE c.sid = '{$sid}' AND (c.lft > c2.lft AND c.lft < c2.rht) " . "AND c2.cid = {$pid} AND c.uid = u.uid AND c.type='{$type}' " . "ORDER BY {$cOrder} LIMIT {$start}, {$limit}";
                    }
                }
                break;
        }
        $thecomments = '';
        $result = DB_query($q);
        if (DB_numRows($result) == 0) {
            if ($page > 1) {
                list($plgurl, $plgid) = CMT_getCommentUrlId($type);
                $plglink = '';
                if (!empty($plgurl)) {
                    $plglink = "{$plgurl}?{$plgid}={$sid}";
                }
                // Requested invalid page
                COM_handle404($plglink);
            }
        }
        $thecomments .= CMT_getComment($result, $mode, $type, $order, $delete_option, false, $ccode, $page);
        // Pagination
        $tot_pages = ceil($count / $limit);
        $is_comment_page = CMT_isCommentPage();
        if ($is_comment_page) {
            $pLink[0] = "comment.php?sid={$sid}";
            $pLink[0] .= "&amp;" . CMT_TYPE . "={$type}&amp;order={$order}&amp;format={$mode}";
        } else {
            list($plgurl, $plgid) = CMT_getCommentUrlId($type);
            $pLink[0] = "{$plgurl}?{$plgid}={$sid}";
            $pLink[0] .= "&amp;" . CMT_TYPE . "={$type}&amp;order={$order}&amp;mode={$mode}";
        }
        $pLink[1] = "#comments";
        $page_str = "cpage=";
        $template->set_var('pagenav', COM_printPageNavigation($pLink, $page, $tot_pages, $page_str, false));
        $template->set_var('comments', $thecomments);
        if (COMMENT_ON_SAME_PAGE) {
            if ($ccode == 0) {
                $cmode = COM_applyFilter(COM_getArgument(CMT_MODE));
                $html = CMT_handleComment($cmode, $type, $title, $sid, $mode);
                $template->set_var('commenteditor', $html);
            }
        }
        $retval = $template->finish($template->parse('output', 'commentarea'));
    }
    return $retval;
}