/** * Reverts to the query string out of the SEF Advance URL * Input: * $url_array, array, The SEF Advance URL split in arrays * $pos, int, The position offset for virtual directories (first virtual directory, which is the component name, begins at $pos+1) * Output: $QUERY_STRING, string, query string (var1=$var1&var2=$var2) * Note that this will be added to already defined first part (option=com_example&Itemid=$Itemid) **/ function revert($url_array, $pos) { if (ini_get('register_globals') == 1 && (!defined('RG_EMULATION') || RG_EMULATION == 1) || ini_get('register_globals') == 0 && (defined('RG_EMULATION') && RG_EMULATION == 1)) { // if register globals on, emulation on OR register globals off, emulation on // then define all variables you pass as globals global $var1, $var2; } // Examine the SEF Advance URL and extract the variables building the query string $QUERY_STRING = ''; if (isset($url_array[$pos + 2]) && $url_array[$pos + 2] != '') { // .../example/$var1/ $var1 = sefdecode($url_array[$pos + 2]); $_GET['var1'] = $_REQUEST['var1'] = $var1; $QUERY_STRING .= "&var1={$var1}"; } if (isset($url_array[$pos + 3]) && $url_array[$pos + 3] != '') { // .../example/$var1/$var2/ $var2 = sefdecode($url_array[$pos + 3]); $_GET['var2'] = $_REQUEST['var2'] = $var2; $QUERY_STRING .= "&var2={$var2}"; } // $QUERY_STRING == "var1=$var1&var2=$var2"; return $QUERY_STRING; }
/** * Reverts to the query string out of the SEF Advance URL * Input: * $url_array, array, The SEF Advance URL split in arrays * $pos, int, The position offset for virtual directories (first virtual directory, which is the component name, begins at $pos+1) * Output: $QUERY_STRING, string, query string (var1=$var1&var2=$var2) * Note that this will be added to already defined first part (option=com_example&Itemid=$Itemid) **/ function revert($url_array, $pos) { require_once JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'helper.php'; $config = EasyBlogHelper::getConfig(); $seftype = $config->get('main_sef', 'default'); global $database; if (empty($database)) { // Joomla! 1.5 native $database = EasyBlogHelper::db(); } $QUERY_STRING = ''; $view = ''; $totalSegment = count(array_filter($url_array)) - $pos; // If user chooses to use the simple sef setup, we need to add the proper view if ($config->get('main_sef') == 'simple' && $totalSegment == 2) { $views = JFolder::folders(JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'views'); if (!in_array($url_array[$pos + 2], $views)) { array_splice($url_array, $pos + 2, 0, 'entry'); } } // We need to remove limitstart from the result foreach ($url_array as $index => $field) { if (preg_match('/limitstart-/i', $field)) { $temp = explode('limitstart-', $field); $temp = explode('&', $temp[1]); $limitstart = $temp[0]; $_GET['limitstart'] = $_REQUEST['limitstart'] = $limitstart; $QUERY_STRING .= '&limitstart=' . $limitstart; unset($url_array[$index]); } } if (isset($url_array[$pos + 2]) && $url_array[$pos + 2] != '') { // .../mydir/$category/ $view = sefdecode($url_array[$pos + 2]); $_GET['view'] = $_REQUEST['view'] = $view; $QUERY_STRING .= "&view={$view}"; if (!empty($view) && file_exists(JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'router.php')) { require_once JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'helper.php'; require_once JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'router.php'; $Itemid = EasyBlogRouter::getItemId($view); } else { $Itemid = ''; } } switch ($view) { case 'entry': if ($seftype == 'date') { $sector = 6; } elseif ($seftype == 'category') { $sector = 4; } elseif ($seftype == 'datecategory') { $sector = 7; } else { $sector = 3; } if (!empty($url_array[$pos + $sector])) { $entryId = ''; if ($config->get('main_sef_unicode')) { // perform manual split on the string. $permalinkSegment = $url_array[$pos + $sector]; $permalinkArr = explode(':', $permalinkSegment); $id = $permalinkArr[0]; } else { $id = $this->revertPermalink($url_array[$pos + $sector], 'blog'); } $_GET['id'] = $_REQUEST['id'] = $id; $QUERY_STRING .= "&id=" . $id; } break; case 'blogger': if (!empty($url_array[$pos + 4]) && $url_array[$pos + 4] == 'statistic') { $_GET['layout'] = $_REQUEST['layout'] = 'statistic'; $QUERY_STRING .= "&layout=statistic"; if (!empty($url_array[$pos + 3])) { if ($config->get('main_sef_unicode')) { // perform manual split on the string. $permalinkSegment = $url_array[$pos + 3]; $permalinkArr = explode(':', $permalinkSegment); $id = $permalinkArr[0]; } else { $id = $this->revertPermalink($url_array[$pos + 3], 'blogger'); } $_GET['id'] = $_REQUEST['id'] = $id; $QUERY_STRING .= "&id=" . $id; } if (!empty($url_array[$pos + 5])) { $stat = sefdecode($url_array[$pos + 5]); $_GET['stat'] = $_REQUEST['stat'] = $stat; $QUERY_STRING .= "&stat=" . $stat; } if (!empty($url_array[$pos + 6]) && !empty($stat)) { switch ($stat) { case 'category': if ($config->get('main_sef_unicode')) { // perform manual split on the string. $permalinkSegment = $url_array[$pos + 6]; $permalinkArr = explode(':', $permalinkSegment); $catid = $permalinkArr[0]; } else { $catid = $this->revertPermalink($url_array[$pos + 6], 'category'); } $_GET['catid'] = $_REQUEST['catid'] = $catid; $QUERY_STRING .= "&catid=" . $catid; break; case 'tag': if ($config->get('main_sef_unicode')) { // perform manual split on the string. $permalinkSegment = $url_array[$pos + 6]; $permalinkArr = explode(':', $permalinkSegment); $tagid = $permalinkArr[0]; } else { $tagid = $this->revertPermalink($url_array[$pos + 6], 'tag'); } $_GET['tagid'] = $_REQUEST['tagid'] = $tagid; $QUERY_STRING .= "&tagid=" . $tagid; break; default: // Do nothing . } } } else { if (!empty($url_array[$pos + 3])) { if ($url_array[$pos + 3] == 'listings') { $_GET['layout'] = $_REQUEST['layout'] = 'listings'; $QUERY_STRING .= "&layout=listings"; if (!empty($url_array[$pos + 4])) { if ($config->get('main_sef_unicode')) { // perform manual split on the string. $permalinkSegment = $url_array[$pos + 4]; $permalinkArr = explode(':', $permalinkSegment); $id = $permalinkArr[0]; } else { $id = $this->revertPermalink($url_array[$pos + 4], 'blogger'); } $_GET['id'] = $_REQUEST['id'] = $id; $QUERY_STRING .= "&id=" . $id; } } else { if (!empty($url_array[$pos + 4])) { if ($url_array[$pos + 4] == 'feed') { if ($config->get('main_sef_unicode')) { // perform manual split on the string. $permalinkSegment = $url_array[$pos + 3]; $permalinkArr = explode(':', $permalinkSegment); $id = $permalinkArr[0]; } else { $id = $this->revertPermalink($url_array[$pos + 3], 'blogger'); } $_GET['id'] = $_REQUEST['id'] = $id; $QUERY_STRING .= "&id=" . $id; $format = $url_array[$pos + 4]; $_GET['format'] = $_REQUEST['format'] = $format; $QUERY_STRING .= "&format=" . $format; $type = $url_array[$pos + 5]; $_GET['type'] = $_REQUEST['type'] = $type; $QUERY_STRING .= "&type=" . $type; } } } } } break; case 'categories': if (!empty($url_array[$pos + 3])) { if ($url_array[$pos + 3] == 'listings') { $_GET['layout'] = $_REQUEST['layout'] = 'listings'; $QUERY_STRING .= "&layout=listings"; if (!empty($url_array[$pos + 4])) { if ($config->get('main_sef_unicode')) { // perform manual split on the string. $permalinkSegment = $url_array[$pos + 4]; $permalinkArr = explode(':', $permalinkSegment); $id = $permalinkArr[0]; } else { $id = $this->revertPermalink($url_array[$pos + 4], 'category'); } $_GET['id'] = $_REQUEST['id'] = $id; $QUERY_STRING .= "&id=" . $id; } } else { if ($url_array[$pos + 4] == 'feed') { if ($config->get('main_sef_unicode')) { // perform manual split on the string. $permalinkSegment = $url_array[$pos + 3]; $permalinkArr = explode(':', $permalinkSegment); $id = $permalinkArr[0]; } else { $id = $this->revertPermalink($url_array[$pos + 3], 'category'); } $_GET['id'] = $_REQUEST['id'] = $id; $QUERY_STRING .= "&id=" . $id; $format = $url_array[$pos + 4]; $_GET['format'] = $_REQUEST['format'] = $format; $QUERY_STRING .= "&format=" . $format; $type = $url_array[$pos + 5]; $_GET['type'] = $_REQUEST['type'] = $type; $QUERY_STRING .= "&type=" . $type; } } } break; case 'tags': if (!empty($url_array[$pos + 3])) { if ($url_array[$pos + 3] == 'tag') { $_GET['layout'] = $_REQUEST['layout'] = 'tag'; $QUERY_STRING .= "&layout=tag"; } if (!empty($url_array[$pos + 4])) { if ($config->get('main_sef_unicode')) { // perform manual split on the string. $permalinkSegment = $url_array[$pos + 4]; $permalinkArr = explode(':', $permalinkSegment); $id = $permalinkArr[0]; } else { $id = $this->revertPermalink($url_array[$pos + 4], 'tag'); } $_GET['id'] = $_REQUEST['id'] = $id; $QUERY_STRING .= "&id=" . $id; } } break; case 'teamblog': if (!empty($url_array[$pos + 4]) && $url_array[$pos + 4] == 'statistic') { $_GET['layout'] = $_REQUEST['layout'] = 'statistic'; $QUERY_STRING .= "&layout=statistic"; if (!empty($url_array[$pos + 3])) { if (!empty($url_array[$pos + 3])) { if ($config->get('main_sef_unicode')) { // perform manual split on the string. $permalinkSegment = $url_array[$pos + 3]; $permalinkArr = explode(':', $permalinkSegment); $id = $permalinkArr[0]; } else { $id = $this->revertPermalink($url_array[$pos + 3], 'teamblog'); } $_GET['id'] = $_REQUEST['id'] = $id; $QUERY_STRING .= "&id=" . $id; } if (!empty($url_array[$pos + 5])) { $stat = sefdecode($url_array[$pos + 5]); $_GET['stat'] = $_REQUEST['stat'] = $stat; $QUERY_STRING .= "&stat=" . $stat; } if (!empty($url_array[$pos + 6]) && !empty($stat)) { switch ($stat) { case 'category': if ($config->get('main_sef_unicode')) { // perform manual split on the string. $permalinkSegment = $url_array[$pos + 6]; $permalinkArr = explode(':', $permalinkSegment); $catid = $permalinkArr[0]; } else { $catid = $this->revertPermalink($url_array[$pos + 6], 'category'); } $_GET['catid'] = $_REQUEST['catid'] = $catid; $QUERY_STRING .= "&catid=" . $catid; break; case 'tag': if ($config->get('main_sef_unicode')) { // perform manual split on the string. $permalinkSegment = $url_array[$pos + 6]; $permalinkArr = explode(':', $permalinkSegment); $tagid = $permalinkArr[0]; } else { $tagid = $this->revertPermalink($url_array[$pos + 6], 'tag'); } $_GET['tagid'] = $_REQUEST['tagid'] = $tagid; $QUERY_STRING .= "&tagid=" . $tagid; break; default: // Do nothing . } } } } else { if (!empty($url_array[$pos + 3])) { if ($url_array[$pos + 3] == 'listings') { $_GET['layout'] = $_REQUEST['layout'] = 'listings'; $QUERY_STRING .= "&layout=listings"; } if (!empty($url_array[$pos + 4])) { if ($config->get('main_sef_unicode')) { // perform manual split on the string. $permalinkSegment = $url_array[$pos + 4]; $permalinkArr = explode(':', $permalinkSegment); $id = $permalinkArr[0]; } else { $id = $this->revertPermalink($url_array[$pos + 4], 'teamblog'); } $_GET['id'] = $_REQUEST['id'] = $id; $QUERY_STRING .= "&id=" . $id; } } } break; case 'dashboard': if (!empty($url_array[$pos + 3])) { $_GET['layout'] = $_REQUEST['layout'] = $url_array[$pos + 3]; $QUERY_STRING .= "&layout=" . $url_array[$pos + 3]; if ($url_array[$pos + 3] == 'write') { if (!empty($url_array[$pos + 4])) { if (preg_match('/blogid-/i', $url_array[$pos + 4])) { $temp = explode('blogid-', $url_array[$pos + 4]); $temp = explode('&', $temp[1]); $blogid = $temp[0]; $_GET['blogid'] = $_REQUEST['blogid'] = $blogid; $QUERY_STRING .= '&blogid=' . $blogid; } } } } break; default: $idname = ''; } if (!empty($Itemid)) { $_GET['Itemid'] = $_REQUEST['Itemid'] = $Itemid; $QUERY_STRING .= '&Itemid=' . $Itemid; } foreach ($url_array as $field) { if (preg_match('/limitstart-/i', $field)) { $temp = explode('limitstart-', $field); $temp = explode('&', $temp[1]); $limitstart = $temp[0]; $_GET['limitstart'] = $_REQUEST['limitstart'] = $limitstart; $QUERY_STRING .= '&limitstart=' . $limitstart; } } //echo $QUERY_STRING.'<br/><br/>'; return $QUERY_STRING; }