/**
  * Send a set of headers to the client (i.e. browser) to tell it how to display
  * the data inside the response body.
  * @param string Specifies the contect type of the response body
  * @param boolean In case of an error message, this var will be set to TRUE
  * @param string Message describing the error in case of an error
  */
 function sendHeaders($type = "xml", $error = false, $error_msg = "")
 {
     //using 'echo @header()', because that seems to implicitely work in some
     //WAMP environments. Why? Pfff, beats me.
     echo @header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     //HTTP/1.1
     echo @header("Cache-Control: no-store, no-cache, must-revalidate");
     echo @header("Cache-Control: post-check=0, pre-check=0", false);
     //HTTP/1.0
     echo @header("Pragma: no-cache");
     $encoding = zmgFactory::getConfig()->get('locale/encoding');
     if (empty($encoding)) {
         $encoding = "UTF-8";
     }
     if ($error) {
         echo @header("zmg_result: " . _ZMG_RPC_RESULT_KO);
         echo @header("zmg_message: " . urlencode($error_msg));
     } else {
         echo @header("zmg_result: " . _ZMG_RPC_RESULT_OK);
     }
     if ($type == "xml") {
         echo @header("Content-type:text/xml; charset=" . $encoding);
     } else {
         if ($type == "plain") {
             echo @header("Content-type:text/plain; charset=" . $encoding);
         } else {
             if ($type == "js" || $type == "json") {
                 echo @header("Content-type:text/javascript; charset=" . $encoding);
             }
         }
     }
 }
 function process(&$medium, &$gallery)
 {
     $ok = true;
     //innocent, until proven guilty ;)
     $events =& zmgFactory::getEvents();
     $config =& zmgFactory::getConfig();
     $imagetools =& zmgToolboxConstants::getImageTools();
     $toolkey = intval($config->get('plugins/toolbox/general/conversiontool'));
     $imagetool = $imagetools[$toolkey - 1];
     zmgimport('org.zoomfactory.var.plugins.toolbox.tools.' . $imagetool . 'Tool');
     $klass = 'zmg' . ucfirst($imagetool) . 'Tool';
     $file = $medium->getAbsPath();
     $size = getimagesize($file);
     $img_meta = array('width' => $size[0], 'height' => $size[1], 'extension' => $medium->getExtension(), 'jpeg_qty' => $config->get('plugins/toolbox/general/jpegquality'));
     $metadata = $events->fire('ongetimagemetadata', false, $medium);
     //rotate image
     //TODO
     //resize to thumbnail
     if ($ok && !file_exists($medium->getAbsPath(ZMG_MEDIUM_THUMBNAIL))) {
         $ok = call_user_func_array(array($klass, 'resize'), array($file, $medium->getAbsPath(ZMG_MEDIUM_THUMBNAIL), intval($config->get('plugins/toolbox/general/imagesizethumbnail')), $img_meta));
     }
     //resize to viewsize format
     $maxSize = intval($config->get('plugins/toolbox/general/imagesizemax'));
     if ($ok && !file_exists($medium->getAbsPath(ZMG_MEDIUM_VIEWSIZE)) && ($img_meta['width'] > $maxSize || $img_meta['height'] > $maxSize)) {
         $ok = call_user_func_array(array($klass, 'resize'), array($file, $medium->getAbsPath(ZMG_MEDIUM_VIEWSIZE), intval($config->get('plugins/toolbox/general/imagesizethumbnail')), $img_meta));
     }
     //apply watermarks
     //TODO
     if ($ok) {
         $ok = $events->fire('onputimagemetadata', false, $medium, $metadata);
     }
     return $ok;
 }
 function shutDown()
 {
     $messages =& zmgFactory::getMessages();
     $session =& zmgFactory::getSession();
     $session->put('zmg.messagecenter.cache', $messages->getAll(), true);
     $session->store();
 }
 function embed()
 {
     $settings_file = ZMG_ABS_PATH . DS . 'var' . DS . 'plugins' . DS . 'getid3' . DS . 'settings.xml';
     if (file_exists($settings_file)) {
         $plugins =& zmgFactory::getPlugins();
         $plugin =& $plugins->get('getid3');
         $plugins->embedSettings(&$plugin, $settings_file);
     }
 }
 function storeDelegate(&$event)
 {
     $aView = $event->getArgument('view');
     $view = implode(':', $aView);
     $config =& zmgFactory::getConfig();
     $events =& zmgFactory::getEvents();
     $request =& zmgFactory::getRequest();
     switch ($view) {
         case "admin:settings:store":
             $request->setResult($config->update($_POST, false));
             break;
         case stristr($view, "admin:settings:plugins:autodetect"):
             $tool = trim($aView[count($aView) - 1]);
             if ($tool == "autodetect") {
                 $tool = "all";
             } else {
                 $tool = array($tool);
             }
             $events->fire('onautodetect', false, $tool);
             break;
         case stristr($view, "admin:update:mediacount"):
             $filter = intval(array_pop($aView));
             $zoom =& zmgFactory::getEvents()->fire('ongetcore');
             $request->setResult($zoom->getMediumCount($filter));
             break;
         case "admin:galleryedit:store":
             zmgimport('org.zoomfactory.var.plugins.datastore.stores.galleryStore');
             zmgGalleryStore::process();
             break;
         case "admin:galleryedit:delete":
             zmgimport('org.zoomfactory.var.plugins.datastore.stores.galleryStore');
             zmgGalleryStore::delete();
             break;
         case "admin:mediumedit:store":
             zmgimport('org.zoomfactory.var.plugins.datastore.stores.mediumStore');
             zmgMediumStore::process();
             break;
         case stristr($view, "admin:mediaupload:store"):
             //SWFUpload needs HTTP headers to signal the user...
             $method = stristr($view, "jupload") ? "jupload" : "swfupload";
             $events->fire('onupload', false, $method);
             //exit;
             break;
         case stristr($view, "admin:mediaupload:update"):
             $gid = array_pop($aView);
             $events->fire('onuploadupdate', false, $gid);
             break;
         case stristr($view, "admin:update:mediacount"):
             $gid = intval(array_pop($aView));
             $zoom =& zmgFactory::getEvents()->fire('ongetcore');
             echo $zoom->getMediumCount($gid);
             break;
         default:
             break;
     }
 }
 function getPath()
 {
     $config =& zmgFactory::getConfig();
     $path = trim($config->get('plugins/toolbox/pdftotext/path'));
     $override = intval($config->get('plugins/toolbox/pdftotext/override'));
     if ($path == "auto") {
         $path = zmgDocumentTool::detectPath();
     }
     return $path;
 }
 function getPath()
 {
     $config =& zmgFactory::getConfig();
     $path = trim($config->get('plugins/toolbox/ffmpeg/path'));
     $override = intval($config->get('plugins/toolbox/ffmpeg/override'));
     if ($path == "auto") {
         $path = zmgVideoTool::detectPath();
     }
     return $path;
 }
 function getImageMetadata($event)
 {
     $medium = $event->getArgument('medium');
     $data = array('headers' => null, 'exif' => null, 'xmp' => null, 'irb' => null, 'finfo' => null);
     $ext = $medium->getExtension();
     $file = $medium->getAbsPath();
     if (zmgFactory::getConfig()->get('plugins/jpeg_metadata/general/readwrite') && ($ext == "jpg" || $ext == "jpeg") && !ZMG_SAFEMODE_ON) {
         //import libs first (duh ;) )
         $jmt_dir = "v" . str_replace('.', '_', ZMG_JMT_VERSION);
         zmgimport('org.zoomfactory.var.plugins.jpeg_metadata.' . $jmt_dir . '.EXIF');
         //takes care of some deferred loading as well
         zmgimport('org.zoomfactory.var.plugins.jpeg_metadata.' . $jmt_dir . '.Photoshop_File_Info');
         // Retreive the EXIF, XMP and Photoshop IRB information from
         // the existing file, so that it can be updated later on...
         $data['headers'] = get_jpeg_header_data($file);
         $data['exif'] = get_EXIF_JPEG($file);
         $data['xmp'] = read_XMP_array_from_text(get_XMP_text($data['headers']));
         $data['irb'] = get_Photoshop_IRB($data['headers']);
         $data['finfo'] = get_photoshop_file_info($data['exif'], $data['xmp'], $data['irb']);
         // Check if there is a default for the date defined
         if (!array_key_exists('date', $data['finfo']) || array_key_exists('date', $data['finfo']) && $data['finfo']['date'] == '') {
             // No default for the date defined
             // figure out a default from the file
             // Check if there is a EXIF Tag 36867 "Date and Time of Original"
             if ($data['exif'] != false && array_key_exists(0, $data['exif']) && array_key_exists(34665, $data['exif'][0]) && array_key_exists(0, $data['exif'][0][34665]) && array_key_exists(36867, $data['exif'][0][34665][0])) {
                 // Tag "Date and Time of Original" found - use it for the default date
                 $data['finfo']['date'] = $data['exif'][0][34665][0][36867]['Data'][0];
                 $data['finfo']['date'] = preg_replace("/(\\d\\d\\d\\d):(\\d\\d):(\\d\\d)( \\d\\d:\\d\\d:\\d\\d)/", "\$1-\$2-\$3", $data['finfo']['date']);
             } elseif ($data['exif'] != false && array_key_exists(0, $data['exif']) && array_key_exists(34665, $data['exif'][0]) && array_key_exists(0, $data['exif'][0][34665]) && array_key_exists(36868, $data['exif'][0][34665][0])) {
                 // Check if there is a EXIF Tag 36868 "Date and Time when Digitized"
                 // Tag "Date and Time when Digitized" found - use it for the default date
                 $data['finfo']['date'] = $data['exif'][0][34665][0][36868]['Data'][0];
                 $data['finfo']['date'] = preg_replace("/(\\d\\d\\d\\d):(\\d\\d):(\\d\\d)( \\d\\d:\\d\\d:\\d\\d)/", "\$1-\$2-\$3", $data['finfo']['date']);
             } else {
                 if ($data['exif'] != false && array_key_exists(0, $data['exif']) && array_key_exists(306, $data['exif'][0])) {
                     // Check if there is a EXIF Tag 306 "Date and Time"
                     // Tag "Date and Time" found - use it for the default date
                     $data['finfo']['date'] = $data['exif'][0][306]['Data'][0];
                     $data['finfo']['date'] = preg_replace("/(\\d\\d\\d\\d):(\\d\\d):(\\d\\d)( \\d\\d:\\d\\d:\\d\\d)/", "\$1-\$2-\$3", $data['finfo']['date']);
                 } else {
                     // Couldn't find an EXIF date in the image
                     // Set default date as creation date of file
                     $data['finfo']['date'] = date("Y-m-d", filectime($file));
                 }
             }
         }
     }
     return zmgJpeg_metadataPlugin::interpretImageData($data, $medium->filename);
 }
 /**
  * Launch all components that are bound to a specific custom event handler.
  *
  * @param string The name of the event that is fired
  * @param bool The event may or may not bubble down
  * @return mixed
  */
 function fire($type, $nobubble = false)
 {
     $event = new zmgEvent($type);
     $args = func_get_args();
     $newArgs = array_splice($args, 2, count($args));
     if (count($newArgs) == 1) {
         $newArgs = $newArgs[0];
     }
     $event->pass($newArgs);
     //bubble through to plugins:
     if (!(bool) $nobubble) {
         $plugins =& zmgFactory::getPlugins();
         return $plugins->bubbleEvent($event);
     }
 }
 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);
     }
 }
 /**
  * Create a HTML dropdown form element which contains a list of galleries
  * (ordered and indented).
  * @param mixed $onchange 
  * @param string $sel_name
  * @param int $sel
  * @param int $exclude
  * @return void
  */
 function galleriesSelect($onchange = 0, $sel_name = "gid", $sel = 0, $exclude = 0)
 {
     $html = "<select name=\"{$sel_name}\" id=\"{$sel_name}\" class=\"inputbox\"";
     if ($onchange !== 0) {
         $html .= " onchange=\"{$onchange}\"";
     }
     $html .= ">\n\t<option value=\"0\">---&nbsp;" . T_('Select a Gallery') . "&nbsp;---</option>\n";
     $zoom =& zmgFactory::getEvents()->fire('ongetcore');
     $galleries =& $zoom->getGalleryList();
     if (isset($galleries)) {
         foreach ($galleries as $set) {
             $gallery = $set['object'];
             if ($gallery->gid != $exclude || $exclude == 0) {
                 $html .= "\t<option value=\"" . $gallery->gid . "\"" . ($sel == $gallery->gid ? " selected" : "") . ">" . $set['path_name'] . "</option>\n";
             }
         }
     }
     echo $html . "</select>\n";
 }
 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);
     }
 }
 /**
  * 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 toJSON()
 {
     $json =& zmgFactory::getJSON();
     return "'gallery': {\n            'gid'         : {$this->gid},\n            'name'        : " . $json->encode($this->name) . ",\n            'descr'       : " . $json->encode($this->descr) . ",\n            'cover_img'   : " . $json->encode($this->getCoverImage()) . ",\n            'dir'         : " . $json->encode($this->dir) . ",\n            'keywords'    : " . $json->encode($this->keywords) . ",\n            'sub_gid'     : {$this->sub_gid},\n            'pos'         : {$this->pos},\n            'hide_msg'    : {$this->hide_msg},\n            'shared'      : {$this->shared},\n            'published'   : {$this->published},\n            'uid'         : {$this->uid},\n            'ordering'    : {$this->ordering},\n            'medium_count': " . $this->getMediumCount() . ",\n            'members'     : " . $json->encode($this->members) . "\n        }";
 }
/**
 * Smarty block function, provides gettext support for smarty.
 *
 * The block content is the text that should be translated.
 *
 * Any parameter that is sent to the function will be represented as %n in the translation text, 
 * where n is 1 for the first parameter. The following parameters are reserved:
 *   - escape - sets escape mode:
 *       - 'html' for HTML escaping, this is the default.
 *       - 'js' for javascript escaping.
 *       - 'url' for url escaping.
 *       - 'no'/'off'/0 - turns off escaping
 *   - plural - The plural version of the text (2nd parameter of ngettext())
 *   - count - The item count for plural mode (3rd parameter of ngettext())
 */
function smarty_block_t($params, $text, &$smarty)
{
    $text = stripslashes($text);
    // set escape mode
    if (isset($params['escape'])) {
        $escape = $params['escape'];
        unset($params['escape']);
    }
    // set plural version
    if (isset($params['plural'])) {
        $plural = $params['plural'];
        unset($params['plural']);
        // set count
        if (isset($params['count'])) {
            $count = $params['count'];
            unset($params['count']);
        }
    }
    // use plural if required parameters are set
    if (isset($count) && isset($plural)) {
        $text = T_ngettext($text, $plural, $count);
    } else {
        // use normal
        $text = T_gettext($text);
    }
    // run strarg if there are parameters
    if (count($params)) {
        $text = smarty_gettext_strarg($text, $params);
    }
    if (!isset($escape) || $escape == 'html') {
        // html escape, default
        $text = nl2br(htmlspecialchars($text));
    } elseif (isset($escape)) {
        switch ($escape) {
            case 'javascript':
            case 'js':
            case 'json':
                // javascript escape {12-12-2007, mike: modified for JSON support in ZMG}
                $json =& zmgFactory::getJSON();
                $text = $json->encode($text);
                break;
            case 'url':
                // url escape
                $text = urlencode($text);
                break;
        }
    }
    return $text;
}
 function embedHTML()
 {
     $config =& zmgFactory::getConfig();
     $out = "<div id=\"zmg_plugins_accordion\" class=\"zmg_halfsize\">\n";
     foreach ($this->_plugins as $plugin) {
         $name = $plugin['settings_name'];
         $settings = $plugin['settings'];
         if (is_array($settings)) {
             $out .= "<div class=\"zmg_accordion_panel\">\n" . "<h3 class=\"zmg_accordion_toggler zmg_accordion_start\">" . T_($name) . "</h3>\n" . "<div class=\"zmg_accordion_element zmg_accordion_start\">\n";
             foreach ($settings as $cat => $sub_settings) {
                 $out .= "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n" . "<tr>\n" . "\t<td colspan\"2\">\n" . "\t\t<h3>" . T_(ucfirst($cat)) . "</h3>\n" . "\t</td>\n" . "</tr>\n";
                 foreach ($sub_settings as $setting => $data) {
                     $setting_parts = array('plugins', $plugin['name'], $cat, $setting);
                     $setting_value = $config->get(implode('/', $setting_parts));
                     $input_name = "zmg_" . implode('_', $setting_parts);
                     $out .= "<tr>\n";
                     switch ($data['type']) {
                         case "checkbox":
                             $out .= "\t\t<td width=\"250\">" . T_($data['label']) . "</td><td>";
                             $checked = $setting_value == $data['value'] ? true : false;
                             $out .= $this->_buildCheckboxInput($input_name, $data['value'], $checked) . "</td>\n";
                             break;
                         case "radio":
                             $out .= "\t\t<td width=\"250\">" . T_($data['label']) . "</td><td>";
                             $checked = $setting_value == $data['value'] ? true : false;
                             $out .= $this->_buildRadioInput($input_name, $data['value'], $checked) . "</td>\n";
                             break;
                         case "select":
                             $options = array();
                             foreach ($data as $key => $value) {
                                 if (stristr($key, 'option')) {
                                     $options[] = $value;
                                 }
                             }
                             $out .= "\t\t<td width=\"250\">" . T_($data['label']) . "</td><td>" . $this->_buildSelectInput($input_name, $options, $setting_value) . "</td>\n";
                             break;
                         case "text":
                         case "password":
                             $out .= "\t\t<td width=\"250\">" . T_($data['label']) . "</td><td>" . $this->_buildTextInput($input_name, $setting_value, $data['type'], $data['size']) . "</td>\n";
                             break;
                     }
                     $out .= "</tr>\n";
                 }
                 $out .= "</table>\n";
             }
             $out .= "</div>\n</div>\n";
         } else {
             //$out .= T_('No settings found for this plugin.');
         }
     }
     return $out . "</div>\n";
 }
 function toJSON()
 {
     $json =& zmgFactory::getJSON();
     return "'comment': {\n            'cid'      : {$this->cid},\n            'mid'      : {$this->mid},\n            'name'     : " . $json->encode($this->name) . ",\n            'content'  : " . $json->encode($this->getContent()) . ",\n            'date_add' : " . $json->encode($this->getDate()) . "\n        }";
 }
<?php

/**
 * zOOm Media Gallery! - a multi-gallery component 
 * 
 * @package zmg
 * @version $Revision$
 * @author Mike de Boer <mike AT zoomfactory.org>
 * @copyright Copyright &copy; 2007, Mike de Boer. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GPL
 */
//list of global constants:
define("_ZMG_EXEC", 1);
define("ZMG_ABS_PATH", preg_replace('#[/\\\\]+administrator#', '', dirname(__FILE__)));
define("ZMG_ADMIN", 1);
//load all required libraries
include ZMG_ABS_PATH . '/lib/initzoom.php';
$view =& zmgFactory::getView();
$events =& zmgFactory::getEvents();
$view->setAndRun();
$events->fire('onfinish');
 function throwError($message)
 {
     if (true) {
         //!zmgEnv::isRPC()) {
         return zmgError::throwError($message);
     } else {
         return zmgFactory::getRequest()->sendHeaders($this->_viewtype, true, $message);
     }
 }
include 'zmgFunctions.php';
//make the object factory available for all other classes
zmgimport('org.zoomfactory.lib.zmgFactory');
//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');
 function &getFTPClient()
 {
     $cfg = zmgFactory::getConfig()->get('plugins/safemode/credentials');
     zmgimport('org.zoomfactory.var.plugins.ftp.zmgFTP');
     return zmgFTP::getInstance($cfg['host'], $cfg['port'], array('root' => $cfg['root']), $cfg['user'], $cfg['pass']);
 }
 function _toJSON($msg)
 {
     $json =& zmgFactory::getJSON();
     return "{\n            'title'    : " . $json->encode($msg[0]) . ",\n            'descr'    : " . $json->encode($msg[1]) . "\n        }";
 }
/**
 * 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 update($vars, $isPlugin = false)
 {
     $updated = false;
     if (!$isPlugin) {
         foreach ($vars as $config => $value) {
             $config = trim($config);
             if (strstr($config, 'zmg_')) {
                 $real = str_replace('_', '/', str_replace('zmg_', '', $config));
                 if ($this->set($real, zmgSQLEscape(trim($value)))) {
                     $updated = true;
                 }
             }
         }
     } else {
         echo "updating plugin config..";
         $keys = array_keys($vars);
         if (!$this->_config['plugins'][$keys[0]]) {
             array_merge($this->_config, $vars);
             print_r($this->_config);
             $updated = true;
         }
     }
     $messages =& zmgFactory::getMessages();
     if ($updated) {
         if ($this->save()) {
             $messages->append(T_('Settings'), T_('Your settings have been saved successfully.'));
             return true;
         }
     }
     $messages->append(T_('Settings'), T_('Your settings could not be saved.'));
     return false;
 }
 function getActiveTemplate()
 {
     return zmgFactory::getView()->getActiveTemplate();
 }
 /**
  * Return the method of ordering for media.
  * @return string
  * @access public
  */
 function getMediaOrdering()
 {
     $methods = array("", "date_add ASC", "date_add DESC", "filename ASC", "filename DESC", "name ASC", "name DESC");
     return $methods[intval(zmgFactory::getConfig()->get('layout/ordering/media'))];
 }
 /**
  * Public variable, containing the zmgViewHelper - helping ZMG with controlling
  * the views on the different models that the Core exposes.
  *
  * @return zmgViewHelper
  */
 function &getView()
 {
     static $instance_view;
     if (!is_object($instance_view)) {
         zmgimport('org.zoomfactory.lib.helpers.zmgViewHelper');
         $config =& zmgFactory::getConfig();
         $instance_view = new zmgViewHelper($config->get('smarty'), $config->get('app/secret'));
     }
     return $instance_view;
 }
 function throwErrors()
 {
     $errors =& zmgToolboxPlugin::getErrors();
     for ($i = 0; $i < count($errors); $i++) {
         zmgFactory::getMessages()->append($errors[$i]['title'], $errors[$i]['description']);
     }
     //reset the process of collecting errors
     $errors = null;
 }
 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 toJSON()
 {
     $json =& zmgFactory::getJSON();
     $out = "'metadata': {\n          'mid': " . $this->_mid;
     if ($this->_raw === null || empty($this->_raw)) {
         return $out . ",'title': " . $json->encode(T_('No Metadata available.')) . "}";
     }
     zmgimport('org.zoomfactory.lib.mime.zmgMimeHelper');
     if (zmgMimeHelper::isImage($this->_ext)) {
         //TODO
         //print_r($this->_raw);
         if (empty($this->_raw['title'])) {
             $out .= ",'title': " . $json->encode(T_('No Metadata available.')) . "}";
         } else {
             $out .= ",\n                  'title' : " . $json->encode($this->_raw['title']);
             if (is_array($this->_raw['IFD'])) {
                 $out .= ",";
                 foreach ($this->_raw['IFD'] as $name => $exif_val) {
                     $out .= $this->interpretJpegMeta($name, $exif_val);
                 }
                 $out = substr($out, 0, -1);
             }
             $out .= "}";
         }
     } else {
         if (zmgMimeHelper::isAudio($this->_ext)) {
             list($artist, $title, $album, $year, $length, $data) = $this->interpretId3($this->_raw);
             $out .= ",\n              'title' : " . $json->encode($title) . "," . $json->encode(T_('Artist')) . ": " . $json->encode($artist) . "," . $json->encode(T_('Song')) . ": " . $json->encode($title) . "," . $json->encode(T_('Album')) . ": " . $json->encode($album) . "," . $json->encode(T_('Year')) . ": " . $json->encode($year) . "," . $json->encode(T_('Length')) . ": " . $json->encode($length) . "," . $json->encode(T_('Data')) . ": " . $json->encode($data) . "}";
         } else {
             if (zmgMimeHelper::isVideo($this->_ext)) {
                 //TODO
                 $out .= ",'title': " . $json->encode(T_('No Metadata available.')) . "}";
             }
         }
     }
     return $out;
 }