Beispiel #1
0
 /**
  * Generate a URL to a route
  *
  * @param string	$route		Name of the route to travel
  * @param array	$params		String or array of additional url parameters
  * @param bool	$is_amp		Is url using & (true) or & (false)
  * @param string|bool		$session_id	Possibility to use a custom session id instead of the global one
  * @param bool|string		$reference_type The type of reference to be generated (one of the constants)
  * @return string The URL already passed through append_sid()
  */
 public function route($route, array $params = array(), $is_amp = true, $session_id = false, $reference_type = UrlGeneratorInterface::ABSOLUTE_PATH)
 {
     $anchor = '';
     if (isset($params['#'])) {
         $anchor = '#' . $params['#'];
         unset($params['#']);
     }
     $context = new RequestContext();
     $context->fromRequest($this->symfony_request);
     if ($this->config['force_server_vars']) {
         $context->setHost($this->config['server_name']);
         $context->setScheme(substr($this->config['server_protocol'], 0, -3));
         $context->setHttpPort($this->config['server_port']);
         $context->setHttpsPort($this->config['server_port']);
         $context->setBaseUrl(rtrim($this->config['script_path'], '/'));
     }
     $script_name = $this->symfony_request->getScriptName();
     $page_name = substr($script_name, -1, 1) == '/' ? '' : utf8_basename($script_name);
     $base_url = $context->getBaseUrl();
     // Append page name if base URL does not contain it
     if (!empty($page_name) && strpos($base_url, '/' . $page_name) === false) {
         $base_url .= '/' . $page_name;
     }
     // If enable_mod_rewrite is false we need to replace the current front-end by app.php, otherwise we need to remove it.
     $base_url = str_replace('/' . $page_name, empty($this->config['enable_mod_rewrite']) ? '/app.' . $this->php_ext : '', $base_url);
     // We need to update the base url to move to the directory of the app.php file if the current script is not app.php
     if ($page_name !== 'app.php' && !$this->config['force_server_vars']) {
         if (empty($this->config['enable_mod_rewrite'])) {
             $base_url = str_replace('/app.' . $this->php_ext, '/' . $this->phpbb_root_path . 'app.' . $this->php_ext, $base_url);
         } else {
             $base_url .= preg_replace(get_preg_expression('path_remove_dot_trailing_slash'), '$2', $this->phpbb_root_path);
         }
     }
     $base_url = $this->request->escape($this->filesystem->clean_path($base_url), true);
     $context->setBaseUrl($base_url);
     $this->router->setContext($context);
     $route_url = $this->router->generate($route, $params, $reference_type);
     if ($is_amp) {
         $route_url = str_replace(array('&', '&'), array('&', '&'), $route_url);
     }
     if ($reference_type === UrlGeneratorInterface::RELATIVE_PATH && empty($this->config['enable_mod_rewrite'])) {
         $route_url = 'app.' . $this->php_ext . '/' . $route_url;
     }
     return append_sid($route_url . $anchor, false, $is_amp, $session_id, true);
 }
Beispiel #2
0
 /**
  * Returns the name of the active main menu item
  *
  * @param array	$nav_array
  *
  * @return string|bool	Returns the name of the active main menu element, if the element not found, returns false
  */
 protected function get_active_main_menu($nav_array)
 {
     $active_route = $this->request->get('_route');
     foreach ($nav_array as $nav_name => $nav_options) {
         $current_menu = $nav_name;
         if (isset($nav_options['route']) && $nav_options['route'] === $active_route) {
             return $nav_name;
         }
         if (is_array($nav_options[0])) {
             foreach ($nav_options[0] as $sub_menus) {
                 if (isset($sub_menus['route']) && $sub_menus['route'] === $active_route) {
                     return $current_menu;
                 }
             }
         }
     }
     return false;
 }
 /**
  * Get a relative root path from the current URL
  *
  * @return string
  */
 public function get_web_root_path()
 {
     if ($this->symfony_request === null) {
         return $this->phpbb_root_path;
     }
     if (null !== $this->web_root_path) {
         return $this->web_root_path;
     }
     // We do not need to escape $path_info, $request_uri and $script_name because we can not find their content in the result.
     // Path info (e.g. /foo/bar)
     $path_info = $this->filesystem->clean_path($this->symfony_request->getPathInfo());
     // Full request URI (e.g. phpBB/app.php/foo/bar)
     $request_uri = $this->symfony_request->getRequestUri();
     // Script name URI (e.g. phpBB/app.php)
     $script_name = $this->symfony_request->getScriptName();
     /*
      * If the path info is empty but we're using app.php, then we
      *	might be using an empty route like app.php/ which is
      *	supported by symfony's routing
      */
     if ($path_info === '/' && preg_match('/app\\.' . $this->php_ext . '\\/$/', $request_uri)) {
         return $this->web_root_path = $this->filesystem->clean_path('./../' . $this->phpbb_root_path);
     }
     /*
      * If the path info is empty (single /), then we're not using
      *	a route like app.php/foo/bar
      */
     if ($path_info === '/') {
         return $this->web_root_path = $this->phpbb_root_path;
     }
     /*
      * Check AJAX request:
      * If the current request is a AJAX we need to fix the paths.
      * We need to get the root path based on the Referer, so we can use
      * the generated URLs in the template of the Referer. If we do not
      * generate the relative path based on the Referer, but based on the
      * currently requested URL, the generated URLs will not point to the
      * intended locations:
      *	Referer				desired URL			desired relative root path
      *	memberlist.php		faq.php				./
      *	memberlist.php		app.php/foo/bar		./
      *	app.php/foo			memberlist.php		../
      *	app.php/foo			app.php/fox			../
      *	app.php/foo/bar		memberlist.php		../../
      *	../page.php			memberlist.php		./phpBB/
      *	../sub/page.php		memberlist.php		./../phpBB/
      *
      * The referer must be specified as a parameter in the query.
      */
     if ($this->request->is_ajax() && $this->symfony_request->get('_referer')) {
         // We need to escape $absolute_board_url because it can be partially concatenated to the result.
         $absolute_board_url = $this->request->escape($this->symfony_request->getSchemeAndHttpHost() . $this->symfony_request->getBasePath(), true);
         $referer_web_root_path = $this->get_web_root_path_from_ajax_referer($this->symfony_request->get('_referer'), $absolute_board_url);
         return $this->web_root_path = $this->phpbb_root_path . $referer_web_root_path;
     }
     // How many corrections might we need?
     $corrections = substr_count($path_info, '/');
     /*
      * If the script name (e.g. phpBB/app.php) does not exists in the
      * requestUri (e.g. phpBB/app.php/foo/template), then we are rewriting
      * the URL. So we must reduce the slash count by 1.
      */
     if (strpos($request_uri, $script_name) !== 0) {
         $corrections--;
     }
     // Prepend ../ to the phpbb_root_path as many times as / exists in path_info
     $this->web_root_path = $this->filesystem->clean_path('./' . str_repeat('../', $corrections) . $this->phpbb_root_path);
     return $this->web_root_path;
 }
Beispiel #4
0
 /**
  * assign / retrun meta tag code
  */
 public function build_meta($page_title = '', $return = false)
 {
     // If meta robots was not manually set
     if (empty($this->meta['robots'])) {
         // Full request URI (e.g. phpBB/app.php/foo/bar)
         $request_uri = $this->symfony_request->getRequestUri();
         // Deny indexing for any url ending with htm(l) or / aznd with a qs (?)
         if (preg_match('`(\\.html?|/)\\?[^\\?]*$`i', $request_uri)) {
             $this->meta['robots'] = 'noindex,follow';
         } else {
             // lets still add some more specific ones
             $this->config['get_filter'] = array_merge($this->config['get_filter'], array('st', 'sk', 'sd', 'ch'));
         }
         // Do we allow indexing based on physical script file name
         if (empty($this->meta['robots'])) {
             if (!empty($this->user->page['page_name']) && strpos($this->config['file_filter'], str_replace(".{$this->php_ext}", '', $this->user->page['page_name'])) !== false) {
                 $this->meta['robots'] = 'noindex,follow';
             }
         }
         // Do we allow indexing based on get variable
         if (empty($this->meta['robots'])) {
             foreach ($this->config['get_filter'] as $get) {
                 if (isset($_GET[$get])) {
                     $this->meta['robots'] = 'noindex,follow';
                     break;
                 }
             }
         }
         // fallback to default if necessary
         if (empty($this->meta['robots'])) {
             $this->meta['robots'] = $this->meta_def['robots'];
         }
     }
     if (!empty($this->config['seo_meta_noarchive'])) {
         $forum_id = isset($_GET['f']) ? max(0, request_var('f', 0)) : 0;
         if ($forum_id) {
             $forum_ids = @explode(',', preg_replace('`[\\s]+`', '', trim($this->config['seo_meta_noarchive'], ', ')));
             if (in_array($forum_id, $forum_ids)) {
                 $this->meta['robots'] .= (!empty($this->meta['robots']) ? ',' : '') . 'noarchive';
             }
         }
     }
     // deal with titles, assign the tag if a default is set
     if (empty($this->meta['title']) && !empty($this->meta_def['title'])) {
         $this->meta['title'] = $page_title;
     }
     $meta_code = '';
     foreach ($this->tpl as $key => $value) {
         if (isset($this->meta[$key])) {
             // do like this so we can deactivate one particular tag on a given page,
             // by just setting the meta to an empty string
             if (trim($this->meta[$key])) {
                 $this->meta[$key] = isset($this->filters[$key]) ? $this->{$this->filters[$key]}($this->meta[$key]) : $this->meta[$key];
             }
         } else {
             if (!empty($this->meta_def[$key])) {
                 $this->meta[$key] = isset($this->filters[$key]) ? $this->{$this->filters[$key]}($this->meta_def[$key]) : $this->meta_def[$key];
             }
         }
         if (trim($this->meta[$key])) {
             $meta_code .= sprintf($value, utf8_htmlspecialchars($this->meta[$key])) . "\n";
         }
     }
     if (!$return) {
         $this->template->assign_var('SEO_META_TAGS', $meta_code);
     } else {
         return $meta_code;
     }
 }