/** * Test d'instance unique */ public function testInstanceof() { $foo = _ioClass('fooclass'); $foo2 = _ioClass('fooclass'); $this->assertTrue($foo === $foo2); //instance unique avec un autre id $foo3 = _ioClass('fooclass', 'id3'); $this->assertTrue($foo !== $foo3); $foo4 = _ioClass('fooclass', 'id3'); $this->assertTrue($foo4 === $foo3); }
/** * Création d'un handler * * @param string $pHandlerId Identifiant du handler à créer * @return ICopixCredentialsHandler * @throws CopixUserException */ public static function create($pHandlerId) { if (!isset(self::$_handlers[$pHandlerId])) { try { self::$_handlers[$pHandlerId] = _ioClass($pHandlerId); } catch (Exception $e) { throw new CopixUserException(_i18n('copix:copixuser.error.undefinedCredentialHandler', $pHandlerId)); } } return self::$_handlers[$pHandlerId]; }
/** * Ajout d'un commentaire dans la base après vérification des droits d'écriture * et que l'on a bien la bonne session */ public function processAddComment() { //Vérifie que l'on a bien un paramètre id CopixRequest::assert('id'); if (($informations = _ioClass('commentsservices')->getEnabled(_request('id'))) === false) { throw new Exception(_i18n('comments.error.badidsession')); } //_log ('FROMPAGE: '.$informations['fromPage']); //_log ('POUR ID: '._request ('id')); //vérifie les droits d'écriture if ($informations['writeCredential'] != "") { CopixAuth::getCurrentUser()->assertCredential($informations['writeCredential']); } //Ajout du commentaire $objComment = _record('comments'); $objComment->content_comment = _request('content'); $objComment->format_comment = 'TEXT'; //aujourd'hui on ne supporte que le format text pour les commentaires $objComment->authorlogin_comment = _request('author'); $objComment->authoremail_comment = _request('mail'); $objComment->authorsite_comment = _request('site'); $objComment->page_comment = $informations['id']; $objComment->date_comment = date('YmdHis'); if (CopixConfig::get('comments|captcha') != 0) { $objComment->captcha_id = _request('captcha_id'); $objComment->captcha_answer = _request('captcha_answer'); } try { if (_request('preview') === null) { _ioDAO('comments')->insert($objComment); _ioClass('commentsservices')->removeEnabled($informations['id']); _notify('Content', array('id' => $informations['id'], 'kind' => 'comment', 'keywords' => null, 'title' => $informations['id'], 'summary' => null, 'content' => $objComment->content_comment, 'url' => $informations['fromPage'])); return _arRedirect($informations['fromPage']); } else { _ioClass('commentsservices')->updateEnabled($objComment); return _arRedirect(_url($informations['fromPage'], array('preview' => 1, 'comments' => 'list'))); } } catch (CopixDAOCheckException $e) { _ioClass('commentsservices')->updateEnabled($objComment); return _arRedirect(_url($informations['fromPage'], array('errors' => 1, 'comments' => 'list'))); } }
/** * Cette fonction retourne l'instance de la stratégie adéquat * * @param String $pProfil nom du profil configurer dans copixConfig * @param String $pLevel niveau du log demandé * @return stratégie qui convient */ private static function _getStrategy($pClasse) { $pClasse = strtolower($pClasse); if ($pClasse == '') { throw new Exception('Pas de stratégie définie'); } if (isset(self::$_strategy[$pClasse])) { return self::$_strategy[$pClasse]; } switch ($pClasse) { case 'file': Copix::RequireOnce(COPIX_PATH . 'log/CopixLogFileStrategy.class.php'); return self::$_strategy[$pClasse] = new CopixLogFileStrategy(); case 'db': Copix::RequireOnce(COPIX_PATH . 'log/CopixLogDbStrategy.class.php'); return self::$_strategy[$pClasse] = new CopixLogDbStrategy(); case 'system': Copix::RequireOnce(COPIX_PATH . 'log/CopixLogSystemStrategy.class.php'); return self::$_strategy[$pClasse] = new CopixLogSystemStrategy(); case 'session': Copix::RequireOnce(COPIX_PATH . 'log/CopixLogSessionStrategy.class.php'); return self::$_strategy[$pClasse] = new CopixLogSessionStrategy(); case 'firebug': Copix::RequireOnce(COPIX_PATH . 'log/CopixLogFirebugStrategy.class.php'); return self::$_strategy[$pClasse] = new CopixLogFireBugStrategy(); case 'page': Copix::RequireOnce(COPIX_PATH . 'log/CopixLogPageStrategy.class.php'); return self::$_strategy[$pClasse] = new CopixLogPageStrategy(); case 'email': Copix::RequireOnce(COPIX_PATH . 'log/CopixLogEmailStrategy.class.php'); return self::$_strategy[$pClasse] = new CopixLogEmailStrategy(); default: return self::$_strategy[$pClasse] = _ioClass($pClasse); } }
public function _createContent(&$toReturn) { CopixHtmlHeader::addCSSLink(_resource('styles/comments.css')); //Si pas d'éléments d'identifiant donné, alors on utilise l'ensemble des paramètres de la requête if (($id = $this->getParam('id')) == "") { $id = array_keys(CopixRequest::asArray()); } if (($mode = $this->getParam('mode')) == "" || $mode == "request") { if (($mode = _request('comments')) == "") { $mode = "summary"; } } if (($newUrl = $this->getParam('moreUrl')) == "") { $newUrl = _url('#', array('comments' => 'list')); } $tpl = new CopixTpl(); $tpl->assign('mode', $mode); $tpl->assign('newUrl', $newUrl); // On teste si nous sommes dans l'actions de prévisualisation if (_request('preview') !== null) { $tpl->assign('preview', 1); $tpl->assign('previewDate', date('YmdHis')); } if (CopixAuth::getCurrentUser()->testCredential('basic:admin')) { $tpl->assign('isAdmin', 1); } else { $tpl->assign('isAdmin', 0); } $idComment = _ioClass('commentsservices')->getId($id); // On vérifie si les commentaires sont ouvert $tpl->assign('locked', _dao('commentslocked')->countBy(_daoSp()->addCondition('locked_page_comment', '=', $idComment))); if ($informations = _ioClass('commentsservices')->getEnabled($idComment)) { $tpl->assign('newComment', $informations['object']); if (_request('errors') !== null) { $tpl->assign('errors', _ioDAO('comments')->check($informations['object'])); } } _ioClass('commentsservices')->addEnabled(array('fromPage' => _url('#'), 'writeCredential' => $this->getParam('credentialWrite'), 'id' => $idComment)); $tpl->assign('idComment', $idComment); switch ($mode) { case "list": if ($this->getParam('credentialRead') != "") { CopixAuth::getCurrentUser()->assertCredential($this->getParam('credentialRead')); } $tpl->assign('arrComments', _dao('comments')->findBy(_daoSp()->addCondition('page_comment', '=', $idComment))); break; case "summary": $tpl->assign('nbComments', _dao('comments')->countBy(_daoSp()->addCondition('page_comment', '=', $idComment))); break; } // Mise en place du captcha si besoin : if (CopixConfig::get('comments|captcha') != 0) { $arrCaptchaMax = _ioDao('commentscaptcha')->findBy(_daoSp()->orderBy(array('captcha_id', 'DESC'))->setLimit(0, 1)); $arrCaptchaMin = _ioDao('commentscaptcha')->findBy(_daoSp()->orderBy('captcha_id')->setLimit(0, 1)); $captcha = false; while (!$captcha || is_null($captcha)) { srand(); $rand = rand($arrCaptchaMin[0]->captcha_id, $arrCaptchaMax[0]->captcha_id); $captcha = _ioDao('commentscaptcha')->get($rand); } $tpl->assign('captcha', $captcha); } $toReturn = $tpl->fetch('zone.comment.tpl'); //_log ('URL: '._url('#')); //_log ('ID: ' . $idComment); return true; }
public function testObject() { $element = new CopixSessionObject($object = _ioClass('fooclass'), CopixModule::getPath('copixtest') . 'classes/fooclass.class.php'); $this->assertEquals($element->getSessionObject(), $object); $serialized = serialize($element); $elementBack = unserialize($serialized); $this->assertEquals(strtolower(get_class($elementBack->getSessionObject())), 'fooclass'); $this->assertEquals(1, $elementBack->getParam(1)); $this->assertEquals(array(1, 2), $elementBack->getArrayWith(1, 2)); $elementBack->test = 2; $this->assertEquals($elementBack->test, 2); $this->assertEquals($elementBack->getSessionObject()->test, 2); $elementBack->notExists = 3; $this->assertEquals($elementBack->notExists, 3); $this->assertEquals($elementBack->getSessionObject()->notExists, 3); $elementBack->setPublicPropertyTest(4); $this->assertEquals($elementBack->test, 4); $this->assertEquals($elementBack->getSessionObject()->test, 4); $this->assertEquals($elementBack->getPublicPropertyTest(), 4); $this->assertEquals($elementBack->getSessionObject()->getPublicPropertyTest(), 4); $elementBack->setPrivatePropertyTest(5); $this->assertEquals($elementBack->getPrivatePropertyTest(), 5); $this->assertEquals($elementBack->getSessionObject()->getPrivatePropertyTest(), 5); $elementBack->setUnknownProperty('notexists', 6); $this->assertEquals($elementBack->getUnknownProperty('notexists'), 6); $this->assertEquals($elementBack->getSessionObject()->getUnknownProperty('notexists'), 6); $this->assertEquals($elementBack->notexists, 6); $this->assertEquals($elementBack->getSessionObject()->notexists, 6); }
public function processGetMultipleSelectContent() { $currentId = null; $classString = CopixSession::get(CopixRequest::get('class')); $arClass = explode('::', $classString); $class = _ioClass($arClass[0]); $values = $class->{$arClass}[1](); $objectMap = CopixRequest::get('objectMap'); if (!empty($objectMap)) { $tab = explode(';', $objectMap); if (count($tab) != 2) { throw new CopixTemplateTagException("[plugin select] parameter 'objectMap' must looks like idProp;captionProp"); } $idProp = $tab[0]; $captionProp = $tab[1]; } $id = CopixRequest::get('idselect'); $name = CopixRequest::get('nameselect'); $toReturn = ''; $compteur = 0; if (empty($objectMap)) { foreach ((array) $values as $key => $caption) { $currentId = uniqid(); $compteur++; $color = $compteur % 2 == 0 ? '#cccccc' : '#ffffff'; $toReturn .= '<div style="width:100%;background-color:' . $color . '"><input type="checkbox" class="check_' . $id . '" id="' . $currentId . '" value="' . $key . '" /><label id="label_' . $currentId . '" for="' . $currentId . '">' . _copix_utf8_htmlentities($caption) . '</label></div>'; } } else { //if given an object mapping request. foreach ((array) $values as $object) { $color = $compteur % 2 == 0 ? '#cccccc' : '#ffffff'; $toReturn .= '<div style="width:100%;background-color:' . $color . '"><input type="checkbox" id="' . $currentId . '" class="check_' . $id . '" value="' . $object->{$idProp} . '" /><label id="label_' . $currentId . '" for="' . $currentId . '">' . _copix_utf8_htmlentities($object->{$captionProp}) . '</label></div>'; } } //CopixSession::set(CopixRequest::get('class'),null); CopixHTMLHeader::addJsCode("\n window.addEvent('domready', function () {\n var input = \$('{$id}');\n \$\$('.check_{$id}').each (function (el) {\n el.addEvent ('change', function () {\n var value = '';\n \$('hidden_{$id}').setHTML('');\n \$\$('.check_{$id}').each ( function (el) {\n if (el.checked) {\n if (value!='') {\n value += ',';\n }\n value += \$('label_'+el.getProperty('id')).innerHTML;\n \$('hidden_{$id}').setHTML (\$('hidden_{$id}').innerHTML+'<input type=\"hidden\" name=\"" . $name . "[]\" value=\"'+el.value+'\" />');\n }\n });\n input.value = value;\n });\n });\n });\n "); return _arDirectPPO(new CopixPPO(array('MAIN' => $toReturn)), 'generictools|blank.tpl'); }
/** * Instancie la stratégie associée à ce type de cache * * @param string $pName Nom de la stratégie à instancier * @return object Instance de la stratégie demandée */ private static function _getStrategy($pName) { $pName = strtolower($pName); if (isset(self::$_strategy[$pName])) { return self::$_strategy[$pName]; } switch ($pName) { case 'file': require_once COPIX_PATH . 'cache/CopixCacheFileStrategy.class.php'; return self::$_strategy[$pName] = new CopixCacheFileStrategy(); case 'apc': require_once COPIX_PATH . 'cache/CopixCacheApcStrategy.class.php'; return self::$_strategy[$pName] = new CopixCacheApcStrategy(); case 'system': require_once COPIX_PATH . 'cache/CopixCacheSystemStrategy.class.php'; return self::$_strategy[$pName] = new CopixCacheSystemStrategy(); default: return self::$_strategy[$pName] = _ioClass($pName); } }
/** * Récupération des connexions * * @return array liste des connections */ private function _getConnections() { if (CopixSession::get('admin|database|configure') === null) { CopixSession::set('admin|database|configure', _ioClass('DatabaseConfigurationFile')->getConnections()); } return CopixSession::get('admin|database|configure'); }