[ Index ]
 

Code source de e107 0.7.8

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/ -> download.php (source)

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


Généré le : Sun Apr 1 01:23:32 2007 par Balluche grâce à PHPXref 0.7