require_once(AT_INCLUDE_PATH.'lib/mysql_connect.inc.php'); //require_once(AT_INCLUDE_PATH.'vitals.inc.php'); //mimic config variables, vitals.inc.php 135-140 /* get config variables. if they're not in the db then it uses the installation default value in constants.inc.php */ $sql = "SELECT * FROM ".TABLE_PREFIX."config"; $result = mysql_query($sql, $db); while ($row = mysql_fetch_assoc($result)) { $_config[$row['name']] = $row['value']; } //Get path info $pathinfo = getPathInfo(); $url_parser = new UrlParser($pathinfo); $path_array = $url_parser->getPathArray(); $_pretty_url_course_id = $path_array[0]; $obj = $path_array[1]; if (!$obj->isEmpty()){ /* * Addresses the issue for relative uri * @refer to constants.inc.php $_rel_link */ $_rel_url = $obj->redirect(); $var_query = $obj->parsePrettyQuery(); save2Get($var_query); //remake all the _GET and _REQUEST variables so that the vitals can use it $_user_location = ''; //reset user_location so that the vital file in each page would validate $pretty_current_page = $obj->getPage(); //If page not found, forward back to index.php
/** * If pretty URL within admin config is switched on. We will apply pretty URL * to all the links in ATutor. This function will authenticate itself towards the current pages. * In our definition, admins, login, registration pages shouldn't have pretty url applied. However, * if one want to use url_rewrite on these pages, please force it by using the third parameter. * Note: If system config has turned off this feature, $force will have no effect. * @param string the Url should be a relative link, have to improve this later on, to check if * it's a relative link, if not, truncate it. * @param boolean Available values are AT_PRETTY_URL_IS_HEADER, AT_PRETTY_URL_NOT_HEADER(default) * use AT_PRETTY_URL_IS_HEADER if url_rewrite is used in php header('Location:..'), absolute path is needed for this. * @param boolean true to force the url_rewrite, false otheriwse. False is the default. * @author Harris Wong */ function url_rewrite($url, $is_rewriting_header = AT_PRETTY_URL_NOT_HEADER, $force = false) { global $_config, $db; $url_parser = new UrlParser(); $pathinfo = $url_parser->getPathArray(); /* If this is any kind of admins, don't prettify the url * $_SESSION['is_guest'] is used to check against login/register/browse page, the links on this page will * only be prettified when a user has logged in. * Had used $_SESSION[valid_user] before but it created this problem: * http://www.atutor.ca/atutor/mantis/view.php?id=3426 */ if ($force || isset($_SESSION['course_id']) && $_SESSION['course_id'] > 0) { //if course id is defined, apply pretty url. } else { if (admin_authenticate(AT_ADMIN_PRIV_ADMIN, AT_PRIV_RETURN) || isset($_SESSION['privileges']) && admin_authenticate($_SESSION['privileges'], AT_PRIV_RETURN) || isset($_SESSION['is_guest']) && $_SESSION['is_guest'] == 1) { return $url; } } //if we allow pretty url in the system if ($_config['pretty_url'] > 0) { $course_id = 0; //If we allow course dir name from sys perf if ($_config['course_dir_name'] > 0) { if (preg_match('/bounce.php\\?course=([\\d]+)$/', $url, $matches) == 1) { // bounce has the highest priority, even if session is set, work on // bounce first. $course_id = $url_parser->getCourseDirName($matches[1]); } elseif (isset($_REQUEST['course'])) { //jump menu $course_id = $url_parser->getCourseDirName($_REQUEST['course']); } elseif (isset($_REQUEST['p_course'])) { // is set when guests access public course. @see bounce.php $course_id = $url_parser->getCourseDirName($_REQUEST['p_course']); } elseif (isset($_SESSION['course_id']) && $_SESSION['course_id'] > 0) { $course_id = $url_parser->getCourseDirName($_SESSION['course_id']); } } else { if (isset($_SESSION['course_id'])) { $course_id = $_SESSION['course_id']; } } $url = $pathinfo[1]->convertToPrettyUrl($course_id, $url); } elseif ($_config['course_dir_name'] > 0) { //enabled course directory name, disabled pretty url if (preg_match('/bounce.php\\?course=([\\d]+)$/', $url, $matches) == 1) { // bounce has the highest priority, even if session is set, work on // bounce first. $course_id = $url_parser->getCourseDirName($matches[1]); } elseif (isset($_REQUEST['course'])) { $course_id = $url_parser->getCourseDirName($_REQUEST['course']); } elseif (isset($_REQUEST['p_course'])) { // is set when guests access public course. @see bounce.php $course_id = $url_parser->getCourseDirName($_REQUEST['p_course']); } elseif (isset($_SESSION['course_id']) && $_SESSION['course_id'] > 0) { $course_id = $url_parser->getCourseDirName($_SESSION['course_id']); } $url = $pathinfo[1]->convertToPrettyUrl($course_id, $url); } //instead of putting AT_BASE_HREF in all the headers location, we will put it here. //Abs paths are required for pretty url because otherwise the url location will be appeneded. //ie. ATutor_161/blogs/CoURSe_rOAd/blogs/view.php/ot/1/oid/1/ instead of // ATutor_161/CoURSe_rOAd/blogs/view.php/ot/1/oid/1/ if ($is_rewriting_header == true) { return AT_BASE_HREF . $url; } return $url; }
$final_home_links .= $pathinfo[1]->getPath() . $pathinfo[1]->getFileName() . '|'; } $final_home_links = substr($final_home_links, 0, -1); } } } // handle ajax post request to remove module from course index page and student tools index page if ($_POST['remove'] != '') { $remove_module = $_POST['remove']; // when pretty url is turned on, revert the pretty url back to regular url if ($_config['pretty_url'] > 0) { if (substr($remove_module, 0, 6) == 'go.php') { $remove_module = substr($remove_module, 6); } $url_parser = new UrlParser($remove_module); $pathinfo = $url_parser->getPathArray(); $remove_module = $pathinfo[1]->getPath() . $pathinfo[1]->getFileName(); } if ($from == 'course_index') { $sql = "SELECT home_links links FROM " . TABLE_PREFIX . "courses WHERE course_id={$_SESSION['course_id']}"; } else { if ($from == 'student_tools') { $sql = "SELECT links FROM " . TABLE_PREFIX . "fha_student_tools WHERE course_id={$_SESSION['course_id']}"; } } $result = mysql_query($sql, $db); $row = mysql_fetch_assoc($result); if (substr($row['links'], 0, strlen($remove_module)) == $remove_module) { $final_home_links = substr($row['links'], strlen($remove_module) + 1); } else { $final_home_links = preg_replace('/\\|' . preg_quote($remove_module, '/') . '/', '', $row['links']);