[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/inc/ -> io.php (summary)

File IO functions

Author: Andreas Gohr
License: GPL 2 (http://www.gnu.org/licenses/gpl.html)
File Size: 781 lines (23 kb)
Included or required: 1 time
Referenced: 0 times
Includes or requires: 0 files

Defines 23 functions

  io_sweepNS()
  io_readWikiPage()
  _io_readWikiPage_action()
  io_readFile()
  bzfile()
  io_writeWikiPage()
  _io_writeWikiPage_action()
  _io_saveFile()
  io_saveFile()
  io_replaceInFile()
  io_deleteFromFile()
  io_lock()
  io_unlock()
  io_createNamespace()
  io_makeFileDir()
  io_mkdir_p()
  io_rmdir()
  io_mktmpdir()
  io_download()
  io_rename()
  io_exec()
  io_grep()
  io_getSizeFile()

Functions
Functions that are not part of a class:

io_sweepNS($id,$basedir='datadir')   X-Ref
Removes empty directories

Sends IO_NAMESPACE_DELETED events for 'pages' and 'media' namespaces.
Event data:
$data[0]    ns: The colon separated namespace path minus the trailing page name.
$data[1]    ns_type: 'pages' or 'media' namespace tree.

author: Andreas Gohr <andi@splitbrain.org>
author: Ben Coburn <btcoburn@silicodon.net>
return: bool - true if at least one namespace was deleted
param: string $id      - a pageid, the namespace of that id will be tried to deleted
param: string $basedir - the config name of the type to delete (datadir or mediadir usally)

io_readWikiPage($file, $id, $rev=false)   X-Ref
Used to read in a DokuWiki page from file, and send IO_WIKIPAGE_READ events.

Generates the action event which delegates to io_readFile().
Action plugins are allowed to modify the page content in transit.
The file path should not be changed.

Event data:
$data[0]    The raw arguments for io_readFile as an array.
$data[1]    ns: The colon separated namespace path minus the trailing page name. (false if root ns)
$data[2]    page_name: The wiki page name.
$data[3]    rev: The page revision, false for current wiki pages.

author: Ben Coburn <btcoburn@silicodon.net>
return: string
param: string   $file filename
param: string   $id page id
param: bool|int $rev revision timestamp

_io_readWikiPage_action($data)   X-Ref
Callback adapter for io_readFile().

author: Ben Coburn <btcoburn@silicodon.net>
return: string
param: array $data event data

io_readFile($file,$clean=true)   X-Ref
Returns content of $file as cleaned string.

Uses gzip if extension is .gz

If you want to use the returned value in unserialize
be sure to set $clean to false!

author: Andreas Gohr <andi@splitbrain.org>
return: string|bool the file contents or false on error
param: string $file  filename
param: bool   $clean

bzfile($file, $array=false)   X-Ref
Returns the content of a .bz2 compressed file as string

author: marcel senf <marcel@rucksackreinigung.de>
author: Andreas Gohr <andi@splitbrain.org>
return: string|array|bool content or false on error
param: string $file filename
param: bool   $array return array of lines

io_writeWikiPage($file, $content, $id, $rev=false)   X-Ref
Used to write out a DokuWiki page to file, and send IO_WIKIPAGE_WRITE events.

This generates an action event and delegates to io_saveFile().
Action plugins are allowed to modify the page content in transit.
The file path should not be changed.
(The append parameter is set to false.)

Event data:
$data[0]    The raw arguments for io_saveFile as an array.
$data[1]    ns: The colon separated namespace path minus the trailing page name. (false if root ns)
$data[2]    page_name: The wiki page name.
$data[3]    rev: The page revision, false for current wiki pages.

author: Ben Coburn <btcoburn@silicodon.net>
return: bool
param: string $file      filename
param: string $content
param: string $id        page id
param: int|bool $rev timestamp of revision

_io_writeWikiPage_action($data)   X-Ref
Callback adapter for io_saveFile().

author: Ben Coburn <btcoburn@silicodon.net>
return: bool
param: array $data event data

_io_saveFile($file, $content, $append)   X-Ref
Internal function to save contents to a file.

author: Andreas Gohr <andi@splitbrain.org>
return: bool true on success, otherwise false
param: string $file filename path to file
param: string $content
param: bool   $append

io_saveFile($file, $content, $append=false)   X-Ref
Saves $content to $file.

If the third parameter is set to true the given content
will be appended.

Uses gzip if extension is .gz
and bz2 if extension is .bz2

author: Andreas Gohr <andi@splitbrain.org>
return: bool true on success, otherwise false
param: string $file filename path to file
param: string $content
param: bool   $append

io_replaceInFile($file, $oldline, $newline, $regex=false, $maxlines=0)   X-Ref
Replace one or more occurrences of a line in a file.

The default, when $maxlines is 0 is to delete all matching lines then append a single line.
A regex that matches any part of the line will remove the entire line in this mode.
Captures in $newline are not available.

Otherwise each line is matched and replaced individually, up to the first $maxlines lines
or all lines if $maxlines is -1. If $regex is true then captures can be used in $newline.

Be sure to include the trailing newline in $oldline when replacing entire lines.

Uses gzip if extension is .gz
and bz2 if extension is .bz2

author: Steven Danz <steven-danz@kc.rr.com>
author: Christopher Smith <chris@jalakai.co.uk>
author: Patrick Brown <ptbrown@whoopdedo.org>
return: bool true on success
param: string $file     filename
param: string $oldline  exact linematch to remove
param: string $newline  new line to insert
param: bool   $regex    use regexp?
param: int    $maxlines number of occurrences of the line to replace

io_deleteFromFile($file,$badline,$regex=false)   X-Ref
Delete lines that match $badline from $file.

Be sure to include the trailing newline in $badline

author: Patrick Brown <ptbrown@whoopdedo.org>
return: bool true on success
param: string $file    filename
param: string $badline exact linematch to remove
param: bool   $regex   use regexp?

io_lock($file)   X-Ref
Tries to lock a file

Locking is only done for io_savefile and uses directories
inside $conf['lockdir']

It waits maximal 3 seconds for the lock, after this time
the lock is assumed to be stale and the function goes on

author: Andreas Gohr <andi@splitbrain.org>
param: string $file filename

io_unlock($file)   X-Ref
Unlocks a file

author: Andreas Gohr <andi@splitbrain.org>
param: string $file filename

io_createNamespace($id, $ns_type='pages')   X-Ref
Create missing namespace directories and send the IO_NAMESPACE_CREATED events
in the order of directory creation. (Parent directories first.)

Event data:
$data[0]    ns: The colon separated namespace path minus the trailing page name.
$data[1]    ns_type: 'pages' or 'media' namespace tree.

author: Ben Coburn <btcoburn@silicodon.net>
param: string $id page id
param: string $ns_type 'pages' or 'media'

io_makeFileDir($file)   X-Ref
Create the directory needed for the given file

author: Andreas Gohr <andi@splitbrain.org>
param: string $file file name

io_mkdir_p($target)   X-Ref
Creates a directory hierachy.

link: http://php.net/manual/en/function.mkdir.php
author: <saint@corenova.com>
author: Andreas Gohr <andi@splitbrain.org>
return: bool|int|string
param: string $target filename

io_rmdir($path, $removefiles = false)   X-Ref
Recursively delete a directory

author: Andreas Gohr <andi@splitbrain.org>
return: bool
param: string $path
param: bool   $removefiles defaults to false which will delete empty directories only

io_mktmpdir()   X-Ref
Creates a unique temporary directory and returns
its path.

author: Michael Klier <chi@chimeric.de>
return: false|string path to new directory or false

io_download($url,$file,$useAttachment=false,$defaultName='',$maxSize=2097152)   X-Ref
downloads a file from the net and saves it

if $useAttachment is false,
- $file is the full filename to save the file, incl. path
- if successful will return true, false otherwise

if $useAttachment is true,
- $file is the directory where the file should be saved
- if successful will return the name used for the saved file, false otherwise

author: Andreas Gohr <andi@splitbrain.org>
author: Chris Smith <chris@jalakai.co.uk>
return: bool|string          if failed false, otherwise true or the name of the file in the given dir
param: string $url           url to download
param: string $file          path to file or directory where to save
param: bool   $useAttachment true: try to use name of download, uses otherwise $defaultName
param: string $defaultName   fallback for if using $useAttachment
param: int    $maxSize       maximum file size

io_rename($from,$to)   X-Ref
Windows compatible rename

rename() can not overwrite existing files on Windows
this function will use copy/unlink instead

return: bool succes or fail
param: string $from
param: string $to

io_exec($cmd, $input, &$output)   X-Ref
Runs an external command with input and output pipes.
Returns the exit code from the process.

author: Tom N Harris <tnharris@whoopdedo.org>
return: int exit code from process
param: string $cmd
param: string $input  input pipe
param: string $output output pipe

io_grep($file,$pattern,$max=0,$backref=false)   X-Ref
Search a file for matching lines

This is probably not faster than file()+preg_grep() but less
memory intensive because not the whole file needs to be loaded
at once.

author: Andreas Gohr <andi@splitbrain.org>
return: array matching lines or backref, false on error
param: string $file    The file to search
param: string $pattern PCRE pattern
param: int    $max     How many lines to return (0 for all)
param: bool   $backref When true returns array with backreferences instead of lines

io_getSizeFile($file)   X-Ref
Get size of contents of a file, for a compressed file the uncompressed size
Warning: reading uncompressed size of content of bz-files requires uncompressing

author: Gerrit Uitslag <klapinklapin@gmail.com>
return: int size of file
param: string $file filename path to file