Example #1
0
function savesiteconfig()
{
    if (!isset($_REQUEST['text'])) {
        return setError('Internal Error in savesiteconfig.text is not defined');
    }
    $strText = stripslashes($_REQUEST['text']);
    $oIniFileTmp = new PConfigfile(CACHE_DIR . 'tmpconfig.ini');
    if (!$oIniFileTmp->Save($strText)) {
        return false;
    }
    if (!$oIniFileTmp->parse()) {
        return false;
    }
    $tabNewParams = $oIniFileTmp->getTabParams();
    $oIniFileTmp->Delete();
    global $configFile;
    foreach ($tabNewParams as $k => $v) {
        $configFile->setParam($k, $v);
    }
    if (!$configFile->Save()) {
        return false;
    }
    echo _("Site configuration has been saved !");
    return true;
}
Example #2
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);
 }