2010-03-14 02:11:23 +00:00
< ? php
/*
* e107 website system
*
2016-12-25 18:36:38 +00:00
* Copyright ( C ) 2008 - 2016 e107 Inc ( e107 . org )
2010-03-14 02:11:23 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* Administration - Media Management Class
*
*/
if ( ! defined ( 'e107_INIT' )) { exit ; }
2016-12-25 18:36:38 +00:00
//TODO LANS
2016-01-24 00:37:36 -08:00
2010-03-14 02:11:23 +00:00
class e_media
{
2012-05-17 09:19:44 +00:00
protected $imagelist = array ();
2015-02-07 11:57:28 -08:00
protected $logging = false ;
2012-05-22 13:32:49 +00:00
2012-05-17 09:19:44 +00:00
protected $mimePaths = array (
'text' => e_MEDIA_FILE ,
'multipart' => e_MEDIA_FILE ,
'application' => e_MEDIA_FILE ,
2014-11-03 16:13:27 +02:00
'audio' => e_MEDIA_FILE ,
2012-05-17 09:19:44 +00:00
'image' => e_MEDIA_IMAGE ,
'video' => e_MEDIA_VIDEO ,
'other' => e_MEDIA_FILE
);
2018-07-18 14:40:29 -07:00
protected $mimeExtensions = array (
'text' => array ( 'txt' ),
'multipart' => array (),
'application' => array ( 'zip' , 'doc' , 'gz' ),
'audio' => array ( 'mp3' , 'wav' ),
'image' => array ( 'jpeg' , 'jpg' , 'png' , 'gif' , 'svg' ),
'video' => array ( 'mp4' , 'youtube' , 'youtubepl' ),
'other' => array (),
// 'glyph' => array('glyph')
);
2012-05-17 09:19:44 +00:00
2015-02-07 11:57:28 -08:00
function __construct ()
{
if ( E107_DEBUG_LEVEL > 0 )
{
$this -> logging = true ;
2016-01-24 00:37:36 -08:00
}
2017-01-23 09:41:23 -08:00
e107 :: includeLan ( e_LANGUAGEDIR . e_LANGUAGE . '/admin/lan_image.php' );
2015-02-07 11:57:28 -08:00
}
2016-03-06 17:42:47 -08:00
public function debug ( $val )
{
$this -> logging = intval ( $val );
}
2010-03-14 02:11:23 +00:00
/**
* Import files from specified path into media database .
* @ param string $cat Category nickname
* @ param string $epath path to file .
2012-07-23 02:25:17 +00:00
* @ param string $fmask [ optional ] filetypes eg . . jpg |. gif IMAGES is the default mask .
2010-04-15 15:38:16 +00:00
* @ return e_media
2010-03-14 02:11:23 +00:00
*/
2015-08-24 17:39:28 -07:00
public function import ( $cat = '' , $epath , $fmask = '' , $options = array ())
2010-03-14 02:11:23 +00:00
{
2010-04-15 15:38:16 +00:00
if ( ! vartrue ( $cat )){ return $this ;}
2012-04-22 06:19:21 +00:00
2013-03-08 02:19:18 -08:00
if ( is_string ( $options ))
{
parse_str ( $options , $options );
}
2010-03-14 02:11:23 +00:00
if ( ! is_readable ( $epath ))
{
2015-08-24 17:39:28 -07:00
e107 :: getMessage () -> addDebug ( " Unable to import: " . $epath );
2010-04-15 15:38:16 +00:00
return $this ;
2010-03-14 02:11:23 +00:00
}
2012-04-22 06:19:21 +00:00
2010-03-14 02:11:23 +00:00
$fl = e107 :: getFile ();
$tp = e107 :: getParser ();
$sql = e107 :: getDb ();
$mes = e107 :: getMessage ();
$fl -> setFileInfo ( 'all' );
2015-08-24 17:39:28 -07:00
if ( empty ( $fmask ))
2010-04-15 15:38:16 +00:00
{
$fmask = '[a-zA-z0-9_-]+\.(png|jpg|jpeg|gif|PNG|JPG|JPEG|GIF)$' ;
}
2015-08-24 17:39:28 -07:00
$img_array = $fl -> get_files ( $epath , $fmask , '' , 2 );
2010-03-14 02:11:23 +00:00
2014-05-25 02:21:59 -07:00
if ( ! count ( $img_array ))
{
e107 :: getMessage () -> addDebug ( " Media-Import could not find any files in <b> " . $epath . " </b> with fmask: " . $fmask );
return $this ;
}
2010-03-14 02:11:23 +00:00
2012-05-25 11:30:49 +00:00
// print_a($img_array);
// return;
2012-12-07 15:16:42 -08:00
$count = 0 ;
2010-03-14 02:11:23 +00:00
foreach ( $img_array as $f )
{
2013-03-08 02:19:18 -08:00
2013-05-01 02:10:02 -07:00
if ( $f [ 'fsize' ] === 0 ) // prevent zero-byte files.
{
continue ;
}
2013-03-08 02:19:18 -08:00
if ( vartrue ( $options [ 'min-width' ]) && ( $f [ 'img-width' ] < $options [ 'min-width' ]))
{
continue ;
}
if ( vartrue ( $options [ 'min-size' ]) && ( $f [ 'fsize' ] < $options [ 'min-size' ]))
{
continue ;
}
2010-03-14 02:11:23 +00:00
$fullpath = $tp -> createConstants ( $f [ 'path' ] . $f [ 'fname' ], 1 );
2012-04-26 01:33:33 +00:00
// echo "<br />cat=".$cat;
2010-03-14 02:11:23 +00:00
$insert = array (
'media_caption' => $f [ 'fname' ],
'media_description' => '' ,
'media_category' => $cat ,
'media_datestamp' => $f [ 'modified' ],
2012-05-25 11:30:49 +00:00
'media_url' => $fullpath ,
2012-07-18 06:34:26 +00:00
'media_userclass' => '0' ,
2012-05-25 11:30:49 +00:00
'media_name' => $f [ 'fname' ],
'media_author' => USERID ,
'media_size' => $f [ 'fsize' ],
2013-03-21 19:45:51 -07:00
'media_dimensions' => vartrue ( $f [ 'img-width' ]) ? $f [ 'img-width' ] . " x " . $f [ 'img-height' ] : " " ,
2012-05-25 11:30:49 +00:00
'media_usedby' => '' ,
'media_tags' => '' ,
'media_type' => $f [ 'mime' ]
2010-03-14 02:11:23 +00:00
);
2015-02-07 11:57:28 -08:00
if ( ! $sql -> select ( 'core_media' , 'media_url' , " media_url = ' " . $fullpath . " ' LIMIT 1 " ))
2010-03-14 02:11:23 +00:00
{
2012-04-26 01:33:33 +00:00
2015-02-07 11:57:28 -08:00
if ( $sql -> insert ( " core_media " , $insert ))
2010-03-14 02:11:23 +00:00
{
2012-12-07 15:16:42 -08:00
$count ++ ;
$mes -> addDebug ( " Imported Media: " . $f [ 'fname' ]);
2010-03-14 02:11:23 +00:00
}
else
{
2010-04-15 15:38:16 +00:00
$mes -> addError ( " Media not imported: " . $f [ 'fname' ]);
2010-03-14 02:11:23 +00:00
}
}
}
2012-12-07 15:16:42 -08:00
if ( $count )
{
// $mes->addSuccess("Imported {$count} Media items.");
}
2010-04-15 15:38:16 +00:00
return $this ;
2010-03-14 02:11:23 +00:00
}
/**
* Import icons into media - manager from specified path .
* @ param string $path
2010-04-15 15:38:16 +00:00
* @ return e_media
2010-03-14 02:11:23 +00:00
*/
public function importIcons ( $path )
{
$iconsrch = array ( 16 , 32 , 48 , 64 );
foreach ( $iconsrch as $size )
{
2010-04-15 15:38:16 +00:00
$types = '[a-zA-z0-9_-]+' . $size . '\.(png|PNG)$' ;
2010-03-14 02:11:23 +00:00
$this -> import ( '_icon_' . $size , $path , $types );
}
2017-01-31 08:23:04 -08:00
$types = '[a-zA-z0-9_-]\.(svg|SVG)$' ;
$this -> import ( '_icon_svg' , $path , $types );
2010-04-15 15:38:16 +00:00
return $this ;
2010-03-14 02:11:23 +00:00
}
/**
* Remove Media from media table
* @ param string $cat [ optional ] remove a full category of media
* @ return
*/
function removeCat ( $cat )
{
$tp = e107 :: getParser ();
$sql = e107 :: getDb ();
$mes = e107 :: getMessage ();
if ( vartrue ( $cat ))
{
2015-02-07 11:57:28 -08:00
$status = ( $sql -> delete ( 'core_media' , " media_cat = ' " . $cat . " ' " )) ? TRUE : FALSE ;
2010-03-14 02:11:23 +00:00
$mes -> add ( " Removing Media in Category: " . $cat , E_MESSAGE_DEBUG );
return $status ;
}
}
/**
* Remove Media from media table
* @ param string $epath remove media in the specified path .
* @ param string $type [ optional ] image | icon
* @ return
*/
function removePath ( $epath , $type = 'image' )
{
$tp = e107 :: getParser ();
$sql = e107 :: getDb ();
$mes = e107 :: getMessage ();
$qry = ( $type == 'icon' ) ? " AND media_category REGEXP '_icon_16|_icon_32|_icon_48|_icon_64' " : " AND NOT media_category REGEXP '_icon_16|_icon_32|_icon_48|_icon_64' " ;
if ( vartrue ( $epath ))
{
$path = $tp -> createConstants ( $epath , 'rel' );
2015-02-07 11:57:28 -08:00
$status = ( $sql -> delete ( 'core_media' , " media_url LIKE ' " . $path . " %' " . $qry )) ? TRUE : FALSE ;
2010-03-14 02:11:23 +00:00
$message = ( $type == 'image' ) ? " Removing Media with path: " . $path : " Removing Icons with path: " . $path ;
$mes -> add ( $message , E_MESSAGE_DEBUG );
return $status ;
}
}
/**
* Return a list if icons in the specified path
* @ param string $epath
* @ return array
*/
function listIcons ( $epath )
{
if ( ! $epath ) return ;
$ret = array ();
$sql = e107 :: getDb ();
$tp = e107 :: getParser ();
$path = $tp -> createConstants ( $epath , 'rel' );
2017-01-31 14:50:55 -08:00
$status = ( $sql -> gen ( " SELECT * FROM `#core_media` WHERE `media_url` LIKE ' " . $path . " %' AND media_category REGEXP '_icon_16|_icon_32|_icon_48|_icon_64|_icon_svg' " )) ? TRUE : FALSE ;
2015-02-07 11:57:28 -08:00
while ( $row = $sql -> fetch ())
2010-03-14 02:11:23 +00:00
{
$ret [] = $row [ 'media_url' ];
}
return $ret ;
}
2010-04-15 15:38:16 +00:00
/**
* Create media category .
* 'class' data is optional , 'id' key is ignored
*
2012-08-19 02:33:43 +00:00
* @ param array $data associative array , db keys should be passed without the leading 'media_cat_' e . g . 'class' , 'type' , etc .
2010-04-15 15:38:16 +00:00
* @ return integer last inserted ID or false on error
*/
2012-08-19 02:33:43 +00:00
public function createCategory ( $datas )
2010-04-15 15:38:16 +00:00
{
2012-08-19 02:33:43 +00:00
foreach ( $datas as $k => $v )
2010-04-15 15:38:16 +00:00
{
$data [ 'media_cat_' . $k ] = $v ;
}
$data [ 'media_cat_id' ] = 0 ;
2012-08-19 02:33:43 +00:00
if ( ! isset ( $data [ 'media_cat_class' ]) || '' === $data [ 'media_cat_class' ])
{
$data [ 'media_cat_class' ] = defset ( 'e_UC_MEMBER' , 253 );
}
2015-02-07 11:57:28 -08:00
return e107 :: getDb () -> insert ( 'core_media_cat' , $data );
2010-04-15 15:38:16 +00:00
}
2014-02-09 15:44:43 -08:00
/**
2015-02-15 02:37:36 -08:00
* Create a user Media - Category .
2014-02-09 15:44:43 -08:00
* @ param $type string image | file | video
2015-02-15 02:37:36 -08:00
* @ param $userId int - leave empty for currently logged in user .
2014-02-09 15:44:43 -08:00
* @ param $userName string - leave blank for currently logged in user
2015-02-15 02:37:36 -08:00
* @ param $parms ( optional ) - for future use .
* @ return bool | int
2014-02-09 15:44:43 -08:00
*/
public function createUserCategory ( $type = 'image' , $userId = USERID , $userName = USERNAME , $parms = null )
{
if ( $type != 'image' && $type = 'file' && $type != 'video' )
{
return false ;
}
$cat = 'user_' . $type . '_' . intval ( $userId );
if ( ! e107 :: getDb () -> gen ( 'SELECT media_cat_id FROM #core_media_cat WHERE media_cat_category = "' . $cat . '" LIMIT 1' ))
{
$insert = array (
'owner' => 'user' ,
'category' => $cat ,
'title' => $userName ,
'sef' => 'media-' . eHelper :: title2sef ( $userName ),
'diz' => '' ,
'class' => '' ,
'image' => '' ,
'order' => ''
);
return $this -> createCategory ( $insert );
}
return false ;
}
2010-04-15 15:38:16 +00:00
/**
* Create multiple media categories in once
* @ param array $data
* @ return integer number of successfully inserted records
*/
public function createCategories ( $multi_data )
{
$cnt = 0 ;
foreach ( $multi_data as $cats )
{
if ( $this -> createCategory ( $cats )) $cnt ++ ;
}
return $cnt ;
}
public function deleteCategory ( $id )
{
// TODO
}
2011-05-05 11:30:00 +00:00
2012-08-19 02:33:43 +00:00
public function deleteAllCategories ( $owner = '' )
{
if ( $owner == '' )
{
2018-07-27 12:07:43 -07:00
return null ;
2012-08-19 02:33:43 +00:00
}
$sql = e107 :: getDb ();
2015-02-07 11:57:28 -08:00
$sql -> select ( 'core_media_cat' , " media_cat_category " , " media_cat_owner = ' " . $owner . " ' " );
2012-08-19 02:33:43 +00:00
while ( $row = $sql -> db_Fetch ())
{
$categories [] = " ' " . $row [ 'media_cat_category' ] . " ' " ;
}
2015-02-07 11:57:28 -08:00
if ( $sql -> delete ( 'core_media_cat' , " media_cat_owner = ' " . $owner . " ' " ))
2012-08-19 02:33:43 +00:00
{
//TODO retrieve all category names for owner, and reset all media categories to _common.
return TRUE ;
// return $sql->db_Update('core_media', "media_category = '_common_image' WHERE media_category IN (".implode(",",$categories).")");
}
return FALSE ;
}
2011-05-10 12:47:03 +00:00
/**
* Return an Array of Media Categories
*/
2012-04-22 06:19:21 +00:00
public function getCategories ( $owner = '' )
2011-05-10 12:47:03 +00:00
{
$ret = array ();
2012-04-22 06:19:21 +00:00
$qry = " SELECT * FROM #core_media_cat " ;
2012-07-14 10:51:37 +00:00
$qry .= ( $owner ) ? " WHERE media_cat_owner = ' " . $owner . " ' " : " (1) " ;
$qry .= " AND media_cat_class IN ( " . USERCLASS_LIST . " ) " ;
2012-04-22 06:19:21 +00:00
$qry .= " ORDER BY media_cat_order " ;
2012-12-15 18:06:55 -08:00
e107 :: getDb () -> gen ( $qry );
2016-02-14 12:15:55 -08:00
while ( $row = e107 :: getDb () -> fetch ())
2011-05-10 12:47:03 +00:00
{
2012-04-22 06:19:21 +00:00
$id = $row [ 'media_cat_category' ];
$ret [ $id ] = $row ;
2011-05-10 12:47:03 +00:00
}
return $ret ;
}
2012-04-24 08:36:35 +00:00
/**
* Return the total number of Images in a particular category
2012-04-28 01:31:30 +00:00
*
2012-04-24 08:36:35 +00:00
*/
2012-08-04 04:15:41 +00:00
public function countImages ( $cat , $search = null )
2012-04-24 08:36:35 +00:00
{
2013-03-09 20:30:37 -08:00
return $this -> getImages ( $cat , 0 , 'all' , $search );
/*
2012-08-04 04:15:41 +00:00
$inc = array ();
$searchinc = array ();
2012-05-24 07:24:49 +00:00
if ( strpos ( $cat , " + " ) || ! $cat )
{
$cat = str_replace ( " + " , " " , $cat );
$inc [] = " media_category = '_common_image' " ;
}
if ( $cat )
{
$inc [] = " media_category REGEXP '(^|,)( " . $cat . " )(,| $ )' " ; // for multiple category field.
}
2012-08-04 04:15:41 +00:00
if ( $search )
{
$searchinc [] = " media_name LIKE '% " . $search . " %' " ;
$searchinc [] = " media_description LIKE '% " . $search . " %' " ;
$searchinc [] = " media_caption LIKE '% " . $search . " %' " ;
$searchinc [] = " media_tags LIKE '% " . $search . " %' " ;
}
2012-05-24 07:24:49 +00:00
$query = " SELECT * FROM #core_media WHERE media_userclass IN ( " . USERCLASS_LIST . " ) AND ( " . implode ( " OR " , $inc ) . " ) " ;
2012-08-04 04:15:41 +00:00
if ( $search )
{
$query .= " AND ( " . implode ( " OR " , $searchinc ) . " ) " ;
}
2016-02-15 00:56:08 -08:00
return e107 :: getDb () -> gen ( $query );
2013-03-09 20:30:37 -08:00
*/
2012-04-24 08:36:35 +00:00
}
2011-05-10 12:47:03 +00:00
2018-07-26 20:14:42 -07:00
public function getFiles ( $cat , $from = 0 , $amount = null , $search = null )
2014-07-05 20:27:37 -07:00
{
2018-07-26 20:14:42 -07:00
return $this -> getMedia ( 'application' , $from , $amount , $search );
2014-07-05 20:27:37 -07:00
}
2015-02-15 02:37:36 -08:00
2018-07-26 19:13:27 -07:00
public function getVideos ( $cat , $from = 0 , $amount = null , $search = null )
2018-07-16 17:14:10 -07:00
{
2018-07-26 19:13:27 -07:00
return $this -> getMedia ( 'video' , $cat , $from , $amount , $search );
2018-07-16 17:14:10 -07:00
}
2018-07-19 12:43:04 -07:00
2018-07-26 19:13:27 -07:00
public function getAudios ( $cat = '' , $from = 0 , $amount = null , $search = null )
2018-07-19 12:43:04 -07:00
{
2018-07-26 19:13:27 -07:00
return $this -> getMedia ( 'audio' , $cat , $from , $amount , $search );
2018-07-19 12:43:04 -07:00
}
2011-05-10 12:47:03 +00:00
/**
* Return an array of Images in a particular category
2012-04-28 01:31:30 +00:00
* @ param string $cat : category name . use + to include _common eg . 'news+'
2014-01-14 08:16:12 -08:00
* @ param $from
* @ param $amount
* @ param $search
2015-02-15 02:37:36 -08:00
* @ return array
2011-05-10 12:47:03 +00:00
*/
2016-03-29 11:44:50 +02:00
public function getImages ( $cat = '' , $from = 0 , $amount = null , $search = null , $orderby = null )
2018-07-26 19:13:27 -07:00
{
return $this -> getMedia ( 'image' , $cat , $from , $amount , $search , $orderby );
}
/**
* Return an array of Images in a particular category
* @ param string $type image | audio | video
* @ param string $cat : category name . use + to include _common eg . 'news+'
* @ param $from
* @ param $amount
* @ param $search
* @ return array
*/
private function getMedia ( $type , $cat = '' , $from = 0 , $amount = null , $search = null , $orderby = null )
2011-05-10 12:47:03 +00:00
{
2012-08-04 04:15:41 +00:00
$inc = array ();
$searchinc = array ();
2012-04-28 01:31:30 +00:00
if ( strpos ( $cat , " + " ) || ! $cat )
{
$cat = str_replace ( " + " , " " , $cat );
2018-07-26 19:13:27 -07:00
$catArray [] = '_common_' . $type ;
2012-04-28 01:31:30 +00:00
}
if ( $cat )
{
2013-10-09 15:48:19 -07:00
if ( strpos ( $cat , " | " ) && ! strpos ( $cat , " + " ) )
{
$catArray = explode ( " | " , $cat );
}
else
{
2018-08-06 14:11:28 -07:00
$catArray [] = $cat ;
if ( $type === 'image' )
{
$catArray [] = $cat . '_image' ; // BC Fix.
}
2013-10-09 15:48:19 -07:00
}
2012-04-28 01:31:30 +00:00
}
2018-07-26 20:14:42 -07:00
2011-05-10 12:47:03 +00:00
// TODO check the category is valid.
2012-08-04 04:15:41 +00:00
if ( $search )
{
2018-07-22 14:45:26 -07:00
$searchinc [] = " media_name LIKE '% " . $search . " %' " ;
2012-08-04 04:15:41 +00:00
$searchinc [] = " media_description LIKE '% " . $search . " %' " ;
$searchinc [] = " media_caption LIKE '% " . $search . " %' " ;
$searchinc [] = " media_tags LIKE '% " . $search . " %' " ;
}
2012-04-28 01:31:30 +00:00
2012-08-04 04:15:41 +00:00
2011-05-10 12:47:03 +00:00
$ret = array ();
2013-03-09 19:22:30 -08:00
2013-03-09 20:30:37 -08:00
$fields = ( $amount == 'all' ) ? " media_id " : " * " ;
2018-07-26 19:13:27 -07:00
$query = " SELECT " . $fields . " FROM #core_media WHERE `media_category` REGEXP '(^|,) " . implode ( " | " , $catArray ) . " (,| $ )'
AND `media_userclass` IN ( " .USERCLASS_LIST. " )
AND `media_type` LIKE '".$type."/%' " ;
2016-12-30 14:45:22 -08:00
2012-08-04 04:15:41 +00:00
if ( $search )
{
$query .= " AND ( " . implode ( " OR " , $searchinc ) . " ) " ;
}
2016-03-29 11:44:50 +02:00
if ( $orderby )
{
$query .= " ORDER BY " . $orderby ;
}
else
{
$query .= " ORDER BY media_id DESC " ;
}
2012-08-04 04:15:41 +00:00
2013-03-09 20:30:37 -08:00
if ( $amount == 'all' )
{
return e107 :: getDb () -> gen ( $query );
}
2012-04-24 08:36:35 +00:00
if ( $amount )
{
$query .= " LIMIT " . $from . " , " . $amount ;
}
2016-12-30 14:45:22 -08:00
2018-07-22 14:45:26 -07:00
e107 :: getDebug () -> log ( $query );
2016-12-30 14:45:22 -08:00
2013-03-09 19:22:30 -08:00
e107 :: getDb () -> gen ( $query );
2016-02-14 12:15:55 -08:00
while ( $row = e107 :: getDb () -> fetch ())
2011-05-10 12:47:03 +00:00
{
$id = $row [ 'media_id' ];
$ret [ $id ] = $row ;
}
return $ret ;
}
2012-05-17 05:09:59 +00:00
/**
* Return an array of Images in a particular category
* @ param string $type : 16 | 32 | 48 | 64
* @ param integer $from
* @ param integer $amount
2015-02-15 02:37:36 -08:00
* @ return array
2012-05-17 05:09:59 +00:00
*/
public function getIcons ( $type = '' , $from = 0 , $amount = null )
{
$inc = array ();
if ( $type )
{
$inc [] = " media_category = '_icon_ " . $type . " ' " ;
}
$ret = array ();
$query = " SELECT * FROM #core_media WHERE media_userclass IN ( " . USERCLASS_LIST . " ) AND media_category LIKE '_icon%' " ;
$query .= ( count ( $inc )) ? " AND ( " . implode ( " OR " , $inc ) . " ) " : " " ;
$query .= " ORDER BY media_category, media_name " ;
if ( $amount )
{
$query .= " LIMIT " . $from . " , " . $amount ;
}
2016-01-24 00:37:36 -08:00
e107 :: getDb () -> gen ( $query );
2018-07-27 17:39:44 -07:00
while ( $row = e107 :: getDb () -> fetch ())
2012-05-17 05:09:59 +00:00
{
$id = $row [ 'media_id' ];
$ret [ $id ] = $row ;
}
return $ret ;
}
2011-05-05 11:30:00 +00:00
/**
2013-02-23 03:15:13 -08:00
* Generate Simple Thumbnail window for image - selection
2011-05-05 11:30:00 +00:00
*/
2013-03-22 16:55:22 -07:00
private function imageSelect ( $cat , $formid = 'imageSel' )
2011-05-05 11:30:00 +00:00
{
$sql = e107 :: getDb ();
$tp = e107 :: getParser ();
2016-01-24 00:37:36 -08:00
$text = " <div style='margin-left:500px;text-align:center; position:relative;z-index:1000;float:left;display:none' id=' { $formid } '> " ;
2011-05-05 11:30:00 +00:00
$text .= " <div style='-moz-box-shadow: 3px 3px 3px #808080;
- webkit - box - shadow : 3 px 3 px 3 px #808080;
box - shadow : 3 px 3 px 3 px #808080;
background - color : black ; border : 1 px solid black ; position : absolute ; height : 200 px ; width : 205 px ; overflow - y : scroll ; bottom : 30 px ; right : 100 px ' > " ;
2016-01-24 00:37:36 -08:00
$total = ( $sql -> gen ( " SELECT * FROM `#core_media` WHERE media_category = '_common' OR media_category = ' " . $cat . " ' ORDER BY media_category,media_datestamp DESC " )) ? TRUE : FALSE ;
2016-12-25 18:36:38 +00:00
$text .= " <div style='font-size:120%;font-weight:bold;text-align:right;margin-right:10px'><a title=' " . LAN_CLOSE . " ' style='text-decoration:none;color:white' href='#' onclick= \" expandit(' { $formid } '); return false; \" >x</a></div> " ;
2011-05-05 11:30:00 +00:00
while ( $row = $sql -> db_Fetch ())
{
$image = $row [ 'media_url' ];
$diz = $row [ 'media_name' ] . " : " . $row [ 'media_dimensions' ];
2011-05-07 07:16:45 +00:00
$insert = " [img] " . $image . " [/img] " ;
2011-05-05 11:30:00 +00:00
$text .= "
< div style = 'border:1px solid silver;margin:5px;width:50px;height:50px;overflow:hidden;float:left' >
2011-12-10 00:00:15 +00:00
< a title = \ " " . $diz . " \" href='#' onclick= \" addtext(' " . $insert . " ', true); expandit(' { $formid } '); return false; \" >
< img src = '".e107::getParser()->thumbUrl($image, ' w = 100 ', true)."' alt = \ " " . $diz . " \" style='width: 50px' />
2011-05-05 11:30:00 +00:00
</ a >
</ div > " ;
}
$text .= " </div></div> " ;
return $text ;
}
2010-03-14 02:11:23 +00:00
2012-04-28 01:31:30 +00:00
2013-03-22 16:55:22 -07:00
private function mediaSelectNav ( $category , $tagid = '' , $option = null )
2012-04-28 01:31:30 +00:00
{
2013-03-22 16:55:22 -07:00
if ( is_string ( $option ))
{
parse_str ( $option , $option );
}
2012-05-24 07:24:49 +00:00
2013-03-22 16:55:22 -07:00
$cat = varset ( $category ) ? '&for=' . $category : " " ;
$cat .= varset ( $tagid ) ? '&tagid=' . $tagid : " " ;
2012-08-04 04:15:41 +00:00
2013-03-22 16:55:22 -07:00
$cat .= varset ( $option [ 'bbcode' ]) ? '&bbcode=' . $option [ 'bbcode' ] : " " ;
$cat .= varset ( $option [ 'limit' ]) ? " &limit= " . $option [ 'limit' ] : " " ;
$cat .= varset ( $option [ 'frm' ]) ? " &frm= " . $option [ 'frm' ] : " " ;
$cat .= varset ( $option [ 'w' ]) ? " &w= " . $option [ 'w' ] : " " ;
2014-01-08 15:51:14 -08:00
$action = varset ( $option [ 'action' ], 'nav' );
2013-03-22 16:55:22 -07:00
2014-01-08 15:51:14 -08:00
$url = e_ADMIN_ABS . " image.php?mode=main&action= " . $action . " &iframe=1 " . $cat . " &from=0 " ;
2012-05-24 07:24:49 +00:00
return $url ;
}
2018-07-27 12:07:43 -07:00
/**
* @ deprecated by browserCarousel
* @ param string $category
* @ param null $tagid
* @ param null $att
* @ return string
*/
2012-05-24 07:24:49 +00:00
public function mediaSelect ( $category = '' , $tagid = null , $att = null )
{
2013-03-09 19:22:30 -08:00
if ( is_string ( $att ))
{
parse_str ( $att , $option ); // grab 'onclick' .
}
2014-11-03 16:13:27 +02:00
else {
$option = $att ;
2013-03-09 19:22:30 -08:00
}
2016-03-11 12:31:09 -08:00
$tp = e107 :: getParser ();
2012-05-24 07:24:49 +00:00
2013-03-21 18:23:40 -07:00
$frm = varset ( $option [ 'from' ]) ? $option [ 'from' ] : 0 ;
$limit = varset ( $option [ 'limit' ]) ? $option [ 'limit' ] : 20 ;
2012-05-24 07:24:49 +00:00
$newfrm = $frm + $limit ;
2013-03-21 18:23:40 -07:00
$bbcode = varset ( $option [ 'bbcode' ]) ? $option [ 'bbcode' ] : null ;
$navMode = varset ( $option [ 'nav' ]) ? TRUE : FALSE ;
$search = varset ( $option [ 'search' ]) ? $option [ 'search' ] : null ;
2016-03-11 12:31:09 -08:00
$prevId = $tagid . " _prev " ; // ID of image in Form.
2012-05-24 07:24:49 +00:00
if ( $category != '_icon' )
2012-05-17 05:09:59 +00:00
{
2018-08-06 13:33:38 -07:00
$cat = ( $category ) ? $category : " " ; // the '+' loads category '_common' as well as the chosen category.
2012-08-04 04:15:41 +00:00
$images = $this -> getImages ( $cat , $frm , $limit , $search );
2012-05-17 05:09:59 +00:00
$class = " media-select-image " ;
2016-03-11 12:31:09 -08:00
$classN = " media-select-image-none " ;
2012-05-17 05:09:59 +00:00
$w = 120 ;
$h = 100 ;
2012-08-04 04:15:41 +00:00
$total = $this -> countImages ( $cat , $search );
2016-03-11 12:31:09 -08:00
$onclick_clear = " parent.document.getElementById(' { $tagid } ').value = '';
parent . document . getElementById ( '".$prevId."' ) . src = '".e_IMAGE_ABS."generic/nomedia.png' ;
return false ; " ;
2012-05-17 05:09:59 +00:00
}
else // Icons
{
$cat = " " ;
$images = $this -> getIcons ( $cat , 0 , 200 );
$class = " media-select-icon " ;
2016-03-11 12:31:09 -08:00
$classN = " media-select-icon-none " ;
2012-05-17 05:09:59 +00:00
$w = 64 ;
$h = 64 ;
2012-05-24 07:24:49 +00:00
$total = 500 ;
2017-01-31 14:50:55 -08:00
$total = $this -> countImages ( " _icon_16|_icon_32|_icon_48|_icon_64|_icon_svg " , $search );
2016-03-11 12:31:09 -08:00
$onclick_clear = " parent.document.getElementById(' { $tagid } ').value = '';
parent . document . getElementById ( '".$prevId."' ) . innerHTML = '' ;
return false ; " ;
2012-05-24 07:24:49 +00:00
// $total = $this->countIcons($cat); //TODO
2012-05-17 05:09:59 +00:00
}
2012-04-29 10:38:45 +00:00
2012-05-24 07:24:49 +00:00
2012-04-28 01:31:30 +00:00
2012-04-29 11:15:44 +00:00
// $total_images = $this->getImages($cat); // for use by next/prev in filter at some point.
2012-05-17 05:09:59 +00:00
2013-03-09 19:22:30 -08:00
$prevAtt = '&aw=' . vartrue ( $option [ 'w' ], $w ); // .'&ah=100'; // Image Parsed back to Form as PREVIEW image.
2016-03-11 12:31:09 -08:00
2013-03-24 05:34:06 -07:00
$thumbAtt = 'aw=120&ah=120' ; // Thumbnail of the Media-Manager Preview.
2012-04-29 11:15:44 +00:00
2013-03-22 16:55:22 -07:00
2012-04-29 11:15:44 +00:00
// EXAMPLE of FILTER GUI.
2013-03-21 18:23:40 -07:00
$text = " " ;
2012-05-24 07:24:49 +00:00
$dipTotal = (( $frm + $limit ) < $total ) ? ( $frm + $limit ) : $total ;
2012-04-30 10:39:03 +00:00
2012-08-04 04:15:41 +00:00
if ( $navMode === false )
{
2013-03-22 16:55:22 -07:00
// $data_src = $this->mediaSelectNav($category,$tagid, "bbcode=".$bbcode)."&from=0";
$data_src = $this -> mediaSelectNav ( $category , $tagid , $option ); // ."&from=0";
2013-02-23 19:23:25 -08:00
// Inline style to override jquery-ui stuff.
2015-07-19 17:10:03 -07:00
$text .= " <div>
2015-07-16 13:41:15 -07:00
< div id = 'admin-ui-media-manager-search' class = 'input-append form-inline' style = 'margin-top:10px;font-size:12px' >
2017-03-02 11:44:15 -08:00
< input type = 'text' id = 'media-search' placeholder = '".LAN_SEARCH."' name = 'search' value = '' class = 'form-control e-tip' data - target = 'media-select-container' data - src = '".$data_src."' />
2014-01-09 04:42:13 -08:00
" ;
2012-11-28 21:07:23 -08:00
// $text .= "<input type='button' value='Go' class='btn btn-primary e-media-nav' data-target='media-select-container' data-src='".$this->mediaSelectNav($category,"tagid=".$tagid."&bbcode=".$bbcode)."&from=0' /> "; // Manual filter, if onkeyup ajax fails for some reason.
2016-10-01 12:39:22 +02:00
$text .= " <button type='button' class='btn btn-primary e-media-nav' data-target='media-select-container' data-src=' " . $data_src . " ' > " . LAN_GO . " </button> " ; // Manual filter, if onkeyup ajax fails for some reason.
2012-11-28 21:07:23 -08:00
2018-01-10 15:06:40 -08:00
$text .= " <button id='admin-ui-media-nav-down' type='button' title=' " . IMALAN_130 . " ' class='btn btn-default btn-secondary e-nav e-media-nav e-tip' style='outline:0' data-target='media-select-container' data-nav-total=' " . $total . " ' data-nav-dir='down' data-nav-inc=' " . $limit . " ' data-src=' " . $data_src . " '>«</button> " ; // see next page of images.
2012-08-04 04:15:41 +00:00
2018-01-10 15:06:40 -08:00
$text .= " <button id='admin-ui-media-nav-up' type='button' title=' " . IMALAN_131 . " ' class='btn btn-default btn-secondary e-nav e-media-nav e-tip' style='outline:0;text-align:center' data-target='media-select-container' data-nav-total=' " . $total . " ' data-nav-dir='up' data-nav-inc=' " . $limit . " ' data-src=' " . $data_src . " ' >»</button> " ; // see next page of images.
2014-01-09 04:42:13 -08:00
$text .= " </div></div> " ;
2016-10-04 09:37:53 +02:00
$text .= " <div id='admin-ui-media-select-count' class='media-select-count' style='text-align:right; display:block'> " ;
$text .= e107 :: getParser () -> lanVars ( IMALAN_162 , array ( 'x' => $frm + 1 , 'y' => $dipTotal , 'z' => $total ));
$text .= " </div> \n " ;
2015-07-19 17:10:03 -07:00
2013-02-23 23:08:30 -08:00
$text .= "
2012-08-04 04:15:41 +00:00
< div id = 'media-select-container' > " ;
}
2016-10-04 09:37:53 +02:00
$text .= " <div id='admin-ui-media-select-count-hidden' class='media-select-count' data-media-select-current-limit=' " . $dipTotal . " ' style='text-align:right; display:none'> " ;
$text .= e107 :: getParser () -> lanVars ( IMALAN_162 , array ( 'x' => $frm + 1 , 'y' => $dipTotal , 'z' => $total ));
$text .= " </div> \n " ;
2012-04-29 08:22:17 +00:00
2013-02-23 23:08:30 -08:00
2012-04-30 10:39:03 +00:00
if ( $bbcode == null ) // e107 Media Manager - new-image mode.
2012-04-29 11:15:44 +00:00
{
2016-10-01 12:39:22 +02:00
$text .= " <a title=' " . IMALAN_165 . " ' class='e-tip thumbnail { $class } " . $classN . " media-select-none e-dialog-close' data-src=' " . varset ( $im [ 'media_url' ]) . " ' style='vertical-align:middle;display:block;float:left;' href='#' onclick= \" { $onclick_clear } \" >
2016-03-11 12:31:09 -08:00
< span > " . $tp->toGlyph ('fa-ban'). " </ span >
2012-05-17 05:09:59 +00:00
</ a > " ;
2012-04-29 11:15:44 +00:00
}
2012-04-30 20:35:59 +00:00
2016-01-11 20:53:05 -08:00
$w = false ; //
2012-07-09 01:07:51 +00:00
$h = false ;
2016-01-11 20:53:05 -08:00
$defaultResizeWidth = 400 ;
2012-07-09 01:07:51 +00:00
2013-02-28 03:38:50 -08:00
if ( $bbcode ) // ie. TinyMce Editor, not imagepicker();
2012-07-09 01:07:51 +00:00
{
e107 :: getBB () -> setClass ( $category );
2016-01-11 20:53:05 -08:00
$defaultResizeWidth = e107 :: getBB () -> resizeWidth (); // resize the image according to prefs.
2012-07-09 01:07:51 +00:00
$h = e107 :: getBB () -> resizeHeight ();
2013-02-28 03:38:50 -08:00
e107 :: getBB () -> clearclass ();
2016-01-11 20:53:05 -08:00
2012-07-09 01:07:51 +00:00
}
2013-03-22 16:55:22 -07:00
// print_a($option);
2012-07-09 01:07:51 +00:00
$tp = e107 :: getParser ();
2013-02-28 03:38:50 -08:00
/*
$media_path : Inserted into html tags eg . < img src = 'here' ...
*/
2012-04-28 01:31:30 +00:00
foreach ( $images as $im )
{
2013-03-18 03:54:50 -07:00
list ( $dbWidth , $dbHeight ) = explode ( " x " , $im [ 'media_dimensions' ]);
2016-01-11 20:53:05 -08:00
$w = ( $dbWidth > $defaultResizeWidth ) ? $defaultResizeWidth : intval ( $dbWidth );
2017-01-31 14:50:55 -08:00
if ( $category === '_icon' )
{
$class = " media-select-icon " ;
$media_path = $tp -> replaceConstants ( $im [ 'media_url' ]); // $tp->replaceConstants($im['media_url'],'full'); // max-size
$realPath = $media_path ;
$img_url = $media_path ;
}
else // Regular image.
{
$class = " media-select-image " ;
$media_path = ( $w || $h ) ? $tp -> thumbUrl ( $im [ 'media_url' ], " &w= { $w } " ) : $tp -> thumbUrl ( $im [ 'media_url' ]); // $tp->replaceConstants($im['media_url'],'full'); // max-size
$realPath = $tp -> thumbUrl ( $im [ 'media_url' ], $prevAtt ); // Parsed back to Form as Preview Image.
$img_url = e107 :: getParser () -> thumbUrl ( $im [ 'media_url' ], $thumbAtt );
}
2013-03-09 19:22:30 -08:00
2016-02-03 19:31:49 -08:00
$diz = $tp -> toAttribute ( varset ( $im [ 'media_name' ])) . " ( " . str_replace ( " " , " " , varset ( $im [ 'media_dimensions' ])) . " ) " ;
2016-01-11 20:53:05 -08:00
$media_alt = $tp -> toAttribute ( vartrue ( $im [ 'media_caption' ]));
2012-04-29 10:38:45 +00:00
2012-04-30 10:39:03 +00:00
if ( $bbcode == null ) // e107 Media Manager
2013-07-12 07:13:10 -07:00
{
2012-04-29 10:38:45 +00:00
$onclicki = " parent.document.getElementById(' { $tagid } ').value = ' { $im [ 'media_url' ] } ';
2013-07-12 07:13:10 -07:00
parent . document . getElementById ( '".$prevId."' ) . src = '{$realPath}' ;
return false ; " ;
2012-06-11 21:25:23 +00:00
//$onclicki = "";
2012-05-23 08:29:57 +00:00
$class .= " e-media-select e-dialog-close " ;
2012-04-29 10:38:45 +00:00
}
2012-05-23 08:29:57 +00:00
else // TinyMce and textarea bbcode
2012-04-29 10:38:45 +00:00
{
2012-04-30 20:35:59 +00:00
//TODO Add a preview window
2012-04-30 10:39:03 +00:00
$onclicki = " document.getElementById('src').value = ' { $im [ 'media_url' ] } ';
2012-04-30 20:35:59 +00:00
document . getElementById ( 'preview' ) . src = '{$realPath}' ;
2012-05-23 08:29:57 +00:00
2012-04-30 20:35:59 +00:00
return false ; " ;
2012-06-11 21:25:23 +00:00
//$onclicki = "";
2012-05-23 08:29:57 +00:00
$class .= " e-media-select " ;
$onclicki = " " ;
2012-04-29 10:38:45 +00:00
}
2012-05-28 13:06:09 +00:00
$data_bb = ( $bbcode ) ? " img " : " " ;
2017-01-31 14:50:55 -08:00
2012-04-29 10:38:45 +00:00
2016-01-11 20:53:05 -08:00
$text .= " <a data-toggle='context' class='thumbnail { $class } e-tip' data-id=' { $im [ 'media_id' ] } ' data-width=' { $w } ' data-height=' { $h } ' data-src=' { $media_path } ' data-bbcode=' { $data_bb } ' data-target=' { $tagid } ' data-path=' { $im [ 'media_url' ] } ' data-preview=' { $realPath } ' data-alt= \" " . $media_alt . " \" title= \" " . $diz . " \" style='float:left' href='#' onclick= \" { $onclicki } \" > " ;
2014-11-03 16:13:27 +02:00
$text .= " <img class='image-rounded' src=' " . $img_url . " ' alt= \" " . $im [ 'media_title' ] . " \" title= \" { $diz } \" /> " ;
2012-04-29 10:38:45 +00:00
$text .= " </a> \n \n " ;
2012-04-28 01:31:30 +00:00
}
2012-04-29 10:38:45 +00:00
2012-05-23 08:29:57 +00:00
2012-05-17 05:09:59 +00:00
$text .= " <div style='clear:both'><!-- --></div> " ;
2012-11-30 22:09:04 -08:00
//fixing tip icon when navigation prev/next page
$text .= " <script> " ;
$text .= " $ (document).ready(function() {
$ ( '.e-tip' ) . each ( function () {
var tip = $ ( this ) . attr ( 'title' );
if ( ! tip )
{
return ;
}
var pos = $ ( this ) . attr ( 'data-placement' );
if ( ! pos )
{
pos = 'top' ;
}
$ ( this ) . tooltip ({ opacity : 1.0 , fade : true , placement : pos });
});
});
" ;
$text .= " </script> " ;
2012-05-23 08:29:57 +00:00
$mes = e107 :: getMessage ();
$mes -> addDebug ( " Target: { $tagid } " );
2012-08-04 04:15:41 +00:00
if ( $navMode === false )
{
$text .= " </div> " ;
}
2012-04-28 01:31:30 +00:00
return $text ;
}
2012-05-17 09:19:44 +00:00
2016-03-06 17:42:47 -08:00
/**
* @ param string $oldpath - path to pre - moved file ( no e107 constants )
* @ param string $newpath - new path to move file to ( no e107 constants )
* @ return bool | string returns false if duplciate entry found otherwise return new path .
*/
function checkDupe ( $oldpath , $newpath )
2012-05-17 09:19:44 +00:00
{
$mes = e107 :: getMessage ();
$tp = e107 :: getParser ();
2013-02-25 12:07:56 -08:00
$sql = e107 :: getDb ();
2012-05-17 09:19:44 +00:00
// $mes->addDebug("checkDupe(): newpath=".$newpath."<br />oldpath=".$oldpath."<br />".print_r($upload,TRUE));
2013-02-25 12:07:56 -08:00
if ( file_exists ( $newpath ) && ( $f = e107 :: getFile () -> get_file_info ( $oldpath , TRUE )))
2012-05-17 09:19:44 +00:00
{
2012-05-22 13:32:49 +00:00
$this -> log ( $newpath . " already exists and will be renamed during import. " );
2012-05-17 09:19:44 +00:00
$mes -> addWarning ( $newpath . " already exists and was renamed during import. " );
$file = $f [ 'pathinfo' ][ 'filename' ] . " _. " . $f [ 'pathinfo' ][ 'extension' ];
$newpath = $this -> getPath ( $f [ 'mime' ]) . '/' . $file ;
}
2013-02-25 12:07:56 -08:00
if ( $sql -> select ( " core_media " , " media_url " , " media_url LIKE '% " . $tp -> createConstants ( $newpath , 'rel' ) . " ' LIMIT 1 " ))
{
// $mes->addWarning($newpath." detected in media-manager.");
2016-03-06 17:42:47 -08:00
$this -> log ( " Import not performed. " . $newpath . " detected in media table already. " );
return false ;
//$row = $sql->fetch();
//$newpath = $row['media_url']; // causes trouble with importFile() if {e_MEDIA_CONSTANT} returned.
2013-02-25 12:07:56 -08:00
}
2012-05-17 09:19:44 +00:00
return $newpath ;
}
2013-07-12 07:13:10 -07:00
2013-07-12 08:16:56 -07:00
/**
2017-01-01 08:13:42 -08:00
* @ param string | array $type
* @ param $type [ 'name' ]
* @ param $type [[ 'type' ]
* @ param $type [ 'path' ] URL or e107 path { e_THEME } etc .
* @ param $type [ 'prefix' ]
* @ param string $addPrefix
* @ return array
2013-07-12 08:16:56 -07:00
*/
2017-01-01 08:13:42 -08:00
function getGlyphs ( $type = 'fa4' , $addPrefix = '' )
2013-07-12 07:13:10 -07:00
{
2014-01-09 04:42:13 -08:00
$icons = array ();
2017-01-01 08:13:42 -08:00
if ( $type === 'bs2' )
2014-01-09 04:42:13 -08:00
{
$matches = array (
'glass' , 'music' , 'search' , 'envelope' , 'heart' , 'star' , 'star-empty' , 'user' , 'film' , 'th-large' , 'th' , 'th-list' , 'ok' ,
'remove' , 'zoom-in' , 'zoom-out' , 'off' , 'signal' , 'cog' , 'trash' , 'home' , 'file' , 'time' , 'road' , 'download-alt' , 'download' ,
'upload' , 'inbox' , 'play-circle' , 'repeat' , 'refresh' , 'list-alt' , 'lock' , 'flag' , 'headphones' , 'volume-off' , 'volume-down' ,
'volume-up' , 'qrcode' , 'barcode' , 'tag' , 'tags' , 'book' , 'bookmark' , 'print' , 'camera' , 'font' , 'bold' , 'italic' , 'text-height' ,
'text-width' , 'align-left' , 'align-center' , 'align-right' , 'align-justify' , 'list' , 'indent-left' , 'indent-right' ,
'facetime-video' , 'picture' , 'pencil' , 'map-marker' , 'adjust' , 'tint' , 'edit' , 'share' , 'check' , 'move' , 'step-backward' ,
'fast-backward' , 'backward' , 'play' , 'pause' , 'stop' , 'forward' , 'fast-forward' , 'step-forward' , 'eject' , 'chevron-left' ,
'chevron-right' , 'plus-sign' , 'minus-sign' , 'remove-sign' , 'ok-sign' , 'question-sign' , 'info-sign' , 'screenshot' ,
'remove-circle' , 'ok-circle' , 'ban-circle' , 'arrow-left' , 'arrow-right' , 'arrow-up' , 'arrow-down' , 'share-alt' ,
'resize-full' , 'resize-small' , 'plus' , 'minus' , 'asterisk' , 'exclamation-sign' , 'gift' , 'leaf' , 'fire' , 'eye-open' ,
'eye-close' , 'warning-sign' , 'plane' , 'calendar' , 'random' , 'comment' , 'magnet' , 'chevron-up' , 'chevron-down' ,
'retweet' , 'shopping-cart' , 'folder-close' , 'folder-open' , 'resize-vertical' , 'resize-horizontal' , 'hdd' ,
'bullhorn' , 'bell' , 'certificate' , 'thumbs-up' , 'thumbs-down' , 'hand-right' , 'hand-left' , 'hand-up' , 'hand-down' ,
'circle-arrow-right' , 'circle-arrow-left' , 'circle-arrow-up' , 'circle-arrow-down' , 'globe' , 'wrench' , 'tasks' ,
'filter' , 'briefcase' , 'fullscreen'
);
foreach ( $matches as $match )
{
2017-01-01 08:13:42 -08:00
$icons [] = $addPrefix . $match ;
2014-01-09 04:42:13 -08:00
}
return $icons ;
}
2017-01-01 08:13:42 -08:00
if ( $type === 'bs3' )
2014-01-09 04:42:13 -08:00
{
$matches = array (
'adjust' , 'align-center' , 'align-justify' , 'align-left' , 'align-right' , 'arrow-down' , 'arrow-left' , 'arrow-right' , 'arrow-up' , 'asterisk' , 'backward' , 'ban-circle' , 'barcode' , 'bell' , 'bold' , ' book
',' bookmark ',' briefcase ',' bullhorn ',' calendar ',' camera ',' certificate ',' check ',' chevron - down ',' chevron - left ',' chevron - right ',' chevron - up ',' circle - arrow - down ',' circle - arrow - left ',' circle - arrow - right
',' circle - arrow - up ',' cloud ',' cloud - download ',' cloud - upload ',' cog ',' collapse - down ',' collapse - up ',' comment ',' compressed ',' copyright - mark ',' credit - card ',' cutlery ',' dashboard ',' download ',' download - alt
',' earphone ',' edit ',' eject ',' envelope ',' euro ',' exclamation - sign ',' expand ',' export ',' eye - close ',' eye - open ',' facetime - video ',' fast - backward ',' fast - forward ',' file ',' film ',' filter ',' fire ',' flag
',' flash ',' floppy - disk ',' floppy - open ',' floppy - remove ',' floppy - save ',' floppy - saved ',' folder - close ',' folder - open ',' font ',' forward ',' fullscreen ',' gbp ',' gift
',' glass ',' globe ',' hand - down ',' hand - left ',' hand - right ',' hand - up ',' hd - video ',' hdd ',' header ',' headphones ',' heart ',' heart - empty ',' home ',' import ',' inbox ',' indent - left ',' indent - right ',' info - sign ',' italic ',' leaf ',' link ',' list
',' list - alt ',' lock ',' log - in ',' log - out ',' magnet ',' map - marker ',' minus ',' minus - sign ',' move ',' music ',' new - window ',' off ',' ok ',' ok - circle ',' ok - sign ',' open ',' paperclip ',' pause ',' pencil ',' phone ',' phone - alt ',' picture
',' plane ',' play ',' play - circle ',' plus ',' plus - sign ',' print ',' pushpin ',' qrcode ',' question - sign ',' random ',' record ',' refresh ',' registration - mark ',' remove ',' remove - circle ',' remove - sign ',' repeat ',' resize - full ',' resize - horizontal
',' resize - small ',' resize - vertical ',' retweet ',' road ',' save ',' saved ',' screenshot ',' sd - video ',' search ',' send ',' share ',' share - alt ',' shopping - cart ',' signal ',' sort ',' sort - by - alphabet ',' sort - by - alphabet - alt
',' sort - by - attributes ',' sort - by - attributes - alt ',' sort - by - order ',' sort - by - order - alt ',' sound - 5 - 1 ',' sound - 6 - 1 ',' sound - 7 - 1 ',' sound - dolby ',' sound - stereo ',' star ',' stats ',' step - backward ',' step - forward ',' stop
',' subtitles ',' tag ',' tags ',' tasks ',' text - height ',' text - width ',' th ',' th - large ',' th - list ',' thumbs - down ',' thumbs - up ',' time ',' tint ',' tower ',' transfer ',' trash ',' tree - conifer ',' tree - deciduous ',' unchecked ',' upload
',' usd ',' user ',' volume - down ',' volume - off ',' volume - up ',' warning - sign ',' wrench ',' zoom - in ',' zoom - out '
);
foreach ( $matches as $match )
{
2017-01-01 08:13:42 -08:00
$icons [] = $addPrefix . $match ;
2014-01-09 04:42:13 -08:00
}
return $icons ;
}
2017-01-01 08:13:42 -08:00
if ( is_array ( $type ))
{
$prefix = $type [ 'prefix' ];
$pattern = $type [ 'pattern' ];
$path = $type [ 'path' ];
$type = $type [ 'name' ];
}
2014-01-09 04:42:13 -08:00
$cache = e107 :: getCache ();
2017-01-01 08:13:42 -08:00
2017-02-03 08:36:49 -08:00
$cachTag = ! empty ( $addPrefix ) ? " Glyphs_ " . $addPrefix . " _ " . $type : " Glyphs_ " . $type ;
2017-01-01 08:13:42 -08:00
2016-12-22 08:47:54 -08:00
if ( $data = $cache -> retrieve ( $cachTag , 360 , true , true ))
2014-01-09 04:42:13 -08:00
{
return e107 :: unserialize ( $data );
}
2017-02-03 08:36:49 -08:00
if ( $type === 'fa4' )
2014-01-09 04:42:13 -08:00
{
2014-01-28 05:59:40 -08:00
$pattern = '/\.(fa-(?:\w+(?:-)?)+):before/' ;
2017-02-03 08:36:49 -08:00
$path = e107 :: getLibrary () -> getPath ( 'fontawesome' );
$subject = file_get_contents ( $path . 'css/font-awesome.css' );
2017-01-01 08:13:42 -08:00
$prefix = 'fa-' ;
2014-01-09 04:42:13 -08:00
}
2017-01-01 08:13:42 -08:00
elseif ( $type === 'fa3' )
2014-11-03 16:13:27 +02:00
{
2014-01-28 05:59:40 -08:00
$pattern = '/\.(icon-(?:\w+(?:-)?)+):before/' ;
2014-11-03 16:13:27 +02:00
$subject = file_get_contents ( e_WEB_JS . 'font-awesome/css/font-awesome.css' );
2017-01-01 08:13:42 -08:00
$prefix = 'fa-' ;
2014-01-09 04:42:13 -08:00
}
2017-01-01 08:13:42 -08:00
elseif ( ! empty ( $pattern ) && ! empty ( $path ))
{
$pattern = '/' . $pattern . '/' ;
if ( substr ( $path , 0 , 4 ) === 'http' )
{
$subject = e107 :: getFile () -> getRemoteContent ( $path );
}
else
{
$path = e107 :: getParser () -> replaceConstants ( $path );
$subject = file_get_contents ( $path );
}
}
$prefixLength = ! empty ( $prefix ) ? strlen ( $prefix ) : 3 ;
2013-07-12 08:16:56 -07:00
preg_match_all ( $pattern , $subject , $matches , PREG_SET_ORDER );
2017-01-01 08:13:42 -08:00
2013-07-12 08:16:56 -07:00
foreach ( $matches as $match )
{
2017-01-01 08:13:42 -08:00
$icons [] = $addPrefix . substr ( $match [ 1 ], $prefixLength );
2013-07-12 08:16:56 -07:00
}
2016-03-25 11:24:07 -07:00
if ( empty ( $icons )) // failed to produce a result so don't cache it. .
{
return array ();
}
2017-02-03 08:36:49 -08:00
$data = e107 :: serialize ( $icons , 'json' );
2016-03-25 11:24:07 -07:00
2017-02-03 08:36:49 -08:00
$cache -> set_sys ( $cachTag , $data , true , true );
2016-12-22 08:47:54 -08:00
2013-07-12 08:16:56 -07:00
return $icons ;
2013-07-12 07:13:10 -07:00
}
2016-12-27 16:07:03 -08:00
2017-01-01 08:13:42 -08:00
2016-12-06 19:24:48 -08:00
function getPath ( $mime , $path = null )
2012-05-17 09:19:44 +00:00
{
$mes = e107 :: getMessage ();
list ( $pmime , $tmp ) = explode ( '/' , $mime );
if ( ! vartrue ( $this -> mimePaths [ $pmime ]))
{
2012-08-12 00:24:02 +00:00
$this -> log ( " Couldn't detect mime-type ( $mime ). " );
2016-12-27 16:07:03 -08:00
$text = $text = str_replace ( '[x]' , $mime , IMALAN_111 ); //FIXME LAN IMALAN_112 is not generic. This method can be called from anywhere, not only e107_admin/image.php.
2016-01-24 00:37:36 -08:00
$mes -> add ( $text , E_MESSAGE_ERROR );
2012-05-17 09:19:44 +00:00
return FALSE ;
}
2016-12-06 19:24:48 -08:00
if ( ! empty ( $path ))
{
$dir = e_MEDIA . " plugins/ " . e107 :: getParser () -> filter ( $path , 'w' );
}
else
{
$dir = $this -> mimePaths [ $pmime ] . date ( " Y-m " );
}
2012-05-17 09:19:44 +00:00
if ( ! is_dir ( $dir ))
{
2016-12-06 19:24:48 -08:00
if ( ! mkdir ( $dir , 0755 , true ))
2012-05-17 09:19:44 +00:00
{
2016-01-24 00:37:36 -08:00
2012-08-12 00:24:02 +00:00
$this -> log ( " Couldn't create folder ( $dir ). " );
2016-01-24 00:37:36 -08:00
$text = str_replace ( '[x]' , $dir , IMALAN_112 );
$mes -> add ( $text , E_MESSAGE_ERROR );
2012-05-17 09:19:44 +00:00
return FALSE ;
};
}
return $dir ;
}
2018-07-18 14:40:29 -07:00
/**
* detected Media Type from Media URL
* @ param $file
* @ return int | string
*/
public function detectType ( $mediaURL )
{
list ( $id , $type ) = explode ( " . " , $mediaURL , 2 );
foreach ( $this -> mimeExtensions as $key => $exts )
{
if ( ! in_array ( $type , $exts ))
{
continue ;
}
return $key ;
}
return null ;
}
2018-07-26 19:13:27 -07:00
/**
* @ param string $default eg . { e_MEDIA_VIDEO } 2018 - 10 / myvideo . mp4
* @ param array $options
* @ return bool | string
*/
public function previewTag ( $default , $options = array ())
{
$tp = e107 :: getParser ();
2018-07-27 17:39:44 -07:00
$type = ! empty ( $options [ 'type' ]) ? $options [ 'type' ] : $this -> detectType ( $default );
2018-07-26 19:13:27 -07:00
$width = vartrue ( $options [ 'w' ], 220 );
$height = vartrue ( $options [ 'h' ], 190 );
switch ( $type )
{
case " video " :
$preview = $tp -> toVideo ( $default , array ( 'w' => $width , 'h' => ( $height - 50 )));
// $previewURL = $tp->toVideo($default, array('mode'=>'url'));
break ;
case " audio " :
$preview = $tp -> toAudio ( $default );
// $previewURL = false;
break ;
case " image " :
/*
if ( '{' != $default [ 0 ]) // legacy path or one without {}
{
list ( $default_thumb , $default ) = $this -> imagepickerDefault ( $default , $parms );
}
$default = $tp -> replaceConstants ( $default , 'abs' );
*/
2018-08-06 14:11:28 -07:00
$preview = $tp -> toImage ( $default , array ( 'w' => $width , 'h' => $height , 'class' => 'image-selector img-responsive img-fluid' , 'legacy' => varset ( $options [ 'legacyPath' ])));
2018-07-26 19:13:27 -07:00
// $previewURL = $tp->thumbUrl($default, array('w'=>800));
break ;
case " application " : // file.
// $preview = $tp->toImage($default, array('w'=>$width, 'h'=>$height, 'class'=>'image-selector img-responsive img-fluid'));
// $previewURL = $tp->thumbUrl($default, array('w'=>800));
break ;
case " glyph " :
2018-07-27 17:39:44 -07:00
$preview = " <span class='icon-preview'> " . $tp -> toGlyph ( $default ) . " </span> " ;
// $previewURL = false;
break ;
case " icon " :
$preview = $tp -> toIcon ( $default );
2018-07-26 19:13:27 -07:00
// $previewURL = false;
break ;
default : // blank
$preview = null ;
}
return $preview ;
}
2018-07-18 14:40:29 -07:00
2012-05-17 09:19:44 +00:00
public function mediaData ( $sc_path )
{
if ( ! $sc_path ) return array ();
$mes = e107 :: getMessage ();
$path = e107 :: getParser () -> replaceConstants ( $sc_path );
if ( ! is_readable ( $path ))
{
$mes -> addError ( " Couldn't read file: { $path } " );
2012-08-12 00:24:02 +00:00
$this -> log ( " Couldn't read file: { $path } " );
2012-05-17 09:19:44 +00:00
return FALSE ;
}
2012-08-12 00:24:02 +00:00
$info = e107 :: getFile () -> get_file_info ( $path , true );
2014-06-11 20:43:12 -07:00
2012-08-12 00:24:02 +00:00
$this -> log ( " File info for $path : " . print_r ( $info , true ));
2012-05-17 09:19:44 +00:00
return array (
2012-08-12 00:24:02 +00:00
'media_type' => vartrue ( $info [ 'mime' ]),
2012-05-17 09:19:44 +00:00
'media_datestamp' => time (),
2014-06-11 20:43:12 -07:00
'media_url' => e107 :: getParser () -> createConstants ( $info [ 'fullpath' ], 'rel' ),
'media_size' => filesize ( $info [ 'fullpath' ]),
2012-05-17 09:19:44 +00:00
'media_author' => USERID ,
'media_usedby' => '' ,
'media_tags' => '' ,
'media_dimensions' => $info [ 'img-width' ] . " x " . $info [ 'img-height' ]
);
}
2012-08-12 00:24:02 +00:00
2012-05-17 09:19:44 +00:00
2012-05-22 13:32:49 +00:00
public function log ( $message )
{
if ( $this -> logging == false ) return ;
2013-02-25 12:07:56 -08:00
$insert = " \n \n " . date ( 'r' ) . " \n " . $message ;
2012-05-23 08:29:57 +00:00
file_put_contents ( e_LOG . " mediaUpload.log " , $insert , FILE_APPEND | LOCK_EX );
2012-05-22 13:32:49 +00:00
}
2016-12-06 19:24:48 -08:00
/**
* Import a file into the Media Manager
* @ param string $file Path to file
* @ param string $category media - category to import into
* @ param null | array $opts
* @ param string $opts [ 'path' ] Custom Folder ( optional )
* @ param array $new_data - Additional media info to save .
* @ param string $new_data [ 'media_caption' ]
* @ param string $new_data [ 'media_descrption' ]
* @ return bool | string
*/
public function importFile ( $file = '' , $category = '_common_image' , $opts = null , $new_data = array ())
2012-05-17 09:19:44 +00:00
{
$mes = e107 :: getMessage ();
$tp = e107 :: getParser ();
$sql = e107 :: getDb ();
2014-11-03 16:50:49 +02:00
2016-12-06 19:24:48 -08:00
if ( is_array ( $opts ))
{
$uploadPath = varset ( $opts [ 'path' ]);
$oldpath = null ;
}
else
{
$uploadPath = null ;
$oldpath = $opts ;
}
2016-03-06 17:42:47 -08:00
if ( empty ( $oldpath )) $oldpath = e_IMPORT . $file ;
2016-12-06 19:24:48 -08:00
2012-05-17 09:19:44 +00:00
if ( ! file_exists ( $oldpath ))
{
2013-02-25 12:07:56 -08:00
// Check it hasn't been imported already.
if ( $newpath = $this -> checkDupe ( $oldpath , $file ))
{
2015-02-07 11:57:28 -08:00
$this -> log ( " Line: " . __LINE__ . " Couldn't find the file: " . $oldpath );
2013-02-25 12:07:56 -08:00
return $newpath ;
}
2012-08-12 00:24:02 +00:00
$this -> log ( " Line: " . __LINE__ . " Couldn't find the file: " . $oldpath );
2013-02-25 12:07:56 -08:00
$mes -> addError ( " Couldn't find the file: " . $oldpath );
2016-03-06 00:23:41 -08:00
return false ;
2012-05-17 09:19:44 +00:00
}
$img_data = $this -> mediaData ( $oldpath ); // Basic File Info only
2016-12-06 19:26:52 -08:00
2016-12-06 19:24:48 -08:00
if ( ! $typePath = $this -> getPath ( $img_data [ 'media_type' ], $uploadPath ))
2012-08-12 00:24:02 +00:00
{
$this -> log ( " Line: " . __LINE__ . " Couldn't generate path from file info: " . $oldpath );
$mes -> addError ( " Couldn't generate path from file info: " . $oldpath );
2016-12-06 19:24:48 -08:00
return false ;
2012-05-17 09:19:44 +00:00
}
2016-03-06 17:42:47 -08:00
if ( ! $newpath = $this -> checkDupe ( $oldpath , $typePath . '/' . $file ))
{
return $tp -> createConstants ( $typePath . '/' . $file , 'rel' );
}
2016-01-11 20:53:05 -08:00
$newpath = $this -> checkFileExtension ( $newpath , $img_data [ 'media_type' ]);
2016-03-06 17:42:47 -08:00
2012-05-22 13:32:49 +00:00
if ( ! rename ( $oldpath , $newpath )) // e_MEDIA.$newpath was working before.
2012-05-17 09:19:44 +00:00
{
2012-05-22 13:32:49 +00:00
$this -> log ( " Couldn't move file from " . realpath ( $oldpath ) . " to " . e_MEDIA . $newpath );
2012-05-17 09:19:44 +00:00
$mes -> add ( " Couldn't move file from " . $oldpath . " to " . $newpath , E_MESSAGE_ERROR );
2016-12-06 19:24:48 -08:00
return false ;
2012-05-17 09:19:44 +00:00
};
$img_data [ 'media_url' ] = $tp -> createConstants ( $newpath , 'rel' );
2016-01-11 20:53:05 -08:00
$img_data [ 'media_name' ] = $tp -> toDB ( basename ( $newpath ));
2016-04-09 16:12:08 -07:00
$img_data [ 'media_caption' ] = vartrue ( $new_data [ 'media_caption' ]);
2014-02-18 10:44:42 -08:00
$img_data [ 'media_category' ] = vartrue ( $category , '_common_image' );
2016-04-09 16:12:08 -07:00
$img_data [ 'media_description' ] = vartrue ( $new_data [ 'media_description' ]);
2012-07-11 04:46:09 +00:00
$img_data [ 'media_userclass' ] = '0' ;
2012-05-17 09:19:44 +00:00
2015-02-07 11:57:28 -08:00
if ( $sql -> insert ( " core_media " , $img_data ))
2012-05-17 09:19:44 +00:00
{
$mes -> add ( " Importing Media: " . $file , E_MESSAGE_SUCCESS );
2012-05-22 13:32:49 +00:00
$this -> log ( " Importing Media: " . $file . " successful " );
2012-05-17 09:19:44 +00:00
return $img_data [ 'media_url' ];
}
else
{
2016-04-09 16:12:08 -07:00
$this -> log ( " Db Insert Failed: " . var_export ( $img_data , true ));
2012-05-17 09:19:44 +00:00
rename ( $newpath , $oldpath ); //move it back.
2016-12-06 19:24:48 -08:00
return false ;
2012-05-17 09:19:44 +00:00
}
}
2016-01-11 20:53:05 -08:00
/**
* Check File - name against mime - type and add missing extension if necessary .
* @ param $path
* @ param $mime
* @ return string
*/
2018-07-27 12:07:43 -07:00
public function checkFileExtension ( $path , $mime )
2016-01-11 20:53:05 -08:00
{
if ( empty ( $mime ))
{
return $path ;
}
2018-07-27 12:07:43 -07:00
$ext = e107 :: getFile () -> getFileExtension ( $mime );
2016-01-11 20:53:05 -08:00
2018-07-27 12:07:43 -07:00
if ( $ext && ( substr ( $path , - 4 ) != $ext ))
2016-01-11 20:53:05 -08:00
{
2018-07-27 12:07:43 -07:00
return $path . $ext ;
2016-01-11 20:53:05 -08:00
}
else
{
return $path ;
}
}
2018-07-21 13:56:13 -07:00
private function browserCarouselItemSelector ( $data )
{
$close = ( E107_DEBUG_LEVEL > 0 ) ? " " : " data-close='true' " ; //
$select = ( E107_DEBUG_LEVEL > 0 ) ? '' : " e-dialog-save e-dialog-close " ;
2018-07-26 19:13:27 -07:00
$style = varset ( $data [ 'style' ], '' );
2018-07-21 13:56:13 -07:00
$class = varset ( $data [ 'class' ], '' );
2018-07-26 19:13:27 -07:00
$dataPreview = ! empty ( $data [ 'previewHtml' ]) ? base64_encode ( $data [ 'previewHtml' ]) : '' ;
2018-07-21 13:56:13 -07:00
2018-07-26 19:13:27 -07:00
$linkTag = " <a data-toggle='context' class='e-media-select e-tip " . $select . " " . $class . " ' " . $close . " data-id=' " . $data [ 'id' ] . " ' data-width=' " . $data [ 'width' ] . " ' data-height=' " . $data [ 'height' ] . " ' data-src=' " . $data [ 'previewUrl' ] . " ' data-type=' " . $data [ 'type' ] . " ' data-bbcode=' " . $data [ 'bbcode' ] . " ' data-target=' " . $data [ 'tagid' ] . " ' data-path=' " . $data [ 'saveValue' ] . " ' data-preview=' " . $data [ 'previewUrl' ] . " ' data-preview-html=' " . $dataPreview . " ' title= \" " . $data [ 'title' ] . " \" style=' " . $style . " ' href='#' > " ;
2018-07-21 13:56:13 -07:00
return $linkTag ;
}
2012-05-17 09:19:44 +00:00
2014-01-08 15:51:14 -08:00
function browserCarouselItem ( $row = array ())
{
$tp = e107 :: getParser ();
2014-01-09 04:42:13 -08:00
$defaultThumb = $tp -> thumbUrl ( '' , 'w=400&h=240' );
2014-01-08 15:51:14 -08:00
2014-01-09 04:42:13 -08:00
$default = array (
'width' => 200 ,
'height' => 113 ,
'id' => '' ,
'type' => 'image' ,
'tagid' => '' ,
'saveValue' => '' ,
'previewUrl' => $defaultThumb ,
2018-07-19 12:43:04 -07:00
'previewHtml' => null ,
2014-01-09 04:42:13 -08:00
'thumbUrl' => $defaultThumb ,
'title' => '' ,
2015-07-16 13:41:15 -07:00
'gridClass' => 'span2 col-md-2' ,
2018-07-25 20:28:30 -07:00
'bbcode' => '' ,
'tooltip' => '' ,
2014-01-08 15:51:14 -08:00
2014-01-09 04:42:13 -08:00
);
$data = array ();
foreach ( $default as $k => $v )
{
$data [ $k ] = isset ( $row [ $k ]) ? $row [ $k ] : $default [ $k ];
}
2014-01-23 17:23:38 -08:00
2014-01-08 15:51:14 -08:00
2018-07-21 13:56:13 -07:00
2015-04-02 02:49:19 -07:00
2018-07-25 12:29:52 -07:00
$text = " \n \n
2014-01-09 04:42:13 -08:00
2018-07-16 17:14:10 -07:00
< div class = 'media-carousel ".$data[' gridClass ']."' >
2014-01-09 04:42:13 -08:00
2018-07-25 20:28:30 -07:00
< div class = 'well clearfix media-carousel-item-container' > \n " ;
2018-07-16 17:14:10 -07:00
2018-07-19 12:43:04 -07:00
2018-07-25 20:28:30 -07:00
$caption = $data [ 'title' ];
if ( ! empty ( $data [ 'tooltip' ]))
{
$data [ 'title' ] = $data [ 'tooltip' ];
}
2018-07-21 13:56:13 -07:00
$linkTag = $this -> browserCarouselItemSelector ( $data );
2018-07-16 17:14:10 -07:00
2018-07-25 20:28:30 -07:00
2018-07-16 17:14:10 -07:00
switch ( $data [ 'type' ])
2014-01-09 04:42:13 -08:00
{
2018-07-16 17:14:10 -07:00
case " video " :
case " audio " :
2018-07-19 12:43:04 -07:00
2018-07-21 13:56:13 -07:00
if ( $data [ 'type' ] === 'video' ) // video
{
$text .= $tp -> toVideo ( $data [ 'thumbUrl' ], array ( 'w' => $data [ 'width' ], 'h' => '' , 'mime' => $data [ 'mime' ]));
}
else // audio
{
$text .= $tp -> toAudio ( $data [ 'thumbUrl' ], array ( 'mime' => $data [ 'mime' ]));
}
2018-07-19 12:43:04 -07:00
2018-07-25 20:28:30 -07:00
$text .= " <div class='row media-carousel-item-controls'>
2018-07-26 13:57:49 -07:00
< div class = 'col-sm-8' >< small class = 'media-carousel-item-caption' > " ;
2018-07-16 17:14:10 -07:00
2018-07-21 13:56:13 -07:00
$text .= $this -> browserCarouselItemSelector ( $data );
2018-07-25 20:28:30 -07:00
$text .= " \n " . $caption ;
2018-07-21 13:56:13 -07:00
$text .= " \n </a></small></div> " ;
2018-07-16 17:14:10 -07:00
2018-07-21 13:56:13 -07:00
$data [ 'style' ] = 'float:right' ;
2018-07-16 17:14:10 -07:00
2018-07-26 13:57:49 -07:00
$text .= " <div class='col-sm-4 text-right'> " .
2018-07-21 13:56:13 -07:00
$this -> browserCarouselItemSelector ( $data ) .
2018-07-25 10:17:49 +02:00
" <button class='btn btn-xs btn-primary' style='margin-top:7px'> " . LAN_SELECT . " </button></a></div>
2018-07-21 13:56:13 -07:00
</ div > \n\n " ;
break ;
2018-07-16 17:14:10 -07:00
case " image " :
2018-07-25 20:28:30 -07:00
2018-07-16 17:14:10 -07:00
$text .= $linkTag ;
2018-07-22 14:45:26 -07:00
$text .= " <span> " ;
2018-07-26 19:13:27 -07:00
$text .= '<img class="img-responsive img-fluid" alt="" src="' . $data [ 'thumbUrl' ] . '" style="display:inline-block" />' ;
2018-07-22 14:45:26 -07:00
$text .= " </span> " ;
2018-07-16 17:14:10 -07:00
$text .= " \n </a> \n \n " ;
2018-07-22 14:45:26 -07:00
2018-07-25 20:28:30 -07:00
$text .= " <div class='row media-carousel-item-controls'>
2018-07-26 13:57:49 -07:00
< div class = 'col-sm-8' >< small class = 'media-carousel-item-caption' > " ;
2018-07-22 14:45:26 -07:00
$text .= $this -> browserCarouselItemSelector ( $data );
2018-07-25 20:28:30 -07:00
$text .= " \n " . $caption ;
2018-07-22 14:45:26 -07:00
$text .= " \n </a></small></div> " ;
$data [ 'style' ] = 'float:right' ;
2018-07-26 13:57:49 -07:00
$text .= " <div class='col-sm-4 text-right'> " .
2018-07-22 14:45:26 -07:00
$this -> browserCarouselItemSelector ( $data ) .
2018-07-25 10:17:49 +02:00
" <button class='btn btn-xs btn-primary' style='margin-top:7px'> " . LAN_SELECT . " </button></a></div>
2018-07-22 14:45:26 -07:00
</ div > " ;
// $text .= "\n<div><small class='media-carousel-item-caption'>".$data['title']."</small></div>";
2018-07-16 17:14:10 -07:00
break ;
case " glyph " :
$text .= $linkTag ;
2018-07-25 20:28:30 -07:00
$text .= " \n <span style='margin:7px;display:inline-block;color: inherit'> " . $tp -> toGlyph ( $data [ 'thumbUrl' ], array ( 'placeholder' => '' )) . " </span> " ;
2018-07-16 17:14:10 -07:00
$text .= " \n </a> \n \n " ;
2018-07-25 20:28:30 -07:00
2018-07-16 17:14:10 -07:00
break ;
2018-07-27 17:39:44 -07:00
case " icon " :
$text .= $linkTag ;
$text .= " \n <span style='margin:7px;display:inline-block;color: inherit'> " . $tp -> toIcon ( $data [ 'thumbUrl' ], array ( 'placeholder' => '' )) . " </span> " ;
$text .= " \n </a> \n \n " ;
break ;
2018-07-16 17:14:10 -07:00
default :
// code to be executed if n is different from all labels;
2014-01-09 04:42:13 -08:00
}
2018-07-16 17:14:10 -07:00
2014-01-09 04:42:13 -08:00
$text .= " </div>
2018-07-25 12:29:52 -07:00
</ div > \n\n\n " ;
2014-01-08 15:51:14 -08:00
return $text ;
}
2014-01-09 04:42:13 -08:00
function browserIndicators ( $slides = array (), $uniqueID )
2014-01-08 15:51:14 -08:00
{
if ( count ( $slides ) < 1 )
{
return ;
}
2015-07-16 13:41:15 -07:00
$indicators = ' < ol class = " carousel-indicators col-md-2 span2 " style = " top:-40px " >
2014-01-09 04:42:13 -08:00
< li data - target = " #'. $uniqueID .' " data - slide - to = " 0 " class = " active " ></ li > ' ;
2014-01-08 15:51:14 -08:00
foreach ( $slides as $key => $v )
{
$id = $key + 1 ;
2014-01-09 04:42:13 -08:00
$indicators .= '<li data-target="#' . $uniqueID . '" data-slide-to="' . $id . '"></li>' ;
2014-01-08 15:51:14 -08:00
}
$indicators .= '</ol>' ;
return $indicators ;
}
2015-03-31 14:48:07 -07:00
/**
* Retriveve a Media - Manager thumbnail which was saved from a remote location . .
* @ param $id
* @ return bool | string
*/
function getThumb ( $id )
{
$id = trim ( $id );
$filename = 'temp/thumb-' . md5 ( $id ) . " .jpg " ;
$filepath = e_MEDIA . $filename ;
if ( file_exists ( $filepath ))
{
return e107 :: getParser () -> createConstants ( $filepath );
}
e107 :: getMessage () -> addDebug ( " Couldn't find " . $filepath );
return false ;
}
/**
* Save a Media - Manager thumbnail from remote location .
* @ param string $imageUrl
* @ param string $id
* @ return bool | string
*/
function saveThumb ( $imageUrl = '' , $id = '' )
{
if ( empty ( $id ) || empty ( $imageUrl ))
{
return false ;
}
$filename = 'temp/thumb-' . md5 ( $id ) . " .jpg " ;
$filepath = e_MEDIA . $filename ;
if ( ! file_exists ( $filepath ))
{
e107 :: getFile () -> getRemoteFile ( $imageUrl , $filename , 'media' );
}
return $filepath ;
}
2015-06-08 15:55:05 -07:00
/**
* Carousel Item Browser .
* @ param array | string $data - array for items or string for an error alert .
* @ param array $parm
* @ return string
*/
2014-01-08 15:51:14 -08:00
function browserCarousel ( $data , $parm = null )
{
/* Fix for Bootstrap2 margin-left issue when wrapping */
e107 :: css ( 'inline' , '
2018-07-19 12:43:04 -07:00
2014-01-08 15:51:14 -08:00
2014-01-09 04:42:13 -08:00
. row - fluid . media - carousel . span6 : nth - child ( 2 n + 3 ) { margin - left : 0 px ; }
. row - fluid . media - carousel . span4 : nth - child ( 3 n + 4 ) { margin - left : 0 px ; }
. row - fluid . media - carousel . span3 : nth - child ( 4 n + 5 ) { margin - left : 0 px ; }
. row - fluid . media - carousel . span2 : nth - child ( 6 n + 7 ) { margin - left : 0 px ; }
2014-01-08 15:51:14 -08:00
' );
2014-01-09 04:42:13 -08:00
2014-01-08 15:51:14 -08:00
$frm = e107 :: getForm ();
// $text .= print_a($_GET,true);
2018-07-22 14:45:26 -07:00
$data_src = $this -> mediaSelectNav ( $parm [ 'category' ], $parm [ 'tagid' ], $parm );
$carouselID = 'media-carousel-' . $parm [ 'action' ];
2015-03-31 14:48:07 -07:00
$searchToolttip = ( empty ( $parm [ 'searchTooltip' ])) ? " Enter some text to filter results " : $parm [ 'searchTooltip' ];
2014-01-08 15:51:14 -08:00
//$text = "<form class='form-search' action='".e_SELF."?".e_QUERY."' id='core-plugin-list-form' method='get'>";
2014-01-11 08:39:22 -08:00
2014-01-08 15:51:14 -08:00
if ( ! e_AJAX_REQUEST )
{
2014-01-11 08:39:22 -08:00
$searchPlaceholder = varset ( $parm [ 'searchPlaceholder' ], LAN_SEARCH );
2015-07-16 13:41:15 -07:00
$text = '<div class="btn-group"><span class="input-append form-inline">' ;
2017-04-02 07:57:41 -07:00
$text .= " <input type='text' class='form-control e-ajax-keyup input-xxlarge ' placeholder= ' " . $searchPlaceholder . " ...' title= \" " . $searchToolttip . " \" name='search' value='' data-target='media-browser-container- " . $parm [ 'action' ] . " ' data-src=' " . $data_src . " ' /> " ;
2015-03-31 14:48:07 -07:00
// $text .= "<span class='field-help'>bablalal</span>";
2014-01-08 15:51:14 -08:00
// $text .= '<button class="btn btn-primary" name="'.$submitName.'" type="submit">'.LAN_GO.'</button>';
2018-07-22 14:45:26 -07:00
// $text .= '<a class="btn btn-primary" href="#'.$carouselID.'" data-slide="prev">‹</a><a class="btn btn-primary" href="#'.$carouselID.'" data-slide="next">›</a>';
$text .= ' & nbsp ; < div class = " btn-group " >
< a id = " '. $carouselID .'-prev " class = " btn btn-primary btn-secondary " href = " #'. $carouselID .' " data - slide = " prev " >< i class = " fa fa-backward " ></ i ></ a >
2018-07-25 20:28:30 -07:00
< a id = " '. $carouselID .'-index " class = " media-carousel-index btn btn-primary btn-secondary " > 1 </ a >
2018-07-22 14:45:26 -07:00
< a id = " '. $carouselID .'-next " class = " btn btn-primary btn-secondary " href = " #'. $carouselID .' " data - slide = " next " >< i class = " fa fa-forward " ></ i ></ a >
</ div > ' ;
$text .= " </span> " ;
2014-01-08 15:51:14 -08:00
$text .= " </div> " ;
2014-01-09 04:42:13 -08:00
$text .= " <div id='media-browser-container- " . $parm [ 'action' ] . " ' class='form-inline clearfix row-fluid'> " ;
2014-01-08 15:51:14 -08:00
}
2015-06-08 15:55:05 -07:00
2014-01-09 04:42:13 -08:00
2014-01-08 15:51:14 -08:00
// $text .= $this->search('srch', $srch, 'go', $filterName, $filterArray, $filterVal).$frm->hidden('mode','online');
2018-07-25 12:29:52 -07:00
$text .= '<div id="' . $carouselID . '" class="carousel slide" data-interval="false" data-wrap="false">' ;
2018-07-22 14:45:26 -07:00
// $text .= '{INDICATORS}';
2018-07-19 12:43:04 -07:00
$text .= '<div style="margin-top:10px" class="row admingrid carousel-inner">' ;
2014-01-08 15:51:14 -08:00
2014-01-09 04:42:13 -08:00
// $text .= "<div class='item active'>";
2014-01-08 15:51:14 -08:00
$perPage = vartrue ( $parm [ 'perPage' ], 12 );
$c = 0 ;
2018-07-25 20:28:30 -07:00
$count = 0 ;
2018-07-25 12:29:52 -07:00
2014-01-08 15:51:14 -08:00
$slides = array ();
2018-07-25 20:28:30 -07:00
$totalSlides = 0 ;
2015-06-08 15:55:05 -07:00
if ( is_array ( $data ) && count ( $data ) > 0 )
2014-01-08 15:51:14 -08:00
{
2015-06-08 15:55:05 -07:00
foreach ( $data as $key => $val )
2014-01-09 04:42:13 -08:00
{
2018-07-25 20:28:30 -07:00
2015-06-08 15:55:05 -07:00
if ( $c == 0 )
2014-01-09 04:42:13 -08:00
{
2015-06-08 15:55:05 -07:00
$active = ( count ( $slides ) < 1 ) ? ' active' : '' ;
2018-07-25 20:28:30 -07:00
$totalSlides ++ ;
2018-07-25 12:29:52 -07:00
2015-06-08 15:55:05 -07:00
$text .= '
2018-07-25 20:28:30 -07:00
<!-- Start Slide '.$parm[' action '].' '.$totalSlides.' -->
2015-06-08 15:55:05 -07:00
< div class = " item'. $active .' " > ' ;
2018-07-25 20:28:30 -07:00
if ( $totalSlides > 2 )
2018-07-25 12:29:52 -07:00
{
$text .= " <!-- " ;
}
2018-07-25 20:28:30 -07:00
2015-06-08 15:55:05 -07:00
if ( vartrue ( $val [ 'slideCaption' ]))
{
$text .= " <h4> " . $val [ 'slideCaption' ] . " </h4> " ;
}
2014-01-09 04:42:13 -08:00
}
2015-06-08 15:55:05 -07:00
$val [ 'width' ] = $parm [ 'width' ];
$val [ 'height' ] = $parm [ 'height' ];
$val [ 'id' ] = $parm [ 'id' ];
$val [ 'tagid' ] = $parm [ 'tagid' ];
$val [ 'type' ] = $parm [ 'type' ];
$val [ 'bbcode' ] = $parm [ 'bbcode' ];
$val [ 'gridClass' ] = $parm [ 'gridClass' ];
2018-07-25 12:29:52 -07:00
2015-06-08 15:55:05 -07:00
$text .= $this -> browserCarouselItem ( $val );
$c ++ ;
2018-07-25 12:29:52 -07:00
2015-06-08 15:55:05 -07:00
if ( varset ( $val [ 'slideCategory' ]) && isset ( $prevCat ))
2014-01-08 15:51:14 -08:00
{
2015-06-08 15:55:05 -07:00
if ( $val [ 'slideCategory' ] !== $prevCat )
{
$c = $perPage ;
}
$prevCat = $val [ 'slideCategory' ];
}
2018-07-25 20:28:30 -07:00
$count ++ ;
if ( $c == $perPage || ( count ( $data ) == $count ))
2015-06-08 15:55:05 -07:00
{
2018-07-25 20:28:30 -07:00
if ( $totalSlides > 2 )
2018-07-25 12:29:52 -07:00
{
$text .= " --> " ;
}
2015-06-08 15:55:05 -07:00
$text .= '
</ div >
2018-07-25 20:28:30 -07:00
<!-- End Slide '.$parm[' action '].' '.$totalSlides.' --> ' ;
2018-07-25 12:29:52 -07:00
2015-06-08 15:55:05 -07:00
$slides [] = 1 ;
$c = 0 ;
2014-01-08 15:51:14 -08:00
}
2018-07-25 12:29:52 -07:00
2014-01-09 04:42:13 -08:00
}
2015-06-08 15:55:05 -07:00
}
elseif ( is_string ( $data )) // error message.
{
$text .= " <div style='line-height: 1.5;'> " . $data . " </div> " ;
}
else
{
2018-07-25 10:17:49 +02:00
$text .= " <div class='alert alert-info alert-block text-center'> " . LAN_NO_RESULTS_FOUND . " </div> " ;
2015-06-08 15:55:05 -07:00
}
2014-01-09 04:42:13 -08:00
$text .= ( $c != 0 ) ? " </div> \n <!-- End Slide --> \n " : " " ;
2014-01-23 15:56:53 -08:00
2014-01-08 15:51:14 -08:00
$text .= " </div> " ;
2014-01-23 15:56:53 -08:00
$text .= " \n <!-- End Carousel --> \n <div class='clearfix'> </div> \n \n " ;
2014-01-08 15:51:14 -08:00
if ( ! e_AJAX_REQUEST )
{
2014-01-09 04:42:13 -08:00
$text .= " </div></div> " ;
2014-01-08 15:51:14 -08:00
}
2014-01-09 04:42:13 -08:00
$ret = str_replace ( '{INDICATORS}' , $this -> browserIndicators ( $slides , $carouselID ), $text );
2015-04-02 02:49:19 -07:00
if ( E107_DEBUG_LEVEL > 0 )
{
2015-06-08 15:55:05 -07:00
// print_a($parm);
2015-04-02 02:49:19 -07:00
}
2014-01-08 15:51:14 -08:00
return $ret ;
}
2012-05-17 09:19:44 +00:00
2015-05-13 13:34:52 -07:00
/**
* Resize an image .
* @ param $src
* @ param $dest
* @ param string $opts
* @ return bool
*/
function resizeImage ( $src = '' , $dest = '' , $opts = null )
{
$pref = e107 :: getPref ();
$tp = e107 :: getParser ();
2015-08-26 19:09:51 -07:00
if ( empty ( $src ))
{
return false ;
}
2015-05-13 13:34:52 -07:00
if ( is_string ( $opts ))
{
parse_str ( $opts , $opts );
}
$quality = vartrue ( $pref [ 'thumbnail_quality' ], 65 );
$src = $tp -> replaceConstants ( $src );
$dest = $tp -> replaceConstants ( $dest );
2016-04-22 16:10:18 -07:00
if ( ! file_exists ( $src ))
{
return false ;
}
2015-05-13 13:34:52 -07:00
$maxWidth = varset ( $opts [ 'w' ], 800 );
$maxHeight = varset ( $opts [ 'h' ], 800 );
$destDir = dirname ( $dest );
$destFile = basename ( $dest );
$destFilePath = $destDir . " / " . varset ( $opts [ 'prefix' ], $maxWidth . 'x' . $maxHeight ) . '_' . $destFile ;
if ( file_exists ( $destFilePath ))
{
return $destFilePath ;
}
@ require ( e_HANDLER . 'phpthumb/ThumbLib.inc.php' );
try
{
$thumb = PhpThumbFactory :: create ( $src );
$thumb -> setOptions ( array ( 'correctPermissions' => true , 'resizeUp' => false , 'jpegQuality' => $quality ));
$thumb -> resize ( $maxWidth , $maxHeight );
$thumb -> save ( $destFilePath );
return $destFilePath ;
}
catch ( Exception $e )
{
2015-08-24 10:10:08 -07:00
$error = array ( 'thumbnailer' => $e -> getMessage (), 'src' => $src , 'dest' => $dest , 'savePath' => $destFilePath , 'backtrace' => 'e_media::resizeImage' );;
e107 :: getMessage () -> addDebug ( print_a ( $error , true ));
2015-05-13 13:34:52 -07:00
e107 :: getLog () -> add ( " RESIZE ERROR " , $error , E_LOG_INFORMATIVE , 'RESIZE' );
return false ;
}
}
2017-11-16 20:17:07 -08:00
/**
* Convert an image to jpeg format .
* @ param string $oldFile path to png or gif file .
* @ param bool $deleteOld - set to true to delete original after conversion .
* @ return string path to new file .
*/
public function convertImageToJpeg ( $oldFile , $deleteOld = false )
{
if ( substr ( $oldFile , - 4 ) !== '.gif' && substr ( $oldFile , - 4 ) !== '.png' ) // jpg or some other format already
{
return false ;
}
2015-05-13 13:34:52 -07:00
2017-11-16 20:17:07 -08:00
if ( strpos ( $oldFile , " .gif " ) !== false )
{
$type = '.gif' ;
}
if ( strpos ( $oldFile , " .png " ) !== false )
{
$type = '.png' ;
}
if ( empty ( $type ))
{
return $oldFile ;
}
$jpgFile = str_replace ( $type , " .jpg " , $oldFile );
$compression = e107 :: getPref ( 'thumbnail_quality' , 45 ); // 0 = worst / smaller file, 100 = better / bigger file
if ( ! file_exists ( $jpgFile ))
{
switch ( $type )
{
case " .gif " :
$image = imagecreatefromgif ( $oldFile );
break ;
case " .png " :
$image = imagecreatefrompng ( $oldFile );
break ;
}
if ( empty ( $image ))
{
return false ;
}
if ( imagejpeg ( $image , $jpgFile , $compression ) === true )
{
if ( $deleteOld === true )
{
unlink ( $oldFile );
}
}
else
{
$jpgFile = false ; // fallback to original
}
// e107::getLog()->addSuccess("Converting <b>".$oldFile."</b> to <b>".$jpgFile."</b>");
imagedestroy ( $image );
}
return $jpgFile ;
}
2015-05-13 13:34:52 -07:00
2010-03-14 02:11:23 +00:00
}