$sqlrsltGetFeeds->data_seek(0); // Pushes the result cursor to the beginning while ($feed = $sqlrsltGetFeeds->fetch_assoc()) { // Foreach feed found in the table, $domdocFeed = new DOMDocument(); // Class to handle the feed libxml_use_internal_errors(true); // Turns off the screeching errors that aren't my fault if ($domdocFeed->load($feed['link'])) { // If successful loading the feed $intrprtrFeed = new Interpreter(); // Create an interpreter $intrprtrFeed->feed = $feed['id']; $intrprtrFeed->source = $feed['source']; // Set the source $artclFeed = $intrprtrFeed->interpret($domdocFeed); // Interpret the article foreach ($artclFeed as $artclArticle) { // Foreach article if (!$artclArticle->exists($conn)) { // If it's new if ($artclArticle->publish($conn)) { // Add to database if (difference($referenceArticle, $artclArticle) > 0.2) { if (push($secure, $artclArticle)) { // And push print '<a href="' . $artclArticle->link . '">' . $artclArticle->title . '</a>: ' . difference($referenceArticle, $artclArticle) . '<br />'; } else { die("Pusher failed. Boo."); } }
function __autoload($class_name) { set_include_path('class'); include_once $class_name . '.php'; } writeln('BEGIN TESTING INTERPRETER PATTERN'); writeln(''); //load BookList for test data $bookList = new BookList(); $inBook1 = new Book('PHP for Cats', 'Larry Truett'); $inBook2 = new Book('MySQL for Cats', 'Larry Truett'); $bookList->addBook($inBook1); $bookList->addBook($inBook2); $interpreter = new Interpreter($bookList); writeln('test 1 - invalid request missing "book"'); writeln($interpreter->interpret('author 1')); writeln(''); writeln('test 2 - valid book author request'); writeln($interpreter->interpret('book author 1')); writeln(''); writeln('test 3 - valid book title request'); writeln($interpreter->interpret('book title 2')); writeln(''); writeln('test 4 - valid book author title request'); writeln($interpreter->interpret('book author title 1')); writeln(''); writeln('test 5 - invalid request with invalid book number'); writeln($interpreter->interpret('book title 3')); writeln(''); writeln('test 6 - invalid request with nuo numeric book number'); writeln($interpreter->interpret('book title one'));
{ return $this->getTitle() . ' by ' . $this->getAuthor(); } } define('BR', '<' . 'BR' . '>'); echo 'BEGIN TESTING INTERPRETER PATTERN' . BR; echo BR; //load BookList for test data $bookList = new BookList(); $inBook1 = new Book('PHP for Cats', 'Larry Truett'); $inBook2 = new Book('MySQL for Cats', 'Larry Truett'); $bookList->addBook($inBook1); $bookList->addBook($inBook2); $interpreter = new Interpreter($bookList); echo 'test 1 - invalid request missing "book"' . BR; echo $interpreter->interpret('author 1'); echo BR . BR; echo 'test 2 - valid book author request' . BR; echo $interpreter->interpret('book author 1'); echo BR . BR; echo 'test 3 - valid book title request' . BR; echo $interpreter->interpret('book title 2'); echo BR . BR; echo 'test 4 - valid book author title request' . BR; echo $interpreter->interpret('book author title 1'); echo BR . BR; echo 'test 5 - invalid request with invalid book number' . BR; echo $interpreter->interpret('book title 3'); echo BR . BR; echo 'test 6 - invalid request with nuo numeric book number' . BR; echo $interpreter->interpret('book title one');