/** * 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 process() { $gid = zmgGetParam($_REQUEST, 'zmg_edit_gallery_gid', 0); $isNew = false; if ($gid === "new") { $isNew = true; $gid = 0; } $gid = intval($gid); $events =& zmgFactory::getEvents(); $messages =& zmgFactory::getMessages(); $gallery = new zmgGallery(zmgDatabase::getDBO()); $res = true; if ($gid > 0) { if (!($res = $gallery->load($gid))) { $messages->append(T_('Gallery could not be saved') . ': ' . $gallery->getError()); } } if ($res && $gid > 0 || $isNew) { $data = array('name' => zmgSQLEscape(zmgGetParam($_REQUEST, 'zmg_edit_gallery_name', $gallery->name)), 'descr' => zmgSQLEscape(zmgGetParam($_REQUEST, 'zmg_edit_gallery_descr', $gallery->descr)), 'keywords' => zmgSQLEscape(zmgGetParam($_REQUEST, 'zmg_edit_gallery_keywords', $gallery->keywords)), 'hide_msg' => intval(zmgGetParam($_REQUEST, 'zmg_edit_gallery_hidenm', $gallery->hide_msg)), 'shared' => intval(zmgGetParam($_REQUEST, 'zmg_edit_gallery_shared', $gallery->shared)), 'published' => intval(zmgGetParam($_REQUEST, 'zmg_edit_gallery_published', $gallery->published)), 'uid' => intval(zmgGetParam($_REQUEST, 'zmg_edit_gallery_acl_gid', $gallery->uid))); if ($isNew) { $data['dir'] = zmgSQLEscape(zmgGetParam($_REQUEST, 'zmg_edit_gallery_dir', '')); } //do some additional validation of strings $data['name'] = $events->fire('onvalidate', false, $data['name']); $data['descr'] = $events->fire('onvalidate', false, $data['descr']); $data['keywords'] = $events->fire('onvalidate', false, $data['keywords']); if (!$gallery->bind($data)) { $messages->append(T_('Gallery could not be saved') . ': ' . $gallery->getError()); } else { if (!$gallery->store()) { $messages->append(T_('Gallery could not be saved') . ': ' . $gallery->getError()); } else { if ($isNew) { $gallery->buildDirStructure(); } $messages->append(T_('Gallery saved successfully!')); } } } else { $messages->append(T_('Gallery could not be saved') . ': ' . $gid); } }
function process() { $mid = intval(zmgGetParam($_REQUEST, 'zmg_edit_mid', 0)); $medium = new zmgMedium(zmgDatabase::getDBO()); $res = true; $events =& zmgFactory::getEvents(); $messages =& zmgFactory::getMessages(); if ($mid > 0) { if (!($res = $medium->load($mid))) { $messages->append(T_('Medium could not be saved') . ': ' . $medium->getError()); } } if ($res && $mid > 0) { $data = array('name' => zmgSQLEscape(zmgGetParam($_REQUEST, 'zmg_edit_name', $medium->name)), 'descr' => zmgSQLEscape(zmgGetParam($_REQUEST, 'zmg_edit_descr', $medium->descr)), 'keywords' => zmgSQLEscape(zmgGetParam($_REQUEST, 'zmg_edit_keywords', $medium->keywords)), 'shared' => intval(zmgGetParam($_REQUEST, 'zmg_edit_shared', $medium->shared)), 'published' => intval(zmgGetParam($_REQUEST, 'zmg_edit_published', $medium->published)), 'uid' => intval(zmgGetParam($_REQUEST, 'zmg_edit_acl_gid', $medium->uid))); //do some additional validation of strings $data['name'] = $events->fire('onvalidate', false, $data['name']); $data['descr'] = $events->fire('onvalidate', false, $data['descr']); $data['keywords'] = $events->fire('onvalidate', false, $data['keywords']); if (!$medium->bind($data)) { $messages->append(T_('Medium could not be saved') . ': ' . $medium->getError()); } else { if (!$medium->store()) { $messages->append(T_('Medium could not be saved') . ': ' . $medium->getError()); } else { $isGalleryImg = intval(zmgGetParam($_REQUEST, 'zmg_edit_gimg', 0)) === 1; $isParentImg = intval(zmgGetParam($_REQUEST, 'zmg_edit_pimg', 0)) === 1; if (!($isGalleryImg && $medium->setAsGalleryImage())) { $messages->append(T_('Medium could not be saved') . ': ' . T_('unable to set as image of gallery')); $res = false; } if (!($isParentImg && $medium->setAsGalleryImage(true))) { $messages->append(T_('Medium could not be saved') . ': ' . T_('unable to set as image of parent gallery')); $res = false; } if ($res) { $messages->append(T_('Medium saved successfully!')); } } } } else { $messages->append(T_('Medium could not be saved') . ': ' . $mid); } }
function getMediumCount() { if ($this->_medium_count === null) { $db =& zmgDatabase::getDBO(); $table = zmgFactory::getConfig()->getTableName('media'); $db->setQuery("SELECT COUNT(mid) FROM " . $table . " WHERE gid = " . $this->gid . " LIMIT 1"); $this->_medium_count = intval($db->loadResult()); } return $this->_medium_count; }
function getMedium($mid, $ret_type = 'object') { $mid = intval($mid); $medium = new zmgMedium(zmgDatabase::getDBO()); $medium->load($mid); if ($ret_type == "json") { return $medium->toJSON(); } else { if ($ret_type == "xml") { return $medium->toXML(); } } return $medium; }
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(); }
/** * Get the comments a medium contains. * * @return void * @access public */ function getComments() { $comments = array(); $db =& zmgDatabase::getDBO(); $table = zmgFactory::getConfig()->getTableName('comments'); $db->setQuery("SELECT cid FROM " . $table . " WHERE mid = " . $this->mid . " ORDER BY date_added ASC"); $_result = $db->loadObjectList(); foreach ($_result as $row) { $comment = new zmgComment($db); $comment->load(intval($row->cmtid)); $comments[] = $comment; } return $comments; }
function getMediaFromRequest() { $token = zmgAPIHelper::getViewToken(); //'last' by default $db =& zmgDatabase::getDBO(); $tokens = explode(',', $token); //will return an array, no matter how many commas $media = array(); foreach ($tokens as $mid) { $medium = new zmgMedium($db); $medium->load($mid); $media[] = $medium; //push } return $media; }
/** * Checks if a user has the right to edit a medium, or if he/ she already * edited the medium before. * * @param int $id * @param string $which * @param string $filename * @return boolean * @access public */ function isEdited($id, $which, $filename = '') { $db =& zmgDatabase::getDBO(); $table = zmgFactory::getConfig()->getTableName('editmon'); $today = time() + intval(zmgEnv::getSessionLifetime()); $sid = md5(zmgEnv::getSessionToken()); switch ($which) { case 'comment': $db->setQuery("SELECT edtid FROM " . $table . " WHERE " . "user_session = '{$sid}' AND comment_time > '{$now}' AND " . "object_id = " . zmgSQLEscape($id)); break; case 'vote': $db->setQuery("SELECT edtid FROM " . $table . " WHERE " . "user_session = '{$sid}' AND vote_time > '{$now}' AND " . "object_id = " . zmgSQLEscape($id)); break; case 'pass': $db->setQuery("SELECT edtid FROM " . $table . " WHERE " . "user_session = '{$sid}' AND pass_time > '{$now}' AND " . "object_id = " . zmgSQLEscape($id)); break; case 'lightbox': $db->setQuery("SELECT edtid FROM " . $table . " WHERE " . "user_session = '{$sid}' AND lightbox_time > '{$now}' AND " . "lightbox_file = '" . zmgSQLEscape($filename) . "'"); break; } $result = $db->query(); if (mysql_num_rows($result) > 0) { return true; } else { return false; } }