?? cvs.php
字號:
closedir( $d ); sort( $namelist, SORT_STRING ); return $namelist; } /** * Recursively create all directories. */ function _mkdir( $path, $mode ) { $directoryName = dirname( $path ); if ( $directoryName != "/" && $directoryName != "\\" && !is_dir( $directoryName ) && $directoryName != "" ) { $rVal = $this->_mkdir( $directoryName, $mode ); } else { $rVal = true; } return ($rVal && @mkdir( $path, $mode ) ); } /** * Recursively create all directories and then the file. */ function _createFile( $path, $mode ) { $this->_mkdir( dirname( $path ), $mode ); touch( $path ); chmod( $path, $mode ); } /** * The lord giveth, and the lord taketh. */ function _deleteFile( $filename ) { if( $fd = fopen($filename, 'a') ) { $locked = flock($fd,2); // Exclusive blocking lock if (!$locked) { $this->_cvsError("Unable to delete file, lock was not obtained.", __LINE__, $filename, EM_NOTICE_ERRORS ); } if ( ($rVal = unlink( $filename )) != 0 ) { $this->_cvsDebug( "[$filename] --> Unlink returned [$rVal]" ); } return $rVal; } else { $this->_cvsError( "deleteFile: Unable to open file", __LINE__, $filename, EM_NOTICE_ERRORS ); return false; } } /** * Called when something happened that causes the CVS backend to * fail. */ function _cvsError( $msg = "no message", $errline = 0, $errfile = "lib/WikiDB/backend/cvs.php", $errno = EM_FATAL_ERRORS) { $err = new PhpError( $errno, "[CVS(be)]: " . $msg, $errfile, $errline); // send error to the debug routine $this->_cvsDebug( $err->asXML() ); // send the error to the error manager $GLOBALS['ErrorManager']->handleError( $err ); } /** * Debug function specifically for the CVS database functions. * Can be deactived by setting the WikiDB['debug_file'] to "" */ function _cvsDebug( $msg ) { if ( $this->_debug_file == "" ) { return; } if ( !file_exists( $this->_debug_file ) ) { $this->_createFile( $this->_debug_file, 0755 ); } if ( $fdlock = @fopen( $this->_debug_file, 'a' ) ) { $locked = flock( $fdlock, 2 ); if ( !$locked ) { fclose( $fdlock ); return; } $fdappend = @fopen( $this->_debug_file, 'a' ); fwrite( $fdappend, ($msg . "\n") ); fclose( $fdappend ); fclose( $fdlock ); } else { // TODO: this should be replaced ... printf("unable to locate/open [%s], turning debug off\n", $filename); $this->_debug_file = ""; } } /** * Execute a command and potentially exit if the flag exitOnNonZero is * set to true and the return value was nonZero */ function _execCommand( $cmdLine, &$cmdOutput, $exitOnNonZero ) { $this->_cvsDebug( sprintf("Preparing to execute [%s]", $cmdLine) ); exec( $cmdLine, $cmdOutput, $cmdReturnVal ); if ( $exitOnNonZero && ($cmdReturnVal != 0) ) { $this->_cvsDebug( sprintf("Command failed [%s], Output: ", $cmdLine) ."[". join("\n",$cmdOutput) . "]" ); $this->_cvsError( sprintf("Command failed [%s], Return value: %s", $cmdLine, $cmdReturnVal), __LINE__ ); } $this->_cvsDebug( "Done execution [" . join("\n", $cmdOutput) . "]" ); return $cmdReturnVal; } /** * Read locks a file, reads it, and returns it contents */ function _readFileWithPath( $filename ) { if ( $fd = @fopen( $filename, "r" ) ) { $locked = flock( $fd, 1 ); // read lock if ( !$locked ) { fclose( $fd ); $this->_cvsError( "Unable to obtain read lock.", __LINE__ ); } $content = file( $filename ); fclose( $fd ); return $content; } else { $this->_cvsError( sprintf("Unable to open file '%s' for reading", $filename), __LINE__ ); return false; } } /** * Either replace the contents of an existing file or create a * new file in the particular store using the page name as the * file name. * * Nothing is returned, might be useful to return something ;-) */ function _writeFileWithPath( $filename, $contents ) { // TODO: $contents should probably be a reference parameter ... if( $fd = fopen($filename, 'a') ) { $locked = flock($fd,2); // Exclusive blocking lock if (!$locked) { $this->_cvsError( "Timeout while obtaining lock.", __LINE__ ); } // Second filehandle -- we use this to write the contents $fdsafe = fopen($filename, 'w'); fwrite($fdsafe, $contents); fclose($fdsafe); fclose($fd); } else { $this->_cvsError( sprintf("Could not open file '%s' for writing", $filename), __LINE__ ); } } /** * Copy the contents of the source directory to the destination directory. */ function _copyFilesFromDirectory( $src, $dest ) { $this->_cvsDebug( sprintf("Copying from [%s] to [%s]", $src, $dest) ); if ( is_dir( $src ) && is_dir( $dest ) ) { $this->_cvsDebug( "Copying " ); $d = opendir( $src ); while ( $entry = readdir( $d ) ) { if ( is_file( $src . "/" . $entry ) && copy( $src . "/" . $entry, $dest . "/" . $entry ) ) { $this->_cvsDebug( sprintf("Copied to [%s]", "$dest/$entry") ); } else { $this->_cvsDebug( sprintf("Failed to copy [%s]", "$src/$entry") ); } } closedir( $d ); return true; } else { $this->_cvsDebug( "Not copying" ); return false; } } /** * Unescape a string value. Normally this comes from doing an * escapeshellcmd. This converts the following: * \{ --> { * \} --> } * \; --> ; * \" --> " */ function _unescape( $val ) { $val = str_replace( "\\{", "{", $val ); $val = str_replace( "\\}", "}", $val ); $val = str_replace( "\\;", ";", $val ); $val = str_replace( "\\\"", "\"", $val ); return $val; } /** * Function for removing the newlines from the ends of the * file data returned from file(..). This is used in retrievePage */ function _strip_newlines( &$item, $key ) { $item = ereg_replace( "\n$", "", $item ); }} /* End of WikiDB_backend_cvs class *//** * Generic iterator for stepping through an array of values. */class Cvs_Backend_Array_Iteratorextends WikiDB_backend_iterator{ var $_array; function Cvs_Backend_Iterator( $arrayValue = Array() ) { $this->_array = $arrayValue; } function next() { while ( ($rVal = array_pop( $this->_array )) != NULL ) { return $rVal; } return false; } function count() { return count($this->_array); } function free() { unset( $this->_array ); }}class Cvs_Backend_Full_Search_Iteratorextends Cvs_Backend_Array_Iterator{ var $_searchString = ''; var $_docDir = ""; function Cvs_Backend_Title_Search_Iterator( $arrayValue = Array(), $searchString = "", $documentDir = ".") { $this->Cvs_Backend_Array_Iterator( $arrayValue ); $_searchString = $searchString; $_docDir = $documentDir; } function next() { do { $pageName = Cvs_Backend_Array_Iterator::next(); } while ( !$this->_searchFile( $_searchString, $_docDir . "/" . $pageName )); return $pageName; } /** * Does nothing more than a grep and search the entire contents * of the given file. Returns TRUE of the searchstring was found, * false if the search string wasn't find or the file was a directory * or could not be read. */ function _searchFile( $searchString, $fileName ) { // TODO: using grep here, it might make more sense to use // TODO: some sort of inbuilt/language specific method for // TODO: searching files. $cmdLine = sprintf( "grep -E -i '%s' %s > /dev/null 2>&1", $searchString, $fileName ); return ( WikiDB_backend_cvs::_execCommand( $cmdLine, $cmdOutput, false ) == 0 ); }}/** * Iterator used for doing a title search. */class Cvs_Backend_Title_Search_Iteratorextends Cvs_Backend_Array_Iterator{ var $_searchString = ''; function Cvs_Backend_Title_Search_Iterator( $arrayValue = Array(), $searchString = "") { $this->Cvs_Backend_Array_Iterator( $arrayValue ); $_searchString = $searchString; } function next() { do { $pageName = Cvs_Backend_Array_Iterator::next(); } while ( !eregi( $this->_searchString, $pageName ) ); return $pageName; }}// (c-file-style: "gnu")// Local Variables:// mode: php// tab-width: 8// c-basic-offset: 4// c-hanging-comment-ender-p: nil// indent-tabs-mode: nil// End: ?>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -