function setAll($messages)
 {
     if (empty($messages) || !is_array($messages)) {
         return zmgError::throwError('Illegal access to zmgMessageCenter::setAll');
     }
     $this->_messages = $messages;
 }
Пример #2
0
 function embed()
 {
     $os = zmgCmsPlugin::_guessCMS();
     $os_dir = ZMG_ABS_PATH . DS . 'var' . DS . 'plugins' . DS . 'cms' . DS . $os;
     if (is_dir($os_dir)) {
         $os_path = 'org.zoomfactory.var.plugins.cms.' . $os;
         zmgimport($os_path . '.aclEmbed');
         zmgimport($os_path . '.databaseEmbed');
         zmgimport($os_path . '.envEmbed');
         return true;
     }
     zmgError::throwError('zmgCmsPlugin: no CMS found.');
     return false;
 }
 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;
 }
 function throwError($message)
 {
     if (true) {
         //!zmgEnv::isRPC()) {
         return zmgError::throwError($message);
     } else {
         return zmgFactory::getRequest()->sendHeaders($this->_viewtype, true, $message);
     }
 }
 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;
 }
Пример #6
0
 function setMimeType($mime = null)
 {
     if (!$this->filename) {
         zmgError::throwError('zmgMedium: medium data not loaded yet');
     }
     if ($mime === null) {
         $path = $this->getAbsPath();
         zmgimport('org.zoomfactory.lib.helpers.zmgFileHelper');
         zmgimport('org.zoomfactory.lib.mime.zmgMimeHelper');
         $mime = zmgMimeHelper::getMime($path, null, $this->getExtension());
     }
     $this->_mime_type = $mime;
 }
Пример #7
0
 /**
  * Autodetect a file's MIME-type with 'file' and System_Command
  *
  * This function may be called staticly.
  *
  * @param  string $file   Path to the file to get the type of
  * @return string $file's MIME-type
  * @since 1.0.0beta1
  * @static
  */
 function _fileAutoDetect($file)
 {
     // Sanity checks
     if (!file_exists($file)) {
         return zmgError::throwError("zmgMime: File \"{$file}\" doesn't exist");
     }
     if (!is_readable($file)) {
         return zmgError::throwError("zmgMime: File \"{$file}\" is not readable");
     }
     $output = '';
     $status = null;
     @exec("file -bi '{$file}'", $output, $status);
     if (@$status) {
         return false;
     } else {
         return $output;
     }
 }
 function delete()
 {
     if (!$this->hasStarted()) {
         return zmgError::throwError('zmgSession: session not started yet.');
     }
     if (empty($this->_vars)) {
         return zmgError::throwError('zmgSession: no variables to fetch.');
     }
     $name = trim($name);
     if ($this->_vars[$this->_var_prefix . $name]) {
         unset($this->_vars[$this->_var_prefix . $name]);
     }
     if ($this->_vars[$name]) {
         unset($this->_vars[$name]);
     }
 }
Пример #9
0
 /**
  * This method is a wrapper that returns a preconfigured error
  * with this object's default error handling applied (if present).
  * If the $mode and $options parameters are not
  * specified, the object's defaults are used.
  *
  * @param mixed $message A text error message
  * @param int $code A numeric error code (it is up to your class
  *                  to define these if you want to use codes)
  */
 function throwError($message = null, $code = null)
 {
     $mode = ZMG_DEFAULT_ERROR_MODE;
     $options = ZMG_DEFAULT_ERROR_OPTIONS;
     if (isset($this) && is_subclass_of($this, 'zmgError')) {
         return $this->raiseError($message, $code, ZMG_DEFAULT_ERROR_MODE, ZMG_DEFAULT_ERROR_OPTIONS);
     } else {
         return zmgError::raiseError($message, $code, $mode, $options);
     }
 }
Пример #10
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);
 }
 function getViewToken($which = 'last')
 {
     $tokens = zmgFactory::getView()->getViewTokens();
     if (count($tokens) == 0) {
         return zmgError::throwError('No tokens available.');
     }
     $token = "";
     switch ($which) {
         case 'first':
             $token = $tokens[0];
             break;
         default:
         case 'last':
             $token = $tokens[count($tokens) - 1];
             break;
     }
     return $token;
 }
Пример #12
0
 function isError($data, $code = null)
 {
     return zmgError::isError($data);
 }
 function embedSettings(&$plugin, $xml_path)
 {
     //echo "DEBUG: ".$xml_path;
     if (!empty($plugin)) {
         if (is_string($plugin)) {
             $plugin =& $this->get($plugin);
         }
     } else {
         return zmgError::throwError('embedSettings::Invalid plugin.');
     }
     if (!file_exists($xml_path)) {
         return zmgError::throwError('Settings file not found (' . $xml_path . ').');
     }
     require_once ZMG_ABS_PATH . DS . 'lib' . DS . 'domit' . DS . 'xml_domit_lite_include.php';
     $xmldoc =& new DOMIT_Lite_Document();
     $xmldoc->resolveErrors(true);
     if (!$xmldoc->loadXML($xml_path, false, true)) {
         unset($xmldoc);
         return zmgError::throwError('DOMIT error: could not open document.');
     }
     if ($xmldoc->documentElement->getTagName() != "settings") {
         unset($xmldoc);
         return zmgError::throwError('Invalid plugin settings file.');
     }
     $plugin['settings'] = array();
     if ($xmldoc->documentElement->hasAttribute('plugin')) {
         $plugin['settings_name'] = $xmldoc->documentElement->getAttribute('plugin');
     } else {
         $plugin['settings_name'] = $this->prettifyName($plugin['name']);
     }
     $els =& $xmldoc->getElementsByTagName('category');
     for ($i = 0; $i < $els->getLength(); $i++) {
         $res =& $els->item($i);
         if ($res->hasAttribute('name')) {
             $cat = $res->getAttribute('name');
             $plugin['settings'][$cat] = array();
             $settings =& $res->getElementsByTagName('setting');
             for ($j = 0; $j < $settings->getLength(); $j++) {
                 $setting =& $settings->item($j);
                 if (!$setting->hasAttribute('name')) {
                     zmgError::throwError('zmgPluginHelper::invalid setting in ' . $xml_path);
                     continue;
                 }
                 $name = trim($setting->getAttribute('name'));
                 $plugin['settings'][$cat][$name] = array();
                 if ($setting->hasAttribute('type')) {
                     $type = $setting->getAttribute('type');
                     $plugin['settings'][$cat][$name]['type'] = $type;
                     if ($type == "select") {
                         $options =& $setting->getElementsByTagName('option');
                         for ($k = 0; $k < $options->getLength(); $k++) {
                             $option =& $options->item($k);
                             $plugin['settings'][$cat][$name]['option' . $k] = array('value' => $option->getAttribute('value'), 'caption' => $option->firstChild->nodeValue);
                         }
                     }
                 }
                 if ($setting->hasAttribute('size')) {
                     $plugin['settings'][$cat][$name]['size'] = $setting->getAttribute('size');
                 }
                 if ($setting->hasAttribute('default')) {
                     $plugin['settings'][$cat][$name]['default'] = $setting->getAttribute('default');
                 }
                 if ($setting->hasAttribute('value')) {
                     $plugin['settings'][$cat][$name]['value'] = $setting->getAttribute('value');
                 }
                 if ($setting->hasAttribute('label')) {
                     $plugin['settings'][$cat][$name]['label'] = $setting->getAttribute('label');
                 }
                 if ($setting->hasAttribute('description')) {
                     $plugin['settings'][$cat][$name]['description'] = $setting->getAttribute('description');
                 }
                 if ($setting->hasAttribute('disabled')) {
                     $plugin['settings'][$cat][$name]['disabled'] = $setting->getAttribute('description') == "true" ? true : false;
                 } else {
                     $plugin['settings'][$cat][$name]['disabled'] = false;
                 }
                 if ($setting->hasAttribute('readonly')) {
                     $plugin['settings'][$cat][$name]['readonly'] = $setting->getAttribute('readonly') == "true" ? true : false;
                 } else {
                     $plugin['settings'][$cat][$name]['readonly'] = false;
                 }
             }
         }
     }
     //TODO: access fromXML with a public API call
     zmgFactory::getConfig()->fromPlugin($plugin);
 }
 /**
  * remove a gallery completely including sub-directories.
  * @param string $path
  * @return boolean
  */
 function deleteDir($path)
 {
     // Sanity check
     if (!$path) {
         // Bad programmer! Bad Bad programmer!
         zmgError::throwError('zmgFileHelper: ' . _('Attempt to delete base directory'));
         return false;
     }
     $res = true;
     $current_dir = opendir($path);
     while ($entryname = readdir($current_dir)) {
         if (is_dir($path . DS . $entryname) && ($entryname != "." && $entryname != "..")) {
             $res = zmgFileHelper::deleteDir($path . DS . $entryname);
         } else {
             if ($entryname != "." && $entryname != "..") {
                 $res = zmgFileHelper::delete($path . DS . $entryname);
             }
         }
     }
     closedir($current_dir);
     if (zmgFactory::getConfig()->get('plugins/safemode/general/enable') == 1) {
         $res = zmgFactory::getEvents()->fire('ondirdelete', $path);
     } else {
         $res = rmdir($path);
     }
     return $res;
 }
Пример #15
0
//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');
Пример #16
0
 /**
  * Set transfer mode
  *
  * @access private
  * @param int $mode Integer representation of data transfer mode [1:Binary|0:Ascii]
  *  Defined constants can also be used [FTP_BINARY|FTP_ASCII]
  * @return boolean True if successful
  */
 function _mode($mode)
 {
     if ($mode == FTP_BINARY) {
         if (!$this->_putCmd("TYPE I", 200)) {
             zmgError::throwError('zmgFTP::_mode: Bad response', 'Server response: ' . $this->_response . ' [Expected: 200] Mode sent: Binary');
             //'35'
             return false;
         }
     } else {
         if (!$this->_putCmd("TYPE A", 200)) {
             zmgError::throwError('zmgFTP::_mode: Bad response', 'Server response: ' . $this->_response . ' [Expected: 200] Mode sent: Ascii');
             //'35'
             return false;
         }
     }
     return true;
 }