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 run($view, $subview, $viewtype)
 {
     //mootools & Ajax preparing stuff
     $this->_type = $viewtype;
     if (!zmgEnv::isRPC()) {
         if ($this->_type == "html") {
             if (ZMG_ADMIN) {
                 $this->_buildAdminToolbar();
             }
             zmgEnv::includeMootools();
             $json =& zmgFactory::getJSON();
             $lifetime = zmgEnv::getSessionLifetime() * 60000;
             //in milliseconds
             //refresh time is 1 minute less than the lifetime assigned in the CMS configuration
             $refreshTime = $lifetime <= 60000 ? 30000 : $lifetime - 60000;
             $this->_constants = array_merge($this->_constants, array("req_uri" => "ZMG.CONST.site_uri + '" . zmgEnv::getAjaxURL() . "'", "res_path" => "ZMG.CONST.site_uri + '/components/com_zoom/var/www/templates/" . $this->_active_template . "'", "base_path" => "'" . zmgGetBasePath() . "'", "refreshtime" => $refreshTime, "sessionid" => $json->encode(zmgEnv::getSessionID()), "sessionname" => $json->encode(zmgEnv::getSessionName())));
             zmgEnv::appendPageHeader(zmgHTML::buildConstScript($this->_constants));
         }
     } else {
         if ($this->_type == "xml") {
             zmgFactory::getRequest()->sendHeaders('xml');
         }
     }
     if ($this->_type == "html") {
         //put the HTML headers in the head section of the parent (hosting) document
         $headers = $this->getHTMLHeaders(zmgEnv::getSiteURL() . '/components/com_zoom/var/www/templates', $this->_type);
         foreach ($headers as $header) {
             zmgEnv::appendPageHeader($header);
         }
     }
     //get template file that belongs to the active view:
     $res =& $this->_getResource('template', $view, $this->_type);
     if ($res) {
         $tpl_file = trim($res->firstChild->getAttribute('href'));
         zmgimport('org.zoomfactory.lib.helpers.zmgAPIHelper');
         $api = new zmgAPIHelper();
         $api->setParam('subview', $subview);
         $this->assign('zmgAPI', $api);
         //the API is accessible for all Smarty templates
         $this->assign('mediapath', $api->getParam('mediapath'));
         $this->display($tpl_file);
     } else {
         return $this->throwError('No template resource found. Unable to run application.');
     }
 }
 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>');
 }
 function getRpcURL()
 {
     return zmgEnv::getSiteURL() . zmgEnv::getAjaxURL();
 }