private function doUpload($mUploadedFile, $sPrefix) { //move uploaded file $sDestinationFileName = AnwUtils::genStrongRandMd5(); AnwUtils::move_uploaded_file($mUploadedFile, self::tmpFilename($sDestinationFileName)); //redirect $sUrl = AnwUtils::aLink($this->getName(), array(self::IN_FILENAME => $sDestinationFileName, self::IN_PREFIX => $sPrefix)); AnwUtils::redirect($sUrl); }
protected function pagenotfound() { if (AnwCurrentSession::isActionAllowed($this->getoPage()->getName(), 'create', -1)) { AnwPlugins::hook('action_view_pagenotfound_create', $this->getoPage()); AnwUtils::redirect(AnwUtils::link($this->getoPage(), "create")); } else { AnwPlugins::hook('action_view_pagenotfound_404', $this->getoPage()); $this->error404(); } }
function run() { $this->getoPage()->checkPageGroupSynchronized(); $this->setTitle($this->t_('title', array('pagename' => $this->getPageName()))); if (AnwEnv::_POST("abort")) { AnwUtils::redirect(AnwUtils::link($this->getoPage())); } else { if (AnwEnv::_POST("submit")) { $this->saveDuplication(); } else { $this->showForm(); } } }
function run() { if (!self::globalCfgUsersRegisterEnabled()) { AnwUtils::redirect(); } $this->setTitle($this->t_('title')); $sError = false; $sLogin = ""; $sDisplayName = ""; $sEmail = ""; if (AnwEnv::_POST("submit")) { $sLogin = AnwEnv::_POST("login", ""); $sDisplayName = AnwEnv::_POST("displayname", ""); $sEmail = AnwEnv::_POST("email", ""); $sPassword = AnwEnv::_POST("password", ""); //try to register try { $this->checkCaptcha(); $sLang = AnwCurrentSession::getLang(); $nTimezone = AnwCurrentSession::getTimezone(); $oUser = AnwUsers::createUser($sLogin, $sDisplayName, $sEmail, $sLang, $nTimezone, $sPassword); AnwCurrentSession::login($sLogin, $sPassword, false); //open a public time-limited session $this->redirectInfo(false, $this->t_("t_created"), $this->t_("p_created")); } catch (AnwLoginAlreadyTakenException $e) { $sError = $this->g_("err_loginalreadytaken"); } catch (AnwBadLoginException $e) { $sError = $this->g_("err_badlogin"); } catch (AnwDisplayNameAlreadyTakenException $e) { $sError = $this->g_("err_displaynamealreadytaken"); } catch (AnwBadDisplayNameException $e) { $sError = $this->g_("err_baddisplayname"); } catch (AnwEmailAlreadyTakenException $e) { $sError = $this->g_("err_emailalreadytaken"); } catch (AnwBadEmailException $e) { $sError = $this->g_("err_bademail"); } catch (AnwBadPasswordException $e) { $sError = $this->g_("err_badpassword"); } catch (AnwBadCaptchaException $e) { $sError = $this->g_("err_badcaptcha"); } } //display register form $this->out .= $this->tpl()->registerForm(AnwUtils::alink("register"), $sLogin, $sDisplayName, $sEmail, $sError); }
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")); } }
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(); } }
protected function saveEditionForm() { try { //save changes $this->getEditionForm()->saveEdition(); //update step status $this->getActionInstall()->updateStepStatusNext(); //redirect AnwUtils::redirect($this->linkStepNext()); } catch (AnwStructuredContentEditionFormException $e) { $sError = $e->getMessage(); $this->showEditionForm($sError); } }
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 run() { $sUrl = AnwUtils::aLink("revert", array("pagegroup" => $this->getoPage()->getPageGroup()->getId())); AnwUtils::redirect($sUrl); }
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 updateSettings() { //update prefs $asErrorsPrefs = array(); try { $sLang = AnwEnv::_POST("lang", ""); AnwCurrentSession::setLang($sLang); $nTimezone = AnwEnv::_POST("timezone", 0); AnwCurrentSession::setTimezone($nTimezone); } catch (AnwBadLangException $e) { $asErrorsPrefs[] = $this->g_("err_badlang"); } catch (AnwBadTimezoneException $e) { $asErrorsPrefs[] = $this->g_("err_badtimezone"); } catch (AnwException $e) { $asErrorsPrefs[] = $this->g_("err_unkn"); } $asErrorsAccount = array(); if (AnwCurrentSession::isLoggedIn() && AnwUsers::isDriverInternal()) { //update account try { //displayname change requested ? if (self::globalCfgUsersChangeDisplayname()) { $sDisplayname = AnwEnv::_POST("displayname", ""); if (AnwCurrentSession::getUser()->getDisplayName() != $sDisplayname) { AnwCurrentSession::getUser()->changeDisplayName($sDisplayname); } } //email change requested ? $sEmail = AnwEnv::_POST("email", ""); if (AnwCurrentSession::getUser()->getEmail() != $sEmail) { AnwCurrentSession::getUser()->changeEmail($sEmail); } //password change requested ? $sNewPassword = AnwEnv::_POST("newpassword"); $sNewPasswordRepeat = AnwEnv::_POST("newpassword_repeat"); $sCurrentPassword = AnwEnv::_POST("currentpassword", ""); if ($sNewPassword) { if ($sNewPassword == $sNewPasswordRepeat) { try { //authenticate with current password AnwCurrentSession::getUser()->authenticate($sCurrentPassword); //authentication ok, change the password try { AnwCurrentSession::getUser()->changePassword($sNewPassword); } catch (AnwBadPasswordException $e) { $asErrorsAccount[] = $this->t_("err_badnewpassword"); } } catch (AnwBadPasswordException $e) { $asErrorsAccount[] = $this->g_("err_incorrectpassword"); } catch (AnwAuthException $e) { $asErrorsAccount[] = $this->g_("err_incorrectpassword"); } } else { $asErrorsAccount[] = $this->g_("err_passwordsmatch"); } } } catch (AnwDisplayNameAlreadyTakenException $e) { $asErrorsAccount[] = $this->g_("err_displaynamealreadytaken"); } catch (AnwBadDisplayNameException $e) { $asErrorsAccount[] = $this->g_("err_baddisplayname"); } catch (AnwEmailAlreadyTakenException $e) { $asErrorsAccount[] = $this->g_("err_emailalreadytaken"); } catch (AnwBadEmailException $e) { $asErrorsAccount[] = $this->g_("err_bademail"); } catch (AnwException $e) { $asErrorsAccount[] = $this->g_("err_unkn"); } } if (count($asErrorsPrefs) > 0 || count($asErrorsAccount) > 0) { $this->formSettings(false, $asErrorsPrefs, $asErrorsAccount); } else { AnwUtils::redirect($this->linkMe(array("done" => 1))); } }
protected function checkPageExists() { if (!$this->pageExists()) { AnwUtils::redirect(AnwUtils::link($this->getoPage())); } }
private function deletePage() { $this->getoPage()->delete(); AnwUtils::redirect(); }
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")); } }
protected function saveEdition() { try { //save changes $this->getEditionForm()->saveEdition(); //redirect $amParameters = array('c' => $this->sComponentName, 't' => $this->sComponentType); $sTarget = AnwUtils::alink($this->getName(), $amParameters); AnwUtils::redirect($sTarget); } catch (AnwStructuredContentEditionFormException $e) { $sError = $e->getMessage(); $this->editForm($sError); } }
function runAndOutput() { try { AnwDebug::startbench("action runAndOutput", true); //captcha request? if (AnwEnv::_GET(self::GET_CAPTCHA)) { $this->doCaptcha(); exit; } //make sure this action is enabled in configuration if (!in_array($this->getName(), AnwComponent::getEnabledComponents(AnwComponent::TYPE_ACTION))) { throw new AnwAclException("Trying to execute an action which is not enabled"); } //is it an admin action? if ($this instanceof AnwAdminAction) { if (!AnwCurrentSession::getUser()->isAdminAllowed()) { throw new AnwAclException("Admin is not allowed"); } } //does action require https if available? if (self::isHttpsAction($this->getName())) { //do we need to redirect to https? if (self::globalCfgHttpsEnabled() && !AnwEnv::isHttps()) { //redirect to https self::debug("Redirecting to https..."); AnwUtils::httpPostToSession(); $asParams = $_GET; $sLink = AnwUtils::alink($this->getName(), $asParams); AnwUtils::redirect($sLink); //should automatically use https } } if (AnwCurrentSession::needsReauth()) { //reauth processing if (AnwEnv::_POST("reauth")) { self::debug("Processing reauth request..."); try { //check password and reset reauth $this->doReauth(AnwEnv::_POST("reauth")); self::debug("Reauth request success!"); } catch (AnwException $e) { //reauth failed, show reauth form again self::debug("Reauth success failed."); $this->doReauthForm(); //post data is already in session exit; } } //must the user reauth for this action? - do this after reauth processing if ($this instanceof AnwHarmlessAction) { //ok, user is authorized to run action without reauthenticating } else { //user needs to reauthenticate $this->checkReauth(); } } //restore POST if any in session AnwUtils::restoreHttpPostFromSession(); $this->initializeAction(); //run the action $this->init(); $this->run(); AnwDebug::stopbench("action runAndOutput"); $this->output(); } catch (AnwLockException $e) { $aoLocks = $e->getLocks(); $asLockInfos = array(); foreach ($aoLocks as $oLock) { $nLockType = $oLock->getLockType(); switch ($nLockType) { case AnwLock::TYPE_PAGEONLY: $sTranslation = "err_ex_lock_details_pageonly"; break; case AnwLock::TYPE_PAGEGROUP: $sTranslation = "err_ex_lock_details_pagegroup"; break; default: throw new AnwUnexpectedException("lock type unknown"); break; } $asLockInfos[] = self::g_($sTranslation, array("user" => '<b>' . AnwUtils::xText($oLock->getLockUser()->getDisplayName()) . '</b>', "pagename" => '<i>' . AnwUtils::xText($oLock->getLockPage()->getName()) . '</i>', "timestart" => Anwi18n::dateTime($oLock->getLockTime()), "timeseen" => Anwi18n::dateTime($oLock->getLockTimeLast()), "timeexpire" => Anwi18n::dateTime($oLock->getLockTimeLast() + self::globalCfgLocksExpiry()))); } $this->headJs($this->tpl()->errorLock_js()); $this->out = $this->tpl()->errorLock($asLockInfos); $this->output(); } catch (AnwException $e) { $nErrorNumber = false; if ($e instanceof AnwAclPhpEditionException) { $sTitle = self::g_("err_ex_acl_t"); $sExplain = self::g_("err_ex_acl_php_p"); $sImageSrc = AnwUtils::pathImg("warning.gif"); } else { if ($e instanceof AnwAclJsEditionException) { $sTitle = self::g_("err_ex_acl_t"); $sExplain = self::g_("err_ex_acl_js_p"); $sImageSrc = AnwUtils::pathImg("warning.gif"); } else { if ($e instanceof AnwAclMinTranslatedPercentException) { $sTitle = self::g_("err_ex_acl_t"); $sExplain = self::g_("err_ex_acl_mintranslatedpercent_p", array('percent' => $e->getTranslatedPercent())); $sImageSrc = AnwUtils::pathImg("warning.gif"); } else { if ($e instanceof AnwAclException) { $sTitle = self::g_("err_ex_acl_t"); if (AnwCurrentSession::isLoggedIn()) { $sExplain = self::g_("err_ex_acl_loggedin_p"); } else { $sExplain = self::g_("err_ex_acl_loggedout_p"); } $sImageSrc = AnwUtils::pathImg("warning.gif"); } else { if ($e instanceof AnwBadCallException) { $sTitle = self::g_("err_ex_badcall_t"); $sExplain = self::g_("err_ex_badcall_p"); $sImageSrc = AnwUtils::pathImg("warning.gif"); } else { if ($e instanceof AnwDbConnectException) { $sTitle = self::g_("err_ex_dbconnect_t"); $sExplain = self::g_("err_ex_dbconnect_p"); $sImageSrc = AnwUtils::pathImg("error.gif"); $nErrorNumber = AnwDebug::reportError($e); } else { $sTitle = self::g_("err_ex_unexpected_t"); $sExplain = self::g_("err_ex_unexpected_p"); $sImageSrc = AnwUtils::pathImg("error.gif"); $nErrorNumber = AnwDebug::reportError($e); } } } } } } $this->out = $this->tpl()->errorException($sTitle, $sExplain, $sImageSrc, $nErrorNumber); //self::output(); //not use $this to avoid potential errors if it's an ActionPage $this->output(); } }
protected function grantUserAdmin($oUser) { //grant admin privileges AnwAcls::grantUserAdminOnInstall($oUser); //open the session AnwSessions::login($oUser, false); //squeezing AnwCurrentSession... //update step status $this->getActionInstall()->updateStepStatusNext(); AnwUtils::redirect($this->linkStepNext()); }
function run() { AnwUtils::redirect(AnwUtils::alink("lastchanges", array("page" => $this->getoPage()->getId()))); }
protected function abortEdition() { //unlock $this->unlockPageForEdition(); //redirect AnwUtils::redirect(AnwUtils::link($this->getoPage())); }
protected function pingDone() { //update step status $this->getActionInstall()->updateStepStatusNext(); AnwUtils::redirect($this->linkStepNext()); }