rhowaldt

releases_autogenerate.php

Oct 10th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.21 KB | None | 0 0
  1. <?php
  2. function getFileList($dir) {
  3.    // array to hold return value
  4.    $retval = array();
  5.    // add trailing slash if missing
  6.    if(substr($dir, -1) != "/") $dir .= "/";
  7.    // open pointer to directory and read list of files
  8.    $d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
  9.    while(false !== ($entry = $d->read())) {
  10.       // skip hidden files
  11.       if($entry[0] == ".") continue;
  12.       if(is_dir("$dir$entry")) {
  13.          $retval[] = array(
  14.          "name" => "$entry",
  15.          "ext" => '-'
  16.          );
  17.       }
  18.       elseif(is_readable("$dir$entry")) {
  19.          $retval[] = array(
  20.          "name" => "$entry",
  21.          "ext" => pathinfo("$dir$entry", PATHINFO_EXTENSION),
  22.          "size" => filesize("$dir$entry"),
  23.          "lastmod" => filemtime("$dir$entry")
  24.          );
  25.       }
  26.    }
  27.    $d->close();
  28.    return $retval;
  29. }
  30. ?>
  31.  
  32. <?php // THANK YOU! http://www.php.net/manual/en/function.ksort.php#89552
  33. function sksort(&$array, $subkey="id", $sort_ascending=false) {
  34.  
  35.     if (count($array))
  36.         $temp_array[key($array)] = array_shift($array);
  37.  
  38.     foreach($array as $key => $val){
  39.         $offset = 0;
  40.         $found = false;
  41.         foreach($temp_array as $tmp_key => $tmp_val)
  42.         {
  43.             if(!$found and strtolower($val[$subkey]) > strtolower($tmp_val[$subkey]))
  44.             {
  45.                 $temp_array = array_merge(    (array)array_slice($temp_array,0,$offset),
  46.                                             array($key => $val),
  47.                                             array_slice($temp_array,$offset)
  48.                                           );
  49.                 $found = true;
  50.             }
  51.             $offset++;
  52.         }
  53.         if(!$found) $temp_array = array_merge($temp_array, array($key => $val));
  54.     }
  55.  
  56.     if ($sort_ascending) $array = array_reverse($temp_array);
  57.  
  58.     else $array = $temp_array;
  59. }
  60. ?>
  61.  
  62. <?php require_once('build_releasepage.php'); ?>
  63.  
  64. <!-- Put IE into quirks mode -->
  65. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  66.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  67. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  68. <head>
  69. <title>LinuxBBQ &#9733; Releases</title>
  70. <link href="linuxbbq_stylesheet.css" rel="stylesheet" type="text/css" />
  71. <link href='http://fonts.googleapis.com/css?family=Potano+Sans|Spinnaker' rel='stylesheet' type='text/css'>
  72. </head>
  73.  
  74. <body>
  75.  
  76. <div id="container">
  77.  
  78. <div id='mid-col-1'>
  79. <!--empteh-->
  80. </div>
  81. <div id='mid-col-2'>
  82. <h1 id="pagetitle">Releases</h1>
  83. <p>
  84.         <div class="field_1">
  85. <table class="releases">
  86. <tr><td style="font-weight:bold;">Release</td><td style="font-weight:bold;">Version</td></tr>
  87. <?php
  88. $dirlist = getFileList("releases/");
  89. foreach($dirlist as $dir) {
  90.    $filecount = 0;
  91.    echo "<tr>"; echo "<td>"; echo $dir['name']; echo "</td>";
  92.    $dirlength = strlen("{$dir['name']}");
  93.    $filelist = getFileList("releases/{$dir['name']}/");
  94.    sksort($filelist, 'name', true);
  95.    foreach($filelist as $file) {
  96.       if($file['ext'] == "md5") {
  97.          $md5 = file_get_contents("releases/{$dir['name']}/{$file['name']}");
  98.          $md5 = substr("$md5", 0, 32);
  99.       }
  100.       elseif($file['ext'] == "txt") {
  101.          $filename = trim($file['name']);
  102.       }
  103.       elseif($file['ext'] == "iso") {
  104.          if ($filecount != 0) {
  105.             echo "<tr><td></td>";
  106.          }
  107.          $filelength = strlen("{$file['name']}");
  108.          $filesubname = substr("{$file['name']}", 9, 3);
  109.          $iso = $file['name'];
  110.          $returned = build_page("releases/{$dir['name']}", "$filename", "$iso", "$md5");
  111.          echo "<td>{$returned[1]}</td>";
  112.          echo '<td><a href="' . $returned[0] . '">details</a></td>';
  113.          echo "<td><a href='releases/{$dir['name']}/$iso'>download</a></td>";
  114.          if ($filecount != 0) {
  115.             echo "</tr>";
  116.          }
  117.          $filecount += 1;
  118.          $filename = "";
  119.          $md5 = "";
  120.          $iso = "";
  121.       }
  122.    }
  123. }
  124. ?>
  125. </table>
  126.  
  127. </div>
  128. </p>
  129.  
  130. </div>
  131.  
  132. <div id='mid-col-3'>
  133. <!--empteh-->
  134. </div>
  135.  
  136. </div> <!-- end of container -->
  137.  
  138. <div id="header">
  139. <?php
  140.    include_once('head.php');
  141. ?>
  142. </div>
  143.  
  144. <div id="footer">
  145. <?php
  146.    include_once('footer.php');
  147. ?>
  148. </div>
  149.  
  150. </body>
  151. </html>
Advertisement
Add Comment
Please, Sign In to add comment