Source for file search.class.php

Documentation is available at search.class.php


1 <?php
2 /**
3 * @author Jan H. Andersen <jha@ipwsystems.dk>
4 * @author Martin R. Larsen <mrl@ipwsystems.dk>
5 * @copyright {@link http://www.ipwsystems.dk/ IPW Systems a.s}
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
7 * @package METAjour
8 * @subpackage extension
9 * $Id: search.class.php,v 1.2 2005/01/03 05:31:55 jan Exp $
10 */
11
12 require_once($system_path . "extension/basicextension.class.php");
13 require_once($system_path . "extension/menu/menu.class.php");
14 require_once($system_path . "extension/search/booleantosql.php");
15 require_once($system_path . "extension/search/keywordtosql.php");
16
17 class ext_search extends basicextension {
18
19 function ext_search() {
20 $this->basicextension();
21
22 # define name of class
23 $this->extname = 'search';
24
25 # does this extension have any configuration datatype
26 $this->hasconfigset = true;
27
28 $this->hasoutput = true;
29 $this->hasresult = true;
30 $this->isdocmod = false;
31
32 # add possible extra parameters to execute statement
33 # elements from configset is automatically appended to this list
34 # eg {document.ext.search.none.execute templatename_result="mytemplate"}
35 $this->addextparam('structureid');
36 $this->addextparam('templatename_result');
37 $this->addextparam('templatename_search');
38 $this->addextparam('boolean');
39 }
40
41 function getdefaultconf() {
42 # misc hardcoded variable assignments
43 $this->extconfig['pageid_result'] = $_REQUEST['pageid'];
44 $this->extconfig['boolean'] = $_REQUEST['boolean'];
45 }
46
47 function _do() {
48 # actions in accordance to the supplied $this->extcmd
49
50 if ($this->extconfig['pageid_result'] == 0) $this->extconfig['pageid_result'] = $_REQUEST['pageid'];
51 switch ($this->extcmd) {
52
53 case "search" :
54
55 if (isset($this->extconfig['templatename_result'])) {
56 $this->settemplatebyname($this->extconfig['templatename_result']);
57 } elseif (isset($this->extconfig['templateid_result']) AND ($this->extconfig['templateid_result'] != 0)) {
58 $this->settemplate($this->extconfig['templateid_result']);
59 } else {
60 $this->installtemplate('standard_search_result');
61 $this->settemplatebyname('standard_search_result');
62 }
63
64 $keyword = $_REQUEST['keyword'];
65
66 if (isset($this->extconfig['structureid'])) {
67 $obj = new menu;
68 $obj->execute($this->extconfig['structureid']);
69 $z = 0;
70 $i = 0;
71 $db =& getdbconn();
72 while ($z < sizeof($obj->extresult)) {
73 if ($obj->extresult[$z]['pageid'] != 0) {
74 $res =& $db->query("select object.parentid as parentid, documentsection.content as content, document.name as name from documentsection, object, document where documentsection.content like '%$keyword%' and object.site = $this->site and object.objectid = documentsection.objectid and document.objectid = ".$obj->extresult[$z]['pageid']." and document.objectid = object.parentid and object.deleted = 0 and document.nosearch = 0 group by object.parentid");
75 while($row = $res->fetchrow()) {
76 $content = strip_tags($row['content']);
77 $this->extresult[$i]["url"] = "showpage.php?pageid=".$row['parentid'];
78 $this->extresult[$i]["content"] = $content;
79 $this->extresult[$i]["contentraw"] = $row['content'];
80 $this->extresult[$i]["name"] = $row['name'];
81 $i++;
82 }
83 }
84 $z++;
85 }
86
87 } else {
88 $db =& getdbconn();
89 $langselect = "";
90 if (isset($_SESSION['lang'])) {
91 $langselect = " and object.language = '".$_SESSION['lang']."' ";
92 }
93 if ($this->extconfig['boolean']) {
94 $btosql = new BooleanToSql($keyword);
95 $varnames = array(
96 'documentsection.content',
97 'documentsection.name',
98 'documentsection.subname',
99 'document.name');
100
101 $where = $btosql->getSQL($varnames, "or", "regexp", "[[:<:]]", "[[:>:]]");
102 $query = "select o.childorder as childnum, o.objectid as sectionobjectid, o.parentid as parentid, " .
103 "documentsection.content as content, documentsection.name as sectionname, ".
104 "documentsection.subname as subname, document.name as name " .
105 "from documentsection, document, object o, object p " .
106 "where (" . $where . ") and " .
107 "o.site = " . $this->site . " and " .
108 "o.objectid = documentsection.objectid and " .
109 "p.objectid = o.parentid and " .
110 "document.objectid = p.objectid and " .
111 "document.nosearch = 0 and " .
112 "p.deleted = 0 " .
113 $langselect .
114 "group by o.parentid";
115 } else {
116 $query = "select o.childorder as childnum, o.objectid as sectionobjectid, o.parentid as parentid, documentsection.content as content,
117 documentsection.name as sectionname, documentsection.subname as subname, document.name as name, p.changed as changed, u.name as createdbyname
118 from
119 documentsection, document, object o, object p, user u
120 where
121 (documentsection.content like '%$keyword%' or
122 documentsection.name like '%$keyword%' or
123 documentsection.subname like '%$keyword%' or
124 document.name like '%$keyword%' ) and
125 o.site = $this->site and
126 o.objectid = documentsection.objectid and
127 p.objectid = o.parentid and
128 document.objectid = p.objectid and
129 document.nosearch = 0 and
130 p.deleted = 0 and
131 p.createdby = u.objectid
132 $langselect
133 group by o.parentid";
134 }
135 $res =& $db->query($query);
136
137 $i = 0;
138 if ($res !== false) {
139 while($row = $res->fetchrow()) {
140 $content = strip_tags($row['content']);
141 $this->extresult[$i]["pageid"] = $row['parentid'];
142 $this->extresult[$i]["url"] = "showpage.php?pageid=".$row['parentid'];
143 $this->extresult[$i]["content"] = $content;
144 $this->extresult[$i]["contentraw"] = $row['content'];
145 $this->extresult[$i]["name"] = $row['name'];
146 $this->extresult[$i]["sectionname"] = $row['sectionname'];
147 $this->extresult[$i]["sectionsubname"] = $row['sectionsubname'];
148 $this->extresult[$i]["sectionobjectid"] = $row['sectionobjectid'];
149 $this->extresult[$i]["changed"] = $row['changed'];
150 $this->extresult[$i]["createdbyname"] = $row['createdbyname'];
151 $d = new documentsection;
152 ## owGet("documentsection",$d);
153 $d->readobject($row['sectionobjectid']);
154 $this->extresult[$i]["sectionnum"] = $d->getfamilybefore($row['childnum']);
155 $i++;
156 }
157 }
158 }
159 break;
160
161 default:
162 # set the next possible command if applicable
163 $this->next_extcmd = "search";
164
165 # try to get the search template by name if set via the
166 # configuration datatype or via the execute-statement
167 if (isset($this->extconfig['templatename_search'])) {
168 $this->settemplatebyname($this->extconfig['templatename_search']);
169 # or try to get the search template by objectid if set
170 # via the configuration datatype or via the execute-statement
171 } elseif (isset($this->extconfig['templateid_search']) AND ($this->extconfig['templateid_search'] != 0)) {
172 $this->settemplate($this->extconfig['templateid_search']);
173 # or install the template from the standard directory
174 } else {
175 $this->installtemplate('standard_search_dialog');
176 $this->settemplatebyname('standard_search_dialog');
177 }
178 }
179 }
180 }
181 ?>

Documentation generated on Thu, 9 Jun 2005 06:53:02 +0200 by phpDocumentor 1.2.3