Task #1297 - The "Forums" tool, prepare4display(): Restoring highlighting in the search results and other minor changes.

skala
Ivan Tcholakov 14 years ago
parent 216aed6e30
commit e55a2c61ca
  1. 46
      main/forum/forumfunction.inc.php
  2. 34
      main/forum/forumsearch.php

@ -3195,17 +3195,21 @@ function store_move_thread($values) {
* @version february 2006, dokeos 1.8
*/
function prepare4display($input = '') {
static $search;
if (!isset($search)) {
$search = html_filter($_POST['search_term']); // No html at all.
}
$highlightcolors = array('yellow', '#33CC33','#3399CC', '#9999FF', '#33CC33');
if (!is_array($input)) {
if (!empty($_GET['search'])) {
if (strstr($_GET['search'],'+')) {
$search_terms = explode('+',$_GET['search']);
if (!empty($search)) {
if (strstr($search, '+')) {
$search_terms = explode('+', $search);
} else {
$search_terms[] = trim($_GET['search']);
$search_terms[] = trim($search);
}
$counter = 0;
foreach ($search_terms as $key => $search_term) {
$input = str_replace(trim($search_term),'<span style="background-color: '.$highlightcolors[$counter].'">'.trim($search_term).'</span>',$input);
$input = api_preg_replace('/'.preg_quote(trim($search_term)).'/i', '<span style="background-color: '.$highlightcolors[$counter].'">$0</span>', $input);
$counter++;
}
}
@ -3228,26 +3232,26 @@ function prepare4display($input='') {
function forum_search() {
global $origin;
// initiate the object
// Initialize the object.
$form = new FormValidator('forumsearch', 'post', 'forumsearch.php?origin='.$origin.'');
// settting the form elements
// Settting the form elements.
$form->addElement('header', '', get_lang('ForumSearch'));
$form->addElement('text', 'search_term', get_lang('SearchTerm'), 'class="input_titles" id="search_title"');
$form->applyFilter('search_term', 'html_filter');
$form->addElement('static', 'search_information', '', get_lang('ForumSearchInformation')/*, $dissertation[$_GET['opleidingsonderdeelcode']]['code']*/);
$form->addElement('style_submit_button', null, get_lang('Search'), 'class="search"');
// setting the rules
// Setting the rules.
$form->addRule('search_term', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('search_term', get_lang('TooShort'), 'minlength', 3);
// The validation or display
// The validation or display.
if( $form->validate() ) {
$values = $form->exportValues();
$form->setDefaults($values);
$form->display();
// display the search results
// Display the search results.
display_forum_search_results(stripslashes($values['search_term']));
} else {
$form->display();
@ -3270,14 +3274,14 @@ function display_forum_search_results($search_term) {
$table_posts = Database :: get_course_table(TABLE_FORUM_POST);
$gradebook = Security::remove_XSS($_GET['gradebook']);
// defining the search strings as an array
// Defining the search strings as an array.
if (strstr($search_term, '+')) {
$search_terms = explode('+', $search_term);
} else {
$search_terms[] = $search_term;
}
// search restriction
// Search restriction.
foreach ($search_terms as $key => $value) {
$search_restriction[] = "(posts.post_title LIKE '%".Database::escape_string(trim($value))."%'
OR posts.post_text LIKE '%".Database::escape_string(trim($value))."%')";
@ -3287,17 +3291,17 @@ function display_forum_search_results($search_term) {
WHERE ".implode(' AND ',$search_restriction)."
GROUP BY posts.post_id";
// getting all the information of the forum categories
// Getting all the information of the forum categories.
$forum_categories_list = get_forum_categories();
// getting all the information of the forums
// Getting all the information of the forums.
$forum_list = get_forums();
$result = Database::query($sql);
while ($row = Database::fetch_array($result, 'ASSOC')) {
$display_result = false;
/*
we only show it when
We only show it when
1. forum cateogory is visible
2. forum is visible
3. thread is visible (to do)
@ -3312,15 +3316,15 @@ function display_forum_search_results($search_term) {
}
if ($display_result) {
$search_results_item = '<li><a href="viewforumcategory.php?forumcategory='.$forum_list[$row['forum_id']]['forum_category'].'&amp;origin='.$origin.'&amp;search='.urlencode($search_term).'">'.$forum_categories_list[$row['forum_id']['forum_category']]['cat_title'].'</a> > ';
$search_results_item .= '<a href="viewforum.php?forum='.$row['forum_id'].'&amp;origin='.$origin.'&amp;search='.urlencode($search_term).'">'.$forum_list[$row['forum_id']]['forum_title'].'</a> > ';
//$search_results_item .= '<a href="">THREAD</a> > ';
$search_results_item .= '<a href="viewthread.php?forum='.$row['forum_id'].'&amp;gradebook='.$gradebook.'&amp;origin='.$origin.'&amp;thread='.$row['thread_id'].'&amp;search='.urlencode($search_term).'">'.$row['post_title'].'</a>';
$search_results_item = '<li><a href="viewforumcategory.php?forumcategory='.$forum_list[$row['forum_id']]['forum_category'].'&amp;origin='.$origin.'&amp;search='.urlencode($search_term).'">'.prepare4display($forum_categories_list[$row['forum_id']['forum_category']]['cat_title']).'</a> &gt; ';
$search_results_item .= '<a href="viewforum.php?forum='.$row['forum_id'].'&amp;origin='.$origin.'&amp;search='.urlencode($search_term).'">'.prepare4display($forum_list[$row['forum_id']]['forum_title']).'</a> &gt; ';
//$search_results_item .= '<a href="">THREAD</a> &gt; ';
$search_results_item .= '<a href="viewthread.php?forum='.$row['forum_id'].'&amp;gradebook='.$gradebook.'&amp;origin='.$origin.'&amp;thread='.$row['thread_id'].'&amp;search='.urlencode($search_term).'">'.prepare4display($row['post_title']).'</a>';
$search_results_item .= '<br />';
if (api_strlen($row['post_title']) > 200 ) {
$search_results_item .= api_substr(strip_tags($row['post_title']),0,200).'...';
$search_results_item .= prepare4display(api_substr(strip_tags($row['post_title']), 0, 200)).'...';
} else {
$search_results_item .= $row['post_title'];
$search_results_item .= prepare4display($row['post_title']);
}
$search_results_item .= '</li>';
$search_results[] = $search_results_item;

@ -21,34 +21,34 @@
* @package chamilo.forum
*/
// name of the language file that needs to be included
// Language files that need to be included.
$language_file = array ('forum', 'group');
// including the global dokeos file
// Including the global initialiation file.
require_once '../inc/global.inc.php';
// the section (tabs)
// The section (tabs).
$this_section = SECTION_COURSES;
// notice for unauthorized people.
// Notification for unauthorized people.
api_protect_course_script(true);
// including additional library scripts
// Including additional library scripts.
require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
include_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
include 'forumfunction.inc.php';
include 'forumconfig.inc.php';
//are we in a lp ?
// Are we in a lp ?
$origin = '';
if (isset($_GET['origin'])) {
$origin = Security::remove_XSS($_GET['origin']);
}
// name of the tool
// Name of the tool
$nameTools = get_lang('ToolForum');
// breadcrumbs
// Breadcrumbs
if (isset($_SESSION['gradebook'])){
$gradebook = $_SESSION['gradebook'];
@ -69,35 +69,35 @@ if (!empty ($_GET['gidReq'])) {
if ($origin == 'group') {
$_clean['toolgroup']=(int)$_SESSION['toolgroup'];
$group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
$interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
$interbreadcrumb[] = array ("url" => "../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
$interbreadcrumb[] = array ("url" => "viewforum.php?origin=".$origin."&amp;gidReq=".$_SESSION['toolgroup']."&amp;forum=".Security::remove_XSS($_GET['forum']),"name" => prepare4display($current_forum['forum_title']));
$interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups'));
$interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$_SESSION['toolgroup'], 'name' => get_lang('GroupSpace').' ('.$group_properties['name'].')');
$interbreadcrumb[] = array('url' => 'viewforum.php?origin='.$origin.'&amp;gidReq='.$_SESSION['toolgroup'].'&amp;forum='.Security::remove_XSS($_GET['forum']), 'name' => prepare4display($current_forum['forum_title']));
$interbreadcrumb[] = array('url' => 'forumsearch.php','name' => get_lang('ForumSearch'));
} else {
$interbreadcrumb[] = array('url' => 'index.php?gradebook='.$gradebook.'', 'name' => $nameTools);
$interbreadcrumb[] = array('url' => 'forumsearch.php', 'name' => get_lang('ForumSearch'));
}
// Display the header
// Display the header.
if ($origin == 'learnpath') {
include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
include api_get_path(INCLUDE_PATH).'reduced_header.inc.php';
} else {
Display :: display_header($nameTools);
}
// Display the tool title
// Display the tool title.
// api_display_tool_title($nameTools);
// Tool introduction
Display::display_introduction_section(TOOL_FORUM);
// tracking
// Tracking
event_access_tool(TOOL_FORUM);
// forum search
// Forum search
forum_search();
// footer
// Footer
if ($origin != 'learnpath') {
Display :: display_footer();
}
Loading…
Cancel
Save