Advertisement
virshu

Front end to gPodder

Feb 13th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.65 KB | None | 0 0
  1. <?php
  2. // Upgrade for gPodder 3.0
  3. $db = new SQLite3('gpodder.sqlite');
  4. $channels = $db->query('select id, title from podcast');
  5. ?>
  6. <!DOCTYPE html>
  7. <html>
  8. <head>
  9.     <meta charset="utf-8" />
  10.     <title>gPodder Feeds</title>
  11.     <script src="js/jquery-1.7.1.js" type="text/javascript"></script>
  12.     <script src="js/jquery-ui.js" type="text/javascript"></script>
  13.     <link href="css/gpodder.css" rel="stylesheet" type="text/css" />
  14.     <link href="css/jquery-ui.css" rel="stylesheet" type="text/css" />
  15. <script type="text/javascript">
  16.     $(function() {
  17.         $.datepicker.setDefaults({ dateFormat: 'yy-mm-dd' });
  18.         $(".datepicker").datepicker();
  19.        
  20.         $("form").submit(function(e) {
  21.             var episode = $("#episodeid", $(this)).val();
  22.             $.post('/gpodder/setdate.php', $(this).serialize(), function(data) {
  23.                 $("#pub" + episode).html(data);
  24.             });
  25.             e.preventDefault();
  26.         });
  27.     });
  28. </script>  
  29. </head>
  30.  
  31. <body>
  32.  
  33.     <header>gPodder RSS Feeds</header>
  34.     <nav>
  35. <?php
  36.             while ($row = $channels->fetchArray()) {
  37.                 echo "<p><a href='/gpodder/index.php?id=" . $row["id"] .
  38.                     "'>" . $row["title"] . "</a></p>";
  39.             }
  40. ?>     
  41.     <hr />
  42.     <a href="/gpodder/" >10 latest shows</a>
  43.     </nav>
  44.     <section>
  45. <?php
  46.     $sql = 'select
  47.              e.id episode_id
  48.             , e.url episode_url
  49.             , e.title episode_title
  50.             , e.file_size
  51.             , e.state
  52.             , e.download_filename filename
  53.             , e.description episode_description
  54.             , e.published
  55.             , e.total_time
  56.  
  57.             , c.id channel_id
  58.             , c.title channel_title
  59.             , c.link
  60.             , c.description channel_description
  61.             , c.cover_url image
  62.         from episode e, podcast c
  63.         where e.podcast_id = c.id ';
  64.        
  65.     if (isset($_GET["id"])) {
  66.         $episodes = $db->query($sql . 'and c.id = ' . $_GET["id"] . ' order by published desc');
  67.         $header = true;
  68.     } else {
  69.         $episodes = $db->query($sql . 'order by published desc limit 10');
  70.         $header = false;       
  71.         echo "<h3>10 Latest Feeds</h3>";
  72.     }
  73.    
  74.     while ($row = $episodes->fetchArray()) {
  75.         if ($header) {
  76.             echo "<a href='" . $row["link"] . "'><img width='100' src='" . $row["image"] .
  77.             "' alt='" . $row["channel_title"] . "' /></a><br />";
  78.             echo $row["channel_description"];
  79.             $header = false;
  80.         }
  81.         echo "<p>";
  82.         echo "<a href='" . $row["episode_url"] . "'>" . $row["episode_title"] . "</a><br />";
  83.         if (!isset($_GET["id"])) {
  84.             echo "<b>" . $row["channel_title"] . "</b><br />";
  85.         }
  86.         echo $row["episode_description"] . "<br />";
  87.        
  88.         echo "<div id='pub" . $row["episode_id"] . "'>";
  89.  
  90.         // Ideally get the date from the database
  91.         if ($row["published"] == 0) {
  92.             // Second best - from the file time stamp
  93.             if ($row["state"]) {
  94.                 $filepath = "/var/gPodder/Downloads/" .
  95.                     $row["channel_title"] . "/" . $row["filename"];
  96.                 $tmpDate = new DateTime('@' . filectime($filepath));
  97. ?>
  98. <form>
  99. <input type="text" class="datepicker" name="published" value="<?php echo $tmpDate->format('Y-m-d') ?>" />
  100. <input type="hidden" name="episodeid" id="episodeid" value="<?php echo $row["episode_id"] ?>" />
  101. <input type="submit" value="Set" />
  102. <br />
  103. </form>
  104. <?php                      
  105.             } else {
  106.                 echo "Date not available. <a href='#'>Click to set</a><br />";
  107.             }
  108.         } else {
  109.             $tmpDate = new DateTime('@' . $row["published"]);
  110.             echo $tmpDate->format('Y-m-d') . "<br />";
  111.         }
  112.         echo "</div>";
  113.        
  114.         $sec = $row["total_time"] % 60;
  115.         $min = (int) $row["total_time"] / 60;
  116.         $hr = (int) ($min / 60);
  117.         $min %= 60;
  118.         echo sprintf("%d:%02d:%02d ", $hr, $min, $sec) .
  119.             number_format ($row["file_size"] / 1024) . "KB <img src=" .  
  120.             ($row["state"] ? "'s_success.png' alt='yes'" :
  121.             "'s_error2.png' alt='no'") . "' />";
  122.         echo "</p>\n";
  123.     }
  124. $db->close();
  125. ?> 
  126.  
  127.     </section>
  128. </body>
  129. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement