Source for file class.acContentBlockBase.php

Documentation is available at class.acContentBlockBase.php

  1. <?php
  2. /**
  3.  * Class definition and methods for AdvancedContent contentblock types.<br />
  4.  * All block types needs to inherit and extend this class!
  5.  *
  6.  * @package AdvancedContent
  7.  * @category CMSModuleContentType
  8.  * @license GPL
  9.  * @author Georg Busch (NaN)
  10.  * @copyright 2010-2012 Georg Busch (NaN)
  11.  * @since 0.9
  12.  * @abstract
  13.  * @access public
  14.  */
  15. abstract class acContentBlockBase
  16. {
  17.     /**
  18.      * @ignore
  19.      */
  20.     private $_properties = array('active' => true); // we shouldn't be here if the block is not active
  21.     
  22.     /**
  23.      * @ignore
  24.      */
  25.     private $_content = NULL;
  26.     
  27.     /**
  28.      * @ignore
  29.      */
  30.     protected $content_obj;
  31.     
  32.     /**
  33.      * @ignore
  34.      */
  35.     protected $_header_html_called = false;
  36.     
  37.     /**
  38.      * Constructor.<br />
  39.      * Required for all subclasses.<br />
  40.      * Should be called from each subclass as the very first.
  41.      * @param array $params - the parameters of that contentblock
  42.      */
  43.     function __construct(&$content_obj, $params = array())
  44.     {
  45.         $this->content_obj = $content_obj;
  46.         
  47.         $AC = &ac_utils::get_module('AdvancedContent');
  48.         
  49.         $this->_properties['smarty']           = isset($params['smarty'])        ? $params['smarty']        : false;
  50.         $this->_properties['editor_groups']    = isset($params['editor_groups']) ? $params['editor_groups'] : '';
  51.         $this->_properties['editor_users']     = isset($params['editor_users'])  ? $params['editor_users']  : '';
  52.         $this->_properties['type']             = isset($params['block_type'])    ? $params['block_type']    : '';
  53.         $this->_properties['name']             = isset($params['block'])         ? $params['block']         : 'content_en';
  54.         $this->_properties['id']               = isset($params['block_id'])      ? $params['block_id']      : preg_replace('/-+/','_', munge_string_to_url($this->_properties['name']));
  55.         $this->_properties['label']            = isset($params['label'])         ? $params['label']         : ucwords($this->_properties['name']);
  56.         $this->_properties['default']          = isset($params['default'])       ? $params['default']       : '';
  57.         $this->_properties['style']            = isset($params['style'])         ? $params['style']         : ''; # deprecated
  58.         $this->_properties['page_tab']         = isset($params['page_tab'])      ? $params['page_tab']      : 'main';
  59.         $this->_properties['block_tab']        = isset($params['block_tab'])     ? $params['block_tab']     : '';
  60.         $this->_properties['block_group']      = isset($params['block_group'])   ? $params['block_group']   : '';
  61.         $this->_properties['description']      = isset($params['description'])   ? $params['description']   : '';
  62.         
  63.         $this->_properties['translate_labels'] = (isset($params['translate_labels']) && ac_utils::IsTrue($params['translate_labels']));
  64.         $this->_properties['translate_values'] = (isset($params['translate_values']) && ac_utils::IsTrue($params['translate_values']));
  65.         $this->_properties['required']         = (isset($params['required'])         && ac_utils::IsTrue($params['required']));
  66.         $this->_properties['allow_none']       = !(isset($params['allow_none'])      && ac_utils::IsFalse($params['allow_none']));
  67.         $this->_properties['no_collapse']      = (isset($params['no_collapse'])      && ac_utils::IsTrue($params['no_collapse']));
  68.         $this->_properties['collapsible']      = !$this->_properties['no_collapse']  && $this->_properties['type'];
  69.         
  70.         if(!$this->_properties['collapsible'])
  71.             $this->_properties['collapse'] = false;
  72.         else
  73.             $this->_properties['collapse'] = isset($params['collapse']) ? !ac_utils::IsFalse($params['collapse']) : $AC->GetPreference('collapse_block_default', true);
  74.         
  75.         $this->_properties['feu_access'] = isset($params['feu_access']) ? $params['feu_access'] : ''; 
  76.         $this->_properties['feu_action'] = (isset($params['feu_action']) && ac_utils::IsTrue($params['feu_action']));
  77.         $this->_properties['feu_hide']   = (isset($params['feu_hide']) && ac_utils::IsTrue($params['feu_hide']));
  78.     }
  79.     
  80.     /**
  81.      * Backwards compatibility
  82.      * @ignore
  83.      * @internal
  84.      */
  85.     public function __call($name, $arguments = array()) 
  86.     {
  87.         $_name = str_replace('Block', '', $name);
  88.         $config = cmsms()->GetConfig();
  89.         if($config['debug'])
  90.             trigger_error('AdvancedContent blocktype method "' . $name . '()" is deprecated! Use "' . $_name . '()" instead.', E_USER_WARNING);
  91.         if(method_exists($this, $_name))
  92.             return $this->$_name(isset($arguments[0]) ? $arguments[0] : NULL, isset($arguments[1]) ? $arguments[1] : NULL, isset($arguments[2]) ? $arguments[2] : NULL);
  93.         return false;
  94.     }
  95.     
  96.     
  97.     /**
  98.      * @ignore
  99.      * @internal
  100.      */
  101.     public final function Type()
  102.     {
  103.         $class = get_class($this);
  104.         if(strpos($class, "acBlockType_") === false)
  105.             return AC_INVALID_BLOCK_TYPE;
  106.         return substr($class, strlen("acBlockType_"));
  107.     }
  108.     
  109.     /**
  110.      * Sets the value of a property. If not exists it will be created.
  111.      * @param string $name - the name of the property
  112.      * @param string $value - the value of the property
  113.      */
  114.     public final function SetProperty($name, $value = '')
  115.     {
  116.         $this->_properties[strtolower($name)] = $value;
  117.     }
  118.     
  119.     /**
  120.      * Returns the value of a property.
  121.      * @param string $name - the name of the property
  122.      * @param string $default - the default value of the property if not exists
  123.      * @return mixed - usually this will be a string
  124.      */
  125.     public final function GetProperty($name, $default = '')
  126.     {
  127.         $name = strtolower($name);
  128.         if(isset($this->_properties[$name]))
  129.             return $this->_properties[$name];
  130.         
  131.         return $default;
  132.     }
  133.     
  134.     /**
  135.      * Returns all valid properties of that block.
  136.      * @return array - array(propname => propvalue)
  137.      */
  138.     public final function GetProperties()
  139.     {
  140.         return $this->_properties;
  141.     }
  142.     
  143.     /**
  144.      * Defines additional properties of the blocktype that affects all blocks of this type
  145.      * and needs to be stored "outside" the block.
  146.      * @return array - array(propname => propvalue)
  147.      * @abstract
  148.      */
  149.     public function SetBlockTypeProperties() {}
  150.     
  151.     /**
  152.      * Gets the html output of the block in backend.<br />
  153.      * This method is required and needs to be overwritten.
  154.      * @return string 
  155.      */
  156.     public function GetInput() {}
  157.     
  158.     /**
  159.      * Gets the html that needs to be inserted in the head section for all blocks of this type when editing a page.<br />
  160.      * Can be useful to add css or js.<br/>
  161.      * Will be called only once for each block type.
  162.      * @return string 
  163.      */
  164.     public function GetHeaderHTML()
  165.     {
  166.         $this->_header_html_called = true;
  167.     }
  168.     
  169.     /**
  170.      * Displays the help text for this blocktype.<br />
  171.      * Helptext will be displayed in modulehelp.
  172.      * @return string 
  173.      */
  174.     public function GetHelp()
  175.     {
  176.         return;
  177.     }
  178.     
  179.     /**
  180.      * Displays the changelog text for this blocktype.<br />
  181.      * Changelog will be displayed in modules changelog.
  182.      * @return string 
  183.      */
  184.     public function GetChangeLog()
  185.     {
  186.         return;
  187.     }
  188.     
  189.     /**
  190.      * Function for the subclass to parse out data for it's parameters.<br />
  191.      * Needs to be overwritten if the blocktype provides a special kind of data that needs to be processed before storing it.
  192.      * @param array &$params - the parameters that are passed when the form is submitted
  193.      * @param bool $editing - a flag to determine if the page is created or edited
  194.      * @return string 
  195.      */
  196.     public function FillParams(&$params, $editing = false)
  197.     {
  198.         return isset($params[$this->_properties['id']]) ? $params[$this->_properties['id']] : '';
  199.     }
  200.     
  201.     /**
  202.      * Function for the subclass to perform the blocks output<br />
  203.      * Needs to be overwritten if the blocktype provides a special kind of data that needs to be processed before displaying it in frontend.
  204.      * @return string 
  205.      */
  206.     public function Show()
  207.     {
  208.         return $this->GetContent();
  209.     }
  210.     
  211.     /**
  212.      * Function for the subclass to validate its data
  213.      * @return bool 
  214.      */
  215.     public function Validate()
  216.     {
  217.         return $this->GetContent();
  218.     }
  219.     
  220.     /**
  221.      * Function to get the blocks raw content<br />
  222.      * @return string 
  223.      * @since 0.9.4
  224.      */
  225.     public final function GetContent()
  226.     {
  227.         return $this->_content !== NULL ? $this->_content : $this->content_obj->GetPropertyValue($this->_properties['id']);
  228.     }
  229.     
  230.     /**
  231.      * Function to set the content of a block temporary on runtime to a certain value<br />
  232.      * @return string 
  233.      * @since 0.9.4
  234.      */
  235.     protected final function SetContent($value)
  236.     {
  237.         $this->_content = $value;
  238.     }
  239. }
  240. ?>

Documentation generated on Tue, 09 Oct 2012 16:57:05 +0200 by phpDocumentor 1.4.1