root/devel/mod/browser/index.php

Revision 1607, 9.7 kB (checked in by misja, 7 months ago)

Assorted patches, thanks rho

  • Property svn:eol-style set to native
Line 
1 <?php
2
3 //    ".$CFG->prefix." browse page
4
5         // Run includes
6         require_once("../../includes.php");
7
8         global $search_sql;
9         global $filter;
10         global $searchtype;
11         global $db;
12         global $CFG;
13         
14         define("context", "network");
15         
16         // Quick config: this changes the number of search results on the page
17         $CFG->browser_search_results = 20;
18         
19         $search_sql = "";
20         
21         $title = __gettext("Browser");
22         $display = optional_param('display', '', PARAM_ALPHANUM);
23         $filter = trim(optional_param('filter', ''));
24         $searchtype = optional_param('searchtype', '');
25         $offset = optional_param('offset', 0, PARAM_INT);
26         $displayicons = optional_param('displayicons','');
27         $drilldown = optional_param('drilldown',-1,PARAM_INT);
28         $offset = optional_param('offset',0,PARAM_INT);
29
30         $access_string = run("users:access_level_sql_where",$_SESSION['userid']);
31         $access_string = str_replace("access","t.access",str_replace("owner","t.owner",$access_string));
32                         
33         if (!empty($searchtype)) {
34             $filter = $searchtype . "::" . $filter;
35         }
36         
37         if ($displayicons == '') {
38             if (empty($_COOKIE['displayicons'])) {
39                 $displayicons = 0;
40             } else {
41                 $displayicons = $_COOKIE['displayicons'];
42             }
43         } else {
44             if ($displayicons != 1) {
45                 $displayicons = 0;
46             }
47             setcookie("displayicons",$displayicons,time() + (86400 * 365));
48         }
49         
50         $userunderline = "";
51         $communitiesunderline = "";
52         $allunderline = "";
53         
54         switch($display) {
55             case "communities":
56                 $usertypefilter = ' u.user_type = "community" ';
57                 $communitiesunderline = ' style="text-decoration: underline;" ';
58                 break;
59             case "users":
60                 $usertypefilter = ' u.user_type = "person" ';
61                 $userunderline = ' style="text-decoration: underline;" ';
62                 break;
63             default:
64                 $display = '';
65                 $usertypefilter = ' 1 ';
66                 $allunderline = ' style="text-decoration: underline;" ';
67                 break;
68         }
69             
70         $functionbody = "
71         
72             global \$search_sql;
73             global \$filter;
74             global \$searchtype;
75         
76             \$passed = \$matches[1];
77             \$searchtype = \$passed;
78             \$search_sql = browser_advanced_search(\$passed,'$display',\$filter);
79             return \"\";
80             
81         ";
82         
83         $filter = preg_replace_callback("/([A-Za-z_0-9]*)\:\:/i",create_function('$matches',$functionbody),$filter);
84         
85         $displayfilter = $filter;
86         if (!empty($searchtype)) {
87             $displayfilter = $searchtype . "::" . $displayfilter;
88         }
89         $displayfilter = htmlspecialchars($displayfilter);
90         
91         $all = __gettext("All");
92         $communities = __gettext("Communities");
93         $users = __gettext("Users");
94         $browse = __gettext("Browse");
95         $filter_text = __gettext("Filter");
96         
97         $body = <<< END
98         
99             <p><b>$browse ::</b>
100             
101                 <a href="index.php?display=all&amp;searchtype=$searchtype&amp;filter=$filter" $allunderline>$all</a> |
102                 <a href="index.php?display=users&amp;searchtype=$searchtype&amp;filter=$filter" $userunderline>$users</a> |
103                 <a href="index.php?display=communities&amp;searchtype=$searchtype&amp;filter=$filter" $communitiesunderline>$communities</a> |
104             </p>
105             
106             <form action="index.php" method="get">
107                 <p>$filter_text : <input type="textbox" size="60" name="filter" value="$displayfilter" />
108                 <input type="hidden" name="display" value="{$display}" />&nbsp;<input type="submit" value="$filter_text &gt;&gt;" /></p>
109             </form>
110         
111 END;
112         
113         if (empty($search_sql)) {
114             $formatted_filter = $db->qstr($filter);
115             
116             if (empty($filter)) {
117                 $search_sql = "SELECT u.ident, u.username, u.name, u.icon, u.user_type, COUNT(m.ident) AS members FROM `".$CFG->prefix."users` u LEFT JOIN ".$CFG->prefix."friends m ON m.friend = u.ident WHERE " . $usertypefilter . " GROUP BY u.ident ORDER BY members DESC, name DESC";
118                 $count_sql = "SELECT COUNT(DISTINCT u.ident) AS numberofusers, COUNT(m.ident) AS members FROM `".$CFG->prefix."users` u LEFT JOIN ".$CFG->prefix."friends m ON m.friend = u.ident WHERE " . $usertypefilter . "";
119             } else {
120                 if (empty($searchtype)) {
121                     $search_sql = "SELECT u.ident, u.username, u.name, u.icon, u.user_type, COUNT(m.ident) AS members FROM ".$CFG->prefix."tags t JOIN ".$CFG->prefix."users u ON u.ident = t.owner LEFT JOIN ".$CFG->prefix."friends m ON m.friend = u.ident WHERE ($access_string) AND t.tag = $formatted_filter AND " . $usertypefilter . " GROUP BY u.ident ORDER BY members DESC, name DESC";
122                     $count_sql = "SELECT COUNT(DISTINCT u.ident) AS numberofusers, COUNT(m.ident) AS members FROM ".$CFG->prefix."tags t JOIN ".$CFG->prefix."users u ON u.ident = t.owner LEFT JOIN ".$CFG->prefix."friends m ON m.friend = u.ident WHERE ($access_string) AND t.tag = $formatted_filter AND " . $usertypefilter . "";
123                 }
124             }
125             
126         }
127         
128         $search_sql .= sql_paging_limit($offset, $CFG->browser_search_results);
129         
130         if ($results = get_records_sql($search_sql)) {
131             
132             if ($displayicons) {
133                 $icontoggle = "<a href=\"index.php?display=$display&amp;searchtype=$searchtype&amp;filter=$filter&amp;displayicons=0\">Hide icons</a>";
134             } else {
135                 $icontoggle = "<a href=\"index.php?display=$display&amp;searchtype=$searchtype&amp;filter=$filter&amp;displayicons=1\">Show icons</a>";
136             }
137             
138             $name = __gettext("Name");
139             $description = __gettext("Description");
140             $connections = __gettext("Connections");
141             $posts = __gettext("Posts");
142             $type = __gettext("Type");
143             
144             $body .= <<< END
145             
146             <table id="search_table" cellpadding="0" cellspacing="0">
147                 <tr>
148                     <td width="10%" colspan="2">$icontoggle</td>
149                     <td width="25%" valign="top"><b>$name</b></td>
150                     <td width="25%" valign="top"><b>$description</b></td>
151                     <td width="12%" valign="top"><b>$connections</b></td>
152                     <td width="12%" valign="top"><b>$posts</b></td>
153                     <td width="16%" valign="top"><b>$type</b></td>
154                 </tr>
155             
156 END;
157             
158             foreach($results as $result) {
159                 
160                 $blogposts = count_records("weblog_posts", "weblog", $result->ident);
161                 $description = get_field("profile_data", "value", "owner", $result->ident, "name", 'minibio');
162                 
163                 $icon_html = user_icon_html($result->ident, 50);
164                 
165                 $name = htmlspecialchars($result->name);
166                 
167                 $iconcode = "<a href=\"{$CFG->wwwroot}{$result->username}\">{$icon_html}</a>";
168                 if (!$displayicons) {
169                     // Uncomment this if we move to Javascript unhide
170                     // $iconcode = "<span style=\"display:none\" class=\"iconhide\">".$iconcode."</span>";
171                     $iconcode = "&nbsp;";
172                 }
173                 
174                 $rowspan = "";
175                 $plus = "";
176                 
177                 if (!empty($filter)) {
178                     if ($drilldown != $result->ident) {
179                         $plus = "<a href=\"index.php?display=$display&amp;searchtype=$searchtype&amp;filter=$filter&amp;drilldown=".$result->ident."#drilldown".$result->ident."\">+</a>";
180                     } else {
181                         $plus = "<a href=\"index.php?display=$display&amp;searchtype=$searchtype&amp;filter=$filter\">-</a>";
182                         $rowspan = "rowspan=\"2\"";
183                     }
184                 }
185                 
186                 $body .= <<< END
187                 
188                 <tr>
189                     <td style="border-right: 0" $rowspan>&nbsp;</td>
190                     <td $rowspan>$iconcode</td>
191                     <td><a href="{$CFG->wwwroot}{$result->username}">{$name}</a></td>
192                     <td>{$description}</td>
193                     <td>{$result->members}</td>
194                     <td>{$blogposts}</td>
195                     <td>{$result->user_type}</td>
196                 </tr>
197 END;
198                 
199             }
200             
201             $body .= <<< END
202             
203             </table>
204             
205 END;
206
207             if (!empty($count_sql) && $search_total = get_record_sql($count_sql)) {
208                 $search_total = $search_total->numberofusers;
209             } else {
210                 $search_total = 0;
211             }
212             
213             if ($search_total > $CFG->browser_search_results) {
214                 
215                 $i = 1;
216                 while (($i * $CFG->browser_search_results) - $CFG->browser_search_results < $search_total) {
217                     
218                     $body .= "<a href=\"index.php?display=$display&amp;searchtype=$searchtype&amp;filter=$filter&amp;offset=".(($i * $CFG->browser_search_results) - ($CFG->browser_search_results))."\">";
219                     $body .= $i;
220                     $body .= "</a> ";
221                     $i++;
222                     
223                 }
224                 
225             }
226
227
228         } else {
229         }
230         
231         templates_page_setup();
232         templates_page_output($title, $body);
233
234 ?>
Note: See TracBrowser for help on using the browser.