コード例 #1
0
ファイル: template.php プロジェクト: voidfiles/explainthis
/**
 * Renders comment(s) without forms.
 *
 * @param $node
 *   The node which comment(s) needs rendering.
 * @param $cid
 *   Optional, if given, only one comment is rendered.
 *
 * @see comment_render.
 */
function comment_display_comment_render_without_form($node, $cid = 0)
{
    global $user;
    $output = '';
    if (user_access('access comments')) {
        // Pre-process variables.
        $nid = $node->nid;
        if (empty($nid)) {
            $nid = 0;
        }
        $mode = _comment_get_display_setting('mode', $node);
        $order = _comment_get_display_setting('sort', $node);
        $comments_per_page = _comment_get_display_setting('comments_per_page', $node);
        if ($cid && is_numeric($cid)) {
            // Single comment view.
            $query = 'SELECT c.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.signature, u.picture, u.data, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d';
            $query_args = array($cid);
            if (!user_access('administer comments')) {
                $query .= ' AND c.status = %d';
                $query_args[] = COMMENT_PUBLISHED;
            }
            $query = db_rewrite_sql($query, 'c', 'cid');
            $result = db_query($query, $query_args);
            if ($comment = db_fetch_object($result)) {
                $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
                $links = module_invoke_all('link', 'comment', $comment, 1);
                drupal_alter('link', $links, $node);
                $output .= theme('comment_view', $comment, $node, $links);
            }
        } else {
            // Multiple comment view
            $query_count = 'SELECT COUNT(*) FROM {comments} c WHERE c.nid = %d';
            $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.signature, u.picture, u.data, c.thread, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d';
            $query_args = array($nid);
            if (!user_access('administer comments')) {
                $query .= ' AND c.status = %d';
                $query_count .= ' AND c.status = %d';
                $query_args[] = COMMENT_PUBLISHED;
            }
            if ($order == COMMENT_ORDER_NEWEST_FIRST) {
                if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) {
                    $query .= ' ORDER BY c.cid DESC';
                } else {
                    $query .= ' ORDER BY c.thread DESC';
                }
            } else {
                if ($order == COMMENT_ORDER_OLDEST_FIRST) {
                    if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) {
                        $query .= ' ORDER BY c.cid';
                    } else {
                        // See comment above. Analysis reveals that this doesn't cost too
                        // much. It scales much much better than having the whole comment
                        // structure.
                        $query .= ' ORDER BY SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))';
                    }
                }
            }
            $query = db_rewrite_sql($query, 'c', 'cid');
            $query_count = db_rewrite_sql($query_count, 'c', 'cid');
            // Start a form, for use with comment control.
            $result = pager_query($query, $comments_per_page, 0, $query_count, $query_args);
            $divs = 0;
            $num_rows = FALSE;
            $comments = '';
            drupal_add_css(drupal_get_path('module', 'comment') . '/comment.css');
            while ($comment = db_fetch_object($result)) {
                $comment = drupal_unpack($comment);
                $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
                $comment->depth = count(explode('.', $comment->thread)) - 1;
                if ($mode == COMMENT_MODE_THREADED_COLLAPSED || $mode == COMMENT_MODE_THREADED_EXPANDED) {
                    if ($comment->depth > $divs) {
                        $divs++;
                        $comments .= '<div class="indented">';
                    } else {
                        while ($comment->depth < $divs) {
                            $divs--;
                            $comments .= '</div>';
                        }
                    }
                }
                if ($mode == COMMENT_MODE_FLAT_COLLAPSED) {
                    $comments .= theme('comment_flat_collapsed', $comment, $node);
                } else {
                    if ($mode == COMMENT_MODE_FLAT_EXPANDED) {
                        $comments .= theme('comment_flat_expanded', $comment, $node);
                    } else {
                        if ($mode == COMMENT_MODE_THREADED_COLLAPSED) {
                            $comments .= theme('comment_thread_collapsed', $comment, $node);
                        } else {
                            if ($mode == COMMENT_MODE_THREADED_EXPANDED) {
                                $comments .= theme('comment_thread_expanded', $comment, $node);
                            }
                        }
                    }
                }
                $num_rows = TRUE;
            }
            while ($divs-- > 0) {
                $comments .= '</div>';
            }
            $output .= $comments;
            $output .= theme('pager', NULL, $comments_per_page, 0);
        }
        $output = theme('comment_wrapper', $output, $node);
    }
    return $output;
}
コード例 #2
0
function rdf_sioc_xml_story_render($xml, $nid, $title, $type, $created, $changed, $last_updated, $uid, $body)
{
    $node_url = url($nid, array('absolute' => true));
    $xml .= "<sioc:Post rdf:about=\"{$node_url}\">\n";
    $xml .= "  <dc:title>{$title}</dc:title>\n";
    $xml .= "  <sioc:content>\n ";
    $xml .= "    <![CDATA[{$body}]]>\n";
    $xml .= "  </sioc:content>\n";
    $xml .= "  <dc:created>" . date(DATE_ISO8601, $created) . "</dc:created>\n";
    $xml .= "  <dc:modified>" . date(DATE_ISO8601, $changed) . "</dc:modified>\n";
    $xml .= "  <sioc:link rdf:resource=\"{$node_url}\" rdfs:label=\"{$title}\" />\n";
    $xml .= "  <sioc:has_creator rdf:nodeID=\"{$uid}\"/>\n";
    /*Add taxonomy terms as SIOC topics*/
    $query = db_query('SELECT tn.tid AS tid, td.name AS name FROM {term_node} tn, {term_data} td WHERE td.tid = tn.tid AND tn.nid = %d', $nid);
    while ($term = db_fetch_object($query)) {
        $taxonomy_terms = "  <sioc:topic rdfs:label=\"{$term->name}\" rdf:resource=\"" . url("taxonomy/term/{$term->tid}", array('absolute' => TRUE)) . "\" />\n";
    }
    $xml .= $taxonomy_terms;
    /*Add comments as SIOC replies*/
    $query_count = 'SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = %d';
    $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.signature, u.picture, u.data, c.thread, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d and c.status = %d ORDER BY SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))';
    $query_args = array($nid, COMMENT_PUBLISHED);
    $query = db_rewrite_sql($query, 'c', 'cid');
    $comment_children = 0;
    $num_rows = FALSE;
    $comments = '';
    $result = db_query($query, $query_args);
    while ($comment = db_fetch_object($result)) {
        $comment = drupal_unpack($comment);
        //    var_dump($comment);module_invoke_all('exit');return;
        //    $comment->depth = count(explode('.', $comment->thread)) - 1;
        //    if ($comment->depth > $comment_children) {
        //      $comment_children++;
        //      $comments .= "  <sioc:has_reply>\n";
        //    }
        //    else {
        //      while ($comment->depth < $comment_children) {
        //        $comment_children--;
        //        $comments .= "  </sioc:has_reply>\n";
        //      }
        //    }
        //    $comments .="     <sioc:Post rdf:about=\"$node_url#comment-$comment->cid\">\n";
        //    while ($comment_children-- > 0) {
        //      $num_rows = TRUE;
        //      $comments .="       <sioc:content><![CDATA[$comment->comment]]></sioc:content>\n";
        //      $comments .="     </sioc:Post>\n";
        //      $comments .= "  </sioc:has_reply>\n";
        //    }
        //  }
        $comments .= "  <sioc:has_reply>\n";
        $comments .= "    <sioc:Post rdf:about=\"{$node_url}#comment-{$comment->cid}\">\n";
        if ($comment->subject) {
            $comments .= "      <dc:title>{$comment->subject}</dc:title>\n";
        }
        if ($comment->timestamp) {
            $comments .= "      <dc:created>" . date(DATE_ISO8601, $comment->timestamp) . "</dc:created>\n";
        }
        if ($comment->uid) {
            $comments .= "    <sioc:has_creator>\n";
            $comments .= "      <sioc:User>\n";
            $comments .= "        <sioc:name>{$comment->registered_name}</sioc:name>\n";
            $comments .= "        <sioc:email rdf:resource=\"mailto:{$comment->mail}\"/>\n";
            $comments .= "         <sioc:link rdf:resource=\"" . url('user/' . $comment->uid, array('absolute' => true)) . "\" rdfs:label=\"{$comment->registered_name}\"/>\n";
            $comments .= "      </sioc:User>\n";
            $comments .= "    </sioc:has_creator>\n";
        }
        $comments .= "      <sioc:content><![CDATA[{$comment->comment}]]></sioc:content>\n";
        $comments .= "    </sioc:Post>\n";
        $comments .= "  </sioc:has_reply>\n";
    }
    $xml .= $comments;
    $xml .= "</sioc:Post>\n";
    return $xml;
}