[pLog-svn] r6910 - in plog/branches/lifetype-1.2/plugins: . getcategory

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Wed Sep 9 11:17:54 EDT 2009


Author: jondaley
Date: 2009-09-09 11:17:54 -0400 (Wed, 09 Sep 2009)
New Revision: 6910

Added:
   plog/branches/lifetype-1.2/plugins/getcategory/
   plog/branches/lifetype-1.2/plugins/getcategory/README.txt
   plog/branches/lifetype-1.2/plugins/getcategory/plugingetcategory.class.php
Log:
get category plugin - I've used it for a while to grab 'random' articles in different templates.  A user on the forums just requested the same behavior, so I'm finally getting around to checking it in.

Added: plog/branches/lifetype-1.2/plugins/getcategory/README.txt
===================================================================
--- plog/branches/lifetype-1.2/plugins/getcategory/README.txt	                        (rev 0)
+++ plog/branches/lifetype-1.2/plugins/getcategory/README.txt	2009-09-09 15:17:54 UTC (rev 6910)
@@ -0,0 +1,26 @@
+Get Category plugin for LifeType.
+Author: Jon Daley
+URL: http://limedaley.com/
+
+This plugin will retrieve any number of articles given a category
+name, perhaps useful for sticky posts, etc.
+
+Example template code:
+
+{if $getcategory}
+ <div id="Press">
+  <h2><a href="/category/press-releases">Press Releases</a></h2>
+  {assign var="pressarticles" 
+          value=$getcategory->getArticles("Press Releases", 3)}
+  {foreach from=$pressarticles item=pa}
+   <p>
+    {assign var="postTitle" value=$pa->getTopic()}
+    {assign var="permLink" value=$url->postPermalink($pa)}
+    {if $postTitle != "Press and Analyst Contacts"}
+       <a href="{$permLink}">{$postTitle}</a><br/>
+       {$pa->getText()|strip_tags|truncate:300:" ...":false}
+    {/if}
+   </p>
+  {/foreach}
+ </div>
+{/if}

Added: plog/branches/lifetype-1.2/plugins/getcategory/plugingetcategory.class.php
===================================================================
--- plog/branches/lifetype-1.2/plugins/getcategory/plugingetcategory.class.php	                        (rev 0)
+++ plog/branches/lifetype-1.2/plugins/getcategory/plugingetcategory.class.php	2009-09-09 15:17:54 UTC (rev 6910)
@@ -0,0 +1,54 @@
+<?php
+ 
+lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+    
+    /*
+     * Plugin that return all posts within a category
+     */
+class PluginGetCategory extends PluginBase
+{
+	
+    function PluginGetCategory($source = ""){
+        $this->PluginBase($source);
+
+	    $this->id = "getcategory";
+        $this->version = "20070914";
+        $this->author = "Jon Daley";
+        $this->desc = "This plugin adds the ability to get ".
+            "posts given a category name";
+    }
+
+    function getArticles($categoryName, $numArticles){
+        lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
+        lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+        lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+        $categories = new ArticleCategories();
+        $mangledName = Textfilter::urlize($categoryName);
+        $category = $categories->getCategoryByName($mangledName,
+                                                   $this->blogInfo->getId());
+        if(!$category){
+            print "couldn't find";
+            return Array();
+        }
+        $articles = new Articles();
+        $arts = $articles->getBlogArticles( $this->blogInfo->getId(),
+                                            -1,
+                                            $numArticles,
+                                            $category->getId());
+           
+        return $arts;
+    }
+
+    function getArticle($articleName){
+        lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+
+        $articles = new Articles();
+        $article = $articles->getBlogArticleByTitle($articleName, 
+                                                    $this->blogInfo->getId());
+        return $article;;
+    }
+
+}
+        
+        
+?>



More information about the pLog-svn mailing list