Changeset 185

Show
Ignore:
Timestamp:
10/24/08 01:32:46 (3 months ago)
Author:
drarok
Message:

* Implemented autoloading of classes.
* Renamed nzb-helper.php to nzb.php (related to autoload).
* Added a new class for feed management.
* Created a command-line tool for feed management. (See HellaWorldInfo on the wiki).
* Merged cron.php functionality into new feed management tool.

Location:
hellaworld/branches/autonzb
Files:
3 added
1 removed
4 modified
1 moved

Legend:

Unmodified
Added
Removed
  • hellaworld/branches/autonzb

    • Property svn:ignore
      •  

        old new  
        22._* 
        33feeds.xml 
         4completed.xml 
  • hellaworld/branches/autonzb/classes/nzb.php

    r179 r185  
    1717                ); 
    1818        } 
     19         
     20        public static function add_feed($dataset, $url) { 
     21                // Check we don't already have this feed... 
     22                foreach ($dataset->feed as $feed) 
     23                        if ($feed['url'] == $url) 
     24                                throw new Exception('Feed already exists.'); 
     25                         
     26                // Add the new feed! 
     27                $atom = new Atom_Feed($url); 
     28                $latest = reset($atom->entry); 
     29                $parsed = nzb::parse($latest); 
     30                 
     31                $feed = $dataset->addNode('feed', array('url' => $url)); 
     32                $feed->addAttribute('name', $parsed->show); 
     33                $feed->addAttribute('latest_episode', $parsed->episode); 
     34        } 
    1935} 
  • hellaworld/branches/autonzb/classes/xml-dataset.php

    r179 r185  
    2626                return $this->root->$key; 
    2727        } 
     28         
     29        public function asXML() { 
     30                return $this->root->asXML(); 
     31        } 
    2832 
    2933        function addNode($name, $attributes = array()) { 
  • hellaworld/branches/autonzb/index.php

    r179 r185  
    9797                $protocol = (($_SERVER['SERVER_PORT'] == 443) ? 'https' : 'http'); 
    9898 
    99                 require_once 'classes/HellaController.php'; 
    100                  
    101                 require_once('classes/xml-dataset.php'); 
    102                 require_once('classes/atom-feed.php'); 
    103                 require_once('classes/nzb-helper.php'); 
     99                require_once 'classes/autoload.php'; 
    104100 
    105101                if ($auth == 'exclusive' && !ipInRange($iprange, $_SERVER['REMOTE_ADDR'])) { 
     
    360356                 
    361357                // Auto-NZB 
    362                 if (array_key_exists('addfeed', $_GET)) {        
    363                         $dataset = new XML_Dataset('./feeds.xml'); 
    364                          
    365                         // Check we don't already have this feed... 
    366                         foreach ($dataset->feed as $feed) 
    367                                 if ($feed->attributes()->url == $_GET['addfeed']) 
    368                                         throw new Exception('Feed already processed.'); 
    369                          
    370                         // Add the new feed! 
    371                         $atom = new Atom_Feed($_GET['addfeed']); 
    372                         $latest = reset($atom->entry); 
    373                         $parsed = nzb::parse($latest); 
    374                          
    375                         $feed = $dataset->addNode('feed', array('url' => $_GET['addfeed'])); 
    376                         $feed->addAttribute('name', $parsed->show); 
    377                         $feed->addAttribute('latest_episode', $parsed->episode); 
    378                         $dataset->save();                                        
     358                if (array_key_exists('addfeed', $_GET)) { 
     359                        $manager = new Feed_Manager(); 
     360                        $manager->add($_GET['addfeed']); 
    379361                } 
    380362 
  • hellaworld/branches/autonzb/templates/default.php

    r179 r185  
    218218                <ul> 
    219219<?php 
    220         if (! isset($dataset)) 
    221                 $dataset = new XML_Dataset('./feeds.xml'); 
    222         if (count($dataset->feed) == 0) 
     220        // We might need to instantiate a manager. 
     221        if (! isset($manager)) 
     222                $manager = new Feed_Manager(); 
     223         
     224        // Grab the feeds. 
     225        $feeds = $manager->feeds(TRUE); 
     226         
     227        // Are there any to show? 
     228        if (count($feeds) == 0) 
    223229                echo '<li>There are no feeds to display.</li>', "\n"; 
    224230        else 
    225                 foreach ($dataset->feed as $feed) { 
    226                         $attrs = $feed->attributes(); 
    227                         echo sprintf('<li>%s (%s)</li>', $attrs->name, $attrs->latest_episode), "\n"; 
    228                 } 
     231                foreach ($feeds as $feed) 
     232                        echo sprintf('<li>%s (%s)</li>', 
     233                                $feed['name'], $feed['latest_episode']), "\n"; 
    229234?> 
    230235                </ul>