Esempio n. 1
0
 public static function getInstance($prefix, $config = array())
 {
     if (is_object(self::$instance)) {
         return self::$instance;
     }
     // Get the environment configuration.
     $basePath = array_key_exists('base_path', $config) ? $config['base_path'] : MPATH_COMPONENT;
     $format = MRequest::getWord('format');
     $command = MRequest::getVar('task', 'display');
     // Check for array format.
     $filter = MFilterInput::getInstance();
     if (is_array($command)) {
         $command = $filter->clean(array_pop(array_keys($command)), 'cmd');
     } else {
         $command = $filter->clean($command, 'cmd');
     }
     // Check for a controller.task command.
     if (strpos($command, '.') !== false) {
         // Explode the controller.task command.
         list($type, $task) = explode('.', $command);
         // Define the controller filename and path.
         $file = self::createFileName('controller', array('name' => $type, 'format' => $format));
         $path = $basePath . '/controllers/' . $file;
         // Reset the task without the controller context.
         MRequest::setVar('task', $task);
     } else {
         // Base controller.
         $type = null;
         $task = $command;
         // Define the controller filename and path.
         $file = self::createFileName('controller', array('name' => 'controller', 'format' => $format));
         $path = $basePath . '/' . $file;
         $backupfile = self::createFileName('controller', array('name' => 'controller'));
         $backuppath = $basePath . '/' . $backupfile;
     }
     // Get the controller class name.
     $class = ucfirst($prefix) . 'Controller' . ucfirst($type);
     // Include the class if not present.
     if (!class_exists($class)) {
         // If the controller file path exists, include it.
         if (file_exists($path)) {
             require_once $path;
         } elseif (isset($backuppath) && file_exists($backuppath)) {
             require_once $backuppath;
         } else {
             throw new InvalidArgumentException(MText::sprintf('MLIB_APPLICATION_ERROR_INVALID_CONTROLLER', $type, $format));
         }
     }
     // Instantiate the class.
     if (class_exists($class)) {
         self::$instance = new $class($config);
     } else {
         throw new InvalidArgumentException(MText::sprintf('MLIB_APPLICATION_ERROR_INVALID_CONTROLLER_CLASS', $class));
     }
     return self::$instance;
 }
Esempio n. 2
0
 public function remove()
 {
     // Check for request forgeries
     MRequest::checkToken() or jexit('Invalid Token');
     $cid = MRequest::getVar('cid', array(), '', 'array');
     MArrayHelper::toInteger($cid);
     $msg = '';
     for ($i = 0, $n = count($cid); $i < $n; $i++) {
         $query = MTable::getInstance('Query', 'Table');
         if (!$query->delete($cid[$i])) {
             $msg .= $query->getError();
             $tom = "error";
         } else {
             $msg = MTEXT::_('COM_MIWOSQL_QUERY_DELETED');
             $tom = "";
         }
     }
     $this->setRedirect('index.php?option=com_miwosql&controller=queries', $msg, $tom);
 }
Esempio n. 3
0
 public function getUserStateFromRequest($key, $request, $default = null, $type = 'none')
 {
     $cur_state = $this->getUserState($key, $default);
     $new_state = MRequest::getVar($request, null, 'default', $type);
     // Save the new value only if it was set in this request.
     if ($new_state !== null) {
         $this->setUserState($key, $new_state);
     } else {
         $new_state = $cur_state;
     }
     return $new_state;
 }
Esempio n. 4
0
 protected function _start()
 {
     // Start session if not started
     if ($this->_state == 'restart') {
         session_id($this->_createId());
     } else {
         $session_name = session_name();
         if (!MRequest::getVar($session_name, false, 'COOKIE')) {
             if (MRequest::getVar($session_name)) {
                 session_id(MRequest::getVar($session_name));
                 setcookie($session_name, '', time() - 3600);
             }
         }
     }
     session_cache_limiter('none');
     session_start();
     return true;
 }
Esempio n. 5
0
 public function save($table, $query)
 {
     $key = MRequest::getCmd('key', null, 'post');
     $fields = MRequest::getVar('fields', array(), 'post', 'array');
     if (!is_null($table) && !is_null($query) && !empty($fields)) {
         $sql_save = "UPDATE {$table} SET ";
         $i = 0;
         $comma = ', ';
         $cnt = count($fields);
         foreach ($fields as $name => $val) {
             $i++;
             if ($cnt <= $i) {
                 $comma = '';
             }
             $sql_save .= "`{$name}`='" . htmlspecialchars($val, ENT_QUOTES) . "'" . $comma;
         }
         $sql_save .= " WHERE `{$key}`='" . $fields[$key] . "'";
     }
     $this->_db->setQuery($sql_save);
     $this->_db->loadAssocList();
     if (!empty($this->_db->_errorMsg)) {
         echo '<small style="color:red;">' . $this->_db->_errorMsg . '</small><br/>';
         return false;
     } else {
         return true;
     }
 }
Esempio n. 6
0
 public static function makeId()
 {
     $app = MFactory::getApplication();
     if (!empty($app->registeredurlparams)) {
         $registeredurlparams = $app->registeredurlparams;
     } else {
         return md5(serialize(MRequest::getURI()));
     }
     $registeredurlparams->format = 'WORD';
     $registeredurlparams->option = 'WORD';
     $registeredurlparams->view = 'WORD';
     $registeredurlparams->layout = 'WORD';
     $registeredurlparams->tpl = 'CMD';
     $registeredurlparams->id = 'INT';
     $safeuriaddon = new stdClass();
     foreach ($registeredurlparams as $key => $value) {
         $safeuriaddon->{$key} = MRequest::getVar($key, null, 'default', $value);
     }
     return md5(serialize($safeuriaddon));
 }
Esempio n. 7
0
 function getQueryData()
 {
     $query = MRequest::getString('ja_query', '', 'get');
     if (!empty($query)) {
         $data = new stdClass();
         $data->id = 0;
         $data->title = '';
         $data->query = base64_decode($query);
     } else {
         $cid = MRequest::getVar('cid', array(0), 'method', 'array');
         $id = $cid[0];
         $data = MTable::getInstance('Query', 'Table');
         $data->load($id);
         $data->query = base64_decode($data->query);
     }
     return $data;
 }