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; } } } }
public static function genericordering($sql, $chop = '30') { $db = MFactory::getDbo(); $options = array(); $db->setQuery($sql); $items = $db->loadObjectList(); // Check for a database error. if ($db->getErrorNum()) { MError::raiseNotice(500, $db->getErrorMsg()); return false; } if (empty($items)) { $options[] = MHtml::_('select.option', 1, MText::_('MOPTION_ORDER_FIRST')); return $options; } $options[] = MHtml::_('select.option', 0, '0 ' . MText::_('MOPTION_ORDER_FIRST')); for ($i = 0, $n = count($items); $i < $n; $i++) { $items[$i]->text = MText::_($items[$i]->text); if (MString::strlen($items[$i]->text) > $chop) { $text = MString::substr($items[$i]->text, 0, $chop) . "..."; } else { $text = $items[$i]->text; } $options[] = MHtml::_('select.option', $items[$i]->value, $items[$i]->value . '. ' . $text); } $options[] = MHtml::_('select.option', $items[$i - 1]->value + 1, $items[$i - 1]->value + 1 . ' ' . MText::_('MOPTION_ORDER_LAST')); return $options; }
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; }
protected function getConnection() { if ((extension_loaded('memcached') && class_exists('Memcached')) != true) { return false; } $config = MFactory::getConfig(); $this->_persistent = $config->get('memcache_persist', true); $this->_compress = $config->get('memcache_compress', false) == false ? 0 : Memcached::OPT_COMPRESSION; $server = array(); $server['host'] = $config->get('memcache_server_host', 'localhost'); $server['port'] = $config->get('memcache_server_port', 11211); if ($this->_persistent) { $session = MFactory::getSession(); self::$_db = new Memcached($session->getId()); } else { self::$_db = new Memcached(); } $memcachedtest = self::$_db->addServer($server['host'], $server['port']); if ($memcachedtest == false) { return MError::raiseError(404, "Could not connect to memcached server"); } self::$_db->setOption(Memcached::OPT_COMPRESSION, $this->_compress); if (self::$_db->get($this->_hash . '-index') === false) { $empty = array(); self::$_db->set($this->_hash . '-index', $empty, 0); } return; }
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); }
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; }
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; }
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; }
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); }
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; }
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; }
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')); } }
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)); } }
public static function getInstance($type = 'output', $options = array()) { MCacheController::addIncludePath(MPATH_WP_CNT . '/miwi/framework/cache/controller'); $type = strtolower(preg_replace('/[^A-Z0-9_\\.-]/i', '', $type)); $class = 'MCacheController' . ucfirst($type); if (!class_exists($class)) { mimport('framework.filesystem.path'); if ($path = MPath::find(MCacheController::addIncludePath(), strtolower($type) . '.php')) { include_once $path; } else { MError::raiseError(500, 'Unable to load Cache Controller: ' . $type); } } return new $class($options); }
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; }
public function __construct($msg, $code = 0, $level = null, $info = null, $backtrace = false) { // Deprecation warning. MLog::add('MException is deprecated.', MLog::WARNING, 'deprecated'); $this->level = $level; $this->code = $code; $this->message = $msg; if ($info != null) { $this->info = $info; } if ($backtrace && function_exists('debug_backtrace')) { $this->backtrace = debug_backtrace(); for ($i = count($this->backtrace) - 1; $i >= 0; --$i) { ++$i; if (isset($this->backtrace[$i]['file'])) { $this->file = $this->backtrace[$i]['file']; } if (isset($this->backtrace[$i]['line'])) { $this->line = $this->backtrace[$i]['line']; } if (isset($this->backtrace[$i]['class'])) { $this->class = $this->backtrace[$i]['class']; } if (isset($this->backtrace[$i]['function'])) { $this->function = $this->backtrace[$i]['function']; } if (isset($this->backtrace[$i]['type'])) { $this->type = $this->backtrace[$i]['type']; } $this->args = false; if (isset($this->backtrace[$i]['args'])) { $this->args = $this->backtrace[$i]['args']; } break; } } // Store exception for debugging purposes! MError::addToStack($this); parent::__construct($msg, (int) $code); }
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]; }
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; }
protected function getConnection() { if ((extension_loaded('memcache') && class_exists('Memcache')) != true) { return false; } $config = MFactory::getConfig(); $this->_persistent = $config->get('memcache_persist', true); $this->_compress = $config->get('memcache_compress', false) == false ? 0 : MEMCACHE_COMPRESSED; $server = array(); $server['host'] = $config->get('memcache_server_host', 'localhost'); $server['port'] = $config->get('memcache_server_port', 11211); // Create the memcache connection self::$_db = new Memcache(); self::$_db->addServer($server['host'], $server['port'], $this->_persistent); $memcachetest = @self::$_db->connect($server['host'], $server['port']); if ($memcachetest == false) { return MError::raiseError(404, "Could not connect to memcache server"); } if (self::$_db->get($this->_hash . '-index') === false) { $empty = array(); self::$_db->set($this->_hash . '-index', $empty, $this->_compress, 0); } return; }
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; }
public function execute() { if (!is_resource($this->connection)) { if (MError::$legacy) { if ($this->debug) { MError::raiseError(500, 'MDatabaseMySQL::query: ' . $this->errorNum . ' - ' . $this->errorMsg); } return false; } else { MLog::add(MText::sprintf('MLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), MLog::ERROR, 'database'); throw new MDatabaseException($this->errorMsg, $this->errorNum); } } // Take a local copy so that we don't modify the original query and cause issues later $sql = $this->replacePrefix((string) $this->sql); if ($this->limit > 0 || $this->offset > 0) { $sql .= ' LIMIT ' . $this->offset . ', ' . $this->limit; } // If debugging is enabled then let's log the query. if ($this->debug) { // Increment the query counter and add the query to the object queue. $this->count++; $this->log[] = $sql; MLog::add($sql, MLog::DEBUG, 'databasequery'); } // Reset the error values. $this->errorNum = 0; $this->errorMsg = ''; #for-multi-db global $wpdb; $multidb_file = MPATH_WP_CNT . '/db.php'; if (!empty($wpdb) and file_exists($multidb_file)) { $this->connection = $wpdb->db_connect($sql); #for-multi-db $sql = $wpdb->sanitize_multidb_query_tables($sql); } // Execute the query. $this->cursor = mysql_query($sql, $this->connection); // If an error occurred handle it. if (!$this->cursor) { $this->errorNum = (int) mysql_errno($this->connection); $this->errorMsg = (string) mysql_error($this->connection) . ' SQL=' . $sql; if (MError::$legacy) { if ($this->debug) { MError::raiseError(500, 'MDatabaseMySQL::query: ' . $this->errorNum . ' - ' . $this->errorMsg); } return false; } else { MLog::add(MText::sprintf('MLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), MLog::ERROR, 'databasequery'); throw new MDatabaseException($this->errorMsg, $this->errorNum); } } return $this->cursor; }
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; }
public function loadTemplate($tpl = null) { // Clear prior output $this->_output = null; $template = MFactory::getApplication()->getTemplate(); $layout = $this->getLayout(); $layoutTemplate = $this->getLayoutTemplate(); // Create the template file name based on the layout $file = isset($tpl) ? $layout . '_' . $tpl : $layout; // Clean the file name $file = preg_replace('/[^A-Z0-9_\\.-]/i', '', $file); $tpl = isset($tpl) ? preg_replace('/[^A-Z0-9_\\.-]/i', '', $tpl) : $tpl; // Load the language file for the template $lang = MFactory::getLanguage(); $lang->load('tpl_' . $template, MPATH_BASE, null, false, true) || $lang->load('tpl_' . $template, MPATH_THEMES . "/{$template}", null, false, true); // Change the template folder if alternative layout is in different template if (isset($layoutTemplate) && $layoutTemplate != '_' && $layoutTemplate != $template) { $this->_path['template'] = str_replace($template, $layoutTemplate, $this->_path['template']); } // Load the template script mimport('framework.filesystem.path'); $filetofind = $this->_createFileName('template', array('name' => $file)); $this->_template = MPath::find($this->_path['template'], $filetofind); // If alternate layout can't be found, fall back to default layout if ($this->_template == false) { $filetofind = $this->_createFileName('', array('name' => 'default' . (isset($tpl) ? '_' . $tpl : $tpl))); $this->_template = MPath::find($this->_path['template'], $filetofind); } if ($this->_template != false) { // Unset so as not to introduce into template scope unset($tpl); unset($file); // Never allow a 'this' property if (isset($this->this)) { unset($this->this); } // Start capturing output into a buffer ob_start(); // Include the requested template filename in the local scope // (this will execute the view logic). include $this->_template; // Done with the requested template; get the buffer and // clear it. $this->_output = ob_get_contents(); ob_end_clean(); return $this->_output; } else { return MError::raiseError(500, MText::sprintf('MLIB_APPLICATION_ERROR_LAYOUTFILE_NOT_FOUND', $file)); } }
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; }
public static function linkoptions($all = false, $unassigned = false) { $db = MFactory::getDbo(); $query = $db->getQuery(true); // get a list of the menu items $query->select('m.id, m.parent_id, m.title, m.menutype'); $query->from($db->quoteName('#__menu') . ' AS m'); $query->where($db->quoteName('m.published') . ' = 1'); $query->order('m.menutype, m.parent_id, m.ordering'); $db->setQuery($query); $mitems = $db->loadObjectList(); // Check for a database error. if ($db->getErrorNum()) { MError::raiseNotice(500, $db->getErrorMsg()); } if (!$mitems) { $mitems = array(); } $mitems_temp = $mitems; // Establish the hierarchy of the menu $children = array(); // First pass - collect children foreach ($mitems as $v) { $pt = $v->parent_id; $list = @$children[$pt] ? $children[$pt] : array(); array_push($list, $v); $children[$pt] = $list; } // Second pass - get an indent list of the items $list = MHtmlMenu::TreeRecurse(intval($mitems[0]->parent_id), '', array(), $children, 9999, 0, 0); // Code that adds menu name to Display of Page(s) $mitems = array(); if ($all | $unassigned) { $mitems[] = MHtml::_('select.option', '<OPTGROUP>', MText::_('MOPTION_MENUS')); if ($all) { $mitems[] = MHtml::_('select.option', 0, MText::_('MALL')); } if ($unassigned) { $mitems[] = MHtml::_('select.option', -1, MText::_('MOPTION_UNASSIGNED')); } $mitems[] = MHtml::_('select.option', '</OPTGROUP>'); } $lastMenuType = null; $tmpMenuType = null; foreach ($list as $list_a) { if ($list_a->menutype != $lastMenuType) { if ($tmpMenuType) { $mitems[] = MHtml::_('select.option', '</OPTGROUP>'); } $mitems[] = MHtml::_('select.option', '<OPTGROUP>', $list_a->menutype); $lastMenuType = $list_a->menutype; $tmpMenuType = $list_a->menutype; } $mitems[] = MHtml::_('select.option', $list_a->id, $list_a->title); } if ($lastMenuType !== null) { $mitems[] = MHtml::_('select.option', '</OPTGROUP>'); } return $mitems; }
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; }
public static function assetgroups($config = array()) { if (empty(MHtmlAccess::$asset_groups)) { $db = MFactory::getDbo(); $query = $db->getQuery(true); $query->select('a.id AS value, a.title AS text'); $query->from($db->quoteName('#__viewlevels') . ' AS a'); $query->group('a.id, a.title, a.ordering'); $query->order('a.ordering ASC'); $db->setQuery($query); MHtmlAccess::$asset_groups = $db->loadObjectList(); // Check for a database error. if ($db->getErrorNum()) { MError::raiseNotice(500, $db->getErrorMsg()); return false; } } return MHtmlAccess::$asset_groups; }
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; }
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; }
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)); }