예제 #1
0
 static function setTraceEnabled($bEnabled)
 {
     self::$bTraceEnabled = $bEnabled;
     if (!$bEnabled) {
         self::$log = array();
     }
 }
예제 #2
0
 function __construct($sMsg = "")
 {
     parent::__construct($sMsg);
     if (class_exists('AnwDebug') && AnwDebug::isEmergencyDebugEnabled()) {
         print "AnwUnexpectedException:" . $sMsg . "<br/>";
     }
     AnwDebug::log("**** new UnexpectedException: " . $sMsg . " ****");
 }
예제 #3
0
 static function isCurrentPage($sPageName)
 {
     try {
         $sCurrentPage = AnwActionPage::getCurrentPageName();
         if ($sPageName == $sCurrentPage) {
             AnwDebug::log("isCurrentPage (" . $sPageName . ") : YES (currently " . $sCurrentPage . ")");
             return true;
         }
         //check translations if page exists
         $oPage = new AnwPageByName($sCurrentPage);
         if ($oPage->exists()) {
             $aoPages = $oPage->getPageGroup()->getPages();
             foreach ($aoPages as $oPageTranslation) {
                 if ($oPageTranslation->getName() == $sPageName) {
                     AnwDebug::log("isCurrentPage (" . $sPageName . ") : YES (currently " . $sCurrentPage . ")");
                     return true;
                 }
             }
         }
     } catch (AnwException $e) {
     }
     AnwDebug::log("isCurrentPage (" . $sPageName . ") : NO (currently " . $sCurrentPage . ")");
     return false;
 }
예제 #4
0
 protected static function debug($sMsg)
 {
     AnwDebug::log("(ContentField)" . $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;
 }
예제 #6
0
 private function debug($sMsg)
 {
     AnwDebug::log("(AnwParser) " . $sMsg);
 }
예제 #7
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");
 }
예제 #8
0
 private static function debug($sMsg)
 {
     AnwDebug::log("(AnwSessions)" . $sMsg);
 }
예제 #9
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);
}
예제 #10
0
function loadAppSafe($sFileName)
{
    (require_once $sFileName) or die("Unable to load " . $sFileName);
    if (class_exists("AnwDebug")) {
        AnwDebug::log("loadApp: " . $sFileName);
    }
}
예제 #11
0
 protected function debug($sMessage)
 {
     return AnwDebug::log("(" . get_class($this) . ")" . $sMessage);
 }
예제 #12
0
 protected static function debug($sMessage)
 {
     return AnwDebug::log("(AnwPage)" . $sMessage);
 }
예제 #13
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;
 }
예제 #14
0
 protected function debug($sMsg)
 {
     AnwDebug::log("(AnwOutput) " . $sMsg);
 }
예제 #15
0
 protected function debug($sMsg)
 {
     AnwDebug::log("(AnwDependancy)" . $sMsg);
 }
예제 #16
0
 private static function debug($sInfo)
 {
     AnwDebug::log('(AnwEnv)' . $sInfo);
 }
예제 #17
0
 private static function debug($sMessage)
 {
     AnwDebug::log("(AnwPlugins)" . $sMessage);
 }
예제 #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($sMessage)
 {
     return AnwDebug::log("(AnwUser)" . $sMessage);
 }
예제 #20
0
 protected static function debug($sMsg)
 {
     AnwDebug::log("(AnwAction)" . "(" . get_class(self::getInstance()) . ")" . $sMsg);
 }
예제 #21
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;
                 }
             }
         }
     }
 }
예제 #22
0
 protected static function debug($sMsg)
 {
     AnwDebug::log("(AnwCache) " . $sMsg);
 }
예제 #23
0
 private static function debug($sMessage)
 {
     return AnwDebug::log("(AnwContentClass)" . $sMessage);
 }
예제 #24
0
 private static function debug($sMessage)
 {
     return AnwDebug::log("(AnwStorage)" . $sMessage);
 }
예제 #25
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
 }