public function _createContent(&$toReturn) { //Création du sous template. $tpl = new CopixTpl(); CopixClassesFactory::fileInclude('cms|ServicesCMSPage'); CopixContext::push('cms'); $sHeadings = CopixClassesFactory::getInstanceOf('copixheadings|CopixHeadingsServices'); $headings = $sHeadings->getTree(); $cmsPages = new ServicesCMSPage(); $pages = $cmsPages->getList(); if (isset($this->_params['onlyLastVersion']) && $this->_params['onlyLastVersion'] == 1) { $pages = $this->_filterLastVersion($pages); } CopixContext::pop(); //pagination foreach ($pages as $page) { $arPages[$page->id_head][] = $page; } $tpl->assign('arPublished', $arPages); $tpl->assign('arHeadings', $headings); $tpl->assign('select', $this->getParam('select')); $tpl->assign('back', $this->getParam('back')); $tpl->assign('popup', $this->getParam('popup')); $tpl->assign('height', Copixconfig::get('htmleditor|height')); $tpl->assign('width', Copixconfig::get('htmleditor|width')); //$tpl->assign ('editorType' , CopixConfig::get('htmleditor|type')); $tpl->assign('editorName', $this->getParam('editorName')); $toReturn = $tpl->fetch('page.select.ptpl'); return true; }
function _createContent(&$toReturn) { //Création du sous template. $tpl =& new CopixTpl(); //require_once (COPIX_MODULE_PATH.'cms/'.COPIX_CLASSES_DIR.'cmsworkflow.class.php'); require_once COPIX_MODULE_PATH . 'cms/' . COPIX_CLASSES_DIR . 'cmspage.services.class.php'; CopixContext::push('cms'); $sHeadings =& CopixClassesFactory::instanceOf('copixheadings|CopixHeadingsServices'); $headings = $sHeadings->getTree(); $cmsPages =& new ServicesCMSPage(); $pages = $cmsPages->getList(); if (isset($this->params['onlyLastVersion']) && $this->params['onlyLastVersion'] == 1) { $pages = $this->_filterLastVersion($pages); } CopixContext::pop(); //pagination foreach ($pages as $page) { $arPages[$page->id_head][] = $page; } $tpl->assign('arPublished', $arPages); $tpl->assign('arHeadings', $headings); $tpl->assign('select', $this->params['select']); $tpl->assign('back', $this->params['back']); $tpl->assign('popup', $this->params['popup']); $tpl->assign('height', Copixconfig::get('htmleditor|height')); $tpl->assign('width', Copixconfig::get('htmleditor|width')); $tpl->assign('editorType', CopixConfig::get('htmleditor|type')); $tpl->assign('editorName', $this->params['editorName']); $toReturn = $tpl->fetch('page.select.ptpl'); return true; }
/** * Encapsulation de l'appel des fonctions pour les transmettre directement à l'objet tout * en ayant au préalable indiqué les informations de contexte * * @param string $pName nom de la fonction * @param array $pArgs arguments passés à la fonction * @return mixed */ public function __call($pName, $pArgs) { CopixContext::push($this->_context); $toReturn = parent::__call($pName, $pArgs); CopixContext::pop(); return $toReturn; }
/** * Test des quelques fonctions de base */ public function testNormalization() { //Test des éléments de module simple $this->assertEquals(CopixSelectorFactory::normalize('module:copixtest|classedetest'), 'module:copixtest|classedetest'); $this->assertEquals(CopixSelectorFactory::normalize('copixtest|classedetest'), 'module:copixtest|classedetest'); CopixContext::push('copixtest'); $this->assertEquals(CopixSelectorFactory::normalize('classedetest'), 'module:copixtest|classedetest'); $this->assertEquals(CopixSelectorFactory::normalize('module:classedetest'), 'module:copixtest|classedetest'); CopixContext::pop(); CopixContext::push('default'); $this->assertEquals(CopixSelectorFactory::normalize('classedetest'), 'module:default|classedetest'); $this->assertEquals(CopixSelectorFactory::normalize('module:classedetest'), 'module:default|classedetest'); CopixContext::pop(); //Test des éléments ActionGroup CopixContext::push('copixtest'); $this->assertEquals(CopixSelectorFactory::normalize('module:copixtest|ActionGroup::methode'), 'module:copixtest|ActionGroup::methode'); $this->assertEquals(CopixSelectorFactory::normalize('copixtest|ActionGroup::methode'), 'module:copixtest|ActionGroup::methode'); $this->assertEquals(CopixSelectorFactory::normalize('ActionGroup::methode'), 'module:copixtest|ActionGroup::methode'); CopixContext::pop(); //Test des éléments de type "non modifiables" lors de la normalisation $this->assertEquals(CopixSelectorFactory::normalize('file:/mon/chemin/de/fichier'), 'file:/mon/chemin/de/fichier'); $this->assertEquals(CopixSelectorFactory::normalize('var:/mon/chemin/de/fichier'), 'var:/mon/chemin/de/fichier'); $this->assertEquals(CopixSelectorFactory::normalize('resource:/mon/chemin/de/fichier'), 'resource:/mon/chemin/de/fichier'); $this->assertEquals(CopixSelectorFactory::normalize('copix:/mon/chemin/de/fichier'), 'copix:/mon/chemin/de/fichier'); }
/** * gets the parameters list */ function _getParams($module) { $toReturn = array(); CopixContext::push($module); foreach (CopixConfig::getParams($module) as $params) { $params['Caption'] = CopixI18N::get($params['Caption']); $toReturn[] = $params; } CopixContext::pop(); return $toReturn; }
public function tearDown() { $c = trim(ob_get_contents()); ob_end_clean(); /* if($c) { $n = $this->getName(); printf('<div style="background-color: white"><a name="%s" href="#%s"><h3>%s</h3></a><pre>%s</pre></div>', $n, $n, $n, $c); } */ CopixContext::pop(); }
/** * Demande l'exécution d'une zone d'identifiant $name avec ses paramètres $params * @param string $pName l'identifiant de la zone à afficher * @param array $pParams les paramètres d'exécution de la zone. * @return string le contenu de la zone */ public static function process($pName, $pParams = array()) { $zoneObject = self::_create($pName); if ($zoneObject === false) { trigger_error('CopixZone [' . $pName . '] not found', E_USER_WARNING); return false; } $content = $zoneObject->_process($pParams); //On sait que createZone place le contexte d'exécution de la zone. CopixContext::pop(); return $content; }
/** * Zone that passes all its parameters to the given template * @param: * abstract * @param: template string the template name where the datas will be assigned to. */ function _createContent(&$toReturn) { //we wants to go back to the current context. $context = CopixContext::pop(); $tpl =& new CopixTpl(); //assign the template variables foreach ($this->params as $var => $value) { if ($var !== 'template') { $tpl->assign($var, $value); } } $toReturn = $tpl->fetch($this->params['template']); //then we wants to bring back the context we poped CopixContext::push($context); return true; }
/** * Tests sur les contextes */ public function testContext() { //En premier lieu, le Contexte doit être default $this->assertEquals(CopixContext::get(), 'default'); //On vérifie que l'on arrive à placer des Contextes CopixContext::push('module1'); $this->assertEquals(CopixContext::get(), 'module1'); //On vérifie que l'on pop correctement le contexte $lastContext = CopixContext::pop(); $this->assertEquals($lastContext, 'module1'); //On vérifie que le contexte est revenu à default $this->assertEquals('default', CopixContext::get()); //on vérifie que même si l'utilisateur fait n'importe quoi et pop de trop, //on indique default comme dernier contexte (ce qui est le cas) $lastContext = CopixContext::pop(); $this->assertEquals($lastContext, 'default'); //On vérifie que l'on peut poser plusieurs éléments $push = array('push1', 'push2', 'push3', 'push4'); foreach ($push as $pushMe) { CopixContext::push($pushMe); $this->assertEquals($pushMe, CopixContext::get()); } //et on vérifie que ces éléments reviennent dans le bon ordre for ($i = 0; $i < count($push); $i++) { $poped = CopixContext::pop(); $this->assertEquals($push[count($push) - ($i + 1)], $poped); } //on vérifie que l'on est bien retourné en default $this->assertEquals(CopixContext::get(), 'default'); //on repousse le tableau pour contrôler la méthode clear. foreach ($push as $pushMe) { CopixContext::push($pushMe); $this->assertEquals($pushMe, CopixContext::get()); } // On efface les contextes CopixContext::clear(); $this->assertEquals(CopixContext::get(), 'default'); }
/** * gets the module info * @return object module informations */ function getInformations($moduleName) { if (!CopixModule::isValid($moduleName)) { return null; } $toReturn = null; require_once COPIX_UTILS_PATH . 'CopixSimpleXml.class.php'; $xmlParser =& new CopixSimpleXML(); $fileName = COPIX_MODULE_PATH . $moduleName . '/module.xml'; if (!($parsedFile = $xmlParser->parseFile($fileName))) { $xmlParser->raiseError(); } if (isset($parsedFile->GENERAL)) { $defaultAttr = $parsedFile->GENERAL->DEFAULT->__attributes; $toReturn->name = $defaultAttr['NAME']; CopixContext::push($toReturn->name); $toReturn->description = CopixI18N::get($defaultAttr['DESCRIPTIONI18N']); $toReturn->longDescription = isset($defaultAttr['LONGDESCRIPTIONI18N']) ? CopixI18N::get($defaultAttr['LONGDESCRIPTIONI18N']) : ''; CopixContext::pop(); $toReturn->dependencies = array(); if (isset($parsedFile->DEPENDENCIES)) { if (is_array($parsedFile->DEPENDENCIES->DEPENDENCY)) { foreach ($parsedFile->DEPENDENCIES->DEPENDENCY as $dependency) { $attributes = $dependency->attributes(); $toReturn->dependencies[] = $attributes['NAME']; } } else { $attributes = $parsedFile->DEPENDENCIES->DEPENDENCY->__attributes; $toReturn->dependencies[] = $attributes['NAME']; } } } return $toReturn; }
/** * Creation d'un objet zone et appel de sa méthode process. * @param string $name le nom de la zone a instancier. * @param array $params un tableau a passer a la fonction processZone de l'objet zone. */ function processZone($name, $params = array()) { //Récupération des éléments critiques. $fileInfo =& new CopixModuleFileSelector($name); CopixContext::push($fileInfo->module); //Récupère le nom du fichier en fonction du module courant. $fileName = $fileInfo->getPath(COPIX_ZONES_DIR) . strtolower($fileInfo->fileName) . COPIX_ZONE_EXT; if (!is_readable($fileName)) { trigger_error(CopixI18N::get('copix:copix.error.load.zone', $fileInfo->fileName), E_USER_ERROR); } //inclusion du fichier. require_once $fileName; $objName = COPIX_ZONE_CLASSNAME . $fileInfo->fileName; $objTraitement =& new $objName(); $toReturn = $objTraitement->processZone($params); CopixContext::pop(); return $toReturn; }
/** * Gets the module info * * @return object module informations */ public static function getInformations($moduleName) { if (!self::isValid($moduleName)) { throw new CopixException('Nom de module ' . $moduleName . ' invalide'); } $toReturn = new CopixModuleDescription(); $parsedFile = simplexml_load_file(self::getPath($moduleName) . 'module.xml'); if (isset($parsedFile->general)) { $defaultAttr = $parsedFile->general->default->attributes(); $toReturn->name = _copix_utf8_decode((string) $defaultAttr['name']); //Récupération de la version des sources $toReturn->version = 0; if (isset($defaultAttr['version'])) { $toReturn->version = _copix_utf8_decode((string) $defaultAttr['version']); } CopixContext::push($toReturn->name); $toReturn->description = isset($defaultAttr['descriptioni18n']) ? _i18n((string) $defaultAttr['descriptioni18n']) : _copix_utf8_decode((string) $defaultAttr['description']); $toReturn->longDescription = isset($defaultAttr['longdescriptioni18n']) ? _i18n((string) $defaultAttr['longdescriptioni18n']) : (isset($defaultAttr['longdescription']) ? _copix_utf8_decode((string) $defaultAttr['longdescription']) : $toReturn->description); $toReturn->path = self::getBasePath($moduleName); if (isset($defaultAttr['icon']) && file_exists(_resourcePath('img/icons/' . (string) $defaultAttr['icon']))) { $toReturn->icon = _resource('img/icons/' . (string) $defaultAttr['icon']); } else { $toReturn->icon = null; } // informations sur le groupe du module (node group) if (isset($parsedFile->general->group)) { $attributes = $parsedFile->general->group->attributes(); // pas d'id renseigné if (!isset($attributes['id'])) { throw new CopixException(_i18n('copix:copixmodule.error.moduleGroupIdEmpty')); } $toReturn->group->id = isset($attributes['id']) ? (string) $attributes['id'] : null; if (isset($attributes['caption'])) { $toReturn->group->caption = (string) $attributes['caption']; } elseif (isset($attributes['captioni18n'])) { $toReturn->group->caption = _i18n((string) $attributes['captioni18n']); } else { $toReturn->group->caption = $toReturn->group_id; } // pas d'information de groupe } else { $toReturn->group->id = null; $toReturn->group->caption = null; } // dépendances $toReturn->dependencies = array(); $toReturn->XMLDependencies = isset($parsedFile->dependencies) ? $parsedFile->dependencies : null; if (isset($parsedFile->dependencies)) { foreach ($parsedFile->dependencies->dependency as $dependency) { $attributes = $dependency->attributes(); $currentDependency = new stdClass(); $currentDependency->name = _copix_utf8_decode((string) $attributes['name']); $currentDependency->kind = _copix_utf8_decode((string) $attributes['kind']); $toReturn->dependencies[] = $currentDependency; } } // liens dans la partie admin $toReturn->admin_links = array(); if (isset($parsedFile->admin)) { $adminAttributes = $parsedFile->admin->attributes(); $toReturn->admin_links_group->id = isset($adminAttributes['groupid']) ? (string) $adminAttributes['groupid'] : null; $toReturn->admin_links_group->caption = null; if (isset($adminAttributes['groupcaption'])) { $toReturn->admin_links_group->caption = (string) $adminAttributes['groupcaption']; } elseif (isset($adminAttributes['groupcaptioni18n'])) { $toReturn->admin_links_group->caption = _i18n((string) $adminAttributes['groupcaptioni18n']); } $toReturn->admin_links_group->icon = isset($adminAttributes['groupicon']) ? _resource('img/icons/' . (string) $adminAttributes['groupicon']) : null; foreach ($parsedFile->admin->link as $link) { $attributes = $link->attributes(); $linkInformations = array(); if (isset($attributes['captioni18n'])) { $linkInformations['caption'] = _i18n((string) $attributes['captioni18n']); } else { $linkInformations['caption'] = isset($attributes['caption']) ? _copix_utf8_decode((string) $attributes['caption']) : $toReturn->name; } $linkInformations['url'] = _url((string) $attributes['url']); $linkInformations['credentials'] = isset($attributes['credentials']) ? (string) $attributes['credentials'] : null; $toReturn->admin_links[] = $linkInformations; } } //Récupération des droits $toReturn->credential = array(); $toReturn->credential_notspecific = array(); if (isset($parsedFile->credentials)) { foreach ($parsedFile->credentials->credential as $credential) { if (isset($credential['specific']) && (string) $credential['specific'] == "false") { $toReturn->credential_notspecific[(string) $credential['name']] = array(); $currentCredential =& $toReturn->credential_notspecific[(string) $credential['name']]; } else { $toReturn->credential[(string) $credential['name']] = array(); $currentCredential =& $toReturn->credential[(string) $credential['name']]; } foreach ($credential->value as $value) { $currentValue = new StdClass(); $currentValue->name = (string) $value['name']; $currentValue->level = isset($value['level']) ? (string) $value['level'] : null; $currentCredential[] = $currentValue; } } } //Récupération de la list des scripts d'update $toReturn->update = array(); if (isset($parsedFile->updates)) { foreach ($parsedFile->updates->update as $update) { $currentUpdate = new stdClass(); $attributes = $update->attributes(); $currentUpdate->script = isset($attributes['script']) ? (string) $attributes['script'] : null; $currentUpdate->from = isset($attributes['from']) ? (string) $attributes['from'] : null; $currentUpdate->to = isset($attributes['to']) ? (string) $attributes['to'] : null; $toReturn->update[] = $currentUpdate; } } CopixContext::pop(); } else { throw new Exception('Impossible de lire le fichier ' . self::getPath($moduleName) . 'module.xml'); } return $toReturn; }
/** * Creation d'un objet zone et appel de sa méthode processZone. * @param string $name le nom de la zone à instancier. * @param array $params un tableau a passer a la fonction processZone de l'objet zone. */ function &_callZone($name, $method, &$params) { //Récupération des éléments critiques. $fileInfo =& new CopixModuleFileSelector($name); CopixContext::push($fileInfo->module); //Récupère le nom du fichier en fonction du module courant. $fileName = $fileInfo->getPath(COPIX_ZONES_DIR) . strtolower($fileInfo->fileName) . '.zone.php'; /* if (!is_readable ($fileName)){ trigger_error (CopixI18N::get('copix:copix.error.load.zone',$fileInfo->fileName), E_USER_ERROR); } */ //inclusion du fichier. require_once $fileName; $objName = 'Zone' . $fileInfo->fileName; $objTraitement =& new $objName(); $toReturn = $objTraitement->{$method}($params); CopixContext::pop(); return $toReturn; }
/** * Execution d'une action * * @param string $pPath Identifier 'module|AG::method' * @param array $pVars Paramètres * @param bool $pFromDesc Indique si l'on viens d'un fichier de description (à raison de compatibilité) * @return CopixActionReturn * @todo Supprimer $pFromDesc dans les prochaines versions de copix * @throws Exception */ public static function process($pPath, $pVars = array(), $pFromDesc = false) { $extractedPath = CopixActionGroup::_extractPath($pPath); if ($extractedPath === null) { throw new Exception(_i18n('copix:copix.error.load.actiongroup', $pPath)); } $actiongroup = CopixActionGroup::instance($extractedPath); $methName = $pFromDesc === false ? 'process' . $extractedPath->method : $extractedPath->method; if (!method_exists($actiongroup, $methName)) { $methName = 'otherAction'; } // on défini le module CopixContext::push($extractedPath->module); foreach ($pVars as $varName => $varValue) { CopixRequest::set($varName, $varValue); } // on essaye d'exécuter l'action try { if (($result = $actiongroup->_beforeAction($extractedPath->method)) === null) { if ($methName == 'otherAction') { $toReturn = $actiongroup->{$methName}($extractedPath); } else { $toReturn = $actiongroup->{$methName}(); } } else { $extractedPath->method = '_beforeAction'; $toReturn = $result; } if (($result = $actiongroup->_afterAction($extractedPath->method, $toReturn)) !== null) { $toReturn = $result; } // si on n'a pas fait de return valide if (!$toReturn instanceof CopixActionReturn) { throw new CopixException(_i18n('copix:copix.error.invalidActionReturn', array(gettype($toReturn)))); } } catch (Exception $e) { try { $toReturn = $actiongroup->_catchActionExceptions($e, $extractedPath->method); } catch (Exception $e) { // on est obligé de relancer un try/catch pour pouvoir faire un pop du contexte CopixContext::pop(); throw $e; } } CopixContext::pop(); return $toReturn; }
/** * Launch an actiongroup method * @param string $path identifier 'module|AG::method' * @param array $vars parameters */ function &process($path, $vars = array()) { static $instance = array(); $toReturn = null; $extractedPath = CopixActionGroup::extractPath($path); if ($extractedPath === null) { trigger_error(CopixI18N::get('copix:copix.error.load.actiongroup', $path), E_USER_ERROR); return $toReturn; } $actionGroupID = $extractedPath->module . '|' . $extractedPath->actiongroup; if (!isset($instance[$actionGroupID])) { if ($extractedPath->module === null) { $execPath = COPIX_PROJECT_PATH; } else { $execPath = COPIX_MODULE_PATH . $extractedPath->module . '/'; } $fileName = $execPath . COPIX_ACTIONGROUP_DIR . strtolower(strtolower($extractedPath->actiongroup)) . '.actiongroup.php'; if (is_readable($fileName)) { require_once $fileName; } else { trigger_error(CopixI18N::get('copix:copix.error.load.actiongroup', $path . '-' . $fileName), E_USER_ERROR); return $toReturn; } //Nom des objets/méthodes à utiliser. $objName = 'ActionGroup' . $extractedPath->actiongroup; //instance de l'objet, qui s'enregistre dans GLOBALS['COPIX']['ACTIONGROUP'] $instance[$actionGroupID] =& new $objName(); } $methName = $extractedPath->method; CopixContext::push($extractedPath->module); $instance[$actionGroupID]->vars =& $vars; $toReturn = $instance[$actionGroupID]->{$methName}(); CopixContext::pop(); return $toReturn; }
/** * Demande l'exécution d'un service donné * @param string $pServiceId L'identifiant du service que l'on souhaite lancer * @param array $vars parameters */ public static function process($pServiceId, $pParams = array(), $pTransactionContext = self::NEW_TRANSACTION) { $extractedPath = self::_extractPath($pServiceId); $service = self::_create($extractedPath, $pParams); $methName = $extractedPath->method; CopixContext::push($extractedPath->module); try { if ($pTransactionContext == self::NEW_TRANSACTION) { CopixDB::begin(); } $toReturn = $service->{$methName}(); if ($pTransactionContext == self::NEW_TRANSACTION) { CopixDB::commit(); } CopixContext::pop(); return $toReturn; } catch (Exception $e) { if ($pTransactionContext == self::NEW_TRANSACTION) { CopixDB::rollback(); } CopixContext::pop(); throw $e; } }
public function tearDown() { CopixContext::pop(); }
/** * Pop le contexte (alias à CopixContext::pop au sein de la classe) * @return string */ private function _popContext() { CopixContext::pop(); }
/** * Renvoi des infos sur un paramètre * * @param string $pParam Nom du paramètre * @return array */ private function _getParam($pParam) { // ce module n'a pas de paramètres sauvegardés if (!isset($this->_xmlParameters[$this->module]) || count($this->_xmlParameters[$this->module]) == 0) { return null; } $module = $this->module === "|" ? "default" : substr($this->module, 0, -1); CopixContext::push($module); // boucle sur tous les paramètres foreach ($this->_xmlParameters[$this->module] as $groupKey => $groupChild) { foreach ($groupChild as $key => $child) { $attributes = $child->attributes(); // si c'est le paramètre $pParam if (isset($attributes['name']) && $attributes['name'] == $pParam) { $type = isset($attributes['type']) && in_array($attributes['type'], $this->_allowedTypes) ? (string) $attributes['type'] : 'text'; $default = (string) $attributes['default']; // récupération de la valeur par défaut "à afficher" if ($type == 'select' || $type == 'multiSelect') { $values = $this->_strToArray((string) $attributes['listValues']); $defaultStr = isset($values[$default]) ? trim($values[$default]) : $default; } elseif ($type == 'bool') { //echo '[$groupKey] [' . $groupKey . '] [$attributes] [' . $attributes['name'] . '] [$type] [' . $type . ']<br />'; $defaultStr = $default == 0 ? _i18n('copix:copix.no') : _i18n('copix:copix.yes'); } else { $defaultStr = (string) $attributes['default']; } $toReturn = array('Name' => (string) $attributes['name'], 'Caption' => isset($attributes['captioni18n']) ? _i18n((string) $attributes['captioni18n']) : utf8_decode((string) $attributes['caption']), 'Default' => utf8_decode($default), 'DefaultStr' => $defaultStr, 'Value' => $default, 'ValueStr' => $defaultStr, 'Type' => $type, 'MinValue' => isset($attributes['minValue']) ? (string) $attributes['minValue'] : null, 'MaxValue' => isset($attributes['maxValue']) ? (string) $attributes['maxValue'] : null, 'MaxLength' => isset($attributes['maxLength']) ? (string) $attributes['maxLength'] : null, 'ListValues' => isset($attributes['listValues']) ? (string) $attributes['listValues'] : null, 'Group' => $groupKey); CopixContext::pop(); return $toReturn; } } } CopixContext::pop(); return null; }
public function tearDown() { CopixConfig::Instance()->i18n_path_enabled = $this->saveConfigi18n; CopixContext::pop(); }