Changeset 1071
- Timestamp:
- 05/10/2008 05:49:54 AM (2 years ago)
- Location:
- trunk
- Files:
-
- 4 modified
-
css/wikka.css (modified) (2 diffs)
-
handlers/referrers/referrers.php (modified) (1 diff)
-
handlers/review_blacklist/review_blacklist.php (modified) (1 diff)
-
libs/Wakka.class.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/css/wikka.css
r1039 r1071 146 146 font-size: 11px; 147 147 } 148 149 ul.menu { 150 text-align: left; 151 margin: 1em 0 0 0; 152 border-bottom: 1px solid #AAC; 153 list-style-type: none; 154 padding: 6px 10px 0px 10px; 155 } 156 157 ul.menu li { 158 display: inline; 159 font-size: 85%; 160 line-height: 85%; 161 } 162 163 ul.menu li a { 164 padding: 3px 4px; 165 border: 1px solid #AAC; 166 background-color: #D0E0F0; 167 color: #336; 168 margin-right: 2px; 169 text-decoration: none; 170 border-bottom: none; 171 } 172 173 ul.menu li.active a { 174 background-color: #fff; 175 border-top: 1px solid #AAC; 176 border-left: 1px solid #AAC; 177 border-right: 1px solid #AAC; 178 border-bottom: 1px solid #FFF; 179 color: #000; 180 padding: 4px 4px 3px 4px; 181 margin-right: 2px; 182 text-decoration: none; 183 } 184 185 ul.menu li a:hover { 186 background: #fff; 187 text-decoration: none; 188 color: #336; 189 } 190 148 191 149 192 /* images */ … … 936 979 /* acls handler */ 937 980 table.acls { 981 } 982 983 /* referrers handler */ 984 985 div#refbody { 986 border-top: none; 987 border-bottom: 1px solid #AAC; 988 border-left: 1px solid #AAC; 989 border-right: 1px solid #AAC; 990 padding: 2em 1em; 991 margin-top: 0; 992 } 993 994 #refform { 995 color: inherit; 996 background-color: inherit; 997 margin-top: 1em; 998 margin-bottom: 1em; 999 width: 32em; 1000 /*border: 1px solid green;*/ /* DEBUG */ 1001 } 1002 1003 #refform .mainlabel { 1004 float: left; 1005 width: 4.6em; /* width will work on _floated_ element, even if not a block! */ 1006 padding-right: 0.5em; 1007 } 1008 1009 #q, #qo, #ho { 1010 width: 10em; 1011 } 1012 #h { 1013 width: 3em; 1014 text-align: right; 1015 } 1016 1017 #reflist { 1018 margin-top: 1em; 1019 margin-bottom: 1em; 1020 border: none; 1021 } 1022 1023 #reflist .hits { 1024 width: 3em; 1025 padding-right: 5px; 1026 text-align: right; 1027 vertical-align: middle; 1028 } 1029 1030 #reflist .action { 1031 width: 4em; 1032 padding-left: 5px; 1033 padding-right: 5px; 1034 text-align: center; 1035 vertical-align: middle; 1036 } 1037 1038 #reflist .refs { 1039 padding-left: 5px; 1040 text-align: left; 1041 vertical-align: middle; 938 1042 } 939 1043 -
trunk/handlers/referrers/referrers.php
r738 r1071 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 * 11 * @uses Config::$referrers_purge_time 12 * @uses Wakka::GetConfigValue() 13 * @uses Wakka::GetPageTag() 14 * @uses Wakka::existsUser() 15 * @uses Wakka::GetHandler() 16 * @uses Wakka::Href() 17 * @uses Wakka::htmlspecialchars_ent() 18 * @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 14 * 15 * @author {@link http://wikka.jsnx.com/DarTar Dario Taraborelli} - code cleanup, search/filter functionality added. 16 * @author {@link http://wikka.jsnx.com/JavaWoman JavaWoman} - more code cleanup, accessibility, integration with referrers_sites 17 * @version 0.8 18 * @since Wikka 1.1.6.X 19 * 20 * @todo for 1.0: 21 * - clean up debug code 22 * - remove LoadReferrers() from core 23 * - configurable choice hostname (NAME_GLOBAL) or 'this site' (config, installer) 24 * - configurable parameters for building days dropdown (config, installer) 25 * - configurable limit to express days as hours (config, installer) 26 * - build an index on the referrer column in the referrers table (installer) 27 * later: 28 * - transfer filter parameters as well so we cen redirect to the exact view we came from 29 * - (global) icons to represent each of the five views, small and larger versions (menu/page) 30 * - adapt FormOpen() to accept id; then fix form kluge here and in stylesheet 31 * - adapt text definitions to take singular-plural into account 32 * - add paging 33 * - turn list into form with checkboxes to allow mass blacklisting 34 * 35 * @input string $q optional: string used to filter the referrers; 36 * default: NULL; 37 * the default can be overridden by providing a POST parameter 'q' 38 * @input integer $qo optional: determines the kind of search to be performed for string $q: 39 * 1: search for all referrers containing a given string 40 * 0: search for all referrers not containing a given string 41 * default: 1; 42 * the default can be overridden by providing a POST parameter 'qo' 43 * @input integer $h optional: number of hits used to filter the referrers; 44 * default: 1; 45 * the default can be overridden by providing a POST parameter 'h' 46 * @input integer $ho optional: determines the kind of filter to be applied to $h: 47 * 1: search for referrers with at least $h hits; 48 * 0: search for referrers with no more than $h hits; 49 * default: 1; 50 * the default can be overridden by providing a POST parameter 'ho' 51 * @input integer $days optional: number of days used to filter the referrers; 52 * default: 1; 53 * the default can be overridden by providing a POST parameter 'h' 54 * @input integer $global optional: switches between local/global referrers: 55 * 1: display referrers for the whole site; 56 * 0: display referrers for the current page; 57 * default: 0; 58 * the default can be overridden by providing a GET/POST parameter 'global' 59 * @input integer $sites optional: switches between referring urls and domains 60 * 1: display referring sites (domains); 61 * 0: display referrers (URLs); 62 * default: 0; 63 * the default can be overridden by providing a GET/POST parameter 'sites' 64 * @input integer $refdel optional: number of referrer records deleted 65 * @input integer $bladd optional: number of blacklist records added 25 66 */ 26 67 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.']'; 68 // Utilities 69 70 /** 71 * Build an array of numbers consisting of 'ranges' with increasing step size in each 'range'. 72 * 73 * A list of numbers like this is useful for instance for a dropdown to choose 74 * a period expressed in number of days: a difference between 2 and 5 days may 75 * be significant while that between 92 and 95 may not be. 76 * 77 * @author {@link http://wikkawiki.org/JavaWoman JavaWoman} 78 * @copyright Copyright © 2005, Marjolein Katsma 79 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License 80 * @version 1.0 81 * 82 * @param mixed $limits required: single integer or array of integers; 83 * defines the upper limits of the ranges as well as the next step size 84 * @param int $max required: upper limit for the whole list 85 * (will be included if smaller than the largest limit) 86 * @param int $firstinc optional: increment for the first range; default 1 87 * @return array resulting list of numbers 88 * @todo find better name 89 * @todo move to core 90 */ 91 function optionRanges($limits, $max, $firstinc = 1) 92 { 93 // initializations 94 if (is_int($limits)) $limits = array($limits); 95 if ($firstinc < 1) $firstinc = 1; 96 $opts = array(); 97 $inc = $firstinc; 98 99 // first element is the first increment 100 $opts[] = $inc; 101 // each $limit is the upper limit of a 'range' 102 foreach ($limits as $limit) 103 { 104 for ($i = $inc + $inc; $i <= $limit && $i < $max; $i += $inc) 105 { 106 $opts[] = $i; 107 } 108 // we quit at $max, even if there are more $limit elements 109 if ($limit >= $max) 110 { 111 // add $max to the list; then break out of the loop 112 $opts[] = $max; 113 break; 114 } 115 // when $limit is reached, it becomes the new start and increment for the next 'range' 116 $inc = $limit; 117 } 118 119 return $opts; 120 } 121 122 // constants 123 124 define('DEBUG',FALSE); # @@@ set TRUE to generate debugging output 125 126 define('SEARCH_LIKE','LIKE'); # search string operator 127 define('SEARCH_UNLIKE','NOT LIKE'); # search string operator 128 define('HITS_DEFAULT', '1'); # (was 0 for referrers, 1 for sites) 129 define('HITS_MIN_OPTION', '>='); 130 define('HITS_MAX_OPTION', '<='); 131 132 define('HOURS_LIMIT',2); # days expressed as hours @@@ could be made configurable 133 define('DAYS_MAX', $this->GetConfigValue('referrers_purge_time')); 134 define('DAYS_DEFAULT', '7'); # default period to retrieve @@@ make configurable 135 136 $days_limits = array(7,30,90,365); # ranges for days dropdown @@@ make configurable 137 138 // ------------------------------------- 139 140 // initialize parameters 141 142 $q = NULL; # search string 143 $qo = 1; # search string option 144 $h = HITS_DEFAULT; # hits number 145 $ho = 1; # hits option 146 $days = DAYS_DEFAULT; # period selection 147 $global = FALSE; # global (site) or this page only 148 $sites = FALSE; # referrers or referring sites 149 $refdel = NULL; # referrer records deleted 150 $bladd = NULL; # blacklist records added 151 152 // ------------------------------------- 153 154 // initialize internal variables 155 156 $string_option = SEARCH_LIKE; # LIKE or NOT LIKE 157 $hits_option = HITS_MIN_OPTION; # MIN (>=) or MAX (<=) 158 $tag = $this->GetPageTag(); 159 $isAdmin = $this->IsAdmin(); 160 $loggedin = ($isAdmin) ? TRUE : (bool)$this->GetUser(); 161 $pre = $this->config['table_prefix']; 162 $par = ''; 163 164 $query = ''; 165 $rows = 0; 166 167 // ------------------------------------- 168 169 // User-interface strings 170 171 define('NAME_GLOBAL',$this->GetConfigValue('wakka_name')); 172 173 define('TITLE_REFERRERS','External pages linking to %s'); 174 define('TITLE_SITES','Domains linking to %s'); 175 176 define('REPORT_BLACKLIST','Referrer records removed: %d; blacklist records added: %d'); 177 178 define('TOTAL_REFERRERS','Total: %d referrers linking to %s'); 179 define('TOTAL_SITES','Total: %d referrers linking to %s'); 180 181 // current target 182 # you can use NAME_GLOBAL instead of 'this site' if the site name is short enough 183 # @@@ JW: choice between 'this site' and NAME_GLOBAL could be set via configuration (later) 184 define('TARGET_GLOBAL','this site'); 185 define('TARGET_PAGE',$tag); 186 187 // menus don't use current target but *possible* targets 188 define('MENU_REFERRERS','Referrers to %s'); 189 define('MENU_SITES','Domains linking to %s'); 190 define('MENU_REFERRERS_PAGE',sprintf(MENU_REFERRERS,TARGET_PAGE)); 191 define('MENU_SITES_PAGE',sprintf(MENU_SITES,TARGET_PAGE)); 192 define('MENU_REFERRERS_GLOBAL',sprintf(MENU_REFERRERS,TARGET_GLOBAL)); 193 define('MENU_SITES_GLOBAL',sprintf(MENU_SITES,TARGET_GLOBAL)); 194 define('MENU_BLACKLIST','Blacklisted sites'); 195 196 define('FORM_LEGEND','Filter view:'); 197 define('FORM_URL_OPT_REFERRERS','URL:'); 198 define('FORM_URL_OPT_SITES','Domain:'); 199 define('FORM_URL_OPT_TITLE','Select search option'); 200 define('FORM_URL_OPT_1','containing'); 201 define('FORM_URL_OPT_0','not containing'); 202 define('FORM_URL_STRING_LABEL','string'); 203 define('FORM_URL_STRING_TITLE','Enter a search string'); 204 define('FORM_HITS_OPT_LABEL','Hits:'); 205 define('FORM_HITS_OPT_TITLE','Select filter option'); 206 define('FORM_HITS_OPT_1','at least'); 207 define('FORM_HITS_OPT_0','no more than'); 208 define('FORM_HITS_NUM_LABEL','hits'); 209 define('FORM_HITS_NUM_TITLE','Enter number of hits'); 210 define('FORM_DAYS_OPT_LABEL','Period:'); 211 define('FORM_DAYS_OPT_TITLE','Select period in days'); 212 define('FORM_DAYS_NUM_LABEL','days'); 213 define('FORM_SUBMIT_URLS','Show referrers'); 214 define('FORM_SUBMIT_SITES','Show referring domains'); 215 216 define('LIST_PERIOD_HOURS',' (last %d hours)'); 217 define('LIST_PERIOD_DAYS',' (last %d days)'); 218 define('LIST_SUMMARY_REFERRERS','Filtered list of referrers, with hits%s, sorted by number of hits'); 219 define('LIST_SUMMARY_SITES','Filtered list of referring sites, with hits%s, sorted by number of hits'); 220 define('LIST_HEAD_HITS','Hits'); 221 define('LIST_HEAD_ACTION','Action'); 222 define('LIST_HEAD_LIST_REFERRERS','Referrers'); 223 define('LIST_HEAD_LIST_SITES','Referring hosts'); 224 define('LIST_REF_UNKNOWN','unknown'); # make sure the *exact* same string is used in the whitelist definition (delete_referrer.php) 225 define('LIST_ACTION_DESC',' and links to blacklist spammers'); 226 define('LIST_ACTION_BLACKLIST','Blacklist'); 227 define('LIST_ACTION_BLACKLIST_TITLE','Blacklist this domain'); 228 229 define('LOGIN_NOTE','You need to login to see referring sites.'); 230 231 // show result counts for target 232 define('LIST_RESULT_COUNTER_REFERRERS','Filtered result: %d referrers linking to %s'); # @@@ does not take account of singular 233 define('LIST_RESULT_COUNTER_SITES','Filtered result: %d domains linking to %s'); # @@@ does not take account of singular 234 define('LIST_RESULT_NONE','Filtered result:'); 235 // show 'no result' summary for target 236 define('NONE_NOTE_REFERRERS','No referrers found linking to %s'); 237 define('NONE_NOTE_SITES','No domains found linking to %s'); 238 239 240 // ------------------------------------- 241 242 // fetch and validate parameters 243 244 // get query string and comparison method 245 if (isset($_POST['q'])) 246 { 247 $tq = trim(strip_tags($_POST['q'])); 248 if ('' != $tq) 249 { 250 $q = mysql_real_escape_string($tq); 251 if (isset($_POST['qo'])) 252 { 253 $qo = ($_POST['qo'] == '1') ? 1 : 0; 254 $string_option = ($qo == 1) ? SEARCH_LIKE : SEARCH_UNLIKE; 255 } 256 } 257 } 258 // get hits and min or max criteria 259 if (isset($_POST['h'])) 260 { 261 $h = (is_numeric($_POST['h'])) ? abs((int)$_POST['h']) : HITS_DEFAULT; # cast to positive integer if numeric 262 } 263 if (isset($_POST['ho'])) 264 { 265 $ho = ($_POST['ho'] == '1') ? 1 : 0; 266 $hits_option = ($ho == 1) ? HITS_MIN_OPTION : HITS_MAX_OPTION; 267 } 268 // get period, not longer than purge time 269 if (isset($_POST['days'])) 270 { 271 $days = (is_numeric($_POST['days'])) ? min(abs((int)$_POST['days']),DAYS_MAX) : DAYS_DEFAULT; 272 } 273 // get search target: page or site (global) 274 if (isset($_POST['global'])) 275 { 276 $global = (bool)$_POST['global']; 277 } 278 elseif (isset($_GET['global'])) 279 { 280 $global = (bool)$_GET['global']; 281 } 282 $iglobal = (int)$global; 283 // get precision: URLS (referrers) or referring sites (domains) 284 if (isset($_POST['sites'])) 285 { 286 $sites = (bool)$_POST['sites']; 287 } 288 elseif (isset($_GET['sites'])) 289 { 290 $sites = (bool)$_GET['sites']; 291 } 292 $isites = (int)$sites; 293 //get reported values (no validation needed, just cast to integer) 294 if (isset($_GET['refdel'])) 295 { 296 $refdel = (int)$_GET['refdel']; 297 $bladd = (isset($_GET['bladd'])) ? $bladd = (int)$_GET['bladd'] : 0; 298 } 299 300 // derive parameters for 'current' links 301 if (1 == $global) 302 { 303 if ('' != $par) $par .= '&'; 304 $par .= 'global=1'; 305 } 306 if (1 == $sites) 307 { 308 if ('' != $par) $par .= '&'; 309 $par .= 'sites=1'; 310 } 311 312 // ------------------------------------- 313 314 // build query from chunks depending on criteria chosen 315 316 if ($loggedin) 317 { 318 $query = 'SELECT referrer'; 319 if ($sites) 320 { 321 // add 'host' = domain extracted from referrring URL using this algorithm: 322 // find first char after http:// : LOCATE('//',referrer)+2 323 // find first / after this: LOCATE('/',referrer,(LOCATE('//',referrer)+2)-1 324 // calculate length: (LOCATE('/',referrer,(LOCATE('//',referrer)+2)-1) - (LOCATE('//',referrer)+2) 325 // get host (standard): SUBSTRING(referrer FROM (LOCATE('//',referrer)+2) FOR ((LOCATE('/',referrer,(LOCATE('//',referrer)+2)-1) - (LOCATE('//',referrer)+2))) 326 // *or* 327 // get host (MySQL-specific): SUBSTRING(SUBSTRING_INDEX(referrer,'/',3) FROM (LOCATE('//',referrer)+1)) 328 $protocol_host = 'SUBSTRING_INDEX(referrer,"/",3)'; # protocol and host: everything before first single / 329 $start_host = 'LOCATE("//",referrer)+2'; # start position of host: after // 330 $query .= ', SUBSTRING('.$protocol_host.' FROM ('.$start_host.')) AS host'; 331 // NOTE: COUNT() cannot use a derived column name but it *can* take an expression 332 $query .= ', COUNT(SUBSTRING('.$protocol_host.' FROM ('.$start_host.'))) AS num'; 333 $query .= ' FROM '.$pre.'referrers'; 334 if (!$global) 335 { 336 $query .= " WHERE page_tag = '".mysql_real_escape_string($tag)."'"; 337 } 338 #if ($days != $max_days) 339 if ($days != DAYS_MAX) 340 { 341 $query .= (!strpos($query,'WHERE')) ? ' WHERE' : ' AND'; 342 $query .= ' TO_DAYS(NOW()) - TO_DAYS(time) <= '.$days; # filter by period 343 } 344 $query .= ' GROUP BY host '; 345 if (isset($q)) 346 { 347 $query .= ' HAVING host '.$string_option." '%".$q."%'"; # filter by string (derived column so we use HAVING) 348 } 349 if ($hits_option != HITS_MIN_OPTION || $h != 1) 350 { 351 $query .= (!strpos($query,'HAVING')) ? ' HAVING' : ' AND'; 352 $query .= ' num '.$hits_option.' '.$h; # filter by hits number (derived column so we use HAVING) 353 } 354 } 355 else 356 { 357 $query = 'SELECT referrer'; 358 $query .= ', COUNT(referrer) AS num'; 359 $query .= ' FROM '.$pre.'referrers'; 360 if (!$global) 361 { 362 $query .= " WHERE page_tag = '".mysql_real_escape_string($tag)."'"; 363 } 364 if (isset($q)) 365 { 366 $query .= (!strpos($query,'WHERE')) ? ' WHERE' : ' AND'; 367 $query .= ' referrer '.$string_option." '%".$q."%'"; # filter by string 368 } 369 #if ($days != $max_days) 370 if ($days != DAYS_MAX) 371 { 372 $query .= (!strpos($query,'WHERE')) ? ' WHERE' : ' AND'; 373 $query .= ' TO_DAYS(NOW()) - TO_DAYS(time) <= '.$days; # filter by period 374 } 375 $query .= ' GROUP BY referrer '; 376 if ($hits_option != HITS_MIN_OPTION || $h != 1) 377 { 378 $query .= ' HAVING num '.$hits_option.' '.$h; # filter by hits number (derived column so we use HAVING) 379 } 380 } 381 $query .= ' ORDER BY num DESC, referrer ASC'; # set order 382 383 // get total number of referrers (NOT records!) 384 $query_refcount = 'SELECT COUNT(DISTINCT(referrer)) AS total'; # @@@ referrer column should be indexed to make this really efficient 385 $query_refcount .= ' FROM '.$pre.'referrers'; 386 if (!$global) 387 { 388 $query_refcount .= " WHERE page_tag = '".mysql_real_escape_string($tag)."'"; 389 } 390 } 391 392 // ------------------------------------- 393 394 // execute query (if logged in) 395 396 // @@@ NOTE: we don't use LoadReferrers any more since the query is now completely dynamically built 397 if ($loggedin) 398 { 399 // execute query 400 $referrers = $this->LoadAll($query); 401 $totalrefs = $this->LoadSingle($query_refcount); 402 } 403 404 // ------------------------------------- 405 406 // build UI elements 407 408 // define current target 409 $target = ($global) ? TARGET_GLOBAL : TARGET_PAGE; 410 411 // title 412 $title = ($sites) ? sprintf(TITLE_SITES,$target) : sprintf(TITLE_REFERRERS,$target); 413 $title .= ($days <= HOURS_LIMIT) ? sprintf(LIST_PERIOD_HOURS,24*$days) : sprintf(LIST_PERIOD_DAYS,$days); 414 415 if ($isAdmin) 416 { 417 if (isset($refdel)) $rptblacklisted = sprintf(REPORT_BLACKLIST,$refdel,$bladd); 418 } 419 420 if ($loggedin) 421 { 422 // results 423 $tot = $totalrefs['total']; 424 $total = ($sites) ? sprintf(TOTAL_SITES,$tot,$target) : sprintf(TOTAL_REFERRERS,$tot,$target); 425 $creferrers = count($referrers); 426 if ($creferrers > 0) 427 { 428 $result = ($sites) ? sprintf(LIST_RESULT_COUNTER_SITES,$creferrers,$target) : sprintf(LIST_RESULT_COUNTER_REFERRERS,$creferrers,$target); 429 } 430 else 431 { 432 $result = LIST_RESULT_NONE; 433 } 434 435 // menu elements: prevent wrapping within element (these *don't* use current target! 436 $menu_referrers_page = str_replace(' ',' ',MENU_REFERRERS_PAGE); 437 $menu_sites_page = str_replace(' ',' ',MENU_SITES_PAGE); 438 $menu_referrers_global = str_replace(' ',' ',MENU_REFERRERS_GLOBAL); 439 $menu_sites_global = str_replace(' ',' ',MENU_SITES_GLOBAL); 440 $menu_blacklist = str_replace(' ',' ',MENU_BLACKLIST); 441 442 //menu links 443 $m_referrers_page = '<a href="'.$this->Href('referrers').'">'.$menu_referrers_page.'</a>'; 444 $m_sites_page ='<a href="'.$this->Href('referrers','','sites=1').'">'.$menu_sites_page.'</a>'; 445 $m_referrers_global = '<a href="'.$this->Href('referrers','','global=1').'">'.$menu_referrers_global.'</a>'; 446 $m_sites_global = '<a href="'.$this->Href('referrers','','global=1&sites=1').'">'.$menu_sites_global.'</a>'; 447 $m_blacklist = '<a href="'.$this->Href('review_blacklist').'">'.$menu_blacklist.'</a>'; 448 449 //build menu 450 $menu = '<ul class="menu">'."\n"; 451 $menu .= '<li'.((!$global && !$sites)? ' class="active"' : '').'>'.$m_referrers_page.'</li>'."\n"; 452 $menu .= '<li'.((!$global && $sites)? ' class="active"' : '').'>'.$m_sites_page.'</li>'."\n"; 453 $menu .= '<li'.(($global && !$sites)? ' class="active"' : '').'>'.$m_referrers_global.'</li>'."\n"; 454 $menu .= '<li'.(($global && $sites)? ' class="active"' : '').'>'.$m_sites_global.'</li>'."\n"; 455 $menu .= '<li>'.$m_blacklist.'</li>'."\n"; 456 $menu .= '</ul>'."\n"; 457 458 // days dropdown content 459 $daysopts = optionRanges($days_limits,DAYS_MAX); 460 461 // form 462 $form = $this->FormOpen('referrers','','POST'); # @@@ add parameter for id 463 $form .= '<fieldset class="hidden">'."\n"; 464 $form .= '<input type="hidden" name="global" value="'.$iglobal.'" />'."\n"; 465 $form .= '<input type="hidden" name="sites" value="'.$isites.'" />'."\n"; 466 $form .= '</fieldset>'."\n"; 467 $form .= '<fieldset>'."\n"; 468 $form .= '<legend>'.FORM_LEGEND.'</legend>'."\n"; 469 470 $form .= '<label for="qo" class="mainlabel">'.(($sites) ? FORM_URL_OPT_SITES : FORM_URL_OPT_REFERRERS).'</label> '."\n"; 471 $form .= '<select name="qo" id="qo" title="'.FORM_URL_OPT_TITLE.'">'."\n"; 472 $form .= '<option value="1"'.(($qo == '1')? ' selected="selected"' : '').'>'.FORM_URL_OPT_1.'</option>'."\n"; 473 $form .= '<option value="0"'.(($qo == '0')? ' selected="selected"' : '').'>'.FORM_URL_OPT_0.'</option>'."\n"; 474 $form .= '</select> '."\n"; 475 $form .= '<label for="q">'.FORM_URL_STRING_LABEL.'</label> '."\n"; 476 $form .= '<input type ="text" name="q" id="q" title="'.FORM_URL_STRING_TITLE.'" size="10" maxlength="50" value="'.$q.'" />'; 477 478 $form .= '<br />'."\n"; 479 480 $form .= '<label for="ho" class="mainlabel">'.FORM_HITS_OPT_LABEL.'</label> '."\n"; 481 $form .= '<select name="ho" id="ho" title="'.FORM_HITS_OPT_TITLE.'">'."\n"; 482 $form .= '<option value="1"'.(($ho == '1')? ' selected="selected"' : '').'>'.FORM_HITS_OPT_1.'</option>'."\n"; 483 $form .= '<option value="0"'.(($ho == '0')? ' selected="selected"' : '').'>'.FORM_HITS_OPT_0.'</option>'."\n"; 484 $form .= '</select> '."\n"; 485 $form .= '<input type ="text" name="h" id="h" title="'.FORM_HITS_NUM_TITLE.'" size="5" maxlength="5" value="'.$h.'" />'."\n"; 486 $form .= ' <label for="h">'.FORM_HITS_NUM_LABEL.'</label>'; 487 488 $form .= '<br />'."\n"; 489 490 $form .= '<label for="days" class="mainlabel">'.FORM_DAYS_OPT_LABEL.'</label> '."\n"; 491 $form .= '<select name="days" id="days" title="'.FORM_DAYS_OPT_TITLE.'">'."\n"; 492 // build drop-down 493 foreach ($daysopts as $opt) 494 { 495 $selected = ($opt == $days) ? ' selected="selected"' : ''; 496 $form .= '<option value="'.$opt.'"'.$selected.'>'.$opt.'</option>'; 497 } 498 $form .= '</select> '."\n"; 499 $form .= ' <label for="h">'.FORM_DAYS_NUM_LABEL.'</label>'."\n"; 500 501 $form .= '</fieldset>'."\n"; 502 503 $form .= '<input type="submit" value="'.(($sites) ? FORM_SUBMIT_SITES : FORM_SUBMIT_URLS).'" accesskey="r" />'."\n"; 504 $form .= $this->FormClose(); 505 506 // referrers list with admin link for blacklisting 507 if ($sites) 508 { 509 $summary = ($isAdmin) ? sprintf(LIST_SUMMARY_SITES,LIST_ACTION_DESC) : sprintf(LIST_SUMMARY_SITES,''); 510 $refshead = LIST_HEAD_LIST_SITES; 511 } 512 else 513 { 514 $summary = ($isAdmin) ? sprintf(LIST_SUMMARY_REFERRERS,LIST_ACTION_DESC) : sprintf(LIST_SUMMARY_REFERRERS,''); 515 $refshead = LIST_HEAD_LIST_REFERRERS; 516 } 517 if ($isAdmin) 518 { 519 $redir = ($global||$sites) ? $this->GetHandler().'&'.$par : $this->GetHandler(); # ensure we return to the same view 520 $par = ($sites) ? 'spam_site' : 'spam_link'; 521 $blacklisturl = $this->Href('delete_referrer','',$par.'=').'%s&redirect=%s'; 522 $blacklink = '<a class="keys" href="'.$blacklisturl.'" title="'.LIST_ACTION_BLACKLIST_TITLE.'">'.LIST_ACTION_BLACKLIST.'</a>'; 523 } 524 525 // ids - use constant for variable-content heading 526 $idTitle = $this->makeId('hn','title'); 527 $idTotal = $this->makeId('hn','total'); 528 $idResult = $this->makeId('hn','result'); 529 } 530 531 // ------------------------------------- 532 533 // show user interface (pre-template) 534 535 echo '<div class="page">'."\n"; 536 echo '<h3 id="'.$idTitle.'">'.$title.'</h3>'."\n"; 537 # debug 538 if (DEBUG) 539 { 540 echo 'Query (ref): '.$query.'<br />'; 541 echo 'Query (sites): '.$query_sites.'<br />'; 542 echo ($global) ? 'Global: TRUE<br />' : 'Global: FALSE<br />'; 543 echo ($sites) ? 'Sites: TRUE<br />' : 'Sites: FALSE<br />'; 544 } 545 # debug 546 547 if ($loggedin) 548 { 549 if ($isAdmin && isset($refdel)) echo '<p class="notes">'.$rptblacklisted.'</p>'; 550 echo $menu."\n"; 551 echo '<div id="refbody">'."\n"; 552 echo '<h4 id="'.$idTotal.'">'.$total.'</h4>'."\n"; 553 echo '<div id="refform">'.$form.'</div>'."\n"; # @@@ kluge until FormOpen() is adapted: id should actually be on form itself and div not necessary! 554 555 if ($creferrers != 0) 556 { 557 echo '<h4 id="'.$idResult.'">'.$result.'</h4>'."\n"; 558 echo '<table id="reflist" class="data" summary="'.$summary.'">'."\n"; 559 echo '<thead>'; 560 echo '<tr><th class="hits" scope="col">'.LIST_HEAD_HITS.'</th>'; 561 if ($isAdmin) echo '<th class="action" scope="col">'.LIST_HEAD_ACTION.'</th>'; 562 echo '<th class="refs" scope="col">'.$refshead.'</th></tr>'."\n"; 563 echo '</thead>'."\n"; 564 echo '<tbody>'."\n"; 565 566 foreach ($referrers as $referrer) 567 { 568 $hits = $referrer['num']; 569 if ($sites) 570 { 571 $ref = $this->htmlspecialchars_ent($referrer['host']); 572 } 573 else 574 { 575 $ref = $this->htmlspecialchars_ent($referrer['referrer']); 576 } 577 echo '<tr>'; 578 echo '<td class="hits">'.$hits.'</td>'; 579 if ($isAdmin) echo '<td class="action">'.sprintf($blacklink,$ref,$redir).'</td>'; 580 if ($sites) 581 { 582 echo '<td class="refs">'.$ref.'</td>'; 583 } 584 else 585 { 586 echo '<td class="refs"><a href="'.$ref.'">'.$ref.'</a></td>'; 587 } 588 echo '</tr>'."\n"; 589 } 590 591 echo '</tbody>'."\n"; 592 echo '</table>'."\n"; 593 } 594 else 595 { 596 echo '<h4 id="'.$idResult.'">'.$result.'</h4>'."\n"; 597 echo '<p><em class="error">'.(($sites) ? sprintf(NONE_NOTE_SITES,$target) : sprintf(NONE_NOTE_REFERRERS,$target)).'</em></p>'."\n"; 598 } 49 599 } 50 600 else 51 601 { 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; 602 echo '<p><strong>'.LOGIN_NOTE.'</strong></p>'."\n"; 603 } 604 echo '</div>'."\n"; 108 605 echo '</div>'."\n"; 109 606 ?> -
trunk/handlers/review_blacklist/review_blacklist.php
r738 r1071 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 * @version 0.8 14 * @since Wikka 1.1.6.X 15 * 16 * @todo for 1.0: 17 * - clean up debug code 18 * - configurable choice hostname (NAME_GLOBAL) or 'this site' (config, installer) 19 * - make index on the spammer column in the referrer_blacklist table _unique_ (installer) and remove extra query 20 * later: 21 * - (global) icons to represent each of the five views, small and larger versions (menu/page) 22 * - adapt FormOpen() to accept id; then fix form kluge here and in stylesheet 23 * - adapt text definitions to take singular-plural into account 24 * - add paging 25 * - turn list into form with checkboxes to allow mass removing 26 * 27 * @input string $q optional: string used to filter the referrers; 28 * default: 'NULL; 29 * the default can be overridden by providing a POST parameter 'q' 30 * @input integer $qo optional: determines the kind of search to be performed for string $q: 31 * 1: search for all referrers containing a given string 32 * 0: search for all referrers not containing a given string 33 * default: 1; 34 * the default can be overridden by providing a POST parameter 'qo' 35 * @input string $remove optional: GET parameter - domain to be removed from the blacklist 36 * default: NULL; 22 37 */ 23 38 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"); 39 // constants 40 41 define('DEBUG',FALSE); # @@@ set TRUE to generate debugging output 42 43 define('SEARCH_LIKE','LIKE'); # search string operator 44 define('SEARCH_UNLIKE','NOT LIKE'); # search string operator 45 46 // ------------------------------------- 47 48 // initialize parameters 49 50 $q = NULL; # search string 51 $qo = 1; # search string option 52 $remove = NULL; # domain to be removed from the blacklist 53 54 // ------------------------------------- 55 56 // initialize internal variables 57 58 $string_option = SEARCH_LIKE; # LIKE or NOT LIKE 59 $tag = $this->GetPageTag(); 60 $isAdmin = $this->IsAdmin(); 61 $loggedin = ($isAdmin) ? TRUE : (bool)$this->GetUser(); 62 $pre = $this->config['table_prefix']; 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 domains'); # @@@ 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" 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>'; 300 if ($isAdmin) echo '<td class="action">'.sprintf($removelink,$ref).'</td>'; 301 echo '<td class="refs">'.$ref.'</td>'; 302 echo '</tr>'."\n"; 303 } 304 echo '</tbody>'."\n"; 305 echo '</table>'."\n"; 306 } 307 else 308 { 309 echo '<h4 id="'.$idResult.'">'.$result.'</h4>'."\n"; 310 echo '<p><em>'.NONE_NOTE.'</em></p>'."\n"; 311 } 57 312 } 58 313 else 59 314 { 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 315 echo '<p><strong>'.LOGIN_NOTE.'</strong></p>'."\n"; 316 } 317 echo '</div>'."\n"; 318 echo '</div>'."\n"; 65 319 ?> -
trunk/libs/Wakka.class.php
r1059 r1071 718 718 * ARRAYS: processing arrays into formatted output 719 719 */ 720 721 /**722 * Build a list from an array.723 *724 * Given an array, this method builds a simple unordered or ordered list725 * with an id.726 * Only a (simple) array is required which will generate an727 * unordered list; optionally id, class, type of list and an indent level728 * can be specified. For type 'menu' an unordered list is generated but729 * with an id in group 'menu' instead of 'ul' or 'ol': this enables the730 * list being styled as a menu.731 *732 * @todo _ make maximum indent configurable733 * - support for nested lists (same type)734 * - support for definition lists735 *736 * @author {@link http://wikkawiki.org/JavaWoman JavaWoman}737 * @copyright Copyright © 2005, Marjolein Katsma738 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License739 *740 * @access public741 * @uses makeId()742 *743 * @param array $array required: flat array with content items744 * @param mixed $id optional: id for the list, will be treated with makeId()745 * or FALSE which suppresses id (for multiple-use elements)746 * @param string $class optional: class for (extra) styling747 * @param string $type optional: type of list to generate; default: ul748 * @param integer $indent optional: indent level749 * @return string generated list750 */751 function makeList($array,$id='',$class='',$type='ul',$indent=0)752 {753 static $validate = TRUE; # need to validate input754 if (!defined('MAKELIST_MAX_INDENT')) define('MAKELIST_MAX_INDENT',20); # @@@ make max configurable)755 // definition756 $aTypes = array('ul','ol','menu'); # @@@ add dl later (menu generates ul)757 // validate/treat input758 if ($validate)759 {760 if (!is_array($array))761 {762 return '<p class="error">Could not generate tag: array required</p>'."\n"; # @@@ i18n763 }764 $type = (!in_array($type,$aTypes)) ? 'ul' : $type;765 $class = trim(strip_tags($class)); # minimum protection for user-supplied input766 $indent = min(MAKELIST_MAX_INDENT,abs((int)$indent)); # positive integer no larger than MAX_INDENT767 $validate = FALSE; # validation done: no need to repeat for recursion768 }769 // build tag770 $tag = ('menu' == $type) ? 'ul' : $type;771 $ind = str_repeat("\t",$indent);772 $attrId = (FALSE !== $id) ? ' id="'.$id = $this->makeId($type,$id).'"' : '';773 $attrClass = ('' != $class) ? ' class="'.$class.'"' : '';774 $out = $ind.'<'.$tag.$attrClass.$attrId.">\n";775 foreach ($array as $item)776 {777 $out .= $ind.' <li>';778 # @@@ add recursion for nested lists779 if (!is_array($item))780 {781 $out .= $item;782 }783 else784 {785 $out .= 'nested list not yet supported'; # @@@ i18n;786 }787 $out .= "</li>\n";788 }789 $out .= $ind.'</'.$tag.">\n";790 // return result791 return $out;792 }793 794 720 795 721 /**