b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (CVS HEAD) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Source for file _chapter.class.php

Documentation is available at _chapter.class.php

  1. <?php
  2. /**
  3.  * This file implements the Chapter class.
  4.  *
  5.  * This file is part of the evoCore framework - {@link http://evocore.net/}
  6.  * See also {@link http://sourceforge.net/projects/evocms/}.
  7.  *
  8.  * @copyright (c)2003-2010 by Francois PLANQUE - {@link http://fplanque.net/}
  9.  *  Parts of this file are copyright (c)2005-2006 by PROGIDISTRI - {@link http://progidistri.com/}.
  10.  *
  11.  *  {@internal License choice
  12.  *  - If you have received this file as part of a package, please find the license.txt file in
  13.  *    the same folder or the closest folder above for complete license terms.
  14.  *  - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  15.  *    then you must choose one of the following licenses before using the file:
  16.  *    - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  17.  *    - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  18.  *  }}}
  19.  *
  20.  * @package evocore
  21.  *
  22.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  23.  * @author fplanque: Francois PLANQUE.
  24.  *
  25.  * @version $Id: _chapter.class.php,v 1.16 2010/02/08 17:52:07 efy-yury Exp $
  26.  */
  27. if!defined('EVO_MAIN_INIT') ) die'Please, do not access this page directly.' );
  28.  
  29. load_class'generic/model/_genericcategory.class.php''GenericCategory' );
  30.  
  31.  
  32. /**
  33.  * Chapter Class
  34.  *
  35.  * @package evocore
  36.  */
  37. class Chapter extends GenericCategory
  38. {
  39.     /**
  40.      * @var integer 
  41.      */
  42.     var $blog_ID;
  43.     /**
  44.      * The Blog of the Item (lazy filled, use {@link get_Blog()} to access it.
  45.      * @access protected
  46.      * @var Blog 
  47.      */
  48.     var $Blog;
  49.  
  50.     var $urlname;
  51.     var $description;
  52.     var $order;
  53.  
  54.     /**
  55.      * Lazy filled
  56.      * @var Chapter 
  57.      */
  58.     var $parent_Chapter;
  59.  
  60.     /**
  61.      * Constructor
  62.      *
  63.      * @param table Database row
  64.       * @param integer|NULLsubset to use for new object
  65.      */
  66.     function Chapter$db_row NULL$subset_ID NULL )
  67.     {
  68.         // Call parent constructor:
  69.         parent::GenericCategory'T_categories''cat_''cat_ID'$db_row );
  70.  
  71.         ifis_null($db_row) )
  72.         {    // We are creating an object here:
  73.             $this->set'blog_ID'$subset_ID );
  74.         }
  75.         else
  76.         {    // Wa are loading an object:
  77.             $this->blog_ID = $db_row->cat_blog_ID;
  78.             $this->urlname = $db_row->cat_urlname;
  79.             $this->description = $db_row->cat_description;
  80.             $this->order = $db_row->cat_order;
  81.         }
  82.     }
  83.  
  84.  
  85.     /**
  86.      * Load data from Request form fields.
  87.      *
  88.      * @return boolean true if loaded data seems valid.
  89.      */
  90.     function load_from_request()
  91.     {
  92.         global $DB$Settings;
  93.  
  94.         parent::load_from_Request();
  95.  
  96.         // Check url name
  97.         param'cat_urlname''string' );
  98.         $this->set_from_Request'urlname' );
  99.  
  100.         // Check description
  101.         param'cat_description''string' );
  102.         $this->set_from_Request'description' );
  103.  
  104.         if$Settings->get('chapter_ordering'== 'manual' )
  105.         {    // Manual ordering
  106.             param'cat_order''integer' );
  107.             $this->set_from_Request'order' );
  108.         }
  109.  
  110.         return param_errors_detected();
  111.     }
  112.  
  113.  
  114.     /**
  115.      *
  116.      */
  117.     function get_parent_Chapter()
  118.     {
  119.         ifisset$this->parent_Chapter ) )
  120.         {    // Not resoleved yet!
  121.             ifempty$this->parent_ID ) )
  122.             {
  123.                 $this->parent_Chapter = NULL;
  124.             }
  125.             else
  126.             {
  127.                 $ChapterCache get_ChapterCache();
  128.                 $this->parent_Chapter = $ChapterCache->get_by_ID$this->parent_ID );
  129.             }
  130.         }
  131.  
  132.         return $this->parent_Chapter;
  133.     }
  134.  
  135.  
  136.     /**
  137.      * Get URL path (made of URL names) back to the root
  138.      */
  139.     function get_url_path()
  140.     {
  141.         $r $this->urlname.'/';
  142.  
  143.         $parent_Chapter $this->get_parent_Chapter();
  144.         if!is_null$parent_Chapter ) )
  145.         {    // Recurse:
  146.             $r $parent_Chapter->get_url_path().$r;
  147.         }
  148.  
  149.         return $r;
  150.     }
  151.  
  152.  
  153.     /**
  154.      * Generate the URL to access the category.
  155.      *
  156.      * @param string|NULL'param_num', 'subchap', 'chapters'
  157.      * @param string|NULLurl to use
  158.      * @param integer category page to link to, default:1
  159.      * @param integer|NULLnumber of posts per page (used for param_num only)
  160.      * @param string glue between url params
  161.      */
  162.     function get_permanent_url$link_type NULL$blogurl NULL$paged 1$chapter_posts_per_page NULL$glue '&amp;' )
  163.     {
  164.         global $DB$cacheweekly$Settings;
  165.  
  166.         ifempty$link_type ) )
  167.         {    // Use default from settings:
  168.             $this->get_Blog();
  169.             $link_type $this->Blog->get_setting'chapter_links' );
  170.         }
  171.  
  172.         ifempty$blogurl ) )
  173.         {
  174.             $this->get_Blog();
  175.             $blogurl $this->Blog->gen_blogurl();
  176.         }
  177.  
  178.         switch$link_type )
  179.         {
  180.             case 'param_num':
  181.                 $r url_add_param$blogurl'cat='.$this->ID$glue );
  182.                 ifempty($chapter_posts_per_page) )
  183.                 {    // Use default from Blog
  184.                     $this->get_Blog();
  185.                     $chapter_posts_per_page $this->Blog->get_setting'chapter_posts_per_page' );
  186.                 }
  187.                 if!empty($chapter_posts_per_page&& $chapter_posts_per_page != $this->Blog->get_setting'posts_per_page' ) )
  188.                 {    // We want a specific post per page count:
  189.                     $r url_add_param$r'posts='.$chapter_posts_per_page$glue );
  190.                 }
  191.                 break;
  192.  
  193.             case 'subchap':
  194.                 $this->get_Blog();
  195.                 $category_prefix $this->Blog->get_setting('category_prefix');
  196.                 if!empty$category_prefix ) )
  197.                 {
  198.                     $r url_add_tail$blogurl'/'.$category_prefix.'/'.$this->urlname.'/' );
  199.                 }
  200.                 else
  201.                 {
  202.                     $r url_add_tail$blogurl'/'.$this->urlname.'/' );
  203.                 }
  204.                 break;
  205.  
  206.             case 'chapters':
  207.             default:
  208.                 $this->get_Blog();
  209.                 $category_prefix $this->Blog->get_setting('category_prefix');
  210.                 if!empty$category_prefix ) )
  211.                 {
  212.                     $r url_add_tail$blogurl'/'.$category_prefix.'/'.$this->get_url_path() );
  213.                 }
  214.                 else
  215.                 {
  216.                     $r url_add_tail$blogurl'/'.$this->get_url_path() );
  217.                 }
  218.                 break;
  219.         }
  220.  
  221.         if$paged )
  222.         {
  223.             $r url_add_param$r'paged='.$paged$glue );
  224.         }
  225.  
  226.         return $r;
  227.     }
  228.  
  229.  
  230.     /**
  231.      * Get the Blog object for the Chapter.
  232.      *
  233.      * @return Blog 
  234.      */
  235.     function get_Blog()
  236.     {
  237.         ifis_null($this->Blog) )
  238.         {
  239.             $this->load_Blog();
  240.         }
  241.  
  242.         return $this->Blog;
  243.     }
  244.  
  245.  
  246.     /**
  247.      * Load the Blog object for the Chapter, without returning it.
  248.      */
  249.     function load_Blog()
  250.     {
  251.         ifis_null($this->Blog) )
  252.         {
  253.             $BlogCache get_BlogCache();
  254.             $this->Blog = $BlogCache->get_by_ID$this->blog_ID );
  255.         }
  256.     }
  257.  
  258.  
  259.     /**
  260.      * Insert object into DB based on previously recorded changes.
  261.      *
  262.      * @return boolean true on success
  263.      */
  264.     function dbinsert()
  265.     {
  266.         global $DB;
  267.  
  268.         load_funcs'items/model/_item.funcs.php' );
  269.  
  270.         if$this->ID != die'Existing object cannot be inserted!' );
  271.  
  272.         $DB->begin();
  273.  
  274.         // validate url title / slug
  275.         $this->set'urlname'urltitle_validate$this->urlname$this->name$this->IDfalse$this->dbprefix.'urlname'$this->dbIDname$this->dbtablename) );
  276.  
  277.         $r parent::dbinsert();
  278.  
  279.         $DB->commit();
  280.  
  281.         return $r;
  282.     }
  283.  
  284.     /**
  285.      * Update the DB based on previously recorded changes
  286.      *
  287.      * @return boolean true on success
  288.      */
  289.     function dbupdate()
  290.     {
  291.         global $DB;
  292.  
  293.         $DB->begin();
  294.  
  295.         // validate url title / slug
  296.         ifempty($this->urlname|| isset($this->dbchanges['cat_urlname']) )
  297.         // Url title has changed or is empty
  298.             $this->set'urlname'urltitle_validate$this->urlname$this->name$this->IDfalse$this->dbprefix.'urlname'$this->dbIDname$this->dbtablename) );
  299.         }
  300.  
  301.         $r parent::dbupdate();
  302.  
  303.         $DB->commit();
  304.  
  305.         return $r;
  306.     }
  307. }
  308.  
  309.  
  310. /*
  311.  * $Log: _chapter.class.php,v $
  312.  * Revision 1.16  2010/02/08 17:52:07  efy-yury
  313.  * copyright 2009 -> 2010
  314.  *
  315.  * Revision 1.15  2009/10/04 20:36:04  blueyed
  316.  * Add missing load_funcs
  317.  *
  318.  * Revision 1.14  2009/09/26 12:00:42  tblue246
  319.  * Minor/coding style
  320.  *
  321.  * Revision 1.13  2009/09/25 07:32:52  efy-cantor
  322.  * replace get_cache to get_*cache
  323.  *
  324.  * Revision 1.12  2009/09/14 12:26:25  efy-arrin
  325.  * Included the ClassName in load_class() call with proper UpperCase
  326.  *
  327.  * Revision 1.11  2009/03/08 23:57:41  fplanque
  328.  * 2009
  329.  *
  330.  * Revision 1.10  2009/01/28 21:23:22  fplanque
  331.  * Manual ordering of categories
  332.  *
  333.  * Revision 1.9  2008/12/28 23:35:51  fplanque
  334.  * Autogeneration of category/chapter slugs(url names)
  335.  *
  336.  * Revision 1.8  2008/01/21 09:35:26  fplanque
  337.  * (c) 2008
  338.  *
  339.  * Revision 1.7  2008/01/07 02:53:27  fplanque
  340.  * cleaner tag urls
  341.  *
  342.  * Revision 1.6  2007/11/25 14:28:17  fplanque
  343.  * additional SEO settings
  344.  *
  345.  * Revision 1.5  2007/10/06 21:17:25  fplanque
  346.  * cleanup
  347.  *
  348.  * Revision 1.4  2007/10/01 13:41:06  waltercruz
  349.  * Category prefix, trying to make the code more b2evo style
  350.  *
  351.  * Revision 1.3  2007/09/29 01:50:49  fplanque
  352.  * temporary rollback; waiting for new version
  353.  *
  354.  * Revision 1.1  2007/06/25 10:59:25  fplanque
  355.  * MODULES (refactored MVC)
  356.  *
  357.  * Revision 1.10  2007/05/09 00:54:45  fplanque
  358.  * Attempt to normalize all URLs before adding params
  359.  *
  360.  * Revision 1.9  2007/04/26 00:11:06  fplanque
  361.  * (c) 2007
  362.  *
  363.  * Revision 1.8  2007/03/02 00:44:43  fplanque
  364.  * various small fixes
  365.  *
  366.  * Revision 1.7  2007/01/15 00:38:06  fplanque
  367.  * pepped up "new blog" creation a little. To be continued.
  368.  *
  369.  * Revision 1.6  2006/12/11 00:32:26  fplanque
  370.  * allow_moving_chapters stting moved to UI
  371.  * chapters are now called categories in the UI
  372.  *
  373.  * Revision 1.5  2006/11/24 18:27:23  blueyed
  374.  * Fixed link to b2evo CVS browsing interface in file docblocks
  375.  */
  376. ?>

Documentation generated on Sat, 06 Mar 2010 04:03:32 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).