From 5dc790cd224d86f0bde8c6a955299f29121ab619 Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 7 Aug 2018 17:05:08 -0700 Subject: [PATCH] Provide useful debug information to developers wishing to create custom Filter and Batch handling methods. Media-Manager updated to use the custom batch Handler method. --- e107_admin/image.php | 55 ++++++++++++++++++++++++++++++++------ e107_handlers/admin_ui.php | 12 ++++++--- 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/e107_admin/image.php b/e107_admin/image.php index 2d0f871a6..cc5b47a26 100644 --- a/e107_admin/image.php +++ b/e107_admin/image.php @@ -366,7 +366,7 @@ class media_form_ui extends e_admin_form_ui } asort($this->cats);*/ // require(e_HANDLER.'phpthumb/ThumbLib.inc.php'); // For resizing on import. - + /* if(!empty($_POST['multiselect']) && varset($_POST['e__execute_batch']) && (varset($_POST['etrigger_batch']) == 'options__rotate_cw' || varset($_POST['etrigger_batch']) == 'options__rotate_ccw')) { $type = str_replace('options__','',$_POST['etrigger_batch']); @@ -390,13 +390,13 @@ class media_form_ui extends e_admin_form_ui $ids = implode(",", e107::getParser()->filter($_POST['multiselect'],'int')); $this->convertImagesToJpeg($ids); } - + if(!empty($_POST['multiselect']) && varset($_POST['e__execute_batch']) && (varset($_POST['etrigger_batch']) == 'options__convert_all_to_jpeg' )) { // $type = str_replace('options__','',$_POST['etrigger_batch']); $ids = implode(",", e107::getParser()->filter($_POST['multiselect'],'int')); $this->convertImagesToJpeg($ids,'all'); - } + }*/ } @@ -543,7 +543,7 @@ class media_form_ui extends e_admin_form_ui } - private function convertImagesToJpeg($ids,$mode=null) + public function convertImagesToJpeg($ids,$mode=null) { $sql = e107::getDb(); $tp = e107::getParser(); @@ -564,7 +564,7 @@ class media_form_ui extends e_admin_form_ui if($jpegFile = $mm->convertImageToJpeg($path,true)) { - $url = $tp->createConstants($jpegFile); + $url = $tp->createConstants($jpegFile, 1); $size = filesize($jpegFile); $update = array ( @@ -848,9 +848,9 @@ class media_admin_ui extends e_admin_ui protected $fields = array( 'checkboxes' => array('title'=> '', 'type' => null, 'data'=> null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'), 'media_id' => array('title'=> LAN_ID, 'type' => 'number', 'data'=> 'int', 'width' =>'5%', 'forced'=> TRUE, 'nolist'=>TRUE), - 'media_preview' => array('title'=> LAN_PREVIEW, 'type'=>'method', 'data'=>false, 'forced'=>true, 'width' => '110px', 'thclass' => 'center', 'class'=>'center'), - 'media_url' => array('title'=> IMALAN_110, 'type' => 'text', 'data'=> 'str', 'inline'=>false, 'thclass' => 'left', 'class'=>'left', 'width' => 'auto', 'writeParms'=>'size=xxlarge'), - 'media_category' => array('title'=> LAN_CATEGORY, 'type' => 'comma', 'inline'=>false, 'data'=> 'str', 'width' => '10%', 'filter' => true, 'batch' => true, 'class'=>'left'), + 'media_preview' => array('title'=> LAN_PREVIEW, 'type' => 'method', 'data'=>false, 'forced'=>true, 'width' => '110px', 'thclass' => 'center', 'class'=>'center'), + 'media_url' => array('title'=> IMALAN_110, 'type' => 'text', 'data'=> 'str', 'inline'=>false, 'thclass' => 'left', 'class'=>'left', 'width' => 'auto', 'writeParms'=>'size=xxlarge'), + 'media_category' => array('title'=> LAN_CATEGORY, 'type' => 'comma', 'inline'=>false, 'data'=> 'str', 'width' => '10%', 'filter' => true, 'batch' => true, 'class'=>'left'), // Upload should be managed completely separately via upload-handler. // 'media_upload' => array('title'=> "Upload File", 'type' => 'upload', 'data'=> false, 'readParms' => 'hidden', 'writeParms' => 'disable_button=1', 'width' => '10%', 'nolist' => true), 'media_name' => array('title'=> LAN_TITLE, 'type' => 'text', 'data'=> 'str', 'inline'=>true, 'width' => 'auto', 'writeParms'=>array('size'=>'xxlarge')), @@ -1177,6 +1177,45 @@ class media_admin_ui extends e_admin_ui } + /** + * Handle Batch options as defined in media_form_ui::options(); handle+action+field+Batch + * @param $selected + * @param $type + */ + function handleListOptionsBatch($selected, $type) + { + + /** @var media_form_ui $frm */ + $frm = $this->getUI(); + + $ids = implode(",", $selected); + + switch($type) + { + case "resize_2048": + $frm->resizeImages($ids,$type); + break; + + case "rotate_cw": + case "rotate_ccw": + $frm->rotateImages($ids,$type); + break; + + case "convert_to_jpeg": + + $frm->convertImagesToJpeg($ids); + break; + + case "convert_all_to_jpeg": + $frm->convertImagesToJpeg($ids,'all'); + break; + + default: + // code to be executed if n is different from all labels; + } + + + } function navPage() // no functioning correctly - see e_AJAX_REQUEST above. { diff --git a/e107_handlers/admin_ui.php b/e107_handlers/admin_ui.php index fe2408bdc..91149f31f 100755 --- a/e107_handlers/admin_ui.php +++ b/e107_handlers/admin_ui.php @@ -3471,7 +3471,8 @@ class e_admin_controller_ui extends e_admin_controller //something like handleListUrlTypeBatch(); for custom handling of 'url_type' field name $method = 'handle'.$actionName.$this->getRequest()->camelize($field).'Batch'; - e107::getDebug()->log("Checking for batch method: ".$method); + e107::getMessage()->addDebug("Searching for custom batch method: ".$method."(".$selected.",".$value.")"); + if(method_exists($this, $method)) // callback handling { $this->$method($selected, $value); @@ -3506,7 +3507,7 @@ class e_admin_controller_ui extends e_admin_controller { return array(); } - $filter = $tp->toDB(explode('__', $filter_value)); + $filter = (array) $tp->toDB(explode('__', $filter_value)); $res = array(); switch($filter[0]) { @@ -3542,12 +3543,17 @@ class e_admin_controller_ui extends e_admin_controller default: //something like handleListUrlTypeFilter(); for custom handling of 'url_type' field name filters $method = 'handle'.$this->getRequest()->getActionName().$this->getRequest()->camelize($filter[0]).'Filter'; + $args = array_slice($filter, 1); + + e107::getMessage()->addDebug("Searching for custom filter method: ".$method."(".implode(', ', $args).")"); + + if(method_exists($this, $method)) // callback handling { //return $this->$method($filter[1], $selected); selected? // better approach - pass all values as method arguments // NOTE - callbacks are allowed to return QUERY as a string, it'll be added in the WHERE clause - $args = array_slice($filter, 1); + e107::getMessage()->addDebug('Executing filter callback '.get_class($this).'::'.$method.'('.implode(', ', $args).')'); return call_user_func_array(array($this, $method), $args);