1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
<?php
/*
* $RCSfile: RewriteParser.class,v $
*
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2006 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
/**
* @package Rewrite
* @version $Revision: 1.2 $ $Date: 2006/01/10 04:42:16 $
* @author Douglas Cau <douglas@cau.se>
*/
/**
* RewriteParser class. Parsers are stored in modules/rewrite/classes/parsers/<parserId>
* and require a parser.inc file in that directory.
*
* @package Rewrite
* @subpackage Classes
*/
class RewriteParser {
/**
* The id of this parser
*
* @var string parser id
* @access private
*/
var $_parserId;
/**
* The name of this url generator class
*
* @var string url generator class name
* @access private
*/
var $_urlGeneratorId;
/**
* The type of this parser. Can be either 'preGallery' or 'inGallery'
*
* @var string url generator class name
* @access private
*/
var $_type;
/**
* Saves the active rewrite rules. This needs to be implemented by the specific plugin. It
* needs to save two rewrite params, activeRules and shortUrls. activeRules is just a
* serialized array of the given activeRules, and shortUrls is returned by
* RewriteHelper::parseActiveRules(). It returns REWRITE_STATUS_OK on success.
*
* @param array active rules (if null, or not set, it defaults to the current rules)
* @param object RewriteModule (optional)
* @return array object GalleryStatus a status code
* int rewrite status code (REWRITE_STATUS_OK on success)
* array string module (on error)
* int rule id (on error)
*/
function saveActiveRules($activeRules=null, $rewriteModule=null) {
return array(GalleryCoreApi::error(ERROR_UNIMPLEMENTED, __FILE__, __LINE__), null, null);
}
/**
* Saves the list of host gallery allows as referer, and if gallery should allow an empty
* referer. This needs to be implemented by the specific plugin. It needs to save a serialized
* array of the hosts and the value of allowEmptyReferer to the params accessList and
* allowEmptyReferer.
*
* @param array access list of referer hosts
* @param boolean true if gallery should allow empty referer
* @return array object GalleryStatus a status code
* int rewrite status code (REWRITE_STATUS_OK on success)
*/
function saveAccessList($accessList, $allowEmptyReferer) {
return array(GalleryCoreApi::error(ERROR_UNIMPLEMENTED, __FILE__, __LINE__), null);
}
/**
* By default there's nothing to configure, so we return success.
*
* @return array object GalleryStatus a status code
* boolean true if this parser needs configuration
*/
function needsConfiguration() {
return array(null, false);
}
/**
* This function is called when new rules are saved and by rewrite.AdminRewrite to know if this
* rule should be displayed. If the parser overrides this function it needs to call this (the
* parent). It also verifies that locked rules are saved with the original pattern. We perform
* a sanity check to minimize possible conflicts and bad regular expression.
*
* @param array rewrite rule
* @param string (optional) set to the custom pattern when called from saveActiveRules
* @return boolean true if the rule is valid
*/
function isValidRule($rule, $pattern=null) {
if (isset($rule['parser']) && $rule['parser'] != $this->getParserType()) {
return false;
}
if (isset($rule['locked']) && isset($pattern) && $rule['pattern'] != $pattern) {
return false;
}
if (isset($pattern) && !preg_match('/^([a-zA-Z0-9\/\.\%\-]+)$/', $pattern)) {
return false;
}
return true;
}
/**
* Returns translated error message, called from AdminRewrite when an unsucsessful save
* has been made. A valid $code is anything that $this->saveActiveRules would return if an
* error occurs.
*
* @param int rewrite status code
* @param object RewriteModule (optional)
* @return array object GalleryStatus a status code
* string translated error message
*/
function getErrorMessage($code, $rewriteModule=null) {
if (!isset($rewriteModule)) {
list($ret, $rewriteModule) = GalleryCoreApi::loadPlugin('module', 'rewrite');
if ($ret) {
return array($ret->wrap(__FILE__, __LINE__), null);
}
}
switch ($code) {
case REWRITE_STATUS_BAD_KEYWORD:
return array(null,
$rewriteModule->translate('Bad keyword.'));
case REWRITE_STATUS_DUPE_SHORT_URL:
return array(null,
$rewriteModule->translate('Duplicate short url rule.'));
case REWRITE_STATUS_INVALID_PATTERN:
return array(null,
$rewriteModule->translate('Ivalid pattern.'));
case REWRITE_STATUS_EMPTY_VALUE:
return array(null,
$rewriteModule->translate('Empty configuration value.'));
}
return array(null, null);
}
/**
* Displays the test results if the template variable $TestResults.body is set. It should
* be a gallery base dir relative path.
*
* @param object GalleryTemplate the template instance
* @param array the form values
* @return object GalleryStatus a status code
*/
function loadTestResultsTemplate(&$template, &$form) {
return null;
}
/**
* Handles the submitted form and should save any settings (ie forced tests).
*
* @param array the form values
* @return array object GalleryStatus a status code
* array error codes
* array status codes
*/
function handleTestResultsRequest($form) {
return array(null, array(), array());
}
/**
* Displays the parser configuration if the template variable $AdminParser.body is set. It
* should be a gallery base dir relative path.
*
* @param object GalleryTemplate the template instance
* @param array the form values
* @return object GalleryStatus a status code
*/
function loadAdminParserTemplate(&$template, &$form) {
return null;
}
/**
* Handles the submitted form and should save the settings.
*
* @param array the form values
* @return array object GalleryStatus a status code
* array error codes
* array status codes
*/
function handleAdminParserRequest($form) {
return array(null, array(), array());
}
/**
* @see RewriteApi::needsEmbedConfig
*/
function needsEmbedConfig() {
return array(null, false);
}
/**
* @see RewriteApi::fetchEmbedConfig
*/
function fetchEmbedConfig() {
return array(null, array());
}
/**
* @see RewriteApi::saveEmbedConfig
*/
function saveEmbedConfig($params) {
return array(null, REWRITE_STATUS_OK, null);
}
/* Getters and setters below */
function _setParserId($parserId) {
$this->_parserId = $parserId;
}
function getParserId() {
return $this->_parserId;
}
function _setUrlGeneratorId($urlGenerator) {
$this->_urlGeneratorId = $urlGenerator;
}
function getUrlGeneratorId() {
return $this->_urlGeneratorId;
}
function _setParserType($parserType) {
$this->_type = $parserType;
}
function getParserType() {
return $this->_type;
}
}
?>
|