Exemple #1
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);
 }
Exemple #2
0
 protected function saveEdition($sComment, $nDraftTime)
 {
     try {
         //check captcha
         if ($this->needsCaptcha()) {
             $this->checkCaptcha();
         }
         //update content from post
         $oEditContent = $this->getEditionForm()->updateContentFromEdition();
         //save changes
         $this->getoPage()->saveEditAndDeploy($oEditContent, AnwChange::TYPE_PAGE_EDITION, $sComment);
         //delete old draft
         /*if ($nDraftTime)
         		{
         			$oDraft = $this->getoPage()->getDraft($nDraftTime);
         			$oDraft->delete();
         		}*/
         //unlock
         $this->unlockPageForEdition();
         //redirect
         AnwUtils::redirect(AnwUtils::link($this->getoPage()));
     } catch (AnwStructuredContentEditionFormException $e) {
         $sError = $e->getMessage();
         $this->editForm($sComment, AnwEnv::_POST("draft"), $sError);
     } catch (AnwBadCaptchaException $e) {
         $sError = $this->g_("err_badcaptcha");
         $this->editForm($sComment, AnwEnv::_POST("draft"), $sError);
     } catch (AnwBadCommentException $e) {
         $sError = $this->g_("err_badcomment");
         $this->editForm($sComment, AnwEnv::_POST("draft"), $sError);
     } catch (AnwUnexpectedException $e) {
         $sError = $this->g_("err_ex_unexpected_p");
         $nErrorNumber = AnwDebug::reportError($e);
         if ($nErrorNumber) {
             $sError .= '<br/>' . $this->g_("err_ex_report", array("errornumber" => $nErrorNumber));
         }
         $this->editForm($sComment, AnwEnv::_POST("draft"), $sError);
     }
 }
Exemple #3
0
 private static function clearCacheDir($sCacheDirectory, $bDefinitive)
 {
     if (is_dir($sCacheDirectory)) {
         try {
             AnwUtils::rmdirFiles($sCacheDirectory, ANWPATH_CACHE);
             if ($bDefinitive) {
                 AnwUtils::rmdir($sCacheDirectory, ANWPATH_CACHE);
             }
         } catch (AnwUnexpectedException $e) {
             AnwDebug::reportError($e);
         }
     }
 }
Exemple #4
0
 private static function generateActionsMapping()
 {
     $aaActionsMapping = array(self::MAPPING_GLOBALNAV => array(), self::MAPPING_PAGENAV => array(), self::MAPPING_MANAGEMENTNAV => array(), self::HTTPS_ACTIONS => array(), self::PUBLIC_ACTIONS => array(), self::ADMIN_ACTIONS => array(), self::ALWAYS_ENABLED_ACTIONS => array(), self::GRANT_ALL_USERS_BY_DEFAULT_ACTIONS => array(), self::ACTIONS_PAGE => array());
     $asEnabledActions = AnwComponent::getAvailableComponents(AnwComponent::TYPE_ACTION);
     foreach ($asEnabledActions as $sEnabledAction) {
         try {
             //load action
             $sEnabledAction = strtolower($sEnabledAction);
             $oAction = AnwAction::loadComponent($sEnabledAction);
             //is it an AnwHttpsAction?
             if ($oAction instanceof AnwHttpsAction) {
                 $aaActionsMapping[self::HTTPS_ACTIONS][] = $oAction->getName();
             }
             //is it an AnwPublicAction?
             if ($oAction instanceof AnwPublicAction) {
                 $aaActionsMapping[self::PUBLIC_ACTIONS][] = $oAction->getName();
             }
             //is it an AnwAdminAction?
             if ($oAction instanceof AnwAdminAction) {
                 $aaActionsMapping[self::ADMIN_ACTIONS][] = $oAction->getName();
             }
             //is it an AnwAlwaysEnabledAction?
             if ($oAction instanceof AnwAlwaysEnabledAction) {
                 $aaActionsMapping[self::ALWAYS_ENABLED_ACTIONS][] = $oAction->getName();
             }
             //is it an AnwGrantAllUsersByDefaultAction?
             if ($oAction instanceof AnwGrantAllUsersByDefaultAction) {
                 $aaActionsMapping[self::GRANT_ALL_USERS_BY_DEFAULT_ACTIONS][] = $oAction->getName();
             }
             //is it an AnwActionPage?
             if ($oAction instanceof AnwActionPage) {
                 $aaActionsMapping[self::ACTIONS_PAGE][] = $oAction->getName();
             }
             $mGlobalNavEntries = $oAction->getNavEntry();
             $aaActionsMapping = self::updateNavMapping($mGlobalNavEntries, $aaActionsMapping);
         } catch (AnwException $e) {
             AnwDebug::reportError($e);
         }
     }
     return $aaActionsMapping;
 }
Exemple #5
0
 private static function generatePluginsMapping()
 {
     $aaMapping = array();
     $asEnabledPlugins = AnwComponent::globalCfgModulesPlugins();
     foreach ($asEnabledPlugins as $sEnabledPlugin) {
         try {
             //load plugin
             $sEnabledPlugin = strtolower($sEnabledPlugin);
             self::loadPlugin($sEnabledPlugin);
             //reflexion
             //we DONT want inherited methods from AnwPlugin, only overriden methods
             $sClassName = get_class(self::getPlugin($sEnabledPlugin));
             $asMethods = get_class_methods($sClassName);
             foreach ($asMethods as $sMethod) {
                 $sMethod = strtolower($sMethod);
                 if (preg_match('!^hook_(.*)$!si', $sMethod, $asMatches)) {
                     $sHookName = $asMatches[1];
                     $aaMapping[self::TYPE_HOOK][$sHookName][] = $sEnabledPlugin;
                 } else {
                     if (preg_match('!^vhook_(.*)$!si', $sMethod, $asMatches)) {
                         $sHookName = $asMatches[1];
                         $aaMapping[self::TYPE_VHOOK][$sHookName][] = $sEnabledPlugin;
                     }
                 }
             }
         } catch (AnwException $e) {
             AnwDebug::reportError($e);
         }
     }
     return $aaMapping;
 }
Exemple #6
0
 /**
  * Import selected files.
  *
  */
 private function doImport($sUploadedFile, $asSelectedPages, $bContinueOnErrors)
 {
     // we will display the import result after running the whole import
     // that's why we save the output in a temporary buffer during this process
     $sOutBuffer = "";
     //load XML from file
     $aaData = $this->getDataFromXmlFile(self::tmpFilename($sUploadedFile));
     //delete tmp file
     AnwUtils::unlink(self::tmpFilename($sUploadedFile), ANWPATH_TMP);
     $nCountImportErrors = 0;
     $nCountImportSuccess = 0;
     $bMustRollback = false;
     // only when $bContinueOnErrors = false
     // MAIN TRANSACTION - only when $bContinueOnErrors = false
     if ($bContinueOnErrors) {
         // won't revert whole import if errors
         $bMainTransaction = false;
         // will commit immediately each imported content
         $bSubTransaction = true;
     } else {
         // will revert whole import if errors
         $bMainTransaction = true;
         // won't commit immediately each imported content
         $bSubTransaction = false;
     }
     if ($bMainTransaction) {
         AnwStorage::transactionStart();
     }
     try {
         foreach ($aaData['PAGEGROUPS'] as $aaDataGroup) {
             $sOutBuffer .= $this->tpl()->rowGroupOpen();
             $oFirstPage = null;
             $oContentClass = AnwContentClasses::getContentClass($aaDataGroup['CONTENTCLASS']);
             foreach ($aaDataGroup['PAGES'] as $aaDataPage) {
                 $asNotices = array();
                 $sOriginalPageName = $aaDataPage['NAME'];
                 $sPageName = AnwEnv::_POST($this->getInputPageName($sOriginalPageName));
                 $sPageLang = AnwEnv::_POST($this->getInputPageLang($sOriginalPageName));
                 if (!$sPageName || !$sPageLang) {
                     throw new AnwUnexpectedException("PageName or PageLang not found for imported content: " . $sOriginalPageName);
                 }
                 $sPageContent = $aaDataPage['CONTENT'];
                 //do we want to import this page?
                 if (in_array($sOriginalPageName, $asSelectedPages) && $sPageName && $sPageLang) {
                     //check pagename and content
                     $asNotices = $this->checkPermissions($sPageName, $sPageLang, $sPageContent);
                     if (count($asNotices) == 0) {
                         // SUB TRANSACTION - only when $bContinueOnErrors = true
                         if ($bSubTransaction) {
                             AnwStorage::transactionStart();
                         }
                         try {
                             // create the new page
                             $oContent = $oContentClass->rebuildContentFromXml($sPageContent);
                             if (!$oFirstPage) {
                                 $oPage = AnwPage::createNewPage($oContentClass, $sPageName, $sPageLang, "", $oContent);
                             } else {
                                 $oPage = $oFirstPage->createNewTranslation($sPageName, $sPageLang, "", $oContent);
                             }
                             if ($bSubTransaction) {
                                 AnwStorage::transactionCommit();
                             }
                             // wait for everything to be completed before affecting $oFirstPage, in case of it fails
                             if (!$oFirstPage) {
                                 $oFirstPage = $oPage;
                             }
                         } catch (AnwException $e) {
                             // special errors management, see FS#62
                             $asNotices[] = $this->t_("notice_unknown") . " (" . $e->getMessage() . ")";
                             //print $e->getFile().'!'.$e->getLine();print_r($e->getTrace());
                             if ($bMainTransaction) {
                                 // we will have to rollback, but we still continue to get the whole report
                                 $bMustRollback = true;
                             }
                             if ($bSubTransaction) {
                                 AnwStorage::transactionRollback();
                             }
                             AnwDebug::reportError($e);
                         }
                     }
                     // import result
                     if (count($asNotices) == 0) {
                         $nCountImportSuccess++;
                         // at least we got a success!
                         $sOutBuffer .= $this->tpl()->rowTranslationProcess_success($oPage->link());
                     } else {
                         $nCountImportErrors++;
                         $sOutBuffer .= $this->tpl()->rowTranslationProcess_failed($sPageName, $sPageLang, $asNotices);
                     }
                 } else {
                     $sOutBuffer .= $this->tpl()->rowTranslationProcess_skipped($sPageName, $sPageLang);
                 }
             }
             $sOutBuffer .= $this->tpl()->rowGroupClose();
         }
         if ($bMainTransaction) {
             if (!$bMustRollback) {
                 AnwStorage::transactionCommit();
             } else {
                 AnwStorage::transactionRollback();
             }
         }
     } catch (AnwException $e) {
         AnwStorage::transactionRollback();
         throw $e;
     }
     // output, with import results before the detailled report
     $this->out .= $this->tpl()->beginProcess();
     if ($nCountImportErrors > 0) {
         if ($nCountImportSuccess > 0) {
             if ($bContinueOnErrors) {
                 $this->out .= $this->tpl()->importResultErrorsContinued($nCountImportSuccess, $nCountImportErrors);
             } else {
                 $this->out .= $this->tpl()->importResultErrorsCancelled($nCountImportSuccess, $nCountImportErrors);
             }
         } else {
             $this->out .= $this->tpl()->importResultFailed($nCountImportErrors);
         }
     } else {
         $this->out .= $this->tpl()->importResultSuccess($nCountImportSuccess);
     }
     $this->out .= $this->tpl()->importDetails($sOutBuffer);
 }
Exemple #7
0
 function updateContentFromEdition()
 {
     try {
         //update content from post
         $this->getRender(true);
         //check errors
         if ($this->hasErrors()) {
             throw new AnwInvalidContentException();
         }
         return $this->getContent();
     } catch (AnwInvalidContentException $e) {
         $sError = AnwComponent::g_("err_contentinvalid");
         throw new AnwStructuredContentEditionFormException($sError);
     } catch (AnwAclPhpEditionException $e) {
         $sError = $e->getMessage();
         throw new AnwStructuredContentEditionFormException($sError);
     } catch (AnwUnexpectedException $e) {
         $sError = AnwComponent::g_("err_ex_unexpected_p");
         $nErrorNumber = AnwDebug::reportError($e);
         if ($nErrorNumber) {
             $sError .= '<br/>' . $this->g_("err_ex_report", array("errornumber" => $nErrorNumber));
         }
         throw new AnwStructuredContentEditionFormException($sError);
     }
 }
Exemple #8
0
function errorApp($e)
{
    $bLogEnvAvailable = class_exists("AnwComponent") && class_exists("AnwUtils");
    $nErrorNumber = false;
    if ($bLogEnvAvailable) {
        $nErrorNumber = AnwDebug::reportError($e);
    }
    print '<h1>Error</h1>';
    print '<div style="margin:0px auto; width:550px">';
    /*if ($e instanceof PhpRuntimeException)
    	{
    		print '<h1>Error</h1>';
    		
    		if (class_exists("AnwUtils") && AnwUtils::isViewDebugAuthorized())
    		{
    			print '<div style="margin:0px auto; width:550px">' .
    			'<p>'.$e->getMessage().' ('.get_class($e).')<br/>' .
    			'<span style="font-size:12px">'.$e->getFile().', line '.$e->getLine().'</span></p>' .
    			'</div>';
    		}
    	}
    	*/
    //display error details if user is allowed to view it
    if ($bLogEnvAvailable && AnwUtils::isViewDebugAuthorized() || class_exists("AnwDebug") && AnwDebug::isEmergencyDebugEnabled()) {
        print '<p>' . $e->getMessage() . ' (' . get_class($e) . ')<br/>';
        print '<span style="font-size:12px">' . $e->getFile() . ', line ' . $e->getLine() . '</span>';
        print '</p>';
    } else {
        print '<p>A problem occurred. Please try again later or contact an administrator.<br/>' . 'We apologize for inconvenience.</p>';
    }
    if ($nErrorNumber) {
        print '<p>Error has been logged. Please contact the administrator with the following error number : <b>' . $nErrorNumber . '</b></p>';
    }
    print '</div>';
    //display error trace and debug log if user is allowed to view it
    if ($bLogEnvAvailable && AnwUtils::isViewDebugAuthorized()) {
        //display trace
        print '<p>Trace :<br/><ul>';
        $asTrace = $e->getTrace();
        $bFirst = true;
        foreach ($asTrace as $sTrace) {
            $sCss = $bFirst ? 'color:red' : '';
            print '<li style="font-size:14px;' . $sCss . '">';
            if (isset($sTrace['class'])) {
                print $sTrace['class'];
            }
            if (isset($sTrace['type'])) {
                print $sTrace['type'];
            }
            print $sTrace['function'];
            if (isset($sTrace['args'])) {
                //hide args for security reasons
                foreach ($sTrace['args'] as $i => $sArg) {
                    $sTrace['args'][$i] = 'p' . ($i + 1);
                }
                print '(' . implode($sTrace['args'], ", ") . ')';
            }
            print '<br/><span style="font-size:12px">File ' . @$sTrace['file'] . ', line ' . @$sTrace['line'] . '</span><br/>';
            print '</li>';
            $bFirst = false;
        }
        print '</ul></p>';
        //display debug
        if (class_exists("AnwDebug")) {
            print '<p>Debug :<br/><div style="font-size:12px">' . AnwDebug::getLog() . '</font></p>';
        }
    }
    exit;
}