/** * Method to get the data that should be injected in the form. * * @return array The default data is an empty array. * @since 1.6 */ protected function loadFormData() { // Check the session for previously entered login form data. $app = JFactory::getApplication(); $data = $app->getUserState('users.login.form.data', array()); $input = $app->input; $method = $input->getMethod(); // Check for return URL from the request first if ($return = $input->{$method}->get('return', '', 'BASE64')) { $data['return'] = base64_decode($return); if (!JUri::isInternal($data['return'])) { $data['return'] = ''; } } // Set the return URL if empty. if (!isset($data['return']) || empty($data['return'])) { $data['return'] = 'index.php?option=com_users&view=profile'; } $app->setUserState('users.login.form.data', $data); $this->preprocessData('com_users.login', $data); //$user = JFactory::getUser(); // print_r($user->groups); // exit; //$data['return'] = JURI::base().'index.php/tracking-time'; // by anwar return $data; }
/** * Install an extension. * * @return void * * @since 1.5 */ public function install() { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $model = $this->getModel('install'); if ($model->install()) { $cache = JFactory::getCache('mod_menu'); $cache->clean(); // TODO: Reset the users acl here as well to kill off any missing bits. } $app = JFactory::getApplication(); $redirect_url = $app->getUserState('com_installer.redirect_url'); // Don't redirect to an external URL. if (!JUri::isInternal($redirect_url)) { $redirect_url = ''; } if (empty($redirect_url)) { $redirect_url = JRoute::_('index.php?option=com_installer&view=install', false); } else { // Wipe out the user state when we're going to redirect. $app->setUserState('com_installer.redirect_url', ''); $app->setUserState('com_installer.message', ''); $app->setUserState('com_installer.extension_message', ''); } $this->setRedirect($redirect_url); }
/** * Update a set of extensions. * * @return void * * @since 1.6 */ public function update() { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); /** @var InstallerModelUpdate $model */ $model = $this->getModel('update'); $uid = $this->input->get('cid', array(), 'array'); JArrayHelper::toInteger($uid, array()); // Get the minimum stability. $component = JComponentHelper::getComponent('com_installer'); $params = $component->params; $minimum_stability = $params->get('minimum_stability', JUpdater::STABILITY_STABLE, 'int'); $model->update($uid, $minimum_stability); if ($model->getState('result', false)) { $cache = JFactory::getCache('mod_menu'); $cache->clean(); } $app = JFactory::getApplication(); $redirect_url = $app->getUserState('com_installer.redirect_url'); // Don't redirect to an external URL. if (!JUri::isInternal($redirect_url)) { $redirect_url = ''; } if (empty($redirect_url)) { $redirect_url = JRoute::_('index.php?option=com_installer&view=update', false); } else { // Wipe out the user state when we're going to redirect. $app->setUserState('com_installer.redirect_url', ''); $app->setUserState('com_installer.message', ''); $app->setUserState('com_installer.extension_message', ''); } $this->setRedirect($redirect_url); }
private function getReturn($key, $type) { $return = base64_decode($this->app->input->post->get($key, '', $type)); if (!JUri::isInternal($return)) { $return = ''; } return $return; }
/** * Get the return URL. * If a "return" variable has been passed in the request * * @return string The return URL. */ protected function getReturnPage() { $return = JRequest::getVar('return', null, 'default', 'base64'); if (empty($return) || !JUri::isInternal(base64_decode($return))) { return JURI::base(); } return base64_decode($return); }
/** * Get the return URL * * If a "return" variable has been passed in the request * * @return string The return URL */ protected function getReturnPage() { $return = JFactory::getApplication()->input->get('return', '', 'base64'); if (empty($return) || !JUri::isInternal(base64_decode($return))) { return JURI::base(); } else { return base64_decode($return); } }
protected function getReturnPage() { $return = $this->input->get('return', null, 'base64'); if (empty($return) || !JUri::isInternal(base64_decode($return))) { return JUri::base(); } else { return base64_decode($return); } }
public function prepareValueForDisplay($value, $field) { if (!$value) { return $value; } $attributes = ''; if (!JUri::isInternal($value)) { $attributes = 'rel="nofollow" target="_blank"'; } return '<a href="' . $value . '" ' . $attributes . '>' . $value . '</a>'; }
public function getInput($fieldValue = null) { if (!$this->isPublished()) { return ""; } $file_detect = 0; $value = !is_null($fieldValue) ? $fieldValue : $this->value; if ($value) { if (JUri::isInternal($value)) { $file_detect = 1; if (stripos($value, JUri::root()) === 0) { $path = JPATH_ROOT . "/" . str_replace(JUri::root(), "", $value); } else { $path = JPATH_ROOT . "/" . $value; } if (!JFile::exists($path)) { $file_detect = 2; } } } $this->setAttribute("type", "text", "input"); $this->addAttribute("class", $this->getInputClass(), "input"); if ((int) $this->params->get("size", 32)) { $this->setAttribute("size", (int) $this->params->get("size", 32), "input"); } if ($this->params->get("placeholder", "")) { $placeholder = htmlspecialchars($this->params->get("placeholder", ""), ENT_COMPAT, 'UTF-8'); $this->setAttribute("placeholder", $placeholder, "input"); } $this->setVariable('file_detect', $file_detect); $this->setVariable('value', $value); return $this->fetch('input.php', __CLASS__); }
protected function populateState() { $app = JFactory::getApplication(); // Load the parameters. $params = $app->getParams(); $this->setState('params', $params); $this->mailNewIssueAdmins = $params->get('mailnewissueadmins'); $this->mailNewIssueUser = $params->get('mailnewissueuser'); $return = JRequest::getVar('return', null, 'default', 'base64'); if (!JUri::isInternal(base64_decode($return))) { $return = null; } $this->setState('return_page', base64_decode($return)); }
/** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @param string $ordering Ordering column * @param string $direction 'ASC' or 'DESC' * * @return void */ protected function populateState($ordering = null, $direction = null) { $app = JFactory::getApplication(); $jinput = $app->input; $return = $jinput->get('return', '', 'base64'); if (!JUri::isInternal(base64_decode($return))) { $return = null; } $this->setState('return_page', base64_decode($return)); // Load the parameters. $params = $app->getParams(); $this->setState('params', $params); $this->setState('layout', $jinput->get('layout')); }
static function getReturnURL($params, $type) { global $cbSpecialReturnAfterLogin, $cbSpecialReturnAfterLogout; static $returnUrl = null; if (!isset($returnUrl)) { $returnUrl = Application::Input()->get('get/return', '', GetterInterface::BASE64); if ($returnUrl) { $returnUrl = base64_decode($returnUrl); if (!JUri::isInternal($returnUrl)) { // The URL isn't internal to the site; reset it to index to be safe: $returnUrl = 'index.php'; } } else { $isHttps = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off'; $returnUrl = 'http' . ($isHttps ? 's' : '') . '://' . $_SERVER['HTTP_HOST']; if (!empty($_SERVER['PHP_SELF']) && !empty($_SERVER['REQUEST_URI'])) { $returnUrl .= $_SERVER['REQUEST_URI']; } else { $returnUrl .= $_SERVER['SCRIPT_NAME']; if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) { $returnUrl .= '?' . $_SERVER['QUERY_STRING']; } } } $returnUrl = cbUnHtmlspecialchars(preg_replace('/[\\\\"\\\'][\\s]*javascript:(.*)[\\\\"\\\']/', '""', preg_replace('/eval\\((.*)\\)/', '', htmlspecialchars(urldecode($returnUrl))))); if (preg_match('/index.php\\?option=com_comprofiler&task=confirm&confirmCode=|index.php\\?option=com_comprofiler&view=confirm&confirmCode=|index.php\\?option=com_comprofiler&task=login|index.php\\?option=com_comprofiler&view=login/', $returnUrl)) { $returnUrl = 'index.php'; } } $secureForm = (int) $params->get('https_post', 0); if ($type == 'login') { $loginReturnUrl = $params->get('login', $returnUrl); if (isset($cbSpecialReturnAfterLogin)) { $loginReturnUrl = $cbSpecialReturnAfterLogin; } $url = cbSef($loginReturnUrl, true, 'html', $secureForm); } elseif ($type == 'logout') { $logoutReturnUrl = $params->get('logout', 'index.php'); if ($logoutReturnUrl == '#') { $logoutReturnUrl = $returnUrl; } if (isset($cbSpecialReturnAfterLogout)) { $logoutReturnUrl = $cbSpecialReturnAfterLogout; } $url = cbSef($logoutReturnUrl, true, 'html', $secureForm); } else { $url = $returnUrl; } return base64_encode($url); }
/** * Method to log out a user. * * @return void */ public function logout() { JSession::checkToken('request') or jexit(JText::_('JInvalid_Token')); $app = JFactory::getApplication(); $userid = $this->input->getInt('uid', null); $options = array('clientid' => $userid ? 0 : 1); $result = $app->logout($userid, $options); if (!$result instanceof Exception) { $model = $this->getModel('login'); $return = $model->getState('return'); // Only redirect to an internal URL. if (JUri::isInternal($return)) { $app->redirect($return); } } parent::display(); }
/** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @since 1.6 */ protected function populateState() { $credentials = array('username' => JRequest::getVar('username', '', 'method', 'username'), 'password' => JRequest::getVar('passwd', '', 'post', 'string', JREQUEST_ALLOWRAW), 'secretkey' => JRequest::getVar('secretkey', '', 'post', 'string', JREQUEST_ALLOWRAW)); $this->setState('credentials', $credentials); // check for return URL from the request first if ($return = JRequest::getVar('return', '', 'method', 'base64')) { $return = base64_decode($return); if (!JUri::isInternal($return)) { $return = ''; } } // Set the return URL if empty. if (empty($return)) { $return = 'index.php'; } $this->setState('return', $return); }
/** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @since 1.6 */ protected function populateState() { $app = JFactory::getApplication(); // Load state from the request. $pk = JRequest::getInt('sub_id'); $this->setState('htraininglogs.sub_id', $pk); // Add compatibility variable for default naming conventions. $this->setState('session.id', $pk); $return = JRequest::getVar('return', null, 'default', 'base64'); if (!JUri::isInternal(base64_decode($return))) { $return = null; } $this->setState('return_page', base64_decode($return)); // Load the parameters. $params = $app->getParams(); $this->setState('params', $params); $this->setState('layout', JRequest::getCmd('layout')); }
/** * Execute the controller. * * @return boolean True if controller finished execution, false if the controller did not * finish execution. A controller might return false if some precondition for * the controller to run has not been satisfied. * * @since 12.1 * @throws LogicException * @throws RuntimeException */ public function execute() { $id = $this->input->getInt('id'); $user = JFactory::getUser(); if ($user->guest) { $this->app->enqueueMessage(JText::_('JGLOBAL_YOU_MUST_LOGIN_FIRST'), 'error'); } else { $model = new MonitorModelSubscription(); if (!$model->isSubscriberProject($id, $user->id)) { $model->subscribeProject($id, $user->id); $this->app->enqueueMessage(JText::_('COM_MONITOR_SUBSCRIPTION_PROJECT'), 'message'); } } $return = base64_decode($this->app->input->get('return', '', 'BASE64')); if (!JUri::isInternal($return)) { $return = 'index.php?option=com_monitor&view=project&id=' . $id; } $this->app->redirect(JRoute::_($return, false)); }
/** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @return void * * @since 1.6 */ protected function populateState() { $app = JFactory::getApplication(); $input = $app->input; $method = $input->getMethod(); $credentials = array('username' => $input->{$method}->get('username', '', 'USERNAME'), 'password' => $input->{$method}->get('passwd', '', 'RAW'), 'secretkey' => $input->{$method}->get('secretkey', '', 'RAW')); $this->setState('credentials', $credentials); // Check for return URL from the request first if ($return = $input->{$method}->get('return', '', 'BASE64')) { $return = base64_decode($return); if (!JUri::isInternal($return)) { $return = ''; } } // Set the return URL if empty. if (empty($return)) { $return = 'index.php'; } $this->setState('return', $return); }
/** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @since 1.6 */ protected function populateState() { $app = JFactory::getApplication(); // Load state from the request. $pk = $app->input->getInt('w_id'); $this->setState('weblink.id', $pk); // Add compatibility variable for default naming conventions. $this->setState('form.id', $pk); $categoryId = $app->input->getInt('catid'); $this->setState('weblink.catid', $categoryId); $return = $app->input->get('return', null, 'base64'); if (!JUri::isInternal(base64_decode($return))) { $return = null; } $this->setState('return_page', base64_decode($return)); // Load the parameters. $params = $app->getParams(); $this->setState('params', $params); $this->setState('layout', $app->input->getString('layout')); }
/** * Method to get the data that should be injected in the form. * * @return array The default data is an empty array. * @since 1.6 */ protected function loadFormData() { // Check the session for previously entered login form data. $app = JFactory::getApplication(); $data = $app->getUserState('users.login.form.data', array()); // check for return URL from the request first if ($return = JRequest::getVar('return', '', 'method', 'base64')) { $data['return'] = base64_decode($return); if (!JUri::isInternal($data['return'])) { $data['return'] = ''; } } // Set the return URL if empty. if (!isset($data['return']) || empty($data['return'])) { $data['return'] = 'index.php?option=com_users&view=profile'; } $app->setUserState('users.login.form.data', $data); $this->preprocessData('com_users.login', $data); return $data; }
/** * Execute the controller. * * @return boolean True if controller finished execution, false if the controller did not * finish execution. A controller might return false if some precondition for * the controller to run has not been satisfied. * * @since 12.1 * @throws LogicException * @throws RuntimeException */ public function execute() { if (!JFactory::getUser()->authorise('attachment.delete', 'com_monitor')) { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); } $app = JFactory::getApplication(); $model = new MonitorModelAttachments($app); $id = $app->input->getInt('id'); if (!$id) { throw new Exception(JText::_('JERROR_NO_ITEMS_SELECTED'), 404); } $model->delete(array($id)); $app->enqueueMessage(JText::_('COM_MONITOR_ATTACHMENT_DELETED')); $return = base64_decode($this->app->input->get('return', '', 'BASE64')); if (!JUri::isInternal($return)) { $return = 'index.php?option=com_monitor&view=projects'; } $this->app->redirect(JRoute::_($return, false)); return true; }
/** * Method to log out a user. * * @since 1.6 */ public function logout() { JSession::checkToken('request') or jexit(JText::_('JInvalid_Token')); $app = JFactory::getApplication(); // Perform the log in. $error = $app->logout(); // Check if the log out succeeded. if (!$error instanceof Exception) { // Get the return url from the request and validate that it is internal. $return = JRequest::getVar('return', '', 'method', 'base64'); $return = base64_decode($return); if (!JUri::isInternal($return)) { $return = ''; } // Redirect the user. $app->redirect(JRoute::_($return, false)); } else { $app->redirect(JRoute::_('index.php?option=com_users&view=login', false)); } }
/** * Method to handle admin cancel * * @return boolean True on success. * * @since 3.2 */ public function execute() { // Check for request forgeries. if (!JSession::checkToken()) { $this->app->enqueueMessage(JText::_('JINVALID_TOKEN')); $this->app->redirect('index.php'); } if (empty($this->context)) { $this->context = $this->option . '.edit' . $this->context; } // Redirect. $this->app->setUserState($this->context . '.data', null); if (!empty($this->redirect)) { // Don't redirect to an external URL. if (!JUri::isInternal($this->redirect)) { $this->redirect = JUri::base(); } $this->app->redirect($this->redirect); } else { parent::execute(); } }
/** * Internal processor for all error handlers * * @param Exception|Throwable $error The Exception or Throwable object to be handled. * * @return void * * @since 3.5 */ private static function doErrorHandling($error) { $app = JFactory::getApplication(); if ($app->isAdmin() || (int) $error->getCode() !== 404) { // Proxy to the previous exception handler if available, otherwise just render the error page if (self::$previousExceptionHandler) { call_user_func_array(self::$previousExceptionHandler, array($error)); } else { JErrorPage::render($error); } } $uri = JUri::getInstance(); $url = rawurldecode($uri->toString(array('scheme', 'host', 'port', 'path', 'query', 'fragment'))); $urlRel = rawurldecode($uri->toString(array('path', 'query', 'fragment'))); $urlWithoutQuery = rawurldecode($uri->toString(array('scheme', 'host', 'port', 'path', 'fragment'))); $urlRelWithoutQuery = rawurldecode($uri->toString(array('path', 'fragment'))); // Why is this (still) here? if (strpos($url, 'mosConfig_') !== false || strpos($url, '=http://') !== false) { JErrorPage::render($error); } $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('*')->from($db->quoteName('#__redirect_links'))->where('(' . $db->quoteName('old_url') . ' = ' . $db->quote($url) . ' OR ' . $db->quoteName('old_url') . ' = ' . $db->quote($urlRel) . ' OR ' . $db->quoteName('old_url') . ' = ' . $db->quote($urlWithoutQuery) . ' OR ' . $db->quoteName('old_url') . ' = ' . $db->quote($urlRelWithoutQuery) . ')'); $db->setQuery($query); $redirect = null; try { $redirects = $db->loadAssocList(); } catch (Exception $e) { JErrorPage::render(new Exception(JText::_('PLG_SYSTEM_REDIRECT_ERROR_UPDATING_DATABASE'), 500, $e)); } $possibleMatches = array_unique(array($url, $urlRel, $urlWithoutQuery, $urlRelWithoutQuery)); foreach ($possibleMatches as $match) { if (($index = array_search($match, array_column($redirects, 'old_url'))) !== false) { $redirect = (object) $redirects[$index]; if ((int) $redirect->published === 1) { break; } } } // A redirect object was found and, if published, will be used if (!is_null($redirect) && (int) $redirect->published === 1) { if (!$redirect->header || (bool) JComponentHelper::getParams('com_redirect')->get('mode', false) === false) { $redirect->header = 301; } if ($redirect->header < 400 && $redirect->header >= 300) { $urlQuery = $uri->getQuery(); $oldUrlParts = parse_url($redirect->old_url); if (empty($oldUrlParts['query']) && $urlQuery !== '') { $redirect->new_url .= '?' . $urlQuery; } $destination = JUri::isInternal($redirect->new_url) ? JRoute::_($redirect->new_url) : $redirect->new_url; $app->redirect($destination, (int) $redirect->header); } JErrorPage::render(new RuntimeException($error->getMessage(), $redirect->header, $error)); } elseif (is_null($redirect)) { $params = new Registry(JPluginHelper::getPlugin('system', 'redirect')->params); if ((bool) $params->get('collect_urls', true)) { $data = (object) array('id' => 0, 'old_url' => $url, 'referer' => $app->input->server->getString('HTTP_REFERER', ''), 'hits' => 1, 'published' => 0, 'created_date' => JFactory::getDate()->toSql()); try { $db->insertObject('#__redirect_links', $data, 'id'); } catch (Exception $e) { JErrorPage::render(new Exception(JText::_('PLG_SYSTEM_REDIRECT_ERROR_UPDATING_DATABASE'), 500, $e)); } } } else { $redirect->hits += 1; try { $db->updateObject('#__redirect_links', $redirect, 'id'); } catch (Exception $e) { JErrorPage::render(new Exception(JText::_('PLG_SYSTEM_REDIRECT_ERROR_UPDATING_DATABASE'), 500, $e)); } } JErrorPage::render($error); }
/** * * @param string $path * @return multitype:multitype:unknown |Ambigous <multitype:, boolean, multitype:unknown multitype:unknown > */ public static function getExternalImages($path) { jimport('joomla.filesystem.folder'); $files = array(); // check if $path is url $path = trim($path); $isHttp = stripos($path, 'http') === 0; if ($isHttp) { if (!JUri::isInternal($path)) { // is external, test if is valid if (version_compare(JVERSION, '3.0.0', '>=')) { // is Joomla 3 $http = JHttpFactory::getHttp(); $head = $http->head($path); if ($head->code == 200 || $head->code == 302 || $head->code == 304) { // is valid url if (preg_match('/image/', $head->headers['Content-Type'])) { // is true image $files[] = $path; } } } else { // for Joomla 3 older $files[] = $path; } if (!count($files)) { //var_dump('Url is not valid'); } return $files; } else { $uri = JUri::getInstance($path); $uri_path = (string) $uri->getPath(); $uri_base = (string) JURI::base(true); if (stripos($uri_path, $uri_base) === 0 && ($baselen = strlen($uri_base))) { $uri_path = substr($uri_path, $baselen); } $path = JPATH_BASE . $uri_path; } } if (($realpath = realpath($path)) === false) { //var_dump('File or Folder is not exists!'); return $files; } if (is_file($realpath)) { $files[] = $realpath; } else { if (is_dir($realpath)) { $files = JFolder::files($path, '.jpg|.png|.gif', false, true); } } return $files; }
/** * Method to parse all link to css files from the html markup * and compress it * * @param string $htmlMarkup HTML Content to response to browser * * @return void */ public static function compress($styleSheets) { static $compressedFiles; // Get object for working with URI $uri = JUri::getInstance(); // Generate link prefix if current scheme is HTTPS $prefix = ''; if ($uri->getScheme() == 'https') { $prefix = $uri->toString(array('scheme', 'host', 'port')); } // Initialize variables $groupIndex = 0; $groupType = 'screen'; $groupFiles = array(); $compress = array(); // Sometime, stylesheet file need to be stored in the original location and file name $document = JFactory::getDocument(); $leaveAlone = preg_split('/[\\r\\n]+/', $document->params->get('compressionExclude')); // We already know that the file galleria.classic.css must be excluded $leaveAlone[] = 'galleria.classic.css'; // Parse link tags foreach ($styleSheets as $key => $line) { // Set default media attribute $attributes['media'] = is_null($line['media']) ? '' : strtolower($line['media']); $attributes['href'] = $key; // Add to result list if this is external file if (!($isInternal = JUri::isInternal($attributes['href'])) or strpos($attributes['href'], '//') === 0) { $compress[] = array('href' => $attributes['href'], 'media' => $attributes['media']); continue; } // Add to result list if this is dynamic generation content $questionPos = false; if (($questionPos = strpos($attributes['href'], '?')) !== false) { $isDynamic = substr($attributes['href'], $questionPos - 4, 4) == '.php'; $path = JSNTplCompressHelper::getFilePath(substr($attributes['href'], 0, $questionPos)); // Check if this is a dynamic generation content if (!$isDynamic and $isInternal) { $isDynamic = !is_file($path); } if ($isDynamic) { $compress[] = array('href' => $attributes['href'], 'media' => $attributes['media']); continue; } } // Check if reserving stylesheet file name is required $stylesheetName = basename($questionPos !== false ? $path : $attributes['href']); if (in_array($stylesheetName, $leaveAlone)) { $attributes['media'] .= '|reserve|' . $stylesheetName; } // Create new compression group when media attribute different with group type if ($attributes['media'] != $groupType) { // Add collected files to compress list if (isset($groupFiles[$groupIndex]) and !empty($groupFiles[$groupIndex])) { $compress[] = array('files' => $groupFiles[$groupIndex], 'media' => $groupType); } // Increase index number of the group $groupIndex++; $groupType = $attributes['media']; } // Initial group if (!isset($groupFiles[$groupIndex])) { $groupFiles[$groupIndex] = array(); } $href = $attributes['href']; $queryStringIndex = strpos($href, '?'); if ($queryStringIndex !== false) { $href = substr($href, 0, $queryStringIndex); } // Add file to the group $groupFiles[$groupIndex][] = preg_match('/^([^\\|]*)\\|reserve\\|.+$/', $groupType) ? $attributes['href'] : $href; } // Add collected files to result list if (isset($groupFiles[$groupIndex]) and !empty($groupFiles[$groupIndex])) { $compress[] = array('files' => $groupFiles[$groupIndex], 'media' => $groupType); } // Initial compress result $compressResult = array(); $fileCompressed = array(); // Get template details $templateName = JFactory::getApplication()->getTemplate(); // Generate path to cache directory if (!preg_match('#^(/|\\|[a-z]:)#i', $document->params->get('cacheDirectory'))) { $compressPath = JPATH_ROOT . '/' . rtrim($document->params->get('cacheDirectory'), '\\/'); } else { $compressPath = rtrim($document->params->get('cacheDirectory'), '\\/'); } $compressPath = $compressPath . '/' . $templateName . '/'; // Create directory if not exists if (!is_dir($compressPath)) { JFolder::create($compressPath); } // Loop to each compress element to compress file $modifiedFlag = false; foreach ($compress as $group) { // Ignore compress when group is a external file if (isset($group['href'])) { $ignoreCompressMedia = ''; $link = '<link rel="stylesheet" href="' . $group['href'] . '" '; if (isset($group['media']) and !empty($group['media'])) { $link .= 'media="' . $group['media'] . '" '; $ignoreCompressMedia = $group['media']; } $link .= '/>'; $compressResult[] = $link; $fileCompressed[] = array('media' => $ignoreCompressMedia, 'file' => $group['href']); continue; } // Check if reserving stylesheet file name is required if (isset($group['media']) and preg_match('/^([^\\|]*)\\|reserve\\|.+$/', $group['media'], $m)) { $reservingStylesshetMedia = ''; $link = '<link rel="stylesheet" href="' . $group['files'][0] . '" '; if (isset($m[1]) and !empty($m[1])) { $link .= 'media="' . $m[1] . '" '; $reservingStylesshetMedia = $m[1]; } $link .= '/>'; $compressResult[] = $link; $fileCompressed[] = array('media' => $reservingStylesshetMedia, 'file' => $group['files'][0]); continue; } // Generate compress file name $compressFile = md5(implode('', $group['files'])) . '.css'; $lastModified = 0; // Check last modified time for each file in the group foreach ($group['files'] as $file) { $path = JSNTplCompressHelper::getFilePath($file); $lastModified = is_file($path) && @filemtime($path) > $lastModified ? @filemtime($path) : $lastModified; } if (@filemtime($compressPath . $compressFile) < $lastModified) { $modifiedFlag = true; } // Compress group when expired if (!is_file($compressPath . $compressFile) or @filemtime($compressPath . $compressFile) < $lastModified) { // Preset compression buffer $buffer = ''; // Preset remote file array $remoteFiles = array(); // Preset some variables to hold compression status $processedFiles = array(); $maxFileSize = 1024 * (int) $document->params->get('maxCompressionSize'); $currentSize = 0; // Read content of each file and write it to the cache file foreach ($group['files'] as $file) { $filePath = JSNTplCompressHelper::getFilePath($file); // Skip when cannot access to file if (!is_file($filePath) or !is_readable($filePath)) { continue; } // Do compression $result = trim(self::_loadFileInto($buffer, $filePath, $maxFileSize, $currentSize, $remoteFiles)); if (empty($result)) { // Store processed file $processedFiles[] = $filePath; } else { // Write buffer to cache file JFile::write($compressPath . $compressFile, $buffer); // Rename created cache file $newFileName = md5(implode('', $processedFiles)) . '.css'; JFile::move($compressPath . $compressFile, $compressPath . $newFileName); // Save every compressed file associated with this page for maintenance later $compressedFiles[] = str_replace('\\', '/', $compressPath) . $newFileName; // Add compressed file to the remote file import list $remoteFiles[] = str_replace(str_replace('\\', '/', JPATH_ROOT), JUri::root(true), str_replace('\\', '/', $compressPath)) . $newFileName; // Reset compression buffer $buffer = $result; // Reset compression status variables $currentSize = strlen($result); $processedFiles = array($filePath); } } // Write buffer to cache file JFile::write($compressPath . $compressFile, $buffer); // Save every compressed file associated with this page for maintenance later $compressedFiles[] = str_replace('\\', '/', $compressPath) . $compressFile; if (!empty($remoteFiles)) { for ($n = count($remoteFiles), $i = $n - 1; $i >= 0; $i--) { JSNTplCompressHelper::prependIntoFile("@import url({$remoteFiles[$i]});" . ($i + 1 < $n ? "\n" : "\n\n"), $compressPath . $compressFile); } } } // Add compressed file to the compress result list $compressUrl = str_replace(str_replace('\\', '/', JPATH_ROOT), JUri::root(true), str_replace('\\', '/', $compressPath)) . $compressFile; $link = '<link rel="stylesheet" href="' . $prefix . $compressUrl . '" '; $mediaCompressedFile = ''; if (isset($group['media']) and !empty($group['media'])) { $link .= 'media="' . preg_replace('/\\|reserve\\|(.+)$/', '', $group['media']) . '" '; $mediaCompressedFile = preg_replace('/\\|reserve\\|(.+)$/', '', $group['media']); } $link .= '/>'; $compressResult[] = $link; $fileCompressed[] = array('media' => $mediaCompressedFile, 'file' => $compressUrl); } // Verify if stylesheets associated with this page has been changed if (isset($compressedFiles)) { $trackFile = $compressPath . 'tracking.php'; $pageLink = JUri::current(); $cleanUp = array(); if (file_exists($trackFile)) { if (!file_exists("{$trackFile}.lock")) { // Get tracking data include $trackFile; if (isset($tracking) && isset($tracking[$pageLink]) && isset($tracking[$pageLink]['css'])) { foreach ($tracking[$pageLink]['css'] as $file) { if (!in_array($file, $compressedFiles)) { // Store obsolete file to be removed $cleanUp[] = $file; } } // Remove obsolete file only if not used in another page foreach ($cleanUp as $file) { $removable = true; foreach ($tracking as $link => $assets) { if ($pageLink == $link) { continue; } if (@in_array($file, $assets['css'])) { $removable = false; break; } } if ($removable && !$modifiedFlag) { JFile::delete($file); } } } } } else { // Clean all unmaintained compressed files if ($files = glob($compressPath . '*.css')) { foreach ($files as $file) { $file = str_replace('\\', '/', $file); if (!in_array($file, $compressedFiles)) { JFile::delete($file); } } } } // Update tracking file if not locked if (!file_exists("{$trackFile}.lock")) { // Create lock file $content = 'Updating'; JFile::write("{$trackFile}.lock", $content); // Preset tracking array if (!isset($tracking)) { $tracking = array($pageLink => array()); } $tracking[$pageLink]['css'] = $compressedFiles; // Update tracking data $content = "<?php\n\$tracking = json_decode('" . json_encode($tracking) . "', true);\n?>"; // Update tracking file JFile::write($trackFile, $content); // Remove lock file JFile::delete("{$trackFile}.lock"); } } return $fileCompressed; }
/** * Method to set the return page as a saved entry in session data. * * @param string $context The context string used to store the return data * * @return void * */ protected function setReturnPage($context) { $app = JFactory::getApplication(); $return = $this->input->get('return', null, 'base64'); if (empty($return) or !JUri::isInternal(base64_decode($return))) { $return = base64_encode(JUri::base()); } $app->setUserState($context . '.return', $return); }
protected function _getReturnPage($base = false) { $app = JFactory::getApplication(); $return = $app->input->getBase64('return'); if (empty($return) || !JUri::isInternal(base64_decode($return))) { return $base == true ? JURI::base() : 'index.php?option=com_cck'; } else { return base64_decode($return); } }
/** * Upload one or more files * * @return boolean * * @since 1.5 */ public function upload() { // Check for request forgeries JSession::checkToken('request') or jexit(JText::_('JINVALID_TOKEN')); $params = JComponentHelper::getParams('com_media'); // Get some data from the request $files = $this->input->files->get('Filedata', '', 'array'); $return = JFactory::getSession()->get('com_media.return_url'); $this->folder = $this->input->get('folder', '', 'path'); // Don't redirect to an external URL. if (!JUri::isInternal($return)) { $return = ''; } // Set the redirect if ($return) { $this->setRedirect($return . '&folder=' . $this->folder); } else { $this->setRedirect('index.php?option=com_media&folder=' . $this->folder); } // Authorize the user if (!$this->authoriseUser('create')) { return false; } // Total length of post back data in bytes. $contentLength = (int) $_SERVER['CONTENT_LENGTH']; // Instantiate the media helper $mediaHelper = new JHelperMedia(); // Maximum allowed size of post back data in MB. $postMaxSize = $mediaHelper->toBytes(ini_get('post_max_size')); // Maximum allowed size of script execution in MB. $memoryLimit = $mediaHelper->toBytes(ini_get('memory_limit')); // Check for the total size of post back data. if ($postMaxSize > 0 && $contentLength > $postMaxSize || $memoryLimit != -1 && $contentLength > $memoryLimit) { JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_WARNUPLOADTOOLARGE')); return false; } $uploadMaxSize = $params->get('upload_maxsize', 0) * 1024 * 1024; $uploadMaxFileSize = $mediaHelper->toBytes(ini_get('upload_max_filesize')); // Perform basic checks on file info before attempting anything foreach ($files as &$file) { $file['name'] = JFile::makeSafe($file['name']); $file['filepath'] = JPath::clean(implode(DIRECTORY_SEPARATOR, array(COM_MEDIA_BASE, $this->folder, $file['name']))); if ($file['error'] == 1 || $uploadMaxSize > 0 && $file['size'] > $uploadMaxSize || $uploadMaxFileSize > 0 && $file['size'] > $uploadMaxFileSize) { // File size exceed either 'upload_max_filesize' or 'upload_maxsize'. JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_WARNFILETOOLARGE')); return false; } if (JFile::exists($file['filepath'])) { // A file with this name already exists JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_FILE_EXISTS')); return false; } if (!isset($file['name'])) { // No filename (after the name was cleaned by JFile::makeSafe) $this->setRedirect('index.php', JText::_('COM_MEDIA_INVALID_REQUEST'), 'error'); return false; } } // Set FTP credentials, if given JClientHelper::setCredentialsFromRequest('ftp'); JPluginHelper::importPlugin('content'); $dispatcher = JEventDispatcher::getInstance(); foreach ($files as &$file) { // The request is valid $err = null; if (!MediaHelper::canUpload($file, $err)) { // The file can't be uploaded return false; } // Trigger the onContentBeforeSave event. $object_file = new JObject($file); $result = $dispatcher->trigger('onContentBeforeSave', array('com_media.file', &$object_file, true)); if (in_array(false, $result, true)) { // There are some errors in the plugins JError::raiseWarning(100, JText::plural('COM_MEDIA_ERROR_BEFORE_SAVE', count($errors = $object_file->getErrors()), implode('<br />', $errors))); return false; } if (!JFile::upload($object_file->tmp_name, $object_file->filepath)) { // Error in upload JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_UNABLE_TO_UPLOAD_FILE')); return false; } else { // Trigger the onContentAfterSave event. $dispatcher->trigger('onContentAfterSave', array('com_media.file', &$object_file, true)); $this->setMessage(JText::sprintf('COM_MEDIA_UPLOAD_COMPLETE', substr($object_file->filepath, strlen(COM_MEDIA_BASE)))); } } return true; }
/** * Redirect back to the referrer page. * * If there's no referrer or it's external, Kunena will return to forum home page. * Also redirects back to tasks are prevented. * * @param string $anchor */ protected function redirectBack($anchor = '') { $default = JUri::base() . ($this->app->isSite() ? ltrim(KunenaRoute::_('index.php?option=com_kunena'), '/') : ''); $referrer = $this->app->input->server->getString('HTTP_REFERER'); $uri = JUri::getInstance($referrer ? $referrer : $default); if (JUri::isInternal($uri->toString())) { // Parse route. $vars = $this->app->getRouter()->parse($uri); $uri = new JUri('index.php'); $uri->setQuery($vars); // Make sure we do not return into a task. $uri->delVar('task'); $uri->delVar(JSession::getFormToken()); } else { $uri = JUri::getInstance($default); } if ($anchor) { $uri->setFragment($anchor); } $this->app->redirect(JRoute::_($uri->toString())); }
/** * Allows caller to log the user out from the site * * @since 1.3 * @access public */ public function logout() { JSession::checkToken('request') or jexit(JText::_('JInvalid_Token')); // Perform the logout $error = $this->app->logout(); // Check if the log out succeeded. if (!$error instanceof Exception) { // Get the return url from the request and validate that it is internal. $return = JRequest::getVar('return', '', 'method', 'base64'); $return = base64_decode($return); if (!JUri::isInternal($return)) { $return = ''; } // Redirect the user. $this->app->redirect(JRoute::_($return, false)); $this->app->close(); } $this->app->redirect(FRoute::login(array(), false)); }