00001 <?php
00010 class aliroSEF {
00011
00012 private $prefix = '';
00013 private $custom_code = array();
00014 private $custom_name = array();
00015 private $custom_PHP = array();
00016 private $custom_short = array();
00017 private $sef_content_task = array();
00018 private $sef_name_chars = array();
00019 public $sef_translate_chars = array();
00020 public $content_data = null;
00021 public $content_items = array();
00022 public $content_sections = array();
00023 public $content_categories = array();
00024 public $SEF_SPACE;
00025
00026 function __construct () {
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 $this->SEF_SPACE = "_";
00057
00058 $this->custom_code = array('com_frontpage','com_contact');
00059 $this->custom_name = array('Frontpage','Contact_Us');
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 $this->sef_name_chars = array('–', '?', '&', '/', ' ');
00078 $this->sef_translate_chars = array('-', '', 'and', ' or ', $this->SEF_SPACE);
00079
00080
00081
00082 if (mamboCore::is_set('mosConfig_sef_prefix')) $this->prefix = mamboCore::get('mosConfig_sef_prefix');
00083 else $this->prefix = 'mos';
00084 if ($this->prefix == 'content' OR $this->prefix == 'component') $this->prefix = 'mos';
00085 foreach ($this->custom_code as $code) {
00086 $codefile = "components/$code/sef_ext.php";
00087 if (file_exists($codefile)) {
00088 include ($codefile);
00089 $this->custom_PHP[] = true;
00090 }
00091 else $this->custom_PHP[] = false;
00092 $split = explode('_',$code);
00093 $this->custom_short[] = $split[1];
00094 }
00095
00096 $this->sef_content_task['findkey'] = 'findkey';
00097 $this->sef_content_task['view'] = 'view';
00098 $this->sef_content_task['section'] = 'section';
00099 $this->sef_content_task['category'] = 'category';
00100 $this->sef_content_task['blogsection'] = 'blogsection';
00101 $this->sef_content_task['blogcategorymulti'] = 'blogcategorymulti';
00102 $this->sef_content_task['blogcategory'] = 'blogcategory';
00103 $this->sef_content_task['archivesection'] = 'archivesection';
00104 $this->sef_content_task['archivecategory'] = 'archivecategory';
00105 $this->sef_content_task['save'] = 'save';
00106 $this->sef_content_task['cancel'] = 'cancel';
00107 $this->sef_content_task['emailform'] = 'emailform';
00108 $this->sef_content_task['emailsend'] = 'emailsend';
00109 $this->sef_content_task['vote'] = 'vote';
00110 $this->sef_content_task['showblogsection'] = 'showblogsection';
00111
00112 }
00113
00114 static function getInstance () {
00115 static $instance;
00116 if (!is_object($instance)) {
00117 $handler = aliroExtensionHandler::getInstance();
00118 $sefplugin = $handler->getExtensionByName('com_sef');
00119 if ($sefplugin AND $sefplugin->class) eval ('$instance = '.$sefplugin->class.'::getInstance();');
00120 else $instance = new aliroSEF();
00121 }
00122 return $instance;
00123 }
00124
00125 function sefRetrieval($register_globals){
00126
00127 if (preg_match('/(\b)GLOBALS|_REQUEST|_SERVER|_ENV|_COOKIE|_GET|_POST|_FILES|_SESSION(\b)/i', $_SERVER['REQUEST_URI']) > 0) {
00128 die('Invalid Request');
00129 }
00130 if (mamboCore::get('mosConfig_sef')) {
00131 $subdir = mamboCore::get('subdirectory');
00132 $uri = substr($_SERVER['REQUEST_URI'], strlen($subdir));
00133 $url_array = explode('/', $uri);
00139 if ('' == $url_array[1]) return 0;
00140 $foundit = false;
00141 if ($url_array[1] == 'content') {
00142 $foundit = true;
00143 $_REQUEST['option'] = $_GET['option'] = $option = 'com_content';
00144
00145
00146 $lang = "";
00147 $parms = array();
00148 foreach($url_array as $key=>$value) {
00149 if ( strcasecmp(substr($value,0,5),'lang,') == 0 ) {
00150 $parts = explode(",", $value);
00151 if (count($parts) > 1) {
00152 $lang = $_REQUEST['lang'] = $_GET['lang'] = $parts[1];
00153 }
00154 }
00155 elseif ( $value != '' AND $key > 1 ) $parms[] = $value;
00156 }
00157
00158
00159 $task = array_search($parms[0], $this->sef_content_task);
00160 if ($task === false OR $task === null) return 1;
00161 $_REQUEST['task'] = $_GET['task'] = $task;
00162 $QUERY_STRING = "option=com_content&task=$task";
00163 $num = count($parms);
00164 for ($i = 1; $i <= $num-1; $i++) {
00165 if (strcmp($parms[$i], (int)$parms[$i]) !== 0) return 1;
00166 }
00167 $i = 1;
00168 if ($num == 6 OR $num == 4) {
00169 $_REQUEST['sectionid'] = $_GET['sectionid'] = $sectionid = $parms[$i];
00170 $QUERY_STRING .= "§ionid=$sectionid";
00171 $i++;
00172 }
00173 if ($num > 1) {
00174 $_REQUEST['id'] = $_GET['id'] = $id = $parms[$i];
00175 $QUERY_STRING .= "&id=$id";
00176 }
00177 if ($num > 2) {
00178 $_REQUEST['Itemid'] = $_GET['Itemid'] = $Itemid = $parms[$i+1];
00179 mamboCore::set('Itemid',$Itemid);
00180 $QUERY_STRING .= "&Itemid=$Itemid";
00181 }
00182 if ($num > 4) {
00183 $_REQUEST['limit'] = $_GET['limit'] = $limit = $parms[$i+2];
00184 $_REQUEST['limitstart'] = $_GET['limitstart'] = $limitstart = $parms[$i+3];
00185 $QUERY_STRING .= "&limit=$limit&limitstart=$limitstart";
00186 }
00187
00188 if ($lang!="") {
00189 $QUERY_STRING .= "&lang=$lang";
00190 }
00191 }
00192
00193
00194
00195
00196
00197 elseif ($url_array[1] == 'component') {
00198 $QUERY_STRING = $this->default_revert('component');
00199 if ($QUERY_STRING) $foundit = true;
00200 }
00201 elseif ($url_array[1] == $this->prefix) {
00202 $menuhandler = aliroMenuHandler::getInstance();
00203 foreach ($this->custom_name as $i=>$compname) {
00204 if ($url_array[2] == $compname) {
00205 $origname = $this->custom_code[$i];
00206 $_REQUEST['Itemid'] = $_GET['Itemid'] = $Itemid = $menuhandler->getIDLikeQuery("option=$origname");
00207 mamboCore::set('Itemid', $Itemid);
00208 if ($this->custom_PHP[$i]) {
00209 $fixup = '$QUERY_STRING = "option='.$origname.'&Itemid=".$Itemid.sef_'.$this->custom_short[$i].'::revert($url_array,1);';
00210 eval($fixup);
00211 }
00212 else $QUERY_STRING = "option=$origname&Itemid=$Itemid".$this->default_revert($compname);
00213 $_REQUEST['option'] = $this->custom_code[$i];
00214 $foundit = true;
00215 break;
00216 }
00217 }
00218 if (!$foundit) {
00219 $content_sef = mamboCore::get('mosConfig_absolute_path').'/components/com_content/sef_ext.php';
00220 if (file_exists($content_sef)) {
00221 require_once($content_sef);
00222 $QUERY_STRING = sef_content::revert($url_array,1);
00223 if ($QUERY_STRING) $foundit = true;
00224 }
00225 }
00226 }
00227 if ($foundit) {
00228 $_SERVER['QUERY_STRING'] = $QUERY_STRING;
00229 $REQUEST_URI = '/index.php?'.$QUERY_STRING;
00230 $_SERVER['REQUEST_URI'] = $REQUEST_URI;
00231 return 0;
00232 }
00233 else return 1;
00234 }
00235 return 0;
00236 }
00237
00238 function default_revert ($specialname) {
00239 $request = explode($specialname.'/', $_SERVER['REQUEST_URI']);
00240 if (isset($request[1])) $parmset = explode("/", $request[1]);
00241 else $parmset = array();
00242 $QUERY_STRING = '';
00243 $menuhandler = aliroMenuHandler::getInstance();
00244 foreach($parmset as $values) {
00245 $parts = explode(",", $values);
00246 if (count($parts) > 1) {
00247 $_REQUEST[$parts[0]] = $_GET[$parts[0]] = $parts[1];
00248 if ($parts[0] == 'option') {
00249 $_REQUEST['Itemid'] = $_GET['Itemid'] = $Itemid = $menuhandler->getIDLikeQuery("option=$parts[1]");
00250 mamboCore::set('Itemid', $Itemid);
00251 $QUERY_STRING .= "$parts[0]=$parts[1]&Itemid=$Itemid";
00252 }
00253 $QUERY_STRING .= "&$parts[0]=$parts[1]";
00254 }
00255 }
00256 return $QUERY_STRING;
00257 }
00258
00259 function sefRelToAbs( $string ) {
00260 global $iso_client_lang;
00261
00262 $server = mamboCore::get('mosConfig_live_site');
00263 if ($string == 'index.php') return $server.'/';
00264
00265 $passed_string = str_replace('&', '&', $string);
00266 if (!mamboCore::get('mosConfig_sef') OR strtolower(substr($passed_string,0,9)) != 'index.php' OR eregi('^(([^:/?#]+):)',$passed_string)) {
00267 return preg_replace('/(&)([^#]|$)/','&$2', $passed_string);
00268 }
00269
00270 $string = substr($passed_string,10);
00271 if(mamboCore::get('mosConfig_mbf_content') AND strpos("lang=", strtolower($string)) === false) {
00272 $string .= "&lang=$iso_client_lang";
00273 }
00274 $option = $task = '';
00275 $oktasks = true;
00276 parse_str($string, $params);
00277 foreach ($params as $key=>$value) {
00278 $lowkey = strtolower($key);
00279 $lowvalue = strtolower($value);
00280 $unset = true;
00281 switch ($lowkey) {
00282 case 'option':
00283 $option = $lowvalue;
00284 break;
00285 case 'task':
00286 $task = $value;
00287 if ($lowvalue == 'new' OR $lowvalue == 'edit') $oktasks = false;
00288 break;
00289 default:
00290 $check_params[$lowkey] = $key;
00291 $unset = false;
00292 }
00293 if ($unset) unset($params[$key]);
00294 }
00295
00296 if (($option == 'com_content' OR $option == 'content') AND $oktasks) {
00297
00298
00299
00300
00301 if ($task) $task = $this->sef_content_task[$task];
00302 $content_sef = mamboCore::get('mosConfig_absolute_path').'/components/com_content/sef_ext.php';
00303 if (file_exists($content_sef)) {
00304 require_once($content_sef);
00305 return $server.'/'.$this->prefix.sef_content::create($task, $params);
00306 }
00307 $keys = array('sectionid', 'id', 'itemid', 'limit', 'limitstart', 'lang');
00308 $string = "/content/$task/";
00309 foreach ($keys as $key) {
00310 if (isset($check_params[$key])) {
00311 $pkey = $check_params[$key];
00312 $string .= $params[$pkey].'/';
00313 }
00314 }
00315 return $server.$string;
00316 }
00317
00318 if (isset($check_params['itemid'])) {
00319 $pkey = $check_params['itemid'];
00320 unset($params[$pkey]);
00321 unset($check_params['itemid']);
00322 }
00323
00324 $i = array_search($option,$this->custom_code);
00325 if ($i !== false AND $i !== null) {
00326 if ($this->custom_PHP[$i]) eval('$string = sef_'.$this->custom_short[$i].'::create($passed_string);');
00327 else $string = $this->componentDetails($params,$task);
00328 return $server.'/'.$this->prefix.'/'.$this->custom_name[$i].'/'.$string;
00329 }
00330
00331 if (strpos($option,'com_')===0 AND $option != 'com_registration' AND $oktasks) {
00332 return "$server/component/option,$option/".$this->componentDetails($params,$task);
00333 }
00334
00335 return $server.'/'.str_replace( '&', '&', $passed_string );
00336 }
00337
00338 function componentDetails (&$params, $task) {
00339 $string = ($task ? "task,$task/" : '');
00340 foreach ($params as $key=>$param) $string .= "$key,$param/";
00341 return $string;
00342 }
00343
00344 }
00345
00346 ?>