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

Configuration

The next thing you need to do is create an entry in your config-IP-ADDRESS.xml under the node FILE_PROCESSORS.
  1. <FILE_PROCESSORS>
  2.     <PROCESSOR dir="ExampleProc" name="Example Processor" classname="ExampleProc" namespace="com\yg" />
  3. </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.
  1. <?php
  2.  
  3.     namespace com\yg;
  4.  
  5.     class ExampleProc extends \FileProc {
  6.  
  7.         public function process ($objectid, $params) {
  8.             $view = sFileMgr()->views->get($params["VIEW"]["ID"]);
  9.             $fileinfo = $params["FILEINFO"];
  10.             $filedir = getrealpath(getcwd()."/".sConfig()->getVar('CONFIG/DIRECTORIES/FILESDIR'))."/";
  11.             $filename = $fileinfo['OBJECTID'].'-'.$fileinfo['VIEWVERSION'].$fileinfo['FILENAME'];
  12.             $info = $this->generateThumbnail($filename, $filedir, $view);
  13.             if ($info) {
  14.                 $file = new \File($fileinfo['OBJECTID'], $fileinfo['VERSION']);
  15.                 $file->views->addGenerated($view["ID"], $info["WIDTH"], $info["HEIGHT"], $info["VIEWTYPE"]);
  16.             }
  17.             return true;
  18.         }
  19.  
  20.         public function generateThumbnail ($filename, $filedir, $view) {
  21.  
  22.             // ...
  23.  
  24.             $final_image = imagecreatetruecolor($target_width, $target_height);
  25.             $viewpath = getrealpath($filedir.$prefix.$filename);
  26.             imagejpeg($final_image, $viewpath, 100);
  27.  
  28.             $info["WIDTH"] = $target_width;
  29.             $info["HEIGHT"] = $target_height;
  30.             $info["VIEWTYPE"] = FILE_TYPE_WEBIMAGE;
  31.  
  32.             return $info;
  33.         }
  34.  
  35.         public function cropFile ($filename, $x, $y, $width, $height) {
  36.             // ...
  37.         }
  38.  
  39.     }
  40.    
  41. ?>
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.
  1. public function cropFile ($filename, $x, $y, $width, $height) {
  2.     $imgsize = getimagesize($filename);
  3.     switch ($imgsize[2]) {
  4.         case 1:
  5.         // gif
  6.         $img_in = imagecreatefromgif($filename);
  7.         break;
  8.         case 2:
  9.         // jpg
  10.         $img_in = imagecreatefromjpeg($filename);
  11.         break;
  12.         case 3:
  13.         // png
  14.         $img_in = imagecreatefrompng($filename);
  15.         break;
  16.         default:
  17.         return 0;
  18.     }
  19.     $img_out = imagecreatetruecolor($width, $height);
  20.     imagecopyresampled($img_out, $img_in, 0, 0, $x, $y, $width, $height, $width, $height);
  21.     imagejpeg($img_out, $filename, 100);
  22. }