Example #1
0
 static function t_($id, $params, $sPrefix, $sLang = false, $sValueIfNotFound = false)
 {
     if ($sLang == false) {
         if (self::isLocalTranslation($id)) {
             $sLang = AnwAction::getActionLang();
         } else {
             $sLang = AnwCurrentSession::getLang();
         }
     }
     $translation = "";
     if (!isset(self::$translations[$sLang][$sPrefix][$id])) {
         //translation is not yet loaded, search in queued translations files
         AnwDebug::log("(Anwi18n) looking for: '" . $id . "' (" . $sLang . ")");
         if (count(@self::$asQueuedTranslationNames[$sPrefix]) > 0) {
             //we have unloaded translations, load it now
             foreach (self::$asQueuedTranslationNames[$sPrefix] as $sTranslationName => $null) {
                 unset(self::$asQueuedTranslationNames[$sPrefix][$sTranslationName]);
                 //avoid recursive loops
                 self::loadTranslationsFromLang($sTranslationName, $sLang);
             }
         }
     }
     if (!isset(self::$translations[$sLang][$sPrefix][$id])) {
         if (count(@self::$aaLoadedTranslationNames[$sPrefix]) > 0) {
             //make sure we loaded corresponding translation files in the requested language
             foreach (self::$aaLoadedTranslationNames[$sPrefix] as $sTranslationName => $null) {
                 if (!isset(self::$aaLoadedTranslationNames[$sPrefix][$sTranslationName][$sLang])) {
                     self::loadTranslationsFromLang($sTranslationName, $sLang);
                 }
             }
         }
     }
     if (isset(self::$translations[$sLang][$sPrefix][$id])) {
         //translation is already loaded
         $translation = self::$translations[$sLang][$sPrefix][$id];
         //parse parameters: parameters names start with % and end with %
         foreach ($params as $find => $replace) {
             $find = '%' . $find . '%';
             $translation = str_replace($find, $replace, $translation);
         }
     } else {
         if ($sLang != self::LANG_DEFAULT) {
             //try in default language
             return self::t_($id, $params, $sPrefix, self::LANG_DEFAULT, $sValueIfNotFound);
         }
         $translation = $sValueIfNotFound === false ? '#' . $id . '#' : $sValueIfNotFound;
         AnwDebug::log("! Missing translation : {$id}");
         //print $sPrefix.'!'.$id.'!';print_r(self::$translations);exit;
     }
     return $translation;
 }
Example #2
0
 static function isActionGlobalAllowed($oUser, $sAction)
 {
     if (AnwAction::isAdminAction($sAction)) {
         $bReturn = self::isAdminAllowed($oUser);
     } else {
         if (AnwAction::isPublicAction($sAction)) {
             $bReturn = true;
         } else {
             if (AnwAction::isMagicAclAction($sAction)) {
                 return false;
                 //we should never go here, this test is just in case of...
             }
             $bReturn = self::getDriver()->isActionGlobalAllowed($oUser, $sAction) || self::isAdminAllowed($oUser);
             //admins have full rights everywhere
         }
     }
     return $bReturn;
 }
 function __construct($sName, $mComponentType)
 {
     parent::__construct($sName);
     // set component type
     $this->mComponentType = $mComponentType;
     // retrieve available components list
     $asComponents = AnwPlugin::getAvailableComponents($mComponentType);
     $asEnumValues = array();
     // special case for actions
     if ($mComponentType == AnwComponent::TYPE_ACTION) {
         foreach ($asComponents as $sAction) {
             if (!AnwAction::isAlwaysEnabledAction($sAction)) {
                 $asEnumValues[$sAction] = $sAction;
             }
         }
     } else {
         $asEnumValues = $asComponents;
     }
     $this->setEnumValuesFromList($asEnumValues);
 }
 function init()
 {
     parent::init();
     //actions page policy
     $oContentField = new AnwContentFieldSettings_radio(self::FIELD_POLICY);
     $asEnumValues = array(self::POLICY_ALL_ACTIONS => $this->getComponent()->t_contentfieldsettings("policy_all_actionspage"), self::POLICY_SELECTED_ACTIONS => $this->getComponent()->t_contentfieldsettings("policy_selected_actionspage"));
     $oContentField->setEnumValues($asEnumValues);
     $oContentField->setDefaultValue(self::POLICY_SELECTED_ACTIONS);
     $this->addContentField($oContentField);
     //actions page selection
     $oContentField = new AnwContentFieldSettings_checkboxGroup(self::FIELD_ACTIONS);
     $asActions = AnwComponent::getEnabledComponents(AnwComponent::TYPE_ACTION);
     $asEnumValues = array();
     foreach ($asActions as $sAction) {
         if (AnwAction::isActionPage($sAction) && !AnwAction::isMagicAclAction($sAction)) {
             $asEnumValues[$sAction] = $sAction;
         }
     }
     $oContentField->setEnumValues($asEnumValues);
     $oMultiplicity = new AnwContentMultiplicity_multiple();
     $oMultiplicity->setSortable(false);
     $oContentField->setMultiplicity($oMultiplicity);
     $this->addContentField($oContentField);
 }
Example #5
0
 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;
 }
Example #6
0
        define('ANWIKI_MODE_MINIMAL', true);
    }
    require_once "engine.inc.php";
    //install redirect
    if (!file_exists(ANWIKI_INSTALL_LOCK) && AnwEnv::_GET('a') != 'install') {
        $sUrlInstall = AnwEnv::_SERVER('SCRIPT_URI') . '?a=install';
        header("Location: " . $sUrlInstall);
        print '<a href="' . AnwUtils::xQuote($sUrlInstall) . '">' . AnwUtils::xQuote($sUrlInstall) . '</a>';
        exit;
    }
    AnwDebug::startbench("preparing action", true);
    //load action code
    try {
        $sAction = strtolower(AnwEnv::_GET(AnwAction::GET_ACTIONNAME, "view"));
        $oAction = AnwAction::loadComponent($sAction);
    } catch (AnwException $e) {
        $sAction = "view";
        $oAction = AnwAction::loadComponent($sAction);
    }
    //security check
    if (ANWIKI_MODE_MINIMAL && !$oAction instanceof AnwActionMinimal) {
        AnwDieCriticalError("Unauthorized mode / bad URL");
    }
    $oAction->setAsCurrentAction();
    AnwDebug::log("Action : " . $sAction);
    AnwDebug::stopbench("preparing action");
    //run
    $oAction->runAndOutput();
} catch (AnwException $e) {
    errorApp($e);
}
Example #7
0
 static function getComponentsRootDir()
 {
     return AnwAction::getComponentDir('install');
 }
Example #8
0
    function renderEditHtmlForm($bFromPost, $sFormUrl = "", $sSuffix = "", $oContentOriginal = null)
    {
        $sHtmlEditForm = "";
        //special process for the first call
        if ($oContentOriginal == null) {
            $oContentOriginal = $this;
            $oContentOriginal->bHtmlEditFormHasErroneousFields = false;
            $oContentOriginal->bHtmlEditFormHasPhpCode = false;
            $oContentOriginal->bHtmlEditFormHasJsCode = false;
            $oContentOriginal->nHtmlEditFormCountErroneousChild = 0;
            $sFormUrl = str_replace('&amp;', '&', $sFormUrl);
            AnwAction::headJs('var g_editcontentform_url="' . AnwUtils::escapeQuote($sFormUrl) . '";');
            AnwAction::headEditContent();
            //render tabs if any
            $aoFieldsTabs = $this->getContentFieldsTabs();
            if (count($aoFieldsTabs) > 0) {
                $sHtmlTabs = "";
                foreach ($aoFieldsTabs as $oFieldTab) {
                    $sHtmlTabs .= $oFieldTab->renderEditTab($sSuffix);
                }
                $sHtmlEditForm .= <<<EOF

<div class="contentfield_tabs">
\t{$sHtmlTabs}
\t<div class="break;"></div>
</div>
EOF;
            }
        }
        $aoContentFields = $this->getContentFieldsContainer()->getContentFields();
        foreach ($aoContentFields as $oContentField) {
            $nPreviousCountErroneousChild = $oContentOriginal->nHtmlEditFormCountErroneousChild;
            $sFieldName = $oContentField->getName();
            $asValuesForRender = array();
            $asFieldValues = array();
            $aoSubContents = array();
            $bHasOverridingValues = null;
            //do not load from post when contentfield is hidden
            if ($bFromPost && !$oContentField->isDisplayed()) {
                $bReallyFromPost = false;
            } else {
                $bReallyFromPost = $bFromPost;
            }
            /*****************************************************************************
             * CONTENTFIELD CONTAINER : recursively get value from it's subcontentfields
             *****************************************************************************/
            if ($oContentField instanceof AnwStructuredContentField_composed) {
                if (!$bReallyFromPost) {
                    // shared code for multiplicity single or multiple
                    try {
                        $aoSubContents = $this->getSubContents($sFieldName);
                    } catch (AnwUnexpectedException $e) {
                        //contentfield_container don't exist already. create it.
                        $aoSubContents = array($this->newContent($oContentField));
                    }
                } else {
                    $aoSubContents = array();
                    if ($oContentField->isMultiple()) {
                        //create as many empty subcontents as instances edited from post
                        $asFieldsIdsFromPost = AnwEnv::_POST($oContentField->getInputName($sSuffix), array());
                        foreach ($asFieldsIdsFromPost as $sFieldIdFromPost) {
                            $aoSubContents[$sFieldIdFromPost] = $this->newContent($oContentField);
                        }
                    } else {
                        //only 1 empty instance
                        $aoSubContents[] = $this->newContent($oContentField);
                    }
                }
                foreach ($aoSubContents as $sIndice => $oSubContent) {
                    //update suffix
                    if (!$bReallyFromPost) {
                        $sSuffixId = AnwUtils::genUniqueIdNumeric();
                    } else {
                        $sSuffixId = $sIndice;
                    }
                    $sNewSuffix = $oContentField->updateSuffix($sSuffix, $sSuffixId);
                    $sSubRender = $oSubContent->renderEditHtmlForm($bReallyFromPost, $sFormUrl, $sNewSuffix, $oContentOriginal);
                    //recursive call
                    //$asValuesForRender[$sSuffixId] = $sSubRender;
                    $asValuesForRender[$sSuffixId] = array(self::IDX_SUBCONTENT => $oSubContent, self::IDX_RENDERED => $sSubRender);
                    if ($oContentField->isCollapsed() || $oContentField->isCollapsedChild()) {
                        $bWasCollapsingEnabled = AnwStructuredContentField::getDoCollapsing();
                        AnwStructuredContentField::setDoCollapsing(false);
                        $sSubRenderUncollapsed = $oSubContent->renderEditHtmlForm($bReallyFromPost, $sFormUrl, $sNewSuffix, $oContentOriginal);
                        //recursive call
                        $asValuesForRender[$sSuffixId]['UNCOLLAPSED'] = $sSubRenderUncollapsed;
                        AnwStructuredContentField::setDoCollapsing($bWasCollapsingEnabled);
                    }
                    //only after calling render on subContent!
                    //$asFieldValues[] = $oSubContent->toXmlString();
                }
                $bHasOverridingValues = self::hasOverridingValues($oContentField, $aoSubContents);
                if ($oContentField->isMultiple()) {
                    if (!$oContentField->hasDefaultSubContents()) {
                        $bHasOverridingValues = false;
                        //special case
                    }
                } else {
                    if (!$oContentField->hasSetDefaultValues()) {
                        $bHasOverridingValues = false;
                        //special case
                    }
                }
            } else {
                if (!$bReallyFromPost) {
                    $asFieldValues = $this->getContentFieldValues($sFieldName);
                } else {
                    $asFieldValues = $oContentField->getValuesFromPost($sSuffix);
                }
                $asValuesForRender = $asFieldValues;
                $bHasOverridingValues = self::hasOverridingValues($oContentField, $asFieldValues);
                if (!$oContentField->hasSetDefaultValues()) {
                    $bHasOverridingValues = false;
                    //special case
                }
            }
            $sFieldError = false;
            // - run the test for any _atomic field.
            // - only run the test for _composed fields which dont't have erroneous childs (important for security reasons, to not trigger test() procedure of these composed fields on unsafe values)
            if ($oContentOriginal->nHtmlEditFormCountErroneousChild == $nPreviousCountErroneousChild) {
                //test values and multiplicity (even for composed fields)
                try {
                    if ($oContentField instanceof AnwStructuredContentField_atomic) {
                        $oContentField->testContentFieldValues($asFieldValues, $this);
                    } else {
                        $oContentField->testContentFieldValues($aoSubContents, $this);
                    }
                } catch (AnwException $e) {
                    //here we can get errors from php edition
                    //display error
                    $sInputName = $oContentField->getInputName($sSuffix);
                    $sFieldError = str_replace('#CONTENTFIELDINPUTID#', $sInputName, $e->getMessage());
                    $oContentOriginal->bHtmlEditFormHasErroneousFields = true;
                    $oContentOriginal->nHtmlEditFormCountErroneousChild++;
                    //quick hack to solve the following problem:
                    //if user enters invalid XML code, in a contentfield such as _xml
                    //the system would fail on setContentFieldValues() or later,
                    //when trying to load invalid XML from the content.
                    //
                    //so we replace erroneous values by a valid-xml string.
                    //these erroneous values should never be read later :
                    // - test for this contentfield was done before
                    // - render is done on $asValuesForRender, so that user views erroneous in edit inputs
                    // - if this contentfield is child of a container, the container won't do the test as it contains already erroneous values
                    if ($e instanceof AnwInvalidContentFieldValueException && $oContentField instanceof AnwStructuredContentField_atomic) {
                        $sErroneousValue = '#ERRONEOUSVALUE#';
                        foreach ($asFieldValues as $nValueIndice => $null) {
                            $asFieldValues[$nValueIndice] = $sErroneousValue;
                        }
                    }
                }
                /*
                				catch(AnwException $e){
                					//should never go here
                					print 'ERROR 62';
                					print_r($e); exit;
                				}*/
            }
            /*else
            		{
            			$sFieldError = "(test skipped)";
            		}*/
            //render it now
            if ($oContentField->isDisplayed()) {
                $sHtmlEditForm .= $oContentField->renderEditInputs($asValuesForRender, $sSuffix, $bHasOverridingValues, $sFieldError);
            }
            if ($bReallyFromPost) {
                //update content for preview/save
                if ($oContentField instanceof AnwStructuredContentField_atomic) {
                    $this->setContentFieldValues($sFieldName, $asFieldValues);
                } else {
                    $this->setSubContents($sFieldName, $aoSubContents);
                }
            }
            if ($oContentField instanceof AnwStructuredContentField_atomic) {
                //check acls - are these checks still needed, as test was integrated in class_contentfield?
                foreach ($asFieldValues as $mContentFieldValue) {
                    //check PHP permission
                    $bHasPhpCode = AnwUtils::contentHasPhpCode($mContentFieldValue);
                    if ($bHasPhpCode) {
                        $oContentOriginal->bHtmlEditFormHasPhpCode = true;
                        AnwCurrentSession::getUser()->checkPhpEditionAllowed();
                    }
                    //check JS permission
                    $bHasJsCode = AnwUtils::contentHasJsCode($mContentFieldValue);
                    if ($bHasJsCode) {
                        $oContentOriginal->bHtmlEditFormHasJsCode = true;
                        AnwCurrentSession::getUser()->checkJsEditionAllowed();
                    }
                }
            }
        }
        return $sHtmlEditForm;
    }
Example #9
0
 protected function showCurrentPage()
 {
     //prepare content for display
     try {
         $oOutputHtml = $this->getoPage()->toHtml();
     } catch (AnwException $e) {
         $oOutputHtml = new AnwOutputHtml($this->getoPage());
         $oOutputHtml->setBody(self::g_("err_rendercontent"), false);
         AnwDebug::reportError($e);
     }
     $this->head($oOutputHtml->runHead());
     $this->title = $oOutputHtml->runTitle();
     $sBody = $oOutputHtml->runBody();
     //if the translation is not complete, display a notice
     if (!$this->getoPage()->isTranslated() && $this->getoPage()->isActionAllowed('translate')) {
         $sNotice = $this->t_("local_notice_incomplete", array("lnkopen" => '<a href="' . AnwUtils::link($this->getoPage(), "translate") . '">', "lnkclose" => '</a>'));
         $this->out .= $this->tpl()->drawNotice($sNotice);
     }
     //page translations
     $aoTranslations = array();
     $aoPages = $this->getoPage()->getPageGroup()->getPages();
     foreach ($aoPages as $oPage) {
         if ($oPage->isActionAllowed('view')) {
             $bCurrent = $oPage->getName() == $this->getoPage()->getName();
             $bTranslatedPercentEnough = $oPage->getTranslatedPercent() >= self::globalCfgViewUntranslatedMinpercent() ? true : false;
             $aoTranslations[] = array('current' => $bCurrent, 'page' => $oPage, 'online' => $bTranslatedPercentEnough);
         }
     }
     //display page content
     $this->out .= $this->tpl()->viewPage(self::g_("local_html_dir", array(), AnwAction::getActionLang()), AnwUtils::cssViewContent($this->getoPage()), $this->title, $sBody, str_replace(',', ' ', Anwi18n::dateTime($this->getoPage()->getTime(), AnwAction::getActionLang())), $aoTranslations);
 }
Example #10
0
 /**
  * Overloaded function to display a toolbar with page actions.
  */
 public function output($bEmergencyError = false)
 {
     if (!$bEmergencyError) {
         if ($this->pageExists()) {
             //action links
             $aoAllowedActions = self::getPageNavEntriesAllowed($this->getoPage());
             $nCountAllowedActions = count($aoAllowedActions);
             if ($nCountAllowedActions > 1 || $nCountAllowedActions == 1 && $aoAllowedActions[0]->getActionName() != 'view') {
                 $this->out = $this->tpl()->pageNav($aoAllowedActions) . $this->out;
             }
         }
         $this->headJs('var g_pagename="' . str_replace('&amp;', '&', AnwUtils::escapeQuote($this->getoPage()->getName())) . '";');
         $this->headJs('var g_actionpageurl="' . str_replace('&amp;', '&', AnwUtils::escapeQuote(AnwUtils::link($this->getoPage(), $this->getName()))) . '";');
     }
     parent::output($bEmergencyError);
 }
Example #11
0
    function showCaptcha()
    {
        $sActionName = AnwAction::getCurrentActionName();
        $asParams = array(AnwAction::GET_CAPTCHA => 1, "t" => time());
        $sActionUrl = AnwUtils::alink($sActionName, $asParams);
        $HTML = <<<EOF

{$this->g_('captcha_copy', array('code' => '<img src="' . $sActionUrl . '" alt=""/>', 'input' => '<input type="text" name="captcha" value="" class="intext captcha" maxlength="4"/>'))}
EOF;
        return $HTML;
    }
 protected function getGrantAllUsersByDefaultActions()
 {
     $asGrantActionGlobal = array();
     $asGrantActionPage = array();
     $aoGrantAllUsersByDefaultActions = AnwAction::getGrantAllUsersByDefaultActions();
     foreach ($aoGrantAllUsersByDefaultActions as $sAction) {
         if (AnwAction::isActionPage($sAction)) {
             $asGrantActionPage[] = $sAction;
         } else {
             $asGrantActionGlobal[] = $sAction;
         }
     }
     return array($asGrantActionGlobal, $asGrantActionPage);
 }
Example #13
0
 function genTranslateForm_onContentFieldValue($oContentField, $oXmlValue, $sInputName)
 {
     $nTranslatableFields = 0;
     //$this->generateTranslatableFields($oNodeRoot, $sFieldName, &$sTranslatableContent, &$nTranslatableFields);
     $fOnTextValue = "genTranslatableField_onTextValue";
     $fBeforeChilds = "genTranslatableField_beforeChilds";
     $fAfterChilds = "genTranslatableField_afterChilds";
     $fOnUntranslatableNode = "genTranslatableField_onUntranslatableNode";
     //&$sTranslatableContent, &$nTranslatableFields
     $this->genTranslatableField_html = "";
     AnwUtils::runCallbacksOnTranslatableValue($this, $oXmlValue, $sInputName, $fOnTextValue, $fBeforeChilds, $fAfterChilds, $fOnUntranslatableNode);
     //print htmlentities($sTranslatableContent);
     //only edit ContentFields which have translatable content
     if ($this->genTranslatableField_html != "") {
         $this->genTranslatableField_html = $this->simplifyHtmlForTranslation($this->genTranslatableField_html);
         $sContentHtmlDir = self::g_("local_html_dir", array(), AnwAction::getActionLang());
         $this->genTranslateForm_html .= $this->tpl()->translateContentField($sContentHtmlDir, $oContentField->getFieldLabel(), $this->genTranslatableField_html);
     }
 }
Example #14
0
 /**
  * Appropriated link base (absolute or relative, HTTP or HTTPS).
  */
 private static function doLinkBase($bUseSecureUrl, $bUseAbsoluteUrl)
 {
     // when we are in HTTPS, we want to stay in this mode...
     if (AnwComponent::globalCfgHttpsEnabled() && ($bUseSecureUrl || AnwAction::isActionSecure($sAction) || AnwEnv::isHttps())) {
         if (!AnwEnv::isHttps() || $bUseAbsoluteUrl) {
             // we switch to HTTPS (or force absolute url)
             $sLink = AnwComponent::globalCfgHttpsUrl();
         } else {
             // we are already in HTTPS (and we want to stay in this mode - even if action doesn't require it)
             $sLink = self::linkRelative();
         }
     } else {
         if ($bUseAbsoluteUrl) {
             // we force absolute url
             $sLink = AnwComponent::globalCfgUrlRoot();
         } else {
             // we are already in HTTP
             $sLink = self::linkRelative();
         }
     }
     return $sLink;
 }