[pLog-svn] r1910 - plugins/trunk/nestedcomments
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Thu Apr 28 13:53:46 GMT 2005
Author: oscar
Date: 2005-04-28 13:53:45 +0000 (Thu, 28 Apr 2005)
New Revision: 1910
Modified:
plugins/trunk/nestedcomments/pluginnestedcomments.class.php
Log:
fixed an annoyance in case the post had no comments.
Modified: plugins/trunk/nestedcomments/pluginnestedcomments.class.php
===================================================================
--- plugins/trunk/nestedcomments/pluginnestedcomments.class.php 2005-04-27 18:30:28 UTC (rev 1909)
+++ plugins/trunk/nestedcomments/pluginnestedcomments.class.php 2005-04-28 13:53:45 UTC (rev 1910)
@@ -1,12 +1,12 @@
<?php
include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
- include_once( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );
-
- /**
- * change this constant in case you want to redefine the limit for nested
- * comments
- */
+ include_once( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );
+
+ /**
+ * change this constant in case you want to redefine the limit for nested
+ * comments
+ */
define( "MAX_NESTED_COMMENTS", 6 );
class PluginNestedComments extends PluginBase
@@ -16,84 +16,91 @@
{
$this->id = "nestedcomments";
$this->author = "The pLog Team";
- $this->locales = Array();
-
- // description
- $this->desc = <<<EOD
-This plugin will generate a nested list of comments. In order to use it, edit your postandcomments.template file
-and where it says:
-<pre>
- {foreach from=\$comments item=comment}
-</pre>
-with:
-<pre>
- {assign var=comments value=\$nestedcomments->getNestedComments(\$post)}
- {foreach from=\$comments item=comment}
-</pre>
-In order to nest the comments, you can check the value of the "depth" field in order to know how
-deeply a certain comment should be nested but keeping in mind that the array of comments is already
-sorted correctly:
-<pre>
- {assign var=comments value=\$nestedcomments->getNestedComments(\$post)}
- {foreach from=\$comments item=comment}
- <div class="comment_{\$comment->getValue("depth")}">
- {\$comment->getTopic()}<br/>
- {\$comment->getText()}<br/>
- </div>
- {/foreach}
-</pre>
-In order to apply different graphical styles for different levels of nesting, define up to 6
-"comment_X" CSS classes (as in "comment_1", "comment_2", "comment_3", etc) in the CSS file used
-by your template set.
-<pre>
- .comment_1 {
- margin-left: 10px;
- }
- .comment_2 {
- margin-left: 20px;
- }
- .comment_3 {
- margin-left: 30px;
- }
- ...
- .comment_6 {
- margin-left: 60px;
- }
-</pre>
-By default there can only
-be up to 6 levels of nesting but this limit is configurable by editing the plugin file.
+ $this->locales = Array();
+
+ // description
+ $this->desc = <<<EOD
+This plugin will generate a nested list of comments. In order to use it, edit your postandcomments.template file
+and where it says:
+<pre>
+ {foreach from=\$comments item=comment}
+</pre>
+with:
+<pre>
+ {assign var=comments value=\$nestedcomments->getNestedComments(\$post)}
+ {foreach from=\$comments item=comment}
+</pre>
+In order to nest the comments, you can check the value of the "depth" field in order to know how
+deeply a certain comment should be nested but keeping in mind that the array of comments is already
+sorted correctly:
+<pre>
+ {assign var=comments value=\$nestedcomments->getNestedComments(\$post)}
+ {foreach from=\$comments item=comment}
+ <div class="comment_{\$comment->getValue("depth")}">
+ {\$comment->getTopic()}<br/>
+ {\$comment->getText()}<br/>
+ </div>
+ {/foreach}
+</pre>
+In order to apply different graphical styles for different levels of nesting, define up to 6
+"comment_X" CSS classes (as in "comment_1", "comment_2", "comment_3", etc) in the CSS file used
+by your template set.
+<pre>
+ .comment_1 {
+ margin-left: 10px;
+ }
+ .comment_2 {
+ margin-left: 20px;
+ }
+ .comment_3 {
+ margin-left: 30px;
+ }
+ ...
+ .comment_6 {
+ margin-left: 60px;
+ }
+</pre>
+By default there can only
+be up to 6 levels of nesting but this limit is configurable by editing the plugin file.
EOD;
}
-
- /**
- * @private
+
+ /**
+ * @private
*/
function _nestComments( $comments, $allComments, $depth = 0 )
- {
- $result = Array();
- foreach( $comments as $comment ) {
- if( $depth > MAX_NESTED_COMMENTS )
- $depth = MAX_NESTED_COMMENTS;
- $comment->setValue( "depth", $depth+1 );
- $result[] = $comment;
- if( isset($allComments[$comment->getId()]))
- $result = array_merge( $result, $this->_nestComments( $allComments[$comment->getId()], $allComments, $depth+1 ));
- }
- return( $result );
+ {
+ $result = Array();
+ foreach( $comments as $comment ) {
+ if( $depth > MAX_NESTED_COMMENTS )
+ $depth = MAX_NESTED_COMMENTS;
+ $comment->setValue( "depth", $depth+1 );
+ $result[] = $comment;
+ if( isset($allComments[$comment->getId()]))
+ $result = array_merge( $result, $this->_nestComments( $allComments[$comment->getId()], $allComments, $depth+1 ));
+ }
+ return( $result );
}
-
- /**
- * returns an array with the comments already sorted in the same way as they should
- * be nested. Use $comment->getValue( "depth" ) in order to know how deeply the comment
- * should be nested.
- *
- * @param post
- * @return An array of of UserComment objects
+
+ /**
+ * returns an array with the comments already sorted in the same way as they should
+ * be nested. Use $comment->getValue( "depth" ) in order to know how deeply the comment
+ * should be nested.
+ *
+ * @param post
+ * @return An array of of UserComment objects
*/
function getNestedComments( $post )
{
- $nestedComments = Array();
+ $nestedComments = Array();
$postComments = $post->getComments();
+
+ // if there are no comments for this post, we should
+ // prevent the php warning by returning for example an
+ // empty array
+ if( !is_array( $postComments ))
+ return( Array());
+
foreach( $postComments as $comment ) {
$key = $comment->getParentId();
if( $nestedComments["$key"] == "" )
@@ -102,9 +109,9 @@
$nestedComments["$key"][] = $comment;
}
- $comments = $this->_nestComments( $nestedComments[0], $nestedComments );
-
- return($comments);
+ $comments = $this->_nestComments( $nestedComments[0], $nestedComments );
+
+ return($comments);
}
}
?>
\ No newline at end of file
More information about the pLog-svn
mailing list