[pLog-svn] r2245 - in plog/branches/plog-1.0.2/plugins: .
categorybrowser
Jon Daley
plogworld at daley.snurgle.org
Fri Jun 17 15:16:25 GMT 2005
oops. wrong tree.
On Fri, 17 Jun 2005 jondaley at devel.plogworld.net wrote:
> Author: jondaley
> Date: 2005-06-17 14:58:05 +0000 (Fri, 17 Jun 2005)
> New Revision: 2245
>
> Added:
> plog/branches/plog-1.0.2/plugins/categorybrowser/
> plog/branches/plog-1.0.2/plugins/categorybrowser/README.txt
> plog/branches/plog-1.0.2/plugins/categorybrowser/locale/
> plog/branches/plog-1.0.2/plugins/categorybrowser/plugincategorybrowser.class.php
> Log:
> new plugin, first,prev,next,last buttons for each post, stays within given category
>
> Added: plog/branches/plog-1.0.2/plugins/categorybrowser/README.txt
> ===================================================================
> --- plog/branches/plog-1.0.2/plugins/categorybrowser/README.txt 2005-06-16 15:51:34 UTC (rev 2244)
> +++ plog/branches/plog-1.0.2/plugins/categorybrowser/README.txt 2005-06-17 14:58:05 UTC (rev 2245)
> @@ -0,0 +1,71 @@
> +Category Browser plugin for pLog.
> +Author: Jon Daley
> +URL: http://limedaley.com/
> +
> +Example URL using this plugin: http://limedaley.com/~jondaley/plog/
> +
> +The default getNext and getPrev post do not obey category boundaries,
> +and you might have readers who are only interested in certain
> +categories.
> +
> +This plugin has four functions to get the first, previous, next, and
> +latest posts in any given category.
> +
> +Here are the available functions:
> +{assign var="postInCategoryFirst"
> + value=$categorybrowser->getFirstArticle($categoryId, $blogId)}
> +{assign var="postInCategoryPrev"
> + value=$categorybrowser->getPrevArticle($post, $categoryId, $blogId)}
> +{assign var="postInCategoryNext"
> + value=$categorybrowser->getNextArticle($post, $categoryId, $blogId)}
> +{assign var="postInCategoryLast"
> + value=$categorybrowser->getLastArticle($categoryId, $blogId)}
> +
> +
> +
> +Here is the code I use in my template, it might be fancier that you
> +want, but I think this looks pretty good.
> +
> +Category
> + {foreach name=categories from=$post->getCategories()
> + item=postCategory}
> + {assign var=categoryName value=$postCategory->getName()}
> + {assign var="blogId" value=$blog->getId()}
> + {assign var="categoryId" value=$postCategory->getId()}
> + {assign var="postInCategoryFirst"
> + value=$categorybrowser->getFirstArticle($categoryId, $blogId)}
> + {assign var="postInCategoryPrev"
> + value=$categorybrowser->getPrevArticle($post, $categoryId, $blogId)}
> + {assign var="postInCategoryNext"
> + value=$categorybrowser->getNextArticle($post, $categoryId, $blogId)}
> + {assign var="postInCategoryLast"
> + value=$categorybrowser->getLastArticle($categoryId, $blogId)}
> +
> + <a href="{$url->categoryLink($postCategory)}">{$categoryName}</a>:
> + <span class="nodisplay">
> + {if $postInCategoryFirst &&
> + ($postInCategoryFirst->getId() != $post->getId())}
> + </span>[<a
> + href="{$url->postPermalink($postInCategoryFirst)}">first</a>]<span
> + class="nodisplay">
> + {/if}
> + {if $postInCategoryPrev &&
> + ($postInCategoryPrev->getId() != $postInCategoryFirst->getId())}
> + </span>[<a
> + href="{$url->postPermalink($postInCategoryPrev)}">previous</a>]<span
> + class="nodisplay">
> + {/if}
> + {if $postInCategoryNext &&
> + ($postInCategoryNext->getId() != $postInCategoryLast->getId())}
> + </span>[<a
> + href="{$url->postPermalink($postInCategoryNext)}">next</a>]<span
> + class="nodisplay">
> + {/if}
> + {if $postInCategoryLast &&
> + ($postInCategoryLast->getId() != $post->getId())}
> + </span>[<a
> + href="{$url->postPermalink($postInCategoryLast)}">newest</a>]<span
> + class="nodisplay">
> + {/if}
> + </span>
> + {/foreach}
>
> Added: plog/branches/plog-1.0.2/plugins/categorybrowser/plugincategorybrowser.class.php
> ===================================================================
> --- plog/branches/plog-1.0.2/plugins/categorybrowser/plugincategorybrowser.class.php 2005-06-16 15:51:34 UTC (rev 2244)
> +++ plog/branches/plog-1.0.2/plugins/categorybrowser/plugincategorybrowser.class.php 2005-06-17 14:58:05 UTC (rev 2245)
> @@ -0,0 +1,132 @@
> +<?php
> +
> +include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
> +include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
> +include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
> +include_once( PLOG_CLASS_PATH."class/dao/article.class.php" );
> +
> + /*
> + * Plugin that offers features to return links to the next and previous articles
> + * within the current category
> + */
> +class PluginCategoryBrowser extends PluginBase
> +{
> + var $_articles;
> + var $_prefix;
> +
> + function PluginCategoryBrowser(){
> + $this->author = "Jon Daley";
> + $this->desc = "This plugin adds the ability to have next
> + and previous buttons that stay within the same category as the
> + current post<br/>Usage:<br/>Functions:<br/>
> + getPrevArticle(currArticle, blogId)<br/>
> + getNextArticle(currArticle, blogId)<br/>
> + getFirstArticle(categoryId, blogId) and<br/>
> + getLastArticle(categoryId, blogId)<br/>
> + Given an article the Prev and Next functions will
> + return the previous and next posts in the same
> + category as the given article.<br/>
> + Given a category id, the First and Last functions
> + will return the first and last posts in the same
> + category.<br/>
> + They will return false if it doesn't exist, or an Article
> + object if it does.<br/>";
> +
> + $this->PluginBase();
> + $this->db =& Db::getDb();
> + $config =& Config::getConfig();
> + $this->_prefix = $config->getValue('db_prefix');
> + $this->id = "categorybrowser";
> + $this->$_articles = new Articles();
> + }
> +
> + function getPrevArticle($article, $categoryId, $blogId){
> + // gets the article that is just before this one in
> + // the same category
> + $query = "SELECT id FROM " . $this->_prefix .
> + "articles, " . $this->_prefix."article_categories_link" .
> + " WHERE date < '" . $article->getDate() .
> + "' AND status=1 AND blog_id = " . $blogId .
> + " AND category_id = " . $categoryId .
> + " and article_id = id" .
> + " ORDER BY date DESC LIMIT 1;";
> +
> + $result = $this->db->Execute($query);
> + if(!$result || ($result->RecordCount() == 0))
> + return false;
> +
> + // get the information from the article
> + $row = $result->FetchRow();
> +
> + // fetch the article
> + return $this->$_articles->getBlogArticle($row["id"], $blogId);
> + }
> +
> + function getNextArticle($article, $categoryId, $blogId){
> + // gets the article that is just after this one in
> + // the same category
> + $query = "SELECT id FROM " . $this->_prefix .
> + "articles, " . $this->_prefix."article_categories_link" .
> + " WHERE date > '" . $article->getDate() .
> + "' AND status=1 AND blog_id = " . $blogId .
> + " AND category_id = " . $categoryId .
> + " and article_id = id" .
> + " ORDER BY date LIMIT 1;";
> +
> + $result = $this->db->Execute($query);
> + if(!$result || ($result->RecordCount() == 0)){
> + return false;
> + }
> +
> + // get the information from the article
> + $row = $result->FetchRow();
> + print $row["id"];
> +
> +
> + // fetch the article
> + return $this->$_articles->getBlogArticle($row["id"], $blogId);
> + }
> +
> + function getFirstArticle($categoryId, $blogId){
> + // gets the first article in the category
> + $query = "SELECT id FROM " . $this->_prefix .
> + "articles, " . $this->_prefix."article_categories_link" .
> + " WHERE status=1 AND blog_id = " . $blogId .
> + " AND category_id = " . $categoryId .
> + " and article_id = id" .
> + " ORDER BY date LIMIT 1;";
> +
> + $result = $this->db->Execute($query);
> + if(!$result || ($result->RecordCount() == 0))
> + return false;
> +
> + // get the information from the article
> + $row = $result->FetchRow();
> +
> + // fetch the article
> + return $this->$_articles->getBlogArticle($row["id"], $blogId);
> + }
> +
> + function getLastArticle($categoryId, $blogId){
> + // gets the last article in the category
> + $query = "SELECT id FROM " . $this->_prefix .
> + "articles, " . $this->_prefix."article_categories_link" .
> + " WHERE status=1 AND blog_id = " . $blogId .
> + " AND category_id = " . $categoryId .
> + " and article_id = id" .
> + " ORDER BY date DESC LIMIT 1;";
> +
> + $result = $this->db->Execute($query);
> + if(!$result || ($result->RecordCount() == 0))
> + return false;
> +
> + // get the information from the article
> + $row = $result->FetchRow();
> +
> + // fetch the article
> + return $this->$_articles->getBlogArticle($row["id"], $blogId);
> + }
> +}
> +
> +
> +?>
>
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.plogworld.net
> http://devel.plogworld.net/mailman/listinfo/plog-svn
>
**************************************************************
* Jonathan M. Daley * Become a fixer, not just a *
* jondaley at snurgle.org * fixture. *
* www.snurgle.org/~jondaley * -- Anthony D'Angelo *
**************************************************************
More information about the pLog-svn
mailing list