function __getEditorFormItem($strParam, $strValue, $idForm) { $strType = $this->getParamDescr($strParam, "TYPE", "text"); $bEditable = $this->getParamDescr($strParam, "EDITABLE", "true") == "false" ? false : true; $strEditable = $bEditable ? "" : " style=\"display:none;\" "; $strReturn = '<div class="params"' . $strEditable . ' >' . "\n"; $strReturn .= '<label class="param" >' . _($this->getVarPrintName($strParam)) . ':</label>'; switch ($strType) { case 'boolean': $strChecked = $strValue == "true" ? 'checked' : ''; $strTpl = '<input class="paramvalue" {STYLE} type="checkbox" name="{PARAM_NAME}" id="field_{PARAM_NAME}" value="{PARAM_VALUE}" {CHECKED} onClick="javascript:if(this.checked){this.value=true;}else{this.value=false;} reloadFileConfigTextArea(\'{ID_FORM}\'); "/><br /> <div class="reset"></div> '; $strReturn .= str_replace(array('{CHECKED}', '{STYLE}', '{PARAM_NAME}', '{PARAM_VALUE}', '{ID_FORM}'), array($strChecked, $strEditable, $strParam, $strValue, $idForm), $strTpl); break; case 'list': $strTpl = '<select name="{PARAM_NAME}" class="paramvalue" {STYLE} id="field_{PARAM_NAME}" onChange="reloadFileConfigTextArea(\'{ID_FORM}\');"> {LIST_ITEMS} </select> <br /><div class="reset"></div> '; $strList = ''; $strListTpl = ' <option value="{PARAM_VALUE}" {SELECTED}>{PARAM_NAME}</option> '; $tabValues = explode(",", $this->getParamDescr($strParam, "LIST_VALUES", $strValue)); foreach ($tabValues as $val) { $strListVal = ''; $strListParam = ''; if (preg_match('/=>/', $val)) { $tabPV = explode('=>', $val); $strListVal = $tabPV[1]; $strListParam = $tabPV[0]; if ($strListParam == 'list_files') { //first search in theme dir then in medias path $strDirPath = is_dir($strListVal) ? $strListVal : SITE_PATH . THEME_DIR . $strListVal; $strDirPath = is_dir($strDirPath) ? $strDirPath : MEDIAS_PATH . SLASH . $strListVal; if (is_dir($strDirPath)) { $pDirList = new PDir($strDirPath); $tabListFiles = $pDirList->listDir($pDirList->ONLY_FILES, false); foreach ($tabListFiles as $strFile) { $oFile = new PFile($strFile); $strSelected = $strFile == $strValue ? 'SELECTED' : ''; $strList .= str_replace(array('{SELECTED}', '{PARAM_NAME}', '{PARAM_VALUE}'), array($strSelected, $oFile->getNameWithoutExt(), $strFile), $strListTpl); } } } else { $strSelected = $strListVal == $strValue ? 'SELECTED' : ''; $strList .= str_replace(array('{SELECTED}', '{PARAM_NAME}', '{PARAM_VALUE}'), array($strSelected, $strListParam, $strListVal), $strListTpl); } } else { $strListParam = $val; $strListVal = $val; $strSelected = $strListVal == $strValue ? 'SELECTED' : ''; $strList .= str_replace(array('{SELECTED}', '{PARAM_NAME}', '{PARAM_VALUE}'), array($strSelected, $strListParam, $strListVal), $strListTpl); } } $strReturn .= str_replace(array('{LIST_ITEMS}', '{STYLE}', '{PARAM_NAME}', '{PARAM_VALUE}', '{ID_FORM}'), array($strList, $strEditable, $strParam, $strValue, $idForm), $strTpl); break; case 'password': $strTpl = '<input class="paramvalueText paramvalue" {STYLE} onChange="reloadFileConfigTextArea(\'{ID_FORM}\');" type="password" name="{PARAM_NAME}" id="field_{PARAM_NAME}" value="{PARAM_VALUE}" /><br /> <div class="reset"></div> '; $strReturn .= str_replace(array('{STYLE}', '{PARAM_NAME}', '{PARAM_VALUE}', '{ID_FORM}'), array($strEditable, $strParam, $strValue, $idForm), $strTpl); break; case 'textarea': $strTpl = '<textarea name="{PARAM_NAME}" id="field_{PARAM_NAME}" class="paramvalue paramvalueTextArea" wrap="off" onChange="reloadFileConfigTextArea(\'{ID_FORM}\');" >{PARAM_VALUE}</textarea> <br /><div class="reset"></div> '; $strReturn .= str_replace(array('{STYLE}', '{PARAM_NAME}', '{PARAM_VALUE}', '{ID_FORM}'), array($strEditable, $strParam, $strValue, $idForm), $strTpl); break; case 'text': $strTpl = '<input class="paramvalueText paramvalue" {STYLE} onChange="reloadFileConfigTextArea(\'{ID_FORM}\');" type="text" name="{PARAM_NAME}" id="field_{PARAM_NAME}" value="{PARAM_VALUE}" /><br /> <div class="reset"></div> '; $strReturn .= str_replace(array('{STYLE}', '{PARAM_NAME}', '{PARAM_VALUE}', '{ID_FORM}'), array($strEditable, $strParam, $strValue, $idForm), $strTpl); break; } //end switch return $strReturn . "\n</div>\n"; }
/** * Rename the page. * This function is called to rename the page. * If the new name of the page contains specific caracters as éà, it is replace by ea, * but the menu name is set with special caracters * An event is attached to this fonction: renamepage * This event is used for example by the search engine plugin to index the file content. * * The difference between move and rename, is that in move do not set the menu title !! * @param string $newname, the new name (basename) * @param string $destDir, if == false the parent dir * @return true if suceed */ function Rename($newname, $destDir = false) { $fileNewName = $this->getUnixName($newname); $pageNewName = $newname; $pageCurrName = $this->getVirtualName(); $fileCurrName = $this->getName(); if (strlen($fileNewName) == 0) { return setError(_('Can not rename with empty name')); } //manage extensions $oFile = new PFile($fileNewName); if ($oFile->getExtension() == '') { $fileNewName .= '.' . $this->getExtension(); } else { $oFile = new PFile($pageNewName); $pageNewName = $oFile->getNameWithoutExt(); } if ($fileNewName == $fileCurrName && $pageCurrName == $pageNewName && $destDir === false) { return true; } //check the name is valid, not a php file or a cgi one for example if (!$this->checkname($pageNewName)) { return false; } //set the menu name in the ini file if has been renamed !! not moved if (!$destDir && !$this->setVirtualName($pageNewName)) { return false; } if ($fileCurrName != $fileNewName || $destDir !== false) { //if history dir exists, rename it $oDirHistoryCache = new PDir(CACHE_HIST_DIR . SLASH . $this->getId()); if (is_dir($oDirHistoryCache->path)) { $destDirModify = !$destDir ? $this->getParentPath() : $destDir; if (substr($destDirModify, -1) == SLASH) { $destDirModify = substr($destDirModify, 0, strlen($destDirModify) - 1); } $oPageNewHistory = new PPage($destDirModify . SLASH . $fileNewName); $strNewHistoryName = $oPageNewHistory->getId(); if ($this->getId() != $strNewHistoryName) { if (!$oDirHistoryCache->Rename($strNewHistoryName)) { return false; } } } if (!doEventAction('renamepage', array(&$this, ($destDir ? $destDir : $this->getParentPath()) . SLASH . $fileNewName))) { return false; } //on supprime le cache du menu if (!deleteMenuCache()) { return false; } //rename the config file if exists if (is_file($this->oPConfigFile->path)) { $oFileTmp = new PFile($fileNewName); if (!$this->oPConfigFile->Rename($oFileTmp->getNameWithoutExt() . ".ini", $destDir)) { return false; } } if (!parent::Rename($fileNewName, $destDir)) { return false; } } return true; }
function Rename($newname, $destDir = false) { $fileNewName = $this->getUnixName($newname); $pageNewName = $newname; $pageCurrName = $this->getVirtualName(); $fileCurrName = $this->getName(); if (strlen($fileNewName) == 0) { return setError(_("Can not rename with empty name")); } if ($fileNewName == $fileCurrName && $pageCurrName == $fileCurrName && $destDir === false) { return false; } //set the menu name in the ini file if needed if (!$destDir && !$this->setVirtualName($pageNewName)) { return false; } //if the directory has changed (move in an other one, or rename) if ($fileCurrName != $fileNewName || $destDir !== false) { //Change the virtual name if (!$destDir && !$this->oPConfigFile->setParam('VIRTUAL_NAME', $pageNewName)) { return false; } if (!$this->oPConfigFile->Save()) { return false; } //rename the config file if exists if (is_file($this->oPConfigFile->path)) { $oFileTmp = new PFile($fileNewName); if (!$this->oPConfigFile->Rename($oFileTmp->getNameWithoutExt() . ".ini", $destDir)) { return false; } } //delete the menu cache if (!deleteMenuCache()) { return false; } if (!parent::Rename($fileNewName, $destDir)) { return false; } } return true; }
/** * Rename a file. If the newname has no file extension, use the current file extension. * If destDir not set, use the current file directory. If set move the file to the * destdir. * * @param string $strNewName, the new name of the file. * @param string $destDir, the path of the destination directory, if false, the parent path * @return true if succeed, else false */ function Rename($strNewName, $destDir = false) { $strNewName = $this->getUnixName($strNewName); $strActionName = !$destDir || $destDir == $this->getParentPath() ? 'rename' : 'move'; //check name if (!$this->checkname($strNewName)) { return false; } //check extension $oFile = new PFile($strNewName); $strNewName .= $oFile->getExtension() == '' ? '.' . $this->getExtension() : ''; if (strlen($oFile->getNameWithoutExt()) == 0) { return setError(_("Can not {$strActionName} with empty name.")); } //check destDir $destDir = !$destDir ? $this->getParentPath() : $destDir; $objDstDir = new PDir($destDir); if (!$objDstDir->isDir()) { return setError(sprintf(_("Can not {$strActionName} file.\nDirectory not %s exists."), $objDstDir->getRelativePath())); } if (!is_writable($objDstDir->path)) { return setError(sprintf(_("Can not {$strActionName} file %s.\nDirectory is not %s writable."), $objDstDir->getRelativePath())); } //check write accesses if (!is_writable($this->path)) { return setError(sprintf(_("Can not {$strActionName} file %s.\n"), $this->getRelativePath())); } $newfile = $destDir . SLASH . $strNewName; if ($this->path == $newfile) { return true; } if (file_exists($newfile)) { return setError(sprintf(_("File: %s exists."), basename($newfile))); } if (!@rename($this->path, $newfile)) { return setError(_("An error occured while renaming file")); } $this->path = $newfile; return true; }
/** * This function is called each time a file is created or renamed * * @param $strName, the name to check, or if = false, check the object file name * @return true if name is ok */ function checkName($strName = false) { if (!$strName) { $strName = basename($this->path); } $oFile = new PFile($strName); if (!preg_match('/^[a-zA-Z0-9\\.\\s_-]*$/', $oFile->getNameWithoutExt())) { return setError(_('Special chars are not allowed.')); } if (strlen($oFile->getNameWithoutExt()) == 0) { return setError(_('Empty name is not allowed')); } return $this->checkExtension($strName); }