/** * Surcharge de la fonction de vérification de l'enregistrement pour avoir les bons libellés. * @param DAORecord $pRecord L'enregistrement à vérifier */ public function check($pRecord) { //vérifications standards. if (($arErrors = $this->_compiled_check($pRecord)) === true) { $arErrors = array(); } //vérification du format du mail try { if (isset($pRecord->authoremail_comment)) { CopixFormatter::getMail($pRecord->authoremail_comment); } } catch (Exception $e) { $arErrors[] = $e->getMessage(); } // vérification de l'antispam if (CopixConfig::get('comments|captcha') != 0 && !isset($pRecord->noCaptcha)) { $results = _ioDAO('commentscaptcha')->findBy(_ioDAOSp()->addCondition("captcha_id", "=", $pRecord->captcha_id)); if (!(isset($results[0]) && $results[0]->captcha_answer == $pRecord->captcha_answer)) { $arErrors[] = _i18n('comments.admin.captcha.error'); } } //on remplace avec les bons libellés foreach ($arErrors as $key => $error) { $arErrors[$key] = str_replace(array('"content_comment"', '"authoremail_comment"', '"authorsite_comment"', '"authorlogin_comment"'), array(_i18n('comments.list.content'), _i18n('comments.list.mail'), _i18n('comments.list.site'), _i18n('comments.list.author')), $error); } //erreurs s'il en existe, true sinon return count($arErrors) == 0 ? true : $arErrors; }
/** * Applique les changements sur le paramètre */ public function processValid() { CopixRequest::assert('idFirst', 'idSecond', 'value'); // si la config existe bien if (CopixConfig::exists(CopixRequest::get('idFirst') . '|' . CopixRequest::get('idSecond'))) { // initialisation de variables $id = CopixRequest::get('idFirst') . '|' . CopixRequest::get('idSecond'); $params = CopixConfig::getParams(CopixRequest::get('idFirst')); $config = $params[$id]; $value = CopixRequest::get('value'); $error = false; // type int if ($config['Type'] == 'int') { // chiffre invalide if ((string) intval($value) != (string) $value) { $error = 'typeInt'; // chiffre trop petit } elseif (!is_null($config['MinValue']) && $config['MinValue'] > intval($value)) { $error = 'typeIntMin'; // chiffre trop grand } elseif (!is_null($config['MaxValue']) && $config['MaxValue'] < intval($value)) { $error = 'typeIntMax'; } // type email } elseif ($config['Type'] == 'email') { // email invalide try { CopixFormatter::getMail($value); } catch (CopixException $e) { $error = 'typeEmail'; } // e-mail trop long if (!is_null($config['MaxLength']) && strlen($value) > $config['MaxLength']) { $error = 'typeEmailMax'; } // type text } elseif ($config['Type'] == 'text') { // texte trop long if (!is_null($config['MaxLength']) && strlen($value) > $config['MaxLength']) { $error = 'typeTextMax'; } } // si il y a eu une erreur if ($error !== false) { return _arRedirect(_url('admin|parameters|', array('choiceModule' => CopixRequest::get('choiceModule'), 'editParam' => CopixRequest::get('idSecond'), 'error' => $error))); } // modification de la config CopixConfig::set($id, $value); } return _arRedirect(_url('admin|parameters|', array('choiceModule' => CopixRequest::get('choiceModule')))); }
/** * Methode qui fait les tests sur la $pValue * * @param mixed $pValue La valeur */ protected function _validate($pValue) { try { CopixFormatter::getMail($pValue); } catch (CopixException $e) { return $e->getMessage(); } if ($this->getParam('tld')) { $arValue = explode('.', $pValue); $pExt = $arValue[count($arValue) - 1]; if (!$this->_isTldValid($pExt)) { return _i18n('copix:copixformatter.error.badmail', $pValue); } } return true; }
public function testExplodeCapitalized() { $this->assertEquals(array('Il', 'Etait', 'Une', 'Fois'), CopixFormatter::explodeCapitalized('IlEtaitUneFois')); $this->assertEquals(array('XML', 'String', 'For', 'You'), CopixFormatter::explodeCapitalized('XMLStringForYou')); $this->assertEquals(array('il', 'Etait', 'Une', 'Fois'), CopixFormatter::explodeCapitalized('ilEtaitUneFois')); $this->assertEquals(array('il', 'Etait', 'Un', 'XML'), CopixFormatter::explodeCapitalized('ilEtaitUnXML')); $this->assertEquals(array('il', 'Etait', 'Un', 'XML', 'File'), CopixFormatter::explodeCapitalized('ilEtaitUnXMLFile')); $this->assertEquals(array('il', 'Etait', 'Un', 'XML', 'File', 'S'), CopixFormatter::explodeCapitalized('ilEtaitUnXMLFileS')); $this->assertEquals(array('il', 'Fait', 'S4'), CopixFormatter::explodeCapitalized('ilFaitS4')); $this->assertEquals(array('il', 'Fait', 'S478W'), CopixFormatter::explodeCapitalized('ilFaitS478W')); $this->assertEquals(array('il', 'Fait', 'S478W', 'Milamber'), CopixFormatter::explodeCapitalized('ilFaitS478WMilamber')); $this->assertEquals(array('il', 'Fait', 'S478W', 'Milamber1'), CopixFormatter::explodeCapitalized('ilFaitS478WMilamber1')); $this->assertEquals(array('il', 'Fait', 'S478W', 'Milamber12'), CopixFormatter::explodeCapitalized('ilFaitS478WMilamber12')); $this->assertEquals(array('il', 'Fait', 'S478W', 'Milamber12nb'), CopixFormatter::explodeCapitalized('ilFaitS478WMilamber12nb')); $this->assertEquals(array('il', 'Fait', 'S478W', 'Milamber12', 'Super'), CopixFormatter::explodeCapitalized('ilFaitS478WMilamber12Super')); $this->assertEquals(array('il', 'Fait', 'S478W', 'Milamber12nb', 'Super'), CopixFormatter::explodeCapitalized('ilFaitS478WMilamber12nbSuper')); }
/** * Methode qui fait les tests sur la $pValue * * @param mixed $pValue La valeur */ public function _validate($pValue) { // Récupération $gender = $this->getParam('gender', null); if ($pValue == '') { return true; } try { CopixFormatter::getNumeroSecuriteSociale(substr($pValue, 0, -2), substr($pValue, -2)); } catch (CopixException $e) { return $e->getMessage(); } if ($gender !== null) { if (!preg_match('/^' . $gender . '/', $pValue)) { return _i18n('copix:copixformatter.error.incorrectdatasecu'); } } return true; }
/** * Methode qui fait les tests sur la $pValue * * @param mixed $pValue La valeur */ public function _validate($pValue) { // Récupération $telKind = $this->getParam('kind', null); try { CopixFormatter::getTelephone($pValue); } catch (CopixException $e) { return $e->getMessage(); } switch ($telKind) { case 'mobile': if (!preg_match('/^06/', $pValue)) { return _i18n('copix:copixformatter.error.badmobile'); } break; case 'international': if (!preg_match('/^00/', $pValue)) { return _i18n('copix:copixformatter.error.badtel'); } break; } return true; }
/** * Validation des modification sur le profil de log */ public function processValid() { $profile = CopixSession::get('admin|log|edit'); if (_request('enabled')) { $profile['enabled'] = true; } else { $profile['enabled'] = false; } $profile['strategy'] = _request('strategy'); if (_request('strategy_class', null, true)) { $profile['strategy'] = _request('strategy_class'); } $profile['level'] = _request('level'); if ($handle = _request('handle', null, true)) { if (is_array($profile['handle'])) { if (!in_array($handle, $profile['handle'])) { $profile['handle'][] = $handle; } } else { $profile['handle'] = array($handle); } } if (!isset($profile['handleExcept'])) { $profile['handleExcept'] = array(); } if (!is_array($profile['handle'])) { if ($handleExcept = _request('handleExcept', null, true)) { if (is_array($profile['handleExcept'])) { if (!in_array($handleExcept, $profile['handleExcept'])) { $profile['handleExcept'][] = $handleExcept; } } else { $profile['handleExcept'] = array($handleExcept); } } } else { if (is_array($profile['handleExcept'])) { unset($profile['handleExcept']); } } // email de destination dans le cas d'une stratégie de profil de type email if ($profile['strategy'] == 'email') { $emails = explode(';', _request('email')); foreach ($emails as $email) { try { $email = CopixFormatter::getMail($email); } catch (CopixException $e) { return _arRedirect(_url('log|edit', array('profile' => $profile['name'], 'error' => 'invalidEMail'))); } } $profile['email'] = _request('email'); } CopixSession::set('admin|log|edit', $profile); if (_request('save')) { $profiles = CopixConfig::instance()->copixlog_getRegisteredProfiles(); $profiles[$profile['name']] = $profile; _class('LogConfigurationFile')->write($profiles); CopixSession::set('admin|log|edit', null); if (strtoupper($profile['strategy']) == "FIREBUG") { if (!CopixPluginRegistry::isRegistered("admin|firebug")) { //on récupère la liste des plugins enregistrés et on ajoute le nouveau plugin $arPlugins = CopixConfig::instance()->plugin_getRegistered(); $arPlugins[] = "admin|firebug"; //écriture du fichier _class('PluginsConfigurationFile')->write($arPlugins); } } return _arRedirect(_url('log|admin')); } else { return _arRedirect(_url('log|edit')); } }
/** * Compresse une variable à X caractères à partir de son nom d'origine et s'assure de l'unicité de son utilisation * @param string $pVariableName Le nom de la variable d'origine * @param int $pTryNum Le numéro d'essais de génération */ private function _compressVariable($pVariableName, $pTryNum = 0) { if (isset($this->_assigned_variables[$pVariableName])) { return $this->_assigned_variables[$pVariableName]; } $suffix = $pTryNum === 0 ? '' : $pTryNum; $pTryNum++; //Compression du nom de la variable, ajout du numéro d'essais $result = CopixFormatter::getReduced($pVariableName, 30 - strlen($suffix)); $result .= $suffix; //On vérifie que le nom trouvé ne corresponds pas déjà à une variable existante. if (in_array($result, $this->_assigned_variables)) { return $this->_compressVariable($pVariableName, $pTryNum); } return $this->_assigned_variables[$pVariableName] = $result; }
/** * Validation des modifications apportées sur un utilisateur */ public function processValid() { //$user = new stdClass (); $user = _record('dbuser'); $user->login_dbuser = _request('login_dbuser', ''); $user->email_dbuser = _request('email_dbuser'); $errors = array(); //on vérifie si le login n'est pas déja pris $sp = _daoSp(); $sp->addCondition('login_dbuser', '=', $user->login_dbuser); if ($user->login_dbuser === '') { $errors['loginEmpty'] = 1; } if (count(_ioDAO('dbuser')->findBy($sp))) { $errors['loginNotAvailable'] = 1; } //on vérifie si un mot de passe est donné qu'ils soient bien identiques if (CopixRequest::get('password_dbuser')) { if (CopixRequest::get('password_dbuser') != CopixRequest::get('password_confirmation_dbuser')) { $errors['passwordDoNotMatch'] = 1; } else { $user->password_dbuser = md5(CopixRequest::get('password_dbuser')); } } else { //Comme c'est automatiquement un nouvel utilisateur, il est obligatoire de saisir un nouveau mot de passe. $errors['passwordEmpty'] = 1; } if (Copixconfig::get('auth|typeConfirm') == "email") { if (!$user->email_dbuser) { $errors['emailEmpty'] = 1; } else { try { CopixFormatter::getMail($user->email_dbuser); } catch (CopixException $e) { $errors['emailIsBad'] = 1; } } } if (Copixconfig::get('auth|typeConfirm') == "email") { $user->enabled_dbuser = 0; } else { $user->enabled_dbuser = 1; } //Si le module imageprotect est activé test la protection anti-spam if (CopixModule::isEnabled('antispam')) { CopixRequest::assert('confirmcode_dbuser'); CopixRequest::assert('idcode_dbuser'); $code = _request('confirmcode_dbuser'); $idCode = _request('idcode_dbuser'); // Test si le code de ssession est valide _classInclude('antispam|imageprotect'); if (!ImageProtect::getCode($idCode, $code)) { $errors['confirmCodeBad'] = 1; } } //redirige vers l'éditeur si il y a des erreurs if (count($errors) != 0) { $errors['idForm'] = uniqid(); CopixSession::set('auth|createForm', $user, $errors['idForm']); return _arRedirect(_url('auth|usersregister|edit', $errors)); } //sauvegarde de l'utilisateur _ioDAO('dbuser')->insert($user); return _arRedirect(_url('')); }
/** * Affichage des infos sur copix. */ public function processDefault() { $ppo = new CopixPPO(); $ppo->TITLE_PAGE = _i18n('copix.titlepage'); $sections = array(); // infos de version $section = _i18n('copix.section.version'); $sections[$section]['COPIX_VERSION'] = COPIX_VERSION; $sections[$section]['COPIX_VERSION_MAJOR'] = COPIX_VERSION_MAJOR; $sections[$section]['COPIX_VERSION_MINOR'] = COPIX_VERSION_MINOR; $sections[$section]['COPIX_VERSION_FIX'] = COPIX_VERSION_FIX; $sections[$section]['COPIX_VERSION_RC'] = COPIX_VERSION_RC; $sections[$section]['COPIX_VERSION_BETA'] = COPIX_VERSION_BETA; $sections[$section]['COPIX_VERSION_DEV'] = COPIX_VERSION_DEV; // infos sur les répertoires $section = _i18n('copix.section.path'); $sections[$section]['COPIX_PATH'] = COPIX_PATH; $sections[$section]['COPIX_CORE_PATH'] = COPIX_CORE_PATH; $sections[$section]['COPIX_UTILS_PATH'] = COPIX_UTILS_PATH; $sections[$section]['COPIX_PROJECT_PATH'] = COPIX_PROJECT_PATH; $sections[$section]['COPIX_TEMP_PATH'] = COPIX_TEMP_PATH; $sections[$section]['COPIX_CACHE_PATH'] = COPIX_CACHE_PATH; $sections[$section]['COPIX_LOG_PATH'] = COPIX_LOG_PATH; $sections[$section]['COPIX_VAR_PATH'] = COPIX_VAR_PATH; $sections[$section]['COPIX_SMARTY_PATH'] = COPIX_SMARTY_PATH; $sections[$section]['COPIX_ACTIONGROUP_DIR'] = COPIX_ACTIONGROUP_DIR; $sections[$section]['COPIX_DESC_DIR'] = COPIX_DESC_DIR; $sections[$section]['COPIX_ZONES_DIR'] = COPIX_ZONES_DIR; $sections[$section]['COPIX_TEMPLATES_DIR'] = COPIX_TEMPLATES_DIR; $sections[$section]['COPIX_CLASSES_DIR'] = COPIX_CLASSES_DIR; $sections[$section]['COPIX_RESOURCES_DIR'] = COPIX_RESOURCES_DIR; $sections[$section]['COPIX_PLUGINS_DIR'] = COPIX_PLUGINS_DIR; $sections[$section]['COPIX_INSTALL_DIR'] = COPIX_INSTALL_DIR; $sections[$section]['arModulesPath'] = CopixConfig::instance()->arModulesPath; $sections[$section]['arPluginsPath'] = CopixConfig::instance()->arPluginsPath; // configuration générale $section = _i18n('copix.section.config'); switch (CopixConfig::instance()->getMode()) { case CopixConfig::DEVEL: $sections[$section]['mode'] = 'DEVEL'; break; case CopixConfig::PRODUCTION: $sections[$section]['mode'] = 'PRODUCTION'; break; case CopixConfig::FORCE_INITIALISATION: $sections[$section]['mode'] = 'FORCE_INITIALISATION'; break; default: $sections[$section]['mode'] = 'UNKNOW'; break; } $sections[$section]['checkTrustedModules'] = CopixFormatter::getBool(CopixConfig::instance()->checkTrustedModules); $sections[$section]['sessionName'] = CopixConfig::instance()->sessionName; $sections[$section]['apcEnabled'] = CopixFormatter::getBool(CopixConfig::instance()->apcEnabled); $sections[$section]['default_language'] = CopixConfig::instance()->default_language; $sections[$section]['default_country'] = CopixConfig::instance()->default_country; $sections[$section]['default_charset'] = CopixConfig::instance()->default_charset; $sections[$section]['i18n_path_enabled'] = CopixFormatter::getBool(CopixConfig::instance()->i18n_path_enabled); $sections[$section]['missingKeyTriggerErrorLevel'] = CopixConfig::instance()->missingKeyTriggerErrorLevel == E_USER_ERROR ? 'E_USER_ERROR' : CopixConfig::instance()->missingKeyTriggerErrorLevel; $sections[$section]['compile_check'] = CopixFormatter::getBool(CopixConfig::instance()->compile_check); $sections[$section]['force_compile'] = CopixFormatter::getBool(CopixConfig::instance()->force_compile); $sections[$section]['template_caching'] = CopixFormatter::getBool(CopixConfig::instance()->template_caching); $sections[$section]['template_use_sub_dirs'] = CopixFormatter::getBool(CopixConfig::instance()->template_use_sub_dirs); $sections[$section]['mainTemplate'] = CopixConfig::instance()->mainTemplate; $sections[$section]['invalidActionTriggersError'] = CopixFormatter::getBool(CopixConfig::instance()->invalidActionTriggersError); $sections[$section]['notFoundDefaultRedirectTo'] = CopixFormatter::getBool(CopixConfig::instance()->notFoundDefaultRedirectTo); $sections[$section]['overrideUnserializeCallbackEnabled'] = CopixFormatter::getBool(CopixConfig::instance()->overrideUnserializeCallbackEnabled); // configuration des url $section = _i18n('copix.section.configUrl'); $sections[$section]['significant_url_mode'] = CopixConfig::instance()->significant_url_mode; $sections[$section]['significant_url_prependIIS_path_key'] = CopixConfig::instance()->significant_url_prependIIS_path_key; $sections[$section]['stripslashes_prependIIS_path_key'] = CopixFormatter::getBool(CopixConfig::instance()->stripslashes_prependIIS_path_key); $sections[$section]['url_requestedscript_variable'] = CopixConfig::instance()->url_requestedscript_variable; // configuration des bases de données $section = _i18n('copix.section.configDb'); $sections[$section][_i18n('copix.configDb.givenDrivers')] = CopixDB::getAllDrivers(); $sections[$section][_i18n('copix.configDb.availableDrivers')] = CopixDB::getAvailableDrivers(); $sections[$section][_i18n('copix.configDb.profils')] = CopixConfig::instance()->copixdb_getProfiles(); $sections[$section][_i18n('copix.configDb.defaultProfil')] = CopixConfig::instance()->copixdb_getDefaultProfileName(); // profil de connexion utilisé actuellement $profile = CopixDb::getConnection()->getProfile(); $parts = $profile->getConnectionStringParts(); $section = _i18n('copix.section.dbProfile', array($profile->getName())); $sections[$section][_i18n('copix.dbProfile.connexionString')] = $profile->getConnectionString(); $sections[$section][_i18n('copix.dbProfile.driverName')] = $profile->getDriverName(); $sections[$section][_i18n('copix.dbProfile.databaseType')] = $profile->getDatabase(); $sections[$section][_i18n('copix.dbProfile.user')] = $profile->getUser(); $sections[$section][_i18n('copix.dbProfile.database')] = $parts['dbname']; $sections[$section][_i18n('copix.dbProfile.serverName')] = isset($parts['host']) ? $parts['host'] : 'localhost'; $sections[$section][_i18n('copix.dbProfile.options')] = $profile->getOptions(); $section = _i18n('copix.section.auth'); $sections[$section]['copixauth_cache'] = CopixFormatter::getBool(CopixConfig::instance()->copixauth_cache); $userHandlers = CopixConfig::instance()->copixauth_getRegisteredUserHandlers(); //echo '<pre><div align="left">'; foreach ($userHandlers as $key => $item) { $userHandlers[$key]['required'] = CopixFormatter::getBool($userHandlers[$key]['required']); } $sections[$section]['userHandlers'] = $userHandlers; $groupHandlers = CopixConfig::instance()->copixauth_getRegisteredGroupHandlers(); foreach ($groupHandlers as $key => $item) { $groupHandlers[$key]['required'] = CopixFormatter::getBool($groupHandlers[$key]['required']); } $sections[$section]['groupHandlers'] = $groupHandlers; $credentialHandlers = CopixConfig::instance()->copixauth_getRegisteredCredentialHandlers(); foreach ($credentialHandlers as $key => $item) { $credentialHandlers[$key]['stopOnSuccess'] = CopixFormatter::getBool($credentialHandlers[$key]['stopOnSuccess']); $credentialHandlers[$key]['stopOnFailure'] = CopixFormatter::getBool($credentialHandlers[$key]['stopOnFailure']); } $sections[$section]['credentialHandlers'] = $credentialHandlers; //$sections[$section][''] = ; $ppo->sections = $sections; return _arPPO($ppo, 'infos.tpl'); }
public function sendmail($mail) { $arrErrors = array(); if ($mail['dest'] == null || $mail['dest'] == "") { $arrErrors[] = _i18n('email.error.nodest'); } else { $arrTmp = explode(",", $mail['dest']); try { foreach ($arrTmp as $key => $tmpMail) { if ($tmpMail != "") { CopixFormatter::getMail($tmpMail); } } } catch (CopixException $e) { $arrErrors[] = _i18n('email.error.baddest'); } } if ($mail['cc'] != "") { $arrTmp = explode(",", $mail['cc']); try { foreach ($arrTmp as $key => $tmpMail) { if ($tmpMail != "") { CopixFormatter::getMail($tmpMail); } } } catch (CopixException $e) { $arrErrors[] = _i18n('email.error.badcc'); } } else { $mail['cc'] = ""; } if ($mail['cci'] != "") { $arrTmp = explode(",", $mail['cci']); try { foreach ($arrTmp as $key => $tmpMail) { if ($tmpMail != "") { CopixFormatter::getMail($tmpMail); } } } catch (CopixException $e) { $arrErrors[] = _i18n('email.error.badcci'); } } else { $mail['cci'] = ""; } if ($mail['subject'] == null || $mail['subject'] == "") { $arrErrors[] = _i18n('email.error.nosubject'); } if ($mail['msg'] == null || $mail['msg'] == "") { $arrErrors[] = _i18n('email.error.nomsg'); } if ($mail['from'] == null || $mail['from'] == "") { $arrErrors[] = _i18n('email.error.nofrom'); } else { $arrTmp = explode(",", $mail['from']); try { foreach ($arrTmp as $tmpMail) { if ($tmpMail != "") { CopixFormatter::getMail($tmpMail); } } } catch (CopixException $e) { $arrErrors[] = _i18n('email.error.badfrom'); } } if ($mail['fromname'] == null || $mail['fromname'] == "") { $arrErrors[] = _i18n('email.error.nofromname'); } if (count($arrErrors) == 0) { $monMail = new CopixTextEMail($mail['dest'], $mail['cc'], $mail['cci'], utf8_decode($mail['subject']), utf8_decode($mail['msg'])); $monMail->send($mail['from'], $mail['fromname']); CopixSession::set('admin|email|donnees', $this->newMail()); } return $arrErrors; }