Lines Matching defs:file
57 * Used to read in a DokuWiki page from file, and send IO_WIKIPAGE_READ events.
61 * The file path should not be changed.
69 * @param string $file filename
76 function io_readWikiPage($file, $id, $rev = false)
81 $data = [[$file, true], getNS($id), noNS($id), $rev];
103 * Returns content of $file as cleaned string.
111 * @param string $file filename
113 * @return string|bool the file contents or false on error
117 function io_readFile($file, $clean = true)
120 if (file_exists($file)) {
121 if (str_ends_with($file, '.gz')) {
123 $ret = gzfile($file);
127 } elseif (str_ends_with($file, '.bz2')) {
129 $ret = bzfile($file);
131 $ret = file_get_contents($file);
143 * Returns the content of a .bz2 compressed file as string
145 * @param string $file filename
152 function bzfile($file, $array = false)
154 $bz = bzopen($file, "r");
188 * Used to write out a DokuWiki page to file, and send IO_WIKIPAGE_WRITE events.
192 * The file path should not be changed.
201 * @param string $file filename
209 function io_writeWikiPage($file, $content, $id, $rev = false)
217 $data = [[$file, $content, false], getNS($id), noNS($id), $rev];
233 // for attic files make sure the file has the mtime of the revision
244 * Internal function to save contents to a file.
246 * @param string $file filename path to file
253 function _io_saveFile($file, $content, $append)
257 $fileexists = file_exists($file);
259 if (str_ends_with($file, '.gz')) {
261 $fh = @gzopen($file, $mode . '9');
265 } elseif (str_ends_with($file, '.bz2')) {
268 $bzcontent = bzfile($file);
272 $fh = @bzopen($file, 'w');
277 $fh = @fopen($file, $mode);
284 chmod($file, $conf['fperm']);
290 * Saves $content to $file.
298 * @param string $file filename path to file
305 function io_saveFile($file, $content, $append = false)
307 io_makeFileDir($file);
308 io_lock($file);
309 if (!_io_saveFile($file, $content, $append)) {
310 msg("Writing $file failed", -1);
311 io_unlock($file);
314 io_unlock($file);
319 * Replace one or more occurrences of a line in a file.
333 * @param string $file filename
344 function io_replaceInFile($file, $oldline, $newline, $regex = false, $maxlines = 0)
351 if (!file_exists($file)) return true;
353 io_lock($file);
356 if (str_ends_with($file, '.gz')) {
358 $lines = gzfile($file);
359 } elseif (str_ends_with($file, '.bz2')) {
361 $lines = bzfile($file, true);
363 $lines = file($file);
392 if (!_io_saveFile($file, implode('', $lines), false)) {
393 msg("Removing content from $file failed", -1);
394 io_unlock($file);
398 @unlink($file);
401 io_unlock($file);
406 * Delete lines that match $badline from $file.
410 * @param string $file filename
417 function io_deleteFromFile($file, $badline, $regex = false)
419 return io_replaceInFile($file, $badline, '', $regex, 0);
423 * Tries to lock a file
431 * @param string $file filename
435 function io_lock($file)
439 $lockDir = $conf['lockdir'] . '/' . md5($file);
458 * Unlocks a file
460 * @param string $file filename
464 function io_unlock($file)
468 $lockDir = $conf['lockdir'] . '/' . md5($file);
498 $tmp = dirname($file = call_user_func($types[$ns_type], $ns));
509 io_makeFileDir($file);
519 * Create the directory needed for the given file
521 * @param string $file file name
525 function io_makeFileDir($file)
527 $dir = dirname($file);
597 foreach ($files as $file) {
598 if (!@unlink($file)) return false; //abort on any error
633 * downloads a file from the net and saves it
636 * - $file is the full filename to save the file, incl. path
640 * - $file is the directory where the file should be saved
641 * - if successful will return the name used for the saved file, false otherwise
644 * @param string $file path to file or directory where to save
646 * false: uses $file as path to file
648 * @param int $maxSize maximum file size
649 * @return bool|string if failed false, otherwise true or the name of the file in the given dir
654 function io_download($url, $file, $useAttachment = false, $defaultName = '', $maxSize = 2_097_152)
683 $file .= $name;
686 $fileexists = file_exists($file);
687 $fp = @fopen($file, "w");
692 chmod($file, $conf['fperm']);
753 * Search a file for matching lines
755 * This is probably not faster than file()+preg_grep() but less
756 * memory intensive because not the whole file needs to be loaded
759 * @param string $file The file to search
767 function io_grep($file, $pattern, $max = 0, $backref = false)
769 $fh = @fopen($file, 'r');
797 * Get size of contents of a file, for a compressed file the uncompressed size
800 * @param string $file filename path to file
801 * @return int size of file
805 function io_getSizeFile($file)
807 if (!file_exists($file)) return 0;
809 if (str_ends_with($file, '.gz')) {
810 $fp = @fopen($file, "rb");
817 } elseif (str_ends_with($file, '.bz2')) {
819 $bz = bzopen($file, "r");
831 $uncompressedsize = filesize($file);