Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24677
Modified Files:
Tag: branch-smarty
serendipity_config.inc.php serendipity_functions.inc.php
Log Message:
- Move recursive/threaded comments into Smarty
- Move printComment and printTrackbacks into the template, in order to use the $entry and other smarty variables within those.
- Allow the usage of sprintf, sizeof and count as a modifier in Smarty
- Remove is_cview stuff and do a more native thing in entries.tpl
- Unset large arrays to free memory
TODO: Comment preview doesn't work, yet
TODO: Annonymous comments have b0rked delete prompts
Index: serendipity_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_functions.inc.php,v
retrieving revision 1.419.2.43
retrieving revision 1.419.2.44
diff -u -d -r1.419.2.43 -r1.419.2.44
--- serendipity_functions.inc.php 7 Oct 2004 10:32:04 -0000 1.419.2.43
+++ serendipity_functions.inc.php 9 Oct 2004 23:16:26 -0000 1.419.2.44
@@ -1007,10 +1007,7 @@
/* IF WE ARE DISPLAYING A FULL ENTRY */
if (isset($serendipity['GET']['id'])) {
- serendipity_printTrackbacks(serendipity_fetchTrackbacks($entry['id']));
-
- ob_start(); // TODO: Remove recursion and output buffering
- serendipity_printComments(serendipity_fetchComments($entry['id']), $viewmode);
+ $entry['viewmode'] = ($serendipity['GET']['cview']) ? $serendipity['GET']['cview'] : VIEWMODE_THREADED;
if (!empty($serendipity['POST']['preview'])) {
serendipity_printComments(
@@ -1028,19 +1025,8 @@
);
}
- $serendipity['smarty']->assign('comments_list', ob_get_contents());
- ob_end_clean();
- serendipity_smarty_fetch('COMMENTS', 'comments.tpl');
-
- if ($serendipity['GET']['cview'] == VIEWMODE_LINEAR) {
- $serendipity['smarty']->assign('is_cview_linear', true);
- } else {
- $serendipity['smarty']->assign('is_cview_linear', false);
- }
-
$serendipity['smarty']->assign(
array(
- 'is_cview_linear' => ($serendipity['GET']['cview'] == VIEWMODE_LINEAR ? true : false),
'comments_messagestack' => (isset($serendipity['messagestack']['comments']) ? (array)$serendipity['messagestack']['comments'] : false),
'is_comment_added' => (isset($serendipity['GET']['csuccess']) && $serendipity['GET']['csuccess'] == 'true' ? true: false),
'is_comment_moderate' => (isset($serendipity['GET']['csuccess']) && $serendipity['GET']['csuccess'] == 'moderate' ? true: false)
@@ -1069,6 +1055,7 @@
}
$serendipity['smarty']->assign('entries', $dategroup);
+ unset($entries, $dategroup);
if (isset($serendipity['short_archives']) && $serendipity['short_archives']) {
serendipity_smarty_fetch('ENTRIES', 'entries_summary.tpl', true);
@@ -1226,104 +1213,74 @@
return $retval;
}
-/*TODO: Don't know how to get recursion done with Smarty in a smarty way.*/
-function serendipity_printComments($comments, $parentid = 0, $indent = '') {
+function serendipity_printComments($comments, $parentid = 0, $depth = 0, $trace = null) {
global $serendipity;
+ static $_smartyComments;
+ /* $_smarty_comment sholds the ending smarty array
+ $level is the current depth of the recurrence
+ $i is the position in the current depth */
if ($parentid === VIEWMODE_THREADED) {
$parentid = 0;
}
- if (!count($comments) && !$parentid) {
-?>
- <div class="serendipity_center"><?php echo NO_COMMENTS; ?></div>
-<?php
+ /* Wait a second, we just got attacked by a call with level 0,
+ this must mean we've started over */
+ if ( $depth == 0 ) {
+ $_smartyComments = array();
}
+
$i = 0;
foreach ($comments as $comment) {
-
if ($parentid === VIEWMODE_LINEAR || !isset($comment['parent_id']) || $comment['parent_id'] == $parentid) {
$i++;
$comment['comment'] = htmlspecialchars(strip_tags($comment['body']));
$comment['url'] = strip_tags($comment['url']);
+ $comment['link_delete'] = $serendipity['baseURL'] . 'comment.php?serendipity[delete]=' . $comment['id'] . '&serendipity[entry]=' . $comment['entry_id'] . '&serendipity[type]=comments';
+
+ /* Fix fucked links */
if (!empty($comment['url']) && substr($comment['url'], 0, 7) != 'http://' && substr($comment['url'], 0, 8) != 'https://') {
$comment['url'] = 'http://' . $comment['url'];
}
serendipity_plugin_api::hook_event('frontend_display', $comment);
- /* Protect submitted mails against spam, by replacing @ with [at]*/
if (!empty($comment['email'])) {
$comment['email'] = str_replace('@', '[at]', $comment['email']);
}
- $name = empty($comment['username']) ? ANONYMOUS : $comment['username'];
- $body = $comment['comment'];
-?>
- <div class="serendipity_comment">
- <a <?php echo ($serendipity['XHTML11'] ? 'id' : 'name'); ?>="c<?php echo $comment['id']; ?>"></a>
- <div class="serendipity_commentBody"><?php echo $body; ?></div>
-
- <div class="serendipity_comment_source">
- <a href="#c<?php echo $comment['id']; ?>" title="<?php echo LINK_TO_COMMENT . $indent . $i; ?>">#<?php echo $indent . $i; ?></a>
-<?php
- /* Link to the user's email */
- if (!empty($comment['email'])) {
- echo '<a href="mailto:' . htmlspecialchars($comment['email']) . '" title="' . SEND_MAIL_TO . ' ' . htmlspecialchars($name) . ' (' . htmlspecialchars(strip_tags($comment['email'])) . ')">' . htmlspecialchars($name) . '</a>';
- } else {
- echo htmlspecialchars($name);
- }
-
- /* Create a link or plain text depending on spam control settings */
- $showlink = serendipity_get_config_var('top_as_links', true);
- if ($showlink === true) {
- $linktext = ' (<a href="' . str_replace('"', '"', $comment['url']) . '" ' . serendipity_xhtml_target('_blank') . ' title="' . htmlspecialchars($comment['url']) . '">Link</a>)';
- } else {
- $linktext = ' (' . htmlspecialchars($comment['url']) . ") ";
- }
-
- /* Link to the user's website only if the URL is valid */
- if ((!isset($comment['type']) || $comment['type'] != 'trackback') && !empty($comment['url']) && $comment['url'] != 'http://' && eregi('^https?://', $comment['url'])) {
- echo $linktext;
- }
-
- /* Show when the entry was made */
- echo ' ' . ON . ' ' . ucfirst(strftime('%b %e %Y, %H:%M', $comment['timestamp']));
+ $comment['author'] = $comment['username'];
+ $comment['body'] = $comment['comment'];
+ $comment['pos'] = $i;
+ $comment['trace'] = $trace . $i;
+ $comment['depth'] = $depth;
- if ($show_admin && $_SESSION['serendipityAuthedUser'] === true && ($_SESSION['serendipityUserlevel'] >= USERLEVEL_CHIEF || $_SESSION['serendipityAuthorid'] == $comment['authorid'])) {
- echo ' (<a href="' . $serendipity['baseURL'] . 'comment.php?serendipity[delete]=' . $comment['id'] . '&serendipity[entry]=' . $comment['entry_id'] . '&serendipity[type]=comments" onclick="return confirm(\''. sprintf(COMMENT_DELETE_CONFIRM, $comment['id'], htmlspecialchars($name)) .'\')">' . DELETE . '</a>)';
+ $_smartyComments[] = $comment;
+ if ($comment['id'] && $parentid !== VIEWMODE_LINEAR ) {
+ serendipity_printComments($comments, $comment['id'], ($depth+1), ($trace . $i .'.'));
}
-
- /* Allow people to easily reply to this comment */
- echo ' <a href="#serendipity_CommentForm" onclick="document.getElementById(\'serendipity_replyTo\').value=\'' . $comment['id'] . '\';">' . REPLY . '</a>';
-?>
- </div>
-<?php
- if ($comment['id'] && $parentid !== VIEWMODE_LINEAR ) {
- serendipity_printComments($comments, $comment['id'], $indent . $i . '.');
- }
-?>
- </div>
-<?php
}
}
- if ($parentid != 0 && $parentid !== VIEWMODE_LINEAR) {
+ /* We are inside a recusive child, and we need to break out */
+ if ( $depth !== 0 ) {
return true;
}
+
+ $serendipity['smarty']->assign('comments', $_smartyComments);
+ unset($_smartyComments);
+
+ return serendipity_smarty_fetch('COMMENTS', 'comments.tpl');
}
-function serendipity_printTrackbacks($comments)
-{
+function serendipity_printTrackbacks($trackbacks) {
global $serendipity;
- $serendipity['smarty']->assign('is_trackbacks_owner', ($_SESSION["serendipityAuthedUser"] === true && ($_SESSION['serendipityUserlevel'] >= USERLEVEL_CHIEF || isset($comment[0]) && $_SESSION['serendipityAuthorid'] == $comment[0]['authorid'])) ? true : false);
- $serendipity['smarty']->assign('trackbacks', $comments);
- $serendipity['smarty']->assign('trackbacks_count', sizeof($comments));
+ $serendipity['smarty']->assign('trackbacks', $trackbacks);
- serendipity_smarty_fetch('TRACKBACKS', 'trackbacks.tpl');
+ return serendipity_smarty_fetch('TRACKBACKS', 'trackbacks.tpl');
}
function serendipity_approveComment($cid, $entry_id, $force = false) {
@@ -3197,7 +3154,7 @@
function serendipity_smarty_fetch($block, $file, $echo = false) {
global $serendipity;
- $output = &$serendipity['smarty']->fetch('file:'. serendipity_getTemplateFile($file, 'serendipityPath'), null, null, ($echo === true && $serendipity['smarty_raw_mode']));
+ $output = $serendipity['smarty']->fetch('file:'. serendipity_getTemplateFile($file, 'serendipityPath'), null, null, ($echo === true && $serendipity['smarty_raw_mode']));
$serendipity['smarty']->assign($block, $output);
return $output;
@@ -3266,6 +3223,29 @@
}
}
+function serendipity_smarty_printComments($params, &$smarty) {
+ if ( !isset($params['entry']) ) {
+ $smarty->trigger_error(__FUNCTION__ .": missing 'entry' parameter");
+ return;
+ }
+
+ if ( !isset($params['mode']) ) {
+ $params['mode'] = VIEWMODE_THREADED;
+ }
+
+ return serendipity_printComments(serendipity_fetchComments($params['entry']), $params['mode']);
+}
+
+function serendipity_smarty_printTrackbacks($params, &$smarty) {
+ if ( !isset($params['entry']) ) {
+ $smarty->trigger_error(__FUNCTION__ .": missing 'entry' parameter");
+ return;
+ }
+
+ return serendipity_printTrackbacks(serendipity_fetchTrackbacks($params['entry']));
+}
+
+
define("serendipity_FUNCTIONS_LOADED", true);
/* vim: set sts=4 ts=4 expandtab : */
?>
Index: serendipity_config.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_config.inc.php,v
retrieving revision 1.93.2.12
retrieving revision 1.93.2.13
diff -u -d -r1.93.2.12 -r1.93.2.13
--- serendipity_config.inc.php 7 Oct 2004 14:00:13 -0000 1.93.2.12
+++ serendipity_config.inc.php 9 Oct 2004 23:16:26 -0000 1.93.2.13
@@ -235,6 +235,7 @@
$serendipity['smarty']->compile_dir = $serendipity['serendipityPath'] . PATH_SMARTY_COMPILE;
$serendipity['smarty']->config_dir = &$serendipity['smarty']->template_dir;
$serendipity['smarty']->secure_dir = array($serendipity['serendipityPath'] . $serendipity['templatePath']);
+$serendipity['smarty']->security_settings['MODIFIER_FUNCS'] = array('sprintf', 'sizeof', 'count');
$serendipity['smarty']->security = true;
$serendipity['smarty']->use_sub_dirs = false;
$serendipity['smarty']->compile_check = true;
@@ -248,6 +249,9 @@
$serendipity['smarty']->register_function('serendipity_printSidebar', 'serendipity_smarty_printSidebar');
$serendipity['smarty']->register_function('serendipity_hookPlugin', 'serendipity_smarty_hookPlugin');
$serendipity['smarty']->register_function('serendipity_getFile', 'serendipity_smarty_getFile');
+$serendipity['smarty']->register_function('serendipity_printComments', 'serendipity_smarty_printComments');
+$serendipity['smarty']->register_function('serendipity_printTrackbacks', 'serendipity_smarty_printTrackbacks');
+
/* vim: set sts=4 ts=4 expandtab : */
?>
|