00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009 function panels_node_comments_panels_content_types() {
00010 if (module_exists('comment')) {
00011 $items['node_comments'] = array(
00012 'title' => t('Node comments'),
00013 'content_types' => 'panels_admin_content_types_node_comments',
00014 'single' => TRUE,
00015 'render callback' => 'panels_content_node_comments',
00016 'add callback' => 'panels_admin_edit_node_comments',
00017 'edit callback' => 'panels_admin_edit_node_comments',
00018 'title callback' => 'panels_admin_title_node_comments',
00019 );
00020 }
00021 return $items;
00022 }
00023
00024
00025
00026
00027
00028 function panels_content_node_comments($conf, $panel_args, $context) {
00029 $node = isset($context->data) ? drupal_clone($context->data) : NULL;
00030 $block = new stdClass();
00031 $block->module = 'comments';
00032 $block->delta = $node->nid;
00033
00034 $block->subject = t('Comments');
00035 if (empty($node)) {
00036 $block->content = t('Node comments go here.');
00037 }
00038 else {
00039 $block->content = panels_comment_render($node, $conf);
00040
00041 node_tag_new($node->nid);
00042 }
00043
00044 return $block;
00045 }
00046
00047
00048
00049
00050 function panels_admin_content_types_node_comments() {
00051 return array(
00052 'comments' => array(
00053 'title' => t('Node comments'),
00054 'icon' => 'icon_node.png',
00055 'path' => panels_get_path('content_types/node'),
00056 'description' => t('The comments of the referenced node.'),
00057 'required context' => new panels_required_context(t('Node'), 'node'),
00058 'category' => array(t('Node context'), -9),
00059 ),
00060 );
00061 }
00062
00063 function panels_admin_edit_node_comments($id, $parents, $conf = array()) {
00064 if (empty($conf)) {
00065 $conf = array(
00066 'mode' => _comment_get_display_setting('mode'),
00067 'order' => _comment_get_display_setting('sort'),
00068 'comments_per_page' => _comment_get_display_setting('comments_per_page'),
00069 );
00070 }
00071
00072 $form['mode'] = array(
00073 '#type' => 'select',
00074 '#title' => t('Mode'),
00075 '#default_value' => $conf['mode'],
00076 '#options' => _comment_get_modes(),
00077 '#weight' => 1,
00078 );
00079 $form['order'] = array(
00080 '#type' => 'select',
00081 '#title' => t('Sort'),
00082 '#default_value' => $conf['order'],
00083 '#options' => _comment_get_orders(),
00084 '#weight' => 2,
00085 );
00086 foreach (_comment_per_page() as $i) {
00087 $options[$i] = t('!a comments per page', array('!a' => $i));
00088 }
00089 $form['comments_per_page'] = array('#type' => 'select',
00090 '#title' => t('Pager'),
00091 '#default_value' => $conf['comments_per_page'],
00092 '#options' => $options,
00093 '#weight' => 3,
00094 );
00095 return $form;
00096 }
00097
00098 function panels_admin_title_node_comments($conf, $context) {
00099 return t('"@s" comments', array('@s' => $context->identifier));
00100 }
00101
00102
00103
00104
00105
00106
00107 function panels_comment_render($node, $conf) {
00108 if (!user_access('access comments')) {
00109 return;
00110 }
00111
00112 $mode = $conf['mode'];
00113 $order = $conf['order'];
00114 $comments_per_page = $conf['comments_per_page'];
00115
00116
00117 $query_count = 'SELECT COUNT(*) FROM {comments} WHERE nid = %d';
00118 $query = 'SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users, c.thread, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d';
00119
00120 $query_args = array($node->nid);
00121 if (!user_access('administer comments')) {
00122 $query .= ' AND c.status = %d';
00123 $query_count .= ' AND status = %d';
00124 $query_args[] = COMMENT_PUBLISHED;
00125 }
00126
00127 if ($order == COMMENT_ORDER_NEWEST_FIRST) {
00128 if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) {
00129 $query .= ' ORDER BY c.timestamp DESC';
00130 }
00131 else {
00132 $query .= ' ORDER BY c.thread DESC';
00133 }
00134 }
00135 else if ($order == COMMENT_ORDER_OLDEST_FIRST) {
00136 if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) {
00137 $query .= ' ORDER BY c.timestamp';
00138 }
00139 else {
00140 $query .= ' ORDER BY SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))';
00141 }
00142 }
00143
00144
00145 $result = pager_query($query, $comments_per_page, 0, $query_count, $query_args);
00146
00147 $divs = 0;
00148 $last_depth = 0;
00149 drupal_add_css(drupal_get_path('module', 'comment') .'/comment.css');
00150 while ($comment = db_fetch_object($result)) {
00151 $comment = drupal_unpack($comment);
00152 $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
00153 $comment->depth = count(explode('.', $comment->thread)) - 1;
00154
00155 if ($mode == COMMENT_MODE_THREADED_COLLAPSED || $mode == COMMENT_MODE_THREADED_EXPANDED) {
00156 if ($comment->depth > $last_depth) {
00157 $divs++;
00158 $output .= '<div class="indented">';
00159 $last_depth++;
00160 }
00161 else {
00162 while ($comment->depth < $last_depth) {
00163 $divs--;
00164 $output .= '</div>';
00165 $last_depth--;
00166 }
00167 }
00168 }
00169
00170 if ($mode == COMMENT_MODE_FLAT_COLLAPSED) {
00171 $output .= theme('comment_flat_collapsed', $comment);
00172 }
00173 else if ($mode == COMMENT_MODE_FLAT_EXPANDED) {
00174 $output .= theme('comment_flat_expanded', $comment);
00175 }
00176 else if ($mode == COMMENT_MODE_THREADED_COLLAPSED) {
00177 $output .= theme('comment_thread_collapsed', $comment);
00178 }
00179 else if ($mode == COMMENT_MODE_THREADED_EXPANDED) {
00180 $output .= theme('comment_thread_expanded', $comment);
00181 }
00182 }
00183 for ($i = 0; $i < $divs; $i++) {
00184 $output .= '</div>';
00185 }
00186 $output .= theme('pager', NULL, $comments_per_page, 0);
00187
00188 return $output;
00189 }
00190