From da6ebf84e8d4bd4d8655bcce4fc6e0cc0ecc1af5 Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@git-test.afi-sa.fr> Date: Thu, 5 Sep 2013 09:36:42 +0000 Subject: [PATCH] Ajout Router pour l'url rewriting rel #9281 --- .gitattributes | 1 + .../Router/RewriteWithoutBaseUrl.php | 53 +++++++++++++++++++ library/startup.php | 11 ++-- 3 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 library/ZendAfi/Controller/Router/RewriteWithoutBaseUrl.php diff --git a/.gitattributes b/.gitattributes index 13399d35c2f..599065d397a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2663,6 +2663,7 @@ library/ZendAfi/Controller/Plugin/SelectionBib.php -text library/ZendAfi/Controller/Plugin/SetupLocale.php -text library/ZendAfi/Controller/Plugin/System.php -text library/ZendAfi/Controller/Plugin/XHProfile.php -text +library/ZendAfi/Controller/Router/RewriteWithoutBaseUrl.php -text library/ZendAfi/Feed.php -text library/ZendAfi/Filters/Post.php -text library/ZendAfi/Filters/ReadSql.php -text diff --git a/library/ZendAfi/Controller/Router/RewriteWithoutBaseUrl.php b/library/ZendAfi/Controller/Router/RewriteWithoutBaseUrl.php new file mode 100644 index 00000000000..f2d898d441a --- /dev/null +++ b/library/ZendAfi/Controller/Router/RewriteWithoutBaseUrl.php @@ -0,0 +1,53 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class ZendAfi_Controller_Router_RewriteWithoutBaseUrl extends Zend_Controller_Router_Rewrite { + /** + * Generates a URL path that can be used in URL creation, redirection, etc. + * + * @param array $userParams Options passed by a user used to override parameters + * @param mixed $name The name of a Route to use + * @param bool $reset Whether to reset to the route defaults ignoring URL params + * @param bool $encode Tells to encode URL parts on output + * @throws Zend_Controller_Router_Exception + * @return string Resulting absolute URL path + */ + public function assemble($userParams, $name = null, $reset = false, $encode = true) { + if ($name == null) { + try { + $name = $this->getCurrentRouteName(); + } catch (Zend_Controller_Router_Exception $e) { + $name = 'default'; + } + } + + $route = $this->getRoute($name); + $url = $route->assemble($userParams, $reset, $encode); + + if (!preg_match('|^[a-z]+://|', $url)) { + $url = '/'. $url; + } + + return $url; + } +} + +?> \ No newline at end of file diff --git a/library/startup.php b/library/startup.php index a70c428cc14..bdef801b2c4 100644 --- a/library/startup.php +++ b/library/startup.php @@ -41,7 +41,7 @@ function setupOpac() { setupCache($cfg); setupMail($cfg); - $front_controller = setupFrontController(); + $front_controller = setupFrontController($cfg); return $front_controller; } @@ -265,7 +265,7 @@ function setupMail($cfg) { } -function setupFrontController() { +function setupFrontController($cfg) { $front_controller = Zend_Controller_Front::getInstance() ->addModuleDirectory(MODULEDIRECTORY) ->addControllerDirectory(ROOT_PATH.'afi/application/modules/opacpriv/controllers','opacpriv') @@ -282,7 +282,7 @@ function setupFrontController() { ->setParam('useDefaultControllerAlways', true); - setupRoutes($front_controller); + setupRoutes($front_controller, $cfg); if (!Class_Users::isCurrentUserSuperAdmin()) return $front_controller; @@ -303,7 +303,10 @@ function setupFrontController() { } -function setupRoutes($front_controller) { +function setupRoutes($front_controller, $cfg) { + if ('1' == $cfg->get('enable_rewriting')) + $front_controller->setRouter(new ZendAfi_Controller_Router_RewriteWithoutBaseUrl()); + $front_controller ->getRouter() ->addRoute('embed', -- GitLab