function toHtml($oContent, $oPage) { $oOutputHtml = new AnwOutputHtml($oPage); $oOutputHtml->setTitle($oContent->getContentFieldValue(self::FIELD_TITLE)); $sNewsCategoryTitle = $oContent->getContentFieldValue(self::FIELD_TITLE); $sNewsCategoryIntro = $oContent->getContentFieldValue(self::FIELD_DESCRIPTION); //try{$aoNewsList = $this->getNewsList($oPage);}catch(Exception $e){print_r($e);} //render news list $aoNewsList = self::getNewsList($oPage); $sHtmlNewsList = ""; if (count($aoNewsList) > 0) { $sHtmlNewsList .= $this->tpl()->newsListStart(); foreach ($aoNewsList as $oNewsPage) { $oNewsContent = $oNewsPage->getContent(); $sNewsTitle = $oNewsContent->getContentFieldValue(AnwContentClassPageDefault_news::FIELD_TITLE); $sNewsIntro = $oNewsContent->getContentFieldValue(AnwContentClassPageDefault_news::FIELD_INTRO); $sNewsDate = Anwi18n::date(AnwUtils::dateToTime($oNewsContent->getContentFieldValue(AnwContentClassPageDefault_news::FIELD_DATE)), $oPage->getLang()); $sNewsUrl = AnwUtils::link($oNewsPage); $sHtmlNewsList .= $this->tpl()->newsListItem($sNewsTitle, $sNewsIntro, $sNewsDate, $sNewsUrl, $oNewsPage->getLang()); } $sHtmlNewsList .= $this->tpl()->newsListEnd(); } unset($aoNewsList); //render the newscategory $sHtmlBody = $this->tpl()->showNewscategory($sNewsCategoryTitle, $sNewsCategoryIntro, $sHtmlNewsList, $oPage->getLang()); $oOutputHtml->setBody($sHtmlBody); return $oOutputHtml; }
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); }
function availableTranslationsRow($oPage) { $sName = $oPage->getName(); $sUrl = AnwUtils::link($oPage); $sStyle = "background:url('" . Anwi18n::srcFlag($oPage->getLang()) . "') no-repeat left;"; $HTML = "<a href=\"" . $this->xQuote($sUrl) . "\" style=\"{$sStyle}\">" . $this->xText($sName) . "</a>"; return $HTML; }
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 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); }
function showForm($sError = false) { $sLink = AnwUtils::link($this->getoPage(), "duplicate"); $sCurrentPageName = $this->getoPage()->getName(); $sCurrentPageLang = $this->getoPage()->getLang(); $aoTranslations = $this->getoPage()->getPageGroup()->getPages($this->getoPage()); $this->out .= $this->tpl()->duplicateStart($sLink, $sCurrentPageName, $sCurrentPageLang, $sError); $sInputName = $this->getInputName($this->getoPage()); $this->out .= $this->tpl()->duplicateRowCurrent($sCurrentPageLang, $sCurrentPageName, $sInputName); foreach ($aoTranslations as $oTranslation) { $sTranslationPageName = $oTranslation->getName(); $sInputName = $this->getInputName($oTranslation); $sCheckBoxName = $this->getChkName($oTranslation); $this->out .= $this->tpl()->duplicateRow($oTranslation->getLang(), $sTranslationPageName, $sInputName, $sCheckBoxName); } $this->out .= $this->tpl()->duplicateStop(); }
private function doBindLinksToPreferedLang($sContentHtmlAndPhp) { $aoOutgoingLinks = AnwPage::getOutgoingLinksFromContent($sContentHtmlAndPhp); foreach ($aoOutgoingLinks as $sOutgoingLink => $oPageTarget) { //get target page in the lang we want $sPreferedLang = $this->oPage->getLang(); $oPageTarget = $oPageTarget->getPageGroup()->getPreferedPage($sPreferedLang); //update the link in content $sLinkTarget = AnwUtils::link($oPageTarget->getName()); $sLinkLang = $oPageTarget->getLang(); $sContentHtmlAndPhp = AnwPage::updateOutgoingLinkInContent($sOutgoingLink, $sLinkTarget, $sContentHtmlAndPhp, $sLinkLang); } return $sContentHtmlAndPhp; }
private function abortRename() { //unlock $this->unlockPageForEdition(); //redirect AnwUtils::redirect(AnwUtils::link($this->getoPage())); }
private function createPageProcess($sLang, $sContentClass) { $sPageName = $this->getPageName(); if (!AnwCurrentSession::isActionAllowed($sPageName, 'create', $sLang)) { throw new AnwAclException("permission create denied"); } $oContentClass = AnwContentClasses::getContentClass($sContentClass); AnwStorage::transactionStart(); try { //create page $oPage = AnwPage::createNewPage($oContentClass, $sPageName, $sLang); //should we create translations for this new page? $asAvailableLangs = $oPage->getPageGroup()->getAvailableLangs(); //check permissions : translate foreach ($asAvailableLangs as $sLang) { if (AnwEnv::_POST($this->getChkName($sLang))) { $sTranslationName = AnwEnv::_POST($this->getInputName($sLang), ""); if (!AnwCurrentSession::isActionAllowed($sTranslationName, 'translate', $sLang)) { throw new AnwAclException("permission translate denied"); } } } foreach ($asAvailableLangs as $sLang) { if (AnwEnv::_POST($this->getChkName($sLang))) { $sTranslationName = AnwEnv::_POST($this->getInputName($sLang), ""); //create translation $oPageTranslation = $oPage->createNewTranslation($sTranslationName, $sLang); } } AnwStorage::transactionCommit(); } catch (AnwException $e) { AnwStorage::transactionRollback(); throw $e; } AnwUtils::redirect(AnwUtils::link($oPage, "edit")); }
function toHtml($oContent, $oPage) { $oOutputHtml = new AnwOutputHtml($oPage); $oOutputHtml->setTitle($oContent->getContentFieldValue(self::FIELD_TITLE)); //load contentclass CSS $oOutputHtml->setHead($this->getCssSrcComponent(self::CSS_FILE)); $sNewsTitle = $oContent->getContentFieldValue(self::FIELD_TITLE); $sNewsIntro = $oContent->getContentFieldValue(self::FIELD_INTRO); $sNewsBody = $oContent->getContentFieldValue(self::FIELD_BODY); $sNewsDate = Anwi18n::date(AnwUtils::dateToTime($oContent->getContentFieldValue(self::FIELD_DATE)), $oPage->getLang()); //render categories $aoCategoriesPages = self::getCategoriesPages($oContent, $oPage); $sHtmlCategories = ""; if (count($aoCategoriesPages) > 0) { $sHtmlCategories .= $this->tpl()->categoriesStart(); foreach ($aoCategoriesPages as $oCategoryPage) { $oCategoryContent = $oCategoryPage->getContent(); $sCategoryTitle = $oCategoryContent->getContentFieldValue(AnwContentClassPageDefault_newscategory::FIELD_TITLE); $sCategoryUrl = AnwUtils::link($oCategoryPage); $sHtmlCategories .= $this->tpl()->categoriesItem($sCategoryTitle, $sCategoryUrl); } $sHtmlCategories .= $this->tpl()->categoriesEnd(); } unset($aoCategoriesPages); //render the news $sHtmlBody = $this->tpl()->showNews($sNewsTitle, $sNewsIntro, $sNewsBody, $sNewsDate, $sHtmlCategories, $oPage->getLang()); $oOutputHtml->setBody($sHtmlBody); return $oOutputHtml; }
function redirectInfo($url, $title, $info = "") { if (!$url || !AnwUtils::isSafeUrl($url)) { $url = AnwUtils::link(self::globalCfgHomePage()); } $this->title = $title; $this->headJsOnload("setTimeout(function(){window.location.href='" . AnwUtils::escapeApostrophe($url) . "';},2000);"); //render head $this->renderHeadForOutput(); $this->out = $this->tpl()->globalBodyRedirectInfo($url, $title, $info); $this->out = $this->tpl()->globalHtml(self::g_("local_html_lang", array(), self::getActionLang()), self::g_("local_html_dir", array(), self::getActionLang()), $this->title, $this->head, $this->out); $this->printOutput(); }
private function selectDeletionType() { $sLinkDeletePage = AnwUtils::link($this->getPageName(), "delete", array("t" => self::$DELETE_PAGE)); $sLinkDeleteGroup = AnwUtils::link($this->getPageName(), "delete", array("t" => self::$DELETE_GROUP)); $this->out .= $this->tpl()->selectDeletionType($sLinkDeletePage, $this->isDeleteGroupAllowed() ? $sLinkDeleteGroup : false); }
function toHtml($oContent, $oPage) { $aoContentClasses = array(); $asContentClassNames = $oContent->getContentFieldValues(self::FIELD_CONTENTCLASS); foreach ($asContentClassNames as $sContentClassName) { $oContentClass = AnwContentClasses::getContentClass($sContentClassName); $aoContentClasses[] = $oContentClass; } unset($asContentClassNames); //get feed items $aoMatchingPages = AnwStorage::fetchPages($oContent->getContentFieldValues(self::FIELD_MATCH, true), $aoContentClasses, array($oPage->getLang()), $oContent->getContentFieldValue(self::FIELD_LIMIT), AnwUtils::SORT_BY_TIME, AnwUtils::SORTORDER_DESC); $aoFeedItems = array(); foreach ($aoMatchingPages as $oMatchingPage) { $oFeedItem = $oMatchingPage->toFeedItem(); $aoFeedItems[] = $oFeedItem; } if (AnwEnv::_GET(self::GET_FEED) != AnwFeed::TYPE_RSS2) { $sUrlRss = AnwUtils::link($oPage, "view", array(self::GET_FEED => AnwFeed::TYPE_RSS2)); //show feed info $oOutputHtml = new AnwOutputHtml($oPage); $oOutputHtml->setTitle($oContent->getContentFieldValue(self::FIELD_TITLE)); $sHtmlItems = ""; foreach ($aoFeedItems as $oFeedItem) { $sHtmlItems .= $this->tpl()->feedItem($oFeedItem->getTitle(), $oFeedItem->getLink()); } $sHtmlBody = $this->tpl()->feedInfo($oContent->getContentFieldValue(self::FIELD_TITLE), $oContent->getContentFieldValue(self::FIELD_DESCRIPTION), $sUrlRss, $sHtmlItems, $oPage->getLang()); $oOutputHtml->setBody($sHtmlBody); // load contentclass CSS $sHtmlHead = $this->getCssSrcComponent(self::CSS_FILE); $sHtmlHead .= $this->tpl()->headRss($sUrlRss, $oContent->getContentFieldValue(self::FIELD_TITLE)); $oOutputHtml->setHead($sHtmlHead); } else { $sUrlRss = AnwUtils::linkAbsolute($oPage, "view", array(self::GET_FEED => AnwFeed::TYPE_RSS2)); //export to rss $oFeed = new AnwFeed(AnwFeed::TYPE_RSS2, $oContent->getContentFieldValue(self::FIELD_TITLE), $sUrlRss, $oContent->getContentFieldValue(self::FIELD_DESCRIPTION)); foreach ($aoFeedItems as $oFeedItem) { $oFeed->addItem($oFeedItem); } $oFeed->output(); } return $oOutputHtml; }
function redirectIfTranslationAvailable($sLang) { if ($this->getLang() != $sLang) { $aoTranslations = $this->getPageGroup()->getPages(); if (isset($aoTranslations[$sLang])) { //translation found, let's redirect $oGoodPage = $aoTranslations[$sLang]; if ($oGoodPage->isActionAllowed('view')) { self::debug("redirectIfTranslationAvailable(" . $sLang . "): translation found"); //save _POST AnwUtils::httpPostToSession(); //save _GET $asParams = $_GET; unset($asParams[AnwActionPage::GET_PAGENAME]); //avoid loop //redirect $sLink = AnwUtils::link($oGoodPage, "view", $asParams); AnwUtils::redirect($sLink); } else { self::debug("redirectIfTranslationAvailable(" . $sLang . "): translation found but no permission"); } } else { self::debug("redirectIfTranslationAvailable(" . $sLang . "): translation NOT found"); } } }
private function doRevert($oPageGroup, $aaRevertPlan) { $nTime = time(); // simulation $aoAllFutureContents = array(); foreach ($aaRevertPlan['REVERT'] as $aoRevertPages) { $oPageCurrent = $aoRevertPages[0]; $oPageForRevert = $aoRevertPages[1]; if (isset($aoAllFutureContents[$oPageForRevert->getLang()])) { throw new AnwUnexpectedException("already have a content for this lang"); } $aoAllFutureContents[$oPageForRevert->getLang()] = $oPageForRevert->getContent(); } foreach ($aaRevertPlan['RESTORE'] as $oPageForRestore) { if (isset($aoAllFutureContents[$oPageForRestore->getLang()])) { throw new AnwUnexpectedException("already have a content for this lang"); } $aoAllFutureContents[$oPageForRestore->getLang()] = $oPageForRestore->getContent(); } foreach ($aaRevertPlan['KEEP'] as $oPageKept) { if (isset($aoAllFutureContents[$oPageKept->getLang()])) { throw new AnwUnexpectedException("already have a content for this lang"); } $aoAllFutureContents[$oPageKept->getLang()] = $oPageKept->getContent(); } // make sure that everything is in order... (or throws an exception) AnwPage::checkSimilarContents($aoAllFutureContents); // now, apply changes AnwStorage::transactionStart(); try { //important, firstly delete pages which needs it, to avoid conflicts when reverting or creating pages foreach ($aaRevertPlan['DELETE'] as $oPageForDelete) { $sChangeComment = "delete for revert"; $oPageForDelete->delete($nTime, $sChangeComment); } foreach ($aaRevertPlan['REVERT'] as $aoRevertPages) { $oPageCurrent = $aoRevertPages[0]; $oPageForRevert = $aoRevertPages[1]; $sChangeComment = "revert to old revision"; $oPageCurrent->revertToRevision($oPageForRevert, $nTime, $sChangeComment); } foreach ($aaRevertPlan['RESTORE'] as $oPageForRestore) { $sChangeComment = "restore for revert"; $oPageForRestore->restoreArchive($nTime, $sChangeComment); } AnwStorage::transactionCommit(); } catch (AnwException $e) { AnwStorage::transactionRollback(); throw $e; } // redirect to reverted page if possible $oPageGroup->refresh(); if (count($oPageGroup->getPages()) > 0) { $oPageRedirect = $oPageGroup->getPreferedPage(); AnwUtils::redirect(AnwUtils::link($oPageRedirect)); } else { // no page available, go home AnwUtils::redirect(); } }
private function saveTranslation() { try { $asAvailableLangs = $this->getoPage()->getPageGroup()->getAvailableLangs(); //check permissions : translate foreach ($asAvailableLangs as $sLang) { if (AnwEnv::_POST($this->getChkName($sLang))) { $sTranslationName = AnwEnv::_POST($this->getInputName($sLang), ""); if (!AnwCurrentSession::isActionAllowed($sTranslationName, 'translate', $sLang)) { throw new AnwAclException("permission translate denied"); } } } $oPageTranslation = null; AnwStorage::transactionStart(); try { foreach ($asAvailableLangs as $sLang) { if (AnwEnv::_POST($this->getChkName($sLang))) { $sTranslationName = AnwEnv::_POST($this->getInputName($sLang), ""); //create translation $oPageTranslation = $this->getoPage()->createNewTranslation($sTranslationName, $sLang); } } AnwStorage::transactionCommit(); } catch (AnwException $e) { AnwStorage::transactionRollback(); throw $e; } if ($oPageTranslation) { // redirect to last created translation AnwUtils::redirect(AnwUtils::link($oPageTranslation)); } else { // no translation was created, show form again $this->showForm(); } } catch (AnwBadPageNameException $e) { $this->showForm($this->g_("err_badpagename")); } catch (AnwBadLangException $e) { $this->showForm($this->g_("err_badlang")); } catch (AnwPageAlreadyExistsException $e) { $this->showForm($this->g_("err_pagealreadyexists")); } catch (AnwAclException $e) { $this->showForm($this->g_("err_nopermission")); } catch (AnwLangExistsForPageGroupException $e) { $this->showForm($this->g_("err_langexistsforpagegroup")); } }
protected function linkMe($asParams = array()) { return AnwUtils::link($this->getPageName(), $this->getName(), $asParams = array()); }
protected function getEditionForm() { if (!$this->oEditionForm) { $sTarget = AnwUtils::link($this->getoPage(), $this->getName()); $this->oEditionForm = new AnwStructuredContentEditionFormPage($this->getoPage()->getContent(), $sTarget); } return $this->oEditionForm; }
function getPageLink($oCurrentPage) { return AnwUtils::link($oCurrentPage, $this->sActionName); }