function getHistoryList() { if (!is_file($this->path)) { return array(); } $oDirHistory = new PDir(CACHE_HIST_DIR . $this->getId()); $tabReturn = array(); //the current version, before editing $tabReturn[] = array('PATH' => $this->path, 'PRINTNAME' => _('Last Version')); if ($oDirHistory->isDir()) { $tabList = array_reverse($oDirHistory->listDir($oDirHistory->ONLY_DIR)); foreach ($tabList as $strDirHistoryVersion) { $pDirVersion = new PDir($strDirHistoryVersion); $listFiles = $pDirVersion->listDir($oDirHistory->ONLY_FILES, true, $filter = '\\.htm[l]?$'); if (sizeof($listFiles) > 0) { $iFileTime = basename($pDirVersion->path); $strDay = date('Y-m-d', time()) == date('Y-m-d', $iFileTime) ? _('today at') : date(_('Y-m-d'), $iFileTime); $strPrintName = $strDay . ' ' . date(_('H:i'), $iFileTime); $tabReturn[] = array('PATH' => $listFiles[0], 'PRINTNAME' => $strPrintName); } } } return $tabReturn; }
/** * 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; }