/** * Gets called when custom data is to be added for a file custom data can for example be * plugin specific name value items that should get added into a file listning. * * @param MCManager $man MCManager reference that the plugin is assigned to. * @param BaseFile $file File reference to add custom info/data to. * @param string $type Where is the info needed for example list or info. * @param Array $custom Name/Value array to add custom items to. * @return bool true/false if the execution of the event chain should continue. */ function onCustomInfo(&$man, &$file, $type, &$input) { switch ($type) { // When the file is selected/inserted case "insert": // Can be used by the insert_templates like this {$custom.mycustomfield} $input['mycustomfield'] = strtoupper($file->getName()); // Will be used as title/alt in TinyMCE link/image dialogs $input['description'] = $file->getName() . " (" . $this->_getSizeStr($file->getLength()) . ")"; break; // When the file is displayed in a more info dialog // When the file is displayed in a more info dialog case "info": //$input['mycustomfield'] = strtoupper($file->getName()); break; // When the file is listed // When the file is listed case "list": //$input['mycustomfield'] = strtoupper($file->getName()); break; } // Chain to next return true; }
/** * Gets called when custom data is to be added for a file custom data can for example be * plugin specific name value items that should get added into a file listning. * * @param MCManager $man MCManager reference that the plugin is assigned to. * @param BaseFile $file File reference to add custom info/data to. * @param string $type Where is the info needed for example list or info. * @param Array $custom Name/Value array to add custom items to. * @return bool true/false if the execution of the event chain should continue. */ function onCustomInfo(&$man, &$file, $type, &$input) { // Is file and image $config = $file->getConfig(); $input["editable"] = false; if ($file->isFile() && ($type == "list" || $type == "insert" || $type == "info")) { // Should we get config on each file here? //$config = $file->getConfig(); $ext = getFileExt($file->getName()); if (!in_array($ext, array('gif', 'jpeg', 'jpg', 'png', 'bmp'))) { return true; } $imageutils = new $config['thumbnail'](); $canEdit = $imageutils->canEdit($ext); $imageInfo = @getimagesize($file->getAbsolutePath()); $fileWidth = $imageInfo[0]; $fileHeight = $imageInfo[1]; $targetWidth = $config['thumbnail.width']; $targetHeight = $config['thumbnail.height']; // Check thumnail size if ($config['thumbnail.scale_mode'] == "percentage") { if ($config['thumbnail.height'] > $config['thumbnail.width']) { $target = $config['thumbnail.width']; } else { $target = $config['thumbnail.height']; } $percentage = 0; if ($fileWidth > $fileHeight) { $percentage = $target / $fileWidth; } else { $percentage = $target / $fileHeight; } if ($percentage <= 1) { $targetWidth = round($fileWidth * $percentage); $targetHeight = round($fileHeight * $percentage); } else { $targetWidth = $fileWidth; $targetHeight = $fileHeight; } } $input["thumbnail"] = true; // Check against config. if ($config["thumbnail.max_width"] != "" && $fileWidth > $config["thumbnail.max_width"] || $config["thumbnail.max_height"] != "" && $fileHeight > $config["thumbnail.max_height"]) { $input["thumbnail"] = false; } else { $input["twidth"] = $targetWidth; $input["theight"] = $targetHeight; } // Get thumbnail URL if ($type == "insert") { $thumbFile = $man->getFile($file->getParent() . "/" . $config['thumbnail.folder'] . "/" . $config['thumbnail.prefix'] . $file->getName()); if ($thumbFile->exists()) { $input["thumbnail_url"] = $man->convertPathToURI($thumbFile->getAbsolutePath()); } } $input["width"] = $fileWidth; $input["height"] = $fileHeight; $input["editable"] = $canEdit; } return true; }