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;
 }
 private function saveTranslations($sAddLang)
 {
     try {
         if (!Anwi18n::langExists($sAddLang)) {
             throw new AnwBadLangException();
         }
         $this->out .= $this->tpl()->startProcess();
         $bSomethingDone = false;
         $aoPageGroups = AnwStorage::getPageGroups(false, null, null);
         AnwStorage::transactionStart();
         try {
             foreach ($aoPageGroups as $oPageGroup) {
                 $aoPages = $oPageGroup->getPages();
                 $bChecked = AnwEnv::_POST($this->getChkName($oPageGroup));
                 if (!isset($aoPages[$sAddLang]) && $bChecked) {
                     $sTranslationName = AnwEnv::_POST($this->getInputName($oPageGroup));
                     //check permissions : translate
                     if (!AnwCurrentSession::isActionAllowed($sTranslationName, 'translate', $sAddLang)) {
                         throw new AnwAclException("permission translate denied");
                     }
                     //find PageRef
                     $nPageRefId = (int) AnwEnv::_POST($this->getInputRef($oPageGroup));
                     $oPageRef = new AnwPageById($nPageRefId);
                     if (isset($aoPages[$oPageRef->getLang()]) && $oPageRef->getId() == $aoPages[$oPageRef->getLang()]->getId()) {
                         //create translation
                         $oPageTranslation = $oPageRef->createNewTranslation($sTranslationName, $sAddLang);
                         $this->out .= $this->tpl()->newTranslationCreated($sAddLang, $oPageTranslation->link());
                         $bSomethingDone = true;
                     }
                 }
             }
             AnwStorage::transactionCommit();
         } catch (AnwException $e) {
             AnwStorage::transactionRollback();
             throw $e;
         }
         $sUrlContinue = $this->linkMe(array("addlang" => $sAddLang));
         if (!$bSomethingDone) {
             AnwUtils::redirect($sUrlContinue);
         }
         $this->out .= $this->tpl()->endProcess($sUrlContinue);
     } catch (AnwBadPageNameException $e) {
         $this->showForm($sAddLang, $this->g_("err_badpagename"));
     } catch (AnwBadLangException $e) {
         $this->showForm($sAddLang, $this->g_("err_badlang"));
     } catch (AnwPageAlreadyExistsException $e) {
         $this->showForm($sAddLang, $this->g_("err_pagealreadyexists"));
     } catch (AnwAclException $e) {
         $this->showForm($sAddLang, $this->g_("err_nopermission"));
     } catch (AnwLangExistsForPageGroupException $e) {
         $this->showForm($sAddLang, $this->g_("err_langexistsforpagegroup"));
     }
 }
Exemple #3
0
 private function importSelectionForm($sUploadedFile, $sImportPrefix)
 {
     //load XML from file
     $aaData = $this->getDataFromXmlFile(self::tmpFilename($sUploadedFile));
     $sExportTime = Anwi18n::dateTime($aaData['TIME']);
     $sExportFrom = $aaData['FROM'];
     $sExportVersionName = $aaData['VERSION_NAME'];
     $nExportVersionId = $aaData['VERSION_ID'];
     //select pages to import
     $this->out .= $this->tpl()->beginSelection($this->linkMe(), $sUploadedFile, self::IN_FILENAME, self::IN_CONTINUE_ON_ERRORS, $sExportTime, $sExportFrom, $sExportVersionName);
     foreach ($aaData['PAGEGROUPS'] as $aaDataGroup) {
         $this->out .= $this->tpl()->rowGroupOpen($sExportTime, $sExportFrom);
         foreach ($aaDataGroup['PAGES'] as $aaDataPage) {
             $asNotices = array();
             $bImportDisabled = false;
             $sOriginalPageName = $aaDataPage['NAME'];
             $sPageName = $sImportPrefix . $sOriginalPageName;
             //prefix
             $sPageLang = $aaDataPage['LANG'];
             $nPageTime = $aaDataPage['TIME'];
             $sPageContent = $aaDataPage['CONTENT'];
             try {
                 //check pagename and content
                 $asNotices = $this->checkPermissions($sPageName, $sPageLang, $sPageContent);
                 foreach ($asNotices as $sNotice) {
                     //don't disable import checkbox for pages already existing, as user may change the destination name
                     if ($sNotice != $this->t_("notice_exists")) {
                         $bImportDisabled = true;
                     }
                 }
             } catch (AnwInvalidContentException $e) {
                 $asNotices[] = $this->t_("notice_content");
                 $bImportDisabled = true;
             } catch (AnwException $e) {
                 $asNotices[] = $this->t_("notice_unknown");
                 $bImportDisabled = true;
             }
             //check lang
             if (!Anwi18n::langExists($sPageLang)) {
                 $asNotices[] = $this->t_("notice_lang");
                 $bImportDisabled = true;
             }
             $sInputPageName = $this->getInputPageName($sOriginalPageName);
             $sInputPageLang = $this->getInputPageLang($sOriginalPageName);
             $this->out .= $this->tpl()->rowTranslation(self::IN_PAGENAMES, $sInputPageName, $sInputPageLang, $sOriginalPageName, $sPageName, $sPageLang, $nPageTime, $bImportDisabled, $asNotices);
         }
         $this->out .= $this->tpl()->rowGroupClose();
     }
     $this->out .= $this->tpl()->endSelection();
 }
Exemple #4
0
 private function cbk_anwloop($asMatches)
 {
     $sLoopParams = $asMatches[1];
     $sLoopContent = $asMatches[2];
     self::debug("Starting loop: " . $sLoopParams);
     //read loop parameters
     //loop/type - REQUIRED
     try {
         $sLoopLoop = self::getTagSetting($sLoopParams, "loop", $this->regexpVariable());
         $bIsFetchLoop = false;
         // it's a normal loop : <anwloop item="$tag" loop="$item.tags" limit="5">
     } catch (AnwUnexpectedException $e) {
         $bIsFetchLoop = true;
         // it's a fetch loop : <anwloop item="$menu" class="menu" match="*" limit="5" sort="myname" order="asc">
     }
     //only Fetching loop can be cached (to avoid unsync problems between parent/childs loops)
     $nLoopCacheTime = -1;
     $bCacheEnabled = false;
     $bCacheBlockEnabled = false;
     $bDoCaching = false;
     if ($bIsFetchLoop) {
         //cachetime - OPTIONAL
         try {
             $nLoopCacheTime = (int) self::getTagSetting($sLoopParams, "cachetime", '!^([0-9]*?)$!si');
         } catch (AnwUnexpectedException $e) {
             //cachetime setting not found, keep default values
             $nLoopCacheTime = AnwComponent::globalCfgLoopsAutoCacheTime();
         }
         if ($nLoopCacheTime > 0) {
             $bCacheEnabled = true;
             //if we have specified a cachetime, look for cacheblock setting
             try {
                 $sTmpCacheBlock = self::getTagSetting($sLoopParams, "cacheblock", '!^(true|false|yes|no|0|1)$!si');
                 $bCacheBlockEnabled = in_array($sTmpCacheBlock, array('true', 'yes', '1'));
                 unset($sTmpCacheBlock);
             } catch (AnwUnexpectedException $e) {
                 //should we implicitely enable cacheblock by default?
                 $bCacheBlockEnabled = AnwComponent::globalCfgLoopsAutoCacheblock();
             }
             self::debug("cacheBlockEnabled: " . $bCacheBlockEnabled);
         }
         //can we really use cache for this loop?
         $bDoCaching = $bCacheEnabled && $this->bCachingEnabled && AnwComponent::globalCfgCacheLoopsEnabled();
         //simulate a cacheblock if enabled
         if ($bDoCaching && $bCacheBlockEnabled) {
             self::debug("cacheblock enabled for loop");
             $this->nTmpCacheBlockId++;
             $nCurrentCacheBlockId = $this->nTmpCacheBlockId;
             //we need to keep this value unchanged for caching under the same key, at the end of the function
             try {
                 $sReturn = AnwCache_cacheBlock::getCacheBlock($this->oPage, $nCurrentCacheBlockId, $nLoopCacheTime);
                 self::debug("AnwLoop found in cacheblock, returning cached result.");
                 return $sReturn;
                 //return directly
             } catch (AnwCacheNotFoundException $e) {
             }
         } else {
             self::debug("cacheblock disabled for loop");
         }
     }
     //item - REQUIRED
     $sLoopItem = self::getTagSetting($sLoopParams, "item", '!^\\$([a-z]*?)$!si');
     //required
     $sLoopItem = substr($sLoopItem, 1);
     //remove starting '$'
     if (isset($this->asTmpLoopItemsInUse[$sLoopItem])) {
         throw new AnwUnexpectedException("Loop item already used : " . $sLoopItem);
     }
     $this->asTmpLoopItemsInUse[$sLoopItem] = 1;
     //limit - OPTIONAL
     try {
         $nLoopLimit = (int) self::getTagSetting($sLoopParams, "limit", '!^([0-9]*?)$!si');
     } catch (AnwUnexpectedException $e) {
         $nLoopLimit = 999999;
         //TODO
     }
     if ($bIsFetchLoop) {
         //class - REQUIRED
         $sLoopClass = self::getTagSetting($sLoopParams, "class", '!^([a-z]*?)$!si');
         //match - OPTIONAL
         try {
             $sLoopMatch = self::getTagSetting($sLoopParams, "match", '!^([^"]*?)$!si');
         } catch (AnwUnexpectedException $e) {
             $sLoopMatch = '*';
         }
         //morelangs - OPTIONAL
         $asLoopLangs = array($this->oPage->getLang());
         try {
             $sTmp = self::getTagSetting($sLoopParams, "morelangs", '!^([a-z,]*?)$!si');
             $asTmpLangs = explode(',', $sTmp);
             foreach ($asTmpLangs as $sTmpLang) {
                 $sTmpLang = trim($sTmpLang);
                 if (Anwi18n::langExists($sTmpLang) && !in_array($sTmpLang, $asLoopLangs)) {
                     $asLoopLangs[] = $sTmpLang;
                 }
             }
         } catch (AnwUnexpectedException $e) {
         }
         //sort - OPTIONAL
         try {
             $sLoopSort = self::getTagSetting($sLoopParams, "sort", '!^([a-z]*?)$!si');
         } catch (AnwUnexpectedException $e) {
             $sLoopSort = AnwUtils::SORT_BY_NAME;
             //TODO secure pattern
         }
         //order - OPTIONAL
         try {
             $sLoopOrder = self::getTagSetting($sLoopParams, "order", '!^(' . AnwUtils::SORTORDER_ASC . '|' . AnwUtils::SORTORDER_DESC . ')$!si');
         } catch (AnwUnexpectedException $e) {
             $sLoopOrder = AnwUtils::SORTORDER_ASC;
         }
         //filter - OPTIONAL
         //filter="required=true,name:test*"
         $asLoopFilters = array();
         try {
             $asFILTERS_OPERATORS = array(AnwUtils::FILTER_OP_EQUALS, AnwUtils::FILTER_OP_LIKE, AnwUtils::FILTER_OP_LT, AnwUtils::FILTER_OP_GT, AnwUtils::FILTER_OP_LE, AnwUtils::FILTER_OP_GE);
             $sTmp = self::getTagSetting($sLoopParams, "filter", '!^([a-z0-9_\\-,#|' . implode('', $asFILTERS_OPERATORS) . '\\*]*?)$!si');
             $asTmpFilters = explode(',', $sTmp);
             foreach ($asTmpFilters as $sTmpFilter) {
                 $sTmpFilter = trim($sTmpFilter);
                 try {
                     list($sFilterOp1, $sFilterOperator, $sFilterOp2) = self::parseOperator($asFILTERS_OPERATORS, $sTmpFilter);
                     $sFilterOp1 = $this->getOperandValue($sFilterOp1);
                     $sFilterOp2 = $this->getOperandValue($sFilterOp2);
                     $asLoopFilters[] = array('FIELD' => $sFilterOp1, 'OPERATOR' => $sFilterOperator, 'VALUE' => $sFilterOp2);
                 } catch (AnwUnexpectedException $e) {
                 }
             }
         } catch (AnwUnexpectedException $e) {
         }
     }
     //iterate over the loop
     $sReturn = "";
     $aoLoopsItems = array();
     try {
         if ($bIsFetchLoop) {
             self::debug("anwloop/fetch found");
             $aoLoopsItems = $this->getAnwloopFetchItems($nLoopLimit, $sLoopClass, $sLoopMatch, $asLoopLangs, $sLoopSort, $sLoopOrder, $asLoopFilters, $bDoCaching, $nLoopCacheTime);
         } else {
             self::debug("anwloop/loop found");
             $aoLoopsItems = $this->parseLoopVariable('{' . $sLoopLoop . '}');
             //throws an exception if error
         }
         //run the loop!
         foreach ($aoLoopsItems as $oLoopItem) {
             self::debug("anwloop iteration");
             $this->aoLoopsItems[$sLoopItem] = $oLoopItem;
             //we may need it during recursive calls
             $sReturn .= $this->runAnwloopIteration($sLoopContent, $sLoopItem);
             unset($this->aoLoopsItems[$sLoopItem]);
         }
     } catch (Exception $e) {
         self::debug("! LOOP ERROR!");
         $sReturn = AnwComponent::g_("local_exec_loop_error");
     }
     unset($this->asTmpLoopItemsInUse[$sLoopItem]);
     //put whole content in cache if cacheblock enabled
     if ($bDoCaching && $bCacheBlockEnabled) {
         AnwCache_cacheBlock::putCacheBlock($this->oPage, $nCurrentCacheBlockId, $sReturn);
     }
     return $sReturn;
 }