function getMime($file, $custom_type, $ext)
 {
     zmgimport('org.zoomfactory.lib.mime.zmgMime');
     return zmgMime::autoDetect($file, $custom_type, $ext);
 }
 function process(&$medium, &$gallery)
 {
     $ok = true;
     //innocent, until proven guilty ;)
     $events =& zmgFactory::getEvents();
     $config =& zmgFactory::getConfig();
     $imagetools =& zmgToolboxConstants::getImageTools();
     $toolkey = intval($config->get('plugins/toolbox/general/conversiontool'));
     $imagetool = $imagetools[$toolkey - 1];
     zmgimport('org.zoomfactory.var.plugins.toolbox.tools.' . $imagetool . 'Tool');
     $klass = 'zmg' . ucfirst($imagetool) . 'Tool';
     $file = $medium->getAbsPath();
     $size = getimagesize($file);
     $img_meta = array('width' => $size[0], 'height' => $size[1], 'extension' => $medium->getExtension(), 'jpeg_qty' => $config->get('plugins/toolbox/general/jpegquality'));
     $metadata = $events->fire('ongetimagemetadata', false, $medium);
     //rotate image
     //TODO
     //resize to thumbnail
     if ($ok && !file_exists($medium->getAbsPath(ZMG_MEDIUM_THUMBNAIL))) {
         $ok = call_user_func_array(array($klass, 'resize'), array($file, $medium->getAbsPath(ZMG_MEDIUM_THUMBNAIL), intval($config->get('plugins/toolbox/general/imagesizethumbnail')), $img_meta));
     }
     //resize to viewsize format
     $maxSize = intval($config->get('plugins/toolbox/general/imagesizemax'));
     if ($ok && !file_exists($medium->getAbsPath(ZMG_MEDIUM_VIEWSIZE)) && ($img_meta['width'] > $maxSize || $img_meta['height'] > $maxSize)) {
         $ok = call_user_func_array(array($klass, 'resize'), array($file, $medium->getAbsPath(ZMG_MEDIUM_VIEWSIZE), intval($config->get('plugins/toolbox/general/imagesizethumbnail')), $img_meta));
     }
     //apply watermarks
     //TODO
     if ($ok) {
         $ok = $events->fire('onputimagemetadata', false, $medium, $metadata);
     }
     return $ok;
 }
 /**
  * Generate a thumbnail from a video stream using the FFMpeg library.
  *
  * @param string $file
  * @param string $size
  * @param string $filename
  * @return boolean
  */
 function process(&$medium, &$gallery)
 {
     //$file, $size, $filename) {
     zmgimport('org/.zoomfactory.lib.helpers.zmgFileHelper');
     //$temp_dir = zmgEnv::getTempDir() . DS.substr(uniqid("zoom_"), 0, 13); //support filesystems which only support 14 char dirnames
     //if (zmgFileHelper::createDir($temp_dir, 0777)) {
     $thumb_file = ereg_replace("(.*)\\.([^\\.]*)\$", "\\1", $medium->filename) . ".jpg";
     $thumb_path = str_replace($medium->filename, $thumb_file, $medium->getAbsPath());
     //$temp_dir.DS.$thumb_file;
     $cmd = zmgVideoTool::getPath() . "ffmpeg -an -y -t 0:0:0.001 -i \"" . $medium->getAbsPath() . "\" -f mjpeg \"" . $thumb_path . "\"";
     $output = $retval = null;
     exec($cmd, $output, $retval);
     if ($retval || !zmgFileHelper::exists($thumb_path)) {
         return zmgToolboxPlugin::registerError($medium->filename, 'FFMpeg: Could not create thumbnail: ' . $output);
     }
     $thumb_obj = new zmgMedium(zmgDatabase::getDBO());
     //temp obj
     $thumb_obj->filename = $thumb_file;
     $thumb_obj->setGalleryDir($medium->getGalleryDir());
     $ret = true;
     zmgimport('org.zoomfactory.var.plugins.toolbox.tools.imageTool');
     if (!zmgImageTool::process($thumb_obj, $gallery)) {
         $ret = false;
     }
     //clean up!
     zmgFileHelper::delete($thumb_path);
     return $ret;
     //} else {
     //    return zmgToolboxPlugin::registerError($medium->filename, 'FFmpeg: Could not create temporary directory.');
     //}
 }
 function storeDelegate(&$event)
 {
     $aView = $event->getArgument('view');
     $view = implode(':', $aView);
     $config =& zmgFactory::getConfig();
     $events =& zmgFactory::getEvents();
     $request =& zmgFactory::getRequest();
     switch ($view) {
         case "admin:settings:store":
             $request->setResult($config->update($_POST, false));
             break;
         case stristr($view, "admin:settings:plugins:autodetect"):
             $tool = trim($aView[count($aView) - 1]);
             if ($tool == "autodetect") {
                 $tool = "all";
             } else {
                 $tool = array($tool);
             }
             $events->fire('onautodetect', false, $tool);
             break;
         case stristr($view, "admin:update:mediacount"):
             $filter = intval(array_pop($aView));
             $zoom =& zmgFactory::getEvents()->fire('ongetcore');
             $request->setResult($zoom->getMediumCount($filter));
             break;
         case "admin:galleryedit:store":
             zmgimport('org.zoomfactory.var.plugins.datastore.stores.galleryStore');
             zmgGalleryStore::process();
             break;
         case "admin:galleryedit:delete":
             zmgimport('org.zoomfactory.var.plugins.datastore.stores.galleryStore');
             zmgGalleryStore::delete();
             break;
         case "admin:mediumedit:store":
             zmgimport('org.zoomfactory.var.plugins.datastore.stores.mediumStore');
             zmgMediumStore::process();
             break;
         case stristr($view, "admin:mediaupload:store"):
             //SWFUpload needs HTTP headers to signal the user...
             $method = stristr($view, "jupload") ? "jupload" : "swfupload";
             $events->fire('onupload', false, $method);
             //exit;
             break;
         case stristr($view, "admin:mediaupload:update"):
             $gid = array_pop($aView);
             $events->fire('onuploadupdate', false, $gid);
             break;
         case stristr($view, "admin:update:mediacount"):
             $gid = intval(array_pop($aView));
             $zoom =& zmgFactory::getEvents()->fire('ongetcore');
             echo $zoom->getMediumCount($gid);
             break;
         default:
             break;
     }
 }
 function getId3Instance()
 {
     static $getid3_instance;
     if (!is_object($getid3_instance)) {
         $getid3_dir = "v" . str_replace('.', '_', ZMG_GETID3_VERSION);
         zmgimport('org.zoomfactory.var.plugins.getid3.' . $getid3_dir . '.getid3');
         $getid3_instance = new getID3();
     }
     return $getid3_instance;
 }
 function embed()
 {
     zmgimport('org.zoomfactory.var.plugins.core.assets.*');
     $messages =& zmgFactory::getMessages();
     $session =& zmgFactory::getSession();
     //also restores the session if needed
     $from_session = $session->get('zmg.messagecenter.cache');
     if (!empty($from_session) && is_array($from_session)) {
         $messages->setAll($from_session);
     }
 }
 function embed()
 {
     $os = zmgCmsPlugin::_guessCMS();
     $os_dir = ZMG_ABS_PATH . DS . 'var' . DS . 'plugins' . DS . 'cms' . DS . $os;
     if (is_dir($os_dir)) {
         $os_path = 'org.zoomfactory.var.plugins.cms.' . $os;
         zmgimport($os_path . '.aclEmbed');
         zmgimport($os_path . '.databaseEmbed');
         zmgimport($os_path . '.envEmbed');
         return true;
     }
     zmgError::throwError('zmgCmsPlugin: no CMS found.');
     return false;
 }
 function getImageMetadata($event)
 {
     $medium = $event->getArgument('medium');
     $data = array('headers' => null, 'exif' => null, 'xmp' => null, 'irb' => null, 'finfo' => null);
     $ext = $medium->getExtension();
     $file = $medium->getAbsPath();
     if (zmgFactory::getConfig()->get('plugins/jpeg_metadata/general/readwrite') && ($ext == "jpg" || $ext == "jpeg") && !ZMG_SAFEMODE_ON) {
         //import libs first (duh ;) )
         $jmt_dir = "v" . str_replace('.', '_', ZMG_JMT_VERSION);
         zmgimport('org.zoomfactory.var.plugins.jpeg_metadata.' . $jmt_dir . '.EXIF');
         //takes care of some deferred loading as well
         zmgimport('org.zoomfactory.var.plugins.jpeg_metadata.' . $jmt_dir . '.Photoshop_File_Info');
         // Retreive the EXIF, XMP and Photoshop IRB information from
         // the existing file, so that it can be updated later on...
         $data['headers'] = get_jpeg_header_data($file);
         $data['exif'] = get_EXIF_JPEG($file);
         $data['xmp'] = read_XMP_array_from_text(get_XMP_text($data['headers']));
         $data['irb'] = get_Photoshop_IRB($data['headers']);
         $data['finfo'] = get_photoshop_file_info($data['exif'], $data['xmp'], $data['irb']);
         // Check if there is a default for the date defined
         if (!array_key_exists('date', $data['finfo']) || array_key_exists('date', $data['finfo']) && $data['finfo']['date'] == '') {
             // No default for the date defined
             // figure out a default from the file
             // Check if there is a EXIF Tag 36867 "Date and Time of Original"
             if ($data['exif'] != false && array_key_exists(0, $data['exif']) && array_key_exists(34665, $data['exif'][0]) && array_key_exists(0, $data['exif'][0][34665]) && array_key_exists(36867, $data['exif'][0][34665][0])) {
                 // Tag "Date and Time of Original" found - use it for the default date
                 $data['finfo']['date'] = $data['exif'][0][34665][0][36867]['Data'][0];
                 $data['finfo']['date'] = preg_replace("/(\\d\\d\\d\\d):(\\d\\d):(\\d\\d)( \\d\\d:\\d\\d:\\d\\d)/", "\$1-\$2-\$3", $data['finfo']['date']);
             } elseif ($data['exif'] != false && array_key_exists(0, $data['exif']) && array_key_exists(34665, $data['exif'][0]) && array_key_exists(0, $data['exif'][0][34665]) && array_key_exists(36868, $data['exif'][0][34665][0])) {
                 // Check if there is a EXIF Tag 36868 "Date and Time when Digitized"
                 // Tag "Date and Time when Digitized" found - use it for the default date
                 $data['finfo']['date'] = $data['exif'][0][34665][0][36868]['Data'][0];
                 $data['finfo']['date'] = preg_replace("/(\\d\\d\\d\\d):(\\d\\d):(\\d\\d)( \\d\\d:\\d\\d:\\d\\d)/", "\$1-\$2-\$3", $data['finfo']['date']);
             } else {
                 if ($data['exif'] != false && array_key_exists(0, $data['exif']) && array_key_exists(306, $data['exif'][0])) {
                     // Check if there is a EXIF Tag 306 "Date and Time"
                     // Tag "Date and Time" found - use it for the default date
                     $data['finfo']['date'] = $data['exif'][0][306]['Data'][0];
                     $data['finfo']['date'] = preg_replace("/(\\d\\d\\d\\d):(\\d\\d):(\\d\\d)( \\d\\d:\\d\\d:\\d\\d)/", "\$1-\$2-\$3", $data['finfo']['date']);
                 } else {
                     // Couldn't find an EXIF date in the image
                     // Set default date as creation date of file
                     $data['finfo']['date'] = date("Y-m-d", filectime($file));
                 }
             }
         }
     }
     return zmgJpeg_metadataPlugin::interpretImageData($data, $medium->filename);
 }
 function _loadPlugins()
 {
     zmgimport('org.zoomfactory.lib.helpers.zmgFileHelper');
     $plugin_cats = zmgFileHelper::readDir(ZMG_ABS_PATH . DS . 'var' . DS . 'plugins', '[^index\\.html]');
     $this->_plugins = array();
     foreach ($plugin_cats as $plugin) {
         if ($plugin != "shared") {
             $content = zmgFileHelper::readDir(ZMG_ABS_PATH . DS . 'var' . DS . 'plugins' . DS . $plugin, '[^index\\.html]');
             if (is_array($content) && count($content) > 0) {
                 $plugin_class = "zmg" . ucfirst($plugin) . "Plugin";
                 zmgimport('org.zoomfactory.var.plugins.' . $plugin . '.' . $plugin . 'Plugin');
                 $events = zmgCallAbstract($plugin_class, 'bindEvents');
                 if (is_array($events)) {
                     // update the PluginHelper's event registry
                     $this->_bindEvents($plugin_class, $events);
                 }
                 $this->_plugins[] = array('name' => $plugin, 'classname' => $plugin_class, 'settings' => null, 'events' => $events);
             }
         }
     }
 }
 /**
  * Class constructor.
  * Prepares files for first run.
  * Global variables setting.
  *
  * @return void
  */
 function zmgLogger($logDir = "log", $logMode = "oneFile")
 {
     //set global variables
     $this->_logDir = $logDir;
     $this->_logMode = $logMode;
     $this->_countFile = $this->_logDir . DS . $this->_countFile;
     zmgimport('org.zoomfactory.lib.helpers.zmgFileHelper');
     //verify log folder existence. If it doesn't I create it
     if (!is_dir($this->_logDir)) {
         if (!zmgFileHelper::createDir($this->_logDir)) {
             zmgError::throwError("Could not create log dir");
         }
     }
     //Counter init
     if (!zmgFileHelper::exists($this->_countFile)) {
         //if log counter file does not exist, I create it
         touch($this->_countFile);
         //inicializing file in 0
         $initNumber = 0;
         $fp = fopen($this->_countFile, "a");
         if (fwrite($fp, $initNumber) === false) {
             zmgError::throwError("Could not write Counter file");
         }
         fclose($fp);
     }
     //read counter
     $logNumber = intval(trim(file_get_contents($this->_countFile)));
     $logNumber++;
     //increment counter
     //set log number in class var
     $this->_logNumber = $logNumber;
     //write incremented counter value
     $fp = fopen($this->_countFile, "w+");
     if (fwrite($fp, $logNumber) === false) {
         zmgError::throwError("Could not write Counter file");
     }
     fclose($fp);
 }
 function processMedium(&$medium, &$gallery)
 {
     $mime = $medium->getMimeType();
     zmgimport('org.zoomfactory.lib.mime.zmgMimeHelper');
     $ok = true;
     if (zmgMimeHelper::isImage($mime, true)) {
         zmgimport('org.zoomfactory.var.plugins.toolbox.tools.imageTool');
         $ok = zmgImageTool::process($medium, $gallery);
         if (!$ok) {
             zmgToolboxPlugin::registerError(T_('Upload medium'), T_('Could not create thumbnail of image file'));
             //TODO: cleanup
         }
     } else {
         if (zmgMimeHelper::isDocument($mime, true) && zmgMimeHelper::isIndexable($mime, true)) {
             zmgimport('org.zoomfactory.var.plugins.toolbox.tools.documentTool');
             $ok = zmgDocumentTool::process($medium, $gallery);
             if (!$ok) {
                 zmgToolboxPlugin::registerError(T_('Upload medium'), T_('Could not index document'));
                 //TODO: cleanup
             }
         } else {
             if (zmgMimeHelper::isVideo($mime, true) && zmgMimeHelper::isThumbnailable($mime, true)) {
                 zmgimport('org.zoomfactory.var.plugins.toolbox.tools.videoTool');
                 $ok = zmgVideoTool::process($medium, $gallery);
                 if (!$ok) {
                     zmgToolboxPlugin::registerError(T_('Upload medium'), T_('Could not create thumbnail of video file'));
                     //TODO: cleanup
                 }
             } else {
                 if (zmgMimeHelper::isAudio($mime, true)) {
                     zmgimport('org.zoomfactory.var.plugins.toolbox.tools.audioTool');
                     $ok = zmgAudioTool::process($medium, $gallery);
                     if (!$ok) {
                         zmgToolboxPlugin::registerError(T_('Upload medium'), T_('Audio file not supported'));
                         //TODO: cleanup
                     }
                 } else {
                     zmgToolboxPlugin::registerError(T_('Upload medium'), T_('Unsupported medium type.'));
                 }
             }
         }
     }
     return $ok;
 }
 /**
  * JFTP object constructor
  *
  * @access protected
  * @param array $options Associative array of options to set
  * @since 1.5
  */
 function __construct($options = array())
 {
     // If default transfer type is no set, set it to autoascii detect
     if (!isset($options['type'])) {
         $options['type'] = FTP_BINARY;
     }
     $this->setOptions($options);
     if (ZMG_ISWIN) {
         $this->_OS = 'WIN';
     } elseif (ZMG_ISMAC) {
         $this->_OS = 'MAC';
     } else {
         $this->_OS = 'UNIX';
     }
     if (FTP_NATIVE) {
         // Import the generic buffer stream handler
         zmgimport('org.zoomfactory.lib.helpers.zmgBufferHelper');
     }
     // Register faked "destructor" in PHP4 to close all connections we might have made
     if (version_compare(PHP_VERSION, '5') == -1) {
         register_shutdown_function(array(&$this, '__destruct'));
     }
 }
 function buildDirStructure()
 {
     zmgimport('org.zoomfactory.lib.helpers.zmgFileHelper');
     $html_file = "<html><body bgcolor=\"#FFFFFF\"></body></html>";
     $root = zmgEnv::getRootPath();
     $mediapath = $root . DS . zmgFactory::getConfig()->get('filesystem/mediapath');
     $dirs = array($mediapath . $this->dir, $mediapath . $this->dir . DS . 'thumbs', $mediapath . $this->dir . DS . 'viewsize');
     foreach ($dirs as $dir) {
         if (zmgFileHelper::createDir($dir, 0777)) {
             if (!zmgFileHelper::write($dir . DS . 'index.html', $html_file)) {
                 zmgError::throwError(T_('Unable to write to file: ') . $dir . DS . 'index.html');
             }
         } else {
             zmgError::throwError(T_('Unable to create directory: ') . $dir);
         }
     }
     return true;
 }
 function finalizeUpload($gid = 0)
 {
     //finish the SwfUpload sequence...
     if ($gid === 0) {
         return zmgToolboxPlugin::registerError(T_('Upload media'), T_('No valid gallery ID provided'));
     }
     $session =& zmgFactory::getSession();
     $events =& zmgFactory::getEvents();
     $config =& zmgFactory::getConfig();
     $db =& zmgDatabase::getDBO();
     $gallery = new zmgGallery($db);
     $gallery->load($gid);
     //now we got the gallery and its data, retrieve the uploaded media
     $media = $session->get('uploadtool.fancyfiles');
     if (!is_array($media) || count($media) == 0) {
         return zmgToolboxPlugin::registerError(T_('Upload media'), T_('No media have been uploaded; nothing to do.'));
     }
     zmgimport('org.zoomfactory.lib.helpers.zmgFileHelper');
     $src_path = ZMG_ABS_PATH . DS . "etc" . DS . "cache" . DS;
     $dest_path = zmgEnv::getRootPath() . DS . $config->get('filesystem/mediapath') . $gallery->dir . DS;
     foreach ($media as $medium) {
         $obj = new zmgMedium($db);
         $name = zmgSQLEscape(zmgGetParam($_REQUEST, 'zmg_upload_name', ''));
         $descr = zmgSQLEscape(zmgGetParam($_REQUEST, 'zmg_upload_descr', ''));
         $data = array('name' => $name, 'filename' => $medium, 'descr' => $descr, 'published' => 1, 'gid' => $gallery->gid);
         $obj->setGalleryDir($gallery->dir);
         //saves a SQL query later on...
         //do some additional validation of strings
         $data['name'] = $events->fire('onvalidate', $data['name']);
         if (!$data['name']) {
             $data['name'] = $name;
         }
         $data['descr'] = $events->fire('onvalidate', $data['descr']);
         if (!$data['descr']) {
             $data['descr'] = $descr;
         }
         if (!$obj->bind($data)) {
             zmgToolboxPlugin::registerError(T_('Upload media'), T_('Medium could not be saved') . ': ' . $obj->getError());
         } else {
             if (!zmgFileHelper::copy($src_path . $medium, $dest_path . $medium)) {
                 zmgToolboxPlugin::registerError(T_('Upload media'), T_('Unable to copy file') . ' ' . $medium);
             } else {
                 if (!zmgFileHelper::delete($src_path . $medium)) {
                     zmgToolboxPlugin::registerError(T_('Upload media'), T_('Unable to delete temporary file') . ' ' . $medium);
                 } else {
                     if (!zmgToolboxPlugin::processMedium($obj, $gallery)) {
                         zmgToolboxPlugin::registerError(T_('Upload media'), T_('Medium could not be processed') . ' ' . $medium);
                     } else {
                         if (!$obj->store()) {
                             //now save this medium in our DB
                             zmgToolboxPlugin::registerError(T_('Upload media'), T_('Medium could not be saved') . ': ' . $obj->getError());
                         }
                     }
                 }
             }
         }
         //delete medium from session data: fourth parameter as TRUE
         $session->update('uploadtool.fancyfiles', $medium, ZMG_DATATYPE_ARRAY, true);
     }
     zmgToolboxPlugin::throwErrors();
 }
//load the error handling base class
zmgimport('org.zoomfactory.lib.zmgError');
//initialize Smarty template engine
zmgimport('org.zoomfactory.lib.smarty.Smarty');
//import other useful stuff
zmgimport('org.zoomfactory.lib.zmgHTML');
if (!class_exists('InputFilter')) {
    zmgimport('org.zoomfactory.lib.phpinputfilter.inputfilter');
}
$config =& zmgFactory::getConfig();
$events =& zmgFactory::getEvents();
$request =& zmgFactory::getRequest();
$view =& zmgFactory::getView();
$events->fire('onstartup');
$events->fire('onstarted');
if (!$config->isInstalled()) {
    $config->firstRun();
}
$view->setViewType(zmgEnv::getViewType());
//set error handling options
zmgError::setErrorHandling($config->get('app/errors/defaultmode'), $config->get('app/errors/defaultoption'));
//load php-gettext (used in zoom in 'fallback mode')
zmgimport('org.zoomfactory.lib.phpgettext.gettext_inc');
// gettext setup
T_setlocale(LC_ALL, $config->get('locale/default'));
// Set the text domain as 'messages'
$domain = $config->get('locale/domain');
T_bindtextdomain($domain, ZMG_ABS_PATH . '/locale');
T_bind_textdomain_codeset($domain, $config->get('locale/encoding'));
T_textdomain($domain);
$events->fire('oncontent');
 /**
  * Public variable, containing the zmgViewHelper - helping ZMG with controlling
  * the views on the different models that the Core exposes.
  *
  * @return zmgViewHelper
  */
 function &getView()
 {
     static $instance_view;
     if (!is_object($instance_view)) {
         zmgimport('org.zoomfactory.lib.helpers.zmgViewHelper');
         $config =& zmgFactory::getConfig();
         $instance_view = new zmgViewHelper($config->get('smarty'), $config->get('app/secret'));
     }
     return $instance_view;
 }
 function save()
 {
     $content = "<?php\n" . "/**\n" . " * zOOm Media Gallery! - a multi-gallery component\n" . " * \n" . " * @package zmg\n" . " * @author Mike de Boer <mike AT zoomfactory.org>\n" . " * @copyright Copyright &copy; 2007, Mike de Boer. All rights reserved.\n" . " * @license http://www.gnu.org/copyleft/gpl.html GPL\n" . " */\n\n" . "defined('_ZMG_EXEC') or die('Restricted access');\n\n" . "\$zoom_config = array();\n" . "\$zoom_config['date_lch'] = " . time() . ";\n" . $this->_buildMetaBlock() . $this->_buildLocaleBlock() . $this->_buildDatabaseBlock() . $this->_buildFilesystemBlock() . $this->_buildSmartyBlock() . $this->_buildLayoutBlock() . $this->_buildAppBlock() . "\n" . "\$zoom_config['events'] = array();\n\n" . $this->_buildPluginsBlock() . "?>\n";
     //echo $content;
     zmgimport('org.zoomfactory.lib.helpers.zmgFileHelper');
     return zmgFileHelper::write(ZMG_ABS_PATH . DS . 'etc' . DS . 'app.config.php', $content);
 }
 function getTemplates()
 {
     if (isset($this) && is_a($this, 'zmgTemplateHelper')) {
         return $this->throwError('This function may only be called statically!');
     }
     $basePath = ZMG_ABS_PATH . DS . 'var' . DS . 'www' . DS . 'templates';
     $baseConfig =& zmgFactory::getConfig()->get('smarty');
     zmgimport('org.zoomfactory.lib.helpers.zmgFileHelper');
     $dirs = zmgFileHelper::readDir($basePath, '[^index\\.html]');
     $tpls = array();
     foreach ($dirs as $dir) {
         if ($dir == "shared" || $dir == "admin") {
             continue;
             //TODO: catch this inside the regex above ('[^index\.html]')...
         }
         if (is_dir($basePath . DS . $dir) && zmgFileHelper::exists($basePath . DS . $dir . DS . 'manifest.xml')) {
             $baseConfig['activetemplate'] = $dir;
             $tpls[] = new zmgTemplateHelper($baseConfig, '', true);
         }
     }
     return $tpls;
 }
 function &getFTPClient()
 {
     $cfg = zmgFactory::getConfig()->get('plugins/safemode/credentials');
     zmgimport('org.zoomfactory.var.plugins.ftp.zmgFTP');
     return zmgFTP::getInstance($cfg['host'], $cfg['port'], array('root' => $cfg['root']), $cfg['user'], $cfg['pass']);
 }
 function toJSON()
 {
     $json =& zmgFactory::getJSON();
     $out = "'metadata': {\n          'mid': " . $this->_mid;
     if ($this->_raw === null || empty($this->_raw)) {
         return $out . ",'title': " . $json->encode(T_('No Metadata available.')) . "}";
     }
     zmgimport('org.zoomfactory.lib.mime.zmgMimeHelper');
     if (zmgMimeHelper::isImage($this->_ext)) {
         //TODO
         //print_r($this->_raw);
         if (empty($this->_raw['title'])) {
             $out .= ",'title': " . $json->encode(T_('No Metadata available.')) . "}";
         } else {
             $out .= ",\n                  'title' : " . $json->encode($this->_raw['title']);
             if (is_array($this->_raw['IFD'])) {
                 $out .= ",";
                 foreach ($this->_raw['IFD'] as $name => $exif_val) {
                     $out .= $this->interpretJpegMeta($name, $exif_val);
                 }
                 $out = substr($out, 0, -1);
             }
             $out .= "}";
         }
     } else {
         if (zmgMimeHelper::isAudio($this->_ext)) {
             list($artist, $title, $album, $year, $length, $data) = $this->interpretId3($this->_raw);
             $out .= ",\n              'title' : " . $json->encode($title) . "," . $json->encode(T_('Artist')) . ": " . $json->encode($artist) . "," . $json->encode(T_('Song')) . ": " . $json->encode($title) . "," . $json->encode(T_('Album')) . ": " . $json->encode($album) . "," . $json->encode(T_('Year')) . ": " . $json->encode($year) . "," . $json->encode(T_('Length')) . ": " . $json->encode($length) . "," . $json->encode(T_('Data')) . ": " . $json->encode($data) . "}";
         } else {
             if (zmgMimeHelper::isVideo($this->_ext)) {
                 //TODO
                 $out .= ",'title': " . $json->encode(T_('No Metadata available.')) . "}";
             }
         }
     }
     return $out;
 }
 /**
  * Deprecated: Load all available custom events from the /var/events folder.
  * Now only importing the zmgEvent class
  */
 function _load()
 {
     zmgimport('org.zoomfactory.lib.zmgEvent');
     //will be used later
 }
 function htmLawed($event)
 {
     $in = $event->getArgument('input');
     zmgimport('org.zoomfactory.var.plugins.htmlawed.htmLawed');
     return htmLawed($in, 1, array());
 }
 /**
  * Autodetect a file's MIME-type
  *
  * This function may be called staticly.
  *
  * @param  string $file        Path to the file to get the type of
  * @param  string $custom_mime An optional custom 'default' value, mostly used for the filetype sent by the users' browser
  * @param  bool   $params      Append MIME parameters if true
  * @return string $file's      MIME-type on success, false boolean otherwise
  * @since 1.0.0beta1
  * @static
  */
 function autoDetect($file, $custom_mime = null, $custom_ext = null, $params = false)
 {
     zmgimport('org.zoomfactory.lib.mime.zmgMimeHelper');
     $type = false;
     if (function_exists('finfo_open')) {
         // We have fileinfo
         $finfo = finfo_open(FILEINFO_MIME);
         $type = finfo_file($finfo, $file);
         finfo_close($finfo);
     } elseif (function_exists('mime_content_type')) {
         $type = mime_content_type($file);
         if (empty($type) && !empty($custom_ext)) {
             $type = zmgMimeHelper::convertExtensionToMime($custom_ext);
         }
     } elseif (!empty($custom_mime)) {
         $type = $custom_mime;
     } else {
         $type = zmgMime::_fileAutoDetect($file);
     }
     // _fileAutoDetect() may have returned an error.
     if ($type === false) {
         return $type;
     }
     if ($type == "application/octet-stream" || $type == "application/unknown") {
         if (!empty($custom_mime)) {
             $type = $custom_mime;
         } elseif (!empty($custom_ext)) {
             $type = zmgMimeHelper::convertExtensionToMime($custom_ext);
         }
     }
     if (!zmgMimeHelper::convertMimeToExtension($type)) {
         $type = zmgMimeHelper::convertExtensionToMime($custom_mime);
     }
     // flv (Flash Video format) files need exceptional handling (for now I'll provide a fictional mimetype)
     if ($custom_ext == "flv") {
         $type = "video/x-flv";
     }
     // Don't return an empty string
     if (!$type || !strlen($type)) {
         return zmgError::throwError("Sorry, couldn't determine file type.");
     }
     // Strip parameters if present & requested
     if (zmgMime::hasParameters($type) && !$params) {
         $type = zmgMime::stripParameters($type);
     }
     return $type;
 }
 /**
  * The class constructor.
  */
 function zmgViewHelper(&$smarty_cfg, $secret)
 {
     zmgimport('org.zoomfactory.lib.helpers.zmgTemplateHelper');
     $this->_template = new zmgTemplateHelper(&$smarty_cfg, $secret);
 }