Example #1
0
 /**
  * function Save.
  * If the $strTextConfig is set, save the config file with this text.
  * Then launch the event manager for event savepage.
  * Finally call the parrent::Save fonction to save the text in the html file.
  *
  * @param string the text of the html file
  * @param string (optional, default false) the text of the config file
  * @return boolean true if suceed, false if an error occured
  */
 function Save($text, $strTextConfig = false)
 {
     $text = stripslashes($text);
     //		$text=str_replace('src="'.SITE_URL,'src="{#SITE_URL#}',$text);
     $strMediasUrl = POFile::getPathUrl(MEDIAS_PATH);
     $text = str_replace('src="' . $strMediasUrl, 'src="{$MEDIAS_URL}', $text);
     $text = str_replace('href="' . $strMediasUrl, 'href="{$MEDIAS_URL}', $text);
     //save the config file, if content has been changed
     $strContentConfig = is_file($this->oPConfigFile->path) ? file_get_contents($this->oPConfigFile->path) : '';
     if ($strTextConfig && $strTextConfig != $strContentConfig) {
         if (!$this->oPConfigFile->Save($strTextConfig)) {
             return false;
         }
     }
     //do not save the page, if content has not been changed
     $strContent = is_file($this->path) ? file_get_contents($this->path) : '';
     if ($text == $strContent) {
         return true;
     }
     //save the history if file exists
     if (is_file($this->path)) {
         // save history folder and file, only one backup per minute
         $iCTime = time();
         $iCTime = $iCTime - date('s', $iCTime);
         //calculate the timestamp for current minute whitout seconds
         $oDirHistoryCache = new PDir(CACHE_HIST_DIR . SLASH . $this->getId() . SLASH . $iCTime);
         //create the directory if not exists
         if (!is_dir($oDirHistoryCache->path)) {
             if (!$oDirHistoryCache->mkdir()) {
                 return false;
             }
         }
         /* html file */
         $oHTMLHistory = new PTextFile($oDirHistoryCache->path . SLASH . basename($this->path));
         if (!$oHTMLHistory->Save($strContent)) {
             return false;
         }
         /* ini file */
         if (is_file($this->oPConfigFile->path)) {
             $oConfigHistory = new PConfigfile($oDirHistoryCache->path . SLASH . basename($this->oPConfigFile->path));
             if (!$oConfigHistory->Save($strContentConfig)) {
                 return false;
             }
         }
     }
     //when saving must load the new file due to cache
     if (doEventAction('savepage', array(&$text, &$this)) === false) {
         return false;
     }
     return parent::Save($text);
 }
Example #2
0
 function Save($strText = false)
 {
     if ($strText === false) {
         $strText = $this->toString();
         if ($strText === false) {
             return false;
         }
     } else {
         //replace break lines by \\n for textarea var
         $tabResult = $this->parseIniFromString(stripslashes($strText));
         $strText = $this->toString($tabResult);
     }
     if (!$this->_Modified($strText)) {
         return true;
     }
     if (!deleteMenuCache()) {
         return false;
     }
     //save without stripslashes
     return parent::Save($strText, false);
 }
Example #3
0
 /**
  * Function: getMenu
  * Generate a table of the structure of the site
  * If adminMode is true take also the not published pages, else take only published page
  * The menu is cached in the menu.cache file as a serialize element, in adminmode the cache is not use,
  * but in production mode only the directory structure is parsed only if menu.cache file not exists. 
  *
  * @rev: 1.0 July 2008
  * 
  * @param adminMode, boolean take or not take the not published pages
  * @return a table of the structure of the web site, each element of the menu contains:
  * NAME of the element, the URL, the ID and the PATH to this element
  *
  */
 function getMenu($adminMode = false)
 {
     $oMenuFile = new PTextFile(SMARTY_CACHE_DIR . 'menu.cache');
     //if tabmenu is in cache and not in admin  mod, load the menu from cache
     if ($adminMode === false && is_file($oMenuFile->path)) {
         if ($strMenu = unserialize(file_get_contents($oMenuFile->path))) {
             return $strMenu;
         }
     }
     $tabMenu =& $this->getMenuFromDir(getFileObject(PAGES_PATH), $adminMode);
     if ($adminMode === false) {
         if (!$oMenuFile->Save(serialize($tabMenu), false)) {
             die(getError());
         }
     }
     return $tabMenu;
 }