Dotclear 2.24
Loading...
Searching...
No Matches
dcMedia Class Reference
Inheritance diagram for dcMedia:
filemanager

Public Member Functions

 __construct (string $type='')
 
 chdir (?string $dir)
 
 addFileHandler (string $type, string $event, $function)
 
 breadCrumb (string $href, string $last='')
 
 setFileSort (string $type='name')
 
 getFSDir ()
 
 getDir ($type=null)
 
 getFile (int $id)
 
 searchMedia (string $query)
 
 getPostMedia (int $post_id, $media_id=null, $link_type=null)
 
 rebuild (string $pwd='')
 
 makeDir (?string $directory)
 
 removeDir (?string $directory)
 
 createFile (string $name, ?string $title=null, bool $private=false, $dt=null, bool $force=true)
 
 updateFile (fileItem $file, fileItem $newFile)
 
 uploadFile (string $tmp, string $name, bool $overwrite=false, ?string $title=null, bool $private=false)
 
 uploadBits (string $name, string $bits)
 
 removeFile (?string $name)
 
 getDBDirs ()
 
 inflateZipFile (fileItem $f, bool $create_dir=true)
 
 getZipContent (fileItem $f)
 
 mediaFireRecreateEvent (fileItem $f)
 
 imageThumbCreate (?cursor $cur, string $f, bool $force=true)
 
 imageThumbRemove (string $f)
 
- Public Member Functions inherited from filemanager
 __construct (?string $root, ?string $root_url='')
 
 chdir (?string $dir)
 
 getPwd ()
 
 writable ()
 
 addExclusion ($list)
 
 inFiles (string $file)
 
 getDir ()
 
 getRootDirs ()
 
 uploadFile (string $tmp, string $dest, bool $overwrite=false)
 
 uploadBits (string $name, string $bits)
 
 makeDir (?string $name)
 
 moveFile (?string $src_path, ?string $dst_path)
 
 removeItem (?string $name)
 
 removeFile (?string $file)
 
 removeDir (?string $directory)
 

Static Public Member Functions

static audioPlayer (string $type, string $url, ?string $player=null, $args=null, bool $fallback=false, bool $preload=true)
 
static videoPlayer (string $type, string $url, ?string $player=null, $args=null, bool $fallback=false, bool $preload=true)
 
static mp3player (string $url, ?string $player=null, $args=null, bool $fallback=false, bool $preload=true)
 
static flvplayer (string $url, ?string $player=null, $args=null)
 

Data Fields

const MEDIA_TABLE_NAME = 'media'
 
 $thumb_tp = '%s/.%s_%s.jpg'
 
 $thumb_tp_alpha = '%s/.%s_%s.png'
 
 $thumb_tp_webp = '%s/.%s_%s.webp'
 
 $thumb_sizes
 
 $icon_img = 'images/media/%s.svg'
 
- Data Fields inherited from filemanager
 $root
 
 $root_url
 
 $dir
 

Protected Member Functions

 callFileHandler (string $type, string $event,... $args)
 
 fileRecord (dcRecord $rs)
 
 sortFileHandler (?fileItem $a, ?fileItem $b)
 
 rebuildDB (?string $pwd)
 
 imageThumbUpdate (fileItem $file, fileItem $newFile)
 
 imageMetaCreate (cursor $cur, string $f, int $id)
 
- Protected Member Functions inherited from filemanager
 isExclude (string $path)
 
 isFileExclude (string $file)
 
 inJail (string $path)
 
 sortHandler (fileItem $a, fileItem $b)
 

Protected Attributes

 $con
 
 $table
 
 $type
 
 $file_sort = 'name-asc'
 
 $path
 
 $relpwd
 
 $file_handler = []
 
 $postmedia
 
- Protected Attributes inherited from filemanager
 $pwd
 
 $exclude_list = []
 
 $exclude_pattern = ''
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( string  $type = '')

Constructs a new instance.

Parameters
string$typeThe media type filter
Exceptions
Exception

References filemanager\$root, filemanager\$root_url, $type, filemanager\addExclusion(), addFileHandler(), dcCore\app(), chdir(), path\clean(), and MEDIA_TABLE_NAME.

Member Function Documentation

◆ chdir()

chdir ( ?string  $dir)

Changes working directory.

Parameters
string$dirThe directory name

Reimplemented from filemanager.

References filemanager\$dir.

Referenced by __construct(), and rebuild().

◆ addFileHandler()

addFileHandler ( string  $type,
string  $event,
  $function 
)

Adds a new file handler for a given media type and event.

Available events are:

  • create: file creation
  • update: file update
  • remove: file deletion
Parameters
string$typeThe media type
string$eventThe event
callable | array$functionThe callback

References $type.

Referenced by __construct().

◆ callFileHandler()

callFileHandler ( string  $type,
string  $event,
  $args 
)
protected

Call filehandler depending on media type and event

Parameters
string$typeThe type
string$eventThe event
mixed...$args The arguments

References $type.

Referenced by createFile(), getDir(), mediaFireRecreateEvent(), removeFile(), and updateFile().

◆ breadCrumb()

breadCrumb ( string  $href,
string  $last = '' 
)

Returns HTML breadCrumb for media manager navigation.

Parameters
string$hrefThe URL pattern
string$lastThe last item pattern
Returns
string HTML code

References filemanager\$pwd.

◆ fileRecord()

fileRecord ( dcRecord  $rs)
protected

Get media file information from recordset

Parameters
dcRecord$rsThe recordset
Returns
fileItem The file item.

References dcCore\app(), path\info(), dcRecord\isEmpty(), filemanager\isFileExclude(), dcAuth\PERMISSION_MEDIA_ADMIN, and dt\str().

Referenced by getDir(), getFile(), getPostMedia(), and searchMedia().

◆ setFileSort()

setFileSort ( string  $type = 'name')

Sets the file sort.

Parameters
string$typeThe type

References $type.

◆ sortFileHandler()

sortFileHandler ( ?fileItem  $a,
?fileItem  $b 
)
protected

Sort calllback

Parameters
fileItem$a1st media
fileItem$b2nd media
Returns
int

◆ getFSDir()

getFSDir ( )

Gets current working directory content (using filesystem).

◆ getDir()

getDir (   $type = null)

Gets current working directory content.

Parameters
mixed$typeThe media type filter
Exceptions
Exception

References filemanager\$dir, $type, dcCore\app(), callFileHandler(), createFile(), fileRecord(), getFile(), files\getMimeType(), filemanager\inFiles(), dcAuth\PERMISSION_MEDIA, and dcAuth\PERMISSION_MEDIA_ADMIN.

◆ getFile()

getFile ( int  $id)

Gets file by its id. Returns a filteItem object.

Parameters
int$idThe file identifier
Returns
fileItem The file.

References dcCore\app(), fileRecord(), and dcAuth\PERMISSION_MEDIA_ADMIN.

Referenced by getDir().

◆ searchMedia()

searchMedia ( string  $query)

Search into media db (only).

Parameters
string$queryThe search query
Returns
bool true or false if nothing found

References dcCore\app(), fileRecord(), and dcAuth\PERMISSION_MEDIA_ADMIN.

◆ getPostMedia()

getPostMedia ( int  $post_id,
  $media_id = null,
  $link_type = null 
)

Returns media items attached to a blog post. Result is an array containing fileItems objects.

Parameters
int$post_idThe post identifier
mixed$media_idThe media identifier(s)
mixed$link_typeThe link type(s)
Returns
array Array of fileItems.

References $path, and fileRecord().

◆ rebuild()

rebuild ( string  $pwd = '')

Rebuilds database items collection. Optional $pwd parameter is the path where to start rebuild.

Parameters
string$pwdThe directory to rebuild
Exceptions
Exception

References filemanager\$dir, filemanager\$pwd, dcCore\app(), chdir(), createFile(), rebuild(), and rebuildDB().

Referenced by rebuild().

◆ rebuildDB()

rebuildDB ( ?string  $pwd)
protected

Rebuilds database items collection. Optional $pwd parameter is the path where to start rebuild else its the current directory

Parameters
string$pwdThe directory to rebuild
Exceptions
Exception

References filemanager\$pwd.

Referenced by rebuild().

◆ makeDir()

makeDir ( ?string  $directory)

Makes a dir.

Parameters
string$directorythe directory to create

Reimplemented from filemanager.

References dcCore\app(), and files\tidyFileName().

◆ removeDir()

removeDir ( ?string  $directory)

Remove a dir.

Removes a directory which is relative to working directory.

Parameters
string$directoryDirectory to remove

Reimplemented from filemanager.

References dcCore\app().

◆ createFile()

createFile ( string  $name,
?string  $title = null,
bool  $private = false,
  $dt = null,
bool  $force = true 
)

Creates or updates a file in database. Returns new media ID or false if file does not exist.

Parameters
string$nameThe file name (relative to working directory)
string$titleThe file title
bool$privateFile is private
mixed$dtFile date
bool$forceThe force flag
Exceptions
Exception
Returns
integer|bool New media ID or false

References dcCore\app(), callFileHandler(), path\clean(), files\getMimeType(), dcAuth\PERMISSION_MEDIA, dcAuth\PERMISSION_MEDIA_ADMIN, and dt\strftime().

Referenced by getDir(), rebuild(), uploadBits(), and uploadFile().

◆ updateFile()

updateFile ( fileItem  $file,
fileItem  $newFile 
)

Updates a file in database.

Parameters
fileItem$fileThe file
fileItem$newFileThe new file
Exceptions
Exception

References dcCore\app(), callFileHandler(), if, filemanager\isFileExclude(), filemanager\moveFile(), dcAuth\PERMISSION_MEDIA, dcAuth\PERMISSION_MEDIA_ADMIN, and files\tidyFileName().

◆ uploadFile()

uploadFile ( string  $tmp,
string  $name,
bool  $overwrite = false,
?string  $title = null,
bool  $private = false 
)

Uploads a file.

Parameters
string$tmpThe full path of temporary uploaded file
string$nameThe file name (relative to working directory)me
bool$overwriteFile should be overwrite
string$titleThe file title (should be string|null)
bool$privateFile is private
Exceptions
Exception
Returns
mixed New media ID or false (should be int|false)

References dcCore\app(), createFile(), dcAuth\PERMISSION_MEDIA, dcAuth\PERMISSION_MEDIA_ADMIN, and files\tidyFileName().

◆ uploadBits()

uploadBits ( string  $name,
string  $bits 
)

Creates a file from binary content.

Parameters
string$nameThe file name (relative to working directory)
string$bitsThe binary file contentits
Exceptions
Exception
Returns
string New media ID or false

Reimplemented from filemanager.

References dcCore\app(), createFile(), dcAuth\PERMISSION_MEDIA, dcAuth\PERMISSION_MEDIA_ADMIN, and files\tidyFileName().

◆ removeFile()

removeFile ( ?string  $name)

Removes a file.

Parameters
string$namefilename
Exceptions
Exception

Reimplemented from filemanager.

References dcCore\app(), callFileHandler(), path\clean(), files\getMimeType(), dcAuth\PERMISSION_MEDIA, and dcAuth\PERMISSION_MEDIA_ADMIN.

◆ getDBDirs()

getDBDirs ( )

Root directories

Returns an array of directory under $root directory.

@uses fileItem

Returns
array

References filemanager\$dir.

◆ inflateZipFile()

inflateZipFile ( fileItem  $f,
bool  $create_dir = true 
)

Extract zip file in current location.

Parameters
fileItem$ffileItem object
bool$create_dirCreate dir
Exceptions
Exception
Returns
string destination

References text\deaccent().

◆ getZipContent()

getZipContent ( fileItem  $f)

Gets the zip content.

Parameters
fileItem$ffileItem object
Returns
array The zip content.

◆ mediaFireRecreateEvent()

mediaFireRecreateEvent ( fileItem  $f)

Calls file handlers registered for recreate event.

Parameters
fileItem$ffileItem object

References callFileHandler(), and files\getMimeType().

◆ imageThumbCreate()

imageThumbCreate ( ?cursor  $cur,
string  $f,
bool  $force = true 
)

Create image thumbnails

Parameters
cursor$curThe cursor
string$fImage filename
bool$forceForce creation
Returns
bool

References imageThumbRemove(), and path\info().

◆ imageThumbUpdate()

imageThumbUpdate ( fileItem  $file,
fileItem  $newFile 
)
protected

Update image thumbnails

Parameters
fileItem$fileThe file
fileItem$newFileThe new file
Returns
bool

References path\info().

◆ imageThumbRemove()

imageThumbRemove ( string  $f)

Remove image thumbnails

Parameters
string$fImage filename
Returns
bool

References path\info().

Referenced by imageThumbCreate().

◆ imageMetaCreate()

imageMetaCreate ( cursor  $cur,
string  $f,
int  $id 
)
protected

Create image meta

Parameters
cursor$curThe cursor
string$fImage filename
int$idThe media identifier
Returns
bool

References dcCore\app(), dt\getTimeOffset(), imageMeta\readMeta(), and dt\str().

◆ audioPlayer()

static audioPlayer ( string  $type,
string  $url,
?string  $player = null,
  $args = null,
bool  $fallback = false,
bool  $preload = true 
)
static

Returns HTML code for audio player (HTML5)

Parameters
string$typeThe audio mime type
string$urlThe audio URL to play
string$playerThe player URL
mixed$argsThe player arguments
bool$fallbackThe fallback
bool$preloadAdd preload="auto" attribute if true, else preload="none"
Returns
string

Referenced by adminMediaList\mediaLine(), and mp3player().

◆ videoPlayer()

static videoPlayer ( string  $type,
string  $url,
?string  $player = null,
  $args = null,
bool  $fallback = false,
bool  $preload = true 
)
static

Returns HTML code for video player (HTML5)

Parameters
string$typeThe video mime type
string$urlThe video URL to play
string$playerThe player URL
mixed$argsThe player arguments
bool$fallbackThe fallback (not more used)
bool$preloadAdd preload="auto" attribute if true, else preload="none"
Returns
string

References $type.

◆ mp3player()

static mp3player ( string  $url,
?string  $player = null,
  $args = null,
bool  $fallback = false,
bool  $preload = true 
)
static

Returns HTML code for MP3 player (HTML5)

Parameters
string$urlThe audio URL to play
string$playerThe player URL
mixed$argsThe player arguments
bool$fallbackThe fallback (not more used)
bool$preloadAdd preload="auto" attribute if true, else preload="none"
Returns
string

References audioPlayer().

◆ flvplayer()

static flvplayer ( string  $url,
?string  $player = null,
  $args = null 
)
static

Returns HTML code for FLV player

Parameters
string$urlThe url
string$playerThe player
mixed$argsThe arguments
Returns
string
Deprecated:
since 2.15

Field Documentation

◆ MEDIA_TABLE_NAME

const MEDIA_TABLE_NAME = 'media'

◆ $con

$con
protected

◆ $table

$table
protected

◆ $type

◆ $file_sort

$file_sort = 'name-asc'
protected

◆ $path

$path
protected

Referenced by getPostMedia().

◆ $relpwd

$relpwd
protected

◆ $file_handler

$file_handler = []
protected

◆ $postmedia

$postmedia
protected

◆ $thumb_tp

$thumb_tp = '%s/.%s_%s.jpg'

◆ $thumb_tp_alpha

$thumb_tp_alpha = '%s/.%s_%s.png'

◆ $thumb_tp_webp

$thumb_tp_webp = '%s/.%s_%s.webp'

◆ $thumb_sizes

$thumb_sizes
Initial value:
= [
'm' => [448, 'ratio', 'medium'],
's' => [240, 'ratio', 'small'],
't' => [100, 'ratio', 'thumbnail'],
'sq' => [48, 'crop', 'square'],
]

◆ $icon_img

$icon_img = 'images/media/%s.svg'

The documentation for this class was generated from the following file: