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. 78
      main/forum/forumfunction.inc.php
  2. 42
      main/forum/forumsearch.php

@ -3194,18 +3194,22 @@ function store_move_thread($values) {
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @version february 2006, dokeos 1.8 * @version february 2006, dokeos 1.8
*/ */
function prepare4display($input='') { 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'); $highlightcolors = array('yellow', '#33CC33','#3399CC', '#9999FF', '#33CC33');
if (!is_array($input)) { if (!is_array($input)) {
if (!empty($_GET['search'])) { if (!empty($search)) {
if (strstr($_GET['search'],'+')) { if (strstr($search, '+')) {
$search_terms = explode('+',$_GET['search']); $search_terms = explode('+', $search);
} else { } else {
$search_terms[] = trim($_GET['search']); $search_terms[] = trim($search);
} }
$counter = 0; $counter = 0;
foreach ($search_terms as $key=>$search_term) { 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++; $counter++;
} }
} }
@ -3213,8 +3217,8 @@ function prepare4display($input='') {
//change this to COURSEMANAGERLOWSECURITY or COURSEMANAGER to lower filtering and allow more styles (see comments of Security::remove_XSS() method to learn about other levels) //change this to COURSEMANAGERLOWSECURITY or COURSEMANAGER to lower filtering and allow more styles (see comments of Security::remove_XSS() method to learn about other levels)
return Security::remove_XSS($input, STUDENT); return Security::remove_XSS($input, STUDENT);
} else { } else {
$returnarray=array_walk($input, 'api_html_entity_decode'); $returnarray = array_walk($input, 'api_html_entity_decode');
$returnarray=array_walk($input, 'stripslashes'); $returnarray = array_walk($input, 'stripslashes');
return $returnarray; return $returnarray;
} }
} }
@ -3228,26 +3232,26 @@ function prepare4display($input='') {
function forum_search() { function forum_search() {
global $origin; global $origin;
// initiate the object // Initialize the object.
$form = new FormValidator('forumsearch','post','forumsearch.php?origin='.$origin.''); $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('header', '', get_lang('ForumSearch'));
$form->addElement('text', 'search_term', get_lang('SearchTerm'),'class="input_titles" id="search_title"'); $form->addElement('text', 'search_term', get_lang('SearchTerm'), 'class="input_titles" id="search_title"');
$form->applyFilter('search_term', 'html_filter'); $form->applyFilter('search_term', 'html_filter');
$form->addElement('static', 'search_information', '', get_lang('ForumSearchInformation')/*, $dissertation[$_GET['opleidingsonderdeelcode']]['code']*/); $form->addElement('static', 'search_information', '', get_lang('ForumSearchInformation')/*, $dissertation[$_GET['opleidingsonderdeelcode']]['code']*/);
$form->addElement('style_submit_button', null, get_lang('Search'), 'class="search"'); $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('ThisFieldIsRequired'), 'required');
$form->addRule('search_term', get_lang('TooShort'),'minlength',3); $form->addRule('search_term', get_lang('TooShort'), 'minlength', 3);
// The validation or display // The validation or display.
if( $form->validate() ) { if( $form->validate() ) {
$values = $form->exportValues(); $values = $form->exportValues();
$form->setDefaults($values); $form->setDefaults($values);
$form->display(); $form->display();
// display the search results // Display the search results.
display_forum_search_results(stripslashes($values['search_term'])); display_forum_search_results(stripslashes($values['search_term']));
} else { } else {
$form->display(); $form->display();
@ -3269,15 +3273,15 @@ function display_forum_search_results($search_term) {
$table_threads = Database :: get_course_table(TABLE_FORUM_THREAD); $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
$table_posts = Database :: get_course_table(TABLE_FORUM_POST); $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
$gradebook=Security::remove_XSS($_GET['gradebook']); $gradebook = Security::remove_XSS($_GET['gradebook']);
// defining the search strings as an array // Defining the search strings as an array.
if (strstr($search_term,'+')) { if (strstr($search_term, '+')) {
$search_terms = explode('+',$search_term); $search_terms = explode('+', $search_term);
} else { } else {
$search_terms[] = $search_term; $search_terms[] = $search_term;
} }
// search restriction // Search restriction.
foreach ($search_terms as $key => $value) { foreach ($search_terms as $key => $value) {
$search_restriction[] = "(posts.post_title LIKE '%".Database::escape_string(trim($value))."%' $search_restriction[] = "(posts.post_title LIKE '%".Database::escape_string(trim($value))."%'
OR posts.post_text LIKE '%".Database::escape_string(trim($value))."%')"; OR posts.post_text LIKE '%".Database::escape_string(trim($value))."%')";
@ -3287,24 +3291,24 @@ function display_forum_search_results($search_term) {
WHERE ".implode(' AND ',$search_restriction)." WHERE ".implode(' AND ',$search_restriction)."
GROUP BY posts.post_id"; 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(); $forum_categories_list = get_forum_categories();
// getting all the information of the forums // Getting all the information of the forums.
$forum_list=get_forums(); $forum_list = get_forums();
$result = Database::query($sql); $result = Database::query($sql);
while ($row = Database::fetch_array($result,'ASSOC')) { while ($row = Database::fetch_array($result, 'ASSOC')) {
$display_result = false; $display_result = false;
/* /*
we only show it when We only show it when
1. forum cateogory is visible 1. forum cateogory is visible
2. forum is visible 2. forum is visible
3. thread is visible (to do) 3. thread is visible (to do)
4. post is visible 4. post is visible
*/ */
if (!api_is_allowed_to_edit(null,true)) { if (!api_is_allowed_to_edit(null, true)) {
if ($forum_categories_list[$row['forum_id']['forum_category']]['visibility'] == '1' AND $forum_list[$row['forum_id']]['visibility'] == '1' AND $row['visible'] == '1') { if ($forum_categories_list[$row['forum_id']['forum_category']]['visibility'] == '1' AND $forum_list[$row['forum_id']]['visibility'] == '1' AND $row['visible'] == '1') {
$display_result = true; $display_result = true;
} }
} else { } else {
@ -3312,15 +3316,15 @@ function display_forum_search_results($search_term) {
} }
if ($display_result) { 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 = '<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).'">'.$forum_list[$row['forum_id']]['forum_title'].'</a> > '; $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> > '; //$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).'">'.$row['post_title'].'</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).'">'.prepare4display($row['post_title']).'</a>';
$search_results_item .= '<br />'; $search_results_item .= '<br />';
if (api_strlen($row['post_title']) > 200 ) { 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 { } else {
$search_results_item .= $row['post_title']; $search_results_item .= prepare4display($row['post_title']);
} }
$search_results_item .= '</li>'; $search_results_item .= '</li>';
$search_results[] = $search_results_item; $search_results[] = $search_results_item;
@ -3328,7 +3332,7 @@ function display_forum_search_results($search_term) {
} }
echo '<div class="row"><div class="form_header">'.count($search_results).' '.get_lang('ForumSearchResults').'</div></div>'; echo '<div class="row"><div class="form_header">'.count($search_results).' '.get_lang('ForumSearchResults').'</div></div>';
echo '<ol>'; echo '<ol>';
if($search_results) { if ($search_results) {
echo implode($search_results); echo implode($search_results);
} }
echo '</ol>'; echo '</ol>';

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