[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/inc/ -> media.php (summary)

All output and handler function needed for the media management popup

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

Defines 63 functions

  media_filesinuse()
  media_metasave()
  media_isexternal()
  media_ispublic()
  media_metaform()
  media_inuse()
  media_delete()
  media_upload_xhr()
  media_upload()
  copy_uploaded_file()
  media_save()
  _media_upload_action()
  media_upload_finish()
  media_saveOldRevision()
  media_contentcheck()
  media_notify()
  media_filelist()
  media_tabs_files()
  media_tabs_details()
  media_tab_files_options()
  _media_get_sort_type()
  _media_get_list_type()
  _media_get_display_param()
  media_tab_files()
  media_tab_upload()
  media_tab_search()
  media_tab_view()
  media_tab_edit()
  media_tab_history()
  media_preview()
  media_preview_buttons()
  media_image_preview_size()
  media_getTag()
  media_file_tags()
  media_details()
  media_diff()
  _media_file_diff()
  media_file_diff()
  media_image_diff()
  media_restore()
  media_searchlist()
  media_printfile()
  media_printicon()
  media_printfile_thumbs()
  media_printimgdetail()
  media_managerURL()
  media_uploadform()
  media_getuploadsize()
  media_searchform()
  media_nstree()
  media_nstree_item()
  media_nstree_li()
  media_resize_image()
  media_crop_image()
  media_get_token()
  media_get_from_URL()
  media_image_download()
  media_resize_imageIM()
  media_crop_imageIM()
  media_resize_imageGD()
  media_alternativefiles()
  media_supportedav()
  media_trackfiles()

Functions
Functions that are not part of a class:

media_filesinuse($data,$id)   X-Ref
Lists pages which currently use a media file selected for deletion

References uses the same visual as search results and share
their CSS tags except pagenames won't be links.

param: array $data
param: string $id
author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>

media_metasave($id,$auth,$data)   X-Ref
Handles the saving of image meta data

param: string $id media id
param: int $auth permission level
param: array $data
author: Andreas Gohr <andi@splitbrain.org>
author: Kate Arzamastseva <pshns@ukr.net>
return: false|string

media_isexternal($id)   X-Ref
check if a media is external source

param: string $id the media ID or URL
author: Gerrit Uitslag <klapinklapin@gmail.com>
return: bool

media_ispublic($id)   X-Ref
Check if a media item is public (eg, external URL or readable by @ALL)

param: string $id  the media ID or URL
author: Andreas Gohr <andi@splitbrain.org>
return: bool

media_metaform($id,$auth)   X-Ref
Display the form to edit image meta data

param: string $id media id
param: int $auth permission level
author: Andreas Gohr <andi@splitbrain.org>
author: Kate Arzamastseva <pshns@ukr.net>
return: bool

media_inuse($id)   X-Ref
Convenience function to check if a media file is still in use

param: string $id media id
author: Michael Klier <chi@chimeric.de>
return: array|bool

media_delete($id,$auth)   X-Ref
Handles media file deletions

If configured, checks for media references before deletion

param: string $id media id
param: int $auth no longer used
author: Andreas Gohr <andi@splitbrain.org>
return: int One of: 0,

media_upload_xhr($ns,$auth)   X-Ref
Handle file uploads via XMLHttpRequest

param: string $ns   target namespace
param: int    $auth current auth check result
return: false|string false on error, id of the new file on success

media_upload($ns,$auth,$file=false)   X-Ref
Handles media file uploads

param: string     $ns    target namespace
param: int        $auth  current auth check result
param: bool|array $file  $_FILES member, $_FILES['upload'] if false
author: Andreas Gohr <andi@splitbrain.org>
author: Michael Klier <chi@chimeric.de>
return: false|string false on error, id of the new file on success

copy_uploaded_file($from, $to)   X-Ref
An alternative to move_uploaded_file that copies

Using copy, makes sure any setgid bits on the media directory are honored

param: string $from
param: string $to
return: bool
see: move_uploaded_file()

media_save($file, $id, $ow, $auth, $move)   X-Ref
This generates an action event and delegates to _media_upload_action().
Action plugins are allowed to pre/postprocess the uploaded file.
(The triggered event is preventable.)

Event data:
$data[0]     fn_tmp:    the temporary file name (read from $_FILES)
$data[1]     fn:        the file name of the uploaded file
$data[2]     id:        the future directory id of the uploaded file
$data[3]     imime:     the mimetype of the uploaded file
$data[4]     overwrite: if an existing file is going to be overwritten
$data[5]     move:      name of function that performs move/copy/..

triggers: MEDIA_UPLOAD_FINISH
param: array  $file
param: string $id   media id
param: bool   $ow   overwrite?
param: int    $auth permission level
param: string $move name of functions that performs move/copy/..
return: false|array|string

_media_upload_action($data)   X-Ref
No description

media_upload_finish($fn_tmp, $fn, $id, $imime, $overwrite, $move = 'move_uploaded_file')   X-Ref
Saves an uploaded media file

param: string $fn_tmp
param: string $fn
param: string $id        media id
param: string $imime     mime type
param: bool   $overwrite overwrite existing?
param: string $move      function name
author: Andreas Gohr <andi@splitbrain.org>
author: Michael Klier <chi@chimeric.de>
author: Kate Arzamastseva <pshns@ukr.net>
return: array|string

media_saveOldRevision($id)   X-Ref
Moves the current version of media file to the media_attic
directory

param: string $id
author: Kate Arzamastseva <pshns@ukr.net>
return: int - revision date

media_contentcheck($file,$mime)   X-Ref
This function checks if the uploaded content is really what the
mimetype says it is. We also do spam checking for text types here.

We need to do this stuff because we can not rely on the browser
to do this check correctly. Yes, IE is broken as usual.

param: string $file path to file
param: string $mime mimetype
author: Andreas Gohr <andi@splitbrain.org>
link: http://www.splitbrain.org/blog/2007-02/12-internet_explorer_facilitates_cross_site_scripting
return: int

media_notify($id,$file,$mime,$old_rev=false)   X-Ref
Send a notify mail on uploads

param: string   $id      media id
param: string   $file    path to file
param: string   $mime    mime type
param: bool|int $old_rev revision timestamp or false
author: Andreas Gohr <andi@splitbrain.org>
return: bool

media_filelist($ns,$auth=null,$jump='',$fullscreenview=false,$sort=false)   X-Ref
List all files in a given Media namespace

param: string      $ns             namespace
param: null|int    $auth           permission level
param: string      $jump           id
param: bool        $fullscreenview
param: bool|string $sort           sorting order, false skips sorting

media_tabs_files($selected_tab = '')   X-Ref
Prints tabs for files list actions

param: string $selected_tab - opened tab
author: Kate Arzamastseva <pshns@ukr.net>
author: Adrian Lang <mail@adrianlang.de>

media_tabs_details($image, $selected_tab = '')   X-Ref
Prints tabs for files details actions

param: string $image filename of the current image
param: string $selected_tab opened tab
author: Kate Arzamastseva <pshns@ukr.net>

media_tab_files_options()   X-Ref
Prints options for the tab that displays a list of all files

author: Kate Arzamastseva <pshns@ukr.net>

_media_get_sort_type()   X-Ref
Returns type of sorting for the list of files in media manager

author: Kate Arzamastseva <pshns@ukr.net>
return: string - sort type

_media_get_list_type()   X-Ref
Returns type of listing for the list of files in media manager

author: Kate Arzamastseva <pshns@ukr.net>
return: string - list type

_media_get_display_param($param, $values)   X-Ref
Get display parameters

param: string $param   name of parameter
param: array  $values  allowed values, where default value has index key 'default'
return: string the parameter value

media_tab_files($ns,$auth=null,$jump='')   X-Ref
Prints tab that displays a list of all files

param: string    $ns
param: null|int  $auth permission level
param: string    $jump item id
author: Kate Arzamastseva <pshns@ukr.net>

media_tab_upload($ns,$auth=null,$jump='')   X-Ref
Prints tab that displays uploading form

param: string   $ns
param: null|int $auth permission level
param: string   $jump item id
author: Kate Arzamastseva <pshns@ukr.net>

media_tab_search($ns,$auth=null)   X-Ref
Prints tab that displays search form

param: string $ns
param: null|int $auth permission level
author: Kate Arzamastseva <pshns@ukr.net>

media_tab_view($image, $ns, $auth=null, $rev='')   X-Ref
Prints tab that displays mediafile details

param: string     $image media id
param: string     $ns
param: null|int   $auth  permission level
param: string|int $rev   revision timestamp or empty string
author: Kate Arzamastseva <pshns@ukr.net>

media_tab_edit($image, $ns, $auth=null)   X-Ref
Prints tab that displays form for editing mediafile metadata

param: string     $image media id
param: string     $ns
param: null|int   $auth permission level
author: Kate Arzamastseva <pshns@ukr.net>

media_tab_history($image, $ns, $auth=null)   X-Ref
Prints tab that displays mediafile revisions

param: string     $image media id
param: string     $ns
param: null|int   $auth permission level
author: Kate Arzamastseva <pshns@ukr.net>

media_preview($image, $auth, $rev='', $meta=false)   X-Ref
Prints mediafile details

param: string         $image media id
param: int            $auth permission level
param: int|string     $rev revision timestamp or empty string
param: JpegMeta|bool  $meta
author: Kate Arzamastseva <pshns@ukr.net>

media_preview_buttons($image, $auth, $rev='')   X-Ref
Prints mediafile action buttons

param: string     $image media id
param: int        $auth  permission level
param: string|int $rev   revision timestamp, or empty string
author: Kate Arzamastseva <pshns@ukr.net>

media_image_preview_size($image, $rev, $meta, $size = 500)   X-Ref
Returns image width and height for mediamanager preview panel

param: string         $image
param: int|string     $rev
param: JpegMeta|bool  $meta
param: int            $size
author: Kate Arzamastseva <pshns@ukr.net>
return: array|false

media_getTag($tags,$meta,$alt='')   X-Ref
Returns the requested EXIF/IPTC tag from the image meta

param: array    $tags array with tags, first existing is returned
param: JpegMeta $meta
param: string   $alt  alternative value
author: Kate Arzamastseva <pshns@ukr.net>
return: string

media_file_tags($meta)   X-Ref
Returns mediafile tags

param: JpegMeta $meta
author: Kate Arzamastseva <pshns@ukr.net>
return: array list of tags of the mediafile

media_details($image, $auth, $rev='', $meta=false)   X-Ref
Prints mediafile tags

param: string        $image image id
param: int           $auth  permission level
param: string|int    $rev   revision timestamp, or empty string
param: bool|JpegMeta $meta  image object, or create one if false
author: Kate Arzamastseva <pshns@ukr.net>

media_diff($image, $ns, $auth, $fromajax = false)   X-Ref
Shows difference between two revisions of file

param: string $image  image id
param: string $ns
param: int $auth permission level
param: bool $fromajax
author: Kate Arzamastseva <pshns@ukr.net>
return: false|null|string

_media_file_diff($data)   X-Ref
Callback for media file diff

param: array $data event data
return: false|null

media_file_diff($image, $l_rev, $r_rev, $ns, $auth, $fromajax)   X-Ref
Shows difference between two revisions of image

param: string $image
param: string|int $l_rev revision timestamp, or empty string
param: string|int $r_rev revision timestamp, or empty string
param: string $ns
param: int $auth permission level
param: bool $fromajax
author: Kate Arzamastseva <pshns@ukr.net>

media_image_diff($image, $l_rev, $r_rev, $l_size, $r_size, $type)   X-Ref
Prints two images side by side
and slider

param: string $image   image id
param: int    $l_rev   revision timestamp, or empty string
param: int    $r_rev   revision timestamp, or empty string
param: array  $l_size  array with width and height
param: array  $r_size  array with width and height
param: string $type
author: Kate Arzamastseva <pshns@ukr.net>

media_restore($image, $rev, $auth)   X-Ref
Restores an old revision of a media file

param: string $image media id
param: int    $rev   revision timestamp or empty string
param: int    $auth
author: Kate Arzamastseva <pshns@ukr.net>
return: string - file's id

media_searchlist($query,$ns,$auth=null,$fullscreen=false,$sort='natural')   X-Ref
List all files found by the search request

triggers: MEDIA_SEARCH
param: string $query
param: string $ns
param: null|int $auth
param: bool $fullscreen
param: string $sort
author: Tobias Sarnowski <sarnowski@cosmocode.de>
author: Andreas Gohr <gohr@cosmocode.de>
author: Kate Arzamastseva <pshns@ukr.net>

media_printfile($item,$auth,$jump,$display_namespace=false)   X-Ref
Formats and prints one file in the list

param: array     $item
param: int       $auth              permission level
param: string    $jump              item id
param: bool      $display_namespace

media_printicon($filename, $size='')   X-Ref
Display a media icon

param: string $filename media id
param: string $size     the size subfolder, if not specified 16x16 is used
return: string html

media_printfile_thumbs($item,$auth,$jump=false,$display_namespace=false)   X-Ref
Formats and prints one file in the list in the thumbnails view

param: array       $item
param: int         $auth              permission level
param: bool|string $jump              item id
param: bool        $display_namespace
author: Kate Arzamastseva <pshns@ukr.net>

media_printimgdetail($item, $fullscreen=false)   X-Ref
Prints a thumbnail and metainfo

param: array $item
param: bool  $fullscreen

media_managerURL($params=false, $amp='&amp;', $abs=false, $params_array=false)   X-Ref
Build link based on the current, adding/rewriting parameters

param: array|bool $params
param: string     $amp           separator
param: bool       $abs           absolute url?
param: bool       $params_array  return the parmeters array?
author: Kate Arzamastseva <pshns@ukr.net>
return: string|array - link or link parameters

media_uploadform($ns, $auth, $fullscreen = false)   X-Ref
Print the media upload form if permissions are correct

param: string $ns
param: int    $auth permission level
param: bool  $fullscreen
author: Andreas Gohr <andi@splitbrain.org>
author: Kate Arzamastseva <pshns@ukr.net>

media_getuploadsize()   X-Ref
Returns the size uploaded files may have

This uses a conservative approach using the lowest number found
in any of the limiting ini settings

returns: int size in bytes

media_searchform($ns,$query='',$fullscreen=false)   X-Ref
Print the search field form

param: string $ns
param: string $query
param: bool $fullscreen
author: Tobias Sarnowski <sarnowski@cosmocode.de>
author: Kate Arzamastseva <pshns@ukr.net>

media_nstree($ns)   X-Ref
Build a tree outline of available media namespaces

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

media_nstree_item($item)   X-Ref
Userfunction for html_buildlist

Prints a media namespace tree item

param: array $item
author: Andreas Gohr <andi@splitbrain.org>
return: string html

media_nstree_li($item)   X-Ref
Userfunction for html_buildlist

Prints a media namespace tree item opener

param: array $item
author: Andreas Gohr <andi@splitbrain.org>
return: string html

media_resize_image($file, $ext, $w, $h=0)   X-Ref
Resizes the given image to the given size

param: string $file filename, path to file
param: string $ext  extension
param: int    $w    desired width
param: int    $h    desired height
author: Andreas Gohr <andi@splitbrain.org>
return: string path to resized or original size if failed

media_crop_image($file, $ext, $w, $h=0)   X-Ref
Crops the given image to the wanted ratio, then calls media_resize_image to scale it
to the wanted size

Crops are centered horizontally but prefer the upper third of an vertical
image because most pics are more interesting in that area (rule of thirds)

param: string $file filename, path to file
param: string $ext  extension
param: int    $w    desired width
param: int    $h    desired height
author: Andreas Gohr <andi@splitbrain.org>
return: string path to resized or original size if failed

media_get_token($id,$w,$h)   X-Ref
Calculate a token to be used to verify fetch requests for resized or
cropped images have been internally generated - and prevent external
DDOS attacks via fetch

param: string  $id    id of the image
param: int     $w     resize/crop width
param: int     $h     resize/crop height
author: Christopher Smith <chris@jalakai.co.uk>
return: string token or empty string if no token required

media_get_from_URL($url,$ext,$cache)   X-Ref
Download a remote file and return local filename

returns false if download fails. Uses cached file if available and
wanted

param: string $url
param: string $ext   extension
param: int    $cache cachetime in seconds
author: Andreas Gohr <andi@splitbrain.org>
author: Pavel Vitis <Pavel.Vitis@seznam.cz>
return: false|string path to cached file

media_image_download($url,$file)   X-Ref
Download image files

param: string $url
param: string $file path to file in which to put the downloaded content
author: Andreas Gohr <andi@splitbrain.org>
return: bool

media_resize_imageIM($ext,$from,$from_w,$from_h,$to,$to_w,$to_h)   X-Ref
resize images using external ImageMagick convert program

param: string $ext     extension
param: string $from    filename path to file
param: int    $from_w  original width
param: int    $from_h  original height
param: string $to      path to resized file
param: int    $to_w    desired width
param: int    $to_h    desired height
author: Pavel Vitis <Pavel.Vitis@seznam.cz>
author: Andreas Gohr <andi@splitbrain.org>
return: bool

media_crop_imageIM($ext,$from,$from_w,$from_h,$to,$to_w,$to_h,$ofs_x,$ofs_y)   X-Ref
crop images using external ImageMagick convert program

param: string $ext     extension
param: string $from    filename path to file
param: int    $from_w  original width
param: int    $from_h  original height
param: string $to      path to resized file
param: int    $to_w    desired width
param: int    $to_h    desired height
param: int    $ofs_x   offset of crop centre
param: int    $ofs_y   offset of crop centre
author: Andreas Gohr <andi@splitbrain.org>
return: bool

media_resize_imageGD($ext,$from,$from_w,$from_h,$to,$to_w,$to_h,$ofs_x=0,$ofs_y=0)   X-Ref
resize or crop images using PHP's libGD support

param: string $ext     extension
param: string $from    filename path to file
param: int    $from_w  original width
param: int    $from_h  original height
param: string $to      path to resized file
param: int    $to_w    desired width
param: int    $to_h    desired height
param: int    $ofs_x   offset of crop centre
param: int    $ofs_y   offset of crop centre
author: Andreas Gohr <andi@splitbrain.org>
author: Sebastian Wienecke <s_wienecke@web.de>
return: bool

media_alternativefiles($src, $exts)   X-Ref
Return other media files with the same base name
but different extensions.

param: string   $src     - ID of media file
param: string[] $exts    - alternative extensions to find other files for
author: Anika Henke <anika@selfthinker.org>
return: array            - array(mime type => file ID)

media_supportedav($mime, $type=NULL)   X-Ref
Check if video/audio is supported to be embedded.

param: string $mime      - mimetype of media file
param: string $type      - type of media files to check ('video', 'audio', or null for all)
author: Anika Henke <anika@selfthinker.org>
return: boolean

media_trackfiles($src)   X-Ref
Return track media files with the same base name
but extensions that indicate kind and lang.
ie for foo.webm search foo.sub.lang.vtt, foo.cap.lang.vtt...

param: string   $src     - ID of media file
author: Schplurtz le Déboulonné <Schplurtz@laposte.net>
return: array            - array(mediaID => array( kind, srclang ))