예제 #1
0
 /**
  * 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 _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);
             }
         }
     }
 }
 function dirDelete($event)
 {
     $path = $event->getArgument('path');
     $ftp =& zmgSafemodePlugin::getFTPClient();
     //Translate the destination path for the FTP account
     $path = zmgFileHelper::cleanPath(str_replace(zmgEnv::getRootPath(), $ftp->getRoot(), $path), '/');
     if (!$ftp->rmdir($path)) {
         // FTP connector throws an error
         return false;
     }
     return true;
 }
 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 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();
 }
예제 #7
0
 function getViewableFile($gallery_path, $smallthumb = false)
 {
     if (!$this->filename) {
         zmgError::throwError('zmgMedium: medium data not loaded yet');
     }
     $file = array('path' => $gallery_path, 'name' => null);
     $template_path = zmgEnv::getSiteURL() . "/components/com_zoom/var/www/templates/" . zmgFactory::getView()->getActiveTemplate() . "/images/mimetypes";
     if ($smallthumb) {
         $template_path .= "/small";
     }
     $ext = $this->getExtension();
     zmgimport('org.zoomfactory.lib.mime.zmgMimeHelper');
     if (zmgMimeHelper::isDocument($ext)) {
         $file['path'] = $template_path;
         if (strstr($ext, 'pdf')) {
             $file['name'] = "pdf.png";
         } else {
             $file['name'] = "doc.png";
         }
     } else {
         if (zmgMimeHelper::isVideo($ext)) {
             if (zmgMimeHelper::isThumbnailable($ext)) {
                 zmgimport('org.zoomfactory.lib.helpers.zmgFileHelper');
                 $filename = ereg_replace("(.*)\\.([^\\.]*)\$", "\\1", $this->filename) . ".jpg";
                 if (zmgFileHelper::exists(str_replace($this->filename, $filename, $this->getAbsPath(ZMG_MEDIUM_THUMBNAIL)))) {
                     $file['name'] = $filename;
                 }
             }
             if (!$file['name']) {
                 $file['path'] = $template_path;
                 $file['name'] = strstr('flv', $ext) ? "flv.png" : "video.png";
             }
         } else {
             if (zmgMimeHelper::isAudio($ext)) {
                 $file['path'] = $template_path;
                 $file['name'] = "audio.png";
             }
         }
     }
     return $file;
 }
예제 #8
0
 /**
  * Deletes log dir and its contents.
  *
  * @return void
  */
 function clean()
 {
     zmgFileHelper::deleteDir($this->_logDir);
 }
 /**
  * Chmods files and directories recursively to Zoom global permissions. Available from 1.0.0 up.
  * @param path The starting file or directory (no trailing slash)
  * @return TRUE=all succeeded FALSE=one or more chmods failed
  */
 function chmod($path)
 {
     $config =& zmgFactory::getConfig();
     $fileperms = octdec($config->get('filesystem/fileperms'));
     $dirperms = octdec($config->get('filesystem/dirperms'));
     if (isset($fileperms) || isset($dirperms)) {
         return zmgFileHelper::chmodRecursive($path, $fileperms, $dirperms);
     }
     return true;
 }
 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;
 }