Changeset 1177
- Timestamp:
- 07/03/2008 04:51:19 PM (12 months ago)
- Location:
- branches/1.1.7-docs
- Files:
-
- 1 removed
- 3 modified
-
css/wikka.css (modified) (7 diffs)
-
handlers/referrers/referrers.php (modified) (1 diff)
-
handlers/referrers_sites (deleted)
-
handlers/review_blacklist/review_blacklist.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.1.7-docs/css/wikka.css
r1166 r1177 181 181 } 182 182 183 ul.menu { 184 text-align: left; 185 margin: 1em 0 0 0; 186 border-bottom: 1px solid #AAC; 187 list-style-type: none; 188 padding: 6px 10px 0px 10px; 189 } 190 191 ul.menu li { 192 display: inline; 193 font-size: 85%; 194 line-height: 85%; 195 } 196 197 ul.menu li a { 198 padding: 3px 4px; 199 border: 1px solid #AAC; 200 background-color: #D0E0F0; 201 color: #336; 202 margin-right: 2px; 203 text-decoration: none; 204 border-bottom: none; 205 } 206 207 ul.menu li.active a { 208 background-color: #fff; 209 border-top: 1px solid #AAC; 210 border-left: 1px solid #AAC; 211 border-right: 1px solid #AAC; 212 border-bottom: 1px solid #FFF; 213 color: #000; 214 padding: 4px 4px 3px 4px; 215 margin-right: 2px; 216 text-decoration: none; 217 } 218 219 ul.menu li a:hover { 220 background: #fff; 221 text-decoration: none; 222 color: #336; 223 } 224 183 225 /* images */ 184 226 … … 238 280 background: #EEE; 239 281 border: 1px solid #CCC; 282 } 283 284 /* simply left-float element */ 285 .left { 286 float:left; 287 } 288 289 /* simply right-float element */ 290 .right { 291 float:right; 240 292 } 241 293 … … 343 395 344 396 .code_header { 345 color: # 666;346 background-color: # EEE;347 border-top: 1px solid # CCC;348 border-right: 1px solid # CCC;349 border-left: 1px solid # CCC;397 color: #336; 398 background-color: #D0E0F0; 399 border-top: 1px solid #AAC; 400 border-right: 1px solid #AAC; 401 border-left: 1px solid #AAC; 350 402 border-bottom: none; 351 403 font-family: Verdana, Arial, sans-serif; … … 359 411 .code { 360 412 color: black; 361 background: #F AFAFA;362 border: 1px solid # CCC;413 background: #F3F3FF; 414 border: 1px solid #AAC; 363 415 font-size: 11px; 364 416 font-family: "Lucida Console", Monaco, monospace; … … 389 441 color: #666; 390 442 padding:2px; 443 } 444 445 select { 446 border: 1px solid #CCC; 447 } 448 449 select:hover { 450 background-color: #F3F3F3; 451 } 452 453 select:focus { 454 background-color: #E6E6FF; 391 455 } 392 456 … … 468 532 469 533 input.grabcode { 534 background-color: #D0E0F0; 535 border-left: 1px solid #EEF; 536 border-left: 1px solid #EEF; 537 border-right: 1px solid #AAC; 538 border-bottom: 1px solid #AAC; 539 color: #336; 470 540 float: right; 471 541 margin-top: 0px; 472 font-size: 90%; 542 font-size: 70%; 543 } 544 545 input.grabcode:hover { 546 background-color: #F3F3FF; 473 547 } 474 548 … … 1086 1160 /* acls handler */ 1087 1161 table.acls { 1162 } 1163 1164 /* referrers handler */ 1165 1166 div#refbody { 1167 border-top: none; 1168 border-bottom: 1px solid #AAC; 1169 border-left: 1px solid #AAC; 1170 border-right: 1px solid #AAC; 1171 padding: 2em 1em; 1172 margin-top: 0; 1173 } 1174 1175 #refform { 1176 color: inherit; 1177 background-color: inherit; 1178 margin-top: 1em; 1179 margin-bottom: 1em; 1180 width: 32em; 1181 line-height: 2em; 1182 /*border: 1px solid green;*/ /* DEBUG */ 1183 } 1184 1185 #refform .mainlabel { 1186 float: left; 1187 width: 4.6em; /* width will work on _floated_ element, even if not a block! */ 1188 padding-right: 0.5em; 1189 } 1190 1191 #q, #qo, #ho { 1192 width: 10em; 1193 } 1194 #h { 1195 width: 3em; 1196 text-align: right; 1197 } 1198 1199 #reflist { 1200 margin-top: 1em; 1201 margin-bottom: 1em; 1202 border: none; 1203 } 1204 1205 #reflist .hits { 1206 width: 3em; 1207 padding-right: 5px; 1208 text-align: right; 1209 vertical-align: middle; 1210 } 1211 1212 #reflist .action { 1213 width: 4em; 1214 padding-left: 5px; 1215 padding-right: 5px; 1216 text-align: center; 1217 vertical-align: middle; 1218 } 1219 1220 #reflist .refs { 1221 padding-left: 5px; 1222 text-align: left; 1223 vertical-align: middle; 1088 1224 } 1089 1225 -
branches/1.1.7-docs/handlers/referrers/referrers.php
r738 r1177 1 1 <?php 2 2 /** 3 * Show external referrers linking to the current page or to this wiki. 3 * Display, filter and search a list of referrers or referring sites for the current page or the site as a whole. 4 * 5 * Usage: append /referrers to the URL of the page 6 * add global=1 to specify referrers for the site instead of the current page 7 * add sites=1 to specify referrerring domains instead of full URLs 8 * 9 * This handler allows logged-in users to display, filter and search the referrer list for 10 * the current page and for the whole site. Current search criteria include strings, 11 * number of hits, reference period. 4 12 * 5 13 * @package Handlers 6 * @subpackage Referrers 7 * @version $Id:referrers.php 407 2007-03-13 05:59:51Z DarTar $ 8 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 9 * @filesource 10 * 14 * 15 * @author {@link http://wikkawiki.org/DarTar Dario Taraborelli} - code cleanup, search/filter functionality added. 16 * @author {@link http://wikkawiki.org/JavaWoman JavaWoman} - more code cleanup, accessibility, integration with referrers_sites 11 17 * @uses Config::$referrers_purge_time 12 * @uses Wakka::GetConfigValue() 18 * @uses Config::$wakka_name 19 * @uses Wakka::FormClose() 20 * @uses Wakka::FormOpen() 21 * @uses Wakka::GetHandler() 13 22 * @uses Wakka::GetPageTag() 14 * @uses Wakka::existsUser() 15 * @uses Wakka::GetHandler() 23 * @uses Wakka::GetUser() 16 24 * @uses Wakka::Href() 17 25 * @uses Wakka::htmlspecialchars_ent() 18 26 * @uses Wakka::IsAdmin() 19 * @uses Wakka::Link 20 * @uses Wakka::LoadReferrers() 21 * 22 * @todo better separation between data gathering and output 23 * @todo $heading should become heading, not bold text 24 * @todo replace with new handlers - #1 27 * @uses Wakka::LoadAll() 28 * @uses Wakka::LoadSingle() 29 * @uses Wakka::makeId() 30 * 31 * @since Wikka 1.1.7 32 * 33 * @todo 34 * - clean up debug code 35 * - remove LoadReferrers() from core 36 * - configurable choice hostname (NAME_GLOBAL) or 'this site' (config, installer) 37 * - configurable parameters for building days dropdown (config, installer) 38 * - configurable limit to express days as hours (config, installer) 39 * - build an index on the referrer column in the referrers table (installer) 40 * later: 41 * - transfer filter parameters as well so we cen redirect to the exact view we came from 42 * - (global) icons to represent each of the five views, small and larger versions (menu/page) 43 * - adapt FormOpen() to accept id; then fix form kluge here and in stylesheet 44 * - adapt text definitions to take singular-plural into account 45 * - add paging 46 * - turn list into form with checkboxes to allow mass blacklisting 47 * 48 * @input string $qs optional: string used to filter the referrers; 49 * default: NULL; 50 * the default can be overridden by providing a POST parameter 'q' 51 * @input integer $qo optional: determines the kind of search to be performed for string $qs: 52 * 1: search for all referrers containing a given string 53 * 0: search for all referrers not containing a given string 54 * default: 1; 55 * the default can be overridden by providing a POST parameter 'qo' 56 * @input integer $h optional: number of hits used to filter the referrers; 57 * default: 1; 58 * the default can be overridden by providing a POST parameter 'h' 59 * @input integer $ho optional: determines the kind of filter to be applied to $h: 60 * 1: search for referrers with at least $h hits; 61 * 0: search for referrers with no more than $h hits; 62 * default: 1; 63 * the default can be overridden by providing a POST parameter 'ho' 64 * @input integer $days optional: number of days used to filter the referrers; 65 * default: 1; 66 * the default can be overridden by providing a POST parameter 'h' 67 * @input integer $global optional: switches between local/global referrers: 68 * 1: display referrers for the whole site; 69 * 0: display referrers for the current page; 70 * default: 0; 71 * the default can be overridden by providing a GET/POST parameter 'global' 72 * @input integer $sites optional: switches between referring urls and domains 73 * 1: display referring sites (domains); 74 * 0: display referrers (URLs); 75 * default: 0; 76 * the default can be overridden by providing a GET/POST parameter 'sites' 77 * @input integer $refdel optional: number of referrer records deleted 78 * @input integer $bladd optional: number of blacklist records added 25 79 */ 26 80 27 $global = ''; 28 $IsAdmin = $this->IsAdmin(); 29 30 // set up output variables 31 $thispage = $this->GetPageTag(); 32 $ref_domains_to_wiki_url = $this->Href('referrers_sites','','global=1'); 33 $ref_domains_to_page_url = $this->Href('referrers_sites'); 34 $ref_urls_to_wiki_url = $this->Href('referrers','','global=1'); 35 $ref_urls_to_page_url = $this->Href('referrers'); 36 $ref_blacklist_url = $this->Href('review_blacklist'); 37 if (isset($_GET["global"])) # #312 38 { 39 // referrers to this wiki 40 // prepare UI 41 $global = $_GET["global"]; # #312 42 $referrers_domains_link = '<a href="'.$ref_domains_to_wiki_url.'">'.REFERRERS_DOMAINS_LINK_DESC.'</a>'; 43 $heading = sprintf(REFERRERS_URLS_TO_WIKI, $referrers_domains_link); 44 45 $ref_domains_to_page_link = '<a href="'.$ref_domains_to_page_url.'">'.sprintf(REFERRERS_DOMAINS_TO_PAGE_LINK_DESC,$thispage).'</a>'; 46 $ref_urls_to_page_link = '<a href="'.$ref_urls_to_page_url.'">'.sprintf(REFERRERS_URLS_TO_PAGE_LINK_DESC,$thispage).'</a>'; 47 $ref_blacklist_link = '<a href="'.$ref_blacklist_url.'">'.REFERRER_BLACKLIST_LINK_DESC.'</a>'; 48 $menu = '['.$ref_domains_to_page_link.' | '.$ref_urls_to_page_link.' | '.$ref_blacklist_link.']'; 81 // Utilities 82 83 /** 84 * Build an array of numbers consisting of 'ranges' with increasing step size in each 'range'. 85 * 86 * A list of numbers like this is useful for instance for a dropdown to choose 87 * a period expressed in number of days: a difference between 2 and 5 days may 88 * be significant while that between 92 and 95 may not be. 89 * 90 * @author {@link http://wikkawiki.org/JavaWoman JavaWoman} 91 * @copyright Copyright © 2005, Marjolein Katsma 92 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License 93 * @version 1.0 94 * 95 * @param mixed $limits required: single integer or array of integers; 96 * defines the upper limits of the ranges as well as the next step size 97 * @param int $max required: upper limit for the whole list 98 * (will be included if smaller than the largest limit) 99 * @param int $firstinc optional: increment for the first range; default 1 100 * @return array resulting list of numbers 101 * @todo find better name 102 * @todo move to core 103 */ 104 function optionRanges($limits, $max, $firstinc = 1) 105 { 106 // initializations 107 if (is_int($limits)) $limits = array($limits); 108 if ($firstinc < 1) $firstinc = 1; 109 $opts = array(); 110 $inc = $firstinc; 111 112 // first element is the first increment 113 $opts[] = $inc; 114 // each $limit is the upper limit of a 'range' 115 foreach ($limits as $limit) 116 { 117 for ($i = $inc + $inc; $i <= $limit && $i < $max; $i += $inc) 118 { 119 $opts[] = $i; 120 } 121 // we quit at $max, even if there are more $limit elements 122 if ($limit >= $max) 123 { 124 // add $max to the list; then break out of the loop 125 $opts[] = $max; 126 break; 127 } 128 // when $limit is reached, it becomes the new start and increment for the next 'range' 129 $inc = $limit; 130 } 131 132 return $opts; 133 } 134 135 // constants 136 137 define('DEBUG',FALSE); # @@@ set TRUE to generate debugging output 138 139 define('SEARCH_LIKE','LIKE'); # search string operator 140 define('SEARCH_UNLIKE','NOT LIKE'); # search string operator 141 define('HITS_DEFAULT', '1'); # (was 0 for referrers, 1 for sites) 142 define('HITS_MIN_OPTION', '>='); 143 define('HITS_MAX_OPTION', '<='); 144 145 define('HOURS_LIMIT',2); # days expressed as hours @@@ could be made configurable 146 define('DAYS_MAX', $this->GetConfigValue('referrers_purge_time')); 147 define('DAYS_DEFAULT', '7'); # default period to retrieve @@@ make configurable 148 149 $days_limits = array(7,30,90,365); # ranges for days dropdown @@@ make configurable 150 151 // ------------------------------------- 152 153 // initialize parameters 154 155 $qs = NULL; # search string sanitized for SQL query 156 $qx = ''; # search string sanitized for XHTML 157 $qo = 1; # search string option 158 $h = HITS_DEFAULT; # hits number 159 $ho = 1; # hits option 160 $days = DAYS_DEFAULT; # period selection 161 $global = FALSE; # global (site) or this page only 162 $sites = FALSE; # referrers or referring sites 163 $refdel = NULL; # referrer records deleted 164 $bladd = NULL; # blacklist records added 165 $r = 1; # row counter 166 167 // ------------------------------------- 168 169 // initialize internal variables 170 171 $string_option = SEARCH_LIKE; # LIKE or NOT LIKE 172 $hits_option = HITS_MIN_OPTION; # MIN (>=) or MAX (<=) 173 $tag = $this->GetPageTag(); 174 $isAdmin = $this->IsAdmin(); 175 $loggedin = ($isAdmin) ? TRUE : (bool)$this->GetUser(); 176 $pre = $this->config['table_prefix']; 177 $par = ''; 178 179 $query = ''; 180 $rows = 0; 181 182 // ------------------------------------- 183 184 // User-interface strings 185 186 define('NAME_GLOBAL',$this->GetConfigValue('wakka_name')); 187 188 define('TITLE_REFERRERS','External pages linking to %s'); 189 define('TITLE_SITES','Domains linking to %s'); 190 191 define('REPORT_BLACKLIST','Referrer records removed: %d; blacklist records added: %d'); 192 193 define('TOTAL_REFERRERS','Total: %d referrers linking to %s'); 194 define('TOTAL_SITES','Total: %d referrers linking to %s'); 195 196 // current target 197 # you can use NAME_GLOBAL instead of 'this site' if the site name is short enough 198 # @@@ JW: choice between 'this site' and NAME_GLOBAL could be set via configuration (later) 199 define('TARGET_GLOBAL','this site'); 200 define('TARGET_PAGE', $tag); 201 202 // menus don't use current target but *possible* targets 203 define('MENU_REFERRERS','Referrers to %s'); 204 define('MENU_SITES','Domains linking to %s'); 205 define('MENU_REFERRERS_PAGE',sprintf(MENU_REFERRERS,TARGET_PAGE)); 206 define('MENU_SITES_PAGE',sprintf(MENU_SITES,TARGET_PAGE)); 207 define('MENU_REFERRERS_GLOBAL',sprintf(MENU_REFERRERS,TARGET_GLOBAL)); 208 define('MENU_SITES_GLOBAL',sprintf(MENU_SITES,TARGET_GLOBAL)); 209 define('MENU_BLACKLIST','Blacklisted sites'); 210 211 define('FORM_LEGEND','Filter view:'); 212 define('FORM_URL_OPT_REFERRERS','URL:'); 213 define('FORM_URL_OPT_SITES','Domain:'); 214 define('FORM_URL_OPT_TITLE','Select search option'); 215 define('FORM_URL_OPT_1','containing'); 216 define('FORM_URL_OPT_0','not containing'); 217 define('FORM_URL_STRING_LABEL','string'); 218 define('FORM_URL_STRING_TITLE','Enter a search string'); 219 define('FORM_HITS_OPT_LABEL','Hits:'); 220 define('FORM_HITS_OPT_TITLE','Select filter option'); 221 define('FORM_HITS_OPT_1','at least'); 222 define('FORM_HITS_OPT_0','no more than'); 223 define('FORM_HITS_NUM_LABEL','hits'); 224 define('FORM_HITS_NUM_TITLE','Enter number of hits'); 225 define('FORM_DAYS_OPT_LABEL','Period:'); 226 define('FORM_DAYS_OPT_TITLE','Select period in days'); 227 define('FORM_DAYS_NUM_LABEL','days'); 228 define('FORM_SUBMIT_URLS','Show referrers'); 229 define('FORM_SUBMIT_SITES','Show referring domains'); 230 231 define('LIST_PERIOD_HOURS',' (last %d hours)'); 232 define('LIST_PERIOD_DAYS',' (last %d days)'); 233 define('LIST_SUMMARY_REFERRERS','Filtered list of referrers, with hits%s, sorted by number of hits'); 234 define('LIST_SUMMARY_SITES','Filtered list of referring sites, with hits%s, sorted by number of hits'); 235 define('LIST_HEAD_HITS','Hits'); 236 define('LIST_HEAD_ACTION','Action'); 237 define('LIST_HEAD_LIST_REFERRERS','Referrers'); 238 define('LIST_HEAD_LIST_SITES','Referring hosts'); 239 define('LIST_REF_UNKNOWN','unknown'); # make sure the *exact* same string is used in the whitelist definition (delete_referrer.php) 240 define('LIST_ACTION_DESC',' and links to blacklist spammers'); 241 define('LIST_ACTION_BLACKLIST','Blacklist'); 242 define('LIST_ACTION_BLACKLIST_TITLE','Blacklist this domain'); 243 244 define('LOGIN_NOTE','You need to login to display referrers.'); 245 246 // show result counts for target 247 define('LIST_RESULT_COUNTER_REFERRERS','Filtered result: %d referrers matching these criteria'); # @@@ does not take account of singular 248 define('LIST_RESULT_COUNTER_SITES','Filtered result: %d domains matching these criteria'); # @@@ does not take account of singular 249 define('LIST_RESULT_NONE','Filtered result:'); 250 // show 'no result' summary for target 251 define('NONE_NOTE_REFERRERS','No referrers found matching these criteria'); 252 define('NONE_NOTE_SITES','No domains found matching these criteria'); 253 254 255 // ------------------------------------- 256 257 // fetch and validate parameters 258 259 // get query string and comparison method 260 if (isset($_POST['q'])) 261 { 262 $tq = trim(strip_tags($_POST['q'])); 263 if ('' != $tq) 264 { 265 $qs = mysql_real_escape_string($tq); 266 $qx = $this->htmlspecialchars_ent($tq); 267 if (isset($_POST['qo'])) 268 { 269 $qo = ($_POST['qo'] == '1') ? 1 : 0; 270 $string_option = ($qo == 1) ? SEARCH_LIKE : SEARCH_UNLIKE; 271 } 272 } 273 } 274 // get hits and min or max criteria 275 if (isset($_POST['h'])) 276 { 277 $h = (is_numeric($_POST['h'])) ? abs((int)$_POST['h']) : HITS_DEFAULT; # cast to positive integer if numeric 278 } 279 if (isset($_POST['ho'])) 280 { 281 $ho = ($_POST['ho'] == '1') ? 1 : 0; 282 $hits_option = ($ho == 1) ? HITS_MIN_OPTION : HITS_MAX_OPTION; 283 } 284 // get period, not longer than purge time 285 if (isset($_POST['days'])) 286 { 287 $days = (is_numeric($_POST['days'])) ? min(abs((int)$_POST['days']),DAYS_MAX) : DAYS_DEFAULT; 288 } 289 // get search target: page or site (global) 290 if (isset($_POST['global'])) 291 { 292 $global = (bool)$_POST['global']; 293 } 294 elseif (isset($_GET['global'])) 295 { 296 $global = (bool)$_GET['global']; 297 } 298 $iglobal = (int)$global; 299 // get precision: URLS (referrers) or referring sites (domains) 300 if (isset($_POST['sites'])) 301 { 302 $sites = (bool)$_POST['sites']; 303 } 304 elseif (isset($_GET['sites'])) 305 { 306 $sites = (bool)$_GET['sites']; 307 } 308 $isites = (int)$sites; 309 //get reported values (no validation needed, just cast to integer) 310 if (isset($_GET['refdel'])) 311 { 312 $refdel = (int)$_GET['refdel']; 313 $bladd = (isset($_GET['bladd'])) ? $bladd = (int)$_GET['bladd'] : 0; 314 } 315 316 // derive parameters for 'current' links 317 if (1 == $global) 318 { 319 if ('' != $par) $par .= '&'; 320 $par .= 'global=1'; 321 } 322 if (1 == $sites) 323 { 324 if ('' != $par) $par .= '&'; 325 $par .= 'sites=1'; 326 } 327 328 // ------------------------------------- 329 330 // build query from chunks depending on criteria chosen 331 332 if ($loggedin) 333 { 334 $query = 'SELECT referrer'; 335 if ($sites) 336 { 337 // add 'host' = domain extracted from referrring URL using this algorithm: 338 // find first char after http:// : LOCATE('//',referrer)+2 339 // find first / after this: LOCATE('/',referrer,(LOCATE('//',referrer)+2)-1 340 // calculate length: (LOCATE('/',referrer,(LOCATE('//',referrer)+2)-1) - (LOCATE('//',referrer)+2) 341 // get host (standard): SUBSTRING(referrer FROM (LOCATE('//',referrer)+2) FOR ((LOCATE('/',referrer,(LOCATE('//',referrer)+2)-1) - (LOCATE('//',referrer)+2))) 342 // *or* 343 // get host (MySQL-specific): SUBSTRING(SUBSTRING_INDEX(referrer,'/',3) FROM (LOCATE('//',referrer)+1)) 344 $protocol_host = 'SUBSTRING_INDEX(referrer,"/",3)'; # protocol and host: everything before first single / 345 $start_host = 'LOCATE("//",referrer)+2'; # start position of host: after // 346 $query .= ', SUBSTRING('.$protocol_host.' FROM ('.$start_host.')) AS host'; 347 // NOTE: COUNT() cannot use a derived column name but it *can* take an expression 348 $query .= ', COUNT(SUBSTRING('.$protocol_host.' FROM ('.$start_host.'))) AS num'; 349 $query .= ' FROM '.$pre.'referrers'; 350 if (!$global) 351 { 352 $query .= " WHERE page_tag = '".mysql_real_escape_string($tag)."'"; 353 } 354 #if ($days != $max_days) 355 if ($days != DAYS_MAX) 356 { 357 $query .= (!strpos($query,'WHERE')) ? ' WHERE' : ' AND'; 358 $query .= ' TO_DAYS(NOW()) - TO_DAYS(time) <= '.$days; # filter by period 359 } 360 $query .= ' GROUP BY host '; 361 if (isset($qs)) 362 { 363 $query .= ' HAVING host '.$string_option." '%".$qs."%'"; # filter by string (derived column so we use HAVING) 364 } 365 if ($hits_option != HITS_MIN_OPTION || $h != 1) 366 { 367 $query .= (!strpos($query,'HAVING')) ? ' HAVING' : ' AND'; 368 $query .= ' num '.$hits_option.' '.$h; # filter by hits number (derived column so we use HAVING) 369 } 370 } 371 else 372 { 373 $query = 'SELECT referrer'; 374 $query .= ', COUNT(referrer) AS num'; 375 $query .= ' FROM '.$pre.'referrers'; 376 if (!$global) 377 { 378 $query .= " WHERE page_tag = '".mysql_real_escape_string($tag)."'"; 379 } 380 if (isset($qs)) 381 { 382 $query .= (!strpos($query,'WHERE')) ? ' WHERE' : ' AND'; 383 $query .= ' referrer '.$string_option." '%".$qs."%'"; # filter by string 384 } 385 #if ($days != $max_days) 386 if ($days != DAYS_MAX) 387 { 388 $query .= (!strpos($query,'WHERE')) ? ' WHERE' : ' AND'; 389 $query .= ' TO_DAYS(NOW()) - TO_DAYS(time) <= '.$days; # filter by period 390 } 391 $query .= ' GROUP BY referrer '; 392 if ($hits_option != HITS_MIN_OPTION || $h != 1) 393 { 394 $query .= ' HAVING num '.$hits_option.' '.$h; # filter by hits number (derived column so we use HAVING) 395 } 396 } 397 $query .= ' ORDER BY num DESC, referrer ASC'; # set order 398 399 // get total number of referrers (NOT records!) 400 $query_refcount = 'SELECT COUNT(DISTINCT(referrer)) AS total'; # @@@ referrer column should be indexed to make this really efficient 401 $query_refcount .= ' FROM '.$pre.'referrers'; 402 if (!$global) 403 { 404 $query_refcount .= " WHERE page_tag = '".mysql_real_escape_string($tag)."'"; 405 } 406 } 407 408 // ------------------------------------- 409 410 // execute query (if logged in) 411 412 // @@@ NOTE: we don't use LoadReferrers any more since the query is now completely dynamically built 413 if ($loggedin) 414 { 415 // execute query 416 $referrers = $this->LoadAll($query); 417 $totalrefs = $this->LoadSingle($query_refcount); 418 } 419 420 // ------------------------------------- 421 422 // build UI elements 423 424 // define current target 425 $target = ($global) ? TARGET_GLOBAL : $this->Link(TARGET_PAGE); 426 427 // title 428 $title = ($sites) ? sprintf(TITLE_SITES,$target) : sprintf(TITLE_REFERRERS,$target); 429 $title .= ($days <= HOURS_LIMIT) ? sprintf(LIST_PERIOD_HOURS,24*$days) : sprintf(LIST_PERIOD_DAYS,$days); 430 431 if ($isAdmin) 432 { 433 if (isset($refdel)) $rptblacklisted = sprintf(REPORT_BLACKLIST,$refdel,$bladd); 434 } 435 436 if ($loggedin) 437 { 438 // results 439 $tot = $totalrefs['total']; 440 $total = ($sites) ? sprintf(TOTAL_SITES,$tot,$target) : sprintf(TOTAL_REFERRERS,$tot,$target); 441 $creferrers = count($referrers); 442 if ($creferrers > 0) 443 { 444 $result = ($sites) ? sprintf(LIST_RESULT_COUNTER_SITES,$creferrers) : sprintf(LIST_RESULT_COUNTER_REFERRERS,$creferrers); 445 } 446 else 447 { 448 $result = LIST_RESULT_NONE; 449 } 450 451 // menu elements: prevent wrapping within element (these *don't* use current target! 452 $menu_referrers_page = str_replace(' ',' ',MENU_REFERRERS_PAGE); 453 $menu_sites_page = str_replace(' ',' ',MENU_SITES_PAGE); 454 $menu_referrers_global = str_replace(' ',' ',MENU_REFERRERS_GLOBAL); 455 $menu_sites_global = str_replace(' ',' ',MENU_SITES_GLOBAL); 456 $menu_blacklist = str_replace(' ',' ',MENU_BLACKLIST); 457 458 //menu links 459 $m_referrers_page = '<a href="'.$this->Href('referrers').'">'.$menu_referrers_page.'</a>'; 460 $m_sites_page ='<a href="'.$this->Href('referrers','','sites=1').'">'.$menu_sites_page.'</a>'; 461 $m_referrers_global = '<a href="'.$this->Href('referrers','','global=1').'">'.$menu_referrers_global.'</a>'; 462 $m_sites_global = '<a href="'.$this->Href('referrers','','global=1&sites=1').'">'.$menu_sites_global.'</a>'; 463 $m_blacklist = '<a href="'.$this->Href('review_blacklist').'">'.$menu_blacklist.'</a>'; 464 465 //build menu 466 $menu = '<ul class="menu">'."\n"; 467 $menu .= '<li'.((!$global && !$sites)? ' class="active"' : '').'>'.$m_referrers_page.'</li>'."\n"; 468 $menu .= '<li'.((!$global && $sites)? ' class="active"' : '').'>'.$m_sites_page.'</li>'."\n"; 469 $menu .= '<li'.(($global && !$sites)? ' class="active"' : '').'>'.$m_referrers_global.'</li>'."\n"; 470 $menu .= '<li'.(($global && $sites)? ' class="active"' : '').'>'.$m_sites_global.'</li>'."\n"; 471 $menu .= '<li>'.$m_blacklist.'</li>'."\n"; 472 $menu .= '</ul>'."\n"; 473 474 // days dropdown content 475 $daysopts = optionRanges($days_limits,DAYS_MAX); 476 477 // form 478 $form = $this->FormOpen('referrers','','POST'); # @@@ add parameter for id 479 $form .= '<fieldset class="hidden">'."\n"; 480 $form .= '<input type="hidden" name="global" value="'.$iglobal.'" />'."\n"; 481 $form .= '<input type="hidden" name="sites" value="'.$isites.'" />'."\n"; 482 $form .= '</fieldset>'."\n"; 483 $form .= '<fieldset>'."\n"; 484 $form .= '<legend>'.FORM_LEGEND.'</legend>'."\n"; 485 486 $form .= '<label for="qo" class="mainlabel">'.(($sites) ? FORM_URL_OPT_SITES : FORM_URL_OPT_REFERRERS).'</label> '."\n"; 487 $form .= '<select name="qo" id="qo" title="'.FORM_URL_OPT_TITLE.'">'."\n"; 488 $form .= '<option value="1"'.(($qo == '1')? ' selected="selected"' : '').'>'.FORM_URL_OPT_1.'</option>'."\n"; 489 $form .= '<option value="0"'.(($qo == '0')? ' selected="selected"' : '').'>'.FORM_URL_OPT_0.'</option>'."\n"; 490 $form .= '</select> '."\n"; 491 $form .= '<label for="q">'.FORM_URL_STRING_LABEL.'</label> '."\n"; 492 $form .= '<input type ="text" name="q" id="q" title="'.FORM_URL_STRING_TITLE.'" size="10" maxlength="50" value="'.$qx.'" />'; 493 494 $form .= '<br />'."\n"; 495 496 $form .= '<label for="ho" class="mainlabel">'.FORM_HITS_OPT_LABEL.'</label> '."\n"; 497 $form .= '<select name="ho" id="ho" title="'.FORM_HITS_OPT_TITLE.'">'."\n"; 498 $form .= '<option value="1"'.(($ho == '1')? ' selected="selected"' : '').'>'.FORM_HITS_OPT_1.'</option>'."\n"; 499 $form .= '<option value="0"'.(($ho == '0')? ' selected="selected"' : '').'>'.FORM_HITS_OPT_0.'</option>'."\n"; 500 $form .= '</select> '."\n"; 501 $form .= '<input type ="text" name="h" id="h" title="'.FORM_HITS_NUM_TITLE.'" size="5" maxlength="5" value="'.$h.'" />'."\n"; 502 $form .= ' <label for="h">'.FORM_HITS_NUM_LABEL.'</label>'; 503 504 $form .= '<br />'."\n"; 505 506 $form .= '<label for="days" class="mainlabel">'.FORM_DAYS_OPT_LABEL.'</label> '."\n"; 507 $form .= '<select name="days" id="days" title="'.FORM_DAYS_OPT_TITLE.'">'."\n"; 508 // build drop-down 509 foreach ($daysopts as $opt) 510 { 511 $selected = ($opt == $days) ? ' selected="selected"' : ''; 512 $form .= '<option value="'.$opt.'"'.$selected.'>'.$opt.'</option>'; 513 } 514 $form .= '</select> '."\n"; 515 $form .= ' <label for="h">'.FORM_DAYS_NUM_LABEL.'</label>'."\n"; 516 517 $form .= '</fieldset>'."\n"; 518 519 $form .= '<input type="submit" value="'.(($sites) ? FORM_SUBMIT_SITES : FORM_SUBMIT_URLS).'" accesskey="r" />'."\n"; 520 $form .= $this->FormClose(); 521 522 // referrers list with admin link for blacklisting 523 if ($sites) 524 { 525 $summary = ($isAdmin) ? sprintf(LIST_SUMMARY_SITES,LIST_ACTION_DESC) : sprintf(LIST_SUMMARY_SITES,''); 526 $refshead = LIST_HEAD_LIST_SITES; 527 } 528 else 529 { 530 $summary = ($isAdmin) ? sprintf(LIST_SUMMARY_REFERRERS,LIST_ACTION_DESC) : sprintf(LIST_SUMMARY_REFERRERS,''); 531 $refshead = LIST_HEAD_LIST_REFERRERS; 532 } 533 if ($isAdmin) 534 { 535 $redir = ($global||$sites) ? $this->GetHandler().'&'.$par : $this->GetHandler(); # ensure we return to the same view 536 $par = ($sites) ? 'spam_site' : 'spam_link'; 537 $blacklisturl = $this->Href('delete_referrer','',$par.'=').'%s&redirect=%s'; 538 $blacklink = '<a class="keys" href="'.$blacklisturl.'" title="'.LIST_ACTION_BLACKLIST_TITLE.'">'.LIST_ACTION_BLACKLIST.'</a>'; 539 } 540 541 // ids - use constant for variable-content heading 542 $idTitle = $this->makeId('hn','title'); 543 $idTotal = $this->makeId('hn','total'); 544 $idResult = $this->makeId('hn','result'); 545 } 546 547 // ------------------------------------- 548 549 // show user interface (pre-template) 550 551 echo '<div class="page">'."\n"; 552 echo '<h3 id="'.$idTitle.'">'.$title.'</h3>'."\n"; 553 # debug 554 if (DEBUG) 555 { 556 echo 'Query (ref): '.$query.'<br />'; 557 echo 'Query (sites): '.$query_sites.'<br />'; 558 echo ($global) ? 'Global: TRUE<br />' : 'Global: FALSE<br />'; 559 echo ($sites) ? 'Sites: TRUE<br />' : 'Sites: FALSE<br />'; 560 } 561 # debug 562 563 if ($loggedin) 564 { 565 if ($isAdmin && isset($refdel)) echo '<p class="notes">'.$rptblacklisted.'</p>'; 566 echo $menu."\n"; 567 echo '<div id="refbody">'."\n"; 568 echo '<h4 id="'.$idTotal.'">'.$total.'</h4>'."\n"; 569 echo '<div id="refform">'.$form.'</div>'."\n"; # @@@ kluge until FormOpen() is adapted: id should actually be on form itself and div not necessary! 570 571 if ($creferrers != 0) 572 { 573 echo '<h4 id="'.$idResult.'">'.$result.'</h4>'."\n"; 574 echo '<table id="reflist" class="data" summary="'.$summary.'">'."\n"; 575 echo '<thead>'; 576 echo '<tr><th class="hits" scope="col">'.LIST_HEAD_HITS.'</th>'; 577 if ($isAdmin) echo '<th class="action c2" scope="col">'.LIST_HEAD_ACTION.'</th>'; 578 echo '<th class="refs" scope="col">'.$refshead.'</th></tr>'."\n"; 579 echo '</thead>'."\n"; 580 echo '<tbody>'."\n"; 581 582 foreach ($referrers as $referrer) 583 { 584 $hits = $referrer['num']; 585 if ($sites) 586 { 587 $ref = $this->htmlspecialchars_ent($referrer['host']); 588 } 589 else 590 { 591 $ref = $this->htmlspecialchars_ent($referrer['referrer']); 592 } 593 echo '<tr'.(($r%2)? '' : ' class="alt"').'>'."\n"; #enable alternate row color echo '<td class="hits">'.$hits.'</td>'; 594 echo '<td class="hits">'.$hits.'</td>'; 595 if ($isAdmin) echo '<td class="action c2">'.sprintf($blacklink,$ref,$redir).'</td>'; 596 if ($sites) 597 { 598 echo '<td class="refs">'.$ref.'</td>'; 599 } 600 else 601 { 602 echo '<td class="refs"><a href="'.$ref.'">'.$ref.'</a></td>'; 603 } 604 echo '</tr>'."\n"; 605 $r++; 606 } 607 608 echo '</tbody>'."\n"; 609 echo '</table>'."\n"; 610 } 611 else 612 { 613 echo '<h4 id="'.$idResult.'">'.$result.'</h4>'."\n"; 614 echo '<p><em class="error">'.(($sites) ? sprintf(NONE_NOTE_SITES) : sprintf(NONE_NOTE_REFERRERS)).'</em></p>'."\n"; 615 } 49 616 } 50 617 else 51 618 { 52 // referrers to this page 53 // prepare UI 54 switch ((int) $this->GetConfigValue('referrers_purge_time')) 55 { 56 case 0: 57 $referrers_purge_time = ''; 58 break; 59 case 1: 60 $referrers_purge_time = ' '.REFERRERS_PURGE_24_HOURS; 61 break; 62 default: 63 $referrers_purge_time = sprintf(' '.REFERRERS_PURGE_N_DAYS, $this->GetConfigValue('referrers_purge_time')); 64 } 65 $referrers_domains_link = '<a href="'.$ref_domains_to_page_url.'">'.REFERRERS_DOMAINS_LINK_DESC.'</a>'; 66 $heading = sprintf(REFERRERS_URLS_TO_PAGE, $this->Link($thispage), $referrers_purge_time, $referrers_domains_link); 67 68 $ref_domains_to_wiki_link = '<a href="'.$ref_domains_to_wiki_url.'">'.REFERRERS_DOMAINS_TO_WIKI_LINK_DESC.'</a>'; 69 $ref_urls_to_wiki_link = '<a href="'.$ref_urls_to_wiki_url.'">'.REFERRERS_URLS_TO_WIKI_LINK_DESC.'</a>'; 70 $ref_blacklist_link = '<a href="'.$ref_blacklist_url.'">'.REFERRER_BLACKLIST_LINK_DESC.'</a>'; 71 $menu = '['.$ref_domains_to_wiki_link.' | '.$ref_urls_to_wiki_link.' | '.$ref_blacklist_link.']'; 72 } 73 74 echo '<div class="page">'."\n"; 75 76 echo '<strong>'.$heading.'</strong><br />'."\n"; 77 echo '<em>'.REFERRERS_NO_SPAM.'</em><br /><br />'."\n"; 78 79 #if ($this->GetUser()) 80 if ($this->existsUser()) 81 { 82 // get data 83 $referrers = ($global !== '') ? $this->LoadReferrers() : $this->LoadReferrers($thispage); 84 if ($referrers) 85 { 86 // present data 87 echo '<table border="0" cellspacing="0" cellpadding="0">'."\n"; 88 foreach ($referrers as $referrer) 89 { 90 echo '<tr>'."\n"; 91 echo '<td width="30" align="right" valign="top" style="padding-right: 10px">'.$referrer['num'].'</td>'."\n"; 92 echo '<td valign="top"><a href="'.$this->htmlspecialchars_ent($referrer['referrer']).'">'.$this->htmlspecialchars_ent($referrer['referrer']).'</a> '.($IsAdmin ? '[<a href="'.$this->Href('delete_referrer', '', 'spam_link=').$this->htmlspecialchars_ent($referrer['referrer']).'&redirect='.$this->GetHandler().'">'.BLACKLIST_LINK_DESC.'</a>]' : '').'</td>'."\n"; 93 echo '</tr>'."\n"; 94 } 95 echo '</table>'."\n"; 96 } 97 else 98 { 99 echo '<em>'.NONE_CAPTION.'</em><br />'."\n"; 100 } 101 } 102 else 103 { 104 echo '<em>'.PLEASE_LOGIN_CAPTION.'</em><br />'."\n"; 105 } 106 107 echo '<br />'.$menu; 619 echo '<p><em class="error">'.LOGIN_NOTE.'</em></p>'."\n"; 620 } 621 echo '</div>'."\n"; 108 622 echo '</div>'."\n"; 109 623 ?> -
branches/1.1.7-docs/handlers/review_blacklist/review_blacklist.php
r738 r1177 1 1 <?php 2 2 /** 3 * Show a list of blacklisted referrers. 4 * 5 * Admins have the possibility to remove entries. 3 * Display, filter and search a list of blacklisted domains. 4 * 5 * Usage: append /review_blacklist to the URL of the page 6 * 7 * This handler allows logged-in users to display and search the blacklist; an admin may 8 * remove blacklisted domains from the database. 6 9 * 7 10 * @package Handlers 8 * @subpackage Referrers 9 * @version $Id$ 10 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 11 * @filesource 12 * 13 * @uses Wakka::IsAdmin() 14 * @uses Wakka::Href() 15 * @uses Wakka::htmlspecialchars_ent() 16 * @uses Wakka::LoadAll() 17 * @uses Wakka::Query() 18 * @uses Wakka::redirect() 19 * 20 * @todo make valid XHTML (can't mix table with ul) 21 * @todo replace with new handlers - #1 11 * 12 * @author {@link http://wikkawiki.org/JavaWoman JavaWoman} - code cleanup, search/filter functionality added, valid XHTML, accessibility 13 * @since Wikka 1.1.7 14 * 15 * @todo 16 * - clean up debug code 17 * - configurable choice hostname (NAME_GLOBAL) or 'this site' (config, installer) 18 * - make index on the spammer column in the referrer_blacklist table _unique_ (installer) and remove extra query 19 * later: 20 * - (global) icons to represent each of the five views, small and larger versions (menu/page) 21 * - adapt FormOpen() to accept id; then fix form kluge here and in stylesheet 22 * - adapt text definitions to take singular-plural into account 23 * - add paging 24 * - turn list into form with checkboxes to allow mass removing 25 * 26 * @input string $q optional: string used to filter the referrers; 27 * default: 'NULL; 28 * the default can be overridden by providing a POST parameter 'q' 29 * @input integer $qo optional: determines the kind of search to be performed for string $q: 30 * 1: search for all referrers containing a given string 31 * 0: search for all referrers not containing a given string 32 * default: 1; 33 * the default can be overridden by providing a POST parameter 'qo' 34 * @input string $remove optional: GET parameter - domain to be removed from the blacklist 35 * default: NULL; 22 36 */ 23 37 24 $IsAdmin = $this->IsAdmin(); 25 26 if ($IsAdmin && isset($_GET["whitelist"])) # 312 27 { 28 $whitelist = $_GET['whitelist']; # 312 29 $this->Query('DELETE FROM '.$this->GetConfigValue('table_prefix').'referrer_blacklist WHERE spammer = "'.mysql_real_escape_string($whitelist).'"'); 30 $this->Redirect($this->Href('review_blacklist')); 31 } 32 33 // set up output variables 34 $ref_domains_to_wiki_url = $this->Href('referrers_sites','','global=1'); 35 $ref_urls_to_wiki_url = $this->Href('referrers','','global=1'); 36 $ref_domains_to_wiki_link = '<a href="'.$ref_domains_to_wiki_url.'">'.REFERRERS_DOMAINS_TO_WIKI_LINK_DESC.'</a>'; 37 $ref_urls_to_wiki_link = '<a href="'.$ref_urls_to_wiki_url.'">'.REFERRERS_URLS_TO_WIKI_LINK_DESC.'</a>'; 38 $menu = '['.$ref_domains_to_wiki_link.' | '.$ref_urls_to_wiki_link.']'; 39 40 // get data 41 $blacklist = $this->LoadAll("SELECT * FROM ".$this->GetConfigValue('table_prefix')."referrer_blacklist"); 38 // constants 39 40 define('DEBUG',FALSE); # @@@ set TRUE to generate debugging output 41 42 define('SEARCH_LIKE','LIKE'); # search string operator 43 define('SEARCH_UNLIKE','NOT LIKE'); # search string operator 44 45 // ------------------------------------- 46 47 // initialize parameters 48 49 $q = NULL; # search string 50 $qo = 1; # search string option 51 $remove = NULL; # domain to be removed from the blacklist 52 53 // ------------------------------------- 54 55 // initialize internal variables 56 57 $string_option = SEARCH_LIKE; # LIKE or NOT LIKE 58 $tag = $this->GetPageTag(); 59 $isAdmin = $this->IsAdmin(); 60 $loggedin = ($isAdmin) ? TRUE : (bool)$this->GetUser(); 61 $pre = $this->config['table_prefix']; 62 $r = 1; # row counter 63 64 $queryd = ''; 65 $querys = ''; 66 $rows = 0; 67 68 // ------------------------------------- 69 70 // User-interface strings 71 72 define('TITLE','Blacklisted domains'); 73 74 define('REPORT_REMOVED','Removed: %d records'); # @@@ does not take account of singular 75 76 define('TOTAL_BL','Total: %d blacklisted domain'); 77 78 // current target 79 # you can use NAME_GLOBAL instead of 'this site' if the site name is short enough 80 # @@@ JW: choice between 'this site' and NAME_GLOBAL could be set via configuration (later) 81 define('TARGET_GLOBAL','this site'); 82 define('TARGET_PAGE',$tag); 83 84 // menus don't use current target but *possible* targets 85 define('MENU_REFERRERS','Referrers to %s'); 86 define('MENU_SITES','Domains linking to %s'); 87 define('MENU_REFERRERS_PAGE',sprintf(MENU_REFERRERS,TARGET_PAGE)); 88 define('MENU_SITES_PAGE',sprintf(MENU_SITES,TARGET_PAGE)); 89 define('MENU_REFERRERS_GLOBAL',sprintf(MENU_REFERRERS,TARGET_GLOBAL)); 90 define('MENU_SITES_GLOBAL',sprintf(MENU_SITES,TARGET_GLOBAL)); 91 define('MENU_BLACKLIST','Blacklisted sites'); 92 93 define('FORM_LEGEND','Filter view:'); 94 define('FORM_URL_OPT_LABEL','Domain:'); 95 define('FORM_URL_OPT_TITLE','Select search option'); 96 define('FORM_URL_OPT_1','containing'); 97 define('FORM_URL_OPT_0','not containing'); 98 define('FORM_URL_STRING_LABEL','string'); 99 define('FORM_URL_STRING_TITLE','Enter a search string'); 100 define('FORM_SUBMIT_BLACKLIST','Show blacklisted domains'); 101 102 define('LIST_SUMMARY_BL','Filtered list of blacklisted domains%s, sorted alphabetically'); 103 define('LIST_HEAD_ACTION','Action'); 104 define('LIST_HEAD_BL','Blacklisted domains'); 105 define('LIST_ACTION_DESC',' and links to remove domains from the blacklist'); 106 define('LIST_ACTION_BL','Remove'); 107 define('LIST_ACTION_BL_TITLE','Remove this domain from the blacklist'); 108 109 define('LOGIN_NOTE','You need to login to see blacklisted domains.'); 110 111 define('LIST_RESULT_COUNTER_SITES','Filtered result: %d domain(s) matching these criteria'); # @@@ does not take account of singular 112 define('LIST_RESULT_NONE','Filtered result:'); 113 define('NONE_NOTE','No blacklisted domains found'); 114 115 // ------------------------------------- 116 117 // fetch and validate parameters 118 119 // get query string and comparison method 120 if (isset($_POST['q'])) 121 { 122 $tq = trim(strip_tags($_POST['q'])); 123 if ('' != $tq) 124 { 125 $q = mysql_real_escape_string($tq); 126 if (isset($_POST['qo'])) 127 { 128 $qo = ($_POST['qo'] == '1') ? 1 : 0; 129 $string_option = ($qo == 1) ? SEARCH_LIKE : SEARCH_UNLIKE; 130 } 131 } 132 } 133 // get host(s) to be removed 134 if (isset($_GET['remove'])) 135 { 136 $remove = mysql_real_escape_string(strip_tags($_GET['remove'])); 137 } 138 139 // ------------------------------------- 140 141 // build remove query 142 143 if ($isAdmin) 144 { 145 $queryd = 'DELETE FROM '.$pre.'referrer_blacklist' 146 . ' WHERE spammer = "'.$remove.'"'; 147 } 148 149 // build filter query 150 151 if ($loggedin) 152 { 153 $querys = 'SELECT * FROM '.$pre.'referrer_blacklist'; 154 if (isset($q)) 155 { 156 $querys .= ' WHERE spammer '.$string_option." '%".$q."%'"; # filter by string 157 } 158 $querys .= ' ORDER BY spammer ASC'; # set order 159 160 // get total number of domains in blacklist 161 $query_refcount = 'SELECT COUNT(spammer) AS total'; 162 $query_refcount .= ' FROM '.$pre.'referrer_blacklist'; 163 } 164 165 // ------------------------------------- 166 167 // execute query (if logged in) 168 169 // do a 'remove' query first, then follow with the select query: 170 // the list should then reflect the situation after removal of a domain 171 if ($loggedin) 172 { 173 if ($isAdmin && isset($remove)) 174 { 175 $rc = $this->Query($queryd); # TRUE on success 176 $numbldeleted = mysql_affected_rows(); # @@@ report back as GET parameter (in $removeurl/$removelink!) 177 } 178 $blacklist = $this->LoadAll($querys); 179 $totalrefs = $this->LoadSingle($query_refcount); 180 } 181 182 // ------------------------------------- 183 184 // build UI elements 185 186 // title 187 $title = TITLE; 188 189 if ($isAdmin) 190 { 191 if (isset($numbldeleted)) $rptremoved = sprintf(REPORT_REMOVED,$numbldeleted); 192 193 $removeurl = $this->Href('review_blacklist','','remove=').'%s'; 194 $removelink = '<a class="keys" href="'.$removeurl.'" title="'.LIST_ACTION_BL_TITLE.'">'.LIST_ACTION_BL.'</a>'; 195 } 196 197 if ($loggedin) 198 { 199 // results 200 $tot = $totalrefs['total']; 201 $total = sprintf(TOTAL_BL,$tot); 202 $cdomains = count($blacklist); 203 204 if ($cdomains > 0) 205 { 206 $result = sprintf(LIST_RESULT_COUNTER_SITES,$cdomains); 207 } 208 else 209 { 210 $result = LIST_RESULT_NONE; 211 } 212 213 // menu elements: prevent wrapping within element (these *don't* use current target! 214 $menu_referrers_page = str_replace(' ',' ',MENU_REFERRERS_PAGE); 215 $menu_sites_page = str_replace(' ',' ',MENU_SITES_PAGE); 216 $menu_referrers_global = str_replace(' ',' ',MENU_REFERRERS_GLOBAL); 217 $menu_sites_global = str_replace(' ',' ',MENU_SITES_GLOBAL); 218 $menu_blacklist = str_replace(' ',' ',MENU_BLACKLIST); 219 220 //menu links 221 $m_referrers_page = '<a href="'.$this->Href('referrers').'">'.$menu_referrers_page.'</a>'; 222 $m_sites_page ='<a href="'.$this->Href('referrers','','sites=1').'">'.$menu_sites_page.'</a>'; 223 $m_referrers_global = '<a href="'.$this->Href('referrers','','global=1').'">'.$menu_referrers_global.'</a>'; 224 $m_sites_global = '<a href="'.$this->Href('referrers','','global=1&sites=1').'">'.$menu_sites_global.'</a>'; 225 $m_blacklist = '<a href="'.$this->Href('review_blacklist').'">'.$menu_blacklist.'</a>'; 226 227 $menu = '<ul class="menu">'."\n"; 228 $menu .= '<li>'.$m_referrers_page.'</li>'."\n"; 229 $menu .= '<li>'.$m_sites_page.'</li>'."\n"; 230 $menu .= '<li>'.$m_referrers_global.'</li>'."\n"; 231 $menu .= '<li>'.$m_sites_global.'</li>'."\n"; 232 $menu .= '<li class="active">'.$m_blacklist.'</li>'."\n"; 233 $menu .= '</ul>'."\n"; 234 235 236 // form 237 $form = $this->FormOpen('review_blacklist','','POST'); # @@@ add parameter for id 238 $form .= '<fieldset>'."\n"; 239 $form .= '<legend>'.FORM_LEGEND.'</legend>'."\n"; 240 241 $form .= '<label for="qo" class="mainlabel">'.FORM_URL_OPT_LABEL.'</label> '."\n"; 242 $form .= '<select name="qo" id="qo" title="'.FORM_URL_OPT_TITLE.'">'."\n"; 243 $form .= '<option value="1"'.(($qo == '1')? ' selected="selected"' : '').'>'.FORM_URL_OPT_1.'</option>'."\n"; 244 $form .= '<option value="0"'.(($qo == '0')? ' selected="selected"' : '').'>'.FORM_URL_OPT_0.'</option>'."\n"; 245 $form .= '</select> '."\n"; 246 $form .= '<label for="q">'.FORM_URL_STRING_LABEL.'</label> '."\n"; 247 $form .= '<input type ="text" name="q" id="q" title="'.FORM_URL_STRING_TITLE.'" size="10" maxlength="50" value="'.$q.'" />'; 248 249 $form .= '</fieldset>'."\n"; 250 251 $form .= '<input type="submit" value="'.FORM_SUBMIT_BLACKLIST.'" accesskey="b" />'."\n"; 252 $form .= $this->FormClose(); 253 254 // blacklist with admin link for removing 255 $summary = ($isAdmin) ? sprintf(LIST_SUMMARY_BL,LIST_ACTION_DESC) : sprintf(LIST_SUMMARY_BL,''); 256 $refshead = LIST_HEAD_BL; 257 258 // ids - use constant for variable-content heading 259 $idTitle = $this->makeId('hn','title'); 260 $idTotal = $this->makeId('hn','total'); 261 $idResult = $this->makeId('hn','result'); 262 } 263 264 // ------------------------------------- 265 266 // show user interface (pre-template) 42 267 43 268 echo '<div class="page">'."\n"; 44 echo '<strong>'.BLACKLIST_HEADING.'</strong><br /><br />'."\n"; 45 46 // present data 47 if ($blacklist) 48 { 49 echo '<table border="0" cellspacing="0" cellpadding="0">'."\n"; 50 foreach ($blacklist as $spammer) 51 { 52 echo '<tr>'."\n"; 53 echo '<td valign="top">'.$spammer['spammer'].' '.($IsAdmin ? '[<a href="'.$this->Href('review_blacklist', '', 'whitelist=').$this->htmlspecialchars_ent($spammer['spammer']).'">'.BLACKLIST_REMOVE_LINK_DESC.'</a>]' : '').'</td>'."\n"; 54 echo '</tr>'."\n"; 55 } 56 echo '</table><br />'."\n"; 269 echo '<h3 id="'.$idTitle.'">'.$title.'</h3>'."\n"; 270 # debug 271 if (DEBUG) 272 { 273 echo 'Query remove: '.$queryd.'<br />'; 274 echo 'Query blacklist: '.$querys.'<br />'; 275 echo 'remove: '.$remove.'<br/>'; 276 echo 'removed: '.$numbldeleted.'<br/>'; 277 } 278 # debug 279 if ($loggedin) 280 { 281 if ($isAdmin && isset($numbldeleted)) echo '<p class="notes">'.$rptremoved.'</p>'; 282 echo '<div class="refmenu">'.$menu.'</div>'."\n"; 283 echo '<div id="refbody">'."\n"; 284 echo '<h4 id="'.$idTotal.'">'.$total.'</h4>'."\n"; 285 echo '<div id="refform">'.$form.'</div>'."\n"; # @@@ kluge until FormOpen() is adapted: id should actually be on form itself and div not necessary! 286 287 if ($cdomains != 0) 288 { 289 echo '<h4 id="'.$idResult.'">'.$result.'</h4>'."\n"; 290 echo '<table id="reflist" class="data" summary="'.$summary.'">'."\n"; 291 echo '<thead>'; 292 if ($isAdmin) echo '<th class="action c2" scope="col">'.LIST_HEAD_ACTION.'</th>'; 293 echo '<th class="refs" scope="col">'.$refshead.'</th></tr>'."\n"; 294 echo '</thead>'."\n"; 295 echo '<tbody>'."\n"; 296 foreach ($blacklist as $spammer) 297 { 298 $ref = $this->htmlspecialchars_ent($spammer['spammer']); 299 echo '<tr'.(($r%2)? '' : ' class="alt"').'>'."\n"; #enable alternate row color echo '<td class="hits">'.$hits.'</td>'; 300 if ($isAdmin) echo '<td class="action c2">'.sprintf($removelink,$ref).'</td>'; 301 echo '<td class="refs">'.$ref.'</td>'; 302 echo '</tr>'."\n"; 303 $r++; 304 } 305 echo '</tbody>'."\n"; 306 echo '</table>'."\n"; 307 } 308 else 309 { 310 echo '<h4 id="'.$idResult.'">'.$result.'</h4>'."\n"; 311 echo '<p><em class="error">'.NONE_NOTE.'</em></p>'."\n"; 312 } 57 313 } 58 314 else 59 315 { 60 echo '<em>'.STATUS_BLACKLIST_EMPTY.'</em><br /><br />'."\n"; 61 } 62 63 echo '<br />'.$menu; 64 echo '</div>'."\n" //TODO: move to templating class 316 echo '<p><em class="error">'.LOGIN_NOTE.'</em></p>'."\n"; 317 } 318 echo '</div>'."\n"; 319 echo '</div>'."\n"; 65 320 ?>