From 891b5f044eaf2c6b799c06cbefe73e25f5e926ad Mon Sep 17 00:00:00 2001 From: Cameron Date: Sat, 11 Aug 2018 12:04:46 -0700 Subject: [PATCH] MediaPicker fixes. --- e107_admin/image.php | 6 +- e107_handlers/media_class.php | 251 ++++++++++++------------- e107_themes/bootstrap3/admin_style.css | 14 +- 3 files changed, 132 insertions(+), 139 deletions(-) diff --git a/e107_admin/image.php b/e107_admin/image.php index a936f1a37..1a1ab9cc6 100644 --- a/e107_admin/image.php +++ b/e107_admin/image.php @@ -1823,7 +1823,7 @@ class media_admin_ui extends e_admin_ui $tp = e107::getParser(); $parms = array( - 'width' => 340, + 'width' => 340, // when inserting into wysiwyg 'height' => 220, 'type' =>'image', 'category' => $category, @@ -1839,6 +1839,10 @@ class media_admin_ui extends e_admin_ui if(!empty($option['bbcode'])) { $close = false; + e107::getBB()->setClass($category); + $parms['width'] = (int) e107::getBB()->resizeWidth(); // resize the image according to prefs. + $parms['height'] = (int) e107::getBB()->resizeHeight(); + e107::getBB()->clearclass(); } diff --git a/e107_handlers/media_class.php b/e107_handlers/media_class.php index d2f7e832e..d9a2af3b6 100644 --- a/e107_handlers/media_class.php +++ b/e107_handlers/media_class.php @@ -30,6 +30,7 @@ class e_media 'other' => e_MEDIA_FILE ); + /** @var array */ protected $mimeExtensions = array( 'text' => array('txt'), 'multipart' => array(), @@ -64,10 +65,11 @@ class e_media * Import files from specified path into media database. * @param string $cat Category nickname * @param string $epath path to file. - * @param string $fmask [optional] filetypes eg. .jpg|.gif IMAGES is the default mask. + * @param string $fmask [optional] filetypes eg. .jpg|.gif IMAGES is the default mask. + * @param array $options * @return e_media */ - public function import($cat='', $epath, $fmask='', $options=array()) + public function import($cat='', $epath='', $fmask='', $options=array()) { if(!vartrue($cat)){ return $this;} @@ -156,7 +158,8 @@ class e_media } } } - if($count) + + // if($count) { // $mes->addSuccess("Imported {$count} Media items."); } @@ -194,20 +197,21 @@ class e_media /** * Remove Media from media table * @param string $cat [optional] remove a full category of media - * @return + * @return bool */ function removeCat($cat) { - $tp = e107::getParser(); + if(empty($cat)) + { + return false; + } + $sql = e107::getDb(); $mes = e107::getMessage(); - - if(vartrue($cat)) - { - $status = ($sql->delete('core_media',"media_cat = '".$cat."'")) ? TRUE : FALSE; - $mes->add("Removing Media in Category: ".$cat, E_MESSAGE_DEBUG); - return $status; - } + + $status = ($sql->delete('core_media',"media_cat = '".$cat."'")) ? true : false; + $mes->add("Removing Media in Category: ".$cat, E_MESSAGE_DEBUG); + return $status; } @@ -216,7 +220,7 @@ class e_media * Remove Media from media table * @param string $epath remove media in the specified path. * @param string $type [optional] image|icon - * @return + * @return bool */ function removePath($epath, $type='image') { @@ -225,15 +229,18 @@ class e_media $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)) + + if(empty($epath)) { - $path = $tp->createConstants($epath, 'rel'); - $status = ($sql->delete('core_media',"media_url LIKE '".$path."%'".$qry)) ? TRUE : FALSE; - $message = ($type == 'image') ? "Removing Media with path: ".$path : "Removing Icons with path: ".$path; - $mes->add($message, E_MESSAGE_DEBUG); - return $status; - } + return false; + } + + $path = $tp->createConstants($epath, 'rel'); + $status = ($sql->delete('core_media',"media_url LIKE '".$path."%'".$qry)) ? TRUE : FALSE; + $message = ($type == 'image') ? "Removing Media with path: ".$path : "Removing Icons with path: ".$path; + $mes->add($message, E_MESSAGE_DEBUG); + return $status; + } @@ -245,7 +252,7 @@ class e_media */ function listIcons($epath) { - if(!$epath) return; + if(!$epath) return array(); $ret = array(); $sql = e107::getDb(); @@ -253,7 +260,7 @@ class e_media $path = $tp->createConstants($epath, 'rel'); - $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; + $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' "); while ($row = $sql->fetch()) { $ret[] = $row['media_url']; @@ -266,7 +273,7 @@ class e_media * Create media category. * 'class' data is optional, 'id' key is ignored * - * @param array $data associative array, db keys should be passed without the leading 'media_cat_' e.g. 'class', 'type', etc. + * @param array $datas associative array, db keys should be passed without the leading 'media_cat_' e.g. 'class', 'type', etc. * @return integer last inserted ID or false on error */ public function createCategory($datas) @@ -299,6 +306,8 @@ class e_media { return false; } + + unset($parms); // remove later if $parms becomes used. $cat = 'user_'.$type.'_'.intval($userId); @@ -326,7 +335,7 @@ class e_media /** * Create multiple media categories in once - * @param array $data + * @param array $multi_data * @return integer number of successfully inserted records */ public function createCategories($multi_data) @@ -368,9 +377,12 @@ class e_media return FALSE; } - + /** * Return an Array of Media Categories + * + * @param string $owner + * @return array */ public function getCategories($owner='') { @@ -390,64 +402,53 @@ class e_media } return $ret; } - + /** * Return the total number of Images in a particular category - * - */ + * + * @param string $cat + * @param string $search + * @return array + */ public function countImages($cat,$search=null) { - return $this->getImages($cat, 0, 'all',$search); - - /* - - $inc = array(); - $searchinc = array(); - - if(strpos($cat,"+") || !$cat) - { - $cat = str_replace("+","",$cat); - $inc[] = "media_category = '_common_image' "; - } - if($cat) - { - $inc[] = "media_category REGEXP '(^|,)(".$cat.")(,|$)' "; // for multiple category field. - } - - if($search) - { - $searchinc[] = "media_name LIKE '%".$search."%' "; - $searchinc[] = "media_description LIKE '%".$search."%' "; - $searchinc[] = "media_caption LIKE '%".$search."%' "; - $searchinc[] = "media_tags LIKE '%".$search."%' "; - } - - - $query = "SELECT * FROM #core_media WHERE media_userclass IN (".USERCLASS_LIST.") AND ( ".implode(" OR ",$inc)." )" ; - - if($search) - { - $query .= " AND ( ".implode(" OR ",$searchinc)." ) " ; - } - - return e107::getDb()->gen($query); - */ } - - + + + /** + * @param string $cat + * @param int $from + * @param int $amount + * @param string $search + * @return array + */ public function getFiles($cat, $from=0, $amount = null, $search = null) { - return $this->getMedia('application', $from, $amount, $search); + return $this->getMedia('application', $cat, $from, $amount, $search); } + /** + * @param string $cat + * @param int $from + * @param int $amount + * @param string $search + * @return array + */ public function getVideos($cat, $from=0, $amount = null, $search = null) { return $this->getMedia('video', $cat, $from, $amount, $search); } + /** + * @param string $cat + * @param int $from + * @param int $amount + * @param string $search + * @return array + */ public function getAudios($cat='', $from=0, $amount = null, $search = null) { return $this->getMedia('audio', $cat, $from, $amount, $search); @@ -455,10 +456,12 @@ class e_media /** * Return an array of Images in a particular category + * * @param string $cat : category name. use + to include _common eg. 'news+' - * @param $from - * @param $amount - * @param $search + * @param int $from + * @param int $amount + * @param string $search + * @param null $orderby * @return array */ public function getImages($cat='', $from=0, $amount=null, $search=null, $orderby=null) @@ -469,17 +472,20 @@ class e_media /** * 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 + * @param int $from + * @param int|string $amount + * @param string $search + * @param string $orderby + * @return array|bool */ private function getMedia($type, $cat='', $from=0, $amount=null, $search=null, $orderby=null) { - $inc = array(); + // $inc = array(); $searchinc = array(); + $catArray = array(); if(strpos($cat,"+") || !$cat) { @@ -599,12 +605,16 @@ class e_media /** - * Generate Simple Thumbnail window for image -selection + * Generate Simple Thumbnail window for image -selection + * @deprecated Currently used only by ren_help PreImage_Select + * @param string $cat + * @param string $formid + * @return string */ - private function imageSelect($cat,$formid='imageSel') + public function imageSelect($cat,$formid='imageSel') { $sql = e107::getDb(); - $tp = e107::getParser(); + // $tp = e107::getParser(); $text = "