/** * 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 Copy($newname, $parent_path = false) { if (!$this->checkName($newname)) { return false; } //check extension $oFile = new PFile($newname); $newname .= $oFile->getExtension() == '' ? '.' . $this->getExtension() : ''; //check parent path access if (!$parent_path) { $parent_path = $this->getParentPath(); } if (!is_writable($parent_path)) { return setError(_("can not copy. Directory not writable.\n Check file permissions.")); } $newfile = $parent_path . SLASH . $newname; if (is_file($newfile) || is_dir($newfile)) { return setError(_("File exists") . ": " . $newname); } if (!copy($this->path, $newfile)) { return setError(_("Error occured while copying file") . ". " . _("Check file permissions") . "."); } return true; }