function zmgAPIHelper() { $config =& zmgFactory::getConfig(); $this->site_url = zmgEnv::getSiteURL(); $this->ajax_url = zmgEnv::getAjaxURL(); $this->rpc_url = zmgEnv::getRpcURL(); $this->mediapath = $config->get('filesystem/mediapath'); $this->result_ok = _ZMG_RPC_RESULT_OK; $this->result_ko = _ZMG_RPC_RESULT_KO; }
/** * Function to strip additional / or \ in a path name * * @static * @param string $path The path to clean * @param string $ds Directory separator (optional) * @return string The cleaned path * @since 1.5 */ function cleanPath($path, $ds = DS) { $path = trim($path); if (empty($path)) { $path = zmgEnv::getRootPath(); } else { // Remove double slashes and backslahses and convert all slashes and backslashes to DS $path = preg_replace('#[/\\\\]+#', $ds, $path); } return $path; }
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; }
/** * Extract the raw text from a PDF document (format: '{filename}.txt') with the Xpdf library (pdftotext) * * @param string $file * @param string $filename * @return boolean */ function process(&$medium, &$gallery) { // this function will contain the algorithm to index a document (like a pdf)... // Method: use PDFtoText to create a plain ASCII text-file, which can be easily // searched through. The text-file will be placed into the same dir as the // original pdf. // Note: support for MS Word, Excel and Powerpoint indexing will be added later. $file = $medium->getAbsPath(); $filename = ereg_replace("(.*)\\.([^\\.]*)\$", "\\1", $medium->filename) . ".txt"; $target_file = zmgEnv::getRootPath() . DS . zmgFactory::getConfig()->get('filesystem/mediapath') . $gallery->dir . DS . $filename; $cmd = zmgDocumentTool::getPath() . "pdftotext \"{$file}\" \"{$target_file}\""; $output = $retval = null; exec($cmd, $output, $retval); if ($retval) { return zmgToolboxPlugin::registerError($file, 'Xpdf: Could not index document: ' . $output); } return true; }
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 run() { if (empty($this->_active_view)) { return $this->throwError('No active view specified. Unable to run application.'); } if (zmgEnv::isRPC() && $this->_active_view == "ping") { zmgFactory::getRequest()->sendHeaders($this->_viewtype); echo " "; return; } $this->_template->run($this->_active_view, $this->getSubView(), $this->_viewtype); }
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(); }
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; }
function includeMootools() { zmgEnv::appendPageHeader('<script src="' . zmgEnv::getSiteURL() . '/components/com_zoom/var/www/shared/mootools.js" type="text/javascript"></script>'); }
/** * Custom callback for ZMG error handling (taking RPC calls into account) * * @access public */ function zmgErrorCallback($error) { if (zmgEnv::isRPC()) { zmgFactory::getMessages()->append($error['message'], $error['backtrace']); return; } zmgBacktrace(); trigger_error($error['message'], $error['level']); }
function getRpcURL() { return zmgEnv::getSiteURL() . zmgEnv::getAjaxURL(); }
//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');
/** * 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; } }
function _buildAdminToolbar() { if (!ZMG_ADMIN) { return $this->throwError('Function may only be called in admin mode.'); } $assets = zmgEnv::getToolbarAssets(); zmgCallAbstract($assets['classHelper'], $assets['commands']['title'], zmgFactory::getConfig()->get('meta/title')); zmgCallAbstract($assets['classHelper'], $assets['commands']['back']); zmgCallAbstract($assets['classHelper'], $assets['commands']['spacer']); $this->appendConstant('toolbar_node', '"' . $assets['node'] . '"'); $this->appendConstant('toolbar_buttonclass', '"' . $assets['classButton'] . '"'); }