gforge-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gforge-commits] gforge/www/search/include RssSearchRenderer.class, NONE


From: gsmet
Subject: [Gforge-commits] gforge/www/search/include RssSearchRenderer.class, NONE, 1.1 ProjectHtmlSearchRenderer.class, NONE, 1.1 SearchRenderer.class, NONE, 1.1 SkillHtmlSearchRenderer.class, NONE, 1.1 ForumHtmlSearchRenderer.class, NONE, 1.1 ArtifactHtmlSearchRenderer.class, NONE, 1.1 HtmlSearchRenderer.class, NONE, 1.1 PeopleHtmlSearchRenderer.class, NONE, 1.1 ProjectRssSearchRenderer.class, NONE, 1.1
Date: Mon, 09 Feb 2004 04:22:25 -0600

Update of /cvsroot/gforge/gforge/www/search/include
In directory db.perdue.net:/tmp/cvs-serv17528/www/search/include

Added Files:
        RssSearchRenderer.class ProjectHtmlSearchRenderer.class 
        SearchRenderer.class SkillHtmlSearchRenderer.class 
        ForumHtmlSearchRenderer.class ArtifactHtmlSearchRenderer.class 
        HtmlSearchRenderer.class PeopleHtmlSearchRenderer.class 
        ProjectRssSearchRenderer.class 
Log Message:
implemented a new search engine architecture

--- NEW FILE: RssSearchRenderer.class ---
<?php

/**
 * GForge Search Engine
 *
 * Portions Copyright 1999-2001 (c) VA Linux Systems
 * The rest Copyright 2004 (c) Guillaume Smet / Open Wide
 *
 * http://gforge.org
 *
 * @version $Id: RssSearchRenderer.class,v 1.1 2004/02/09 10:22:19 gsmet Exp $
 */

require_once('www/search/include/SearchRenderer.class');

class RssSearchRenderer extends SearchRenderer {
        
        /**
         * callback function name used during the RSS export
         *
         * @var string $callbackFunction
         */
        var $callbackFunction = '';

        /**
         * Constructor
         *
         * @param string $typeOfSearch type of the search (Software, Forum, 
People and so on)
         * @param string $words words we are searching for
         * @param int $offset offset
         * @param boolean $isExact if we want to search for all the words or if 
only one matching the query is sufficient
         * @param object $searchQuery SearchQuery instance
         */
        function RssSearchRenderer($typeOfSearch, $words, $isExact, 
$searchQuery) {
                $this->SearchRenderer($typeOfSearch, $words, $isExact, 
$searchQuery);
        }

        /**
         * flush - flush the RSS output
         */
        function flush() {
                $searchQuery =& $this->searchQuery;

                header('Content-Type: text/plain');
                
                if($searchQuery->isError() || $this->isError()) {
                        echo '<channel></channel>';
                } else {                
                        $searchQuery->executeQuery();
                        include_once('www/export/rss_utils.inc');
        
                        rss_dump_project_result_set(
                                $searchQuery->getResult(),
                                'GForge Search Results',
                                'GForge Search Results for 
"'.$this->query['words'].'"',
                                $this->callbackFunction
                        );
                }
                exit();
        }

}

?>
--- NEW FILE: ProjectHtmlSearchRenderer.class ---
<?php

/**
 * GForge Search Engine
 *
 * Portions Copyright 1999-2001 (c) VA Linux Systems
 * The rest Copyright 2004 (c) Guillaume Smet / Open Wide
 *
 * http://gforge.org
 *
 * @version $Id: ProjectHtmlSearchRenderer.class,v 1.1 2004/02/09 10:22:19 
gsmet Exp $
 */

require_once('www/search/include/HtmlSearchRenderer.class');
require_once('common/search/ProjectSearchQuery.class');

class ProjectHtmlSearchRenderer extends HtmlSearchRenderer {

        /**
         * Constructor
         *
         * @param string $words words we are searching for
         * @param int $offset offset
         * @param boolean $isExact if we want to search for all the words or if 
only one matching the query is sufficient
         */
        function ProjectHtmlSearchRenderer($words, $offset, $isExact) {
                
                $searchQuery = new ProjectSearchQuery($words, $offset, 
$isExact);
                
                $this->HtmlSearchRenderer(SEARCH__TYPE_IS_SOFTWARE, $words, 
$isExact, $searchQuery);
                
                $this->tableHeaders = array(
                        $this->Language->getText('search', 'group_name'),
                        $this->Language->getText('search', 'group_description')
                );
        }

        /**
         * writeHeader - write the header of the output
         */
        function writeHeader() {
                
$GLOBALS['HTML']->header(array('title'=>$this->Language->getText('search', 
'title'), 'pagename'=>'search'));
                parent::writeHeader();
        }

        /**
         * getRows - get the html output for result rows
         *
         * @return string html output
         */
        function getRows() {
                $rowsCount = $this->searchQuery->getRowsCount();
                $result =& $this->searchQuery->getResult();
                
                $return = '';
                
                for($i = 0; $i < $rowsCount; $i++) {
                        if (db_result($result, $i, 'type') == 2) {
                                $what = 'foundry';
                        } else {
                                $what = 'projects';
                        }               
                        $return .= '<tr 
'.$GLOBALS['HTML']->boxGetAltRowStyle($i).'>'
                                .'<td width="30%"><a href="/'.$what.'/'
                                .db_result($result, $i, 'unix_group_name').'/">'
                                .html_image('ic/msg.png', '10', '12', 
array('border'=>'0'))
                                .' 
'.$this->highlightTargetWords(db_result($result, $i, 'group_name')).'</a></td>'
                                .'<td 
width="70%">'.$this->highlightTargetWords(db_result($result, $i, 
'short_description')).'</td></tr>';
                }
                
                return $return;
        }

        /**
         * redirectToResult - redirect the user  directly to the result when 
there is only one matching result
         */
        function redirectToResult() {
                header('Location: /'.($this->getResultId('type') == 2 ? 
'foundry' : 'projects').'/'.$this->getResultId('unix_group_name').'/');
                exit();
        }
        
}

?>
--- NEW FILE: SearchRenderer.class ---
<?php

class SearchRenderer extends Error {
        
        /**
         * This is not the SQL query but elements from the HTTP query
         *
         * @var array $query
         */
        var $query = array();

        /**
         * This is the searchQuery. It's a SearchQuery instance.
         *
         * @var object $searchQuery
         */
        var $searchQuery;

        /**
         * Constructor
         *
         * @param string $typeOfSearch type of search
         * @param string $words words we are searching for
         * @param int $offset offset
         * @param boolean $isExact if we want to search for all the words or if 
only one matching the query is sufficient
         */
        function SearchRenderer($typeOfSearch, $words, $isExact, $searchQuery) {
                $this->query['typeOfSearch'] = $typeOfSearch;
                $this->query['isExact'] = $isExact;
                $this->query['words'] = $words;
                
                $this->searchQuery = $searchQuery;
        }

        /**
         * flush - flush the output
         * This is an abstract method. It _MUST_ be implemented in children 
classes.
         */
        function flush() {}
        
}

?>
--- NEW FILE: SkillHtmlSearchRenderer.class ---
<?php

/**
 * GForge Search Engine
 *
 * Portions Copyright 1999-2001 (c) VA Linux Systems
 * The rest Copyright 2004 (c) Guillaume Smet / Open Wide
 *
 * http://gforge.org
 *
 * @version $Id: SkillHtmlSearchRenderer.class,v 1.1 2004/02/09 10:22:19 gsmet 
Exp $
 */

require_once('www/search/include/HtmlSearchRenderer.class');
require_once('common/search/SkillSearchQuery.class');

class SkillHtmlSearchRenderer extends HtmlSearchRenderer {

        /**
         * Constructor
         *
         * @param string $words words we are searching for
         * @param int $offset offset
         * @param boolean $isExact if we want to search for all the words or if 
only one matching the query is sufficient
         */
        function SkillHtmlSearchRenderer($words, $offset, $isExact) {
                
                $searchQuery = new SkillSearchQuery($words, $offset, $isExact);
                
                $this->HtmlSearchRenderer(SEARCH__TYPE_IS_SKILL, $words, 
$isExact, $searchQuery);
                
                $this->tableHeaders = array(
                        $this->Language->getText('search', 'skill_name'),
                        $this->Language->getText('search', 'skill_type'),
                        $this->Language->getText('search', 'skill_title'),
                        $this->Language->getText('search', 'skill_keywords'),
                        $this->Language->getText('search', 'skill_from'),
                        $this->Language->getText('search', 'skill_to')
                );
        }

        /**
         * writeHeader - write the header of the output
         */
        function writeHeader() {
                
$GLOBALS['HTML']->header(array('title'=>$this->Language->getText('search', 
'title'), 'pagename'=>'search'));
                parent::writeHeader();
        }
        
        /**
         * getRows - get the html output for result rows
         *
         * @return string html output
         */
        function getRows() {
                $rowsCount = $this->searchQuery->getRowsCount();
                $result =& $this->searchQuery->getResult();
                
                $monthArray = array();
                for($i = 1; $i <= 12; $i++) {
                        array_push($monthArray,date('M', mktime(0, 0, 0, $i, 
10, 1980)));
                }
                
                $return = '';
                
                for($i = 0; $i < $rowsCount; $i++) {
                        $start = db_result($result, $i, 'start');
                        $startYear = substr($start, 0, 4);
                        $startMonth = substr($start, 4, 2);

                        $finish = db_result($result, $i, 'finish');
                        $finishYear = substr($finish, 0, 4);
                        $finishMonth = substr($finish, 4, 2);
                                
                        $return .= '<tr 
'.$GLOBALS['HTML']->boxGetAltRowStyle($i).'>'
                                . '<td><a href="/users/'.db_result($result, $i, 
'user_name').'/">'
                                . db_result($result, $i, 'realname').'</a></td>'
                                . '<td>'.db_result($result, $i, 
'type_name').'</td>'
                                . '<td>'.db_result($result, $i, 'title').'</td>'
                                . '<td>'.db_result($result, $i, 
'keywords').'</td>'
                                . '<td>'.$monthArray[$startMonth - 1].' 
'.$startYear.'</td>'
                                . '<td>'.$monthArray[$finishMonth - 1].' 
'.$finishYear.'</td>'
                                . '<tr>';
                }
                
                return $return;
        }
        
        /**
         * redirectToResult - redirect the user  directly to the result when 
there is only one matching result
         */
        function redirectToResult() {
                header('Location: /users/'.$this->getResultId('user_name').'/');
                exit();
        }
}

?>
--- NEW FILE: ForumHtmlSearchRenderer.class ---
<?php

/**
 * GForge Search Engine
 *
 * Portions Copyright 1999-2001 (c) VA Linux Systems
 * The rest Copyright 2004 (c) Guillaume Smet / Open Wide
 *
 * http://gforge.org
 *
 * @version $Id: ForumHtmlSearchRenderer.class,v 1.1 2004/02/09 10:22:19 gsmet 
Exp $
 */

require_once('www/search/include/HtmlSearchRenderer.class');
require_once('common/search/ForumSearchQuery.class');

class ForumHtmlSearchRenderer extends HtmlSearchRenderer {
        
        /**
         * group id
         *
         * @var int $groupId
         */
        var $groupId;
        
        /**
         * forum id
         *
         * @var int $groupId
         */
        var $forumId;
        
        /**
         * Constructor
         *
         * @param string $words words we are searching for
         * @param int $offset offset
         * @param boolean $isExact if we want to search for all the words or if 
only one matching the query is sufficient
         * @param int $groupId group id
         * @param int $forumId forum id
         */
        function ForumHtmlSearchRenderer($words, $offset, $isExact, $groupId, 
$forumId) {
                $this->groupId = $groupId;
                $this->forumId = $forumId;
                
                $searchQuery = new ForumSearchQuery($words, $offset, $isExact, 
$groupId, $forumId);
                
                $this->HtmlSearchRenderer(SEARCH__TYPE_IS_FORUM, $words, 
$isExact, $searchQuery);
                
                $this->tableHeaders = array(
                        $this->Language->getText('search', 'forum_thread'),
                        $this->Language->getText('search', 'forum_author'),
                        $this->Language->getText('search', 'forum_date')
                );
        }

        /**
         * writeHeader - write the header of the output
         */
        function writeHeader() {
                site_project_header(array('title' => 
$this->Language->getText('search', 'project_search'), 'group' => 
$this->groupId, 'pagename' => 'search', 'toptab' => 'forums'));
                parent::writeHeader();
        }
        
        /**
         * getRows - get the html output for result rows
         *
         * @return string html output
         */
        function getRows() {
                $rowsCount = $this->searchQuery->getRowsCount();
                $result =& $this->searchQuery->getResult();
                $dateFormat = $GLOBALS['sys_datefmt'];
                
                $return = '';
                for($i = 0; $i < $rowsCount; $i++) {
                        $return .= '<tr '. 
$GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td width="50%"><a 
href="/forum/message.php?msg_id='
                                . db_result($result, $i, 'msg_id').'">'
                                . html_image('ic/msg.png', '10', '12', 
array('border' => '0'))
                                . ' '.db_result($result, $i, 
'subject').'</a></td>'
                                . '<td width="30%">'.db_result($result, $i, 
'realname').'</td>'
                                . '<td width="20%">'.date($dateFormat, 
db_result($result, $i, 'post_date')).'</td></tr>';
                }
                return $return;
        }

        /**
         * getPreviousResultsUrl - get the url to go to see the previous results
         *
         * @return string url to previous results page
         */
        function getPreviousResultsUrl() {
                return 
parent::getPreviousResultsUrl().'&amp;group_id='.$this->groupId.'&amp;forum_id='.$this->forumId;
        }
        
        /**
         * getNextResultsUrl - get the url to go to see the next results
         *
         * @return string url to next results page
         */
        function getNextResultsUrl() {
                return 
parent::getNextResultsUrl().'&amp;group_id='.$this->groupId.'&amp;forum_id='.$this->forumId;
        }

        /**
         * redirectToResult - redirect the user  directly to the result when 
there is only one matching result
         */
        function redirectToResult() {
                header('Location: 
/forum/message.php?msg_id='.$this->getResultId('msg_id'));
                exit();
        }
}

?>
--- NEW FILE: ArtifactHtmlSearchRenderer.class ---
<?php

/**
 * GForge Search Engine
 *
 * Portions Copyright 1999-2001 (c) VA Linux Systems
 * The rest Copyright 2004 (c) Guillaume Smet / Open Wide
 *
 * http://gforge.org
 *
 * @version $Id: ArtifactHtmlSearchRenderer.class,v 1.1 2004/02/09 10:22:19 
gsmet Exp $
 */

require_once('www/search/include/HtmlSearchRenderer.class');
require_once('common/search/ArtifactSearchQuery.class');

class ArtifactHtmlSearchRenderer extends HtmlSearchRenderer {
        
        /**
         * group id
         *
         * @var int $groupId
         */
        var $groupId;
        
        /**
         * artifact id
         *
         * @var int $artifactId
         */
        var $artifactId;
        
        /**
         * Constructor
         *
         * @param string $words words we are searching for
         * @param int $offset offset
         * @param boolean $isExact if we want to search for all the words or if 
only one matching the query is sufficient
         * @param int $groupId group id
         * @param int $artifactId artifact id
         */
        function ArtifactHtmlSearchRenderer($words, $offset, $isExact, 
$groupId, $artifactId) {
                $this->groupId = $groupId;
                $this->artifactId = $artifactId;
                
                $searchQuery = new ArtifactSearchQuery($words, $offset, 
$isExact, $groupId, $artifactId);
                
                $this->HtmlSearchRenderer(SEARCH__TYPE_IS_ARTIFACT, $words, 
$isExact, $searchQuery);
                
                $this->tableHeaders = array(
                        $this->Language->getText('search', 'artifact_id'),
                        $this->Language->getText('search', 'artifact_summary'),
                        $this->Language->getText('search', 'artifact_author'),
                        $this->Language->getText('search', 'artifact_date')
                );
        }

        /**
         * writeHeader - write the header of the output
         * artifact search has a specific header
         */
        function writeHeader() {
                site_project_header(array('title' => 
$this->Language->getText('search', 'project_search'), 'group' => 
$this->groupId, 'pagename' => 'search', 'toptab' => 'tracker'));
                parent::writeHeader();
        }
        
        /**
         * getRows - get the html output for result rows
         *
         * @return string html output
         */
        function getRows() {
                $rowsCount = $this->searchQuery->getRowsCount();
                $result =& $this->searchQuery->getResult();
                $groupId = $this->groupId;
                $dateFormat = $GLOBALS['sys_datefmt'];
                
                $return = '';
                for($i = 0; $i < $rowsCount; $i++) {
                        $return .= '<tr '. 
$GLOBALS['HTML']->boxGetAltRowStyle($i) .'>'
                                .'<td>'.db_result($result, $i, 
'artifact_id').'</td>'
                                .'<td><a 
href="/tracker/?group_id='.$groupId.'&amp;atid='
                                . db_result($result, $i, 'group_artifact_id') 
                                . '&amp;func=detail&aid='
                                . db_result($result, $i, 'artifact_id').'"> '
                                . html_image('ic/msg.png', '10', '12', 
array('border'=>'0'))
                                . ' '.db_result($result, $i, 
'summary').'</a></td>'
                                . '<td>'.db_result($result, $i, 
'realname')."</td>"
                                . '<td>'.date($dateFormat, db_result($result, 
$i, 'open_date')).'</td></tr>';
                }
                return $return;
        }
        
        /**
         * getPreviousResultsUrl - get the url to go to see the previous results
         *
         * @return string url to previous results page
         */
        function getPreviousResultsUrl() {
                return 
parent::getPreviousResultsUrl().'&amp;group_id='.$this->groupId.'&amp;atid='.$this->artifactId;
        }
        
        /**
         * getNextResultsUrl - get the url to go to see the next results
         *
         * @return string url to next results page
         */
        function getNextResultsUrl() {
                return 
parent::getNextResultsUrl().'&amp;group_id='.$this->groupId.'&amp;atid='.$this->artifactId;
        }
        
        /**
         * redirectToResult - redirect the user  directly to the result when 
there is only one matching result
         */
        function redirectToResult() {
                header('Location: 
/tracker/?group_id='.$this->groupId.'&atid='.$this->artifactId.'&func=detail&aid='.$this->getResultId('artifact_id'));
                exit();
        }
        
}

?>
--- NEW FILE: HtmlSearchRenderer.class ---
<?php

/**
 * GForge Search Engine
 *
 * Portions Copyright 1999-2001 (c) VA Linux Systems
 * The rest Copyright 2004 (c) Guillaume Smet / Open Wide
 *
 * http://gforge.org
 *
 * @version $Id: HtmlSearchRenderer.class,v 1.1 2004/02/09 10:22:19 gsmet Exp $
 */

require_once('www/search/include/SearchRenderer.class');

class HtmlSearchRenderer extends SearchRenderer {

        /**
         * Localization BaseLanguage object
         *
         * @var object $Language
         */
        var $Language;
        
        /**
         * Headers of the HTML results table
         *
         * @var array $tableHeaders
         */
        var $tableHeaders = array();

        /**
         * Constructor
         *
         * @param string $typeOfSearch type of the search (Software, Forum, 
People and so on)
         * @param string $words words we are searching for
         * @param int $offset offset
         * @param boolean $isExact if we want to search for all the words or if 
only one matching the query is sufficient
         * @param object $searchQuery SearchQuery instance
         */
        function HtmlSearchRenderer($typeOfSearch, $words, $isExact, 
$searchQuery) {
                global $Language;
                $this->Language =& $GLOBALS['Language'];
                
                $this->SearchRenderer($typeOfSearch, $words, $isExact, 
$searchQuery);
        }

        /**
         * flush - flush the html output
         */
        function flush() {
                $searchQuery =& $this->searchQuery;
                if($searchQuery->isError()) {
                        $this->writeHeader();
                        echo '<h2>'.$this->Language->getText('search', 
$searchQuery->getErrorMessage()).'</h2>';
                        $this->writeFooter();
                } else {
                        $searchQuery->executeQuery();
                        if($searchQuery->getResult() && 
($searchQuery->getRowsTotalCount() == 1 && $searchQuery->getOffset() == 0) && 
$this->implementsRedirectToResult()) {
                                $this->redirectToResult();
                        } else {
                                $this->writeHeader();
                                $this->writeBody();
                                $this->writeFooter();
                        }
                }
        }

        /**
         * writeHeader - write the header of the output
         */
        function writeHeader() {
                echo '<div align="center">';
                echo $GLOBALS['HTML']->searchBox();
                echo '</div>';
        }

        /**
         * writeBody - write the body
         */
        function writeBody() {
                echo $this->writeResults();
        }

        /**
         * writeFooter - write the footer
         */
        function writeFooter() {
                $GLOBALS['HTML']->footer(array());
        }
        
        /**
         * getResults - get the html output which will display the search 
results
         *
         * @return string html output
         */
        function writeResults() {
                $searchQuery =& $this->searchQuery;
                $query =& $this->query;
                
                $html = '';
                
                if(!$searchQuery->getResult() || $searchQuery->getRowsCount() < 
1) {
                        $html .= '<h2>'.$this->Language->getText('search', 
'no_matches_found', array(htmlspecialchars($query['words']))).'</h2>';
                        $html .= db_error();
                } else {
                        $html .= '<h3>'.$this->Language->getText('search', 
'search_results', array(htmlspecialchars($query['words']))).'</h3>';
                
                        $html .= 
$GLOBALS['HTML']->listTableTop($this->tableHeaders);
                        $html .= $this->getRows();
                        $html .= $GLOBALS['HTML']->listTableBottom();
                }
                
                if($searchQuery->getRowsCount() > 0 && 
($searchQuery->getRowsTotalCount() > $searchQuery->getRowsCount() || 
$searchQuery->getOffset() != 0 )) {
                        $html .= $this->getNavigationPanel();
                }
                
                return $html;
        }

        /**
         * getNavigationPanel - get the html output for the navigation panel
         *
         * @return string html output
         */ 
        function getNavigationPanel() {
                $searchQuery =& $this->searchQuery;
                
                $html = '';
                $html .= '<br />';
                $html .= '<table 
style="background-color:'.$GLOBALS['HTML']->COLOR_LTBACK1.'" width="100%" 
cellpadding="5" cellspacing="0">';
                $html .= '<tr>';
                $html .= '<td>';
                if ($searchQuery->getOffset() != 0) {
                        $html .= '<a href="'.$this->getPreviousResultsUrl().'" 
style="text-decoration: none; font-weight:bold;">'
                                . html_image('t2.png', '15', '15', 
array('border'=>'0','align'=>'middle'))
                                . ' '.$this->Language->getText('search', 
'previous_results').'</a>';
                } else {
                        $html .= '&nbsp;';
                }
                $html .= '</td><td align="right">';
                if ($searchQuery->getRowsTotalCount() > 
$searchQuery->getRowsCount()) {
                        $html .= '<a href="'.$this->getNextResultsUrl().'" 
style="text-decoration: none; font-weight:bold;">'
                                .$this->Language->getText('search', 
'next_results').' '
                                . html_image('t.png', '15', '15', 
array('border'=>'0','align'=>'middle')) . '</a>';
                } else {
                        $html .= '&nbsp;';
                }
                $html .= '</td></tr>';
                $html .= '</table>';
                return $html;
        }
        
        /**
         * getPreviousResultsUrl - get the url to go to see the previous results
         *
         * @return string url to previous results page
         */
        function getPreviousResultsUrl() {
                $offset = $this->searchQuery->getOffset() - 
$this->searchQuery->getRowsPerPage();
                $query =& $this->query;
                
                $url = 
'/search/?type='.$query['typeOfSearch'].'&amp;exact='.$query['isExact'].'&amp;q='.urlencode($query['words']);
                if($offset > 0) {
                        $url .= '&amp;offset='.$offset;
                }
                return $url;
        }
        
        /**
         * getNextResultsUrl - get the url to go to see the next results
         *
         * @return string url to next results page
         */
        function getNextResultsUrl() {
                $query =& $this->query;
                return 
'/search/?type='.$query['typeOfSearch'].'&amp;exact='.$query['isExact'].'&amp;q='.urlencode($query['words']).'&amp;offset='.($this->searchQuery->getOffset()
 + $this->searchQuery->getRowsPerPage());
        }

        /**
         * highlightTargetWords - highlight the words we are looking for
         *
         * @param string $text text
         * @return string text with keywords highlighted
         */
        function highlightTargetWords($text) {
                if (empty($text)) {
                        return '&nbsp;';
                }
                $regexp = implode($this->searchQuery->getWords(), '|');
                return preg_replace('/('.str_replace('/', '\/', 
$regexp).')/i','<span style="background-color:pink">\1</span>', $text);
        }

        /**
         * implementsRedirectToResult - check if the current object implements 
the redirect to result feature by having a redirectToResult method
         *
         * @return boolean true if our object implements search by id, false 
otherwise.
         */
        function implementsRedirectToResult() {
                return method_exists($this, 'redirectToResult');
        }

        /**
         * getResultId - get the field value for the first row of a result 
handle
         *
         * @param string $fieldName field name
         * @return string value of the field
         */
        function getResultId($fieldName) {
                return db_result($this->searchQuery->getResult(), 0, 
$fieldName);
        }

}

?>
--- NEW FILE: PeopleHtmlSearchRenderer.class ---
<?php

/**
 * GForge Search Engine
 *
 * Portions Copyright 1999-2001 (c) VA Linux Systems
 * The rest Copyright 2004 (c) Guillaume Smet / Open Wide
 *
 * http://gforge.org
 *
 * @version $Id: PeopleHtmlSearchRenderer.class,v 1.1 2004/02/09 10:22:19 gsmet 
Exp $
 */

require_once('www/search/include/HtmlSearchRenderer.class');
require_once('common/search/PeopleSearchQuery.class');

class PeopleHtmlSearchRenderer extends HtmlSearchRenderer {

        /**
         * Constructor
         *
         * @param string $words words we are searching for
         * @param int $offset offset
         * @param boolean $isExact if we want to search for all the words or if 
only one matching the query is sufficient
         */
        function PeopleHtmlSearchRenderer($words, $offset, $isExact) {
                
                $searchQuery = new PeopleSearchQuery($words, $offset, $isExact);
                
                $this->HtmlSearchRenderer(SEARCH__TYPE_IS_PEOPLE, $words, 
$isExact, $searchQuery);
                
                $this->tableHeaders = array(
                        $this->Language->getText('search', 'people_user_name'),
                        $this->Language->getText('search', 'people_real_name')
                );
        }

        /**
         * writeHeader - write the header of the output
         */
        function writeHeader() {
                
$GLOBALS['HTML']->header(array('title'=>$this->Language->getText('search', 
'title'), 'pagename'=>'search'));
                parent::writeHeader();
        }
        
        /**
         * getRows - get the html output for result rows
         *
         * @return string html output
         */
        function getRows() {
                $rowsCount = $this->searchQuery->getRowsCount();
                $result =& $this->searchQuery->getResult();
                
                $return = '';
                for($i = 0; $i < $rowsCount; $i++) {
                        $return .= '<tr '. 
$GLOBALS['HTML']->boxGetAltRowStyle($i) .'>'.
                                '<td width="40%"><a 
href="/users/'.db_result($result, $i, 
'user_name').'/">'.html_image('ic/msg.png', '10', '12', array('border'=>'0')).' 
'.db_result($result, $i, 'user_name').'</a></td>'.
                                '<td width="60%">'.db_result($result, $i, 
'realname').'</td>'.
                                '</tr>';
                }
                return $return;
        }
        
        /**
         * redirectToResult - redirect the user  directly to the result when 
there is only one matching result
         */
        function redirectToResult() {
                header('Location: /users/'.$this->getResultId('user_name').'/');
                exit();
        }
}

?>
--- NEW FILE: ProjectRssSearchRenderer.class ---
<?php

/**
 * GForge Search Engine
 *
 * Portions Copyright 1999-2001 (c) VA Linux Systems
 * The rest Copyright 2004 (c) Guillaume Smet / Open Wide
 *
 * http://gforge.org
 *
 * @version $Id: ProjectRssSearchRenderer.class,v 1.1 2004/02/09 10:22:19 gsmet 
Exp $
 */

require_once('www/search/include/RssSearchRenderer.class');
require_once('common/search/ExportProjectSearchQuery.class');

/**
 * callback function used during the RSS export
 *
 * @param array $dataRow array containing data for the current row
 * @return string additionnal information added in the RSS document
 */
function rssProjectCallback($dataRow) {
        // $default_trove_cat defined in local.inc
        $result = db_query('SELECT trove_cat.fullpath '
                .'FROM trove_group_link, trove_cat '
                .'WHERE 
trove_group_link.trove_cat_root='.$GLOBALS['default_trove_cat'].' '
                .'AND trove_group_link.trove_cat_id=trove_cat.trove_cat_id '
                .'AND group_id=\''.$dataRow['group_id'].'\'');
        
        $return = '';
        $return .= ' | date registered: '.date('M jS Y', 
$dataRow['register_time']);
        $return .= ' | category: '.str_replace(' ', '', implode(',', 
util_result_column_to_array($result)));
        $return .= ' | license: '.$dataRow['license'];
        
        return $return;
}

class ProjectRssSearchRenderer extends RssSearchRenderer {

        /**
         * Constructor
         *
         * @param string $words words we are searching for
         * @param int $offset offset
         * @param boolean $isExact if we want to search for all the words or if 
only one matching the query is sufficient
         */
        function ProjectRssSearchRenderer($words, $offset, $isExact) {
                
                $this->callbackFunction = 'rssProjectCallback';
                
                $searchQuery = new ExportProjectSearchQuery($words, $offset, 
$isExact);
                
                $this->RssSearchRenderer(SEARCH__TYPE_IS_SOFTWARE, $words, 
$isExact, $searchQuery);
        }
}

?>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]