Annotation of /mambo/branches/4.6/includes/sef.php
Parent Directory
|
Revision Log
Revision 149 - (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 : | var $custom_code = array(); | ||
| 13 : | var $custom_name = array(); | ||
| 14 : | var $custom_PHP = array(); | ||
| 15 : | var $custom_short = array(); | ||
| 16 : | var $sef_content_task = array(); | ||
| 17 : | var $sef_name_chars = array(); | ||
| 18 : | var $sef_translate_chars = array(); | ||
| 19 : | var $content_data = null; | ||
| 20 : | var $content_items = array(); | ||
| 21 : | var $content_sections = array(); | ||
| 22 : | var $content_categories = array(); | ||
| 23 : | var $SEF_SPACE; | ||
| 24 : | |||
| 25 : | function mosSEF () { | ||
| 26 : | /******************************************************************************* | ||
| 27 : | ** The following are parameters for the ReMOSef Search Engine | ||
| 28 : | ** Optimisation component. $this->SEF_SPACE should be set to the | ||
| 29 : | ** character that is to replace blanks in names that form the URL. | ||
| 30 : | ** You can vary this, although the only sensible choices seem to be | ||
| 31 : | ** underscore or hyphen (_ or -). | ||
| 32 : | ** | ||
| 33 : | ** The arrays $this->custom_code and $this->custom_name must be kept exactly | ||
| 34 : | ** in step with each other. $this->custom_code is a list of the components | ||
| 35 : | ** that are to be handled by ReMOSef. | ||
| 36 : | ** | ||
| 37 : | ** The array $this->custom_name is the alternative name that will be used | ||
| 38 : | ** in the optimised URL to identify the component and can be whatever | ||
| 39 : | ** you please so long as it is unique and legal for a URL. Apart from | ||
| 40 : | ** using the custom name for the component, ReMOSef will do no further | ||
| 41 : | ** translation of the URL than is done by the standard Mambo SEF - UNLESS | ||
| 42 : | ** there is a sef_ext.php file installed for that component. The | ||
| 43 : | ** exception to this is ReMOSitory - the optimisation code for Remository | ||
| 44 : | ** is integrated in ReMOSef. For other components, if a sef_ext.php is | ||
| 45 : | ** present, it will be invoked by ReMOSef. | ||
| 46 : | ** | ||
| 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 : | $this->custom_code = array('com_remository','com_simpleboard','com_frontpage','com_contact','com_mrecommend','com_graphitory'); | ||
| 59 : | $this->custom_name = array('Remository','Forum','Frontpage','Contact_Us','Recommend_Us','Graphitory'); | ||
| 60 : | /******************************************************************************* | ||
| 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 : | foreach ($this->custom_code as $code) { | ||
| 83 : | $codefile = "components/$code/sef_ext.php"; | ||
| 84 : | if (file_exists($codefile)) { | ||
| 85 : | include ($codefile); | ||
| 86 : | $this->custom_PHP[] = true; | ||
| 87 : | } | ||
| 88 : | else $this->custom_PHP[] = false; | ||
| 89 : | $split = explode('_',$code); | ||
| 90 : | $this->custom_short[] = $split[1]; | ||
| 91 : | } | ||
| 92 : | |||
| 93 : | $this->sef_content_task['findkey'] = 'findkey'; | ||
| 94 : | $this->sef_content_task['view'] = 'view'; | ||
| 95 : | $this->sef_content_task['section'] = 'section'; | ||
| 96 : | $this->sef_content_task['category'] = 'category'; | ||
| 97 : | $this->sef_content_task['blogsection'] = 'blogsection'; | ||
| 98 : | $this->sef_content_task['blogcategorymulti'] = 'blogcategorymulti'; | ||
| 99 : | $this->sef_content_task['blogcategory'] = 'blogcategory'; | ||
| 100 : | $this->sef_content_task['archivesection'] = 'archivesection'; | ||
| 101 : | $this->sef_content_task['archivecategory'] = 'archivecategory'; | ||
| 102 : | $this->sef_content_task['save'] = 'save'; | ||
| 103 : | $this->sef_content_task['cancel'] = 'cancel'; | ||
| 104 : | $this->sef_content_task['emailform'] = 'emailform'; | ||
| 105 : | $this->sef_content_task['emailsend'] = 'emailsend'; | ||
| 106 : | $this->sef_content_task['vote'] = 'vote'; | ||
| 107 : | $this->sef_content_task['showblogsection'] = 'showblogsection'; | ||
| 108 : | |||
| 109 : | } | ||
| 110 : | |||
| 111 : | function &getInstance () { | ||
| 112 : | static $instance; | ||
| 113 : | if (!is_object($instance)) $instance = new mosSEF(); | ||
| 114 : | return $instance; | ||
| 115 : | } | ||
| 116 : | |||
| 117 : | function sefRetrieval($register_globals){ | ||
| 118 : | |||
| 119 : | if (preg_match('/(\b)GLOBALS|_REQUEST|_SERVER|_ENV|_COOKIE|_GET|_POST|_FILES|_SESSION(\b)/i', $_SERVER['REQUEST_URI']) > 0) { | ||
| 120 : | die('Invalid Request'); | ||
| 121 : | } | ||
| 122 : | if (mamboCore::get('mosConfig_sef')) { | ||
| 123 : | $url_array = explode('/', $_SERVER['REQUEST_URI']); | ||
| 124 : | /** | ||
| 125 : | * Content | ||
| 126 : | * /$option/$task/$sectionid/$id/$Itemid/$limit/$limitstart | ||
| 127 : | */ | ||
| 128 : | |||
| 129 : | $foundit = false; | ||
| 130 : | if ($url_array[1] == 'content') { | ||
| 131 : | $foundit = true; | ||
| 132 : | $_REQUEST['option'] = $_GET['option'] = $option = 'com_content'; | ||
| 133 : | |||
| 134 : | // language hook for content | ||
| 135 : | $lang = ""; | ||
| 136 : | $parms = array(); | ||
| 137 : | foreach($url_array as $key=>$value) { | ||
| 138 : | if ( strcasecmp(substr($value,0,5),'lang,') == 0 ) { | ||
| 139 : | $parts = explode(",", $value); | ||
| 140 : | if (count($parts) > 1) { | ||
| 141 : | $lang = $_REQUEST['lang'] = $_GET['lang'] = $parts[1]; | ||
| 142 : | } | ||
| 143 : | } | ||
| 144 : | elseif ( $value != '' AND $key > 1 ) $parms[] = $value; | ||
| 145 : | } | ||
| 146 : | |||
| 147 : | // $option/$task/$sectionid/$id/$Itemid/$limit/$limitstart | ||
| 148 : | $task = array_search($parms[0], $this->sef_content_task); | ||
| 149 : | if ($task === false OR $task === null) return 1; | ||
| 150 : | $_REQUEST['task'] = $_GET['task'] = $task; | ||
| 151 : | $QUERY_STRING = "option=com_content&task=$task"; | ||
| 152 : | $num = count($parms); | ||
| 153 : | for ($i = 1; $i <= $num-1; $i++) { | ||
| 154 : | if (strcmp($parms[$i], (int)$parms[$i]) !== 0) return 1; | ||
| 155 : | } | ||
| 156 : | $i = 1; | ||
| 157 : | if ($num == 6 OR $num == 4) { | ||
| 158 : | $_REQUEST['sectionid'] = $_GET['sectionid'] = $sectionid = $parms[$i]; | ||
| 159 : | $QUERY_STRING .= "§ionid=$sectionid"; | ||
| 160 : | $i++; | ||
| 161 : | } | ||
| 162 : | if ($num > 1) { | ||
| 163 : | $_REQUEST['id'] = $_GET['id'] = $id = $parms[$i]; | ||
| 164 : | $QUERY_STRING .= "&id=$id"; | ||
| 165 : | } | ||
| 166 : | if ($num > 2) { | ||
| 167 : | $_REQUEST['Itemid'] = $_GET['Itemid'] = $Itemid = $parms[$i+1]; | ||
| 168 : | mamboCore::set('Itemid',$Itemid); | ||
| 169 : | $QUERY_STRING .= "&Itemid=$Itemid"; | ||
| 170 : | } | ||
| 171 : | if ($num > 4) { | ||
| 172 : | $_REQUEST['limit'] = $_GET['limit'] = $limit = $parms[$i+2]; | ||
| 173 : | $_REQUEST['limitstart'] = $_GET['limitstart'] = $limitstart = $parms[$i+3]; | ||
| 174 : | $QUERY_STRING .= "&limit=$limit&limitstart=$limitstart"; | ||
| 175 : | } | ||
| 176 : | |||
| 177 : | if ($lang!="") { | ||
| 178 : | $QUERY_STRING .= "&lang=$lang"; | ||
| 179 : | } | ||
| 180 : | } | ||
| 181 : | |||
| 182 : | /* | ||
| 183 : | Components | ||
| 184 : | http://www.domain.com/component/$name,$value | ||
| 185 : | */ | ||
| 186 : | elseif ($url_array[1] == 'component') { | ||
| 187 : | $foundit = true; | ||
| 188 : | $QUERY_STRING = $this->default_revert('component'); | ||
| 189 : | } | ||
| 190 : | else { | ||
| 191 : | $menuhandler = mosMenuHandler::getInstance(); | ||
| 192 : | foreach ($this->custom_name as $i=>$compname) { | ||
| 193 : | if ($url_array[1] == $compname) { | ||
| 194 : | $foundit = true; | ||
| 195 : | $origname = $this->custom_code[$i]; | ||
| 196 : | $_REQUEST['Itemid'] = $_GET['Itemid'] = $Itemid = $menuhandler->getIDLikeLink("index.php?option=$origname"); | ||
| 197 : | mamboCore::set('Itemid', $Itemid); | ||
| 198 : | if ($this->custom_PHP[$i]) { | ||
| 199 : | $fixup = '$QUERY_STRING = "option='.$origname.'&Itemid=".$Itemid.sef_'.$this->custom_short[$i].'::revert($url_array,0);'; | ||
| 200 : | eval($fixup); | ||
| 201 : | } | ||
| 202 : | else $QUERY_STRING = "option=$origname&Itemid=$Itemid".$this->default_revert($compname); | ||
| 203 : | $_REQUEST['option'] = $this->custom_code[$i]; | ||
| 204 : | break; | ||
| 205 : | } | ||
| 206 : | } | ||
| 207 : | if (!$foundit) { | ||
| 208 : | $content_sef = mamboCore::get('mosConfig_absolute_path').'/components/com_content/sef_ext.php'; | ||
| 209 : | if (file_exists($content_sef)) { | ||
| 210 : | require_once($content_sef); | ||
| 211 : | $QUERY_STRING = sef_content::revert($url_array,0); | ||
| 212 : | if ($QUERY_STRING) $foundit = true; | ||
| 213 : | } | ||
| 214 : | } | ||
| 215 : | } | ||
| 216 : | |||
| 217 : | if ($foundit) { | ||
| 218 : | $_SERVER['QUERY_STRING'] = $QUERY_STRING; | ||
| 219 : | $REQUEST_URI = '/index.php?'.$QUERY_STRING; | ||
| 220 : | $_SERVER['REQUEST_URI'] = $REQUEST_URI; | ||
| 221 : | return 0; | ||
| 222 : | } | ||
| 223 : | else return 1; | ||
| 224 : | } | ||
| 225 : | } | ||
| 226 : | |||
| 227 : | function default_revert ($specialname) { | ||
| 228 : | $request = explode($specialname.'/', $_SERVER['REQUEST_URI']); | ||
| 229 : | if (isset($request[1])) $parmset = explode("/", $request[1]); | ||
| 230 : | else $parmset = array(); | ||
| 231 : | $QUERY_STRING = ''; | ||
| 232 : | $menuhandler = mosMenuHandler::getInstance(); | ||
| 233 : | foreach($parmset as $values) { | ||
| 234 : | $parts = explode(",", $values); | ||
| 235 : | if (count($parts) > 1) { | ||
| 236 : | $_REQUEST[$parts[0]] = $_GET[$parts[0]] = $parts[1]; | ||
| 237 : | if ($parts[0] == 'option') { | ||
| 238 : | $_REQUEST['Itemid'] = $_GET['Itemid'] = $Itemid = $menuhandler->getIDLikeLink("index.php?option=$parts[1]"); | ||
| 239 : | mamboCore::set('Itemid', $Itemid); | ||
| 240 : | $QUERY_STRING .= "$parts[0]=$parts[1]&Itemid=$Itemid"; | ||
| 241 : | } | ||
| 242 : | $QUERY_STRING .= "&$parts[0]=$parts[1]"; | ||
| 243 : | } | ||
| 244 : | } | ||
| 245 : | return $QUERY_STRING; | ||
| 246 : | } | ||
| 247 : | |||
| 248 : | function sefRelToAbs( $string ) { | ||
| 249 : | global $iso_client_lang; | ||
| 250 : | |||
| 251 : | csouza | 149 | // $server = 'http://'.$_SERVER['HTTP_HOST']; |
| 252 : | $server = mamboCore::get('mosConfig_live_site'); | ||
| 253 : | if ($string == 'index.php') return $server.'/index.php'; | ||
| 254 : | mambo | 117 | |
| 255 : | if (!mamboCore::get('mosConfig_sef') OR strtolower(substr($string,0,9)) != 'index.php' OR eregi('^(([^:/?#]+):)',$string)) return $string; | ||
| 256 : | |||
| 257 : | $passed_string = str_replace('&', '&', $string); | ||
| 258 : | $string = substr($passed_string,10); | ||
| 259 : | if(mamboCore::get('mosConfig_mbf_content') AND strpos("lang=", strtolower($string)) === false) { | ||
| 260 : | $string .= "&lang=$iso_client_lang"; | ||
| 261 : | } | ||
| 262 : | $option = $task = ''; | ||
| 263 : | $oktasks = true; | ||
| 264 : | parse_str($string, $params); | ||
| 265 : | foreach ($params as $key=>$value) { | ||
| 266 : | $lowkey = strtolower($key); | ||
| 267 : | $lowvalue = strtolower($value); | ||
| 268 : | $unset = true; | ||
| 269 : | switch ($lowkey) { | ||
| 270 : | case 'option': | ||
| 271 : | $option = $lowvalue; | ||
| 272 : | break; | ||
| 273 : | case 'task': | ||
| 274 : | $task = $value; | ||
| 275 : | if ($lowvalue == 'new' OR $lowvalue == 'edit') $oktasks = false; | ||
| 276 : | break; | ||
| 277 : | default: | ||
| 278 : | $check_params[$lowkey] = $key; | ||
| 279 : | $unset = false; | ||
| 280 : | } | ||
| 281 : | if ($unset) unset($params[$key]); | ||
| 282 : | } | ||
| 283 : | // Process content items | ||
| 284 : | if (($option == 'com_content' OR $option == 'content') AND $oktasks) { | ||
| 285 : | /* | ||
| 286 : | Content | ||
| 287 : | index.php?option=com_content&task=$task§ionid=$sectionid&id=$id&Itemid=$Itemid&limit=$limit&limitstart=$limitstart | ||
| 288 : | */ | ||
| 289 : | $task = $this->sef_content_task[$task]; | ||
| 290 : | $content_sef = mamboCore::get('mosConfig_absolute_path').'/components/com_content/sef_ext.php'; | ||
| 291 : | if (file_exists($content_sef)) { | ||
| 292 : | require_once($content_sef); | ||
| 293 : | return $server.sef_content::create($task, $params); | ||
| 294 : | } | ||
| 295 : | $keys = array('sectionid', 'id', 'itemid', 'limit', 'limitstart', 'lang'); | ||
| 296 : | $string = "/content/$task/"; | ||
| 297 : | foreach ($keys as $key) { | ||
| 298 : | if (isset($check_params[$key])) { | ||
| 299 : | $pkey = $check_params[$key]; | ||
| 300 : | $string .= $params[$pkey].'/'; | ||
| 301 : | } | ||
| 302 : | } | ||
| 303 : | return $server.$string; | ||
| 304 : | } | ||
| 305 : | // Other types of URL than content do not use Itemid in the SEO version | ||
| 306 : | if (isset($check_params['itemid'])) { | ||
| 307 : | $pkey = $check_params['itemid']; | ||
| 308 : | unset($params[$pkey]); | ||
| 309 : | unset($check_params['itemid']); | ||
| 310 : | } | ||
| 311 : | // Process customised components | ||
| 312 : | $i = array_search($option,$this->custom_code); | ||
| 313 : | if ($i !== false AND $i !== null) { | ||
| 314 : | if ($this->custom_PHP[$i]) eval('$string = sef_'.$this->custom_short[$i].'::create($passed_string);'); | ||
| 315 : | else $string = $this->componentDetails($params,$task); | ||
| 316 : | return $server.'/'.$this->custom_name[$i].'/'.$string; | ||
| 317 : | } | ||
| 318 : | // Process ordinary components | ||
| 319 : | if (strpos($option,'com_')===0 AND $option != 'com_registration' AND $oktasks) { | ||
| 320 : | return "$server/component/option,$option/".$this->componentDetails($params,$task); | ||
| 321 : | } | ||
| 322 : | // Anything else is returned as received, except it is guaranteed that & will be & | ||
| 323 : | return $server.'/'.str_replace( '&', '&', $passed_string ); | ||
| 324 : | } | ||
| 325 : | |||
| 326 : | function componentDetails (&$params, $task) { | ||
| 327 : | $string = ($task ? "task,$task/" : ''); | ||
| 328 : | foreach ($params as $key=>$param) $string .= "$key,$param/"; | ||
| 329 : | return $string; | ||
| 330 : | } | ||
| 331 : | |||
| 332 : | } | ||
| 333 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

