Getting started
File Processors allow the processing of Files which have been uploaded to yeager. A File Processor is called everytime a File gets updated or a View gets added to a File. Each File Type specifies one specific File Processor which will be used to process the Files in the background.
File structure
To add a File Processor you need to put a new folder into your processor directory, which you configured during the installation (e.g. /frontend/processors/)
/processor_directory/
/processor_class-name.php
/processor_directory/
/processor_class-name.php
Configuration
The next thing you need to do is create an entry in your config-IP-ADDRESS.xml under the node FILE_PROCESSORS.
- <FILE_PROCESSORS>
- <PROCESSOR dir="ExampleProc" name="Example Processor" classname="ExampleProc" namespace="com\yg" />
- </FILE_PROCESSORS>
dir |
Specifies the directory name in the processor folder |
name |
Specifies the name displayed in yeager's File Type administration panel |
namespace |
Specifies the namespace which will also have to be used in your processors PHP file |
Implementation
Following is a minimalistic example of a File Processor. The only mandatory method is process(). In case you want to make use of yeager's manual cropping UI you need to specifiy cropFile() as well.
- <?php
- namespace com\yg;
- class ExampleProc extends \FileProc {
- public function process ($objectid, $params) {
- $view = sFileMgr()->views->get($params["VIEW"]["ID"]);
- $fileinfo = $params["FILEINFO"];
- $filedir = getrealpath(getcwd()."/".sConfig()->getVar('CONFIG/DIRECTORIES/FILESDIR'))."/";
- $filename = $fileinfo['OBJECTID'].'-'.$fileinfo['VIEWVERSION'].$fileinfo['FILENAME'];
- $info = $this->generateThumbnail($filename, $filedir, $view);
- if ($info) {
- $file = new \File($fileinfo['OBJECTID'], $fileinfo['VERSION']);
- $file->views->addGenerated($view["ID"], $info["WIDTH"], $info["HEIGHT"], $info["VIEWTYPE"]);
- }
- return true;
- }
- public function generateThumbnail ($filename, $filedir, $view) {
- // ...
- $final_image = imagecreatetruecolor($target_width, $target_height);
- $viewpath = getrealpath($filedir.$prefix.$filename);
- imagejpeg($final_image, $viewpath, 100);
- $info["WIDTH"] = $target_width;
- $info["HEIGHT"] = $target_height;
- $info["VIEWTYPE"] = FILE_TYPE_WEBIMAGE;
- return $info;
- }
- public function cropFile ($filename, $x, $y, $width, $height) {
- // ...
- }
- }
- ?>
After processing a View it needs to be added to a File by executing $file->views->addGenerated (see API docs: Views->addGenerated). yeager's ability to preview those Views in it's UI is depending on the specified type:
Type / Constant | Description |
FILE_TYPE_WEBNONE |
Cannot be displayed / previewed in webbrowsers |
FILE_TYPE_WEBIMAGE |
Is an image file, which can be displayed as image in a webbrowser. yeager will try to preview these Files (usually jpg, jpeg, png, gif) |
FILE_TYPE_WEBAUDIO |
Is an audio file - there will be functionality built into yeager in the future which will allow previewing/playing of certain audio files |
FILE_TYPE_WEBVIDEO |
Is a video file - there will be functionality built into yeager in the future which will allow previewing of PDF files |
FILE_TYPE_WEBVECTOR |
Is a vector image - there will be functionality built into yeager in the future which will allow previewing of certain vector images |
FILE_TYPE_PDF |
Is a PDF - there will be functionality built into yeager in the future which will allow previewing of PDF files |
Image cropping functionality
yeager will offer functionality to crop Views of the type FILE_TYPE_WEBIMAGE. Therefore you need to implement the cropFile method in your File Processor, in case you plan to process web images.
- public function cropFile ($filename, $x, $y, $width, $height) {
- $imgsize = getimagesize($filename);
- switch ($imgsize[2]) {
- case 1:
- // gif
- $img_in = imagecreatefromgif($filename);
- break;
- case 2:
- // jpg
- $img_in = imagecreatefromjpeg($filename);
- break;
- case 3:
- // png
- $img_in = imagecreatefrompng($filename);
- break;
- default:
- return 0;
- }
- $img_out = imagecreatetruecolor($width, $height);
- imagecopyresampled($img_out, $img_in, 0, 0, $x, $y, $width, $height, $width, $height);
- imagejpeg($img_out, $filename, 100);
- }