id, "forum", "search", "search.php?id=$course->id&search=".urlencode($search), $search); $strforums = get_string("modulenameplural", "forum"); $strsearch = get_string("search", "forum"); $strsearchresults = get_string("searchresults", "forum"); $strpage = get_string("page"); if (!$search || $showform) { $navlinks = array(); $navlinks[] = array('name' => $strforums, 'link' => "index.php?id=$course->id", 'type' => 'activity'); $navlinks[] = array('name' => $strsearch, 'link' => '', 'type' => 'title'); $navigation = build_navigation($navlinks); print_header_simple("$strsearch", "", $navigation, 'search.words', "", "", " ", navmenu($course)); forum_print_big_search_form($course); print_footer($course); exit; } /// We need to do a search now and print results $searchterms = str_replace('forumid:', 'instance:', $search); $searchterms = explode(' ', $searchterms); $searchform = forum_search_form($course, $search); $navlinks = array(); $navlinks[] = array('name' => $strsearch, 'link' => "search.php?id=$course->id", 'type' => 'activityinstance'); $navlinks[] = array('name' => s($search, true), 'link' => '', 'type' => 'link'); $navigation = build_navigation($navlinks); if (!$posts = forum_search_posts($searchterms, $course->id, $page*$perpage, $perpage, $totalcount)) { print_header_simple("$strsearchresults", "", $navigation, 'search.words', "", "", " ", navmenu($course)); print_heading(get_string("nopostscontaining", "forum", $search)); if (!$individualparams) { $words = $search; } forum_print_big_search_form($course); print_footer($course); exit; } print_header_simple("$strsearchresults", "", $navigation, '', "", "", $searchform, navmenu($course)); echo '
'.$strmissingsearchterms.' '.$missing_terms.'
'.$post->message; } // Prepare a link to the post in context, to be displayed after the forum post. $fulllink = "discussion#p$post->id\">".get_string("postincontext", "forum").""; // Now pring the post. forum_print_post($post, $discussion, $forum, $cm, $course, false, false, false, false, $fulllink, $strippedsearch, -99, false); } print_paging_bar($totalcount, $page, $perpage, "search.php?search=".urlencode(stripslashes($search))."&id=$course->id&perpage=$perpage&"); print_footer($course); /** * @todo Document this function */ function forum_print_big_search_form($course) { global $CFG, $words, $subject, $phrase, $user, $userid, $fullwords, $notwords, $datefrom, $dateto; print_simple_box(get_string('searchforumintro', 'forum'), 'center', '', '', 'searchbox', 'intro'); print_simple_box_start("center"); echo "\n"; echo ''; echo "\n"; print_simple_box_end(); } /** * This function takes each word out of the search string, makes sure they are at least * two characters long and returns an array containing every good word. * * @param string $words String containing space-separated strings to search for * @param string $prefix String to prepend to the each token taken out of $words * @returns array * @todo Take the hardcoded limit out of this function and put it into a user-specified parameter */ function forum_clean_search_terms($words, $prefix='') { $searchterms = explode(' ', $words); foreach ($searchterms as $key => $searchterm) { if (strlen($searchterm) < 2) { unset($searchterms[$key]); } else if ($prefix) { $searchterms[$key] = $prefix.$searchterm; } } return trim(implode(' ', $searchterms)); } /** * @todo Document this function */ function forum_menu_list($course) { $menu = array(); $modinfo = get_fast_modinfo($course); if (empty($modinfo->instances['forum'])) { return $menu; } foreach ($modinfo->instances['forum'] as $cm) { if (!$cm->uservisible) { continue; } $context = get_context_instance(CONTEXT_MODULE, $cm->id); if (!has_capability('mod/forum:viewdiscussion', $context)) { continue; } $menu[$cm->instance] = format_string($cm->name); } return $menu; } ?>