コード例 #1
0
 /**
  * Recieves the string you want lo log. This function is used by "logThis"
  * function, which offers simplified logging with some practical functions.
  *
  * @param String $logString
  * @return void
  */
 function writeLog($logString)
 {
     global $logNumber;
     //depending on selected log mode...
     //use only one log file, or one file per log instance
     $logFile = $this->_logDir . DS . $this->_logFile . ".log";
     if ($this->_logMode == "oneFilePerLog") {
         $logFile = $this->_logDir . DS . $this->_logFile . $this->_logNumber . ".log";
     }
     //in case file does not exist
     if (!zmgFileHelper::exists($logFile)) {
         //if log file does not exist, I create it
         touch($logFile);
         //generate file header
         $logHeader = $this->_headerTitle . "\n" . "--------------------------------------------------------------------\n" . "--------------------------------------------------------------------\n\n\n";
         $fp = fopen($logFile, "w+");
         if (fwrite($fp, $logHeader) === false) {
             zmgError::throwError("Could not write LOG Header");
         }
         fclose($fp);
     }
     //write to log file
     $fp = fopen($logFile, "a");
     if (fwrite($fp, $logString) === false) {
         zmgError::throwError("Could not write to LOG file");
     }
     fclose($fp);
 }
コード例 #2
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.');
     //}
 }
コード例 #3
0
 /**
  * Check if a file is within the filesize limits, set by the administrator.
  * @return boolean
  * @param string $file
  * @access public
  */
 function tooBig($file)
 {
     if (zmgFileHelper::exists($file)) {
         $config =& zmgFactory::getConfig();
         $size = intval(filesize($file) / 1024);
         if ($size <= intval($config->get('filesystem/upload/maxfilesize'))) {
             return false;
         } else {
             return true;
         }
     } else {
         return false;
     }
 }
コード例 #4
0
 function firstRun()
 {
     // do the check again, for safety reasons:
     if ($this->_config['date_lch'] !== null) {
         $this->_installed = true;
         return zmgError::throwError('Illegal way of accessing firstRun');
     }
     zmgimport('org.zoomfactory.lib.helpers.zmgFileHelper');
     if (zmgFileHelper::exists(ZMG_ABS_PATH . DS . 'etc' . DS . 'app.config.php.bak')) {
         $this->_installed = true;
         return zmgError::throwError('Illegal access: component already installed.');
     }
     $messages =& zmgFactory::getMessages();
     $html_file = "<html><body bgcolor=\"#FFFFFF\"></body></html>";
     //make all the necessary folders writable for ZMG
     $config_dir = ZMG_ABS_PATH . DS . "etc";
     if (!zmgFileHelper::chmodRecursive($config_dir)) {
         $messages->append('Installation Error!', 'Unable to set directory permissions for: ' . $config_dir);
     }
     //make sure the configuration file itself is writable
     if (!zmgFileHelper::chmodRecursive($config_dir . DS . 'app.config.php')) {
         $messages->append('Installation Error!', 'Unable to set file permissions for: ' . $config_dir . DS . 'app.config.php');
     }
     $media_dir = zmgEnv::getRootPath() . DS . $this->get('filesystem/mediapath');
     if (!is_dir($media_dir)) {
         if (zmgFileHelper::createDir($media_dir)) {
             if (!zmgFileHelper::write($media_dir . DS . 'index.html', $html_file)) {
                 $messages->append('Installation Error!', 'Unable to write to file: ' . $media_dir . DS . 'index.html');
             }
         } else {
             $messages->append('Installation Error!', 'Unable to create directory: ' . $media_dir);
         }
     }
     //backup the original config file that came with the distribution package
     if (!zmgFileHelper::copy('app.config.php', 'app.config.php.bak', ZMG_ABS_PATH . DS . 'etc')) {
         $messages->append('Installation Error!', 'Unable to copy file: ' . ZMG_ABS_PATH . DS . 'etc' . DS . 'app.config.php');
     }
     $this->_installed = $this->save();
     if ($this->_installed) {
         $messages->append('Installation Success!', 'Your component is ready to use now.');
     } else {
         $messages->append('Installation Error!', 'Settings could not be saved.');
     }
     return $this->_installed;
 }
コード例 #5
0
 function upload($method)
 {
     $zoom =& zmgFactory::getEvents()->fire('ongetcore');
     zmgimport('org.zoomfactory.lib.helpers.zmgFileHelper');
     zmgimport('org.zoomfactory.lib.mime.zmgMimeHelper');
     if ($method == "jupload") {
         echo "JUpload!!!";
     } else {
         $file = zmgGetParam($_FILES, 'Filedata');
         $filename = $zoom->checkDuplicate(zmgFileHelper::makeSafe(urldecode($file['name'])));
         $ext = zmgFileHelper::getExt($filename);
         $mime = zmgMimeHelper::getMime($file['tmp_name'], $file['type'], $ext);
         if (zmgFileHelper::tooBig($file['tmp_name'])) {
             header('HTTP/1.0 415 Unsupported Media Type');
             die('Error. File too big!');
         }
         if (!zmgMimeHelper::acceptableFormat($mime, true)) {
             header('HTTP/1.0 415 Unsupported Media Type');
             die('Error. Unsupported Media Type!');
         }
         //try to move the file to a proper location:
         $dest = ZMG_ABS_PATH . DS . "etc" . DS . "cache" . DS . $filename;
         if (zmgFileHelper::exists($dest)) {
             header('HTTP/1.0 409 Conflict');
             die('Error. File already exists');
         }
         if (!zmgFileHelper::upload($file['tmp_name'], $dest)) {
             header('HTTP/1.0 400 Bad Request');
             die('Error. Unable to upload file');
         }
         // store the filename into the session (the data is sent to the backend
         // after the file has been uploaded).
         $session =& zmgFactory::getSession();
         $session->update('uploadtool.fancyfiles', $filename, ZMG_DATATYPE_ARRAY);
         $session->store();
     }
 }
コード例 #6
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;
 }
コード例 #7
0
 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;
 }