"Fossies" - the Fresh Open Source Software Archive 
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the latest
Fossies "Diffs" side-by-side code changes report for "lib_search.php3":
1.2.0_vs_1.2.1.
1 <?
2 #----------------------------------------------------------------->
3 # $Id: lib_search.php3,v 1.34 2016/06/26 09:20:51 ldrolez Exp $
4 #
5 # Website: http://mythreads.sourceforge.net
6 #
7 # Desc: lib_search.php3. all the search functions......
8 #
9 #
10 # License: This code is released under the terms of the GNU GPL
11 # version 2 or later. Please refer to www.gnu.org for a copy
12 # of this license.
13 #
14 #----------------------------------------------------------------->
15
16
17 ###########################
18 # Search Functions Follow #
19 ###########################
20
21 # Show Next Previous Page
22 function Search_showNext($search,$view_stop,$view_start,$nomore)
23 {
24 global $start_script, $start_script_t, $config, $most, $tpl;
25
26 $view_prev = $view_start - $config["max_displayed_links"];
27
28 if ($view_prev <= 0 ) { $view_prev = 0; }
29
30 if ($view_start >= 1) {
31 $tpl->set_var("PREV_LINK", $start_script_t."mode=search&search=$search&view=$view_prev");
32 } else {
33 # remove the prev button
34 $tpl->set_block("prevnext", "previous_page", "deleteme");
35 }
36
37 if (! $nomore ) {
38 $tpl->set_var("NEXT_LINK", $start_script_t."mode=search&search=$search&view=$view_stop");
39 } else {
40 # remove the next button
41 $tpl->set_block("prevnext", "next_page", "deleteme");
42 }
43 $tpl->set_var("deleteme" , "");
44
45 $content = $tpl->subst("prevnext");
46 return $content;
47 }
48
49 # search function
50 function Search($search,$view)
51 {
52 global $tpl;
53 global $config, $nomore, $view_start, $start_script, $start_script_t, $update_link;
54 global $custom, $buttons, $mylink;
55
56 $enc_search = urlencode("$search");
57 $search = htmlspecialchars("$search");
58
59 # find which fields to search : text fields
60 $fields = array( "title", "message" );
61 while(list($f,$type) = each($custom)) {
62 if ($type == "text") {
63 $fields[] = $f;
64 }
65 }
66
67 $sqlcommand = "WHERE (";
68 $howmany_fields = count($fields);
69 while(list(,$field) = each($fields))
70 {
71 $split_search = explode(" and ", $search);
72 $howmany = count($split_search);
73
74 $search_title = "";
75 while(list($key,$data)=each($split_search))
76 {
77 $data = trim($data);
78 $howmany--;
79 if (strlen($data) >= 2) {
80 $search_title .="lower($field) LIKE '%$data%' ";
81 if ($howmany != 0) {
82 $search_title .="AND ";
83 }
84 } else {
85 die ( Message("no_valid_search_term_and") );
86 }
87 }
88
89 $sqlcommand .= "($search_title)";
90 $howmany_fields--;
91 if ($howmany_fields != 0) {
92 $sqlcommand .= " OR ";
93 }
94 }
95 $sqlcommand .= ") AND status=0";
96
97 # $view hold the from for LIMIT. Must not be 0
98 if (! isset($view)){ $view='0';}
99
100 $view_start = $view;
101 $view_stop = $view + $config["max_displayed_links"];
102
103 #########
104 # count how many and not go over the max...
105 $af = mysqli_query($mylink, "SELECT COUNT(*) FROM ".$config["pre"]."links $sqlcommand") or die (mysqli_error($mylink));
106 $howmany = mysqli_fetch_array($af) or die (mysqli_error($mylink));
107 $total_links = $howmany[0];
108 if ($howmany[0] <= $view_stop)
109 {
110 $view_stop = $howmany[0];
111 $nomore=1;
112 }
113
114 $cat_links = Message ("total_links_found",
115 array ( "TOTAL" => "$total_links"));
116
117 $link_prev_next = Search_showNext($enc_search,$view_stop,$view_start,$nomore);
118
119 $cat_links .= $link_prev_next;
120
121 $result = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."links $sqlcommand order by title LIMIT $view_start,".$config["max_displayed_links"]) or die (mysqli_error($mylink));
122
123 if (mysqli_num_rows($result))
124 {
125 $tpl->set_var("link_rows", "");
126 while ($list = mysqli_fetch_array($result) )
127 {
128 # limit the "message" field
129 if (strlen($list["message"]) > $config["limit_message_length"]) {
130 $list["message"] = substr($list["message"], 0,
131 $config["limit_message_length"]). "...";
132 }
133 $idx = $list["idx"];
134 $tpl->set_var( array(
135 "LINK_TITLE" => $list["title"],
136 "LINK_MESSAGE" => $list["message"],
137 "LINK_ADDED" => $list["date"],
138 "LINK_HITS" => $list["hits"],
139 "LINK_GO" => $start_script_t."count=$idx",
140 "LINK_MORE" => $start_script_t."more=$idx",
141 "LINK_EDIT" => "$update_link&link=$idx"
142 ));
143 $tpl->parse ("link_rows", "link_row", true);
144 }
145
146 $cat_links .= $tpl->subst("link");
147
148 } else {
149
150 $cat_links .= Message("no_links_in_this_category_try");
151 }
152
153 $cat_links = TextToLink($cat_links);
154 $cat_links .= $link_prev_next;
155
156 return $cat_links;
157 }
158
159 ###########
160 # below is for using the above
161 #
162 if (isset($_POST['search_help']))
163 {
164 $content = Message ("search_help_text");
165
166 $tpl->set_var( array(
167 "CATEGORY_TITLE" => Message ("search_help"),
168 "CONTENT" => $content
169 ));
170 showStartTemplate();
171 }
172 else if($_POST['search'] != "" or $_GET['search'] != "")
173 {
174 $view = 0;
175 if (isset($_GET['search']))
176 {
177 $search_string = $_GET['search'];
178 if (isset ($_GET['view']))
179 $view = intval($_GET['view']);
180 }
181 else
182 {
183 $search_string = $_POST['search'];
184 if (isset ($_POST['view']))
185 $view = intval($_POST['view']);
186 }
187
188 $content = Search($search_string, $view);
189
190 $tpl->set_var( array(
191 "CATEGORY_TITLE" => Message ("search_results"),
192 "CONTENT" => $content
193 ));
194 showStartTemplate();
195
196 } else {
197 showMainPage();
198 }
199 ?>