Ejemplo n.º 1
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;
             }
         }
     }
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
0
 public function getData()
 {
     $db = MFactory::getDbo();
     $html = '';
     if (empty($this->_query)) {
         return $html;
     }
     if (preg_match('/REPLACE PREFIX (.*) TO (.*)/', $this->_query)) {
         self::_replacePrefix($db, $db, $this->_query);
     } else {
         $query_arr = self::_splitSQL($this->_query);
         for ($i = 0; $i <= count($query_arr) - 1; $i++) {
             if (empty($query_arr[$i])) {
                 continue;
             }
             $html .= self::_getHtmlTable($query_arr[$i], $i, $db);
         }
     }
     return $html;
 }
Ejemplo n.º 5
0
 public function deleteTables()
 {
     if (!MFile::exists($filename = MPATH_WP_PLG . '/' . $this->context . '/admin/uninstall.sql')) {
         return null;
     }
     $db = MFactory::getDbo();
     $file_content = file($filename);
     if (empty($file_content)) {
         return null;
     }
     $query = '';
     foreach ($file_content as $sql_line) {
         $tsl = trim($sql_line);
         if ($tsl != '' && (strpos($tsl, '--') != 0 || strpos($tsl, '--') != 1) && substr($tsl, 0, 1) != '#') {
             $query .= $sql_line;
             if (preg_match('/;\\s*$/', $sql_line)) {
                 $db->setQuery($query);
                 $db->query();
                 $query = '';
             }
         }
     }
 }
Ejemplo n.º 6
0
 public function display($tpl = null)
 {
     $db = MFactory::getDbo();
     $task = MRequest::getCmd('task');
     $table = MiwosqlHelper::getVar('tbl');
     $query = MiwosqlHelper::getVar('qry');
     $id = MRequest::getInt('id', MRequest::getInt('id', null, 'post'), 'get');
     $key = MRequest::getCmd('key', MRequest::getCmd('key', null, 'post'), 'get');
     $document = MFactory::getDocument();
     $document->addStyleSheet(MURL_MIWOSQL . '/admin/assets/css/miwosql.css');
     // Toolbar
     MToolBarHelper::title(MText::_('MiwoSQL') . ': <small><small> ' . $table . ' [ ' . $key . ' = ' . $id . ' ]' . ' </small></small>', 'miwosql');
     MToolBarHelper::apply();
     MToolBarHelper::save();
     MToolBarHelper::divider();
     MToolBarHelper::cancel();
     if ($task == 'edit') {
         $fld_value = '$value = $this->rows[$this->id][$field];';
     } else {
         $fld_value = '$value = "";';
     }
     list($rows, $last_key_vol) = $this->get('Data');
     $this->task = $task;
     $this->id = $id;
     $this->key = $key;
     $this->table = $table;
     $this->query = $query;
     $this->fld_value = $fld_value;
     $this->last_key_vol = $last_key_vol;
     $this->rows = $rows;
     $fields = $this->get('Fields');
     if (!MiwosqlHelper::is30()) {
         $fields = $fields[$this->table];
     }
     $this->fields = $fields;
     parent::display($tpl);
 }
Ejemplo n.º 7
0
 public static function categories($extension, $config = array('filter.published' => array(0, 1)))
 {
     $hash = md5($extension . '.' . serialize($config));
     if (!isset(self::$items[$hash])) {
         $config = (array) $config;
         $db = MFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select('a.id, a.title, a.level, a.parent_id');
         $query->from('#__categories AS a');
         $query->where('a.parent_id > 0');
         // Filter on extension.
         $query->where('extension = ' . $db->quote($extension));
         // Filter on the published state
         if (isset($config['filter.published'])) {
             if (is_numeric($config['filter.published'])) {
                 $query->where('a.published = ' . (int) $config['filter.published']);
             } elseif (is_array($config['filter.published'])) {
                 MArrayHelper::toInteger($config['filter.published']);
                 $query->where('a.published IN (' . implode(',', $config['filter.published']) . ')');
             }
         }
         $query->order('a.lft');
         $db->setQuery($query);
         $items = $db->loadObjectList();
         // Assemble the list options.
         self::$items[$hash] = array();
         foreach ($items as &$item) {
             $repeat = $item->level - 1 >= 0 ? $item->level - 1 : 0;
             $item->title = str_repeat('- ', $repeat) . $item->title;
             self::$items[$hash][] = MHtml::_('select.option', $item->id, $item->title);
         }
         // Special "Add to root" option:
         self::$items[$hash][] = MHtml::_('select.option', '1', MText::_('MLIB_HTML_ADD_TO_ROOT'));
     }
     return self::$items[$hash];
 }
Ejemplo n.º 8
0
 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;
 }
Ejemplo n.º 9
0
 public static function users($name, $active, $nouser = 0, $javascript = null, $order = 'name', $reg = 1)
 {
     $db = MFactory::getDbo();
     $query = $db->getQuery(true);
     if ($reg) {
         // Does not include registered users in the list
         // @deprecated
         $query->where('m.group_id != 2');
     }
     $query->select('u.id AS value, u.name AS text');
     $query->from('#__users AS u');
     $query->join('LEFT', '#__user_usergroup_map AS m ON m.user_id = u.id');
     $query->where('u.block = 0');
     $query->order($order);
     $db->setQuery($query);
     if ($nouser) {
         $users[] = MHtml::_('select.option', '0', MText::_('MOPTION_NO_USER'));
         $users = array_merge($users, $db->loadObjectList());
     } else {
         $users = $db->loadObjectList();
     }
     $users = MHtml::_('select.genericlist', $users, $name, array('list.attr' => 'class="inputbox" size="1" ' . $javascript, 'list.select' => $active));
     return $users;
 }
Ejemplo n.º 10
0
 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;
 }
Ejemplo n.º 11
0
 protected function getInput()
 {
     MHtml::_('behavior.tooltip');
     // Initialise some field attributes.
     $section = $this->element['section'] ? (string) $this->element['section'] : '';
     $component = $this->element['component'] ? (string) $this->element['component'] : '';
     $assetField = $this->element['asset_field'] ? (string) $this->element['asset_field'] : 'asset_id';
     // Get the actions for the asset.
     $actions = MAccess::getActions($component, $section);
     // Iterate over the children and add to the actions.
     foreach ($this->element->children() as $el) {
         if ($el->getName() == 'action') {
             $actions[] = (object) array('name' => (string) $el['name'], 'title' => (string) $el['title'], 'description' => (string) $el['description']);
         }
     }
     // Get the explicit rules for this asset.
     if ($section == 'component') {
         // Need to find the asset id by the name of the component.
         $db = MFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select($db->quoteName('id'));
         $query->from($db->quoteName('#__assets'));
         $query->where($db->quoteName('name') . ' = ' . $db->quote($component));
         $db->setQuery($query);
         $assetId = (int) $db->loadResult();
         if ($error = $db->getErrorMsg()) {
             MError::raiseNotice(500, $error);
         }
     } else {
         // Find the asset id of the content.
         // Note that for global configuration, com_config injects asset_id = 1 into the form.
         $assetId = $this->form->getValue($assetField);
     }
     // Use the compact form for the content rules (deprecated).
     //if (!empty($component) && $section != 'component') {
     //	return MHtml::_('rules.assetFormWidget', $actions, $assetId, $assetId ? null : $component, $this->name, $this->id);
     //}
     // Full width format.
     // Get the rules for just this asset (non-recursive).
     $assetRules = MAccess::getAssetRules($assetId);
     // Get the available user groups.
     $groups = $this->getUserGroups();
     // Build the form control.
     $curLevel = 0;
     // Prepare output
     $html = array();
     $html[] = '<div id="permissions-sliders" class="pane-sliders">';
     $html[] = '<p class="rule-desc">' . MText::_('MLIB_RULES_SETTINGS_DESC') . '</p>';
     $html[] = '<ul id="rules">';
     // Start a row for each user group.
     foreach ($groups as $group) {
         $difLevel = $group->level - $curLevel;
         if ($difLevel > 0) {
             $html[] = '<li><ul>';
         } elseif ($difLevel < 0) {
             $html[] = str_repeat('</ul></li>', -$difLevel);
         }
         $html[] = '<li>';
         $html[] = '<div class="panel">';
         $html[] = '<h3 class="pane-toggler title"><a href="javascript:void(0);"><span>';
         $html[] = str_repeat('<span class="level">|&ndash;</span> ', $curLevel = $group->level) . $group->text;
         $html[] = '</span></a></h3>';
         $html[] = '<div class="pane-slider content pane-hide">';
         $html[] = '<div class="mypanel">';
         $html[] = '<table class="group-rules">';
         $html[] = '<thead>';
         $html[] = '<tr>';
         $html[] = '<th class="actions" id="actions-th' . $group->value . '">';
         $html[] = '<span class="acl-action">' . MText::_('MLIB_RULES_ACTION') . '</span>';
         $html[] = '</th>';
         $html[] = '<th class="settings" id="settings-th' . $group->value . '">';
         $html[] = '<span class="acl-action">' . MText::_('MLIB_RULES_SELECT_SETTING') . '</span>';
         $html[] = '</th>';
         // The calculated setting is not shown for the root group of global configuration.
         $canCalculateSettings = $group->parent_id || !empty($component);
         if ($canCalculateSettings) {
             $html[] = '<th id="aclactionth' . $group->value . '">';
             $html[] = '<span class="acl-action">' . MText::_('MLIB_RULES_CALCULATED_SETTING') . '</span>';
             $html[] = '</th>';
         }
         $html[] = '</tr>';
         $html[] = '</thead>';
         $html[] = '<tbody>';
         foreach ($actions as $action) {
             $html[] = '<tr>';
             $html[] = '<td headers="actions-th' . $group->value . '">';
             $html[] = '<label class="hasTip" for="' . $this->id . '_' . $action->name . '_' . $group->value . '" title="' . htmlspecialchars(MText::_($action->title) . '::' . MText::_($action->description), ENT_COMPAT, 'UTF-8') . '">';
             $html[] = MText::_($action->title);
             $html[] = '</label>';
             $html[] = '</td>';
             $html[] = '<td headers="settings-th' . $group->value . '">';
             $html[] = '<select name="' . $this->name . '[' . $action->name . '][' . $group->value . ']" id="' . $this->id . '_' . $action->name . '_' . $group->value . '" title="' . MText::sprintf('MLIB_RULES_SELECT_ALLOW_DENY_GROUP', MText::_($action->title), trim($group->text)) . '">';
             $inheritedRule = MAccess::checkGroup($group->value, $action->name, $assetId);
             // Get the actual setting for the action for this group.
             $assetRule = $assetRules->allow($action->name, $group->value);
             // Build the dropdowns for the permissions sliders
             // The parent group has "Not Set", all children can rightly "Inherit" from that.
             $html[] = '<option value=""' . ($assetRule === null ? ' selected="selected"' : '') . '>' . MText::_(empty($group->parent_id) && empty($component) ? 'MLIB_RULES_NOT_SET' : 'MLIB_RULES_INHERITED') . '</option>';
             $html[] = '<option value="1"' . ($assetRule === true ? ' selected="selected"' : '') . '>' . MText::_('MLIB_RULES_ALLOWED') . '</option>';
             $html[] = '<option value="0"' . ($assetRule === false ? ' selected="selected"' : '') . '>' . MText::_('MLIB_RULES_DENIED') . '</option>';
             $html[] = '</select>&#160; ';
             // If this asset's rule is allowed, but the inherited rule is deny, we have a conflict.
             if ($assetRule === true && $inheritedRule === false) {
                 $html[] = MText::_('MLIB_RULES_CONFLICT');
             }
             $html[] = '</td>';
             // Build the Calculated Settings column.
             // The inherited settings column is not displayed for the root group in global configuration.
             if ($canCalculateSettings) {
                 $html[] = '<td headers="aclactionth' . $group->value . '">';
                 // This is where we show the current effective settings considering currrent group, path and cascade.
                 // Check whether this is a component or global. Change the text slightly.
                 if (MAccess::checkGroup($group->value, 'core.admin', $assetId) !== true) {
                     if ($inheritedRule === null) {
                         $html[] = '<span class="icon-16-unset">' . MText::_('MLIB_RULES_NOT_ALLOWED') . '</span>';
                     } elseif ($inheritedRule === true) {
                         $html[] = '<span class="icon-16-allowed">' . MText::_('MLIB_RULES_ALLOWED') . '</span>';
                     } elseif ($inheritedRule === false) {
                         if ($assetRule === false) {
                             $html[] = '<span class="icon-16-denied">' . MText::_('MLIB_RULES_NOT_ALLOWED') . '</span>';
                         } else {
                             $html[] = '<span class="icon-16-denied"><span class="icon-16-locked">' . MText::_('MLIB_RULES_NOT_ALLOWED_LOCKED') . '</span></span>';
                         }
                     }
                 } elseif (!empty($component)) {
                     $html[] = '<span class="icon-16-allowed"><span class="icon-16-locked">' . MText::_('MLIB_RULES_ALLOWED_ADMIN') . '</span></span>';
                 } else {
                     // Special handling for  groups that have global admin because they can't  be denied.
                     // The admin rights can be changed.
                     if ($action->name === 'core.admin') {
                         $html[] = '<span class="icon-16-allowed">' . MText::_('MLIB_RULES_ALLOWED') . '</span>';
                     } elseif ($inheritedRule === false) {
                         // Other actions cannot be changed.
                         $html[] = '<span class="icon-16-denied"><span class="icon-16-locked">' . MText::_('MLIB_RULES_NOT_ALLOWED_ADMIN_CONFLICT') . '</span></span>';
                     } else {
                         $html[] = '<span class="icon-16-allowed"><span class="icon-16-locked">' . MText::_('MLIB_RULES_ALLOWED_ADMIN') . '</span></span>';
                     }
                 }
                 $html[] = '</td>';
             }
             $html[] = '</tr>';
         }
         $html[] = '</tbody>';
         $html[] = '</table></div>';
         $html[] = '</div></div>';
         $html[] = '</li>';
     }
     $html[] = str_repeat('</ul></li>', $curLevel);
     $html[] = '</ul><div class="rule-notes">';
     if ($section == 'component' || $section == null) {
         $html[] = MText::_('MLIB_RULES_SETTING_NOTES');
     } else {
         $html[] = MText::_('MLIB_RULES_SETTING_NOTES_ITEM');
     }
     $html[] = '</div></div>';
     $js = "jQuery(document).ready(function () { new Fx.Accordion(\$\$('div#permissions-sliders.pane-sliders .panel h3.pane-toggler')," . "\$\$('div#permissions-sliders.pane-sliders .panel div.pane-slider'), {onActive: function(toggler, i) {toggler.addClass('pane-toggler-down');" . "toggler.removeClass('pane-toggler');i.addClass('pane-down');i.removeClass('pane-hide');Cookie.write('jpanesliders_permissions-sliders" . $component . "',\$\$('div#permissions-sliders.pane-sliders .panel h3').indexOf(toggler));}," . "onBackground: function(toggler, i) {toggler.addClass('pane-toggler');toggler.removeClass('pane-toggler-down');i.addClass('pane-hide');" . "i.removeClass('pane-down');}, duration: 300, display: " . MRequest::getInt('jpanesliders_permissions-sliders' . $component, 0, 'cookie') . ", show: " . MRequest::getInt('jpanesliders_permissions-sliders' . $component, 0, 'cookie') . ", alwaysHide:true, opacity: false}); });";
     MFactory::getDocument()->addScriptDeclaration($js);
     return implode("\n", $html);
 }
Ejemplo n.º 12
0
 public function __construct($config = array())
 {
     // Guess the option from the class name (Option)Model(View).
     if (empty($this->option)) {
         $r = null;
         if (!preg_match('/(.*)Model/i', get_class($this), $r)) {
             MError::raiseError(500, MText::_('MLIB_APPLICATION_ERROR_MODEL_GET_NAME'));
         }
         $this->option = 'com_' . strtolower($r[1]);
     }
     // Set the view name
     if (empty($this->name)) {
         if (array_key_exists('name', $config)) {
             $this->name = $config['name'];
         } else {
             $this->name = $this->getName();
         }
     }
     // Set the model state
     if (array_key_exists('state', $config)) {
         $this->state = $config['state'];
     } else {
         $this->state = new MObject();
     }
     // Set the model dbo
     if (array_key_exists('dbo', $config)) {
         $this->_db = $config['dbo'];
     } else {
         $this->_db = MFactory::getDbo();
     }
     // Set the default view search path
     if (array_key_exists('table_path', $config)) {
         $this->addTablePath($config['table_path']);
     } elseif (defined('MPATH_COMPONENT_ADMINISTRATOR')) {
         $this->addTablePath(MPATH_COMPONENT_ADMINISTRATOR . '/tables');
     }
     // Set the internal state marker - used to ignore setting state from the request
     if (!empty($config['ignore_request'])) {
         $this->__state_set = true;
     }
     // Set the clean cache event
     if (isset($config['event_clean_cache'])) {
         $this->event_clean_cache = $config['event_clean_cache'];
     } elseif (empty($this->event_clean_cache)) {
         $this->event_clean_cache = 'onContentCleanCache';
     }
 }