Esempio n. 1
0
 /**
  * Loads a module component. Components are the building blocks of the site and
  * include controllers which build up the pages we see and blocks that build up the controllers.
  *
  * @param string $sClass Name of the component to load.
  * @param array $aParams (Optional) Custom params you can pass to the component.
  * @param string $sType (Optional) Identify if this component is a block or a controller.
  * @param boolean $bTemplateParams Assign $aParams to the template
  * @return mixed Return the component object if it exists, otherwise FALSE.
  */
 public function getComponent($sClass, $aParams = array(), $sType = 'block', $bTemplateParams = false)
 {
     ($sPlugin = Phpfox_Plugin::get('module_getcomponent_start')) ? eval($sPlugin) : false;
     if ($sType == 'ajax' && strpos($sClass, '.') === false) {
         $sClass = $sClass . '.ajax';
     }
     if (is_array($sClass)) {
         return Phpfox::getBlock('core.holder', array('block_location' => $this->_aCacheBlockId[md5($sClass[0])]['location'], 'block_custom_id' => $this->_aCacheBlockId[md5($sClass[0])]['block_id'], 'content' => $sClass[0]));
     }
     $aParts = explode('.', $sClass);
     $sModule = $aParts[0];
     $sComponent = $sType . PHPFOX_DS . substr_replace(str_replace('.', PHPFOX_DS, $sClass), '', 0, strlen($sModule . PHPFOX_DS));
     if ($sType == 'controller') {
         $this->_sModule = $sModule;
         $this->_sController = substr_replace(str_replace('.', PHPFOX_DS, $sClass), '', 0, strlen($sModule . PHPFOX_DS));
     }
     static $sBlockName = '';
     if ($sModule == 'custom') {
         if (preg_match('/block\\' . PHPFOX_DS . 'cf_(.*)/i', $sComponent, $aCustomMatch)) {
             $aParams = array('type_id' => 'user_main', 'template' => 'content', 'custom_field_id' => $aCustomMatch[1]);
             $sBlockName = 'custom_cf_' . $aCustomMatch[1];
             $sComponent = 'block' . PHPFOX_DS . 'display';
             $sClass = 'custom.display';
         }
     }
     /*if (Theme_Service_Theme::instance()->isInDnDMode() || defined('PHPFOX_IN_DESIGN_MODE'))
     		{
     			Phpfox_Template::instance()->assign(array('sDeleteBlock' => str_replace('.','_',$sClass),
     				'bBlockCanMove' => true));				
     		}*/
     $sMethod = $sModule . '_component_' . str_replace(PHPFOX_DS, '_', $sComponent) . '_process';
     /*
     if (preg_match('/(.*?)\((.*?)\)/', $sComponent, $aMatches) && !empty($aMatches[2]))
     {
     	eval('$aParams = array_merge($aParams, array(' . $aMatches[2] . '));');
     
     	$sComponent = $aMatches[1];		
     	$sClass = $aMatches[1];			
     }		
     */
     $sHash = md5($sClass . $sType);
     if (!isset($this->_aModules[$sModule])) {
         return false;
     }
     if (isset($this->_aComponent[$sHash])) {
         $this->_aComponent[$sHash]->__construct(array('sModule' => $sModule, 'sComponent' => $sComponent, 'aParams' => $aParams));
     } else {
         $sClassFile = PHPFOX_DIR_MODULE . $sModule . PHPFOX_DS . PHPFOX_DIR_MODULE_COMPONENT . PHPFOX_DS . $sComponent . '.class.php';
         if (!file_exists($sClassFile) && isset($aParts[1])) {
             $sClassFile = PHPFOX_DIR_MODULE . $sModule . PHPFOX_DS . PHPFOX_DIR_MODULE_COMPONENT . PHPFOX_DS . $sComponent . PHPFOX_DS . $aParts[1] . '.class.php';
         }
         ($sPlugin = Phpfox_Plugin::get('library_module_getcomponent_1')) ? eval($sPlugin) : false;
         if (isset($mPluginReturn)) {
             return $mPluginReturn;
         }
         // Lets check if there is such a component
         if (!file_exists($sClassFile)) {
             ($sPlugin = Phpfox_Plugin::get('library_module_getcomponent_2')) ? eval($sPlugin) : false;
             if (isset($mPluginReturn)) {
                 return $mPluginReturn;
             }
             // Opps, for some reason we have loaded an invalid component. Lets send back info to the dev.
             Phpfox_Error::trigger('Failed to load component: ' . $sClass . ' (' . $sClassFile . ')', E_USER_ERROR);
         }
         // Require the component
         require $sClassFile;
         // Get the object
         $this->_aComponent[$sHash] = Phpfox::getObject($sModule . '_component_' . str_replace(PHPFOX_DS, '_', $sComponent), array('sModule' => $sModule, 'sComponent' => $sComponent, 'aParams' => $aParams));
     }
     $mReturn = 'blank';
     if ($sType != 'ajax') {
         ($sPlugin = Phpfox_Plugin::get('component_pre_process')) ? eval($sPlugin) : false;
         $mReturn = $this->_aComponent[$sHash]->process();
         if (is_object($mReturn) && $mReturn instanceof Closure) {
             ob_clean();
             echo $mReturn->__invoke();
             exit;
         }
         if ($sType == 'controller' && (is_array($mReturn) || is_object($mReturn))) {
             if ($mReturn instanceof Core\jQuery) {
                 $mReturn = ['run' => (string) $mReturn];
             }
             ob_clean();
             header('Content-type: application/json');
             echo json_encode($mReturn);
             exit;
         }
         ($sPlugin = Phpfox_Plugin::get('component_post_process')) ? eval($sPlugin) : false;
     }
     $this->_aReturn[$sClass] = $mReturn;
     // If we return the component as 'false' then there is no need to display it.
     if (is_bool($mReturn) && !$mReturn || $this->_bNoTemplate) {
         if ($this->_bNoTemplate) {
             $this->_bNoTemplate = false;
         }
         return $this->_aComponent[$sHash];
     }
     /* Should we pass the params to the template? */
     if ($bTemplateParams) {
         Phpfox_Template::instance()->assign($aParams);
     }
     // Check if we don't want to display a template
     if (!isset($aParams['bNoTemplate']) && $mReturn != 'blank') {
         if ($mReturn && is_string($mReturn)) {
             $sBlockShowName = $sModule == 'custom' && !empty($sBlockName) ? $sBlockName : ucwords(str_replace('.', ' ', $sClass));
             $sBlockBorderJsId = $sModule == 'custom' && !empty($sBlockName) ? $sBlockName : str_replace('.', '_', $sClass);
             $sBlockPath = $sModule . '.' . str_replace('block' . PHPFOX_DS, '', $sComponent);
             $bCanMove = !isset($this->_aMoveBlocks[$this->_sModule . '.' . $this->_sController][$sBlockPath]) || isset($this->_aMoveBlocks[$this->_sModule . '.' . $this->_sController][$sBlockPath]) && $this->_aMoveBlocks[$this->_sModule . '.' . $this->_sController][$sBlockPath] == true;
             Phpfox_Template::instance()->assign(array('sBlockShowName' => $sBlockShowName, 'sBlockBorderJsId' => $sBlockBorderJsId, 'bCanMove' => $bCanMove, 'sClass' => $sClass))->setLayout($mReturn);
         }
         if (!is_array($mReturn)) {
             $sComponentTemplate = $sModule . '.' . str_replace(PHPFOX_DS, '.', $sComponent);
             ($sPlugin = Phpfox_Plugin::get('module_getcomponent_gettemplate')) ? eval($sPlugin) : false;
             Phpfox_Template::instance()->getTemplate($sComponentTemplate);
         }
         // Check if the component we have loaded has the clean() method
         if (is_object($this->_aComponent[$sHash]) && method_exists($this->_aComponent[$sHash], 'clean')) {
             // This method is used to clean out any garbage we don't need later on in the script. In most cases Template assigns.
             $this->_aComponent[$sHash]->clean();
         }
     }
     return $this->_aComponent[$sHash];
 }
Esempio n. 2
0
 /**
  * Get a phpFox library. This includes the class file and creates the object for you.
  * 
  * Example usage:
  * <code>
  * Phpfox_Url::instance()->makeUrl('test');
  * </code>
  * In the example we called the URL library found in the folder: include/library/phpfox/url/url.class.php
  * then created an object for it so we could directly call the method "makeUrl".
  *
  * @param string $sClass Library class name.
  * @param array $aParams ARRAY of params you can pass to the library.
  * @return object Object of the library class is returned.
  */
 public static function &getLib($sClass, $aParams = array())
 {
     class_exists('Phpfox_Plugin') && ($sPlugin = Phpfox_Plugin::get('library_phpfox_getlib_0')) ? eval($sPlugin) : false;
     if (substr($sClass, 0, 7) != 'phpfox.' || ($sClass == 'phpfox.api' || $sClass == 'phpfox.process')) {
         $sClass = 'phpfox.' . $sClass;
     }
     $sHash = md5($sClass . serialize($aParams));
     if (isset(self::$_aObject[$sHash])) {
         return self::$_aObject[$sHash];
     }
     Phpfox::getLibClass($sClass);
     $sClass = str_replace('phpfox.phpfox.', 'phpfox.', $sClass);
     self::$_aObject[$sHash] = Phpfox::getObject($sClass, $aParams);
     return self::$_aObject[$sHash];
 }
Esempio n. 3
0
	/**
	 * Get a phpFox library. This includes the class file and creates the object for you.
	 * 
	 * Example usage:
	 * <code>
	 * Phpfox::getLib('url')->makeUrl('test');
	 * </code>
	 * In the example we called the URL library found in the folder: include/library/phpfox/url/url.class.php
	 * then created an object for it so we could directly call the method "makeUrl".
	 *
	 * @param string $sClass Library class name.
	 * @param array $aParams ARRAY of params you can pass to the library.
	 * @return object Object of the library class is returned.
	 */
	public static function &getLib($sClass, $aParams = array())
	{		
		if ((substr($sClass, 0, 7) != 'phpfox.') || ($sClass == 'phpfox.api' || $sClass == 'phpfox.process'))
		{
			$sClass = 'phpfox.' . $sClass;
		}
		
		$sHash = md5($sClass . serialize($aParams));
		
		if (isset(self::$_aObject[$sHash]))
		{	
			return self::$_aObject[$sHash];
		}		
		
		Phpfox::getLibClass($sClass);		

		$sClass = str_replace('phpfox.phpfox.', 'phpfox.', $sClass);		

		self::$_aObject[$sHash] = Phpfox::getObject($sClass, $aParams);
		
		return self::$_aObject[$sHash];
	}