示例#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);
 }
示例#2
0
 static function setTraceEnabled($bEnabled)
 {
     self::$bTraceEnabled = $bEnabled;
     if (!$bEnabled) {
         self::$log = array();
     }
 }
示例#3
0
 static function tag_anwloop($sMatch, $sContentClass, $asLangs, $nLimit, $sSortUser, $sOrder, $asFilters)
 {
     AnwDebug::startBench("anwloop", true);
     $oContentClass = AnwContentClasses::getContentClass($sContentClass);
     $aoPages = AnwStorage::fetchPagesByClass(array($sMatch), $oContentClass, $asLangs, $nLimit, $sSortUser, $sOrder, $asFilters);
     AnwDebug::stopBench("anwloop");
     return $aoPages;
 }
示例#4
0
 function __construct($sMsg = "")
 {
     parent::__construct($sMsg);
     if (class_exists('AnwDebug') && AnwDebug::isEmergencyDebugEnabled()) {
         print "AnwUnexpectedException:" . $sMsg . "<br/>";
     }
     AnwDebug::log("**** new UnexpectedException: " . $sMsg . " ****");
 }
示例#5
0
 /**
  * Load group's pages information from meta file.
  */
 private function loadInfo()
 {
     if ($this->bInfoLoaded) {
         return;
     }
     try {
         //get PageGroup from storage system
         if (!$this->nId) {
             throw new AnwPageGroupNotFoundException();
         }
         AnwDebug::log("(AnwPageGroup)Loading PageGroup info...");
         $oPageGroup = AnwStorage::getPageGroup($this->nId);
         //PageGroup exists, update it's attributes
         $this->bExists = true;
         $this->sContentClass = $oPageGroup->getContentClassName();
         $this->aoPages = $oPageGroup->getPages();
     } catch (AnwPageGroupNotFoundException $e) {
         //PageGroup doesn't exist
         $this->bExists = false;
         $this->aoPages = array();
     }
     $this->bInfoLoaded = true;
 }
 private static function debug($sMessage)
 {
     return AnwDebug::log("(AnwContentClass)" . $sMessage);
 }
示例#7
0
 private function debug($sMsg)
 {
     AnwDebug::log("(AnwParser) " . $sMsg);
 }
示例#8
0
 private static function debug($sMessage)
 {
     return AnwDebug::log("(AnwStorage)" . $sMessage);
 }
示例#9
0
 protected static function debug($sMsg)
 {
     AnwDebug::log("(AnwCache) " . $sMsg);
 }
示例#10
0
 protected static function debug($sMessage)
 {
     return AnwDebug::log("(AnwPage)" . $sMessage);
 }
示例#11
0
 private static function debug($sInfo)
 {
     AnwDebug::log('(AnwEnv)' . $sInfo);
 }
示例#12
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);
 }
示例#13
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);
     }
 }
示例#14
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;
}
示例#15
0
 private function xmlDiff($node1, $node2, $bFindMovedEdited)
 {
     $aoDiffs = self::xmlDiffBasic($node1, $node2);
     if ($bFindMovedEdited) {
         /*print "************1. BEFORE MOVED**************".'<ul style="font-size:12px; font-family:verdana">';
         		foreach ($aoDiffs as $oDiff){
         			print $oDiff->debugHtml();
         		}
         		print '</ul>';*/
         //must wait to have the whole diffs tree to search for moved nodes
         AnwDebug::startBench("findMovedNodes", true);
         $aoDiffs = self::findMovedNodes($aoDiffs);
         //find moved nodes
         AnwDebug::stopBench("findMovedNodes");
         /*print "************2. BEFORE EDITED**************".'<ul style="font-size:12px; font-family:verdana">';
         		foreach ($aoDiffs as $oDiff){
         			print $oDiff->debugHtml();
         		}
         		print '</ul>';*/
         AnwDebug::startBench("findEditedNodes", true);
         $aoDiffs = self::findEditedNodes($aoDiffs);
         //now find edited nodes
         AnwDebug::stopBench("findEditedNodes");
         /*print "************3. AFTER EDITED**************".'<ul style="font-size:12px; font-family:verdana">';
         		foreach ($aoDiffs as $oDiff){
         			print $oDiff->debugHtml();
         		}
         		print '</ul>';*/
     }
     return $aoDiffs;
 }
示例#16
0
 protected function debug($sMessage)
 {
     return AnwDebug::log("(" . get_class($this) . ")" . $sMessage);
 }
示例#17
0
 protected static function debug($sMsg)
 {
     AnwDebug::log("(ContentField)" . $sMsg);
 }
示例#18
0
 static function getCachedComponentsMapping()
 {
     $sCacheFile = self::filenameCachedComponentsMapping();
     if (!file_exists($sCacheFile)) {
         throw new AnwCacheNotFoundException();
     }
     //mapping must be newer than override-global-settings
     if (filemtime($sCacheFile) < filemtime(AnwUtils::getFileOverride("global.cfg.php", AnwComponent::getGlobalComponentFullDir()))) {
         AnwDebug::log("cachedComponentsMapping obsoleted by settings");
         throw new AnwCacheNotFoundException();
     }
     //TODO: mapping should be expired by each modified available component?
     //load it from cache
     $oObject = (array) self::getCachedObject($sCacheFile);
     if (!is_array($oObject)) {
         AnwDebug::log("cachedComponentsMapping invalid : " . $sCacheFile);
         throw new AnwCacheNotFoundException();
     } else {
         AnwDebug::log("cachedComponentsMapping found : " . $sCacheFile);
     }
     return $oObject;
 }
示例#19
0
 protected function debug($sMsg)
 {
     AnwDebug::log("(AnwOutput) " . $sMsg);
 }
示例#20
0
 protected static function debug($sMsg)
 {
     AnwDebug::log("(AnwAction)" . "(" . get_class(self::getInstance()) . ")" . $sMsg);
 }
示例#21
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);
}
示例#22
0
 private static function applyDiffsToTranslation($oRootNode, $oDiffs, $oContentField)
 {
     //AnwDebug::log("Applying diffs to : ".htmlentities(AnwUtils::xmlDumpNode($oRootNode)));
     $aoDiffs = $oDiffs->getAllDiffs();
     $oChildNodes = $oRootNode->childNodes;
     $i = 0;
     foreach ($aoDiffs as $oDiff) {
         $oChild = $oChildNodes->item($i);
         if (!$oChild) {
             //AnwDebug::logdetail("oChild=null");
         }
         AnwDebug::logdetail("//step dump: " . htmlentities(AnwUtils::xmlDumpNode($oRootNode)));
         $sDiffType = $oDiff->getDiffType();
         $bSkipIncrement = false;
         switch ($sDiffType) {
             case AnwDiff::TYPE_ADDED:
                 if ($oDiff->hasSubMovedNode()) {
                     $oNodeRef = $oDiff->getNode();
                     $oNewNode = $oRootNode->ownerDocument->createElement($oNodeRef->nodeName);
                     //no need to check for UnmodifiableBlockNodes, a comment/php node can't have submoved nodes
                     AnwXml::xmlCopyNodeAttributes($oNodeRef, $oNewNode);
                     //recursive call for SubAdded nodes
                     AnwDebug::log(" * SUBADDED : " . htmlentities(AnwUtils::xmlDumpNode($oNewNode)));
                     if ($oChild) {
                         AnwDebug::logdetail("added->insertBefore : before=" . htmlentities(AnwUtils::xmlDumpNode($oChild)));
                         $oRootNode->insertBefore($oNewNode, $oChild);
                     } else {
                         AnwDebug::logdetail("added->appendChild");
                         $oRootNode->appendChild($oNewNode);
                     }
                     //continue on subadded diffs
                     self::applyDiffsToTranslation($oNewNode, $oDiff, $oContentField);
                 } else {
                     //quick test for special case with xmlIsUnmodifiableBlockNode
                     $oTmpNode = $oDiff->getMovedNode() ? $this->getMovedNode() : $oDiff->getNode();
                     if (AnwXml::xmlIsUnmodifiableBlockNode($oTmpNode)) {
                         //keep it unchanged
                         $oNodeToImport = $oTmpNode;
                     } else {
                         //mark it as untranslated only if translatable (contentfield check)
                         $bMarkAsUntranslated = AnwXml::xmlAreTranslatableAncestors($oRootNode, $oContentField);
                         //TODO: move code from getNodeWithTranslateTags() here
                         $oNodeToImport = $oDiff->getNodeWithTranslateTags($bMarkAsUntranslated, $oContentField);
                     }
                     $oNewNode = $oRootNode->ownerDocument->importNode($oNodeToImport, true);
                     AnwDebug::log(" * ADDED : " . htmlentities(AnwUtils::xmlDumpNode($oNewNode)));
                     if ($oChild) {
                         AnwDebug::logdetail("added->insertBefore : before=" . htmlentities(AnwUtils::xmlDumpNode($oChild)));
                         $oRootNode->insertBefore($oNewNode, $oChild);
                     } else {
                         AnwDebug::logdetail("added->appendChild");
                         $oRootNode->appendChild($oNewNode);
                     }
                 }
                 break;
             case AnwDiff::TYPE_MOVED:
                 //No need to import node as we get a node from the same document
                 $oMovedNode = $oDiff->getMovedNode();
                 //tmp check
                 if (!$oMovedNode) {
                     //print AnwDebug::log('-----'.AnwUtils::xmlDumpNode($oDiff->getDiffDeleted()->getNode()));
                     AnwDebug::log("****ERROR**** getMovedNode() returned NULL on AnwDiffMoved !");
                     throw new AnwUnexpectedException("ERROR getMovedNode() returned NULL on AnwDiffMoved !");
                     break;
                 }
                 AnwDebug::log(" * MOVED : " . htmlentities(AnwUtils::xmlDumpNode($oMovedNode)));
                 //did the textlayout change?
                 if ($oDiff->hasTextLayoutChanged()) {
                     //we need to apply the new textlayout...
                     $oMovedNode->nodeValue = AnwXml::xmlPreserveTextLayout($oMovedNode->nodeValue, $oDiff->getTextLayoutReferenceValue());
                 }
                 //the following operations will MOVE the node into the document
                 if ($oChild) {
                     AnwDebug::log("added->insertBefore" . htmlentities(AnwUtils::xmlDumpNode($oMovedNode)));
                     $oRootNode->insertBefore($oMovedNode, $oChild);
                 } else {
                     AnwDebug::logdetail("added->appendChild");
                     if (!$oRootNode->appendChild($oMovedNode)) {
                         throw new AnwUnexpectedException("appendChild failed");
                     }
                 }
                 break;
             case AnwDiff::TYPE_DELETED:
                 //if (!$oDiff->getMovedDiff())
                 //{
                 AnwDebug::logdetail(" * DELETED : " . htmlentities(AnwUtils::xmlDumpNode($oDiff->getNode())) . " == " . htmlentities(AnwUtils::xmlDumpNode($oChild)));
                 //if (!$oRootNode->removeChild($oChild)) throw new AnwUnexpectedException("removeChild failed");
                 //$bSkipIncrement = true;
                 // !!! We don't delete nodes now, because we may need it if it contains moved nodes...
                 // these nodes will be deleted later
                 ////self::$aoNodesMarkedForDeletion[] = array($oRootNode,$oChild);
                 if (!$oRootNode->removeChild($oChild)) {
                     throw new AnwUnexpectedException("removeChild failed");
                 }
                 $bSkipIncrement = true;
                 //}
                 //else
                 //{
                 //	AnwDebug::log(" * DELETED : deletion skipped (node will be moved)");
                 //}
                 break;
             case AnwDiff::TYPE_KEPT:
                 //don't touch anything
                 AnwDebug::log(" * KEPT : " . htmlentities(AnwUtils::xmlDumpNode($oDiff->getNode())) . " == " . htmlentities(AnwUtils::xmlDumpNode($oChild)));
                 break;
             case AnwDiff::TYPE_EDITED:
                 AnwDebug::log(" * EDITED : " . htmlentities(AnwUtils::xmlDumpNode($oChild)) . " == " . htmlentities(AnwUtils::xmlDumpNode($oDiff->getDiffAdded()->getNode())));
                 //TODO: warning, this code is very crappy and needs to be cleaned and tested
                 //update attributes
                 $oNodeRef = $oDiff->getDiffAdded()->getNode();
                 if (AnwXml::xmlIsUnmodifiableBlockNode($oChild)) {
                     $oNewNode = AnwXml::xmlReplaceUnmodifiableBlockNode($oChild, $oNodeRef);
                 } else {
                     if (!AnwXml::xmlIsTextNode($oChild)) {
                         throw new AnwUnexpectedException("not a text node in TYPE_EDITED");
                     }
                     if ($oDiff->isEmpty() || !AnwXml::xmlAreTranslatableAncestors($oRootNode, $oContentField)) {
                         AnwDebug::log("//edited : empty/untranslatable content, copying value but keeping it as translated");
                         //copy new value, but keep it as translated
                         $oNewNode = AnwXml::xmlReplaceTextNode($oChild, $oNodeRef);
                     } else {
                         if ($oDiff->getDiffDeleted()->getMovedDiff()) {
                             //special - consider it as an added node : set new value & mark this as untranslated
                             AnwDebug::log("//edited : special case, considering as added node");
                             $oNewNode = AnwXml::xmlReplaceTextNode($oChild, $oNodeRef);
                             $oNewNode = AnwXml::xmlSetTextUntranslated($oNewNode, true);
                         } else {
                             //content has really changed, mark it as untranslated if translatable (contentfield check)
                             //current node is translatable... set new value & mark this as untranslated
                             if ($oChild->nodeValue != $oNodeRef->nodeValue) {
                                 //we need to check if text has really changed, or if it's just some layout (spaces, breaklines...) which changed the nodeValue...
                                 $oNodeRefOld = $oDiff->getDiffDeleted()->getNode();
                                 if (AnwXml::xmlTrimTextLayout($oNodeRefOld->nodeValue) == AnwXml::xmlTrimTextLayout($oNodeRef->nodeValue)) {
                                     AnwDebug::log("//edited : case 3.1, only textLayout has changed");
                                     $sOldValue = $oChild->nodeValue;
                                     //content has not really changed, we just added/removed a space, tab, line break before/after the text value
                                     //ex: "blah blah\n" --> "blah blah\n\n"
                                     //we silently apply the new text layout, without turning it untranslated
                                     $oChild->nodeValue = AnwXml::xmlPreserveTextLayout($oChild->nodeValue, $oNodeRef->nodeValue);
                                 } else {
                                     AnwDebug::log("//edited : case 3.2, content has really changed");
                                     $oNewNode = AnwXml::xmlReplaceTextNode($oChild, $oNodeRef);
                                     $oNewNode = AnwXml::xmlSetTextUntranslated($oNewNode, true);
                                 }
                             }
                             /*
                             							//current node is translatable... keep CURRENT value and mark it as untranslated
                             							$oNewNode = $oChild;
                             							if ($oNewNode->nodeValue != $oNodeRef->nodeValue)
                             							{
                             								$oNewNode = AnwXml::xmlSetTextUntranslated($oNewNode, true);
                             							}*/
                         }
                     }
                 }
                 break;
             case AnwDiff::TYPE_DIFFS:
                 $oNodeDiffRef = $oDiff->getNodeRootNew();
                 AnwDebug::log(" * DIFFS : " . htmlspecialchars(AnwUtils::xmlDumpNode($oNodeDiffRef)) . " == " . htmlentities(AnwUtils::xmlDumpNode($oChild)));
                 //update attributes
                 AnwXml::xmlCopyNodeAttributes($oNodeDiffRef, $oChild);
                 //recursive call
                 self::applyDiffsToTranslation($oChild, $oDiff, $oContentField);
                 break;
             default:
                 AnwDebug::log("ERROR - Unknown DiffType :" . $sDiffType);
         }
         //just to prevent erros...
         unset($oNewNode);
         unset($oNodeRef);
         if (!$bSkipIncrement) {
             //AnwDebug::logdetail(" * Loop i++");
             $i++;
             //AnwDebug::logdetail("//step dump_end : ".htmlentities(AnwUtils::xmlDumpNode($oRootNode)));
         }
         //AnwDebug::log("Loop[$i] applydiffs intermediate result : ".htmlentities(AnwUtils::xmlDumpNode($oRootNode)));
     }
     //AnwDebug::log("applydiffs result : ".htmlentities(AnwUtils::xmlDumpNode($oRootNode)));
     return $oRootNode;
 }
示例#23
0
 private static function debug($sMsg)
 {
     AnwDebug::log("(AnwSessions)" . $sMsg);
 }
示例#24
0
 protected function debug($sMsg)
 {
     AnwDebug::log("(AnwDependancy)" . $sMsg);
 }
示例#25
0
 private static function debug($sMessage)
 {
     AnwDebug::log("(AnwPlugins)" . $sMessage);
 }
示例#26
0
 protected function debug($sMessage)
 {
     return AnwDebug::log("(AnwUser)" . $sMessage);
 }
示例#27
0
 private static function loadCurrentSession()
 {
     AnwDebug::startbench("Current session load");
     try {
         self::$oSession = AnwSessions::getCurrentSession();
         //keepalive
         $nElapsedTimeSinceKeepalive = time() - self::getLastKeepAlive();
         $nKeepAliveInterval = AnwComponent::globalCfgKeepaliveDelay();
         AnwDebug::log('(AnwSessions) Time elapsed since last keepalive: ' . $nElapsedTimeSinceKeepalive . '/' . $nKeepAliveInterval . 's');
         if ($nElapsedTimeSinceKeepalive > $nKeepAliveInterval) {
             AnwDebug::log('(AnwSessions) Running keepalive...');
             $nTime = time();
             self::resetLastKeepAlive();
             //keepalive session
             AnwSessions::keepAlive();
             //run hooks
             $oSessionUser = self::$oSession->getUser();
             AnwPlugins::hook("session_keepalive_any", $oSessionUser);
             if (self::$oSession->isLoggedIn()) {
                 AnwPlugins::hook("session_keepalive_loggedin", $oSessionUser);
             } else {
                 AnwPlugins::hook("session_keepalive_loggedout", $oSessionUser);
             }
         }
     } catch (AnwUserNotFoundException $e) {
         //current user doesn't exist anymore
         self::$oSession = new AnwSession();
         self::logout();
     }
     AnwDebug::stopbench("Current session load");
 }
示例#28
0
 private static function loadTranslationsFromFile($sFileName, $sLang, $sPrefix, $sTranslationName)
 {
     $lang = array();
     //$lang is defined in the translation file
     AnwDebug::log("Loading translation file : " . $sFileName);
     (require_once $sFileName) or die("Unable to load language file : " . $sFileName);
     foreach ($lang as $sTranslationId => $sTranslationValue) {
         if ($sLang == AnwCurrentSession::getLang()) {
             //we store ANY translationid for session lang
             self::$translations[$sLang][$sPrefix][$sTranslationId] = $sTranslationValue;
         } else {
             //for other langs, we only store LOCAL translations
             if (self::isLocalTranslation($sTranslationId)) {
                 self::$translations[$sLang][$sPrefix][$sTranslationId] = $sTranslationValue;
             } else {
                 if (!isset(self::$translations[AnwCurrentSession::getLang()][$sPrefix][$sTranslationId])) {
                     self::$translations[$sLang][$sPrefix][$sTranslationId] = $sTranslationValue;
                 }
             }
         }
     }
 }
示例#29
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);
     }
 }
示例#30
0
 function saveTranslation_onTextValue($oRootNode, $sFieldInput)
 {
     //escape < and >
     $sTranslatedValue = $this->getTranslatedValueFromPost($sFieldInput);
     $bTranslated = (int) AnwEnv::_POST("done-" . $sFieldInput) == 1 ? true : false;
     //deny empty values to avoid unsync
     if (trim($sTranslatedValue) == "") {
         $sTranslatedValue = self::EMPTY_VALUE;
     }
     AnwDebug::log(" --> {$sFieldInput} : " . ($bTranslated ? "TRANSLATED" : "UNTRANSLATED") . " : " . $sTranslatedValue . " ( was " . $oRootNode->nodeValue . ")");
     //$oRootNode->nodeValue = $sTranslatedValue;
     $oRootNode = AnwXml::xmlReplaceTextNodeValue($oRootNode, $sTranslatedValue);
     $oRootNode = AnwXml::xmlSetTextUntranslated($oRootNode, !$bTranslated);
     //xml structure is now modified
 }