[ Index ]

PHP Cross Reference of E107 v0.7.22 code documentation

title

Body

[close]

/ -> 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: /cvs_backup/e107_0.7/download.php,v $
  14  |     $Revision: 11346 $
  15  |     $Date: 2010-02-17 13:56:14 -0500 (Wed, 17 Feb 2010) $
  16  |     $Author: secretr $
  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", PAGE_NAME." / ".$download_category_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      require_once(HEADERF);
 269      $text = '';
 270  
 271      /* SHOW SUBCATS ... */
 272      if($sql -> db_Select("download_category", "download_category_id", "download_category_parent='{$id}' "))
 273      {
 274          /* there are subcats - display them ... */
 275          $qry = "
 276          SELECT dc.*, dc2.download_category_name AS parent_name, dc2.download_category_icon as parent_icon, SUM(d.download_filesize) AS d_size,
 277          COUNT(d.download_id) AS d_count,
 278          MAX(d.download_datestamp) as d_last,
 279          SUM(d.download_requested) as d_requests
 280          FROM #download_category AS dc
 281          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.")
 282          LEFT JOIN #download_category as dc2 ON dc2.download_category_id='{$id}'
 283          WHERE dc.download_category_class IN (".USERCLASS_LIST.") AND dc.download_category_parent='{$id}'
 284          GROUP by dc.download_category_id ORDER by dc.download_category_order
 285          ";
 286          $sql->db_Select_gen($qry);
 287          $scArray = $sql -> db_getList();
 288          $load_template = 'download_template';
 289          if (!isset($DOWNLOAD_CAT_PARENT_TABLE)) eval($template_load_core);
 290          if(!defined("DL_IMAGESTYLE")){ define("DL_IMAGESTYLE","border:1px solid blue");}
 291  
 292          foreach($scArray as $row)
 293          {
 294              $download_cat_table_string .= parse_download_cat_child_table($row, FALSE);
 295          }
 296          if(strstr($row['parent_icon'], chr(1)))    {
 297              list($download_category_icon, $download_category_icon_empty) = explode(chr(1), $row['parent_icon']);
 298          }
 299          $DOWNLOAD_CAT_MAIN_ICON = ($download_category_icon ? "<img src='".e_IMAGE."icons/".$download_category_icon."' alt='' style='float: left' />" : "&nbsp;");
 300          $DOWNLOAD_CAT_MAIN_NAME = $tp->toHTML($row['parent_name'], FALSE, 'TITLE');
 301  //        $download_cat_table_start = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_CAT_TABLE_START);
 302          $download_cat_table_start = $tp->simpleParse($DOWNLOAD_CAT_TABLE_START);
 303          $DOWNLOAD_CAT_NEWDOWNLOAD_TEXT = "<img src='".IMAGE_NEW."' alt='' style='vertical-align:middle' /> ".LAN_dl_36;
 304  //        $download_cat_table_end = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_CAT_TABLE_END);
 305          $download_cat_table_end = $tp->simpleParse($DOWNLOAD_CAT_TABLE_END);
 306          $text = $download_cat_table_start.$download_cat_table_string.$download_cat_table_end;
 307          if($DOWNLOAD_CAT_TABLE_RENDERPLAIN)
 308          {
 309              echo $text;
 310          }
 311          else
 312          {
 313              $ns->tablerender($type, $text);
 314          }
 315          $text = '';        // If other files, show in a separate block
 316          $type = '';       // Cancel title once displayed
 317      }  // End of subcategory display
 318  
 319  // Now display individual downloads
 320      // Next line looks unnecessary
 321  //    $core_total = $sql->db_Count("download WHERE download_category='{$id}' AND download_active > 0 AND download_visible IN (".USERCLASS_LIST.")");
 322      if (!check_class($download_category_class))
 323      {
 324          $ns->tablerender(LAN_dl_18, "<div style='text-align:center'>".LAN_dl_3."</div>");
 325          require_once(FOOTERF);
 326          exit;
 327      }
 328  
 329      if ($total_downloads < $view) { $dl_from = 0; }
 330  
 331      if(isset($download_category_icon) && strstr($download_category_icon, chr(1)))
 332      {
 333          list($download_category_icon, $download_category_icon_empty) = explode(chr(1), $download_category_icon);
 334      }
 335      $DOWNLOAD_CATEGORY_ICON = (varsettrue($download_category_icon) ? "<img src='".e_IMAGE."icons/".$download_category_icon."' alt='' style='float: left' />" : "&nbsp;");
 336  
 337      $DOWNLOAD_CATEGORY = $tp->toHTML($download_category_name,FALSE,'TITLE');
 338      $DOWNLOAD_CATEGORY_DESCRIPTION = $tp -> toHTML($download_category_description, TRUE,'DESCRIPTION');
 339  
 340      $load_template = 'download_template';
 341      if (!isset($DOWNLOAD_LIST_TABLE)) eval($template_load_core);
 342      if(!defined("DL_IMAGESTYLE")){ define("DL_IMAGESTYLE","border:1px solid blue");}
 343  
 344      $gen = new convert;
 345      require_once(e_HANDLER."rate_class.php");
 346      $rater = new rater;
 347      $tdownloads = 0;
 348  
 349      // $dl_from - first entry to show  (note - can get reset due to reuse of query, even if values overridden this time)
 350      // $view - number of entries per page
 351      // $total_downloads - total number of entries matching search criteria
 352      $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}");
 353      $ft = ($filetotal < $view ? $filetotal : $view);
 354      $download_list_table_string = '';
 355      while ($row = $sql->db_Fetch())
 356      {
 357          extract($row);
 358          $download_list_table_string .= parse_download_list_table($row);
 359          $tdownloads += $download_requested;
 360      }
 361  
 362      $DOWNLOAD_LIST_TOTAL_AMOUNT = $tdownloads." ".LAN_dl_16;
 363      $DOWNLOAD_LIST_TOTAL_FILES = $ft." ".LAN_dl_17;
 364  
 365  //    $download_list_table_start = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_LIST_TABLE_START);
 366      $download_list_table_start = $tp->simpleParse($DOWNLOAD_LIST_TABLE_START);
 367      
 368  //    $download_list_table_end = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_LIST_TABLE_END);
 369      $download_list_table_end = $tp->simpleParse($DOWNLOAD_LIST_TABLE_END);
 370      $text .= $download_list_table_start.$download_list_table_string.$download_list_table_end;
 371  
 372  
 373      if ($filetotal)
 374      {  // Only show list if some files in it
 375          if(varsettrue($DOWNLOAD_LIST_TABLE_RENDERPLAIN))
 376          {
 377              echo $text;
 378          }
 379              else
 380          {
 381              $ns->tablerender($type, $text);
 382          }
 383      }
 384  
 385      if(!isset($DOWNLOAD_LIST_NEXTPREV))
 386      {
 387          $sc_style['DOWNLOAD_LIST_NEXTPREV']['pre'] = "<div class='nextprev'>";
 388          $sc_style['DOWNLOAD_LIST_NEXTPREV']['post'] = "</div>";
 389  
 390          $DOWNLOAD_LIST_NEXTPREV = "
 391              <div style='text-align:center;margin-left:auto;margin-right:auto'>{DOWNLOAD_BACK_TO_CATEGORY_LIST}<br /><br />
 392              {DOWNLOAD_LIST_NEXTPREV}
 393              </div>";
 394      }
 395  
 396      $nextprev_parms = $total_downloads.",".$view.",".$dl_from.",".e_SELF."?[FROM].list.{$id}.{$view}.{$order}.{$sort}.";
 397      echo $tp->parseTemplate($DOWNLOAD_LIST_NEXTPREV, TRUE, $download_shortcodes);
 398  
 399      require_once(FOOTERF);
 400      exit;
 401  }    // end of action=="list"
 402  
 403  
 404  //====================================================
 405  //                VIEW
 406  //====================================================
 407  if ($action == "view")
 408  {
 409      $gen = new convert;
 410  
 411      $highlight_search = FALSE;
 412      if (isset($_POST['highlight_search'])) {
 413          $highlight_search = TRUE;
 414      }
 415  
 416      $query = "
 417          SELECT d.*, dc.* FROM #download AS d
 418          LEFT JOIN #download_category AS dc ON d.download_category = dc.download_category_id
 419          WHERE d.download_id = {$id} AND d.download_active > 0
 420          AND d.download_visible IN (".USERCLASS_LIST.")
 421          AND dc.download_category_class IN (".USERCLASS_LIST.")
 422          LIMIT 1";
 423  
 424      if(!$sql -> db_Select_gen($query)){
 425          require_once(HEADERF);
 426          $ns->tablerender(LAN_dl_18, "<div style='text-align:center'>".LAN_dl_3."</div>");
 427          require_once(FOOTERF);
 428          exit;
 429      }
 430  
 431      $dl = $sql -> db_Fetch();
 432  
 433  $comment_edit_query = 'comment.download.'.$id;
 434  
 435      $load_template = 'download_template';
 436      if (!isset($DOWNLOAD_VIEW_TABLE)) eval($template_load_core);
 437      if(!defined("DL_IMAGESTYLE")){ define("DL_IMAGESTYLE","border:0px");}
 438      if(!isset($DL_VIEW_PAGETITLE))
 439      {
 440          $DL_VIEW_PAGETITLE = PAGE_NAME." / {DOWNLOAD_CATEGORY} / {DOWNLOAD_VIEW_NAME}";
 441      }
 442  
 443      $DL_TITLE = $tp->parseTemplate($DL_VIEW_PAGETITLE, TRUE, $download_shortcodes);
 444  
 445      define("e_PAGETITLE", $DL_TITLE);
 446  
 447      require_once(HEADERF);
 448      $DL_TEMPLATE = varset($DOWNLOAD_VIEW_TABLE_START, '').$DOWNLOAD_VIEW_TABLE.varset($DOWNLOAD_VIEW_TABLE_END, '');
 449      $text = $tp->parseTemplate($DL_TEMPLATE, TRUE, $download_shortcodes);
 450  
 451      if(!isset($DL_VIEW_CAPTION))
 452      {
 453          $DL_VIEW_CAPTION = "{DOWNLOAD_VIEW_CAPTION}";
 454      }
 455  
 456      if(!isset($DL_VIEW_NEXTPREV))
 457      {
 458          $DL_VIEW_NEXTPREV = "
 459          <div style='text-align:center'>
 460              <table style='".USER_WIDTH."'>
 461              <tr>
 462              <td style='width:40%;'>{DOWNLOAD_VIEW_PREV}</td>
 463              <td style='width:20%; text-align: center;'>{DOWNLOAD_BACK_TO_LIST}</td>
 464              <td style='width:40%; text-align: right;'>{DOWNLOAD_VIEW_NEXT}</td>
 465              </tr>
 466              </table>
 467              </div>
 468              ";
 469      }
 470          // ------- Next/Prev -----------
 471      $text .= $tp->parseTemplate($DL_VIEW_NEXTPREV,TRUE,$download_shortcodes);
 472      $caption = $tp->parseTemplate($DL_VIEW_CAPTION,TRUE,$download_shortcodes);
 473  
 474      if(varsettrue($DOWNLOAD_VIEW_TABLE_RENDERPLAIN))
 475      {
 476          echo $text;
 477      }
 478      else
 479      {
 480  
 481          $ns->tablerender($caption, $text);
 482      }
 483  
 484      unset($text);
 485  
 486      if ($dl['download_comment']) {
 487          $cobj->compose_comment("download", "comment", $id, 0, $dl['download_name'], $showrate=FALSE);
 488      }
 489  
 490      require_once(FOOTERF);
 491      exit;
 492  
 493  }
 494  
 495  //====================================================
 496  //                REPORT BROKEN LINKS
 497  //====================================================
 498  if ($action == "report" && check_class($pref['download_reportbroken']))
 499  {
 500      if (!$sql->db_Select("download", "*", "download_id = {$id} AND download_active > 0")) {
 501          require_once(HEADERF);
 502          require_once(FOOTERF);
 503          exit;
 504      }
 505  
 506      $row = $sql -> db_Fetch();
 507      extract($row);
 508  
 509      if (isset($_POST['report_download'])) {
 510          $report_add = $tp -> toDB($_POST['report_add']);
 511          $download_name = $tp -> toDB($download_name);
 512          $user = USER ? USERNAME : LAN_dl_52;
 513  
 514          if ($pref['download_email']) {    // this needs to be moved into the NOTIFY, with an event.
 515              require_once(e_HANDLER."mail.php");
 516              $subject = LAN_dl_60." ".SITENAME;
 517              $report = LAN_dl_58." ".SITENAME.":\n".(substr(SITEURL, -1) == "/" ? SITEURL : SITEURL."/")."download.php?view.".$download_id."\n
 518              ".LAN_dl_59." ".$user."\n".$report_add;
 519              sendemail(SITEADMINEMAIL, $subject, $report);
 520          }
 521  
 522          $sql->db_Insert('generic', "0, 'Broken Download', ".time().",'".USERID."', '{$download_name}', {$id}, '{$report_add}'");
 523  
 524          define("e_PAGETITLE", PAGE_NAME." / ".LAN_dl_47);
 525          require_once(HEADERF);
 526  
 527          $text = LAN_dl_48."<br /><br /><a href='".e_BASE."download.php?view.".$download_id."'>".LAN_dl_49."</a";
 528          $ns->tablerender(LAN_dl_50, $text);
 529  
 530      } else {
 531          define("e_PAGETITLE", PAGE_NAME." / ".LAN_dl_51." ".$download_name);
 532          require_once(HEADERF);
 533  
 534          $text = "<form action='".e_SELF."?report.{$download_id}' method='post'>
 535          <table style='".USER_WIDTH."'>
 536              <tr>
 537              <td  style='width:50%' >
 538              ".LAN_dl_32.": ".$download_name."<br />
 539              <a href='".e_SELF."?view.{$download_id}'>
 540              <span class='smalltext'>".LAN_dl_53."</span>
 541              </a>
 542              </td>
 543              <td style='text-align:center;width:50%'>
 544              </td>
 545              </tr>
 546              <tr>
 547              <td>".LAN_dl_54."<br />".LAN_dl_55."
 548              </td>
 549              <td style='text-align:center;'>
 550              <textarea cols='40' rows='10' class='tbox' name='report_add'></textarea>
 551              </td>
 552              </tr>
 553              <tr>
 554              <td colspan='2' style='text-align:center;'><br />
 555              <input class='button' type='submit' name='report_download' value=\"".LAN_dl_45."\" />
 556              </td>
 557              </tr>
 558              </table></form>";
 559          $ns->tablerender(LAN_dl_50, $text);
 560      }
 561      require_once(FOOTERF);
 562      exit;
 563  }
 564  
 565  
 566  //====================================================
 567  //                MIRRORS
 568  //====================================================
 569  if($action == "mirror")
 570  {
 571      require_once(HEADERF);
 572  
 573      $load_template = 'download_template';
 574      if (!isset($DOWNLOAD_MIRROR_START)) eval($template_load_core);
 575  
 576      $sql -> db_Select("download_mirror");
 577      $mirrorList = $sql -> db_getList("ALL", 0, 200, "mirror_id");
 578  
 579      if($sql -> db_Select("download", "*", "download_id = {$id}"))
 580      {
 581          $row = $sql->db_Fetch();
 582  
 583          extract($row);
 584          $array = explode(chr(1), $download_mirror);
 585  
 586          // Shuffle the mirror list into a random order
 587          $c = count($array) -1;        // Will always be an empty entry at the end
 588          for ($i=1; $i<$c; $i++)
 589          {
 590              $d = mt_rand(0, $i);
 591              $tmp = $array[$i];
 592              $array[$i] = $array[$d];
 593              $array[$d] = $tmp;
 594          }
 595  
 596          $download_mirror = "";
 597          foreach($array as $mirrorstring)
 598          {
 599              if($mirrorstring)
 600              {
 601                  $download_mirror .= parse_download_mirror_table($row, $mirrorstring, $mirrorList);
 602              }
 603          }
 604  
 605          $DOWNLOAD_MIRROR_HOST_LAN = LAN_dl_68;
 606          $DOWNLOAD_MIRROR_GET_LAN = LAN_dl_32;
 607          $DOWNLOAD_MIRROR_LOCATION_LAN = LAN_dl_70;
 608          $DOWNLOAD_MIRROR_DESCRIPTION_LAN = LAN_dl_71;
 609          $DOWNLOAD_MIRROR_REQUEST = LAN_dl_72."'".$download_name."'";
 610  
 611  //        $download_mirror_start = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_MIRROR_START);
 612          $download_mirror_start = $tp->simpleParse($DOWNLOAD_MIRROR_START);
 613  //        $download_mirror_end = preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_MIRROR_END);
 614          $download_mirror_end = $tp->simpleParse($DOWNLOAD_MIRROR_END);
 615          
 616          $text = $download_mirror_start.$download_mirror.$download_mirror_end;
 617  
 618          if($DOWNLOAD_MIRROR_RENDERPLAIN) {
 619              echo $text;
 620          } else {
 621              $ns->tablerender(LAN_dl_67, $text);
 622          }
 623  
 624          require_once(FOOTERF);
 625      }
 626  }
 627  
 628  function parse_download_mirror_table($row, $mirrorstring, $mirrorList)
 629  {
 630      global $pref, $DOWNLOAD_MIRROR, $tp;
 631      $tVars = array();
 632      list($mirrorHost_id, $mirrorHost_url, $mirrorRequests) = explode(",", $mirrorstring);
 633  
 634      extract($mirrorList[$mirrorHost_id]);
 635  
 636      $tVars['DOWNLOAD_MIRROR_NAME'] = "<a href='{$mirror_url}' rel='external'>{$mirror_name}</a>";
 637      $tVars['DOWNLOAD_MIRROR_IMAGE'] = ($mirror_image ? "<a href='{$mirror_url}' rel='external'><img src='".e_FILE."downloadimages/".$mirror_image."' alt='' style='border:0' /></a>" : "");
 638      $tVars['DOWNLOAD_MIRROR_LOCATION'] = ($mirror_location ? $mirror_location : "");
 639      $tVars['DOWNLOAD_MIRROR_DESCRIPTION'] = ($mirror_description ? $mirror_description : "");
 640  
 641      $tVars['DOWNLOAD_MIRROR_FILESIZE'] = parsesize($row['download_filesize']);
 642      $agreetext = '';
 643      if ($pref['agree_flag'])
 644      {
 645          $agreetext = " onclick= \"return confirm('".$tp->toJS($tp->toHTML($pref['agree_text'],FALSE,"parse_sc, defs"))."');\"";
 646      }
 647      $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>";
 648  
 649      $tVars['DOWNLOAD_MIRROR_REQUESTS'] = (ADMIN ? LAN_dl_73.$mirrorRequests : "");
 650      $tVars['DOWNLOAD_TOTAL_MIRROR_REQUESTS'] = (ADMIN ? LAN_dl_74.$mirror_count : "");
 651  
 652      return($tp->simpleParse($DOWNLOAD_MIRROR, $tVars));
 653  }
 654  
 655  function parsesize($size) {
 656      $kb = 1024;
 657      $mb = 1024 * $kb;
 658      $gb = 1024 * $mb;
 659      $tb = 1024 * $gb;
 660      if(!$size)
 661      {
 662          return '0';
 663      }
 664      if ($size < $kb) {
 665          return $size." ".CORE_LAN_B;
 666      }
 667      else if($size < $mb) {
 668          return round($size/$kb, 2)." ".CORE_LAN_KB;
 669      }
 670      else if($size < $gb) {
 671          return round($size/$mb, 2)." ".CORE_LAN_MB;
 672      }
 673      else if($size < $tb) {
 674          return round($size/$gb, 2)." ".CORE_LAN_GB;
 675      } else {
 676          return round($size/$tb, 2)." ".CORE_LAN_TB;
 677      }
 678  }
 679  
 680  
 681  
 682  
 683  function parse_download_cat_parent_table($row)
 684  {
 685      global $tp,$current_row,$DOWNLOAD_CAT_PARENT_TABLE;
 686      extract($row);
 687      $current_row = ($current_row) ? 0 : 1;  // Alternating CSS for each row.(backwards compatible)
 688  
 689      $template = ($current_row == 1) ? $DOWNLOAD_CAT_PARENT_TABLE : str_replace("forumheader3","forumheader3 forumheader3_alt",$DOWNLOAD_CAT_PARENT_TABLE);
 690  
 691      $tVars['DOWNLOAD_CAT_MAIN_ICON'] = '';
 692      $tVars['DOWNLOAD_CAT_MAIN_NAME'] = '';
 693      $tVars['DOWNLOAD_CAT_MAIN_DESCRIPTION'] = '';
 694  
 695      if (check_class($download_category_class))
 696      {
 697          if(strstr($download_category_icon, chr(1)))
 698          {
 699              list($download_category_icon, $download_category_icon_empty) = explode(chr(1), $download_category_icon);
 700          }
 701          $tVars['DOWNLOAD_CAT_MAIN_ICON'] = ($download_category_icon ? "<img src='".e_IMAGE."icons/".$download_category_icon."' alt='' style='float: left' />" : "&nbsp;");
 702          $tVars['DOWNLOAD_CAT_MAIN_NAME'] = $tp->toHTML($download_category_name,FALSE,'TITLE');
 703          $tVars['DOWNLOAD_CAT_MAIN_DESCRIPTION'] = $tp->toHTML($row['download_category_description'],TRUE,'DESCRIPTION');
 704      }
 705  //    return(preg_replace("/\{(.*?)\}/e", '$\1', $template));
 706      return($tp->simpleParse($template, $tVars));
 707  }
 708  
 709  
 710  	  function get_cat_icons($source, $count)
 711        {
 712          if (!$source) return "&nbsp;";
 713          list($ret[TRUE],$ret[FALSE]) = explode(chr(1), $source.chr(1));
 714          if (!$ret[FALSE]) $ret[FALSE] = $ret[TRUE];
 715          return     "<img src='".e_IMAGE."icons/{$ret[($count!=0)]}' alt='' style='float: left' />";
 716        }
 717  
 718  	  function check_new_download($last_val)
 719        {
 720          if(USER && ($last_val > USERLV))
 721          {
 722            return "<img src='".IMAGE_NEW."' alt='' style='vertical-align:middle' />";
 723          }
 724          else
 725          {
 726            return "";
 727          }
 728        }
 729  
 730  
 731  function parse_download_cat_child_table($row)
 732  {
 733      global $tp,$current_row, $DOWNLOAD_CAT_CHILD_TABLE, $DOWNLOAD_CAT_SUBSUB_TABLE;
 734  
 735      $current_row = ($current_row) ? 0 : 1;  // Alternating CSS for each row.(backwards compatible)
 736      $template = ($current_row == 1) ? $DOWNLOAD_CAT_CHILD_TABLE : str_replace("forumheader3","forumheader3 forumheader3_alt",$DOWNLOAD_CAT_CHILD_TABLE);
 737  
 738      $tVars['DOWNLOAD_CAT_SUB_ICON'] = get_cat_icons($row['download_category_icon'],$row['d_count']);
 739      $tVars['DOWNLOAD_CAT_SUB_NEW_ICON'] = check_new_download($row['d_last_subs']);
 740      $dcatname=$tp->toHTML($row['download_category_name'],FALSE,'TITLE');
 741      $tVars['DOWNLOAD_CAT_SUB_NAME'] = ($row['d_count'] ? "<a href='".e_BASE."download.php?list.".$row['download_category_id']."'>".$dcatname."</a>" : $dcatname);
 742      $tVars['DOWNLOAD_CAT_SUB_NAME_LINKED'] = "<a href='".e_BASE."download.php?list.".$row['download_category_id']."'>".$dcatname."</a>";
 743      $tVars['DOWNLOAD_CAT_SUB_DESCRIPTION'] = $tp->toHTML($row['download_category_description'],TRUE,'DESCRIPTION');
 744      $tVars['DOWNLOAD_CAT_SUB_COUNT'] = $row['d_count'];
 745      $tVars['DOWNLOAD_CAT_SUB_SIZE'] = parsesize( $row['d_size']);
 746      $tVars['DOWNLOAD_CAT_SUB_DOWNLOADED'] = intval( $row['d_requests']);
 747      $tVars['DOWNLOAD_CAT_SUBSUB'] = "";
 748      // check for subsub cats ...
 749      foreach($row['subsubcats'] as $subrow)
 750      {
 751        $tVars['DOWNLOAD_CAT_SUBSUB_ICON'] = get_cat_icons($subrow['download_category_icon'],$subrow['d_count']);
 752        $tVars['DOWNLOAD_CAT_SUBSUB_DESCRIPTION'] = $tp->toHTML($subrow['download_category_description'],TRUE,'DESCRIPTION');
 753        $tVars['DOWNLOAD_CAT_SUBSUB_COUNT'] = intval($subrow['d_count']);
 754        $tVars['DOWNLOAD_CAT_SUBSUB_SIZE'] = parsesize($subrow['d_size']);
 755        $tVars['DOWNLOAD_CAT_SUBSUB_DOWNLOADED'] = intval($subrow['d_requests']);
 756  
 757        $tVars['DOWNLOAD_CAT_SUBSUB_NEW_ICON'] = check_new_download($subrow['d_last']);
 758        $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'));
 759  //      $tVars['DOWNLOAD_CAT_SUBSUB'] .= preg_replace("/\{(.*?)\}/e", '$\1', $DOWNLOAD_CAT_SUBSUB_TABLE);
 760        $tVars['DOWNLOAD_CAT_SUBSUB'] .= $tp->simpleParse($DOWNLOAD_CAT_SUBSUB_TABLE, $tVars);
 761      }
 762  
 763  //    return(preg_replace("/\{(.*?)\}/e", '$\1', $template));
 764      return($tp->simpleParse($template, $tVars));
 765  }
 766  
 767  
 768  function parse_download_list_table($row)
 769  {
 770  // ***** $agreetext may not need to be global
 771      global $download_shortcodes,$tp,$current_row,$DOWNLOAD_LIST_TABLE, $rater, $pref, $gen, $agreetext;
 772  
 773      $agreetext = $tp->toHTML(varset($pref['agree_text'], ''),TRUE,"parse_sc");
 774      $current_row = ($current_row) ? 0 : 1;  // Alternating CSS for each row.(backwards compatible)
 775      $template = ($current_row == 1) ? $DOWNLOAD_LIST_TABLE : str_replace("forumheader3","forumheader3 forumheader3_alt",$DOWNLOAD_LIST_TABLE);
 776  
 777      return $tp->parseTemplate($template,TRUE,$download_shortcodes);
 778  
 779  }
 780  
 781  
 782  //=============================================
 783  //        DOWNLOAD CATEGORY CLASS
 784  //=============================================
 785  
 786  class down_cat_handler
 787  {
 788    var $cat_tree;            // Initialised with all categories in a tree structure
 789    var $cat_count;            // Count visible subcats and subsubcats
 790    var $down_count;            // Counts total downloads
 791  
 792    function down_cat_handler($nest_level = 1, $load_class = USERCLASS_LIST, $main_cat_load = '', $accum = FALSE)
 793    {  // Constructor - make a copy of the tree for re-use
 794       // $nest_level = 0 merges subsubcats with subcats. >0 creates full tree.
 795       // If load-class non-null, assumed to be a 'class set' such as USERCLASS_LIST
 796       // If $accum is TRUE, include file counts and sizes in superior categories
 797      define("SUB_PREFIX","-->");                // Added in front of sub categories
 798      define("SUBSUB_PREFIX","---->");        // Added in front of sub-sub categories
 799      $this->cat_tree = $this->down_cat_tree($nest_level,$load_class, $main_cat_load, $accum);
 800    }
 801  
 802  
 803  // Function returns a 'tree' of download categories, subcategories, and sub-sub-categories.
 804  // Returns empty array if nothing defined
 805  // Within the 'main category' level of the nesting, array 'subcats' has the next level's info
 806  // Within the 'sub-category' level of the nesting, array 'subsubcats' has the next level's info
 807  // If $main_cat_load is numeric, and the value of a 'main' category, only that main category is displayed.
 808  //        (Unpredictable if $main_cat_load is some other category)
 809  	function down_cat_tree($nest_level = 1, $load_cat_class = USERCLASS_LIST, $main_cat_load = '', $accum = FALSE)
 810      {
 811        global $sql2;
 812  
 813        $catlist = array();
 814        $this->cat_count = 0;
 815        $this->down_count = 0;
 816        $temp2 = "";
 817        $temp1 = "";
 818        if ($load_cat_class != "")
 819        {
 820          $temp1 = " WHERE dc.download_category_class IN ({$load_cat_class}) ";
 821          $temp2 = "AND d.download_visible IN ({$load_cat_class}) ";
 822        }
 823  
 824        $qry = "
 825        SELECT dc.*,
 826        dc1.download_category_parent AS d_parent1, dc1.download_category_order,
 827        SUM(d.download_filesize) AS d_size,
 828        COUNT(d.download_id) AS d_count,
 829        MAX(d.download_datestamp) as d_last,
 830        SUM(d.download_requested) as d_requests
 831        FROM #download_category as dc
 832        LEFT JOIN #download_category as dc1 ON dc1.download_category_id=dc.download_category_parent
 833        LEFT JOIN #download_category as dc2 ON dc2.download_category_id=dc1.download_category_parent
 834        LEFT JOIN #download AS d on d.download_category = dc.download_category_id AND d.download_active > 0 {$temp2}
 835        {$temp1}
 836        GROUP by dc.download_category_id
 837        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
 838  
 839          if (!$sql2->db_Select_gen($qry)) return $catlist;
 840  
 841        while ($row = $sql2->db_Fetch())
 842        {
 843          $tmp = $row['download_category_parent'];
 844          if ($tmp == '0')
 845          {  // Its a main category
 846            if (!is_numeric($main_cat_load) || ($main_cat_load == $row['download_category_id']))
 847            {
 848              $row['subcats'] = array();
 849              $catlist[$row['download_category_id']] = $row;
 850            }
 851          }
 852          else
 853          {
 854            if (isset($catlist[$tmp]))
 855            {  // Sub-Category
 856              $this->cat_count++;
 857              $this->down_count += $row['d_count'];
 858              $catlist[$tmp]['subcats'][$row['download_category_id']] = $row;
 859              $catlist[$tmp]['subcats'][$row['download_category_id']]['subsubcats'] = array();
 860              $catlist[$tmp]['subcats'][$row['download_category_id']]['d_last_subs'] =
 861                      $catlist[$tmp]['subcats'][$row['download_category_id']]['d_last'];
 862            }
 863            else
 864            {  // Its a sub-sub category
 865              if (isset($catlist[$row['d_parent1']]['subcats'][$tmp]))
 866              {
 867                $this->cat_count++;
 868                $this->down_count += $row['d_count'];
 869                if ($accum || ($nest_level == 0))
 870                {  // Add the counts into the subcategory values
 871                  $catlist[$row['d_parent1']]['subcats'][$tmp]['d_size'] += $row['d_size'];
 872                  $catlist[$row['d_parent1']]['subcats'][$tmp]['d_count'] += $row['d_count'];
 873                  $catlist[$row['d_parent1']]['subcats'][$tmp]['d_requests'] += $row['d_requests'];
 874                }
 875                if ($nest_level == 0)
 876                {  // Reflect subcat dates in category
 877                  if ($catlist[$row['d_parent1']]['subcats'][$tmp]['d_last'] < $row['d_last'])
 878                      $catlist[$row['d_parent1']]['subcats'][$tmp]['d_last'] = $row['d_last'];
 879                }
 880                else
 881                {
 882                  $catlist[$row['d_parent1']]['subcats'][$tmp]['subsubcats'][$row['download_category_id']] = $row;
 883                }
 884                 // Separately accumulate 'last update' for subcat plus associated subsubcats
 885                if ($catlist[$row['d_parent1']]['subcats'][$tmp]['d_last_subs'] < $row['d_last'])
 886                      $catlist[$row['d_parent1']]['subcats'][$tmp]['d_last_subs'] = $row['d_last'];
 887              }
 888            }
 889          }
 890        }
 891        return $catlist;
 892      }
 893  
 894  
 895  // Rest of the class isn't actually used normally, but print_tree() might help with debug
 896  
 897      function print_cat($cat, $prefix,$postfix)
 898      {
 899        $text = "<tr><td>".$cat['download_category_id']."</td><td>".$cat['download_category_parent']."</td><td>";
 900        $text .= $prefix.htmlspecialchars($cat['download_category_name']).$postfix."</td><td>".$cat['d_size']."</td>";
 901        $text .= "<td>".$cat['d_count']."</td><td>".$cat['d_requests']."</td><td>".strftime('%H:%M %d-%m-%Y',$cat['d_last'])."</td>";
 902        $text .= "</tr>";
 903        return $text;
 904      }
 905  
 906  	function print_tree()
 907      {
 908        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>";
 909        foreach ($this->cat_tree as $thiscat)
 910        {  // Main categories
 911          $scprefix = SUB_PREFIX;
 912          echo $this->print_cat($thiscat,'<strong>','</strong>');
 913          foreach ($thiscat['subcats'] as $sc)
 914          {  // Sub-categories
 915            $sscprefix = SUBSUB_PREFIX;
 916            echo $this->print_cat($sc,$scprefix,'');
 917            foreach ($sc['subsubcats'] as $ssc)
 918            {  // Sub-sub categories
 919              echo $this->print_cat($ssc,$sscprefix,'');
 920            }
 921          }
 922        }
 923        echo "</table>";
 924      return;
 925      }
 926  
 927  }
 928  
 929  
 930  
 931  
 932  ?>


Generated: Tue Aug 3 00:19:13 2010
Open Source related documentation for developers.