function init() { parent::init(); $oContentField = new AnwContentFieldSettings_select(self::FIELD_LANG_DEFAULT); $asEnumValues = array(); $asLangs = AnwComponent::globalCfgLangs(); foreach ($asLangs as $sLang) { $sLangName = $sLang . " - " . Anwi18n::langName($sLang); $asEnumValues[$sLang] = $sLangName; } $oContentField->setEnumValues($asEnumValues); $this->addContentField($oContentField); $oContentField = new AnwContentFieldSettings_string(self::FIELD_LANGS); $oContentField->addAllowedPattern("!^.{" . Anwi18n::MINLEN_LANG . "," . Anwi18n::MAXLEN_LANG . "}\$!"); $oContentMultiplicity = new AnwContentMultiplicity_multiple(); $oContentField->setMultiplicity($oContentMultiplicity); $this->addContentField($oContentField); $oContentField = new AnwContentFieldSettings_select(self::FIELD_TIMEZONE_DEFAULT); $anEnumValues = array(); $anTimezones = AnwUsers::getTimezones(); foreach ($anTimezones as $nTimezone) { $sTimezoneName = Anwi18n::timezoneName($nTimezone); $anEnumValues[$nTimezone] = $sTimezoneName; } $oContentField->setEnumValues($anEnumValues); $this->addContentField($oContentField); }
protected function doPing($bAddInDirectory) { //here, url is passed in any case for verification purpose //but don't worry, it's stored on server side only when 'addindirectory' is true $sPingTarget = ANWIKI_WEBPING . 'newinstall?' . 'siteurl=' . urlencode(AnwComponent::globalCfgUrlRoot()) . '&sitelang=' . urlencode(AnwComponent::globalCfgLangDefault()) . '&lang=' . urlencode(AnwCurrentSession::getLang()) . '&addindirectory=' . ($bAddInDirectory ? '1' : '0') . '&versionid=' . urlencode(ANWIKI_VERSION_ID) . '&nocache=' . time(); $this->out .= $this->tpl()->doPing($sPingTarget, $this->linkMe() . '&pingdone=1'); }
private static function loadContentClasses() { $asEnabledContentClasses = AnwComponent::globalCfgModulesContentClasses(); foreach ($asEnabledContentClasses as $sContentClassName) { $sContentClassName = strtolower($sContentClassName); if (!self::isContentClassLoaded($sContentClassName)) { self::loadContentClass($sContentClassName); } } }
function run() { $sDirToDelete = $this->getActionInstall()->getMyComponentPathDefault(); $sLinkHome = AnwUtils::link(AnwComponent::globalCfgHomePage()); $sLinkEditConfig = AnwUtils::alink('editconfig'); $sWebsite = '<a href="' . ANWIKI_WEBSITE . '" target="_blank">' . ANWIKI_WEBSITE . '</a>'; $this->out .= $this->tpl()->showFinished($sDirToDelete, $sLinkHome, $sLinkEditConfig, $sWebsite); //lock install $asInstallInfo = array('install_timehuman' => date("Y-m-d H:i:s"), 'install_time' => time(), 'install_version_id' => ANWIKI_VERSION_ID, 'install_version_name' => ANWIKI_VERSION_NAME); AnwUtils::putFileSerializedObject(ANWIKI_INSTALL_LOCK, $asInstallInfo); }
function editConfigLayout($sLinkRefresh, $aaConfigurableComponents, $sHtmlContent) { $HTML = <<<EOF \t<div id="listconfigurables"> \t\t<div id="refreshcomponentslist"><a href="{$this->xQuote($sLinkRefresh)}">{$this->t_("refreshcomponents_redirect_link")}</a></div> \t\t \t\t<ul> EOF; foreach ($aaConfigurableComponents as $mComponentType => $asComponents) { $HTML .= <<<EOF \t\t<li><label>{$this->xText($mComponentType)}</label> \t\t\t<ul> EOF; $asComponentsEnabled = array(); $asComponentsDisabled = array(); foreach ($asComponents as $sComponent) { if (AnwComponent::isComponentEnabled($sComponent, $mComponentType)) { $asComponentsEnabled[] = $sComponent; } else { $asComponentsDisabled[] = $sComponent; } } foreach ($asComponentsEnabled as $sComponent) { $sLink = AnwUtils::aLink("editconfig", array("c" => $sComponent, "t" => $mComponentType)); $HTML .= <<<EOF \t\t\t<li class="active"><a href="{$this->xQuote($sLink)}">{$this->xText($sComponent)}</a></li> EOF; } foreach ($asComponentsDisabled as $sComponent) { $sLink = AnwUtils::aLink("editconfig", array("c" => $sComponent, "t" => $mComponentType)); $HTML .= <<<EOF \t\t\t<li class="inactive"><a href="{$this->xQuote($sLink)}">{$this->xText($sComponent)}</a></li> EOF; } $HTML .= <<<EOF \t\t\t</ul> EOF; } $HTML .= <<<EOF \t \t\t</ul> \t</div> \t<div id="editconfigurable"> \t\t{$sHtmlContent} \t</div> EOF; return $HTML; }
function run() { loadApp($this->getMyComponentPathDefault() . 'class_stepinstall.php'); //make sure it's not already installed if (file_exists(ANWIKI_INSTALL_LOCK)) { $sLinkHome = AnwUtils::link(AnwComponent::globalCfgHomePage()); $sLinkForce = AnwStepInstall::linkStep(AnwStepInstall::getStepDefault()); $this->out .= $this->tpl()->alreadyInstalled($sLinkHome, $sLinkForce, ANWIKI_INSTALL_LOCK, ANWIKI_INSTALL_STATUS); return; } //make sure writable dir is writable if (!file_exists(ANWIKI_INSTALL_STATUS)) { @touch(ANWIKI_INSTALL_STATUS); } if (!is_writable(ANWPATH_WRITABLE) || !is_writable(ANWIKI_INSTALL_STATUS)) { $this->out .= $this->tpl()->error($this->t_("err_notwritable_directory_explain", array('directory' => '<br/>' . ANWPATH_WRITABLE)), $this->t_("err_notwritable_t")); return; } //security define('ANWIKI_IN_INSTALL', true); //read next step $nCurrentStepStatus = self::getCurrentStepStatus(); self::debug("current step status: " . $nCurrentStepStatus); //find step to execute $nStepOrder = (int) AnwEnv::_GET("step", AnwEnv::_POST("step", $nCurrentStepStatus)); //do not go to next steps if previous steps were not completed if ($nStepOrder > $nCurrentStepStatus) { $nStepOrder = $nCurrentStepStatus; } //make sure step exists try { $sStepName = AnwStepInstall::getStepForOrder($nStepOrder); } catch (AnwException $e) { $nStepOrder = $nCurrentStepStatus; $sStepName = AnwStepInstall::getStepForOrder($nStepOrder); } //load the step $this->oStepInstall = AnwStepInstall::loadComponent($sStepName); AnwStepInstall::setActionInstall($this); $nCountSteps = count(AnwStepInstall::getAllSteps()); $sLinkPrevious = $this->oStepInstall->linkStepPrevious(); $sLinkNext = $this->oStepInstall->linkStepNext(); $sTitleStep = $this->oStepInstall->getStepTitle(); $this->out .= $this->tpl()->headerInstall($sTitleStep, $nStepOrder, $nCountSteps, $sLinkPrevious, $sLinkNext); //run the step $this->out .= $this->oStepInstall->runStepInstall(); $this->out .= $this->tpl()->footerInstall($sTitleStep, $nStepOrder, $nCountSteps, $sLinkPrevious, $sLinkNext); }
protected function initializeAdditional() { $sInitLog = ""; //----------------------------- // create default home page //----------------------------- $oContentClass = AnwContentClasses::getContentClass('page'); $sPageName = AnwComponent::globalCfgHomePage(); $sPageLang = AnwComponent::globalCfgLangDefault(); $sChangeComment = "Installation assistant"; $oContent = new AnwContentPage($oContentClass); $sHomeTitle = $this->t_("local_homepage_title", array(), $sPageLang); $sHomeHead = $this->tpl()->homePageHead($sPageLang); $sHomeBody = $this->tpl()->homePageBody($sPageLang, ANWIKI_WEBSITE); $oContent->setContentFieldValues(AnwIContentClassPageDefault_page::FIELD_TITLE, array($sHomeTitle)); $oContent->setContentFieldValues(AnwIContentClassPageDefault_page::FIELD_HEAD, array($sHomeHead)); $oContent->setContentFieldValues(AnwIContentClassPageDefault_page::FIELD_BODY, array($sHomeBody)); $oPage = AnwPage::createNewPage($oContentClass, $sPageName, $sPageLang, $sChangeComment, $oContent); $sInitLog .= $this->t_("initlog_pagecreated", array('pagename' => $sPageName)) . '<br/>'; //----------------------------- // create default menu //----------------------------- $oContentClass = AnwContentClasses::getContentClass('menu'); $sPageName = 'en/_include/menu'; //TODO $sPageLang = Anwi18n::langExists('en') ? 'en' : AnwComponent::globalCfgLangDefault(); //TODO $sChangeComment = "Installation assistant"; $oContent = new AnwContentPage($oContentClass); //menu title $sMenuTitle = $this->t_("local_menu_title", array(), $sPageLang); $oContent->setContentFieldValues(AnwIContentClassPageDefault_menu::FIELD_TITLE, array($sMenuTitle)); //items $oContentFieldItems = $oContentClass->getContentField(AnwIContentClassPageDefault_menu::FIELD_ITEMS); $oSubContentItem = new AnwContentPage($oContentFieldItems); //main link $oContentFieldMainLink = $oContentFieldItems->getContentField(AnwIContentFieldPage_menu_menuItem::FIELD_MAINLINK); $oSubContentMainLink = new AnwContentPage($oContentFieldMainLink); $sMainLinkTitle = $this->t_("local_menu_mainlink_title", array(), $sPageLang); $oSubContentMainLink->setContentFieldValues(AnwIPage_link::FIELD_TITLE, array($sMainLinkTitle)); $oSubContentMainLink->setContentFieldValues(AnwIPage_link::FIELD_URL, array(AnwComponent::globalCfgHomePage())); $oSubContentMainLink->setContentFieldValues(AnwIPage_link::FIELD_TARGET, array(AnwIPage_link::TARGET_SELF)); $oSubContentItem->setSubContents(AnwIContentFieldPage_menu_menuItem::FIELD_MAINLINK, array($oSubContentMainLink)); $oContent->setSubContents(AnwIContentClassPageDefault_menu::FIELD_ITEMS, array($oSubContentItem)); $oPage = AnwPage::createNewPage($oContentClass, $sPageName, $sPageLang, $sChangeComment, $oContent); $sInitLog .= $this->t_("initlog_pagecreated", array('pagename' => $sPageName)) . '<br/>'; return $sInitLog; }
/** * Clean output before caching and running. */ protected function clean($sContentHtmlAndPhp) { try { if (trim($sContentHtmlAndPhp) == "") { return $sContentHtmlAndPhp; } $sReturn = $sContentHtmlAndPhp; //strip out <fix> tags $sReturn = self::cleanFixTags($sReturn); $sReturn = $this->doBindLinksToPreferedLang($sReturn); $sReturn = AnwPlugins::vhook('output_clean', $sReturn, $this->oPage); //print nl2br(htmlentities($sReturn)).'<hr/>'; return $sReturn; } catch (AnwException $e) { self::debug("local_exec_dynamic_error: " . $e); return AnwComponent::g_("local_exec_dynamic_error"); } }
function init() { parent::init(); //lang policy $oContentField = new AnwContentFieldSettings_radio(self::FIELD_POLICY); $asEnumValues = array(self::POLICY_ALL_LANGS => $this->getComponent()->t_contentfieldsettings("policy_all_langs"), self::POLICY_SELECTED_LANGS => $this->getComponent()->t_contentfieldsettings("policy_selected_langs")); $oContentField->setEnumValues($asEnumValues); $oContentField->setDefaultValue(self::POLICY_ALL_LANGS); $this->addContentField($oContentField); //langs selection $oContentField = new AnwContentFieldSettings_checkboxGroup(self::FIELD_LANGS); $asLangs = AnwComponent::globalCfgLangs(); $asEnumValues = array(); foreach ($asLangs as $sLang) { $sLangName = $sLang . " - " . Anwi18n::langName($sLang); $asEnumValues[$sLang] = $sLangName; } $oContentField->setEnumValues($asEnumValues); $oMultiplicity = new AnwContentMultiplicity_multiple(); $oMultiplicity->setSortable(false); $oContentField->setMultiplicity($oMultiplicity); $this->addContentField($oContentField); }
static function getCachedActionsMapping() { $sCacheFile = self::filenameCachedActionsMapping(); if (!file_exists($sCacheFile)) { throw new AnwCacheNotFoundException(); } //mapping must be newer than enabled-plugins-settings try { if (filemtime($sCacheFile) < filemtime(AnwUtils::getFileOverride("global.cfg.php", AnwComponent::getGlobalComponentFullDir()))) { self::debug("cachedActionsMapping obsoleted by settings"); throw new AnwCacheNotFoundException(); } } catch (AnwFileNotFoundException $e) { } //no override config //mapping must be newer than each available action $asEnabledActions = AnwComponent::getAvailableComponents(AnwComponent::TYPE_ACTION); foreach ($asEnabledActions as $sEnabledAction) { $asActionsFilesLocations = array(); $sActionFile = 'action_' . $sEnabledAction . '.php'; $sActionDir = AnwAction::getComponentDir($sEnabledAction); list($sFileActionDefault, $null) = AnwUtils::getFileDefault($sActionFile, $sActionDir); $asActionsFilesLocations[] = $sFileActionDefault; try { $sFileActionOverride = AnwUtils::getFileOverride($sActionDir, $sActionDir); $asActionsFilesLocations[] = $sFileActionOverride; } catch (AnwFileNotFoundException $e) { } //no override config foreach ($asActionsFilesLocations as $sActionFileLocation) { if (file_exists($sActionFileLocation) && filemtime($sCacheFile) < filemtime($sActionFileLocation)) { self::debug("cachedActionsMapping obsoleted by action : " . $sEnabledAction); throw new AnwCacheNotFoundException(); } } } //load it from cache $oObject = (array) self::getCachedObject($sCacheFile); if (!is_array($oObject)) { self::debug("cachedActionsMapping invalid : " . $sCacheFile); throw new AnwCacheNotFoundException(); } else { self::debug("cachedActionsMapping found : " . $sCacheFile); } return $oObject; }
static function reportError($oException, $nErrorNumber = null) { if (AnwComponent::globalCfgReportFileEnabled() || AnwComponent::globalCfgReportMailEnabled()) { if (!$nErrorNumber) { $nErrorNumber = time(); } $sExceptionName = get_class($oException); $sExceptionMessage = $oException->getMessage(); self::log("=== exception " . $sExceptionName . " - logged as error #" . $nErrorNumber . " : " . $sExceptionMessage); self::endLog(); $sLoggedStr = "\n\n"; $sLoggedStr .= "********* BEGIN ERROR LOG #" . $nErrorNumber . "*********\n"; $sLoggedStr .= "Date : " . date("Y-m-d H:i:s") . "\n"; $sLoggedStr .= "Exception : " . $sExceptionName . "\n"; $sLoggedStr .= "Message : " . $sExceptionMessage . "\n"; $sLoggedStr .= "Stack trace below :\n"; $sLoggedStr .= " * File " . $oException->getFile() . ", line " . $oException->getLine() . "\n"; $asTrace = $oException->getTrace(); foreach ($asTrace as $sTrace) { $sLoggedStr .= ' * '; if (isset($sTrace['class'])) { $sLoggedStr .= $sTrace['class']; } if (isset($sTrace['type'])) { $sLoggedStr .= $sTrace['type']; } $sLoggedStr .= $sTrace['function']; //hide args for security reasons if (is_array(@$sTrace['args'])) { foreach ($sTrace['args'] as $i => $sArg) { $sTrace['args'][$i] = 'p' . ($i + 1); //$sTrace['args'][$i] = serialize($sArg); } $sLoggedStr .= '(' . implode($sTrace['args'], ", ") . ') - '; } $sLoggedStr .= 'File ' . @$sTrace['file'] . ', line ' . @$sTrace['line']; $sLoggedStr .= "\n"; } $sLoggedStr .= "Execution log below :\n\n"; $sLoggedStr .= implode("\n", self::$log) . "\n"; $sLoggedStr .= "********* END ERROR LOG #" . $nErrorNumber . " *********\n"; if (AnwComponent::globalCfgReportFileEnabled()) { try { AnwUtils::file_put_contents(ANWPATH_ERRORLOG, $sLoggedStr, LOCK_EX | FILE_APPEND); } catch (AnwException $e) { } } if (AnwComponent::globalCfgReportMailEnabled()) { $sSubject = AnwComponent::g_("err_mailreport_subject", array("errornumber" => $nErrorNumber)); $sBody = AnwComponent::g_("err_mailreport_body", array("website" => AnwComponent::globalCfgWebsiteName())); $sBody .= "\n\n" . $sLoggedStr; $asEmail = AnwComponent::globalCfgReportMailAddresses(); foreach ($asEmail as $sEmail) { AnwUtils::mail($sEmail, $sSubject, $sBody); } } return $nErrorNumber; } return false; }
protected function loadComponentToConfigure() { return AnwComponent::loadComponentGeneric('global', 'global'); }
/** * @throws AnwUnexpectedException */ static function loadDriver() { AnwDebug::startbench("Acls driver init"); self::$oDriver = AnwAclsDriver::loadComponent(AnwComponent::globalCfgDriverAcls()); AnwDebug::stopbench("Acls driver init"); }
protected function doTestContentFieldValueComposed($oSubContent) { $sUser = $oSubContent->getContentFieldValue(self::FIELD_USER); $sPassword = $oSubContent->getContentFieldValue(self::FIELD_PASSWORD); $sHost = $oSubContent->getContentFieldValue(self::FIELD_HOST); $sDatabase = $oSubContent->getContentFieldValue(self::FIELD_DATABASE); $sPrefix = $oSubContent->getContentFieldValue(self::FIELD_PREFIX); try { $oDbLinkTest = AnwMysql::getInstance($sUser, $sPassword, $sHost, $sDatabase, $sPrefix); } catch (AnwDbConnectException $e) { $sError = AnwComponent::g_editcontent("err_contentfield_mysqlconnexion_dbconnect", array("details" => $e->getMessage())); throw new AnwInvalidContentFieldValueException($sError); } //print "<br/>Test::user={$sUser}, pwd={$sPassword}, db={$sDatabase}, host={$sHost}, prefix={$sPrefix}<br/>"; }
/** * Conflicts checker/solver. * When $amSolvedValues is null, it will only check for dependancies problems and throw exceptions. * When $amSolvedValues is not null, it must be an array of misc values, at the same indexes than $aoComponents. * If a solution is found, $amSolvedValues will be reorganized in the correct order. */ private function doCheckOrSolveDependancies($aoComponents, $amSolvedValues = null, $nDepth = 0) { self::debug("solveDependancies() for " . $this->getSourceComponent()->getComponentName()); // search for source/target indices... $nSourceComponentIndice = null; $nTargetComponentIndice = null; foreach ($aoComponents as $i => $oComponent) { if ($nSourceComponentIndice === null && $this->sourceComponentMatches($oComponent)) { $nSourceComponentIndice = $i; } else { if ($nTargetComponentIndice === null && $this->targetComponentMatches($oComponent)) { $nTargetComponentIndice = $i; } } if ($nSourceComponentIndice !== null && $nTargetComponentIndice !== null) { break; } } if ($nSourceComponentIndice === null) { throw new AnwUnexpectedException("Source component not found"); //should never happend } // begin dependancies resolution if ($nTargetComponentIndice !== null) { //the conflicting component has been found... if ($this->mSolution == self::SOLUTION_NONE) { // there is no solution self::debug("conflict between " . $this->getSourceComponent()->getComponentName() . " and " . $this->getTargetComponentName() . " : no solution"); throw new AnwDependancyException(AnwComponent::g_editcontent("dependancy_conflict", array('component1' => $this->getSourceComponent()->getComponentName(), 'component2' => $this->getTargetComponentName()))); } else { // there is a solution, we will try to apply it... $bSolvedValuesWereChanged = false; if ($this->mSolution == self::SOLUTION_LOAD_BEFORE && $nSourceComponentIndice < $nTargetComponentIndice || $this->mSolution == self::SOLUTION_LOAD_AFTER && $nSourceComponentIndice > $nTargetComponentIndice) { // already solved self::debug("conflict between " . $this->getSourceComponent()->getComponentName() . " and " . $this->getTargetComponentName() . " : already solved"); } else { self::debug("conflict between " . $this->getSourceComponent()->getComponentName() . " and " . $this->getTargetComponentName() . " : solvable"); if ($amSolvedValues !== null) { // conflict can be solved by permuting the two components (must permute it in $aoComponents AND $amSolvedValues) list($aoComponents, $amSolvedValues) = AnwUtils::permuteMultipleArrays(array($aoComponents, $amSolvedValues), $nSourceComponentIndice, $nTargetComponentIndice); $bSolvedValuesWereChanged = true; } else { throw new AnwDependancyException(AnwComponent::g_editcontent("dependancy_conflict_unsolved", array('component1' => $this->getSourceComponent()->getComponentName(), 'component2' => $this->getTargetComponentName()))); } } if ($amSolvedValues !== null && $bSolvedValuesWereChanged) { // we have to check again the whole values, to be sure that we didn't break a dependancy while reorganizing $amSolvedValues $nDepth++; if ($nDepth > 3) { // we may be in an infinite dependancies problem... give up! self::debug("amSolvedValues have changed, but nDepth exceeded"); throw new AnwDependancyException(AnwComponent::g_editcontent("dependancy_conflict_exceed", array('component1' => $this->getSourceComponent()->getComponentName(), 'component2' => $this->getTargetComponentName()))); } else { self::debug("amSolvedValues have changed, checking again whole values"); $aoComponents = $this->doCheckOrSolveDependancies($aoComponents, $amSolvedValues, $nDepth); //recursive call } } } } else { //no dependancy problem self::debug("conflict between " . $this->getSourceComponent()->getComponentName() . " and " . $this->getTargetComponentName() . " : no dependancy problem"); } return $amSolvedValues; }
static function rebuildUser($nId, $sLogin, $sDisplayName, $sEmail, $sLang, $nTimezone) { $oUser = new AnwUserById($nId); if (!AnwUsers::isValidLogin($sLogin)) { throw new AnwBadLoginException(); } $oUser->sLogin = $sLogin; if (!AnwUsers::isValidDisplayName($sDisplayName)) { throw new AnwBadDisplayNameException(); } $oUser->sDisplayName = $sDisplayName; if (!AnwUsers::isValidEmail($sEmail)) { throw new AnwBadEmailException(); } $oUser->sEmail = $sEmail; if (!Anwi18n::isValidLang($sLang)) { $sLang = AnwComponent::globalCfgLangDefault(); } $oUser->sLang = $sLang; if (!AnwUsers::isValidTimezone($nTimezone)) { $nTimezone = AnwComponent::globalCfgTimezoneDefault(); } $oUser->nTimezone = $nTimezone; $oUser->bExists = true; $oUser->bInfoLoaded = true; return $oUser; }
static function unsetCookie($sName, $sPath = null, $sDomain = null) { //add a prefix to avoid conflicts between multiple anwiki instances running on same host $sName = self::getCookiesPrefix($sName) . $sName; $nExpires = time() - 86400; //unset if (!$sPath) { $sPath = AnwComponent::globalCfgCookiesPath(); } if (!$sDomain) { $sDomain = AnwComponent::globalCfgCookiesDomain(); } setcookie($sName, "", $nExpires, $sPath, $sDomain); if (isset($_COOKIE[$sName])) { unset($_COOKIE[$sName]); } self::debug("unsetCookie(" . $sName . ") [" . $sPath . " ; " . $sDomain . "]"); }
static function getLang() { return AnwComponent::globalCfgLangDefault(); }
/** * Special override system for translations. * Below there is an example applied to contentclass_menu. * C means that the string comes from the class (ex: "menuItem" comes from "AnwContentFieldPage_menuItem") * N means that the string comes from the name of the field (ex: "subitems" is the name of a field in "AnwContentFieldPage_menuItem") * Here is the order for looking to translations. * * contentfield_menu_items_subitems_link_title_label * C N N N N * * contentfield_menuItem_subitems_link_title_label * C N N N * * contentfield_menuSubItem_link_title_label * C N N * * contentfield_link_title_label * C N */ protected final function doGetFieldTranslation($sBasePrefix, $sTranslationName, $asParameters, $bFromComponent, $nMaxDeep = -1) { if ($nMaxDeep == -1) { //initialize maxDeep to highest possible value $nHighestDeep = 0; $oTest = $this; while ($oTest->getContainer() instanceof AnwStructuredContentField_composed) { $oTest = $oTest->getContainer(); $nHighestDeep++; } $nMaxDeep = $nHighestDeep; //try last level translation (special case) $sFullTranslationName = $this->baseTranslationName($sBasePrefix, $nMaxDeep, true) . $sTranslationName; //print "<br/>**Max=".$nMaxDeep.": ".$sFullTranslationName."***<br/>"; if ($bFromComponent) { $sTranslation = $this->t_structuredcontentfield($sFullTranslationName, $asParameters, false, ""); } else { $sTranslation = AnwComponent::g_editcontent($sFullTranslationName, $asParameters, false, ""); //instance call required as it's abstract } if ($sTranslation !== "") { return $sTranslation; } } $sFullTranslationName = $this->baseTranslationName($sBasePrefix, $nMaxDeep, false) . $sTranslationName; if ($bFromComponent) { $sTranslation = $this->t_structuredcontentfield($sFullTranslationName, $asParameters, false, ""); } else { $sTranslation = AnwComponent::g_editcontent($sFullTranslationName, $asParameters, false, ""); //instance call required as it's abstract } //print "<br/>**Max=".$nMaxDeep.": ".$sFullTranslationName."***<br/>"; if ($sTranslation === "") { $nMaxDeep--; if ($nMaxDeep >= 0) { $sTranslation = $this->doGetFieldTranslation($sBasePrefix, $sTranslationName, $asParameters, $bFromComponent, $nMaxDeep); } } return $sTranslation; }
function getAvailableLangs() { $asAvailableLangs = AnwComponent::globalCfgLangs(); $asPages = $this->getPages(); foreach ($asAvailableLangs as $i => $sLang) { if (isset($asPages[$sLang])) { unset($asAvailableLangs[$i]); } } return $asAvailableLangs; }
function getSettingsForInitialization() { $oMysqlSettings = $this->cfg(self::CFG_MYSQL); return AnwComponent::g_editcontent("contentfield_mysqlconnexion_collapsed", array('user' => $oMysqlSettings[AnwISettings_mysqlconnexion::FIELD_USER], 'host' => $oMysqlSettings[AnwISettings_mysqlconnexion::FIELD_HOST], 'database' => $oMysqlSettings[AnwISettings_mysqlconnexion::FIELD_DATABASE], 'prefix' => $oMysqlSettings[AnwISettings_mysqlconnexion::FIELD_PREFIX])); }
static function g_err_need_write_file($sFileName) { return AnwComponent::g_("err_need_write_file", array('filename' => $sFileName, 'processuser' => AnwEnv::getProcessUser(), 'processgroup' => AnwEnv::getProcessGroup())); }
static function putCachedPage($oPage, $sCacheKey) { $sCacheFile = self::cachedirPage($oPage) . self::relativefilenameCachedPage($sCacheKey); self::debug("putting cachedPage : " . $sCacheFile . " (" . $oPage->getName() . ")"); self::putCachedObject($sCacheFile, $oPage); //do symlinks for quick access $nPageGroupId = $oPage->getPageGroup()->getId(); $nPageId = $oPage->getId(); //target of symlink $sTargetDir = 'bygroup/' . $nPageGroupId . '/' . $nPageId . '/'; if (AnwComponent::globalCfgSymlinksRelative()) { $sTargetDir = '../' . $sTargetDir; } else { $sTargetDir = ANWPATH_CACHECONTENT . $sTargetDir; } $sSymlink = self::symlinkPageByName($oPage->getName()); self::cacheSymlink($sTargetDir, $sSymlink, ANWPATH_CACHECONTENT); $sSymlink = self::symlinkPageById($oPage->getId()); self::cacheSymlink($sTargetDir, $sSymlink, ANWPATH_CACHECONTENT); }
protected function loadComponentToConfigure() { return AnwComponent::loadComponentGeneric(AnwComponent::globalCfgDriverSessions(), 'sessionsdriver'); }
private static function loadCurrentSession() { AnwDebug::startbench("Current session load"); try { self::$oSession = AnwSessions::getCurrentSession(); //keepalive $nElapsedTimeSinceKeepalive = time() - self::getLastKeepAlive(); $nKeepAliveInterval = AnwComponent::globalCfgKeepaliveDelay(); AnwDebug::log('(AnwSessions) Time elapsed since last keepalive: ' . $nElapsedTimeSinceKeepalive . '/' . $nKeepAliveInterval . 's'); if ($nElapsedTimeSinceKeepalive > $nKeepAliveInterval) { AnwDebug::log('(AnwSessions) Running keepalive...'); $nTime = time(); self::resetLastKeepAlive(); //keepalive session AnwSessions::keepAlive(); //run hooks $oSessionUser = self::$oSession->getUser(); AnwPlugins::hook("session_keepalive_any", $oSessionUser); if (self::$oSession->isLoggedIn()) { AnwPlugins::hook("session_keepalive_loggedin", $oSessionUser); } else { AnwPlugins::hook("session_keepalive_loggedout", $oSessionUser); } } } catch (AnwUserNotFoundException $e) { //current user doesn't exist anymore self::$oSession = new AnwSession(); self::logout(); } AnwDebug::stopbench("Current session load"); }
static function getCachedComponentsMapping() { $sCacheFile = self::filenameCachedComponentsMapping(); if (!file_exists($sCacheFile)) { throw new AnwCacheNotFoundException(); } //mapping must be newer than override-global-settings if (filemtime($sCacheFile) < filemtime(AnwUtils::getFileOverride("global.cfg.php", AnwComponent::getGlobalComponentFullDir()))) { AnwDebug::log("cachedComponentsMapping obsoleted by settings"); throw new AnwCacheNotFoundException(); } //TODO: mapping should be expired by each modified available component? //load it from cache $oObject = (array) self::getCachedObject($sCacheFile); if (!is_array($oObject)) { AnwDebug::log("cachedComponentsMapping invalid : " . $sCacheFile); throw new AnwCacheNotFoundException(); } else { AnwDebug::log("cachedComponentsMapping found : " . $sCacheFile); } return $oObject; }
/** * @throws AnwUnexpectedException */ static function loadDriver() { AnwDebug::startbench("Storage driver init"); self::$oDriver = AnwStorageDriver::loadComponent(AnwComponent::globalCfgDriverStorage()); AnwDebug::stopbench("Storage driver init"); }
static function rebuildSession($oUser, $bResume, $sLang, $nTimezone, $sId, $nTimeStart, $nTimeSeen, $nTimeAuth = 0) { $oSession = new AnwSession(); $oSession->oUser = $oUser; $oSession->bResume = $bResume; if (!Anwi18n::isValidLang($sLang)) { $sLang = AnwComponent::globalCfgLangDefault(); } $oSession->sLang = $sLang; if ($oUser->exists()) { $oSession->bLoggedIn = true; } else { $oSession->bLoggedIn = false; } $oSession->sId = $sId; if (!AnwUsers::isValidTimezone($nTimezone)) { $nTimezone = AnwComponent::globalCfgTimezoneDefault(); } $oSession->nTimezone = $nTimezone; $oSession->nTimeStart = $nTimeStart; $oSession->nTimeSeen = $nTimeSeen; $oSession->nTimeAuth = $nTimeAuth; return $oSession; }
function getMultiplicityTip($oContentField) { $sTranslation = $oContentField->getFieldLabelPlural(); if ($this->nMin > 0 && $this->nMax < self::UNLIMITED) { if ($this->nMin == $this->nMax) { return AnwComponent::g_editcontent("contentmultiplicity_multiple_tip_fixed", array("count" => $this->nMin, "contentfield" => $sTranslation)); } return AnwComponent::g_editcontent("contentmultiplicity_multiple_tip_between", array("mincount" => $this->nMin, "maxcount" => $this->nMax, "contentfield" => $sTranslation)); } if ($this->nMin > 0) { return AnwComponent::g_editcontent("contentmultiplicity_multiple_tip_greater", array("mincount" => $this->nMin, "contentfield" => $sTranslation)); } if ($this->nMax < self::UNLIMITED) { return AnwComponent::g_editcontent("contentmultiplicity_multiple_tip_lower", array("maxcount" => $this->nMax, "contentfield" => $sTranslation)); } return AnwComponent::g_editcontent("contentmultiplicity_multiple_tip_any", array("contentfield" => $sTranslation)); }
static function isResumeEnabled() { return AnwComponent::globalCfgSessionResumeEnabled() && self::getDriver() instanceof AnwSessionsCapability_resume; }