~ubuntu-branches/ubuntu/lucid/gallery2/lucid

« back to all changes in this revision

Viewing changes to modules/rewrite/classes/parsers/modrewrite/ModRewriteUrlGenerator.class

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2008-10-19 05:01:26 UTC
  • mfrom: (1.1.8 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20081019050126-25a4kxy8z7orqxx5
Tags: 2.3-1
New upstream release (Closes: #502681)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
/*
3
3
 * Gallery - a web based photo album viewer and editor
4
 
 * Copyright (C) 2000-2007 Bharat Mediratta
 
4
 * Copyright (C) 2000-2008 Bharat Mediratta
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or modify
7
7
 * it under the terms of the GNU General Public License as published by
26
26
 * @package Rewrite
27
27
 * @subpackage Parsers
28
28
 * @author Douglas Cau <douglas@cau.se>
29
 
 * @version $Revision: 17652 $
 
29
 * @version $Revision: 17580 $
30
30
 */
31
31
class ModRewriteUrlGenerator extends RewriteUrlGenerator {
32
32
 
33
33
    /**
 
34
     * @see GalleryUrlGenerator::init
 
35
     */
 
36
    function init($baseUri=null, $g2Uri=null, $embedSessionString=null) {
 
37
        /* Verify that we're configured to work in this mode.  Else disable short-URLs. */
 
38
        $location = GalleryUtilities::isEmbedded() ? 'embeddedLocation' : 'galleryLocation';
 
39
        list ($ret, $configuredLocation) =
 
40
            GalleryCoreApi::getPluginParameter('module', 'rewrite', 'modrewrite.' . $location);
 
41
        if ($ret) {
 
42
            return $ret;
 
43
        }
 
44
        if (empty($configuredLocation)) {
 
45
            /* Disable short-URLs */
 
46
            $this->_error = true;
 
47
        }
 
48
 
 
49
        return parent::init($baseUri, $g2Uri, $embedSessionString);
 
50
    }
 
51
 
 
52
    /**
34
53
     * @see GalleryUrlGenerator::initNavigation
35
54
     */
36
55
    function initNavigation() {
79
98
            $tmp = $path . $this->_file[$forceDirect];
80
99
            $queryString = GalleryUtilities::getServerVar('QUERY_STRING');
81
100
            if (!empty($queryString)) {
82
 
                $queryString = ModRewriteUrlGenerator::_sanitizeRequestUri($queryString);
 
101
                GalleryUtilities::unsanitizeInputValues($queryString, false);
83
102
                $tmp .= ((strpos($tmp, '?') === false) ? '?' : '&') . $queryString;
84
103
            }
85
104
 
99
118
 
100
119
        return parent::generateUrl($params, $options);
101
120
    }
102
 
 
103
 
    /**
104
 
     * Sanitize a request URI (REQUEST_URI / QUERY_STRING).
105
 
     *
106
 
     * Apply URL specific input filering (RFC 1738), thereby removing illegal characters.
107
 
     * Note that single quotes and any URL encoded characters are allowed.
108
 
     *
109
 
     * @param string $uri
110
 
     * @return filtered $uri
111
 
     */
112
 
    function _sanitizeRequestUri($uri) {
113
 
        GalleryUtilities::unsanitizeInputValues($uri, false);
114
 
        /* Normalize slashes */
115
 
        $uri = str_replace('\\', '/', $uri);
116
 
        /* Be tolerant: allow for space, single quote and pipe */
117
 
        $uri = preg_replace("{[^A-Za-z0-9_\-$./+!*'(),~?&=# %|]}", '', $uri);
118
 
        /* Don't allow for games in the path */
119
 
        return str_replace('/../', '/', $uri);
120
 
    }
121
121
}
122
122
?>