Exemplo n.º 1
0
 public function extract($archive, $destination, $options = array())
 {
     // Initialise variables.
     $this->_data = null;
     $this->_metadata = null;
     if (!($this->_data = MFile::read($archive))) {
         $this->set('error.message', 'Unable to read archive');
         return MError::raiseWarning(100, $this->get('error.message'));
     }
     if (!$this->_getTarInfo($this->_data)) {
         return MError::raiseWarning(100, $this->get('error.message'));
     }
     for ($i = 0, $n = count($this->_metadata); $i < $n; $i++) {
         $type = strtolower($this->_metadata[$i]['type']);
         if ($type == 'file' || $type == 'unix file') {
             $buffer = $this->_metadata[$i]['data'];
             $path = MPath::clean($destination . '/' . $this->_metadata[$i]['name']);
             // Make sure the destination folder exists
             if (!MFolder::create(dirname($path))) {
                 $this->set('error.message', 'Unable to create destination');
                 return MError::raiseWarning(100, $this->get('error.message'));
             }
             if (MFile::write($path, $buffer) === false) {
                 $this->set('error.message', 'Unable to write entry');
                 return MError::raiseWarning(100, $this->get('error.message'));
             }
         }
     }
     return true;
 }
Exemplo n.º 2
0
 public static function getInstance($type, $prefix = 'MTable', $config = array())
 {
     // Sanitize and prepare the table class name.
     $type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type);
     $tableClass = $prefix . ucfirst($type);
     // Only try to load the class if it doesn't already exist.
     if (!class_exists($tableClass)) {
         // Search for the class file in the MTable include paths.
         mimport('framework.filesystem.path');
         MTable::addIncludePath(MPATH_MIWI . '/proxy/database/table');
         if ($path = MPath::find(MTable::addIncludePath(), strtolower($type) . '.php')) {
             // Import the class file.
             include_once $path;
             // If we were unable to load the proper class, raise a warning and return false.
             if (!class_exists($tableClass)) {
                 MError::raiseWarning(0, MText::sprintf('MLIB_DATABASE_ERROR_CLASS_NOT_FOUND_IN_FILE', $tableClass));
                 return false;
             }
         } else {
             // If we were unable to find the class file in the MTable include paths, raise a warning and return false.
             MError::raiseWarning(0, MText::sprintf('MLIB_DATABASE_ERROR_NOT_SUPPORTED_FILE_NOT_FOUND', $type));
             return false;
         }
     }
     // If a database object was passed in the configuration array use it, otherwise get the global one from MFactory.
     $db = isset($config['dbo']) ? $config['dbo'] : MFactory::getDbo();
     // Instantiate a new table class and return it.
     return new $tableClass($db);
 }
Exemplo n.º 3
0
 protected function getOptions()
 {
     MLog::add('MFormFieldEditors is deprecated. Use MFormFieldPlugins instead (with folder="editors").', MLog::WARNING, 'deprecated');
     // Get the database object and a new query object.
     $db = MFactory::getDBO();
     $query = $db->getQuery(true);
     // Build the query.
     $query->select('element AS value, name AS text');
     $query->from('#__extensions');
     $query->where('folder = ' . $db->quote('editors'));
     $query->where('enabled = 1');
     $query->order('ordering, name');
     // Set the query and load the options.
     $db->setQuery($query);
     $options = $db->loadObjectList();
     $lang = MFactory::getLanguage();
     foreach ($options as $i => $option) {
         $lang->load('plg_editors_' . $option->value, MPATH_ADMINISTRATOR, null, false, false) || $lang->load('plg_editors_' . $option->value, MPATH_PLUGINS . '/editors/' . $option->value, null, false, false) || $lang->load('plg_editors_' . $option->value, MPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load('plg_editors_' . $option->value, MPATH_PLUGINS . '/editors/' . $option->value, $lang->getDefault(), false, false);
         $options[$i]->text = MText::_($option->text);
     }
     // Check for a database error.
     if ($db->getErrorNum()) {
         MError::raiseWarning(500, $db->getErrorMsg());
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Exemplo n.º 4
0
 protected function getOptions()
 {
     // Initialize variables.
     $options = array();
     // Initialize some field attributes.
     $key = $this->element['key_field'] ? (string) $this->element['key_field'] : 'value';
     $value = $this->element['value_field'] ? (string) $this->element['value_field'] : (string) $this->element['name'];
     $translate = $this->element['translate'] ? (string) $this->element['translate'] : false;
     $query = (string) $this->element['query'];
     // Get the database object.
     $db = MFactory::getDBO();
     // Set the query and get the result list.
     $db->setQuery($query);
     $items = $db->loadObjectlist();
     // Check for an error.
     if ($db->getErrorNum()) {
         MError::raiseWarning(500, $db->getErrorMsg());
         return $options;
     }
     // Build the field options.
     if (!empty($items)) {
         foreach ($items as $item) {
             if ($translate == true) {
                 $options[] = MHtml::_('select.option', $item->{$key}, MText::_($item->{$value}));
             } else {
                 $options[] = MHtml::_('select.option', $item->{$key}, $item->{$value});
             }
         }
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Exemplo n.º 5
0
 protected function getOptions()
 {
     // Initialise variables
     $folder = $this->element['folder'];
     if (!empty($folder)) {
         // Get list of plugins
         $db = MFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select('element AS value, name AS text');
         $query->from('#__extensions');
         $query->where('folder = ' . $db->q($folder));
         $query->where('enabled = 1');
         $query->order('ordering, name');
         $db->setQuery($query);
         $options = $db->loadObjectList();
         $lang = MFactory::getLanguage();
         foreach ($options as $i => $item) {
             $source = MPATH_PLUGINS . '/' . $folder . '/' . $item->value;
             $extension = 'plg_' . $folder . '_' . $item->value;
             $lang->load($extension . '.sys', MPATH_ADMINISTRATOR, null, false, false) || $lang->load($extension . '.sys', $source, null, false, false) || $lang->load($extension . '.sys', MPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load($extension . '.sys', $source, $lang->getDefault(), false, false);
             $options[$i]->text = MText::_($item->text);
         }
         if ($db->getErrorMsg()) {
             MError::raiseWarning(500, MText::_('MFRAMEWORK_FORM_FIELDS_PLUGINS_ERROR_FOLDER_EMPTY'));
             return '';
         }
     } else {
         MError::raiseWarning(500, MText::_('MFRAMEWORK_FORM_FIELDS_PLUGINS_ERROR_FOLDER_EMPTY'));
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Exemplo n.º 6
0
 public static function level($name, $selected, $attribs = '', $params = true, $id = false)
 {
     $db = MFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select('a.id AS value, a.title AS text');
     $query->from('#__viewlevels AS a');
     $query->group('a.id, a.title, a.ordering');
     $query->order('a.ordering ASC');
     $query->order($query->qn('title') . ' ASC');
     // Get the options.
     $db->setQuery($query);
     $options = $db->loadObjectList();
     // Check for a database error.
     if ($db->getErrorNum()) {
         MError::raiseWarning(500, $db->getErrorMsg());
         return null;
     }
     // If params is an array, push these options to the array
     if (is_array($params)) {
         $options = array_merge($params, $options);
     } elseif ($params) {
         array_unshift($options, MHtml::_('select.option', '', MText::_('MOPTION_ACCESS_SHOW_ALL_LEVELS')));
     }
     return MHtml::_('select.genericlist', $options, $name, array('list.attr' => $attribs, 'list.select' => $selected, 'id' => $id));
 }
Exemplo n.º 7
0
 public static function runSqlFile($sql_file)
 {
     $db = MFactory::getDbo();
     if (!file_exists($sql_file)) {
         return;
     }
     $buffer = file_get_contents($sql_file);
     if ($buffer === false) {
         return;
     }
     $queries = $db->splitSql($buffer);
     if (count($queries) == 0) {
         return;
     }
     foreach ($queries as $query) {
         $query = trim($query);
         if ($query != '' && $query[0] != '#') {
             $db->setQuery($query);
             if (!$db->query()) {
                 MError::raiseWarning(1, 'MInstaller::install: ' . MText::_('SQL Error') . " " . $db->stderr(true));
                 return;
             }
         }
     }
 }
Exemplo n.º 8
0
 public static function getInstance($handler = null, $options = array())
 {
     static $now = null;
     MCacheStorage::addIncludePath(MPATH_WP_CNT . '/miwi/framework/cache/storage');
     if (!isset($handler)) {
         $conf = MFactory::getConfig();
         $handler = $conf->get('cache_handler');
         if (empty($handler)) {
             return MError::raiseWarning(500, MText::_('MLIB_CACHE_ERROR_CACHE_HANDLER_NOT_SET'));
         }
     }
     if (is_null($now)) {
         $now = time();
     }
     $options['now'] = $now;
     $handler = strtolower(preg_replace('/[^A-Z0-9_\\.-]/i', '', $handler));
     $class = 'MCacheStorage' . ucfirst($handler);
     if (!class_exists($class)) {
         mimport('joomla.filesystem.path');
         if ($path = MPath::find(MCacheStorage::addIncludePath(), strtolower($handler) . '.php')) {
             include_once $path;
         } else {
             return MError::raiseWarning(500, MText::sprintf('MLIB_CACHE_ERROR_CACHE_STORAGE_LOAD', $handler));
         }
     }
     return new $class($options);
 }
Exemplo n.º 9
0
 public function extract($archive, $destination, $options = array())
 {
     // Initialise variables.
     $this->_data = null;
     if (!extension_loaded('bz2')) {
         $this->set('error.message', MText::_('MLIB_FILESYSTEM_BZIP_NOT_SUPPORTED'));
         return MError::raiseWarning(100, $this->get('error.message'));
     }
     if (!isset($options['use_streams']) || $options['use_streams'] == false) {
         // Old style: read the whole file and then parse it
         if (!($this->_data = MFile::read($archive))) {
             $this->set('error.message', 'Unable to read archive');
             return MError::raiseWarning(100, $this->get('error.message'));
         }
         $buffer = bzdecompress($this->_data);
         unset($this->_data);
         if (empty($buffer)) {
             $this->set('error.message', 'Unable to decompress data');
             return MError::raiseWarning(100, $this->get('error.message'));
         }
         if (MFile::write($destination, $buffer) === false) {
             $this->set('error.message', 'Unable to write archive');
             return MError::raiseWarning(100, $this->get('error.message'));
         }
     } else {
         // New style! streams!
         $input = MFactory::getStream();
         $input->set('processingmethod', 'bz');
         // use bzip
         if (!$input->open($archive)) {
             $this->set('error.message', MText::_('MLIB_FILESYSTEM_BZIP_UNABLE_TO_READ'));
             return MError::raiseWarning(100, $this->get('error.message'));
         }
         $output = MFactory::getStream();
         if (!$output->open($destination, 'w')) {
             $this->set('error.message', MText::_('MLIB_FILESYSTEM_BZIP_UNABLE_TO_WRITE'));
             $input->close();
             // close the previous file
             return MError::raiseWarning(100, $this->get('error.message'));
         }
         do {
             $this->_data = $input->read($input->get('chunksize', 8196));
             if ($this->_data) {
                 if (!$output->write($this->_data)) {
                     $this->set('error.message', MText::_('MLIB_FILESYSTEM_BZIP_UNABLE_TO_WRITE_FILE'));
                     return MError::raiseWarning(100, $this->get('error.message'));
                 }
             }
         } while ($this->_data);
         $output->close();
         $input->close();
     }
     return true;
 }
Exemplo n.º 10
0
 protected function getOptions()
 {
     // Initialise variables.
     $options = array();
     $extension = $this->element['extension'] ? (string) $this->element['extension'] : (string) $this->element['scope'];
     $published = (string) $this->element['published'];
     $name = (string) $this->element['name'];
     // Load the category options for a given extension.
     if (!empty($extension)) {
         // Filter over published state or not depending upon if it is present.
         if ($published) {
             $options = MHtml::_('category.options', $extension, array('filter.published' => explode(',', $published)));
         } else {
             $options = MHtml::_('category.options', $extension);
         }
         // Verify permissions.  If the action attribute is set, then we scan the options.
         if ((string) $this->element['action']) {
             // Get the current user object.
             $user = MFactory::getUser();
             // For new items we want a list of categories you are allowed to create in.
             if (!$this->form->getValue($name)) {
                 foreach ($options as $i => $option) {
                     // To take save or create in a category you need to have create rights for that category
                     // unless the item is already in that category.
                     // Unset the option if the user isn't authorised for it. In this field assets are always categories.
                     if ($user->authorise('core.create', $extension . '.category.' . $option->value) != true) {
                         unset($options[$i]);
                     }
                 }
             } else {
                 $categoryOld = $this->form->getValue($name);
                 foreach ($options as $i => $option) {
                     // If you are only allowed to edit in this category but not edit.state, you should not get any
                     // option to change the category.
                     if ($user->authorise('core.edit.state', $extension . '.category.' . $categoryOld) != true) {
                         if ($option->value != $categoryOld) {
                             unset($options[$i]);
                         }
                     } elseif ($user->authorise('core.create', $extension . '.category.' . $option->value) != true && $option->value != $categoryOld) {
                         unset($options[$i]);
                     }
                 }
             }
         }
         if (isset($this->element['show_root'])) {
             array_unshift($options, MHtml::_('select.option', '0', MText::_('MGLOBAL_ROOT')));
         }
     } else {
         MError::raiseWarning(500, MText::_('MLIB_FORM_ERROR_FIELDS_CATEGORY_ERROR_EXTENSION_EMPTY'));
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Exemplo n.º 11
0
 public function extract($archive, $destination, $options = array())
 {
     if (!is_file($archive)) {
         $this->set('error.message', 'Archive does not exist');
         return false;
     }
     if ($this->hasNativeSupport()) {
         return $this->_extractNative($archive, $destination, $options) ? true : MError::raiseWarning(100, $this->get('error.message'));
     } else {
         return $this->_extract($archive, $destination, $options) ? true : MError::raiseWarning(100, $this->get('error.message'));
     }
 }
Exemplo n.º 12
0
 public function register($event, $handler)
 {
     // Are we dealing with a class or function type handler?
     if (function_exists($handler)) {
         // Ok, function type event handler... let's attach it.
         $method = array('event' => $event, 'handler' => $handler);
         $this->attach($method);
     } elseif (class_exists($handler)) {
         // Ok, class type event handler... let's instantiate and attach it.
         $this->attach(new $handler($this));
     } else {
         return MError::raiseWarning('SOME_ERROR_CODE', MText::sprintf('MLIB_EVENT_ERROR_DISPATCHER', $handler));
     }
 }
Exemplo n.º 13
0
 public static function userlist()
 {
     // Get the database object and a new query object.
     $db = MFactory::getDBO();
     $query = $db->getQuery(true);
     // Build the query.
     $query->select('a.ID AS value, a.display_name AS text');
     $query->from('#__users AS a');
     $query->where('a.user_status = 0');
     $query->order('a.display_name');
     // Set the query and load the options.
     $db->setQuery($query);
     $items = $db->loadObjectList();
     // Detect errors
     if ($db->getErrorNum()) {
         MError::raiseWarning(500, $db->getErrorMsg());
     }
     return $items;
 }
Exemplo n.º 14
0
 public static function getInstance($type, $prefix = '', $config = array())
 {
     $type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type);
     $modelClass = $prefix . ucfirst($type);
     if (!class_exists($modelClass)) {
         mimport('framework.filesystem.path');
         $path = MPath::find(self::addIncludePath(null, $prefix), self::_createFileName('model', array('name' => $type)));
         if (!$path) {
             $path = MPath::find(self::addIncludePath(null, ''), self::_createFileName('model', array('name' => $type)));
         }
         if ($path) {
             require_once $path;
             if (!class_exists($modelClass)) {
                 MError::raiseWarning(0, MText::sprintf('MLIB_APPLICATION_ERROR_MODELCLASS_NOT_FOUND', $modelClass));
                 return false;
             }
         } else {
             return false;
         }
     }
     return new $modelClass($config);
 }
Exemplo n.º 15
0
 public static function getInstance($identifier = 0)
 {
     // Find the user id
     if (empty($identifier) and function_exists('wp_get_current_user')) {
         $user = wp_get_current_user();
         $id = $user->ID;
     } else {
         if (!is_numeric($identifier)) {
             if (!($id = MUserHelper::getUserId($identifier))) {
                 MError::raiseWarning('SOME_ERROR_CODE', MText::sprintf('MLIB_USER_ERROR_ID_NOT_EXISTS', $identifier));
                 $retval = false;
                 return $retval;
             }
         } else {
             $id = $identifier;
         }
     }
     if (empty(self::$instances[$id])) {
         $user = new MUser($id);
         self::$instances[$id] = $user;
     }
     return self::$instances[$id];
 }
Exemplo n.º 16
0
 public function test(&$element, $value, $group = null, &$input = null, &$form = null)
 {
     // If the field is empty and not required, the field is valid.
     $required = (string) $element['required'] == 'true' || (string) $element['required'] == 'required';
     if (!$required && empty($value)) {
         return true;
     }
     // Test the value against the regular expression.
     if (!parent::test($element, $value, $group, $input, $form)) {
         return false;
     }
     // Check if we should test for uniqueness.
     $unique = (string) $element['unique'] == 'true' || (string) $element['unique'] == 'unique';
     if ($unique) {
         // Get the database object and a new query object.
         $db = MFactory::getDBO();
         $query = $db->getQuery(true);
         // Build the query.
         $query->select('COUNT(*)');
         $query->from('#__users');
         $query->where('email = ' . $db->quote($value));
         // Get the extra field check attribute.
         $userId = $form instanceof MForm ? $form->getValue('id') : '';
         $query->where($db->quoteName('id') . ' <> ' . (int) $userId);
         // Set and query the database.
         $db->setQuery($query);
         $duplicate = (bool) $db->loadResult();
         // Check for a database error.
         if ($db->getErrorNum()) {
             MError::raiseWarning(500, $db->getErrorMsg());
         }
         if ($duplicate) {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 17
0
 public function test(&$element, $value, $group = null, &$input = null, &$form = null)
 {
     // Get the database object and a new query object.
     $db = MFactory::getDBO();
     $query = $db->getQuery(true);
     // Build the query.
     $query->select('COUNT(*)');
     $query->from('#__users');
     $query->where('username = '******'id') : '';
     $query->where($db->quoteName('id') . ' <> ' . (int) $userId);
     // Set and query the database.
     $db->setQuery($query);
     $duplicate = (bool) $db->loadResult();
     // Check for a database error.
     if ($db->getErrorNum()) {
         MError::raiseWarning(500, $db->getErrorMsg());
     }
     if ($duplicate) {
         return false;
     }
     return true;
 }
Exemplo n.º 18
0
 public function authenticate($credentials, $options = array())
 {
     // Get plugins
     $plugins = MPluginHelper::getPlugin('authentication');
     // Create authentication response
     $response = new MAuthenticationResponse();
     foreach ($plugins as $plugin) {
         $className = 'plg' . $plugin->type . $plugin->name;
         if (class_exists($className)) {
             $plugin = new $className($this, (array) $plugin);
         } else {
             // Bail here if the plugin can't be created
             MError::raiseWarning(50, MText::sprintf('MLIB_USER_ERROR_AUTHENTICATION_FAILED_LOAD_PLUGIN', $className));
             continue;
         }
         // Try to authenticate
         $plugin->onUserAuthenticate($credentials, $options, $response);
         // If authentication is successful break out of the loop
         if ($response->status === MAuthentication::STATUS_SUCCESS) {
             if (empty($response->type)) {
                 $response->type = isset($plugin->_name) ? $plugin->_name : $plugin->name;
             }
             break;
         }
     }
     if (empty($response->username)) {
         $response->username = $credentials['username'];
     }
     if (empty($response->fullname)) {
         $response->fullname = $credentials['username'];
     }
     if (empty($response->password)) {
         $response->password = $credentials['password'];
     }
     return $response;
 }
Exemplo n.º 19
0
 public function login($credentials, $options = array())
 {
     // Get the global MAuthentication object.
     mimport('framework.user.authentication');
     $authenticate = MAuthentication::getInstance();
     $response = $authenticate->authenticate($credentials, $options);
     if ($response->status === MAuthentication::STATUS_SUCCESS) {
         // validate that the user should be able to login (different to being authenticated)
         // this permits authentication plugins blocking the user
         $authorisations = $authenticate->authorise($response, $options);
         foreach ($authorisations as $authorisation) {
             $denied_states = array(MAuthentication::STATUS_EXPIRED, MAuthentication::STATUS_DENIED);
             if (in_array($authorisation->status, $denied_states)) {
                 // Trigger onUserAuthorisationFailure Event.
                 $this->triggerEvent('onUserAuthorisationFailure', array((array) $authorisation));
                 // If silent is set, just return false.
                 if (isset($options['silent']) && $options['silent']) {
                     return false;
                 }
                 // Return the error.
                 switch ($authorisation->status) {
                     case MAuthentication::STATUS_EXPIRED:
                         return MError::raiseWarning('102002', MText::_('MLIB_LOGIN_EXPIRED'));
                         break;
                     case MAuthentication::STATUS_DENIED:
                         return MError::raiseWarning('102003', MText::_('MLIB_LOGIN_DENIED'));
                         break;
                     default:
                         return MError::raiseWarning('102004', MText::_('MLIB_LOGIN_AUTHORISATION'));
                         break;
                 }
             }
         }
         // Import the user plugin group.
         MPluginHelper::importPlugin('user');
         // OK, the credentials are authenticated and user is authorised.  Lets fire the onLogin event.
         $results = $this->triggerEvent('onUserLogin', array((array) $response, $options));
         if (!in_array(false, $results, true)) {
             // Set the remember me cookie if enabled.
             if (isset($options['remember']) && $options['remember']) {
                 // Create the encryption key, apply extra hardening using the user agent string.
                 $privateKey = self::getHash(@$_SERVER['HTTP_USER_AGENT']);
                 $key = new MCryptKey('simple', $privateKey, $privateKey);
                 $crypt = new MCrypt(new MCryptCipherSimple(), $key);
                 $rcookie = $crypt->encrypt(json_encode($credentials));
                 $lifetime = time() + 365 * 24 * 60 * 60;
                 // Use domain and path set in config for cookie if it exists.
                 $cookie_domain = $this->getCfg('cookie_domain', '');
                 $cookie_path = $this->getCfg('cookie_path', '/');
                 // Check for SSL connection
                 $secure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || getenv('SSL_PROTOCOL_VERSION');
                 setcookie(self::getHash('MLOGIN_REMEMBER'), $rcookie, $lifetime, $cookie_path, $cookie_domain, $secure, true);
             }
             return true;
         }
     }
     // Trigger onUserLoginFailure Event.
     $this->triggerEvent('onUserLoginFailure', array((array) $response));
     // If silent is set, just return false.
     if (isset($options['silent']) && $options['silent']) {
         return false;
     }
     // If status is success, any error will have been raised by the user plugin
     if ($response->status !== MAuthentication::STATUS_SUCCESS) {
         MError::raiseWarning('102001', $response->error_message);
     }
     return false;
 }
Exemplo n.º 20
0
 protected function getInput()
 {
     // Initialize variables.
     // Get the client id.
     $clientId = $this->element['client_id'];
     if (is_null($clientId) && $this->form instanceof MForm) {
         $clientId = $this->form->getValue('client_id');
     }
     $clientId = (int) $clientId;
     $client = MApplicationHelper::getClientInfo($clientId);
     // Get the extension.
     $extn = (string) $this->element['extension'];
     if (empty($extn) && $this->form instanceof MForm) {
         $extn = $this->form->getValue('extension');
     }
     $extn = preg_replace('#\\W#', '', $extn);
     // Get the template.
     $template = (string) $this->element['template'];
     $template = preg_replace('#\\W#', '', $template);
     // Get the style.
     if ($this->form instanceof MForm) {
         $template_style_id = $this->form->getValue('template_style_id');
     }
     $template_style_id = preg_replace('#\\W#', '', $template_style_id);
     // Get the view.
     $view = (string) $this->element['view'];
     $view = preg_replace('#\\W#', '', $view);
     // If a template, extension and view are present build the options.
     if ($extn && $view && $client) {
         // Load language file
         $lang = MFactory::getLanguage();
         $lang->load($extn . '.sys', MPATH_ADMINISTRATOR, null, false, false) || $lang->load($extn . '.sys', MPATH_ADMINISTRATOR . '/components/' . $extn, null, false, false) || $lang->load($extn . '.sys', MPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load($extn . '.sys', MPATH_ADMINISTRATOR . '/components/' . $extn, $lang->getDefault(), false, false);
         // Get the database object and a new query object.
         $db = MFactory::getDBO();
         $query = $db->getQuery(true);
         // Build the query.
         $query->select('e.element, e.name');
         $query->from('#__extensions as e');
         $query->where('e.client_id = ' . (int) $clientId);
         $query->where('e.type = ' . $db->quote('template'));
         $query->where('e.enabled = 1');
         if ($template) {
             $query->where('e.element = ' . $db->quote($template));
         }
         if ($template_style_id) {
             $query->join('LEFT', '#__template_styles as s on s.template=e.element');
             $query->where('s.id=' . (int) $template_style_id);
         }
         // Set the query and load the templates.
         $db->setQuery($query);
         $templates = $db->loadObjectList('element');
         // Check for a database error.
         if ($db->getErrorNum()) {
             MError::raiseWarning(500, $db->getErrorMsg());
         }
         // Build the search paths for component layouts.
         $component_path = MPath::clean($client->path . '/components/' . $extn . '/views/' . $view . '/tmpl');
         // Prepare array of component layouts
         $component_layouts = array();
         // Prepare the grouped list
         $groups = array();
         // Add a Use Global option if useglobal="true" in XML file
         if ($this->element['useglobal'] == 'true') {
             $groups[MText::_('MOPTION_FROM_STANDARD')]['items'][] = MHtml::_('select.option', '', MText::_('MGLOBAL_USE_GLOBAL'));
         }
         // Add the layout options from the component path.
         if (is_dir($component_path) && ($component_layouts = MFolder::files($component_path, '^[^_]*\\.xml$', false, true))) {
             // Create the group for the component
             $groups['_'] = array();
             $groups['_']['id'] = $this->id . '__';
             $groups['_']['text'] = MText::sprintf('MOPTION_FROM_COMPONENT');
             $groups['_']['items'] = array();
             foreach ($component_layouts as $i => $file) {
                 // Attempt to load the XML file.
                 if (!($xml = simplexml_load_file($file))) {
                     unset($component_layouts[$i]);
                     continue;
                 }
                 // Get the help data from the XML file if present.
                 if (!($menu = $xml->xpath('layout[1]'))) {
                     unset($component_layouts[$i]);
                     continue;
                 }
                 $menu = $menu[0];
                 // Add an option to the component group
                 $value = MFile::stripext(MFile::getName($file));
                 $component_layouts[$i] = $value;
                 $text = isset($menu['option']) ? MText::_($menu['option']) : (isset($menu['title']) ? MText::_($menu['title']) : $value);
                 $groups['_']['items'][] = MHtml::_('select.option', '_:' . $value, $text);
             }
         }
         // Loop on all templates
         if ($templates) {
             foreach ($templates as $template) {
                 // Load language file
                 $lang->load('tpl_' . $template->element . '.sys', $client->path, null, false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, null, false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path, $lang->getDefault(), false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, $lang->getDefault(), false, false);
                 $template_path = MPath::clean($client->path . '/templates/' . $template->element . '/html/' . $extn . '/' . $view);
                 // Add the layout options from the template path.
                 if (is_dir($template_path) && ($files = MFolder::files($template_path, '^[^_]*\\.php$', false, true))) {
                     // Files with corresponding XML files are alternate menu items, not alternate layout files
                     // so we need to exclude these files from the list.
                     $xml_files = MFolder::files($template_path, '^[^_]*\\.xml$', false, true);
                     for ($j = 0, $count = count($xml_files); $j < $count; $j++) {
                         $xml_files[$j] = MFile::stripext(MFile::getName($xml_files[$j]));
                     }
                     foreach ($files as $i => $file) {
                         // Remove layout files that exist in the component folder or that have XML files
                         if (in_array(MFile::stripext(MFile::getName($file)), $component_layouts) || in_array(MFile::stripext(MFile::getName($file)), $xml_files)) {
                             unset($files[$i]);
                         }
                     }
                     if (count($files)) {
                         // Create the group for the template
                         $groups[$template->name] = array();
                         $groups[$template->name]['id'] = $this->id . '_' . $template->element;
                         $groups[$template->name]['text'] = MText::sprintf('MOPTION_FROM_TEMPLATE', $template->name);
                         $groups[$template->name]['items'] = array();
                         foreach ($files as $file) {
                             // Add an option to the template group
                             $value = MFile::stripext(MFile::getName($file));
                             $text = $lang->hasKey($key = strtoupper('TPL_' . $template->name . '_' . $extn . '_' . $view . '_LAYOUT_' . $value)) ? MText::_($key) : $value;
                             $groups[$template->name]['items'][] = MHtml::_('select.option', $template->element . ':' . $value, $text);
                         }
                     }
                 }
             }
         }
         // Compute attributes for the grouped list
         $attr = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
         // Prepare HTML code
         $html = array();
         // Compute the current selected values
         $selected = array($this->value);
         // Add a grouped list
         $html[] = MHtml::_('select.groupedlist', $groups, $this->name, array('id' => $this->id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $selected));
         return implode($html);
     } else {
         return '';
     }
 }
Exemplo n.º 21
0
 public static function getXML($data, $isFile = true)
 {
     mimport('framework.utilities.xmlelement');
     // Disable libxml errors and allow to fetch error information as needed
     libxml_use_internal_errors(true);
     if ($isFile) {
         // Try to load the XML file
         $xml = simplexml_load_file($data, 'MXMLElement');
     } else {
         // Try to load the XML string
         $xml = simplexml_load_string($data, 'MXMLElement');
     }
     if (empty($xml)) {
         // There was an error
         MError::raiseWarning(100, MText::_('MLIB_UTIL_ERROR_XML_LOAD'));
         if ($isFile) {
             MError::raiseWarning(100, $data);
         }
         foreach (libxml_get_errors() as $error) {
             MError::raiseWarning(100, 'XML: ' . $error->message);
         }
     }
     return $xml;
 }
Exemplo n.º 22
0
 protected function _handleError($code, $line, $col)
 {
     // Deprecation warning.
     MLog::add('MSimpleXML::_handleError() is deprecated.', MLog::WARNING, 'deprecated');
     MError::raiseWarning('SOME_ERROR_CODE', 'XML Parsing Error at ' . $line . ':' . $col . '. Error ' . $code . ': ' . xml_error_string($code));
 }
Exemplo n.º 23
0
 public static function setCredentialsFromRequest($client)
 {
     // Determine whether FTP credentials have been passed along with the current request
     $user = MRequest::getString('username', null, 'POST', MREQUEST_ALLOWRAW);
     $pass = MRequest::getString('password', null, 'POST', MREQUEST_ALLOWRAW);
     if ($user != '' && $pass != '') {
         // Add credentials to the session
         if (MClientHelper::setCredentials($client, $user, $pass)) {
             $return = false;
         } else {
             $return = MError::raiseWarning('SOME_ERROR_CODE', MText::_('MLIB_CLIENT_ERROR_HELPER_SETCREDENTIALSFROMREQUEST_FAILED'));
         }
     } else {
         // Just determine if the FTP input fields need to be shown
         $return = !MClientHelper::hasCredentials('ftp');
     }
     return $return;
 }
Exemplo n.º 24
0
 protected function _folders($path, $filter = '.', $recurse = false, $fullpath = false, $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'), $excludefilter = array('^\\..*'))
 {
     $arr = array();
     $path = $this->_cleanPath($path);
     if (!is_dir($path)) {
         MError::raiseWarning(21, 'MCacheStorageFile::_folders' . MText::sprintf('MLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER', $path));
         return false;
     }
     if (!($handle = @opendir($path))) {
         return $arr;
     }
     if (count($excludefilter)) {
         $excludefilter_string = '/(' . implode('|', $excludefilter) . ')/';
     } else {
         $excludefilter_string = '';
     }
     while (($file = readdir($handle)) !== false) {
         if ($file != '.' && $file != '..' && !in_array($file, $exclude) && (empty($excludefilter_string) || !preg_match($excludefilter_string, $file))) {
             $dir = $path . '/' . $file;
             $isDir = is_dir($dir);
             if ($isDir) {
                 if (preg_match("/{$filter}/", $file)) {
                     if ($fullpath) {
                         $arr[] = $dir;
                     } else {
                         $arr[] = $file;
                     }
                 }
                 if ($recurse) {
                     if (is_integer($recurse)) {
                         $arr2 = $this->_folders($dir, $filter, $recurse - 1, $fullpath, $exclude, $excludefilter);
                     } else {
                         $arr2 = $this->_folders($dir, $filter, $recurse, $fullpath, $exclude, $excludefilter);
                     }
                     $arr = array_merge($arr, $arr2);
                 }
             }
         }
     }
     closedir($handle);
     return $arr;
 }
Exemplo n.º 25
0
 public function loadButtonType($type, $new = false)
 {
     $signature = md5($type);
     if (isset($this->_buttons[$signature]) && $new === false) {
         return $this->_buttons[$signature];
     }
     if (!class_exists('MButton')) {
         MError::raiseWarning('SOME_ERROR_CODE', MText::_('MLIB_HTML_BUTTON_BASE_CLASS'));
         return false;
     }
     $buttonClass = 'MButton' . $type;
     if (!class_exists($buttonClass)) {
         if (isset($this->_buttonPath)) {
             $dirs = $this->_buttonPath;
         } else {
             $dirs = array();
         }
         $file = MFilterInput::getInstance()->clean(str_replace('_', DIRECTORY_SEPARATOR, strtolower($type)) . '.php', 'path');
         mimport('framework.filesystem.path');
         if ($buttonFile = MPath::find($dirs, $file)) {
             include_once $buttonFile;
         } else {
             MError::raiseWarning('SOME_ERROR_CODE', MText::sprintf('MLIB_HTML_BUTTON_NO_LOAD', $buttonClass, $buttonFile));
             return false;
         }
     }
     if (!class_exists($buttonClass)) {
         //return	MError::raiseError('SOME_ERROR_CODE', "Module file $buttonFile does not contain class $buttonClass.");
         return false;
     }
     $this->_buttons[$signature] = new $buttonClass($this);
     return $this->_buttons[$signature];
 }
Exemplo n.º 26
0
 protected function _mode($mode)
 {
     if ($mode == FTP_BINARY) {
         if (!$this->_putCmd("TYPE I", 200)) {
             MError::raiseWarning('35', MText::sprintf('MLIB_CLIENT_ERROR_MFTP_MODE_BINARY', $this->_response));
             return false;
         }
     } else {
         if (!$this->_putCmd("TYPE A", 200)) {
             MError::raiseWarning('35', MText::sprintf('MLIB_CLIENT_ERROR_MFTP_MODE_ASCII', $this->_response));
             return false;
         }
     }
     return true;
 }
Exemplo n.º 27
0
 public function validate($data, $group = null)
 {
     // Make sure there is a valid MForm XML document.
     if (!$this->xml instanceof SimpleXMLElement) {
         return false;
     }
     // Initialise variables.
     $return = true;
     // Create an input registry object from the data to validate.
     $input = new MRegistry($data);
     // Get the fields for which to validate the data.
     $fields = $this->findFieldsByGroup($group);
     if (!$fields) {
         // PANIC!
         return false;
     }
     // Validate the fields.
     foreach ($fields as $field) {
         // Initialise variables.
         $value = null;
         $name = (string) $field['name'];
         // Get the group names as strings for ancestor fields elements.
         $attrs = $field->xpath('ancestor::fields[@name]/@name');
         $groups = array_map('strval', $attrs ? $attrs : array());
         $group = implode('.', $groups);
         // Get the value from the input data.
         if ($group) {
             $value = $input->get($group . '.' . $name);
         } else {
             $value = $input->get($name);
         }
         // Validate the field.
         $valid = $this->validateField($field, $group, $value, $input);
         // Check for an error.
         if ($valid instanceof Exception) {
             switch ($valid->get('level')) {
                 case E_ERROR:
                     MError::raiseWarning(0, $valid->getMessage());
                     return false;
                     break;
                 default:
                     array_push($this->errors, $valid);
                     $return = false;
                     break;
             }
         }
     }
     return $return;
 }
Exemplo n.º 28
0
 public static function extract($archivename, $extractdir)
 {
     mimport('framework.filesystem.file');
     mimport('framework.filesystem.folder');
     $untar = false;
     $result = false;
     $ext = MFile::getExt(strtolower($archivename));
     // Check if a tar is embedded...gzip/bzip2 can just be plain files!
     if (MFile::getExt(MFile::stripExt(strtolower($archivename))) == 'tar') {
         $untar = true;
     }
     switch ($ext) {
         case 'zip':
             $adapter = MArchive::getAdapter('zip');
             if ($adapter) {
                 $result = $adapter->extract($archivename, $extractdir);
             }
             break;
         case 'tar':
             $adapter = MArchive::getAdapter('tar');
             if ($adapter) {
                 $result = $adapter->extract($archivename, $extractdir);
             }
             break;
         case 'tgz':
             // This format is a tarball gzip'd
             $untar = true;
         case 'gz':
         case 'gzip':
             // This may just be an individual file (e.g. sql script)
             $adapter = MArchive::getAdapter('gzip');
             if ($adapter) {
                 $config = MFactory::getConfig();
                 $tmpfname = $config->get('tmp_path') . '/' . uniqid('gzip');
                 $gzresult = $adapter->extract($archivename, $tmpfname);
                 if ($gzresult instanceof Exception) {
                     @unlink($tmpfname);
                     return false;
                 }
                 if ($untar) {
                     // Try to untar the file
                     $tadapter = MArchive::getAdapter('tar');
                     if ($tadapter) {
                         $result = $tadapter->extract($tmpfname, $extractdir);
                     }
                 } else {
                     $path = MPath::clean($extractdir);
                     MFolder::create($path);
                     $result = MFile::copy($tmpfname, $path . '/' . MFile::stripExt(MFile::getName(strtolower($archivename))), null, 1);
                 }
                 @unlink($tmpfname);
             }
             break;
         case 'tbz2':
             // This format is a tarball bzip2'd
             $untar = true;
         case 'bz2':
         case 'bzip2':
             // This may just be an individual file (e.g. sql script)
             $adapter = MArchive::getAdapter('bzip2');
             if ($adapter) {
                 $config = MFactory::getConfig();
                 $tmpfname = $config->get('tmp_path') . '/' . uniqid('bzip2');
                 $bzresult = $adapter->extract($archivename, $tmpfname);
                 if ($bzresult instanceof Exception) {
                     @unlink($tmpfname);
                     return false;
                 }
                 if ($untar) {
                     // Try to untar the file
                     $tadapter = MArchive::getAdapter('tar');
                     if ($tadapter) {
                         $result = $tadapter->extract($tmpfname, $extractdir);
                     }
                 } else {
                     $path = MPath::clean($extractdir);
                     MFolder::create($path);
                     $result = MFile::copy($tmpfname, $path . '/' . MFile::stripExt(MFile::getName(strtolower($archivename))), null, 1);
                 }
                 @unlink($tmpfname);
             }
             break;
         default:
             MError::raiseWarning(10, MText::_('MLIB_FILESYSTEM_UNKNOWNARCHIVETYPE'));
             return false;
             break;
     }
     if (!$result || $result instanceof Exception) {
         return false;
     }
     return true;
 }
Exemplo n.º 29
0
 public function getName()
 {
     if (empty($this->_name)) {
         $r = null;
         if (!preg_match('/View((view)*(.*(view)?.*))$/i', get_class($this), $r)) {
             MError::raiseError(500, MText::_('MLIB_APPLICATION_ERROR_VIEW_GET_NAME'));
         }
         if (strpos($r[3], "view")) {
             MError::raiseWarning('SOME_ERROR_CODE', MText::_('MLIB_APPLICATION_ERROR_VIEW_GET_NAME_SUBSTRING'));
         }
         $this->_name = strtolower($r[3]);
     }
     return $this->_name;
 }
Exemplo n.º 30
0
 protected function getInput()
 {
     // Get the client id.
     $clientId = $this->element['client_id'];
     if (is_null($clientId) && $this->form instanceof MForm) {
         $clientId = $this->form->getValue('client_id');
     }
     $clientId = (int) $clientId;
     $client = MApplicationHelper::getClientInfo($clientId);
     // Get the module.
     $module = (string) $this->element['module'];
     if (empty($module) && $this->form instanceof MForm) {
         $module = $this->form->getValue('module');
     }
     $module = preg_replace('#\\W#', '', $module);
     // Get the template.
     $template = (string) $this->element['template'];
     $template = preg_replace('#\\W#', '', $template);
     // Get the style.
     if ($this->form instanceof MForm) {
         $template_style_id = $this->form->getValue('template_style_id');
     }
     $template_style_id = preg_replace('#\\W#', '', $template_style_id);
     // If an extension and view are present build the options.
     if ($module && $client) {
         // Load language file
         $lang = MFactory::getLanguage();
         $lang->load($module . '.sys', $client->path, null, false, false) || $lang->load($module . '.sys', $client->path . '/modules/' . $module, null, false, false) || $lang->load($module . '.sys', $client->path, $lang->getDefault(), false, false) || $lang->load($module . '.sys', $client->path . '/modules/' . $module, $lang->getDefault(), false, false);
         // Get the database object and a new query object.
         $db = MFactory::getDBO();
         $query = $db->getQuery(true);
         // Build the query.
         $query->select('element, name');
         $query->from('#__extensions as e');
         $query->where('e.client_id = ' . (int) $clientId);
         $query->where('e.type = ' . $db->quote('template'));
         $query->where('e.enabled = 1');
         if ($template) {
             $query->where('e.element = ' . $db->quote($template));
         }
         if ($template_style_id) {
             $query->join('LEFT', '#__template_styles as s on s.template=e.element');
             $query->where('s.id=' . (int) $template_style_id);
         }
         // Set the query and load the templates.
         $db->setQuery($query);
         $templates = $db->loadObjectList('element');
         // Check for a database error.
         if ($db->getErrorNum()) {
             MError::raiseWarning(500, $db->getErrorMsg());
         }
         // Build the search paths for module layouts.
         $module_path = MPath::clean($client->path . '/modules/' . $module . '/tmpl');
         // Prepare array of component layouts
         $module_layouts = array();
         // Prepare the grouped list
         $groups = array();
         // Add the layout options from the module path.
         if (is_dir($module_path) && ($module_layouts = MFolder::files($module_path, '^[^_]*\\.php$'))) {
             // Create the group for the module
             $groups['_'] = array();
             $groups['_']['id'] = $this->id . '__';
             $groups['_']['text'] = MText::sprintf('MOPTION_FROM_MODULE');
             $groups['_']['items'] = array();
             foreach ($module_layouts as $file) {
                 // Add an option to the module group
                 $value = MFile::stripExt($file);
                 $text = $lang->hasKey($key = strtoupper($module . '_LAYOUT_' . $value)) ? MText::_($key) : $value;
                 $groups['_']['items'][] = MHtml::_('select.option', '_:' . $value, $text);
             }
         }
         // Loop on all templates
         if ($templates) {
             foreach ($templates as $template) {
                 // Load language file
                 $lang->load('tpl_' . $template->element . '.sys', $client->path, null, false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, null, false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path, $lang->getDefault(), false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, $lang->getDefault(), false, false);
                 $template_path = MPath::clean($client->path . '/templates/' . $template->element . '/html/' . $module);
                 // Add the layout options from the template path.
                 if (is_dir($template_path) && ($files = MFolder::files($template_path, '^[^_]*\\.php$'))) {
                     foreach ($files as $i => $file) {
                         // Remove layout that already exist in component ones
                         if (in_array($file, $module_layouts)) {
                             unset($files[$i]);
                         }
                     }
                     if (count($files)) {
                         // Create the group for the template
                         $groups[$template->element] = array();
                         $groups[$template->element]['id'] = $this->id . '_' . $template->element;
                         $groups[$template->element]['text'] = MText::sprintf('MOPTION_FROM_TEMPLATE', $template->name);
                         $groups[$template->element]['items'] = array();
                         foreach ($files as $file) {
                             // Add an option to the template group
                             $value = MFile::stripExt($file);
                             $text = $lang->hasKey($key = strtoupper('TPL_' . $template->element . '_' . $module . '_LAYOUT_' . $value)) ? MText::_($key) : $value;
                             $groups[$template->element]['items'][] = MHtml::_('select.option', $template->element . ':' . $value, $text);
                         }
                     }
                 }
             }
         }
         // Compute attributes for the grouped list
         $attr = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
         // Prepare HTML code
         $html = array();
         // Compute the current selected values
         $selected = array($this->value);
         // Add a grouped list
         $html[] = MHtml::_('select.groupedlist', $groups, $this->name, array('id' => $this->id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $selected));
         return implode($html);
     } else {
         return '';
     }
 }