| [ Index ] |
PHP Cross Reference of e107 v1 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 + ----------------------------------------------------------------------------+ 4 | e107 website system 5 | 6 | Copyright (C) 2001-2002 Steve Dunstan (jalist@e107.org) 7 | Copyright (C) 2008-2010 e107 Inc (e107.org) 8 | 9 | 10 | Released under the terms and conditions of the 11 | GNU General Public License (http://gnu.org). 12 | 13 | $URL: https://e107.svn.sourceforge.net/svnroot/e107/trunk/e107_0.7/download.php $ 14 | $Revision: 12321 $ 15 | $Id: download.php 12321 2011-07-18 18:28:39Z nlstart $ 16 | $Author: nlstart $ 17 | 18 +----------------------------------------------------------------------------+ 19 */ 20 21 require_once ("class2.php"); 22 require_once(e_HANDLER."comment_class.php"); 23 require_once(e_FILE."shortcode/batch/download_shortcodes.php"); 24 25 $cobj = new comment; 26 global $tp; 27 28 $dl_text = ''; // Output variable 29 30 if(!defined("USER_WIDTH")) { define("USER_WIDTH","width:100%"); } 31 32 // Following two now set in prefs 33 // To prevent display of sub-categories on the main display, change the value in the following line from '1' to '0' 34 //$pref['download_subsub'] = '1'; 35 // To include file counts and sizes from subcategories and subsubcategories in superior categories, change the following to '1' 36 //$pref['download_incinfo'] = '1'; 37 38 /* define images */ 39 define("IMAGE_DOWNLOAD", (file_exists(THEME."images/download.png") ? THEME."images/download.png" : e_IMAGE."generic/".IMODE."/download.png")); 40 define("IMAGE_NEW", (file_exists(THEME."images/new.png") ? THEME."images/new.png" : e_IMAGE."generic/".IMODE."/new.png")); 41 42 $template_load_core = ' 43 $template_name = $load_template.".php"; 44 if (is_readable(THEME."templates/".$template_name)) 45 { 46 require_once(THEME."templates/".$template_name); 47 } 48 elseif (is_readable(THEME.$template_name)) 49 { 50 require_once(THEME.$template_name); 51 } 52 else 53 { 54 require_once(e_THEME."templates/".$template_name); 55 } 56 '; 57 58 $order_options = array('download_id','download_datestamp','download_requested','download_name','download_author'); 59 $sort_options = array('ASC', 'DESC'); 60 61 62 if (!e_QUERY || varsettrue($_GET['elan'])) 63 { 64 $action = 'maincats'; // List categories 65 $maincatval = ''; // Show all main categories 66 } 67 else 68 { // Get parameters from the query 69 $maincatval = ''; // Show all main categories 70 $tmp = explode(".", e_QUERY); 71 if (is_numeric($tmp[0])) // $tmp[0] at least must be valid 72 { 73 $dl_from = intval($tmp[0]); 74 $action = varset(preg_replace("#\W#", "", $tp -> toDB($tmp[1])),'list'); 75 $id = intval($tmp[2]); 76 $view = intval($tmp[3]); 77 $order = preg_replace("#\W#", "", $tp -> toDB($tmp[4])); 78 $sort = preg_replace("#\W#", "", $tp -> toDB($tmp[5])); 79 } 80 else 81 { 82 $action = preg_replace("#\W#", "", $tp -> toDB($tmp[0])); 83 $id = intval($tmp[1]); 84 $errnum = intval(varset($tmp[2],0)); 85 } 86 switch ($action) 87 { 88 case 'list' : // Category-based listing 89 if (isset($_POST['view'])) 90 { 91 $view = intval($_POST['view']); 92 $sort = varset($_POST['sort'],'DESC'); 93 $order = varset($_POST['order'],'download_datestamp'); 94 } 95 if (!isset($dl_from)) $dl_from = 0; 96 97 // Get category type, page title 98 if ($sql->db_Select("download_category", "download_category_name,download_category_description,download_category_parent,download_category_class", "(download_category_id='{$id}') AND (download_category_class IN (".USERCLASS_LIST."))") ) 99 { 100 $row = $sql->db_Fetch(); 101 extract($row); 102 $type = $download_category_name; 103 $type .= ($download_category_description) ? " [ ".$download_category_description." ]" : ""; 104 define("e_PAGETITLE", $download_category_name." / ".PAGE_NAME); 105 } 106 else 107 { // No access to this category 108 define("e_PAGETITLE", PAGE_NAME); 109 require_once(HEADERF); 110 $ns->tablerender(LAN_dl_18, "<div style='text-align:center'>".LAN_dl_3."</div>"); 111 require_once(FOOTERF); 112 exit; 113 } 114 if ($download_category_parent == 0) 115 { // It's a main category - change the listing type required 116 $action = 'maincats'; 117 $maincatval = $id; 118 } 119 break; 120 case 'view' : // Details of individual download 121 break; 122 case 'report' : 123 break; 124 case 'mirror' : 125 break; 126 case 'error' : // Errors passed from request.php 127 define("e_PAGETITLE", PAGE_NAME); 128 require_once(HEADERF); 129 switch ($errnum) 130 { 131 case 1 : 132 if (strlen($pref['download_denied']) > 0) { 133 $errmsg = $tp->toHTML($pref['download_denied'],true); 134 } else { 135 $errmsg = LAN_dl_63; 136 } 137 break; 138 case 2 : 139 $errmsg = LAN_dl_62; // Quota exceeded 140 break; 141 default: 142 $errmsg = LAN_dl_61." ".$errnum; // Generic error - shouldn't happen 143 } 144 $ns->tablerender(LAN_dl_61, "<div style='text-align:center'>".$errmsg."</div>"); 145 require_once(FOOTERF); 146 exit; 147 } 148 } 149 150 if (isset($order) && !in_array($order,$order_options)) unset($order); 151 if (isset($sort) && !in_array($sort,$sort_options)) unset($sort); 152 153 if (!isset($order)) $order = varset($pref['download_order'],'download_datestamp'); 154 if (!isset($sort)) $sort = varset($pref['download_sort'], 'DESC'); 155 if (!isset($view)) $view = varset($pref['download_view'], '10'); 156 157 158 //-------------------------------------------------- 159 // GENERATE DISPLAY TEXT 160 //-------------------------------------------------- 161 switch ($action) 162 { // Displaying main category or categories 163 case 'maincats' : 164 require_once(HEADERF); 165 if ($cacheData = $e107cache->retrieve("download_cat".$maincatval,720)) // expires every 12 hours. 166 { 167 echo $cacheData; 168 require_once(FOOTERF); 169 exit; 170 } 171 172 // Load the theme 173 $load_template = 'download_template'; 174 if (!isset($DOWNLOAD_CAT_PARENT_TABLE)) eval($template_load_core); 175 176 if(!defined("DL_IMAGESTYLE")){ define("DL_IMAGESTYLE","border:1px solid blue");} 177 178 // Read in tree of categories which this user is allowed to see 179 $dl = new down_cat_handler(varset($pref['download_subsub'],1),USERCLASS_LIST,$maincatval,varset($pref['download_incinfo'],FALSE)); 180 181 if ($dl->down_count == 0) 182 { 183 $ns->tablerender(LAN_dl_18, "<div style='text-align:center'>".LAN_dl_2."</div>"); 184 require_once(FOOTERF); 185 exit; 186 } 187 else 188 { 189 $download_cat_table_string = ""; // Notice removal 190 foreach($dl->cat_tree as $row) 191 { // Display main category headings, then sub-categories, optionally with sub-sub categories expanded 192 $download_cat_table_string .= parse_download_cat_parent_table($row); 193 foreach($row['subcats'] as $crow) 194 { 195 $download_cat_table_string .= parse_download_cat_child_table($crow); 196 } 197 } 198 } 199 200 // $download_cat_table_start = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_CAT_TABLE_START); 201 $download_cat_table_start = $tp->simpleParse($DOWNLOAD_CAT_TABLE_START); 202 203 $DOWNLOAD_CAT_NEWDOWNLOAD_TEXT = "<img src='".IMAGE_NEW."' alt='' style='vertical-align:middle' /> ".LAN_dl_36; 204 $DOWNLOAD_CAT_SEARCH = " 205 <form method='get' action='".e_BASE."search.php'> 206 <p> 207 <input class='tbox' type='text' name='q' size='30' value='' maxlength='50' /> 208 <input class='button' type='submit' name='s' value='".LAN_dl_41."' /> 209 <input type='hidden' name='r' value='0' /> 210 </p> 211 </form>"; 212 213 // $download_cat_table_end = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_CAT_TABLE_END); 214 $download_cat_table_end = $tp->simpleParse($DOWNLOAD_CAT_TABLE_END); 215 216 $dl_text = $download_cat_table_start.$download_cat_table_string.$download_cat_table_end; 217 218 ob_start(); 219 220 if(isset($DOWNLOAD_CAT_TABLE_RENDERPLAIN) && $DOWNLOAD_CAT_TABLE_RENDERPLAIN) 221 { 222 echo $dl_text; 223 } 224 else 225 { 226 $ns->tablerender(LAN_dl_18, $dl_text); 227 } 228 229 $cache_data = ob_get_flush(); 230 $e107cache->set("download_cat".$maincatval, $cache_data); 231 232 require_once(FOOTERF); 233 exit; 234 // Add other 'cases' here 235 } // End switch ($action) 236 237 238 if (isset($_POST['commentsubmit'])) 239 { 240 if (!$sql->db_Select("download", "download_comment", "download_id = '{$id}' ")) 241 { 242 header("location:".e_BASE."index.php"); 243 exit; 244 } 245 else 246 { 247 $row = $sql->db_Fetch(); 248 if ($row['download_comment'] && (ANON === TRUE || USER === TRUE)) 249 { 250 $clean_authorname = $_POST['author_name']; 251 $clean_comment = $_POST['comment']; 252 $clean_subject = $_POST['subject']; 253 254 $cobj->enter_comment($clean_authorname, $clean_comment, "download", $id, $pid, $clean_subject); 255 // $e107cache->clear("comment.download.{$sub_action}"); $sub_action not used here 256 $e107cache->clear("comment.download"); 257 } 258 } 259 } 260 261 //==================================================== 262 // LIST 263 //==================================================== 264 if ($action == "list") 265 { 266 $total_downloads = $sql->db_Count("download", "(*)", "WHERE download_category = '{$id}' AND download_active > 0 AND download_visible REGEXP '".e_CLASS_REGEXP."'"); 267 268 // Auto-meta descr. 269 if(!empty($row['download_category_description'])) 270 { 271 define("META_DESCRIPTION", $tp->text_truncate( 272 str_replace( 273 array('"', "'"), '', strip_tags($tp->toHTML($row['download_category_description'])) 274 ), 250, '...')); 275 } 276 277 require_once(HEADERF); 278 279 $text = ''; 280 281 /* SHOW SUBCATS ... */ 282 if($sql -> db_Select("download_category", "download_category_id", "download_category_parent='{$id}' ")) 283 { 284 /* there are subcats - display them ... */ 285 $qry = " 286 SELECT dc.*, dc2.download_category_name AS parent_name, dc2.download_category_icon as parent_icon, SUM(d.download_filesize) AS d_size, 287 COUNT(d.download_id) AS d_count, 288 MAX(d.download_datestamp) as d_last, 289 SUM(d.download_requested) as d_requests 290 FROM #download_category AS dc 291 LEFT JOIN #download AS d ON dc.download_category_id = d.download_category AND d.download_active > 0 AND d.download_visible IN (".USERCLASS_LIST.") 292 LEFT JOIN #download_category as dc2 ON dc2.download_category_id='{$id}' 293 WHERE dc.download_category_class IN (".USERCLASS_LIST.") AND dc.download_category_parent='{$id}' 294 GROUP by dc.download_category_id ORDER by dc.download_category_order 295 "; 296 $sql->db_Select_gen($qry); 297 $scArray = $sql -> db_getList(); 298 $load_template = 'download_template'; 299 if (!isset($DOWNLOAD_CAT_PARENT_TABLE)) eval($template_load_core); 300 if(!defined("DL_IMAGESTYLE")){ define("DL_IMAGESTYLE","border:1px solid blue");} 301 302 foreach($scArray as $row) 303 { 304 $download_cat_table_string .= parse_download_cat_child_table($row, FALSE); 305 } 306 if(strstr($row['parent_icon'], chr(1))) { 307 list($download_category_icon, $download_category_icon_empty) = explode(chr(1), $row['parent_icon']); 308 } 309 $DOWNLOAD_CAT_MAIN_ICON = ($download_category_icon ? "<img src='".e_IMAGE."icons/".$download_category_icon."' alt='' style='float: left' />" : " "); 310 $DOWNLOAD_CAT_MAIN_NAME = $tp->toHTML($row['parent_name'], FALSE, 'TITLE'); 311 // $download_cat_table_start = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_CAT_TABLE_START); 312 $download_cat_table_start = $tp->simpleParse($DOWNLOAD_CAT_TABLE_START); 313 $DOWNLOAD_CAT_NEWDOWNLOAD_TEXT = "<img src='".IMAGE_NEW."' alt='' style='vertical-align:middle' /> ".LAN_dl_36; 314 // $download_cat_table_end = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_CAT_TABLE_END); 315 $download_cat_table_end = $tp->simpleParse($DOWNLOAD_CAT_TABLE_END); 316 $text = $download_cat_table_start.$download_cat_table_string.$download_cat_table_end; 317 if($DOWNLOAD_CAT_TABLE_RENDERPLAIN) 318 { 319 echo $text; 320 } 321 else 322 { 323 $ns->tablerender($type, $text); 324 } 325 $text = ''; // If other files, show in a separate block 326 $type = ''; // Cancel title once displayed 327 } // End of subcategory display 328 329 // Now display individual downloads 330 // Next line looks unnecessary 331 // $core_total = $sql->db_Count("download WHERE download_category='{$id}' AND download_active > 0 AND download_visible IN (".USERCLASS_LIST.")"); 332 if (!check_class($download_category_class)) 333 { 334 $ns->tablerender(LAN_dl_18, "<div style='text-align:center'>".LAN_dl_3."</div>"); 335 require_once(FOOTERF); 336 exit; 337 } 338 339 if ($total_downloads < $view) { $dl_from = 0; } 340 341 if(isset($download_category_icon) && strstr($download_category_icon, chr(1))) 342 { 343 list($download_category_icon, $download_category_icon_empty) = explode(chr(1), $download_category_icon); 344 } 345 $DOWNLOAD_CATEGORY_ICON = (varsettrue($download_category_icon) ? "<img src='".e_IMAGE."icons/".$download_category_icon."' alt='' style='float: left' />" : " "); 346 347 $DOWNLOAD_CATEGORY = $tp->toHTML($download_category_name,FALSE,'TITLE'); 348 $DOWNLOAD_CATEGORY_DESCRIPTION = $tp -> toHTML($download_category_description, TRUE,'DESCRIPTION'); 349 350 $load_template = 'download_template'; 351 if (!isset($DOWNLOAD_LIST_TABLE)) eval($template_load_core); 352 if(!defined("DL_IMAGESTYLE")){ define("DL_IMAGESTYLE","border:1px solid blue");} 353 354 $gen = new convert; 355 require_once(e_HANDLER."rate_class.php"); 356 $rater = new rater; 357 $tdownloads = 0; 358 359 // $dl_from - first entry to show (note - can get reset due to reuse of query, even if values overridden this time) 360 // $view - number of entries per page 361 // $total_downloads - total number of entries matching search criteria 362 $filetotal = $sql->db_Select("download", "*", "download_category='{$id}' AND download_active > 0 AND download_visible IN (".USERCLASS_LIST.") ORDER BY {$order} {$sort} LIMIT {$dl_from}, {$view}"); 363 $ft = ($filetotal < $view ? $filetotal : $view); 364 $download_list_table_string = ''; 365 while ($row = $sql->db_Fetch()) 366 { 367 extract($row); 368 $download_list_table_string .= parse_download_list_table($row); 369 $tdownloads += $download_requested; 370 } 371 372 $DOWNLOAD_LIST_TOTAL_AMOUNT = $tdownloads." ".LAN_dl_16; 373 $DOWNLOAD_LIST_TOTAL_FILES = $ft." ".LAN_dl_17; 374 375 // $download_list_table_start = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_LIST_TABLE_START); 376 $download_list_table_start = $tp->simpleParse($DOWNLOAD_LIST_TABLE_START); 377 378 // $download_list_table_end = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_LIST_TABLE_END); 379 $download_list_table_end = $tp->simpleParse($DOWNLOAD_LIST_TABLE_END); 380 $text .= $download_list_table_start.$download_list_table_string.$download_list_table_end; 381 382 383 if ($filetotal) 384 { // Only show list if some files in it 385 if(varsettrue($DOWNLOAD_LIST_TABLE_RENDERPLAIN)) 386 { 387 echo $text; 388 } 389 else 390 { 391 $ns->tablerender($type, $text); 392 } 393 } 394 395 if(!isset($DOWNLOAD_LIST_NEXTPREV)) 396 { 397 $sc_style['DOWNLOAD_LIST_NEXTPREV']['pre'] = "<div class='nextprev'>"; 398 $sc_style['DOWNLOAD_LIST_NEXTPREV']['post'] = "</div>"; 399 400 $DOWNLOAD_LIST_NEXTPREV = " 401 <div style='text-align:center;margin-left:auto;margin-right:auto'>{DOWNLOAD_BACK_TO_CATEGORY_LIST}<br /><br /> 402 {DOWNLOAD_LIST_NEXTPREV} 403 </div>"; 404 } 405 406 $nextprev_parms = $total_downloads.",".$view.",".$dl_from.",".e_SELF."?[FROM].list.{$id}.{$view}.{$order}.{$sort}."; 407 echo $tp->parseTemplate($DOWNLOAD_LIST_NEXTPREV, TRUE, $download_shortcodes); 408 409 require_once(FOOTERF); 410 exit; 411 } // end of action=="list" 412 413 414 //==================================================== 415 // VIEW 416 //==================================================== 417 if ($action == "view") 418 { 419 $gen = new convert; 420 421 $highlight_search = FALSE; 422 if (isset($_POST['highlight_search'])) { 423 $highlight_search = TRUE; 424 } 425 426 $query = " 427 SELECT d.*, dc.* FROM #download AS d 428 LEFT JOIN #download_category AS dc ON d.download_category = dc.download_category_id 429 WHERE d.download_id = {$id} AND d.download_active > 0 430 AND d.download_visible IN (".USERCLASS_LIST.") 431 AND dc.download_category_class IN (".USERCLASS_LIST.") 432 LIMIT 1"; 433 434 if(!$sql -> db_Select_gen($query)){ 435 require_once(HEADERF); 436 $ns->tablerender(LAN_dl_18, "<div style='text-align:center'>".LAN_dl_3."</div>"); 437 require_once(FOOTERF); 438 exit; 439 } 440 441 $dl = $sql -> db_Fetch(); 442 443 $comment_edit_query = 'comment.download.'.$id; 444 445 $load_template = 'download_template'; 446 if (!isset($DOWNLOAD_VIEW_TABLE)) eval($template_load_core); 447 if(!defined("DL_IMAGESTYLE")){ define("DL_IMAGESTYLE","border:0px");} 448 if(!isset($DL_VIEW_PAGETITLE)) 449 { 450 $DL_VIEW_PAGETITLE = "{DOWNLOAD_VIEW_NAME} / {DOWNLOAD_CATEGORY} / ".PAGE_NAME; 451 } 452 453 $DL_TITLE = $tp->parseTemplate($DL_VIEW_PAGETITLE, TRUE, $download_shortcodes); 454 455 define("e_PAGETITLE", $DL_TITLE); 456 // Auto-meta descr. 457 if($dl['download_description']) 458 define("META_DESCRIPTION", $tp->text_truncate( 459 str_replace( 460 array('"', "'"), '', strip_tags($tp->parseTemplate('{DOWNLOAD_VIEW_DESCRIPTION}', TRUE, $download_shortcodes)) 461 ), 250, '...') 462 ); 463 464 require_once(HEADERF); 465 $DL_TEMPLATE = varset($DOWNLOAD_VIEW_TABLE_START, '').$DOWNLOAD_VIEW_TABLE.varset($DOWNLOAD_VIEW_TABLE_END, ''); 466 $text = $tp->parseTemplate($DL_TEMPLATE, TRUE, $download_shortcodes); 467 468 if(!isset($DL_VIEW_CAPTION)) 469 { 470 $DL_VIEW_CAPTION = "{DOWNLOAD_VIEW_CAPTION}"; 471 } 472 473 if(!isset($DL_VIEW_NEXTPREV)) 474 { 475 $DL_VIEW_NEXTPREV = " 476 <div style='text-align:center'> 477 <table style='".USER_WIDTH."'> 478 <tr> 479 <td style='width:40%;'>{DOWNLOAD_VIEW_PREV}</td> 480 <td style='width:20%; text-align: center;'>{DOWNLOAD_BACK_TO_LIST}</td> 481 <td style='width:40%; text-align: right;'>{DOWNLOAD_VIEW_NEXT}</td> 482 </tr> 483 </table> 484 </div> 485 "; 486 } 487 // ------- Next/Prev ----------- 488 $text .= $tp->parseTemplate($DL_VIEW_NEXTPREV,TRUE,$download_shortcodes); 489 $caption = $tp->parseTemplate($DL_VIEW_CAPTION,TRUE,$download_shortcodes); 490 491 if(varsettrue($DOWNLOAD_VIEW_TABLE_RENDERPLAIN)) 492 { 493 echo $text; 494 } 495 else 496 { 497 498 $ns->tablerender($caption, $text); 499 } 500 501 unset($text); 502 503 if ($dl['download_comment']) { 504 $cobj->compose_comment("download", "comment", $id, 0, $dl['download_name'], $showrate=FALSE); 505 } 506 507 require_once(FOOTERF); 508 exit; 509 510 } 511 512 //==================================================== 513 // REPORT BROKEN LINKS 514 //==================================================== 515 if ($action == "report" && check_class($pref['download_reportbroken'])) 516 { 517 if (!$sql->db_Select("download", "*", "download_id = {$id} AND download_active > 0")) { 518 require_once(HEADERF); 519 require_once(FOOTERF); 520 exit; 521 } 522 523 $row = $sql -> db_Fetch(); 524 extract($row); 525 526 if (isset($_POST['report_download'])) { 527 $report_add = $tp -> toDB($_POST['report_add']); 528 $download_name = $tp -> toDB($download_name); 529 $user = USER ? USERNAME : LAN_dl_52; 530 531 if ($pref['download_email']) { // this needs to be moved into the NOTIFY, with an event. 532 require_once(e_HANDLER."mail.php"); 533 $subject = LAN_dl_60." ".SITENAME; 534 $report = LAN_dl_58." ".SITENAME.":\n".(substr(SITEURL, -1) == "/" ? SITEURL : SITEURL."/")."download.php?view.".$download_id."\n 535 ".LAN_dl_59." ".$user."\n".$report_add; 536 sendemail(SITEADMINEMAIL, $subject, $report); 537 } 538 539 $sql->db_Insert('generic', "0, 'Broken Download', ".time().",'".USERID."', '{$download_name}', {$id}, '{$report_add}'"); 540 541 define("e_PAGETITLE", LAN_dl_47." / ".PAGE_NAME); 542 require_once(HEADERF); 543 544 $text = LAN_dl_48."<br /><br /><a href='".e_BASE."download.php?view.".$download_id."'>".LAN_dl_49."</a>"; 545 $ns->tablerender(LAN_dl_50, $text); 546 547 } else { 548 define("e_PAGETITLE", LAN_dl_51." ".$download_name." / ".PAGE_NAME); 549 require_once(HEADERF); 550 551 $text = "<form action='".e_SELF."?report.{$download_id}' method='post'> 552 <table style='".USER_WIDTH."'> 553 <tr> 554 <td style='width:50%' > 555 ".LAN_dl_32.": ".$download_name."<br /> 556 <a href='".e_SELF."?view.{$download_id}'> 557 <span class='smalltext'>".LAN_dl_53."</span> 558 </a> 559 </td> 560 <td style='text-align:center;width:50%'> 561 </td> 562 </tr> 563 <tr> 564 <td>".LAN_dl_54."<br />".LAN_dl_55." 565 </td> 566 <td style='text-align:center;'> 567 <textarea cols='40' rows='10' class='tbox' name='report_add'></textarea> 568 </td> 569 </tr> 570 <tr> 571 <td colspan='2' style='text-align:center;'><br /> 572 <input class='button' type='submit' name='report_download' value=\"".LAN_dl_45."\" /> 573 </td> 574 </tr> 575 </table></form>"; 576 $ns->tablerender(LAN_dl_50, $text); 577 } 578 require_once(FOOTERF); 579 exit; 580 } 581 582 583 //==================================================== 584 // MIRRORS 585 //==================================================== 586 if($action == "mirror") 587 { 588 require_once(HEADERF); 589 590 $load_template = 'download_template'; 591 if (!isset($DOWNLOAD_MIRROR_START)) eval($template_load_core); 592 593 $sql -> db_Select("download_mirror"); 594 $mirrorList = $sql -> db_getList("ALL", 0, 200, "mirror_id"); 595 596 if($sql -> db_Select("download", "*", "download_id = {$id}")) 597 { 598 $row = $sql->db_Fetch(); 599 600 extract($row); 601 $array = explode(chr(1), $download_mirror); 602 603 // Shuffle the mirror list into a random order 604 $c = count($array) -1; // Will always be an empty entry at the end 605 for ($i=1; $i<$c; $i++) 606 { 607 $d = mt_rand(0, $i); 608 $tmp = $array[$i]; 609 $array[$i] = $array[$d]; 610 $array[$d] = $tmp; 611 } 612 613 $download_mirror = ""; 614 foreach($array as $mirrorstring) 615 { 616 if($mirrorstring) 617 { 618 $download_mirror .= parse_download_mirror_table($row, $mirrorstring, $mirrorList); 619 } 620 } 621 622 $DOWNLOAD_MIRROR_HOST_LAN = LAN_dl_68; 623 $DOWNLOAD_MIRROR_GET_LAN = LAN_dl_32; 624 $DOWNLOAD_MIRROR_LOCATION_LAN = LAN_dl_70; 625 $DOWNLOAD_MIRROR_DESCRIPTION_LAN = LAN_dl_71; 626 $DOWNLOAD_MIRROR_REQUEST = LAN_dl_72."'".$download_name."'"; 627 628 // $download_mirror_start = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_MIRROR_START); 629 $download_mirror_start = $tp->simpleParse($DOWNLOAD_MIRROR_START); 630 // $download_mirror_end = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_MIRROR_END); 631 $download_mirror_end = $tp->simpleParse($DOWNLOAD_MIRROR_END); 632 633 $text = $download_mirror_start.$download_mirror.$download_mirror_end; 634 635 if($DOWNLOAD_MIRROR_RENDERPLAIN) { 636 echo $text; 637 } else { 638 $ns->tablerender(LAN_dl_67, $text); 639 } 640 641 require_once(FOOTERF); 642 } 643 } 644 645 function parse_download_mirror_table($row, $mirrorstring, $mirrorList) 646 { 647 global $pref, $DOWNLOAD_MIRROR, $tp; 648 $tVars = array(); 649 list($mirrorHost_id, $mirrorHost_url, $mirrorRequests) = explode(",", $mirrorstring); 650 651 extract($mirrorList[$mirrorHost_id]); 652 653 $tVars['DOWNLOAD_MIRROR_NAME'] = "<a href='{$mirror_url}' rel='external'>{$mirror_name}</a>"; 654 $tVars['DOWNLOAD_MIRROR_IMAGE'] = ($mirror_image ? "<a href='{$mirror_url}' rel='external'><img src='".e_FILE."downloadimages/".$mirror_image."' alt='' style='border:0' /></a>" : ""); 655 $tVars['DOWNLOAD_MIRROR_LOCATION'] = ($mirror_location ? $mirror_location : ""); 656 $tVars['DOWNLOAD_MIRROR_DESCRIPTION'] = ($mirror_description ? $mirror_description : ""); 657 658 $tVars['DOWNLOAD_MIRROR_FILESIZE'] = parsesize($row['download_filesize']); 659 $agreetext = ''; 660 if ($pref['agree_flag']) 661 { 662 $agreetext = " onclick= \"return confirm('".$tp->toJS($tp->toHTML($pref['agree_text'],FALSE,"parse_sc, defs"))."');\""; 663 } 664 $tVars['DOWNLOAD_MIRROR_LINK'] = "<a href='".e_BASE."request.php?mirror.{$row['download_id']}.{$mirrorHost_id}'{$agreetext} title='".LAN_dl_32."'><img src='".IMAGE_DOWNLOAD."' alt='' style='border:0' /></a>"; 665 666 $tVars['DOWNLOAD_MIRROR_REQUESTS'] = (ADMIN ? LAN_dl_73.$mirrorRequests : ""); 667 $tVars['DOWNLOAD_TOTAL_MIRROR_REQUESTS'] = (ADMIN ? LAN_dl_74.$mirror_count : ""); 668 669 return($tp->simpleParse($DOWNLOAD_MIRROR, $tVars)); 670 } 671 672 function parsesize($size) { 673 $kb = 1024; 674 $mb = 1024 * $kb; 675 $gb = 1024 * $mb; 676 $tb = 1024 * $gb; 677 if(!$size) 678 { 679 return '0'; 680 } 681 if ($size < $kb) { 682 return $size." ".CORE_LAN_B; 683 } 684 else if($size < $mb) { 685 return round($size/$kb, 2)." ".CORE_LAN_KB; 686 } 687 else if($size < $gb) { 688 return round($size/$mb, 2)." ".CORE_LAN_MB; 689 } 690 else if($size < $tb) { 691 return round($size/$gb, 2)." ".CORE_LAN_GB; 692 } else { 693 return round($size/$tb, 2)." ".CORE_LAN_TB; 694 } 695 } 696 697 698 699 700 function parse_download_cat_parent_table($row) 701 { 702 global $tp,$current_row,$DOWNLOAD_CAT_PARENT_TABLE; 703 extract($row); 704 $current_row = ($current_row) ? 0 : 1; // Alternating CSS for each row.(backwards compatible) 705 706 $template = ($current_row == 1) ? $DOWNLOAD_CAT_PARENT_TABLE : str_replace("forumheader3","forumheader3 forumheader3_alt",$DOWNLOAD_CAT_PARENT_TABLE); 707 708 $tVars['DOWNLOAD_CAT_MAIN_ID'] = ''; 709 $tVars['DOWNLOAD_CAT_MAIN_ICON'] = ''; 710 $tVars['DOWNLOAD_CAT_MAIN_NAME'] = ''; 711 $tVars['DOWNLOAD_CAT_MAIN_DESCRIPTION'] = ''; 712 713 if (check_class($download_category_class)) 714 { 715 if(strstr($download_category_icon, chr(1))) 716 { 717 list($download_category_icon, $download_category_icon_empty) = explode(chr(1), $download_category_icon); 718 } 719 $tVars['DOWNLOAD_CAT_MAIN_ID'] = $row['download_category_id']; 720 $tVars['DOWNLOAD_CAT_MAIN_ICON'] = ($download_category_icon ? "<img src='".e_IMAGE."icons/".$download_category_icon."' alt='' style='float: left' />" : " "); 721 $tVars['DOWNLOAD_CAT_MAIN_NAME'] = $tp->toHTML($download_category_name,FALSE,'TITLE'); 722 $tVars['DOWNLOAD_CAT_MAIN_DESCRIPTION'] = $tp->toHTML($row['download_category_description'],TRUE,'DESCRIPTION'); 723 } 724 // return(preg_replace("/\{(.*?)\}/e", '$\1', $template)); 725 return($tp->simpleParse($template, $tVars)); 726 } 727 728 729 function get_cat_icons($source, $count) 730 { 731 if (!$source) return " "; 732 list($ret[TRUE],$ret[FALSE]) = explode(chr(1), $source.chr(1)); 733 if (!$ret[FALSE]) $ret[FALSE] = $ret[TRUE]; 734 return "<img src='".e_IMAGE."icons/{$ret[($count!=0)]}' alt='' style='float: left' />"; 735 } 736 737 function check_new_download($last_val) 738 { 739 if(USER && ($last_val > USERLV)) 740 { 741 return "<img src='".IMAGE_NEW."' alt='' style='vertical-align:middle' />"; 742 } 743 else 744 { 745 return ""; 746 } 747 } 748 749 750 function parse_download_cat_child_table($row) 751 { 752 global $tp,$current_row, $DOWNLOAD_CAT_CHILD_TABLE, $DOWNLOAD_CAT_SUBSUB_TABLE; 753 754 $current_row = ($current_row) ? 0 : 1; // Alternating CSS for each row.(backwards compatible) 755 $template = ($current_row == 1) ? $DOWNLOAD_CAT_CHILD_TABLE : str_replace("forumheader3","forumheader3 forumheader3_alt",$DOWNLOAD_CAT_CHILD_TABLE); 756 757 $tVars['DOWNLOAD_CAT_SUB_ID'] = $row['download_category_id']; 758 $tVars['DOWNLOAD_CAT_SUB_ICON'] = get_cat_icons($row['download_category_icon'],$row['d_count']); 759 $tVars['DOWNLOAD_CAT_SUB_NEW_ICON'] = check_new_download($row['d_last_subs']); 760 $dcatname=$tp->toHTML($row['download_category_name'],FALSE,'TITLE'); 761 $tVars['DOWNLOAD_CAT_SUB_NAME'] = ($row['d_count'] ? "<a href='".e_BASE."download.php?list.".$row['download_category_id']."'>".$dcatname."</a>" : $dcatname); 762 $tVars['DOWNLOAD_CAT_SUB_NAME_LINKED'] = "<a href='".e_BASE."download.php?list.".$row['download_category_id']."'>".$dcatname."</a>"; 763 $tVars['DOWNLOAD_CAT_SUB_DESCRIPTION'] = $tp->toHTML($row['download_category_description'],TRUE,'DESCRIPTION'); 764 $tVars['DOWNLOAD_CAT_SUB_COUNT'] = $row['d_count']; 765 $tVars['DOWNLOAD_CAT_SUB_SIZE'] = parsesize( $row['d_size']); 766 $tVars['DOWNLOAD_CAT_SUB_DOWNLOADED'] = intval( $row['d_requests']); 767 $tVars['DOWNLOAD_CAT_SUBSUB'] = ""; 768 // check for subsub cats ... 769 foreach($row['subsubcats'] as $subrow) 770 { 771 $tVars['DOWNLOAD_CAT_SUBSUB_ICON'] = get_cat_icons($subrow['download_category_icon'],$subrow['d_count']); 772 $tVars['DOWNLOAD_CAT_SUBSUB_DESCRIPTION'] = $tp->toHTML($subrow['download_category_description'],TRUE,'DESCRIPTION'); 773 $tVars['DOWNLOAD_CAT_SUBSUB_COUNT'] = intval($subrow['d_count']); 774 $tVars['DOWNLOAD_CAT_SUBSUB_SIZE'] = parsesize($subrow['d_size']); 775 $tVars['DOWNLOAD_CAT_SUBSUB_DOWNLOADED'] = intval($subrow['d_requests']); 776 777 $tVars['DOWNLOAD_CAT_SUBSUB_NEW_ICON'] = check_new_download($subrow['d_last']); 778 $tVars['DOWNLOAD_CAT_SUBSUB_NAME'] = ($subrow['d_count'] ? "<a href='".e_BASE."download.php?list.".$subrow['download_category_id']."'>".$tp->toHTML($subrow['download_category_name'])."</a>" : $tp->toHTML($subrow['download_category_name'],FALSE,'TITLE')); 779 // $tVars['DOWNLOAD_CAT_SUBSUB'] .= preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_CAT_SUBSUB_TABLE); 780 $tVars['DOWNLOAD_CAT_SUBSUB'] .= $tp->simpleParse($DOWNLOAD_CAT_SUBSUB_TABLE, $tVars); 781 } 782 783 // return(preg_replace("/\{(.*?)\}/e", '$\1', $template)); 784 return($tp->simpleParse($template, $tVars)); 785 } 786 787 788 function parse_download_list_table($row) 789 { 790 // ***** $agreetext may not need to be global 791 global $download_shortcodes,$tp,$current_row,$DOWNLOAD_LIST_TABLE, $rater, $pref, $gen, $agreetext; 792 793 $agreetext = $tp->toHTML(varset($pref['agree_text'], ''),TRUE,"parse_sc"); 794 $current_row = ($current_row) ? 0 : 1; // Alternating CSS for each row.(backwards compatible) 795 $template = ($current_row == 1) ? $DOWNLOAD_LIST_TABLE : str_replace("forumheader3","forumheader3 forumheader3_alt",$DOWNLOAD_LIST_TABLE); 796 797 return $tp->parseTemplate($template,TRUE,$download_shortcodes); 798 799 } 800 801 802 //============================================= 803 // DOWNLOAD CATEGORY CLASS 804 //============================================= 805 806 class down_cat_handler 807 { 808 var $cat_tree; // Initialised with all categories in a tree structure 809 var $cat_count; // Count visible subcats and subsubcats 810 var $down_count; // Counts total downloads 811 812 function down_cat_handler($nest_level = 1, $load_class = USERCLASS_LIST, $main_cat_load = '', $accum = FALSE) 813 { // Constructor - make a copy of the tree for re-use 814 // $nest_level = 0 merges subsubcats with subcats. >0 creates full tree. 815 // If load-class non-null, assumed to be a 'class set' such as USERCLASS_LIST 816 // If $accum is TRUE, include file counts and sizes in superior categories 817 define("SUB_PREFIX","-->"); // Added in front of sub categories 818 define("SUBSUB_PREFIX","---->"); // Added in front of sub-sub categories 819 $this->cat_tree = $this->down_cat_tree($nest_level,$load_class, $main_cat_load, $accum); 820 } 821 822 823 // Function returns a 'tree' of download categories, subcategories, and sub-sub-categories. 824 // Returns empty array if nothing defined 825 // Within the 'main category' level of the nesting, array 'subcats' has the next level's info 826 // Within the 'sub-category' level of the nesting, array 'subsubcats' has the next level's info 827 // If $main_cat_load is numeric, and the value of a 'main' category, only that main category is displayed. 828 // (Unpredictable if $main_cat_load is some other category) 829 function down_cat_tree($nest_level = 1, $load_cat_class = USERCLASS_LIST, $main_cat_load = '', $accum = FALSE) 830 { 831 global $sql2; 832 833 $catlist = array(); 834 $this->cat_count = 0; 835 $this->down_count = 0; 836 $temp2 = ""; 837 $temp1 = ""; 838 if ($load_cat_class != "") 839 { 840 $temp1 = " WHERE dc.download_category_class IN ({$load_cat_class}) "; 841 $temp2 = "AND d.download_visible IN ({$load_cat_class}) "; 842 } 843 844 $qry = " 845 SELECT dc.*, 846 dc1.download_category_parent AS d_parent1, dc1.download_category_order, 847 SUM(d.download_filesize) AS d_size, 848 COUNT(d.download_id) AS d_count, 849 MAX(d.download_datestamp) as d_last, 850 SUM(d.download_requested) as d_requests 851 FROM #download_category as dc 852 LEFT JOIN #download_category as dc1 ON dc1.download_category_id=dc.download_category_parent 853 LEFT JOIN #download_category as dc2 ON dc2.download_category_id=dc1.download_category_parent 854 LEFT JOIN #download AS d on d.download_category = dc.download_category_id AND d.download_active > 0 {$temp2} 855 {$temp1} 856 GROUP by dc.download_category_id 857 ORDER by dc2.download_category_order, dc1.download_category_order, dc.download_category_order"; // This puts main categories first, then sub-cats, then sub-sub cats 858 859 if (!$sql2->db_Select_gen($qry)) return $catlist; 860 861 while ($row = $sql2->db_Fetch()) 862 { 863 $tmp = $row['download_category_parent']; 864 if ($tmp == '0') 865 { // Its a main category 866 if (!is_numeric($main_cat_load) || ($main_cat_load == $row['download_category_id'])) 867 { 868 $row['subcats'] = array(); 869 $catlist[$row['download_category_id']] = $row; 870 } 871 } 872 else 873 { 874 if (isset($catlist[$tmp])) 875 { // Sub-Category 876 $this->cat_count++; 877 $this->down_count += $row['d_count']; 878 $catlist[$tmp]['subcats'][$row['download_category_id']] = $row; 879 $catlist[$tmp]['subcats'][$row['download_category_id']]['subsubcats'] = array(); 880 $catlist[$tmp]['subcats'][$row['download_category_id']]['d_last_subs'] = 881 $catlist[$tmp]['subcats'][$row['download_category_id']]['d_last']; 882 } 883 else 884 { // Its a sub-sub category 885 if (isset($catlist[$row['d_parent1']]['subcats'][$tmp])) 886 { 887 $this->cat_count++; 888 $this->down_count += $row['d_count']; 889 if ($accum || ($nest_level == 0)) 890 { // Add the counts into the subcategory values 891 $catlist[$row['d_parent1']]['subcats'][$tmp]['d_size'] += $row['d_size']; 892 $catlist[$row['d_parent1']]['subcats'][$tmp]['d_count'] += $row['d_count']; 893 $catlist[$row['d_parent1']]['subcats'][$tmp]['d_requests'] += $row['d_requests']; 894 } 895 if ($nest_level == 0) 896 { // Reflect subcat dates in category 897 if ($catlist[$row['d_parent1']]['subcats'][$tmp]['d_last'] < $row['d_last']) 898 $catlist[$row['d_parent1']]['subcats'][$tmp]['d_last'] = $row['d_last']; 899 } 900 else 901 { 902 $catlist[$row['d_parent1']]['subcats'][$tmp]['subsubcats'][$row['download_category_id']] = $row; 903 } 904 // Separately accumulate 'last update' for subcat plus associated subsubcats 905 if ($catlist[$row['d_parent1']]['subcats'][$tmp]['d_last_subs'] < $row['d_last']) 906 $catlist[$row['d_parent1']]['subcats'][$tmp]['d_last_subs'] = $row['d_last']; 907 } 908 } 909 } 910 } 911 return $catlist; 912 } 913 914 915 // Rest of the class isn't actually used normally, but print_tree() might help with debug 916 917 function print_cat($cat, $prefix,$postfix) 918 { 919 $text = "<tr><td>".$cat['download_category_id']."</td><td>".$cat['download_category_parent']."</td><td>"; 920 $text .= $prefix.htmlspecialchars($cat['download_category_name']).$postfix."</td><td>".$cat['d_size']."</td>"; 921 $text .= "<td>".$cat['d_count']."</td><td>".$cat['d_requests']."</td><td>".strftime('%H:%M %d-%m-%Y',$cat['d_last'])."</td>"; 922 $text .= "</tr>"; 923 return $text; 924 } 925 926 function print_tree() 927 { 928 echo "<table><tr><th>ID</th><th>Parent</th><th>Name</th><th>Bytes</th><th>Files</th><th>Requests</th><th>Last Download</th><tr>"; 929 foreach ($this->cat_tree as $thiscat) 930 { // Main categories 931 $scprefix = SUB_PREFIX; 932 echo $this->print_cat($thiscat,'<strong>','</strong>'); 933 foreach ($thiscat['subcats'] as $sc) 934 { // Sub-categories 935 $sscprefix = SUBSUB_PREFIX; 936 echo $this->print_cat($sc,$scprefix,''); 937 foreach ($sc['subsubcats'] as $ssc) 938 { // Sub-sub categories 939 echo $this->print_cat($ssc,$sscprefix,''); 940 } 941 } 942 } 943 echo "</table>"; 944 return; 945 } 946 947 } 948 949 950 951 952 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Mar 12 16:28:38 2012 | Cross Reference PHPXref |