[ 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: 2545 lines (77 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.

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

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

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

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

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

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

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

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

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

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

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

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

If configured, checks for media references before deletion

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

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

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

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

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
param: string     $ns    target namespace
param: int        $auth  current auth check result
param: bool|array $file  $_FILES member, $_FILES['upload'] if false

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

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

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/..

return: false|array|string
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/..

_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

author: Andreas Gohr <andi@splitbrain.org>
author: Michael Klier <chi@chimeric.de>
author: Kate Arzamastseva <pshns@ukr.net>
return: array|string
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

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

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

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.

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

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

author: Andreas Gohr <andi@splitbrain.org>
return: bool
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

media_file_tags($meta)   X-Ref
Returns mediafile tags

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

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

author: Kate Arzamastseva <pshns@ukr.net>
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

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

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

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

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

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

author: Kate Arzamastseva <pshns@ukr.net>
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

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

author: Kate Arzamastseva <pshns@ukr.net>
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

media_nstree_item($item)   X-Ref
Userfunction for html_buildlist

Prints a media namespace tree item

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

media_nstree_li($item)   X-Ref
Userfunction for html_buildlist

Prints a media namespace tree item opener

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

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

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

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)

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

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

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

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

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

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

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

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

author: Pavel Vitis <Pavel.Vitis@seznam.cz>
author: Andreas Gohr <andi@splitbrain.org>
return: bool
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

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

author: Andreas Gohr <andi@splitbrain.org>
return: bool
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

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

author: Andreas Gohr <andi@splitbrain.org>
author: Sebastian Wienecke <s_wienecke@web.de>
return: bool
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

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

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

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

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

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...

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