| 1 | 
        
            562
         | 
        
            Ruebenwurz
         | 
        <?php
  | 
      
      
        | 2 | 
        
         | 
        
         | 
        
  | 
      
      
        | 3 | 
        
         | 
        
         | 
        // $Id$
  | 
      
      
        | 4 | 
        
         | 
        
         | 
        
  | 
      
      
        | 5 | 
        
         | 
        
         | 
        /*
  | 
      
      
        | 6 | 
        
         | 
        
         | 
        
  | 
      
      
        | 7 | 
        
         | 
        
         | 
         Website Baker Project <http://www.websitebaker.org/>
  | 
      
      
        | 8 | 
        
         | 
        
         | 
         Copyright (C) 2004-2008, Ryan Djurovich
  | 
      
      
        | 9 | 
        
         | 
        
         | 
        
  | 
      
      
        | 10 | 
        
         | 
        
         | 
         Website Baker is free software; you can redistribute it and/or modify
  | 
      
      
        | 11 | 
        
         | 
        
         | 
         it under the terms of the GNU General Public License as published by
  | 
      
      
        | 12 | 
        
         | 
        
         | 
         the Free Software Foundation; either version 2 of the License, or
  | 
      
      
        | 13 | 
        
         | 
        
         | 
         (at your option) any later version.
  | 
      
      
        | 14 | 
        
         | 
        
         | 
        
  | 
      
      
        | 15 | 
        
         | 
        
         | 
         Website Baker is distributed in the hope that it will be useful,
  | 
      
      
        | 16 | 
        
         | 
        
         | 
         but WITHOUT ANY WARRANTY; without even the implied warranty of
  | 
      
      
        | 17 | 
        
         | 
        
         | 
         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  | 
      
      
        | 18 | 
        
         | 
        
         | 
         GNU General Public License for more details.
  | 
      
      
        | 19 | 
        
         | 
        
         | 
        
  | 
      
      
        | 20 | 
        
         | 
        
         | 
         You should have received a copy of the GNU General Public License
  | 
      
      
        | 21 | 
        
         | 
        
         | 
         along with Website Baker; if not, write to the Free Software
  | 
      
      
        | 22 | 
        
         | 
        
         | 
         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  | 
      
      
        | 23 | 
        
         | 
        
         | 
        
  | 
      
      
        | 24 | 
        
         | 
        
         | 
        */
  | 
      
      
        | 25 | 
        
         | 
        
         | 
        
  | 
      
      
        | 26 | 
        
         | 
        
         | 
        function news_search($func_vars) {
 | 
      
      
        | 27 | 
        
         | 
        
         | 
        	extract($func_vars, EXTR_PREFIX_ALL, 'func');
  | 
      
      
        | 28 | 
        
         | 
        
         | 
        
  | 
      
      
        | 29 | 
        
         | 
        
         | 
        	// how many lines of excerpt we want to have at most
  | 
      
      
        | 30 | 
        
         | 
        
         | 
        	$max_excerpt_num = $func_default_max_excerpt;
  | 
      
      
        | 31 | 
        
         | 
        
         | 
        	// do we want excerpt from comments?
  | 
      
      
        | 32 | 
        
         | 
        
         | 
        	$excerpt_from_comments = true; // TODO: make this configurable
  | 
      
      
        | 33 | 
        
         | 
        
         | 
        	$divider = ".";
  | 
      
      
        | 34 | 
        
         | 
        
         | 
        	$result = false;
  | 
      
      
        | 35 | 
        
         | 
        
         | 
        
  | 
      
      
        | 36 | 
        
         | 
        
         | 
        	// fetch all active news-posts (from active groups) in this section.
  | 
      
      
        | 37 | 
        
            600
         | 
        
            thorn
         | 
        	$t = time();
  | 
      
      
        | 38 | 
        
            562
         | 
        
            Ruebenwurz
         | 
        	$table_posts = TABLE_PREFIX."mod_news_posts";
  | 
      
      
        | 39 | 
        
         | 
        
         | 
        	$table_groups = TABLE_PREFIX."mod_news_groups";
  | 
      
      
        | 40 | 
        
         | 
        
         | 
        	$query = $func_database->query("
 | 
      
      
        | 41 | 
        
         | 
        
         | 
        		SELECT p.post_id, p.title, p.content_short, p.content_long, p.link, p.posted_when, p.posted_by
  | 
      
      
        | 42 | 
        
         | 
        
         | 
        		FROM $table_posts AS p LEFT OUTER JOIN $table_groups AS g ON p.group_id = g.group_id
  | 
      
      
        | 43 | 
        
         | 
        
         | 
        		WHERE p.section_id='$func_section_id' AND p.active = '1' AND ( g.active IS NULL OR g.active = '1' )
  | 
      
      
        | 44 | 
        
            600
         | 
        
            thorn
         | 
        		AND (published_when = '0' OR published_when <= $t) AND (published_until = 0 OR published_until >= $t)
  | 
      
      
        | 45 | 
        
            562
         | 
        
            Ruebenwurz
         | 
        		ORDER BY p.post_id DESC
  | 
      
      
        | 46 | 
        
         | 
        
         | 
        	");
  | 
      
      
        | 47 | 
        
         | 
        
         | 
        	// now call print_excerpt() for every single post
  | 
      
      
        | 48 | 
        
         | 
        
         | 
        	if($query->numRows() > 0) {
 | 
      
      
        | 49 | 
        
         | 
        
         | 
        		while($res = $query->fetchRow()) {
 | 
      
      
        | 50 | 
        
         | 
        
         | 
        			$text = $res['title'].$divider.$res['content_short'].$divider.$res['content_long'].$divider;
  | 
      
      
        | 51 | 
        
         | 
        
         | 
        			// fetch comments and add to $text
  | 
      
      
        | 52 | 
        
         | 
        
         | 
        			if($excerpt_from_comments) {
 | 
      
      
        | 53 | 
        
         | 
        
         | 
        				$table = TABLE_PREFIX."mod_news_comments";
  | 
      
      
        | 54 | 
        
         | 
        
         | 
        				$commentquery = $func_database->query("
 | 
      
      
        | 55 | 
        
         | 
        
         | 
        					SELECT title, comment
  | 
      
      
        | 56 | 
        
         | 
        
         | 
        					FROM $table
  | 
      
      
        | 57 | 
        
         | 
        
         | 
        					WHERE post_id='{$res['post_id']}'
 | 
      
      
        | 58 | 
        
         | 
        
         | 
        					ORDER BY commented_when ASC
  | 
      
      
        | 59 | 
        
         | 
        
         | 
        				");
  | 
      
      
        | 60 | 
        
         | 
        
         | 
        				if($commentquery->numRows() > 0) {
 | 
      
      
        | 61 | 
        
         | 
        
         | 
        					while($c_res = $commentquery->fetchRow()) {
 | 
      
      
        | 62 | 
        
         | 
        
         | 
        						$text .= $c_res['title'].$divider.$c_res['comment'].$divider;
  | 
      
      
        | 63 | 
        
         | 
        
         | 
        					}
  | 
      
      
        | 64 | 
        
         | 
        
         | 
        				}
  | 
      
      
        | 65 | 
        
         | 
        
         | 
        			}
  | 
      
      
        | 66 | 
        
         | 
        
         | 
        			$mod_vars = array(
  | 
      
      
        | 67 | 
        
         | 
        
         | 
        				'page_link' => $res['link'], // use direct link to news-item
  | 
      
      
        | 68 | 
        
         | 
        
         | 
        				'page_link_target' => "",
  | 
      
      
        | 69 | 
        
         | 
        
         | 
        				'page_title' => $func_page_title,
  | 
      
      
        | 70 | 
        
         | 
        
         | 
        				'page_description' => $res['title'], // use news-title as description
  | 
      
      
        | 71 | 
        
         | 
        
         | 
        				'page_modified_when' => $res['posted_when'],
  | 
      
      
        | 72 | 
        
         | 
        
         | 
        				'page_modified_by' => $res['posted_by'],
  | 
      
      
        | 73 | 
        
         | 
        
         | 
        				'text' => $text,
  | 
      
      
        | 74 | 
        
         | 
        
         | 
        				'max_excerpt_num' => $max_excerpt_num
  | 
      
      
        | 75 | 
        
         | 
        
         | 
        			);
  | 
      
      
        | 76 | 
        
         | 
        
         | 
        			if(print_excerpt2($mod_vars, $func_vars)) {
 | 
      
      
        | 77 | 
        
         | 
        
         | 
        				$result = true;
  | 
      
      
        | 78 | 
        
         | 
        
         | 
        			}
  | 
      
      
        | 79 | 
        
         | 
        
         | 
        		}
  | 
      
      
        | 80 | 
        
         | 
        
         | 
        	}
  | 
      
      
        | 81 | 
        
         | 
        
         | 
        
  | 
      
      
        | 82 | 
        
         | 
        
         | 
        	// now fetch group-titles - ignore those without (active) postings
  | 
      
      
        | 83 | 
        
         | 
        
         | 
        	$table_groups = TABLE_PREFIX."mod_news_groups";
  | 
      
      
        | 84 | 
        
         | 
        
         | 
        	$table_posts = TABLE_PREFIX."mod_news_posts";
  | 
      
      
        | 85 | 
        
         | 
        
         | 
        	$query = $func_database->query("
 | 
      
      
        | 86 | 
        
         | 
        
         | 
        		SELECT DISTINCT g.title, g.group_id
  | 
      
      
        | 87 | 
        
         | 
        
         | 
        		FROM $table_groups AS g INNER JOIN $table_posts AS p ON g.group_id = p.group_id
  | 
      
      
        | 88 | 
        
         | 
        
         | 
        		WHERE g.section_id='$func_section_id' AND g.active = '1' AND p.active = '1'
  | 
      
      
        | 89 | 
        
         | 
        
         | 
        	");
  | 
      
      
        | 90 | 
        
         | 
        
         | 
        	// now call print_excerpt() for every single group, too
  | 
      
      
        | 91 | 
        
         | 
        
         | 
        	if($query->numRows() > 0) {
 | 
      
      
        | 92 | 
        
         | 
        
         | 
        		while($res = $query->fetchRow()) {
 | 
      
      
        | 93 | 
        
         | 
        
         | 
        			$mod_vars = array(
  | 
      
      
        | 94 | 
        
         | 
        
         | 
        				'page_link' => $func_page_link,
  | 
      
      
        | 95 | 
        
         | 
        
         | 
        				'page_link_target' => "&g=".$res['group_id'],
  | 
      
      
        | 96 | 
        
         | 
        
         | 
        				'page_title' => $func_page_title,
  | 
      
      
        | 97 | 
        
         | 
        
         | 
        				'page_description' => $func_page_description,
  | 
      
      
        | 98 | 
        
         | 
        
         | 
        				'page_modified_when' => $func_page_modified_when,
  | 
      
      
        | 99 | 
        
         | 
        
         | 
        				'page_modified_by' => $func_page_modified_by,
  | 
      
      
        | 100 | 
        
         | 
        
         | 
        				'text' => $res['title'].$divider,
  | 
      
      
        | 101 | 
        
         | 
        
         | 
        				'max_excerpt_num' => $max_excerpt_num
  | 
      
      
        | 102 | 
        
         | 
        
         | 
        			);
  | 
      
      
        | 103 | 
        
         | 
        
         | 
        			if(print_excerpt2($mod_vars, $func_vars)) {
 | 
      
      
        | 104 | 
        
         | 
        
         | 
        				$result = true;
  | 
      
      
        | 105 | 
        
         | 
        
         | 
        			}
  | 
      
      
        | 106 | 
        
         | 
        
         | 
        		}
  | 
      
      
        | 107 | 
        
         | 
        
         | 
        	}
  | 
      
      
        | 108 | 
        
         | 
        
         | 
        	return $result;
  | 
      
      
        | 109 | 
        
         | 
        
         | 
        }
  | 
      
      
        | 110 | 
        
         | 
        
         | 
        
  | 
      
      
        | 111 | 
        
         | 
        
         | 
        ?>
  |