Source for file content.class.php

Documentation is available at content.class.php

  1. <?php
  2. /**
  3. @package Mambo
  4. @author Mambo Foundation Inc see README.php
  5. @copyright Mambo Foundation Inc.
  6. *  See COPYRIGHT.php for copyright notices and details.
  7. @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see
  8. *  LICENSE.php
  9. *  Mambo is free software; you can redistribute it and/or
  10. *  modify it under the terms of the GNU General Public License
  11. *  as published by the Free Software Foundation; version 2 of the
  12. *  License.
  13. */
  14.  
  15. /**
  16. * Category database table class
  17. */
  18. class mosCategory extends mosDBTable {
  19.     /** @var int Primary key */
  20.     var $id=null;
  21.     /** @var string The menu title for the Category (a short name)*/
  22.     var $title=null;
  23.     /** @var string The full name for the Category*/
  24.     var $name=null;
  25.     /** @var string */
  26.     var $image=null;
  27.     /** @var string */
  28.     var $section=null;
  29.     /** @var int */
  30.     var $image_position=null;
  31.     /** @var string */
  32.     var $description=null;
  33.     /** @var boolean */
  34.     var $published=null;
  35.     /** @var boolean */
  36.     var $checked_out=null;
  37.     /** @var time */
  38.     var $checked_out_time=null;
  39.     /** @var int */
  40.     var $ordering=null;
  41.     /** @var int */
  42.     var $access=null;
  43.     /** @var string */
  44.     var $params=null;
  45.  
  46.     /**
  47.     * @param database A database connector object
  48.     */
  49.     function mosCategory&$db {
  50.         $this->mosDBTable'#__categories''id'$db );
  51.     }
  52.     // overloaded check function
  53.     function check({
  54.         // check for valid name
  55.         if (trim$this->title == ''{
  56.             $this->_error = "Your Category must contain a title.";
  57.             return false;
  58.         }
  59.         if (trim$this->name == ''{
  60.             $this->_error = "Your Category must have a name.";
  61.             return false;
  62.         }
  63.         // check for existing name
  64.         $this->_db->setQuery"SELECT id FROM #__categories "
  65.         . "\nWHERE name='".$this->name."' AND section='".$this->section."'"
  66.         );
  67.  
  68.         $xid intval$this->_db->loadResult() );
  69.         if ($xid && $xid != intval$this->id )) {
  70.             $this->_error = "There is a category already with that name, please try again.";
  71.             return false;
  72.         }
  73.         return true;
  74.     }
  75. }
  76.  
  77. /**
  78. * Section database table class
  79. @package Mambo
  80. */
  81. class mosSection extends mosDBTable {
  82.     /** @var int Primary key */
  83.     var $id=null;
  84.     /** @var string The menu title for the Section (a short name)*/
  85.     var $title=null;
  86.     /** @var string The full name for the Section*/
  87.     var $name=null;
  88.     /** @var string */
  89.     var $image=null;
  90.     /** @var string */
  91.     var $scope=null;
  92.     /** @var int */
  93.     var $image_position=null;
  94.     /** @var string */
  95.     var $description=null;
  96.     /** @var boolean */
  97.     var $published=null;
  98.     /** @var boolean */
  99.     var $checked_out=null;
  100.     /** @var time */
  101.     var $checked_out_time=null;
  102.     /** @var int */
  103.     var $ordering=null;
  104.     /** @var int */
  105.     var $access=null;
  106.     /** @var string */
  107.     var $params='';
  108.  
  109.     /**
  110.     * @param database A database connector object
  111.     */
  112.     function mosSection&$db {
  113.         $this->mosDBTable'#__sections''id'$db );
  114.     }
  115.     // overloaded check function
  116.     function check({
  117.         // check for valid name
  118.         if (trim$this->title == ''{
  119.             $this->_error = "Your Section must contain a title.";
  120.             return false;
  121.         }
  122.         if (trim$this->name == ''{
  123.             $this->_error = "Your Section must have a name.";
  124.             return false;
  125.         }
  126.         // check for existing name
  127.         $this->_db->setQuery"SELECT id FROM #__sections "
  128.         . "\nWHERE name='$this->name' AND scope='$this->scope'"
  129.         );
  130.  
  131.         $xid intval$this->_db->loadResult() );
  132.         if ($xid && $xid != intval$this->id )) {
  133.             $this->_error = "There is a section already with that name, please try again.";
  134.             return false;
  135.         }
  136.         return true;
  137.     }
  138. }
  139.  
  140. /**
  141. * Module database table class
  142. @package Mambo
  143. */
  144. class mosContent extends mosDBTable {
  145.     /** @var int Primary key */
  146.     var $id=null;
  147.     /** @var string */
  148.     var $title=null;
  149.     /** @var string */
  150.     var $title_alias=null;
  151.     /** @var string */
  152.     var $introtext=null;
  153.     /** @var string */
  154.     var $fulltext=null;
  155.     /** @var int */
  156.     var $state=null;
  157.     /** @var int The id of the category section*/
  158.     var $sectionid=null;
  159.     /** @var int DEPRECATED */
  160.     var $mask=null;
  161.     /** @var int */
  162.     var $catid=null;
  163.     /** @var datetime */
  164.     var $created=null;
  165.     /** @var int User id*/
  166.     var $created_by=null;
  167.     /** @var string An alias for the author*/
  168.     var $created_by_alias=null;
  169.     /** @var datetime */
  170.     var $modified=null;
  171.     /** @var int User id*/
  172.     var $modified_by=null;
  173.     /** @var boolean */
  174.     var $checked_out=null;
  175.     /** @var time */
  176.     var $checked_out_time=null;
  177.     /** @var datetime */
  178.     var $frontpage_up=null;
  179.     /** @var datetime */
  180.     var $frontpage_down=null;
  181.     /** @var datetime */
  182.     var $publish_up=null;
  183.     /** @var datetime */
  184.     var $publish_down=null;
  185.     /** @var string */
  186.     var $images=null;
  187.     /** @var string */
  188.     var $urls=null;
  189.     /** @var string */
  190.     var $attribs=null;
  191.     /** @var int */
  192.     var $version=null;
  193.     /** @var int */
  194.     var $parentid=null;
  195.     /** @var int */
  196.     var $ordering=null;
  197.     /** @var string */
  198.     var $metakey=null;
  199.     /** @var string */
  200.     var $metadesc=null;
  201.     /** @var int */
  202.     var $access=null;
  203.     /** @var int */
  204.     var $hits=null;
  205.  
  206.     /**
  207.     * @param database A database connector object
  208.     */
  209.     function mosContent({
  210.         $db =mamboDatabase::getInstance();
  211.         $this->mosDBTable'#__content''id'$db );
  212.     }
  213.  
  214.     /**
  215.      * Validation and filtering
  216.      */
  217.     function check({
  218.         // filter malicious code
  219.         $ignoreList array'introtext''fulltext' );
  220.         $this->filter$ignoreList );
  221.  
  222.         /*
  223.         TODO: This filter is too rigorous,
  224.         need to implement more configurable solution
  225.         // specific filters
  226.         $iFilter = new InputFilter( null, null, 1, 1 );
  227.         $this->introtext = trim( $iFilter->process( $this->introtext ) );
  228.         $this->fulltext =  trim( $iFilter->process( $this->fulltext ) );
  229.         */
  230.  
  231.         if (trimstr_replace'&nbsp;'''$this->fulltext ) ) == ''{
  232.             $this->fulltext = '';
  233.         }
  234.  
  235.         return true;
  236.     }
  237.  
  238.     /**
  239.     * Converts record to XML
  240.     * @param boolean Map foreign keys to text values
  241.     */
  242.     function toXML$mapKeysToText=false {
  243.         global $database;
  244.  
  245.         if ($mapKeysToText{
  246.             $query 'SELECT name FROM #__sections WHERE id=' $this->sectionid;
  247.             $database->setQuery$query );
  248.             $this->sectionid = $database->loadResult();
  249.  
  250.             $query 'SELECT name FROM #__categories WHERE id=' $this->catid;
  251.             $database->setQuery$query );
  252.             $this->catid = $database->loadResult();
  253.  
  254.             $query 'SELECT name FROM #__users WHERE id=' $this->created_by;
  255.             $database->setQuery$query );
  256.             $this->created_by = $database->loadResult();
  257.         }
  258.  
  259.         return parent::toXML$mapKeysToText );
  260.     }
  261. }
  262.  
  263. class mosExtendedContent extends mosContent {
  264.     /** @var numeric */
  265.     var $rating = null;
  266.     /** @var int */
  267.     var $rating_count = null;
  268.     /** @var string */
  269.     var $author = null;
  270.     /** @var string */
  271.     var $usertype = null;
  272.     /** @var string */
  273.     var $section = null;
  274.     /** @var string */
  275.     var $category = null;
  276.     /** @var string */
  277.     var $groups = null;
  278.     /** @var string */
  279.     var $text = null;
  280.  
  281.     function getText ({
  282.         return $this->text;
  283.     }
  284.  
  285.     function saveText ($text{
  286.         $this->text = $text;
  287.     }
  288.  
  289.     function getImages ({
  290.         return $this->images;
  291.     }
  292.  
  293.     function saveImages ($images{
  294.         $this->images = $images;
  295.     }
  296.  
  297.     function getId ({
  298.         return $this->id;
  299.     }
  300.  
  301.     function getRating ({
  302.         return $this->rating;
  303.     }
  304.  
  305.     function getRatingCount ({
  306.         return $this->rating_count;
  307.     }
  308.  
  309. }
  310.  
  311. class contentHandler {
  312.     var $_category_limit = 250;
  313.     var $_category_status = 0;
  314.     var $_category;
  315.     var $_section_limit = 250;
  316.     var $_section_status = 0;
  317.     var $_sections;
  318.  
  319.     function &getInstance ({
  320.         static $instance;
  321.         if (!is_object($instance)) $instance new contentHandler();
  322.         return $instance;
  323.     }
  324.     /**
  325.     * @return number of Published Blog Sections
  326.     */
  327.     function getBlogSectionCount{
  328.         $menuhandler =mosMenuHandler::getInstance();
  329.         if (count($menuhandler->getMenusByType('content_blog_section'))) {
  330.             $query "SELECT COUNT( m.id )"
  331.             ."\n FROM #__content AS i"
  332.             ."\n LEFT JOIN #__sections AS s ON i.sectionid=s.id"
  333.             ."\n LEFT JOIN #__menu AS m ON m.componentid=s.id "
  334.             ."\n WHERE m.type='content_blog_section'"
  335.             ."\n AND m.published='1'"
  336.             ;
  337.             $database =mamboDatabase::getInstance();
  338.             $database->setQuery$query );
  339.             $count $database->loadResult();
  340.         else {
  341.             $count 0;
  342.         }
  343.         return $count;
  344.     }
  345.  
  346.     /**
  347.     * @return number of Published Blog Categories
  348.     */
  349.     function getBlogCategoryCount{
  350.         $menuhandler =mosMenuHandler::getInstance();
  351.         if (count($menuhandler->getMenusByType('content_blog_category'))) {
  352.             $query "SELECT COUNT( m.id )"
  353.             . "\n FROM #__content AS i"
  354.             . "\n LEFT JOIN #__categories AS c ON i.catid=c.id"
  355.             . "\n LEFT JOIN #__menu AS m ON m.componentid=c.id "
  356.             . "\n WHERE m.type='content_blog_category'"
  357.             . "\n  AND m.published='1'"
  358.             ;
  359.             $database =mamboDatabase::getInstance();
  360.             $database->setQuery$query );
  361.             $count $database->loadResult();
  362.         }
  363.         else $count 0;
  364.         return $count;
  365.     }
  366.  
  367.     /**
  368.     * @return number of Published Global Blog Sections
  369.     */
  370.     function getGlobalBlogSectionCount{
  371.         $menuhandler =mosMenuHandler::getInstance();
  372.         return $menuhandler->getGlobalBlogSectionCount();
  373.     }
  374.  
  375.     /**
  376.     * @return number of Static Content
  377.     */
  378.     function getStaticContentCount{
  379.         $menuhandler =mosMenuHandler::getInstance();
  380.         return $menuhandler->getMenuCount ('content_typed'1);
  381.     }
  382.  
  383.     /**
  384.     * @return number of Content Item Links
  385.     */
  386.     function getContentItemLinkCount{
  387.         $menuhandler =mosMenuHandler::getInstance();
  388.         return $menuhandler->getMenuCount ('content_item_link'1);
  389.     }
  390.  
  391.     function getItemid ($id$typed=1$link=1$bs=1$bc=1$gbs=1{
  392.         $_Itemid null;
  393.         $menuhandler =mosMenuHandler::getInstance();
  394.         if ($typed{
  395.             // Search for typed link
  396.             $_Itemid $menuhandler->getIDByTypeLink('content_typed'"index.php?option=com_content&task=view&id=$id");
  397.         }
  398.  
  399.         if ($_Itemid == null AND $link{
  400.             // Search for item link
  401.             $_Itemid $menuhandler->getIDByTypeLink('content_item_link'"index.php?option=com_content&task=view&id=$id");
  402.         }
  403.         $sectionid $this->getSection($id);
  404.         if ($_Itemid == null{
  405.             // Search in sections
  406.             $_Itemid $menuhandler->getIDByTypeCid ('content_section'$sectionid);
  407.         }
  408.         if ($_Itemid == null{
  409.             // Search in sections
  410.             $_Itemid $menuhandler->getIDByTypeCid ('content_blog_section'$sectionid);
  411.         }
  412.         if ($_Itemid == null{
  413.             // Search in sections
  414.             $_Itemid $menuhandler->getIDByTypeCid ('content_blog_category'$sectionid);
  415.         }
  416.         if ($_Itemid == null AND $gbs{
  417.             // Search in global blog section
  418.             $_Itemid $menuhandler->getIDByTypeCid('content_blog_section'0);
  419.         }
  420.         /*
  421.         if ($_Itemid == '') {
  422.             // Search in global blog category
  423.             $this->_db->setQuery( "SELECT id "
  424.             ."\nFROM #__menu "
  425.             ."\nWHERE type='content_blog_category' AND published='1' AND componentid=0" );
  426.             $_Itemid = $this->_db->loadResult();
  427.         }
  428.         */
  429.         $catid $this->getCategory($id);
  430.         if ($_Itemid == null{
  431.             // Search in blog categories
  432.             $_Itemid $menuhandler->getIDByTypeCid ('content_blog_category'$catid);
  433.         }
  434.         if ($_Itemid == null{
  435.             // Search in categories
  436.             $_Itemid $menuhandler->getIDByTypeCid ('content_category'$catid);
  437.         }
  438.         if ($_Itemid == null{
  439.             // Search in main menu
  440.             $menus $menuhandler->getByParentOrder(0,'منوی اصلی');
  441.             $home $menus[0];
  442.             $_Itemid $home->id;
  443.         }
  444.         if ($_Itemidreturn $_Itemid;
  445.         else return mamboCore::get('Itemid');
  446.     }
  447.  
  448.     function getSection ($id{
  449.         $database =mamboDatabase::getInstance();
  450.         $limit $this->_section_limit;
  451.         if (!$this->_section_status{
  452.             $database->setQuery("SELECT i.id, i.sectionid FROM #__content AS i, #__sections AS s WHERE i.sectionid=s.id ORDER BY i.id DESC LIMIT $limit");
  453.             $sections $database->loadObjectList();
  454.             if ($sections{
  455.                 foreach ($sections as $section$this->_sections[$section->id$section->sectionid;
  456.                 $this->_section_status = count($sections);
  457.             }
  458.         }
  459.         if ($this->_section_status{
  460.             if (isset($this->_sections[$id])) return $this->_sections[$id];
  461.             if (count($this->_sections$limitreturn 0;
  462.             $database->setQuery("SELECT i.sectionid FROM #__content AS i, #__sections AS s WHERE i.sectionid=s.id AND i.id=$id");
  463.             return $database->loadResult();
  464.         }
  465.         else return 0;
  466.     }
  467.  
  468.     function getCategory ($id{
  469.         $database =mamboDatabase::getInstance();
  470.         $limit $this->_category_limit;
  471.         if (!$this->_category_status{
  472.             $database->setQuery("SELECT i.id, i.catid FROM #__content AS i, #__categories AS s WHERE i.catid=s.id ORDER BY i.id DESC LIMIT $limit");
  473.             $categories $database->loadObjectList();
  474.             if ($categories{
  475.                 foreach ($categories as $category$this->_categories[$category->id$category->catid;
  476.                 $this->_category_status = count($categories);
  477.             }
  478.         }
  479.         if ($this->_category_status{
  480.             if (isset($this->_categories[$id])) return $this->_categories[$id];
  481.             if (count($this->_categories$limitreturn 0;
  482.             $database->setQuery("SELECT i.catid FROM #__content AS i, #__categories AS s WHERE i.catid=s.id AND i.id=$id");
  483.             return $database->loadResult();
  484.         }
  485.         else return 0;
  486.     }
  487.  
  488. }
  489.  
  490. ?>

Documentation generated on Mon, 05 May 2008 16:18:19 +0400 by phpDocumentor 1.4.0