Skip to content

Commit

Permalink
search MDL-19822 Upgraded deprecated calls and added set_url calls
Browse files Browse the repository at this point in the history
  • Loading branch information
samhemelryk committed Oct 15, 2009
1 parent beebcf2 commit c86bdd5
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 16 deletions.
15 changes: 12 additions & 3 deletions search/documents/chat_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function chat_make_link($cm_id, $start, $end) {
/**
* fetches all the records for a given session and assemble them as a unique track
* we revamped here the code of report.php for making sessions, but without any output.
* note that we should collect sessions "by groups" if groupmode() is SEPARATEGROUPS.
* note that we should collect sessions "by groups" if $groupmode is SEPARATEGROUPS.
* @param int $chat_id the database
* @param int $fromtime
* @param int $totime
Expand All @@ -91,7 +91,11 @@ function chat_get_session_tracks($chat_id, $fromtime = 0, $totime = 0) {
$course = $DB->get_record('course', array('id' => $chat->course));
$coursemodule = $DB->get_field('modules', 'id', array('name' => 'data'));
$cm = $DB->get_record('course_modules', array('course' => $course->id, 'module' => $coursemodule, 'instance' => $chat->id));
$groupmode = groupmode($course, $cm);
if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
$groupmode = $cm->groupmode;
} else {
$groupmode = $course->groupmode;
}

$fromtimeclause = ($fromtime) ? "AND timestamp >= {$fromtime}" : '';
$totimeclause = ($totime) ? "AND timestamp <= {$totime}" : '';
Expand Down Expand Up @@ -283,7 +287,12 @@ function chat_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
//group consistency check : checks the following situations about groups
// trap if user is not same group and groups are separated
$course = $DB->get_record('course', array('id' => $chat->course));
if ((groupmode($course, $cm) == SEPARATEGROUPS) && !ismember($group_id) && !has_capability('moodle/site:accessallgroups', $context)){
if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
$groupmode = $cm->groupmode;
} else {
$groupmode = $course->groupmode;
}
if (($groupmode == SEPARATEGROUPS) && !ismember($group_id) && !has_capability('moodle/site:accessallgroups', $context)){
if (!empty($CFG->search_access_debug)) echo "search reject : chat element is in separated group ";
return false;
}
Expand Down
7 changes: 6 additions & 1 deletion search/documents/data_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,12 @@ function data_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
//group consistency check : checks the following situations about groups
// trap if user is not same group and groups are separated
$course = $DB->get_record('course', 'id', $data->course);
if ((groupmode($course, $cm) == SEPARATEGROUPS) && !ismember($group_id) && !has_capability('moodle/site:accessallgroups', $context)){
if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
$groupmode = $cm->groupmode;
} else {
$groupmode = $course->groupmode;
}
if (($groupmode == SEPARATEGROUPS) && !ismember($group_id) && !has_capability('moodle/site:accessallgroups', $context)){
if (!empty($CFG->search_access_debug)) echo "search reject : separated group owned resource ";
return false;
}
Expand Down
38 changes: 32 additions & 6 deletions search/documents/forum_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,25 @@ function forum_db_names() {
* @param int $forum_id a forum identifier
* @uses $CFG, $USER, $DB
* @return an array of posts
* @todo get rid of old isteacher() call
*/
function forum_get_discussions_fast($forum_id) {
global $CFG, $USER, $DB;

$timelimit='';
if (!empty($CFG->forum_enabletimedposts)) {
if (!((has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))
&& !empty($CFG->admineditalways)) || isteacher(get_field('forum', 'course', 'id', $forum_id)))) {

$courseid = $DB->get_field('forum', 'course', array('id'=>$forum_id));

if ($courseid) {
$coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
} else {
$coursecontext = get_context_instance(CONTEXT_SYSTEM);
$systemcontext = $coursecontext;
}

if (!((has_capability('moodle/site:doanything', $systemcontext) && !empty($CFG->admineditalways))
|| has_any_capability(array('moodle/legacy:teacher', 'moodle/legacy:editingteacher', 'moodle/legacy:admin'), $coursecontext, $userid, false))) {
$now = time();
$timelimit = " AND ((d.timestart = 0 OR d.timestart <= '$now') AND (d.timeend = 0 OR d.timeend > '$now')";
if (!empty($USER->id)) {
Expand Down Expand Up @@ -283,7 +293,7 @@ function forum_get_child_posts_fast($parent, $forum_id) {
* @return true if access is allowed, false elsewhere
*/
function forum_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
global $CFG, $USER, $DB;
global $CFG, $USER, $DB, $SESSION;

include_once("{$CFG->dirroot}/{$path}/lib.php");

Expand All @@ -307,9 +317,25 @@ function forum_check_text_access($path, $itemtype, $this_id, $user, $group_id, $
}

// group check : entries should be in accessible groups
$current_group = get_current_group($discussion->course);
if (isset($SESSION->currentgroup[$discussion->course])) {
$current_group = $SESSION->currentgroup[$discussion->course];
} else {
$current_group = groups_get_all_groups($discussion->course, $USER->id);
if (is_array($current_group)) {
$current_group = array_shift(array_keys($current_group));
$SESSION->currentgroup[$discussion->course] = $current_group;
} else {
$current_group = 0;
}
}

$course = $DB->get_record('course', array('id' => $discussion->course));
if ($group_id >= 0 && (groupmode($course, $cm) == SEPARATEGROUPS) && ($group_id != $current_group) && !has_capability('mod/forum:viewdiscussionsfromallgroups', $context)){
if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
$groupmode = $cm->groupmode;
} else {
$groupmode = $course->groupmode;
}
if ($group_id >= 0 && ($groupmode == SEPARATEGROUPS) && ($group_id != $current_group) && !has_capability('mod/forum:viewdiscussionsfromallgroups', $context)){
if (!empty($CFG->search_access_debug)) echo "search reject : separated grouped forum item";
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion search/documents/lesson_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ function lesson_check_text_access($path, $itemtype, $this_id, $user, $group_id,
}

// the user have it seen yet ? did he tried one time at least
$attempt = get_record('lesson_attempts', 'lessonid', $lesson->id, 'pageid', $page->id, 'userid', $USER->id);
$attempt = $DB->get_record('lesson_attempts', array('lessonid'=>$lesson->id,'pageid'=>$page->id, 'userid'=>$USER->id));

if (!$attempt && !$lessonsuperuser){
if (!empty($CFG->search_access_debug)) echo "search reject : never tried this lesson ";
return false;
Expand Down
22 changes: 19 additions & 3 deletions search/documents/wiki_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ function wiki_db_names() {
* @return true if access is allowed, false elsewhere
*/
function wiki_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id){
global $CFG, $DB;
global $CFG, $DB, $SESSION;

// get the wiki object and all related stuff
$page = $DB->get_record('wiki_pages', array('id' => $this_id));
Expand All @@ -275,8 +275,24 @@ function wiki_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c

//group consistency check : checks the following situations about groups
// trap if user is not same group and groups are separated
$current_group = get_current_group($course->id);
if ((groupmode($course) == SEPARATEGROUPS) && $group_id != $current_group && !has_capability('moodle/site:accessallgroups', $context)) {
if (isset($SESSION->currentgroup[$course->id])) {
$current_group = $SESSION->currentgroup[$course->id];
} else {
$current_group = groups_get_all_groups($course->id, $USER->id);
if (is_array($current_group)) {
$current_group = array_shift(array_keys($current_group));
$SESSION->currentgroup[$course->id] = $current_group;
} else {
$current_group = 0;
}
}

if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
$groupmode = $cm->groupmode;
} else {
$groupmode = $course->groupmode;
}
if (($groupmode == SEPARATEGROUPS) && $group_id != $current_group && !has_capability('moodle/site:accessallgroups', $context)) {
if (!empty($CFG->search_access_debug)) echo "search reject : separated group owner wiki ";
return false;
}
Expand Down
1 change: 1 addition & 0 deletions search/indexersplash.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
// print page header
$site = get_site();

$PAGE->set_url(new moodle_url($CFG->wwwroot.'/search/indexersplash.php'));
$PAGE->navbar->add($strsearch, new moodle_url($CFG->wwwroot.'/search/index.php'));
$PAGE->navbar->add($strquery, new moodle_url($CFG->wwwroot.'/search/stats.php'));
$PAGE->navbar->add(get_string('runindexer','search'));
Expand Down
9 changes: 9 additions & 0 deletions search/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@
$advanced = (optional_param('a', '0', PARAM_INT) == '1') ? true : false;
$query_string = stripslashes(optional_param('query_string', '', PARAM_CLEAN));

$url = new moodle_url($CFG->wwwroot.'/search/query.php');
if ($page_number !== -1) {
$url->param('page', $page_number);
}
if ($advanced) {
$url->param('a', '1');
}
$PAGE->set_url($url);

/// discard harmfull searches

if (!isset($CFG->block_search_utf8dir)){
Expand Down
2 changes: 1 addition & 1 deletion search/querylib.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ private function can_display(&$user, $this_id, $doctype, $course_id, $group_id,
$unenroled = !in_array($course_id, array_keys($myCourses));

// if guests are allowed, logged guest can see
$isallowedguest = (isguest()) ? $DB->get_field('course', 'guest', array('id' => $course_id)) : false ;
$isallowedguest = (isguestuser()) ? $DB->get_field('course', 'guest', array('id' => $course_id)) : false ;

if ($unenroled && !$isallowedguest){
return false;
Expand Down
2 changes: 1 addition & 1 deletion search/stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

$site = get_site();

$PAGE->set_url($CFG->wwwroot.'/search/stats.php');
$PAGE->navbar->add($strsearch, new moodle_url($CFG->wwwroot.'/search/index.php'));
$PAGE->navbar->add($strquery, new moodle_url($CFG->wwwroot.'/search/stats.php'));
$PAGE->set_title($strsearch);
Expand Down Expand Up @@ -125,7 +126,6 @@

echo $OUTPUT->table($admin_table);
echo $OUTPUT->spacer($spacer) . '<br />';
print_spacer(20);
}

/// this is the standard summary table for normal users, shows document counts
Expand Down

0 comments on commit c86bdd5

Please sign in to comment.