Annotation of /mambo/branches/4.6/includes/sef.php
Parent Directory
|
Revision Log
Revision 223 - (view) (download)
| 1 : | mambo | 117 | <?php |
| 2 : | /** | ||
| 3 : | * @version $Id: sef.php,v 1.3 2005/11/23 22:49:07 csouza Exp $ | ||
| 4 : | * @package Mambo | ||
| 5 : | * @copyright (C) 2000 - 2005 Miro International Pty Ltd | ||
| 6 : | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL | ||
| 7 : | * Mambo is Free Software | ||
| 8 : | */ | ||
| 9 : | |||
| 10 : | class mosSEF { | ||
| 11 : | |||
| 12 : | counterpoi | 222 | t var $prefix = ''; |
| 13 : | mambo | 117 | var $custom_code = array(); |
| 14 : | var $custom_name = array(); | ||
| 15 : | var $custom_PHP = array(); | ||
| 16 : | var $custom_short = array(); | ||
| 17 : | var $sef_content_task = array(); | ||
| 18 : | var $sef_name_chars = array(); | ||
| 19 : | var $sef_translate_chars = array(); | ||
| 20 : | var $content_data = null; | ||
| 21 : | var $content_items = array(); | ||
| 22 : | var $content_sections = array(); | ||
| 23 : | var $content_categories = array(); | ||
| 24 : | var $SEF_SPACE; | ||
| 25 : | |||
| 26 : | function mosSEF () { | ||
| 27 : | /******************************************************************************* | ||
| 28 : | ** The following are parameters for the ReMOSef Search Engine | ||
| 29 : | ** Optimisation component. $this->SEF_SPACE should be set to the | ||
| 30 : | ** character that is to replace blanks in names that form the URL. | ||
| 31 : | ** You can vary this, although the only sensible choices seem to be | ||
| 32 : | ** underscore or hyphen (_ or -). | ||
| 33 : | ** | ||
| 34 : | ** The arrays $this->custom_code and $this->custom_name must be kept exactly | ||
| 35 : | ** in step with each other. $this->custom_code is a list of the components | ||
| 36 : | ** that are to be handled by ReMOSef. | ||
| 37 : | ** | ||
| 38 : | ** The array $this->custom_name is the alternative name that will be used | ||
| 39 : | ** in the optimised URL to identify the component and can be whatever | ||
| 40 : | ** you please so long as it is unique and legal for a URL. Apart from | ||
| 41 : | ** using the custom name for the component, ReMOSef will do no further | ||
| 42 : | ** translation of the URL than is done by the standard Mambo SEF - UNLESS | ||
| 43 : | ** there is a sef_ext.php file installed for that component. The | ||
| 44 : | ** exception to this is ReMOSitory - the optimisation code for Remository | ||
| 45 : | ** is integrated in ReMOSef. For other components, if a sef_ext.php is | ||
| 46 : | ** present, it will be invoked by ReMOSef. | ||
| 47 : | ** | ||
| 48 : | ** The array $remosef_content_task is capable of translating the tasks | ||
| 49 : | ** understood by the Mambo content component. Please DO NOT CHANGE what | ||
| 50 : | ** is to the left of the equals sign. When putting different values on | ||
| 51 : | ** the right hand side, remember that they must all be different, and must | ||
| 52 : | ** also be different from any of the custom names used for components. | ||
| 53 : | ** Without that, Remosef cannot figure out what a SEF URL means and will | ||
| 54 : | ** give unpredictable results. | ||
| 55 : | *******************************************************************************/ | ||
| 56 : | $this->SEF_SPACE = "_"; // divide words with underscores | ||
| 57 : | // can be changed to a hyphen "-" | ||
| 58 : | counterpoi | 222 | t $this->custom_code = array('com_frontpage','com_contact'); |
| 59 : | t $this->custom_name = array('Frontpage','Contact_Us'); | ||
| 60 : | mambo | 117 | /******************************************************************************* |
| 61 : | ** The following are the parameters for the optional content specific | ||
| 62 : | ** URL optimisation. | ||
| 63 : | ** | ||
| 64 : | ** The following two lines define the translations that SEF will perform on | ||
| 65 : | ** names of sections and categories when translating them for inclusion in a URL. | ||
| 66 : | ** Each item in $this->sef_name_chars is translated into the corresponding | ||
| 67 : | ** element of $this->sef_translate_chars. | ||
| 68 : | ** | ||
| 69 : | ** NOTE it is important that space be the last translate character, since the | ||
| 70 : | ** characters are processed in the order in which they appear. Since earlier | ||
| 71 : | ** translates may create new spaces, it is vital that the space translation is | ||
| 72 : | ** done last. | ||
| 73 : | ** | ||
| 74 : | ** You can extend these arrays as you wish, although it is obviously important | ||
| 75 : | ** to make sure that the items of one match the items of the other exactly. | ||
| 76 : | *******************************************************************************/ | ||
| 77 : | csouza | 129 | $this->sef_name_chars = array('', '?', '&', '/', ' '); |
| 78 : | $this->sef_translate_chars = array('-', '', 'and', ' or ', $this->SEF_SPACE); | ||
| 79 : | mambo | 117 | |
| 80 : | /************** DO NOT MAKE CHANGES PAST HERE EXCEPT AT YOUR OWN RISK! ********************/ | ||
| 81 : | |||
| 82 : | counterpoi | 222 | t if (mamboCore::is_set('mosConfig_sef_prefix')) $this->prefix = mamboCore::get('mosConfig_sef_prefix'); |
| 83 : | t else $this->prefix = 'mos'; | ||
| 84 : | t if ($this->prefix == 'content' OR $this->prefix == 'component') $this->prefix = 'mos'; | ||
| 85 : | mambo | 117 | foreach ($this->custom_code as $code) { |
| 86 : | $codefile = "components/$code/sef_ext.php"; | ||
| 87 : | if (file_exists($codefile)) { | ||
| 88 : | include ($codefile); | ||
| 89 : | $this->custom_PHP[] = true; | ||
| 90 : | } | ||
| 91 : | else $this->custom_PHP[] = false; | ||
| 92 : | $split = explode('_',$code); | ||
| 93 : | $this->custom_short[] = $split[1]; | ||
| 94 : | } | ||
| 95 : | |||
| 96 : | $this->sef_content_task['findkey'] = 'findkey'; | ||
| 97 : | $this->sef_content_task['view'] = 'view'; | ||
| 98 : | $this->sef_content_task['section'] = 'section'; | ||
| 99 : | $this->sef_content_task['category'] = 'category'; | ||
| 100 : | $this->sef_content_task['blogsection'] = 'blogsection'; | ||
| 101 : | $this->sef_content_task['blogcategorymulti'] = 'blogcategorymulti'; | ||
| 102 : | $this->sef_content_task['blogcategory'] = 'blogcategory'; | ||
| 103 : | $this->sef_content_task['archivesection'] = 'archivesection'; | ||
| 104 : | $this->sef_content_task['archivecategory'] = 'archivecategory'; | ||
| 105 : | $this->sef_content_task['save'] = 'save'; | ||
| 106 : | $this->sef_content_task['cancel'] = 'cancel'; | ||
| 107 : | $this->sef_content_task['emailform'] = 'emailform'; | ||
| 108 : | $this->sef_content_task['emailsend'] = 'emailsend'; | ||
| 109 : | $this->sef_content_task['vote'] = 'vote'; | ||
| 110 : | $this->sef_content_task['showblogsection'] = 'showblogsection'; | ||
| 111 : | |||
| 112 : | } | ||
| 113 : | |||
| 114 : | function &getInstance () { | ||
| 115 : | static $instance; | ||
| 116 : | if (!is_object($instance)) $instance = new mosSEF(); | ||
| 117 : | return $instance; | ||
| 118 : | } | ||
| 119 : | |||
| 120 : | function sefRetrieval($register_globals){ | ||
| 121 : | |||
| 122 : | if (preg_match('/(\b)GLOBALS|_REQUEST|_SERVER|_ENV|_COOKIE|_GET|_POST|_FILES|_SESSION(\b)/i', $_SERVER['REQUEST_URI']) > 0) { | ||
| 123 : | die('Invalid Request'); | ||
| 124 : | } | ||
| 125 : | if (mamboCore::get('mosConfig_sef')) { | ||
| 126 : | counterpoi | 222 | t $subdir = mamboCore::get('subdirectory'); |
| 127 : | t $uri = substr($_SERVER['REQUEST_URI'], strlen($subdir)); | ||
| 128 : | t $url_array = explode('/', $uri); | ||
| 129 : | mambo | 117 | /** |
| 130 : | * Content | ||
| 131 : | * /$option/$task/$sectionid/$id/$Itemid/$limit/$limitstart | ||
| 132 : | */ | ||
| 133 : | |||
| 134 : | $foundit = false; | ||
| 135 : | if ($url_array[1] == 'content') { | ||
| 136 : | $foundit = true; | ||
| 137 : | $_REQUEST['option'] = $_GET['option'] = $option = 'com_content'; | ||
| 138 : | |||
| 139 : | // language hook for content | ||
| 140 : | $lang = ""; | ||
| 141 : | $parms = array(); | ||
| 142 : | foreach($url_array as $key=>$value) { | ||
| 143 : | if ( strcasecmp(substr($value,0,5),'lang,') == 0 ) { | ||
| 144 : | $parts = explode(",", $value); | ||
| 145 : | if (count($parts) > 1) { | ||
| 146 : | $lang = $_REQUEST['lang'] = $_GET['lang'] = $parts[1]; | ||
| 147 : | } | ||
| 148 : | } | ||
| 149 : | elseif ( $value != '' AND $key > 1 ) $parms[] = $value; | ||
| 150 : | } | ||
| 151 : | |||
| 152 : | // $option/$task/$sectionid/$id/$Itemid/$limit/$limitstart | ||
| 153 : | $task = array_search($parms[0], $this->sef_content_task); | ||
| 154 : | if ($task === false OR $task === null) return 1; | ||
| 155 : | $_REQUEST['task'] = $_GET['task'] = $task; | ||
| 156 : | $QUERY_STRING = "option=com_content&task=$task"; | ||
| 157 : | $num = count($parms); | ||
| 158 : | for ($i = 1; $i <= $num-1; $i++) { | ||
| 159 : | if (strcmp($parms[$i], (int)$parms[$i]) !== 0) return 1; | ||
| 160 : | } | ||
| 161 : | $i = 1; | ||
| 162 : | if ($num == 6 OR $num == 4) { | ||
| 163 : | $_REQUEST['sectionid'] = $_GET['sectionid'] = $sectionid = $parms[$i]; | ||
| 164 : | $QUERY_STRING .= "§ionid=$sectionid"; | ||
| 165 : | $i++; | ||
| 166 : | } | ||
| 167 : | if ($num > 1) { | ||
| 168 : | $_REQUEST['id'] = $_GET['id'] = $id = $parms[$i]; | ||
| 169 : | $QUERY_STRING .= "&id=$id"; | ||
| 170 : | } | ||
| 171 : | if ($num > 2) { | ||
| 172 : | $_REQUEST['Itemid'] = $_GET['Itemid'] = $Itemid = $parms[$i+1]; | ||
| 173 : | mamboCore::set('Itemid',$Itemid); | ||
| 174 : | $QUERY_STRING .= "&Itemid=$Itemid"; | ||
| 175 : | } | ||
| 176 : | if ($num > 4) { | ||
| 177 : | $_REQUEST['limit'] = $_GET['limit'] = $limit = $parms[$i+2]; | ||
| 178 : | $_REQUEST['limitstart'] = $_GET['limitstart'] = $limitstart = $parms[$i+3]; | ||
| 179 : | $QUERY_STRING .= "&limit=$limit&limitstart=$limitstart"; | ||
| 180 : | } | ||
| 181 : | |||
| 182 : | if ($lang!="") { | ||
| 183 : | $QUERY_STRING .= "&lang=$lang"; | ||
| 184 : | } | ||
| 185 : | } | ||
| 186 : | |||
| 187 : | /* | ||
| 188 : | Components | ||
| 189 : | http://www.domain.com/component/$name,$value | ||
| 190 : | */ | ||
| 191 : | elseif ($url_array[1] == 'component') { | ||
| 192 : | $QUERY_STRING = $this->default_revert('component'); | ||
| 193 : | counterpoi | 222 | t if ($QUERY_STRING) $foundit = true; |
| 194 : | mambo | 117 | } |
| 195 : | counterpoi | 222 | t elseif ($url_array[1] == $this->prefix) { |
| 196 : | mambo | 117 | $menuhandler = mosMenuHandler::getInstance(); |
| 197 : | foreach ($this->custom_name as $i=>$compname) { | ||
| 198 : | counterpoi | 222 | t if ($url_array[2] == $compname) { |
| 199 : | mambo | 117 | $origname = $this->custom_code[$i]; |
| 200 : | $_REQUEST['Itemid'] = $_GET['Itemid'] = $Itemid = $menuhandler->getIDLikeLink("index.php?option=$origname"); | ||
| 201 : | mamboCore::set('Itemid', $Itemid); | ||
| 202 : | if ($this->custom_PHP[$i]) { | ||
| 203 : | counterpoi | 222 | t $fixup = '$QUERY_STRING = "option='.$origname.'&Itemid=".$Itemid.sef_'.$this->custom_short[$i].'::revert($url_array,1);'; |
| 204 : | mambo | 117 | eval($fixup); |
| 205 : | } | ||
| 206 : | else $QUERY_STRING = "option=$origname&Itemid=$Itemid".$this->default_revert($compname); | ||
| 207 : | $_REQUEST['option'] = $this->custom_code[$i]; | ||
| 208 : | counterpoi | 222 | t $foundit = true; |
| 209 : | mambo | 117 | break; |
| 210 : | } | ||
| 211 : | } | ||
| 212 : | if (!$foundit) { | ||
| 213 : | $content_sef = mamboCore::get('mosConfig_absolute_path').'/components/com_content/sef_ext.php'; | ||
| 214 : | if (file_exists($content_sef)) { | ||
| 215 : | require_once($content_sef); | ||
| 216 : | counterpoi | 222 | t $QUERY_STRING = sef_content::revert($url_array,1); |
| 217 : | mambo | 117 | if ($QUERY_STRING) $foundit = true; |
| 218 : | } | ||
| 219 : | } | ||
| 220 : | } | ||
| 221 : | if ($foundit) { | ||
| 222 : | $_SERVER['QUERY_STRING'] = $QUERY_STRING; | ||
| 223 : | $REQUEST_URI = '/index.php?'.$QUERY_STRING; | ||
| 224 : | $_SERVER['REQUEST_URI'] = $REQUEST_URI; | ||
| 225 : | return 0; | ||
| 226 : | } | ||
| 227 : | else return 1; | ||
| 228 : | } | ||
| 229 : | counterpoi | 222 | t return 0; |
| 230 : | mambo | 117 | } |
| 231 : | |||
| 232 : | function default_revert ($specialname) { | ||
| 233 : | $request = explode($specialname.'/', $_SERVER['REQUEST_URI']); | ||
| 234 : | if (isset($request[1])) $parmset = explode("/", $request[1]); | ||
| 235 : | else $parmset = array(); | ||
| 236 : | $QUERY_STRING = ''; | ||
| 237 : | $menuhandler = mosMenuHandler::getInstance(); | ||
| 238 : | foreach($parmset as $values) { | ||
| 239 : | $parts = explode(",", $values); | ||
| 240 : | if (count($parts) > 1) { | ||
| 241 : | $_REQUEST[$parts[0]] = $_GET[$parts[0]] = $parts[1]; | ||
| 242 : | if ($parts[0] == 'option') { | ||
| 243 : | $_REQUEST['Itemid'] = $_GET['Itemid'] = $Itemid = $menuhandler->getIDLikeLink("index.php?option=$parts[1]"); | ||
| 244 : | mamboCore::set('Itemid', $Itemid); | ||
| 245 : | $QUERY_STRING .= "$parts[0]=$parts[1]&Itemid=$Itemid"; | ||
| 246 : | } | ||
| 247 : | $QUERY_STRING .= "&$parts[0]=$parts[1]"; | ||
| 248 : | } | ||
| 249 : | } | ||
| 250 : | return $QUERY_STRING; | ||
| 251 : | } | ||
| 252 : | |||
| 253 : | function sefRelToAbs( $string ) { | ||
| 254 : | global $iso_client_lang; | ||
| 255 : | |||
| 256 : | csouza | 149 | $server = mamboCore::get('mosConfig_live_site'); |
| 257 : | counterpoi | 223 | t if ($string == 'index.php') return $server.'/'; |
| 258 : | mambo | 117 | |
| 259 : | if (!mamboCore::get('mosConfig_sef') OR strtolower(substr($string,0,9)) != 'index.php' OR eregi('^(([^:/?#]+):)',$string)) return $string; | ||
| 260 : | |||
| 261 : | $passed_string = str_replace('&', '&', $string); | ||
| 262 : | $string = substr($passed_string,10); | ||
| 263 : | if(mamboCore::get('mosConfig_mbf_content') AND strpos("lang=", strtolower($string)) === false) { | ||
| 264 : | $string .= "&lang=$iso_client_lang"; | ||
| 265 : | } | ||
| 266 : | $option = $task = ''; | ||
| 267 : | $oktasks = true; | ||
| 268 : | parse_str($string, $params); | ||
| 269 : | foreach ($params as $key=>$value) { | ||
| 270 : | $lowkey = strtolower($key); | ||
| 271 : | $lowvalue = strtolower($value); | ||
| 272 : | $unset = true; | ||
| 273 : | switch ($lowkey) { | ||
| 274 : | case 'option': | ||
| 275 : | $option = $lowvalue; | ||
| 276 : | break; | ||
| 277 : | case 'task': | ||
| 278 : | $task = $value; | ||
| 279 : | if ($lowvalue == 'new' OR $lowvalue == 'edit') $oktasks = false; | ||
| 280 : | break; | ||
| 281 : | default: | ||
| 282 : | $check_params[$lowkey] = $key; | ||
| 283 : | $unset = false; | ||
| 284 : | } | ||
| 285 : | if ($unset) unset($params[$key]); | ||
| 286 : | } | ||
| 287 : | // Process content items | ||
| 288 : | if (($option == 'com_content' OR $option == 'content') AND $oktasks) { | ||
| 289 : | /* | ||
| 290 : | Content | ||
| 291 : | index.php?option=com_content&task=$task§ionid=$sectionid&id=$id&Itemid=$Itemid&limit=$limit&limitstart=$limitstart | ||
| 292 : | */ | ||
| 293 : | $task = $this->sef_content_task[$task]; | ||
| 294 : | $content_sef = mamboCore::get('mosConfig_absolute_path').'/components/com_content/sef_ext.php'; | ||
| 295 : | if (file_exists($content_sef)) { | ||
| 296 : | require_once($content_sef); | ||
| 297 : | counterpoi | 222 | t return $server.'/'.$this->prefix.sef_content::create($task, $params); |
| 298 : | mambo | 117 | } |
| 299 : | $keys = array('sectionid', 'id', 'itemid', 'limit', 'limitstart', 'lang'); | ||
| 300 : | $string = "/content/$task/"; | ||
| 301 : | foreach ($keys as $key) { | ||
| 302 : | if (isset($check_params[$key])) { | ||
| 303 : | $pkey = $check_params[$key]; | ||
| 304 : | $string .= $params[$pkey].'/'; | ||
| 305 : | } | ||
| 306 : | } | ||
| 307 : | return $server.$string; | ||
| 308 : | } | ||
| 309 : | // Other types of URL than content do not use Itemid in the SEO version | ||
| 310 : | if (isset($check_params['itemid'])) { | ||
| 311 : | $pkey = $check_params['itemid']; | ||
| 312 : | unset($params[$pkey]); | ||
| 313 : | unset($check_params['itemid']); | ||
| 314 : | } | ||
| 315 : | // Process customised components | ||
| 316 : | $i = array_search($option,$this->custom_code); | ||
| 317 : | if ($i !== false AND $i !== null) { | ||
| 318 : | if ($this->custom_PHP[$i]) eval('$string = sef_'.$this->custom_short[$i].'::create($passed_string);'); | ||
| 319 : | else $string = $this->componentDetails($params,$task); | ||
| 320 : | counterpoi | 222 | t return $server.'/'.$this->prefix.'/'.$this->custom_name[$i].'/'.$string; |
| 321 : | mambo | 117 | } |
| 322 : | // Process ordinary components | ||
| 323 : | if (strpos($option,'com_')===0 AND $option != 'com_registration' AND $oktasks) { | ||
| 324 : | return "$server/component/option,$option/".$this->componentDetails($params,$task); | ||
| 325 : | } | ||
| 326 : | // Anything else is returned as received, except it is guaranteed that & will be & | ||
| 327 : | return $server.'/'.str_replace( '&', '&', $passed_string ); | ||
| 328 : | } | ||
| 329 : | |||
| 330 : | function componentDetails (&$params, $task) { | ||
| 331 : | $string = ($task ? "task,$task/" : ''); | ||
| 332 : | foreach ($params as $key=>$param) $string .= "$key,$param/"; | ||
| 333 : | return $string; | ||
| 334 : | } | ||
| 335 : | |||
| 336 : | } | ||
| 337 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

