[pLog-svn] r3314 - plog/trunk/class/dao
Jon Daley
plogworld at jon.limedaley.com
Mon May 1 22:57:06 GMT 2006
Whoops - didn't specify the filename on the commit. I guess I
will add the unique post name config option tonight...
On Mon, 1 May 2006, jondaley at devel.lifetype.net wrote:
> Author: jondaley
> Date: 2006-05-01 22:22:51 +0000 (Mon, 01 May 2006)
> New Revision: 3314
>
> Modified:
> plog/trunk/class/dao/articlecategories.class.php
> plog/trunk/class/dao/articles.class.php
> Log:
> removed debug info
>
> Modified: plog/trunk/class/dao/articlecategories.class.php
> ===================================================================
> --- plog/trunk/class/dao/articlecategories.class.php 2006-05-01 21:36:06 UTC (rev 3313)
> +++ plog/trunk/class/dao/articlecategories.class.php 2006-05-01 22:22:51 UTC (rev 3314)
> @@ -158,7 +158,7 @@
> break;
> }
>
> - print_r($sorting);
> +// print_r($sorting);
>
> $categories = $this->getMany( "blog_id",
> $blogId,
>
> Modified: plog/trunk/class/dao/articles.class.php
> ===================================================================
> --- plog/trunk/class/dao/articles.class.php 2006-05-01 21:36:06 UTC (rev 3313)
> +++ plog/trunk/class/dao/articles.class.php 2006-05-01 22:22:51 UTC (rev 3314)
> @@ -70,11 +70,31 @@
> }
>
> /**
> + * Check to see if an article title already exists. Used
> + * when article urls don't have dates in them, so post names
> + * must be unique across the entire blog.
> + *
> + * @param artTitle Identifier of the article we want to fetch
> + * @param blogId If set, the article must belong to the given blog
> + * @return Returns an Article object or 'false' otherwise.
> + */
> + function checkBlogArticleTitle( $artTitle, $blogId = -1, $artId = -1 )
> + {
> + $prefix = $this->getPrefix();
> + $query = "SELECT a.id FROM {$prefix}articles a ";
> +
> + $query .= "WHERE a.slug = '".Db::qstr($artTitle)."'";
> + if( $blogId != -1 )
> + $query .= " AND a.blog_id = ".Db::qstr($blogId);
> + if( $artId != -1 )
> + $query .= " AND a.id != $artId;";
> +
> + return $this->_getBlogArticleFromQuery( $query, false, true );
> + }
> +
> + /**
> * Gets an article from the database, given its slug, this is used
> * with the fancy permalinks
> - * This method will always return the first matching article, so
> - * if there're more than one article with the same title, you will
> - * always get only one of them.
> *
> * @param artTitle Identifier of the article we want to fetch
> * @param blogId If set, the article must belong to the given blog
> @@ -112,11 +132,11 @@
>
> return( $article );
> }
> -
> +
> /**
> * @private
> */
> - function _getBlogArticleFromQuery( $query, $includeHiddenFields )
> + function _getBlogArticleFromQuery( $query, $includeHiddenFields, $onlyCheck=false )
> {
> // we send the query and then fetch the first array with the result
> $result = $this->Execute( $query );
> @@ -127,8 +147,12 @@
> if ( $result->RecordCount() == 0)
> return false;
>
> + if($onlyCheck){
> + $result->Close();
> + return true;
> + }
> +
> $row = $result->FetchRow( $result );
> -
> $article = $this->mapRow( $row, $includeHiddenFields );
>
> return $article;
> @@ -755,6 +779,20 @@
> */
> function addArticle( &$newArticle )
> {
> +
> + $slug = $newArticle->getPostSlug();
> + $i = 1;
> + // check if there already is a blog with the same mangled name
> + while($this->checkBlogArticleTitle($slug, $newArticle->getBlog())){
> + $i++;
> + // and if so, assign a new one
> + // if we already tried with blogname+"i" we have
> + // to strip "i" before adding it again!
> + $slug = substr($slug, 0,
> + ($i > 2) ? strlen($slug)-strlen($i-1) : strlen($slug)).$i;
> + }
> + $newArticle->setPostSlug($slug);
> +
> include_once( PLOG_CLASS_PATH.'class/dao/customfields/customfields.class.php' );
> include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
>
> @@ -890,6 +928,20 @@
> */
> function updateArticle( $article )
> {
> + $slug = $article->getPostSlug();
> + $i = 1;
> + // check if there already is a blog with the same mangled name
> + while($this->checkBlogArticleTitle($slug, $article->getBlog(),
> + $article->getId())){
> + $i++;
> + // and if so, assign a new one
> + // if we already tried with slug+"i" we have
> + // to strip "i" before adding it again!
> + $slug = substr($slug, 0,
> + ($i > 2) ? strlen($slug)-strlen($i-1) : strlen($slug)).$i;
> + }
> + $article->setPostSlug($slug);
> +
> // keep the old version, since we're going to need it to udpate the category counters
> $oldArticle = $this->getArticle( $article->getId());
>
>
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.lifetype.net
> http://devel.lifetype.net/mailman/listinfo/plog-svn
>
**************************************
Jon Daley
http://jon.limedaley.com/
01 potato, 10 potato, 11 potato, xor!
-- Gary Young
More information about the pLog-svn
mailing list