/** * 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] .= "&" . CMT_TYPE . "={$type}&order={$order}&format={$mode}"; } else { list($plgurl, $plgid) = CMT_getCommentUrlId($type); $pLink[0] = "{$plgurl}?{$plgid}={$sid}"; $pLink[0] .= "&" . CMT_TYPE . "={$type}&order={$order}&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; }
/** * 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, poll, 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; if (!empty($_USER['uid'])) { $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 = 'ASC'; } 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 = new Template($_CONF['path_layout'] . 'comment'); $template->set_file(array('commentarea' => 'startcomment.thtml')); $template->set_var('xhtml', XHTML); $template->set_var('site_url', $_CONF['site_url']); $template->set_var('site_admin_url', $_CONF['site_admin_url']); $template->set_var('layout_url', $_CONF['layout_url']); $template->set_var('commentbar', CMT_commentBar($sid, $title, $type, $order, $mode, $ccode)); $template->set_var('sid', $sid); $template->set_var('comment_type', $type); 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); $thecomments .= CMT_getComment($result, $mode, $type, $order, $delete_option, false, $ccode); // Pagination $tot_pages = ceil($count / $limit); $pLink = $_CONF['site_url'] . "/article.php?story={$sid}&type={$type}&order={$order}&mode={$mode}"; $template->set_var('pagenav', COM_printPageNavigation($pLink, $page, $tot_pages)); $template->set_var('comments', $thecomments); $retval = $template->finish($template->parse('output', 'commentarea')); } return $retval; }
/** * 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, $sid_author_id = '') { global $_CONF, $_TABLES, $_USER, $LANG01; $retval = ''; if (!isset($_CONF['comment_engine'])) { $_CONF['comment_engine'] = 'internal'; } switch ($_CONF['comment_engine']) { case 'disqus': if ($type == 'article') { $pageURL = COM_buildUrl($_CONF['site_url'] . "/article.php?story={$sid}"); $pageIdentifier = 'article_' . $sid; } else { // for a plugin // Link to plugin defined link or lacking that a generic link that the plugin should support (hopefully) list($pageURL, $plgid) = PLG_getCommentUrlId($type); $pageIdentifier = $type . '_' . $sid; $pageURL = PLG_getItemInfo($type, $sid, 'url'); } $pageTitle = $title; $pageURL = str_replace('&', '&', $pageURL); $retval = ' <a name="comment_entry"></a> <div id="disqus_thread"></div> <script> var disqus_config = function () { this.page.url = \'' . $pageURL . '\'; this.page.identifier = \'' . $pageIdentifier . '\'; this.page.title = \'' . addslashes($pageTitle) . '\'; }; (function() { var d = document, s = d.createElement(\'script\'); s.src = \'//' . $_CONF['comment_disqus_shortname'] . '.disqus.com/embed.js\'; s.setAttribute(\'data-timestamp\', +new Date()); (d.head || d.body).appendChild(s); })(); </script> <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript> '; break; case 'facebook': if ($type == 'article') { $pageURL = COM_buildUrl($_CONF['site_url'] . "/article.php?story={$sid}"); $pageIdentifier = 'article_' . $sid; } else { // for a plugin // Link to plugin defined link or lacking that a generic link that the plugin should support (hopefully) list($pageURL, $plgid) = PLG_getCommentUrlId($type); $pageIdentifier = $type . '_' . $sid; $pageURL = PLG_getItemInfo($type, $sid, 'url'); } $pageTitle = urlencode($title); $pageURL = str_replace('&', '&', $pageURL); $retval = '<a name="comment_entry"></a><div class="fb-comments" data-href="' . $pageURL . '" data-numposts="20"></div>'; break; case 'internal': default: $valid_modes = array('threaded', 'nested', 'flat', 'nocomment'); if (in_array($mode, $valid_modes) === false) { $mode = 'nested'; } if ($mode == 'threaded') { $mode = 'nested'; } 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 = 'ASC'; } $validmodes = array('flat', 'nested', 'nocomment', 'nobar'); if (!in_array($mode, $validmodes)) { $mode = $_CONF['comment_mode']; } if (empty($mode)) { $mode = $_CONF['comment_mode']; } if (empty($limit)) { $limit = $_CONF['comment_limit']; } else { $limit = (int) $limit; } if (!is_numeric($page) || $page < 1) { $page = 1; } else { $page = (int) $page; } $start = $limit * ($page - 1); $template = new Template($_CONF['path_layout'] . 'comment'); $template->set_file(array('commentarea' => 'startcomment.thtml')); if ($mode != 'nobar') { $template->set_var('commentbar', CMT_commentBar($sid, $title, $type, $order, $mode, $ccode)); } $template->set_var('sid', $sid); $template->set_var('comment_type', $type); 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 = " . (int) $pid . " AND type='" . DB_escapeString($type) . "'"; } else { $count = DB_count($_TABLES['comments'], array('sid', 'type'), array(DB_escapeString($sid), DB_escapeString($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 = '" . DB_escapeString($sid) . "' AND type='" . DB_escapeString($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 = '" . DB_escapeString($sid) . "' AND (c.lft >= c2.lft AND c.lft <= c2.rht) " . "AND c2.cid = " . (int) $pid . " AND c.type='" . DB_escapeString($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 = '" . DB_escapeString($sid) . "' AND (c.lft >= c2.lft AND c.lft <= c2.rht) " . "AND c2.cid = " . (int) $pid . " AND c.uid = u.uid AND c.type='" . DB_escapeString($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(DB_escapeString($sid), DB_escapeString($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 = '" . DB_escapeString($sid) . "' AND c.uid = u.uid AND type='" . DB_escapeString($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 = '" . DB_escapeString($sid) . "' AND (c.lft > c2.lft AND c.lft < c2.rht) " . "AND c2.cid = " . (int) $pid . " AND c.type='" . DB_escapeString($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 = '" . DB_escapeString($sid) . "' AND (c.lft > c2.lft AND c.lft < c2.rht) " . "AND c2.cid = " . (int) $pid . " AND c.uid = u.uid AND c.type='" . DB_escapeString($type) . "' " . "ORDER BY {$cOrder} LIMIT {$start}, {$limit}"; } } break; } $thecomments = ''; $result = DB_query($q); $thecomments .= CMT_getComment($result, $mode, $type, $order, $delete_option, false, $ccode, $sid_author_id); // Pagination $tot_pages = ceil($count / $limit); if ($type == 'article') { $pLink = $_CONF['site_url'] . "/article.php?story={$sid}&type={$type}&order={$order}&mode={$mode}"; $pageStr = 'page='; } else { // plugin // Link to plugin defined link or lacking that a generic link that the plugin should support (hopefully) list($plgurl, $plgid, $plg_page_str) = PLG_getCommentUrlId($type); $pLink = $plgurl . '?' . $plgid . '=' . $sid . "&type={$type}&order={$order}&mode={$mode}"; if ($plg_page_str != '') { $pageStr = $plg_page_str; } else { $pageStr = 'page='; } } $template->set_var('pagenav', COM_printPageNavigation($pLink, $page, $tot_pages, $pageStr, false, '', '', '#comments')); $template->set_var('comments', $thecomments); } $retval = $template->finish($template->parse('output', 'commentarea')); break; } return $retval; }