Esempio n. 1
0
 public function bind($array, $ignore = '')
 {
     if (key_exists('params', $array) && is_array($array['params'])) {
         $registry = new MRegistry();
         $registry->loadArray($array['params']);
         $array['params'] = (string) $registry;
     }
     // Attempt to bind the data.
     $return = parent::bind($array, $ignore);
     // Load the real group data based on the bound ids.
     if ($return && !empty($this->groups)) {
         // Set the group ids.
         MArrayHelper::toInteger($this->groups);
         // Get the titles for the user groups.
         $query = $this->_db->getQuery(true);
         $query->select($this->_db->quoteName('id'));
         $query->select($this->_db->quoteName('title'));
         $query->from($this->_db->quoteName('#__usergroups'));
         $query->where($this->_db->quoteName('id') . ' = ' . implode(' OR ' . $this->_db->quoteName('id') . ' = ', $this->groups));
         $this->_db->setQuery($query);
         // Set the titles for the user groups.
         $this->groups = $this->_db->loadAssocList('id', 'id');
         // Check for a database error.
         if ($this->_db->getErrorNum()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
     }
     return $return;
 }
Esempio n. 2
0
 public function __construct($options = array())
 {
     // Load the menu items
     $this->load();
     foreach ($this->_items as $item) {
         if ($item->home) {
             $this->_default[trim($item->language)] = $item->id;
         }
         // Decode the item params
         $result = new MRegistry();
         $result->loadString($item->params);
         $item->params = $result;
     }
 }
Esempio n. 3
0
 public function render($module, $attribs = array(), $content = null)
 {
     if (!is_object($module)) {
         $title = isset($attribs['title']) ? $attribs['title'] : null;
         $module_id = isset($attribs['number']) ? $attribs['number'] : null;
         $module = MModuleHelper::getModule($module, $title, $module_id);
         if (!is_object($module)) {
             if (is_null($content)) {
                 return '';
             } else {
                 $tmp = $module;
                 $module = new stdClass();
                 $module->params = null;
                 $module->module = $tmp;
                 $module->id = 0;
                 $module->user = 0;
             }
         }
     }
     // Get the user and configuration object
     // $user = MFactory::getUser();
     $conf = MFactory::getConfig();
     // Set the module content
     if (!is_null($content)) {
         $module->content = $content;
     }
     // Get module parameters
     $params = new MRegistry();
     $params->loadString($module->params);
     // Use parameters from template
     if (isset($attribs['params'])) {
         $template_params = new MRegistry();
         $template_params->loadString(html_entity_decode($attribs['params'], ENT_COMPAT, 'UTF-8'));
         $params->merge($template_params);
         $module = clone $module;
         $module->params = (string) $params;
     }
     $contents = MModuleHelper::renderModule($module, $attribs);
     return $contents;
 }
Esempio n. 4
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;
 }
Esempio n. 5
0
 protected static function _load($option)
 {
     if (isset(self::$components[$option]) and self::$components[$option] !== null) {
         return true;
     }
     mimport('framework.filesystem.folder');
     $folders = MFolder::folders(MPATH_WP_PLG);
     if (empty($folders)) {
         self::$components[$option] = new stdClass();
         return false;
     }
     self::$components = array();
     $n = count($folders);
     for ($i = 0; $i < $n; $i++) {
         $folder = @$folders[$i];
         if (empty($folder)) {
             continue;
         }
         if (substr($folder, 0, 4) != 'miwo') {
             continue;
         }
         $com = new stdClass();
         $com->id = $i;
         $com->option = 'com_' . $folder;
         $com->params = MFactory::getWOption($folder);
         $com->enabled = 1;
         // Convert the params to an object.
         if (is_string($com->params)) {
             $temp = new MRegistry();
             $temp->loadString($com->params);
             $com->params = $temp;
         }
         self::$components[$com->option] = $com;
     }
     return true;
 }
Esempio n. 6
0
 protected static function createConfig($file, $type = 'PHP', $namespace = '')
 {
     if (is_file($file)) {
         include_once $file;
     }
     // Create the registry with a default namespace of config
     $registry = new MRegistry();
     // Sanitize the namespace.
     $namespace = ucfirst((string) preg_replace('/[^A-Z_]/i', '', $namespace));
     // Build the config name.
     $name = 'MConfig' . $namespace;
     // Handle the PHP configuration type.
     if ($type == 'PHP' && class_exists($name)) {
         // Create the MConfig object
         $config = new $name();
         // Load the configuration values into the registry
         $registry->loadObject($config);
     }
     return $registry;
 }
Esempio n. 7
0
 public static function renderModule($module, $attribs = array())
 {
     static $chrome;
     if (constant('MDEBUG')) {
         MProfiler::getInstance('Application')->mark('beforeRenderModule ' . $module->module . ' (' . $module->title . ')');
     }
     $app = MFactory::getApplication();
     // Record the scope.
     $scope = $app->scope;
     // Set scope to component name
     $app->scope = $module->module;
     // Get module parameters
     $params = new MRegistry();
     $params->loadString($module->params);
     // Get module path
     $module->module = preg_replace('/[^A-Z0-9_\\.-]/i', '', $module->module);
     $path = MPATH_MODULES . '/' . $module->module . '/' . $module->module . '.php';
     // Load the module
     // $module->user is a check for 1.0 custom modules and is deprecated refactoring
     if (empty($module->user) && file_exists($path)) {
         $lang = MFactory::getLanguage();
         // 1.5 or Core then 1.6 3PD
         $lang->load($module->module, MPATH_BASE, null, false, true) || $lang->load($module->module, dirname($path), null, false, true);
         $content = '';
         ob_start();
         include $path;
         $module->content = ob_get_contents() . $content;
         ob_end_clean();
     }
     // Load the module chrome functions
     if (!$chrome) {
         $chrome = array();
     }
     include_once MPATH_MODULES . '/modules.php';
     $chromePath = MPATH_THEMES . '/' . $app->getTemplate() . '/html/modules.php';
     if (!isset($chrome[$chromePath])) {
         if (file_exists($chromePath)) {
             include_once $chromePath;
         }
         $chrome[$chromePath] = true;
     }
     // Make sure a style is set
     if (!isset($attribs['style'])) {
         $attribs['style'] = 'none';
     }
     foreach (explode(' ', $attribs['style']) as $style) {
         $chromeMethod = 'modChrome_' . $style;
         // Apply chrome and render module
         if (function_exists($chromeMethod)) {
             $module->style = $attribs['style'];
             ob_start();
             $chromeMethod($module, $params, $attribs);
             $module->content = ob_get_contents();
             ob_end_clean();
         }
     }
     //revert the scope
     $app->scope = $scope;
     if (constant('MDEBUG')) {
         MProfiler::getInstance('Application')->mark('afterRenderModule ' . $module->module . ' (' . $module->title . ')');
     }
     return $module->content;
 }
Esempio n. 8
0
 public function getItem($pk = null)
 {
     $pk = !empty($pk) ? $pk : (int) $this->getState($this->getName() . '.id');
     $table = $this->getTable();
     if ($pk > 0) {
         // Attempt to load the row.
         $return = $table->load($pk);
         // Check for a table object error.
         if ($return === false && $table->getError()) {
             $this->setError($table->getError());
             return false;
         }
     }
     // Convert to the MObject before adding other data.
     $properties = $table->getProperties(1);
     $item = MArrayHelper::toObject($properties, 'MObject');
     if (property_exists($item, 'params')) {
         $registry = new MRegistry();
         $registry->loadString($item->params);
         $item->params = $registry->toArray();
     }
     return $item;
 }