Exemple #1
0
 /**
  * Parse url and reroute with routes.xml rules if found
  * 
  * @return Uri      Return the instance of Uri (rerouted or not) 
  */
 public function parseUrl()
 {
     // Get new instance of Uri
     $uriInst = Uri::getInstance();
     // Remove first / from uri
     $uri = trim($uriInst->getUri(false), '/');
     // Init vars
     $defaultRedirect = null;
     // Parse routes
     foreach ($this->_routes as $route) {
         // Converts shortcuts to regexp
         $rule = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $route->attributes()->rule));
         // Rule match to uri
         if (preg_match('#^' . $rule . '$#', $uri)) {
             // Is there any back reference
             if (strpos($route->attributes()->redirect, '$') !== false && strpos($rule, '(') !== false) {
                 $uri = preg_replace('#^' . $rule . '$#', $route->attributes()->redirect, $uri);
             } else {
                 $uri = $route->attributes()->redirect;
             }
             // Define rerouted uri to current instance of Uri
             return $uriInst->setUri($uri);
         }
         if ($rule === 'default') {
             $defaultRedirect = (string) $route->attributes()->redirect . '/' . $uri;
         }
     }
     if (!$uriInst->isDefined() && $defaultRedirect !== null) {
         $uriInst->setUri($defaultRedirect);
     }
     return $uriInst;
 }
Exemple #2
0
 public function redirect($location, $statusCode = 302)
 {
     if (substr($location, 0, 4) != 'http') {
         $location = Uri::getInstance()->location(ltrim($location, '/'));
     }
     self::$statusText = 'Location: ' . $location;
     self::$statusCode = $statusCode;
     return '<html><head><meta http-equiv="refresh" content="0; url=' . $location . '" /></head><body></body></html>';
 }
 /**
  * Get action class name from called action and module
  * 
  * @return void 
  */
 private function _getActionClassName()
 {
     if ($this->_module !== null) {
         // Action is not defined,
         if ($this->_action === null) {
             $this->_action = self::DEFAULT_MODULE_ACTION;
         }
         // Build class Name
         $className = 'm_' . $this->_module . '_action_' . $this->_action;
         // Check if class exists
         if (!class_exists($className)) {
             throw new RuntimeException('Class ' . $className . ' not found !', E_USER_ERROR);
         }
         // Check if default action method exists
         if (!method_exists($className, self::DEFAULT_ACTION_METHOD)) {
             trigger_error('Method ' . self::DEFAULT_ACTION_METHOD . ' not found in ' . $className, E_USER_ERROR);
         }
         // Add args to default method
         if ($this->_args === null) {
             $this->_args = Uri::getInstance()->segmentsSlice(2);
         }
         // Set class name
         $this->_className = $className;
         // Instanciate action class
         $this->_classInstance = new $this->_className();
     }
 }
 function partialView($filename)
 {
     $this->page_active = strtolower(get_class($this));
     $this->menuHelper = MenuHelper::getInstance();
     $pages = $this->menuHelper->getNavBar($this->page_active, $this->sub_menu_active);
     $addmarging = strcmp(get_class($this), "Accueil") === 0 ? "margin-0" : "margin_bottom40";
     if (!empty($this->vars)) {
         foreach ($this->vars as $key => $value) {
             $this->tpl->assign($key, $value);
         }
     }
     $uri = Uri::getInstance()->getFragment();
     $home = "";
     if (isset($uri[0])) {
         $home = $uri[0];
         unset($uri[0]);
     }
     $this->displayTpl($filename);
 }
Exemple #5
0
 /**
  * This function will refresh the current page. Useful for forms but beware on loops.
  */
 function refresh()
 {
     $url = Uri::getInstance()->getHost(true) . $_SERVER['REQUEST_URI'];
     redirect($url);
 }
 /**
  * Render the feed.
  *
  * @param   string  $name     The name of the element to render
  * @param   array   $params   Array of values
  * @param   string  $content  Override the output of the renderer
  *
  * @return  string  The output of the script
  *
  * @see JDocumentRenderer::render()
  * @since   11.1
  */
 public function render($name = '', $params = null, $content = null)
 {
     $app = Factory::getApplication();
     // Gets and sets timezone offset from site configuration
     $tz = new DateTimeZone($app->getCfg('offset'));
     $now = Factory::getDate();
     $now->setTimeZone($tz);
     $data = $this->_doc;
     $uri = Uri::getInstance();
     $url = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
     $syndicationURL = Route::_('&format=feed&type=atom');
     if ($app->getCfg('sitename_pagetitles', 0) == 1) {
         $title = Text::sprintf('JPAGETITLE', $app->getCfg('sitename'), $data->title);
     } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) {
         $title = Text::sprintf('JPAGETITLE', $data->title, $app->getCfg('sitename'));
     } else {
         $title = $data->title;
     }
     $feed_title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8');
     $feed = "<feed xmlns=\"http://www.w3.org/2005/Atom\" ";
     if ($data->language != "") {
         $feed .= " xml:lang=\"" . $data->language . "\"";
     }
     $feed .= ">\n";
     $feed .= "\t<title type=\"text\">" . $feed_title . "</title>\n";
     $feed .= "\t<subtitle type=\"text\">" . htmlspecialchars($data->description, ENT_COMPAT, 'UTF-8') . "</subtitle>\n";
     if (empty($data->category) === false) {
         if (is_array($data->category)) {
             foreach ($data->category as $cat) {
                 $feed .= "\t<category term=\"" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "\" />\n";
             }
         } else {
             $feed .= "\t<category term=\"" . htmlspecialchars($data->category, ENT_COMPAT, 'UTF-8') . "\" />\n";
         }
     }
     $feed .= "\t<link rel=\"alternate\" type=\"text/html\" href=\"" . $url . "\"/>\n";
     $feed .= "\t<id>" . str_replace(' ', '%20', $data->getBase()) . "</id>\n";
     $feed .= "\t<updated>" . htmlspecialchars($now->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</updated>\n";
     if ($data->editor != "") {
         $feed .= "\t<author>\n";
         $feed .= "\t\t<name>" . $data->editor . "</name>\n";
         if ($data->editorEmail != "") {
             $feed .= "\t\t<email>" . htmlspecialchars($data->editorEmail, ENT_COMPAT, 'UTF-8') . "</email>\n";
         }
         $feed .= "\t</author>\n";
     }
     $feed .= "\t<generator uri=\"http://joomla.org\" version=\"1.6\">" . $data->getGenerator() . "</generator>\n";
     $feed .= '	<link rel="self" type="application/atom+xml" href="' . str_replace(' ', '%20', $url . $syndicationURL) . "\"/>\n";
     for ($i = 0, $count = count($data->items); $i < $count; $i++) {
         $feed .= "\t<entry>\n";
         $feed .= "\t\t<title>" . htmlspecialchars(strip_tags($data->items[$i]->title), ENT_COMPAT, 'UTF-8') . "</title>\n";
         $feed .= '		<link rel="alternate" type="text/html" href="' . $url . $data->items[$i]->link . "\"/>\n";
         if ($data->items[$i]->date == "") {
             $data->items[$i]->date = $now->toUnix();
         }
         $itemDate = Factory::getDate($data->items[$i]->date);
         $itemDate->setTimeZone($tz);
         $feed .= "\t\t<published>" . htmlspecialchars($itemDate->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</published>\n";
         $feed .= "\t\t<updated>" . htmlspecialchars($itemDate->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</updated>\n";
         if (empty($data->items[$i]->guid) === true) {
             $feed .= "\t\t<id>" . str_replace(' ', '%20', $url . $data->items[$i]->link) . "</id>\n";
         } else {
             $feed .= "\t\t<id>" . htmlspecialchars($data->items[$i]->guid, ENT_COMPAT, 'UTF-8') . "</id>\n";
         }
         if ($data->items[$i]->author != "") {
             $feed .= "\t\t<author>\n";
             $feed .= "\t\t\t<name>" . htmlspecialchars($data->items[$i]->author, ENT_COMPAT, 'UTF-8') . "</name>\n";
             if ($data->items[$i]->authorEmail != "") {
                 $feed .= "\t\t\t<email>" . htmlspecialchars($data->items[$i]->authorEmail, ENT_COMPAT, 'UTF-8') . "</email>\n";
             }
             $feed .= "\t\t</author>\n";
         }
         if ($data->items[$i]->description != "") {
             $feed .= "\t\t<summary type=\"html\">" . htmlspecialchars($data->items[$i]->description, ENT_COMPAT, 'UTF-8') . "</summary>\n";
             $feed .= "\t\t<content type=\"html\">" . htmlspecialchars($data->items[$i]->description, ENT_COMPAT, 'UTF-8') . "</content>\n";
         }
         if (empty($data->items[$i]->category) === false) {
             if (is_array($data->items[$i]->category)) {
                 foreach ($data->items[$i]->category as $cat) {
                     $feed .= "\t\t<category term=\"" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "\" />\n";
                 }
             } else {
                 $feed .= "\t\t<category term=\"" . htmlspecialchars($data->items[$i]->category, ENT_COMPAT, 'UTF-8') . "\" />\n";
             }
         }
         if ($data->items[$i]->enclosure != null) {
             $feed .= "\t\t<link rel=\"enclosure\" href=\"" . $data->items[$i]->enclosure->url . "\" type=\"" . $data->items[$i]->enclosure->type . "\"  length=\"" . $data->items[$i]->enclosure->length . "\" />\n";
         }
         $feed .= "\t</entry>\n";
     }
     $feed .= "</feed>\n";
     return $feed;
 }
Exemple #7
0
 /**
  * Stop script and show a configuration error page
  * 
  * @return void
  */
 public static function showConfigurationError()
 {
     while (ob_get_level()) {
         ob_end_clean();
     }
     set_header(404);
     $uri = Uri::getInstance()->getUri(false);
     $tpl = Template::getInstance();
     $tpl->setTemplateDir(HOOKS_DIR . DS . 'errors');
     $tpl->addTemplateDir(FW_DIR . DS . 'errors');
     $tpl->assign('uri', $uri);
     $tpl->assign('routeFilePath', trim(CACHE_DIR . DS . 'routes.xml'));
     $tpl->assign('tests', self::environmentTests());
     try {
         $tpl->setTemplate('configuration.html')->render();
     } catch (Exception $exc) {
         echo $exc->getMessage();
     }
     die;
 }
 /**
  * Method to apply an input filter to a value based on field data.
  *
  * @param   string  $element  The XML element object representation of the form field.
  * @param   mixed   $value    The value to filter for the field.
  *
  * @return  mixed   The filtered value.
  *
  * @since   11.1
  */
 protected function filterField($element, $value)
 {
     // Make sure there is a valid SimpleXMLElement.
     if (!$element instanceof SimpleXMLElement) {
         return false;
     }
     // Get the field filter type.
     $filter = (string) $element['filter'];
     // Process the input value based on the filter.
     $return = null;
     switch (strtoupper($filter)) {
         // Access Control Rules.
         case 'RULES':
             $return = array();
             foreach ((array) $value as $action => $ids) {
                 // Build the rules array.
                 $return[$action] = array();
                 foreach ($ids as $id => $p) {
                     if ($p !== '') {
                         $return[$action][$id] = $p == '1' || $p == 'true' ? true : false;
                     }
                 }
             }
             break;
             // Do nothing, thus leaving the return value as null.
         // Do nothing, thus leaving the return value as null.
         case 'UNSET':
             break;
             // No Filter.
         // No Filter.
         case 'RAW':
             $return = $value;
             break;
             // Filter the input as an array of integers.
         // Filter the input as an array of integers.
         case 'INT_ARRAY':
             // Make sure the input is an array.
             if (is_object($value)) {
                 $value = get_object_vars($value);
             }
             $value = is_array($value) ? $value : array($value);
             ArrayHelper::toInteger($value);
             $return = $value;
             break;
             // Filter safe HTML.
         // Filter safe HTML.
         case 'SAFEHTML':
             $return = Input::getInstance(null, null, 1, 1)->clean($value, 'string');
             break;
             // Convert a date to UTC based on the server timezone offset.
         // Convert a date to UTC based on the server timezone offset.
         case 'SERVER_UTC':
             if ((int) $value > 0) {
                 // Get the server timezone setting.
                 $offset = Factory::getConfig()->get('offset');
                 // Return an SQL formatted datetime string in UTC.
                 $return = Factory::getDate($value, $offset)->toSql();
             } else {
                 $return = '';
             }
             break;
             // Convert a date to UTC based on the user timezone offset.
         // Convert a date to UTC based on the user timezone offset.
         case 'USER_UTC':
             if ((int) $value > 0) {
                 // Get the user timezone setting defaulting to the server timezone setting.
                 $offset = Factory::getUser()->getParam('timezone', Factory::getConfig()->get('offset'));
                 // Return a MySQL formatted datetime string in UTC.
                 $return = Factory::getDate($value, $offset)->toSql();
             } else {
                 $return = '';
             }
             break;
             // Ensures a protocol is present in the saved field. Only use when
             // the only permitted protocols requre '://'. See JFormRuleUrl for list of these.
         // Ensures a protocol is present in the saved field. Only use when
         // the only permitted protocols requre '://'. See JFormRuleUrl for list of these.
         case 'URL':
             if (empty($value)) {
                 return;
             }
             $value = Input::getInstance()->clean($value, 'html');
             $value = trim($value);
             // Check for a protocol
             $protocol = parse_url($value, PHP_URL_SCHEME);
             // If there is no protocol and the relative option is not specified,
             // we assume that it is an external URL and prepend http://.
             if ($element['type'] == 'url' && !$protocol && !$element['relative'] || !$element['type'] == 'url' && !$protocol) {
                 $protocol = 'http';
                 // If it looks like an internal link, then add the root.
                 if (substr($value, 0) == 'index.php') {
                     $value = Uri::root() . $value;
                 }
                 // Otherwise we treat it is an external link.
                 // Put the url back together.
                 $value = $protocol . '://' . $value;
             } elseif (!$protocol && $element['relative']) {
                 $host = Uri::getInstance('SERVER')->gethost();
                 // If it starts with the host string, just prepend the protocol.
                 if (substr($value, 0) == $host) {
                     $value = 'http://' . $value;
                 } else {
                     $value = Uri::root() . $value;
                 }
             }
             $return = $value;
             break;
         case 'TEL':
             $value = trim($value);
             // Does it match the NANP pattern?
             if (preg_match('/^(?:\\+?1[-. ]?)?\\(?([2-9][0-8][0-9])\\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/', $value) == 1) {
                 $number = (string) preg_replace('/[^\\d]/', '', $value);
                 if (substr($number, 0, 1) == 1) {
                     $number = substr($number, 1);
                 }
                 if (substr($number, 0, 2) == '+1') {
                     $number = substr($number, 2);
                 }
                 $result = '1.' . $number;
             } elseif (preg_match('/^\\+(?:[0-9] ?){6,14}[0-9]$/', $value) == 1) {
                 $countrycode = substr($value, 0, strpos($value, ' '));
                 $countrycode = (string) preg_replace('/[^\\d]/', '', $countrycode);
                 $number = strstr($value, ' ');
                 $number = (string) preg_replace('/[^\\d]/', '', $number);
                 $result = $countrycode . '.' . $number;
             } elseif (preg_match('/^\\+[0-9]{1,3}\\.[0-9]{4,14}(?:x.+)?$/', $value) == 1) {
                 if (strstr($value, 'x')) {
                     $xpos = strpos($value, 'x');
                     $value = substr($value, 0, $xpos);
                 }
                 $result = str_replace('+', '', $value);
             } elseif (preg_match('/[0-9]{1,3}\\.[0-9]{4,14}$/', $value) == 1) {
                 $result = $value;
             } else {
                 $value = (string) preg_replace('/[^\\d]/', '', $value);
                 if ($value != null && strlen($value) <= 15) {
                     $length = strlen($value);
                     // If it is fewer than 13 digits assume it is a local number
                     if ($length <= 12) {
                         $result = '.' . $value;
                     } else {
                         // If it has 13 or more digits let's make a country code.
                         $cclen = $length - 12;
                         $result = substr($value, 0, $cclen) . '.' . substr($value, $cclen);
                     }
                 } else {
                     $result = '';
                 }
             }
             $return = $result;
             break;
         default:
             // Check for a callback filter.
             if (strpos($filter, '::') !== false && is_callable(explode('::', $filter))) {
                 $return = call_user_func(explode('::', $filter), $value);
             } elseif (function_exists($filter)) {
                 $return = call_user_func($filter, $value);
             } else {
                 $return = Input::getInstance()->clean($value, $filter);
             }
             break;
     }
     return $return;
 }