Lines Matching defs:file
56 * Used to read in a DokuWiki page from file, and send IO_WIKIPAGE_READ events.
60 * The file path should not be changed.
68 * @param string $file filename
75 function io_readWikiPage($file, $id, $rev = false)
80 $data = [[$file, true], getNS($id), noNS($id), $rev];
102 * Returns content of $file as cleaned string.
110 * @param string $file filename
112 * @return string|bool the file contents or false on error
116 function io_readFile($file, $clean = true)
119 if (file_exists($file)) {
120 if (str_ends_with($file, '.gz')) {
122 $ret = gzfile($file);
126 } elseif (str_ends_with($file, '.bz2')) {
128 $ret = bzfile($file);
130 $ret = file_get_contents($file);
142 * Returns the content of a .bz2 compressed file as string
144 * @param string $file filename
151 function bzfile($file, $array = false)
153 $bz = bzopen($file, "r");
187 * Used to write out a DokuWiki page to file, and send IO_WIKIPAGE_WRITE events.
191 * The file path should not be changed.
200 * @param string $file filename
208 function io_writeWikiPage($file, $content, $id, $rev = false)
216 $data = [[$file, $content, false], getNS($id), noNS($id), $rev];
232 // for attic files make sure the file has the mtime of the revision
243 * Internal function to save contents to a file.
245 * @param string $file filename path to file
252 function _io_saveFile($file, $content, $append)
256 $fileexists = file_exists($file);
258 if (str_ends_with($file, '.gz')) {
260 $fh = @gzopen($file, $mode . '9');
264 } elseif (str_ends_with($file, '.bz2')) {
267 $bzcontent = bzfile($file);
271 $fh = @bzopen($file, 'w');
276 $fh = @fopen($file, $mode);
283 chmod($file, $conf['fperm']);
289 * Saves $content to $file.
297 * @param string $file filename path to file
304 function io_saveFile($file, $content, $append = false)
306 io_makeFileDir($file);
307 io_lock($file);
308 if (!_io_saveFile($file, $content, $append)) {
309 msg("Writing $file failed", -1);
310 io_unlock($file);
313 io_unlock($file);
318 * Replace one or more occurrences of a line in a file.
332 * @param string $file filename
343 function io_replaceInFile($file, $oldline, $newline, $regex = false, $maxlines = 0)
350 if (!file_exists($file)) return true;
352 io_lock($file);
355 if (str_ends_with($file, '.gz')) {
357 $lines = gzfile($file);
358 } elseif (str_ends_with($file, '.bz2')) {
360 $lines = bzfile($file, true);
362 $lines = file($file);
391 if (!_io_saveFile($file, implode('', $lines), false)) {
392 msg("Removing content from $file failed", -1);
393 io_unlock($file);
397 @unlink($file);
400 io_unlock($file);
405 * Delete lines that match $badline from $file.
409 * @param string $file filename
416 function io_deleteFromFile($file, $badline, $regex = false)
418 return io_replaceInFile($file, $badline, '', $regex, 0);
422 * Tries to lock a file
430 * @param string $file filename
434 function io_lock($file)
438 $lockDir = $conf['lockdir'] . '/' . md5($file);
457 * Unlocks a file
459 * @param string $file filename
463 function io_unlock($file)
467 $lockDir = $conf['lockdir'] . '/' . md5($file);
497 $tmp = dirname($file = call_user_func($types[$ns_type], $ns));
508 io_makeFileDir($file);
518 * Create the directory needed for the given file
520 * @param string $file file name
524 function io_makeFileDir($file)
526 $dir = dirname($file);
596 foreach ($files as $file) {
597 if (!@unlink($file)) return false; //abort on any error
632 * downloads a file from the net and saves it
635 * - $file is the full filename to save the file, incl. path
639 * - $file is the directory where the file should be saved
640 * - if successful will return the name used for the saved file, false otherwise
643 * @param string $file path to file or directory where to save
645 * false: uses $file as path to file
647 * @param int $maxSize maximum file size
648 * @return bool|string if failed false, otherwise true or the name of the file in the given dir
653 function io_download($url, $file, $useAttachment = false, $defaultName = '', $maxSize = 2_097_152)
682 $file .= $name;
685 $fileexists = file_exists($file);
686 $fp = @fopen($file, "w");
691 chmod($file, $conf['fperm']);
752 * Search a file for matching lines
754 * This is probably not faster than file()+preg_grep() but less
755 * memory intensive because not the whole file needs to be loaded
758 * @param string $file The file to search
766 function io_grep($file, $pattern, $max = 0, $backref = false)
768 $fh = @fopen($file, 'r');
796 * Get size of contents of a file, for a compressed file the uncompressed size
799 * @param string $file filename path to file
800 * @return int size of file
804 function io_getSizeFile($file)
806 if (!file_exists($file)) return 0;
808 if (str_ends_with($file, '.gz')) {
809 $fp = @fopen($file, "rb");
816 } elseif (str_ends_with($file, '.bz2')) {
818 $bz = bzopen($file, "r");
830 $uncompressedsize = filesize($file);