[ 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: 2239 lines (65 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 61 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_printicon()
  media_managerURL()
  media_uploadform()
  media_getuploadsize()
  media_searchform()
  media_nstree()
  media_nstree_item()
  media_nstree_li()
  media_mod_image()
  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

return: false|string
author: Andreas Gohr <andi@splitbrain.org>
author: Kate Arzamastseva <pshns@ukr.net>
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

return: bool
author: Gerrit Uitslag <klapinklapin@gmail.com>
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)

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

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

return: bool
author: Andreas Gohr <andi@splitbrain.org>
author: Kate Arzamastseva <pshns@ukr.net>
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

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

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

If configured, checks for media references before deletion

return: int One of: 0,
author: Andreas Gohr <andi@splitbrain.org>
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

return: false|string false on error, id of the new file on success
author: Andreas Gohr <andi@splitbrain.org>
author: Michael Klier <chi@chimeric.de>
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/..

triggers: MEDIA_UPLOAD_FINISH
return: false|array|string
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
Callback adapter for media_upload_finish() triggered by MEDIA_UPLOAD_FINISH

return: false|array|string
author: Michael Klier <chi@chimeric.de>
param: array $data event data

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

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

return: int - revision date
author: Kate Arzamastseva <pshns@ukr.net>
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
return: int
author: Andreas Gohr <andi@splitbrain.org>
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>
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

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

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

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

_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: int|string $rev   revision timestamp, or empty string

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

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

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

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

return: array list of tags of the mediafile
author: Kate Arzamastseva <pshns@ukr.net>
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>
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

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

return: string - file's id
author: Kate Arzamastseva <pshns@ukr.net>
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

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

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_managerURL($params = false, $amp = '&amp;', $abs = false, $params_array = false)   X-Ref
Build link based on the current, adding/rewriting parameters

return: string|array - link or link parameters
author: Kate Arzamastseva <pshns@ukr.net>
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

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

media_nstree_li($item)   X-Ref
Userfunction for html_buildlist

Prints a media namespace tree item opener

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

media_mod_image($file, $ext, $w, $h = 0, $crop = false)   X-Ref
Resizes or crop the given image to the given size

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

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

return: string path to resized or original size if failed
author: Andreas Gohr <andi@splitbrain.org>
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
Center crops the given image to the wanted size

return: string path to resized or original size if failed
author: Andreas Gohr <andi@splitbrain.org>
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

return: string token or empty string if no token required
author: Christopher Smith <chris@jalakai.co.uk>
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

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

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

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

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

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

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

return: array            - array(mime type => file ID)
author: Anika Henke <anika@selfthinker.org>
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.

return: boolean
author: Anika Henke <anika@selfthinker.org>
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...

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