Ejemplo n.º 1
0
 function test_missingElement()
 {
     $file = '<?xml version="1.0" encoding="utf-8"?>
     <rss version="2.0">
        <channel>
           <title>sample blog</title>
           <link>http://www.example.com/</link>
           <description>sample rss2 feed</description>
           <language>en</language>
           <copyright>Copyright 2006</copyright>
           <lastBuildDate>Tue, 25 Jul 2006 11:53:38 -0500</lastBuildDate>
           <generator>http://www.sixapart.com/movabletype/?v=3.31</generator>
           <docs>http://blogs.law.harvard.edu/tech/rss</docs> 
           <item>
              <title>A sample entry</title>
              <description>Sample content</description>
              <link>http://www.example.com/archives/2006/07</link>
              <guid>http://www.example.com/archives/2006/07</guid>
              <category>Examples</category>
              <pubDate>Tue, 25 Jul 2006 11:53:38 -0500</pubDate>
           </item>
         </channel></rss>';
     $feed = new XML_Feed_Parser($file, false, true);
     $entry = $feed->getEntryByOffset(0);
     $this->assertFalse($entry->enclosure());
 }
 function test_handlesAmpersandsInUrls()
 {
     $xml = file_get_contents($this->sample_dir . "/bug12919.xml");
     $feed = new XML_Feed_Parser($xml);
     $entry = $feed->getEntryById('entry-id');
     $this->assertEquals('<a href="http://www.vzbv.de/start/index.php?page=presse&amp;bereichs_id=25">Linktext</a>', trim($entry->content));
 }
 /**
  * Try to work with this ill-formed feed. If the tidy extension is not installed,
  * it expects parsing to fail. If tidy is installed and parsing fails, the test
  * fails. If tidy is installed and it parses, then the test passes.
  */
 function test_Tidy()
 {
     if (!extension_loaded('tidy')) {
         $this->markTestSkipped("You need the tidy extension installed to run this test");
     }
     $sample_dir = XML_Feed_Parser_TestCase::getSampleDir();
     $file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . "illformed_atom10.xml");
     $feed = new XML_Feed_Parser($file, false, true, true);
     $entry = $feed->getEntryByOffset(0);
     $this->assertEquals($entry->author, 'Example author');
 }
Ejemplo n.º 4
0
 function test_Base()
 {
     $sample_dir = XML_Feed_Parser_TestCase::getSampleDir();
     $file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . "xmlbase.xml");
     try {
         $feed = new XML_Feed_Parser($file, false, true, true);
     } catch (XML_Feed_Parser_Exception $e) {
         $this->assertTrue(false);
     }
     $entry = $feed->getEntryByOffset(0);
     $this->assertEquals($entry->link, 'http://www.tbray.org/ongoing/When/200x/2006/02/17/FSS');
 }
Ejemplo n.º 5
0
 /**
  * Try to work with this ill-formed feed. If the tidy extension is not installed,
  * it expects parsing to fail. If tidy is installed and parsing fails, the test
  * fails. If tidy is installed and it parses, then the test passes.
  */
 function test_Tidy()
 {
     $sample_dir = XML_Feed_Parser_TestCase::getSampleDir();
     $file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . "illformed_atom10.xml");
     try {
         $feed = new XML_Feed_Parser($file, false, true, true);
     } catch (XML_Feed_Parser_Exception $e) {
         if (extension_loaded('tidy')) {
             $this->assertTrue(false);
         } else {
             $this->assertTrue(true);
         }
         return;
     }
     $entry = $feed->getEntryByOffset(0);
     $this->assertEquals($entry->author, 'Example author');
 }
Ejemplo n.º 6
0
 function test_rss_version_missing_1()
 {
     $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/rss/rss_version_missing.xml');
     $feed = new XML_Feed_Parser($content, false, true);
     $this->assertVersionMostlyCorrect('rss', $feed->version());
 }
Ejemplo n.º 7
0
 function test_item_title_1()
 {
     $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/cdf/item_title.xml');
     try {
         $feed = new XML_Feed_Parser($content);
     } catch (XML_Feed_Parser_Exception $e) {
         $this->assertTrue(false);
         return;
     }
     $this->assertEquals('Example item', $feed->getEntryByOffset(0)->title);
 }
Ejemplo n.º 8
0
 function test_relative_xml_base_2_1()
 {
     $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/base/relative_xml_base_2.xml');
     try {
         $feed = new XML_Feed_Parser($content);
     } catch (XML_Feed_Parser_Exception $e) {
         $this->assertTrue(false);
         return;
     }
     $this->assertEquals('http://example.com/test/', $feed->getEntryByOffset(0)->title(0, 'base'));
 }
 function testEntryLink()
 {
     foreach ($this->files as $file) {
         $contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
         $feed = new XML_Feed_Parser($contents);
         $entry = $feed->getEntryByOffset(0);
         $this->assertEquals($entry->link, $entry->link());
     }
 }
Ejemplo n.º 10
0
 function test_rss_version_10_not_default_ns_1()
 {
     $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/rdf/rss_version_10_not_default_ns.xml');
     try {
         $feed = new XML_Feed_Parser($content);
     } catch (XML_Feed_Parser_Exception $e) {
         $this->assertTrue(false);
         return;
     }
     $this->assertEquals('rss10', $feed->version());
 }
Ejemplo n.º 11
0
 function test_item_xhtml_body_xml_lang_inherit_1()
 {
     $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/lang/item_xhtml_body_xml_lang_inherit.xml');
     $feed = new XML_Feed_Parser($content);
     $this->assertEquals('en', $feed->getEntryByOffset(0)->content(0, 'language'));
 }
Ejemplo n.º 12
0
 function test_item_pubDate_rfc2822_1()
 {
     $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/date/item_pubDate_rfc2822.xml');
     $feed = new XML_Feed_Parser($content);
     $this->assertEquals(array(2004, 1, 1, 19, 48, 21, 3, 1, 0), $feed->getEntryByOffset(0)->date_parsed);
 }
Ejemplo n.º 13
0
 function hookLeftColumn($params)
 {
     global $smarty;
     // Conf
     $title = strval(Configuration::get('RSS_FEED_TITLE'));
     $url = strval(Configuration::get('RSS_FEED_URL'));
     $nb = intval(Configuration::get('RSS_FEED_NBR'));
     // Getting data
     if ($contents = @file_get_contents($url)) {
         if ($url) {
             @($src = new XML_Feed_Parser($contents));
         }
         $content = '';
         for ($i = 0; isset($src) and $i < ($nb ? $nb : 5); ++$i) {
             @($item = $src->getEntryByOffset($i));
             $content .= '<li><a href="' . @$item->link . '">' . Tools::htmlentitiesUTF8(@$item->title) . '</a></li>';
         }
     }
     // Display smarty
     $smarty->assign('title', $title ? $title : $this->l('RSS feed'));
     $smarty->assign('content', isset($content) ? $content : '');
     return $this->display(__FILE__, 'blockrss.tpl');
 }
Ejemplo n.º 14
0
 function test_handlesEmptyPubdates()
 {
     $value = '<?xml version="1.0" encoding="utf-8"?>
   <rss version="2.0"
   xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
   <channel>
     <title>Tobbis-Podcast</title>
     <item>
       <title>Entry</title>
     </item>
   </channel>
   </rss>';
     $parsed = new XML_Feed_Parser($value);
     $this->assertEquals(false, $parsed->pubDate);
     $entry = $parsed->entries(0);
     $this->assertEquals(false, $entry['pubDate']);
 }
Ejemplo n.º 15
0
 function test_itunes_link_enclosure_maps_id_2_1()
 {
     $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/itunes/itunes_link_enclosure_maps_id_2.xml');
     $feed = new XML_Feed_Parser($content, false, true);
     $this->assertEquals('http://example.com/id', $feed->getEntryByOffset(0)->id);
 }
Ejemplo n.º 16
0
 function hookLeftColumn($params)
 {
     // Conf
     $title = strval(Configuration::get('RSS_FEED_TITLE'));
     $url = strval(Configuration::get('RSS_FEED_URL'));
     $nb = (int) Configuration::get('RSS_FEED_NBR');
     $cacheId = $this->getCacheId($this->name . '-' . date("YmdH"));
     if (!$this->isCached('blockrss.tpl', $cacheId)) {
         // Getting data
         $rss_links = array();
         if ($url && ($contents = Tools::file_get_contents($url))) {
             try {
                 if (@($src = new XML_Feed_Parser($contents))) {
                     for ($i = 0; $i < ($nb ? $nb : 5); $i++) {
                         if (@($item = $src->getEntryByOffset($i))) {
                             $xmlValues = array();
                             foreach (self::$xmlFields as $xmlField) {
                                 $xmlValues[$xmlField] = $item->__get($xmlField);
                             }
                             $xmlValues['enclosure'] = $item->getEnclosure();
                             # Compatibility
                             $xmlValues['url'] = $xmlValues['link'];
                             $rss_links[] = $xmlValues;
                         }
                     }
                 }
             } catch (XML_Feed_Parser_Exception $e) {
                 Tools::dieOrLog(sprintf($this->l('Error: invalid RSS feed in "blockrss" module: %s'), $e->getMessage()), false);
             }
         }
         // Display smarty
         $this->smarty->assign(array('title' => $title ? $title : $this->l('RSS feed'), 'rss_links' => $rss_links));
     }
     return $this->display(__FILE__, 'blockrss.tpl', $cacheId);
 }
Ejemplo n.º 17
0
    if (!$products) {
        $products = array();
    }
    $products_commasep = join(',', $products);
    $sprink = new Sprinkles();
    $creds = $sprink->current_user_session();
    if (!$creds) {
        $target_page = $preview_after_login ? 'submit.php' : 'handle-submit.php';
        redirect('user-login.php?return=' . urlencode($target_page . '?' . $args));
        exit(0);
    }
    $POST_URL = $api_root . 'companies/' . $sprink->company_sfnid . '/topics';
    $req = $sprink->oauthed_request('POST', $POST_URL, $creds, null, array('topic[subject]' => $subject, 'topic[additional_detail]' => $details, 'topic[style]' => $style, 'topic[keywords]' => $tags, 'topic[products]' => $products_commasep, 'topic[emotitag][face]' => $face, 'topic[emotitag][feeling]' => $emotion));
    $response_body = $req->getResponseBody();
    try {
        $topic_feed = new XML_Feed_Parser($response_body);
    } catch (Exception $e) {
        error("Failed to post new topic; response was: " . $req->getResponseCode() . ", body: " . $response_body);
        throw new Exception($response_body);
    }
    if ($topic_feed->id()) {
        # FIXME: better error checking here.
        redirect('topic.php?id=' . $topic_feed->id());
        exit(0);
    } else {
        print "An error occured";
    }
} catch (Exception $e) {
    error_log("Exception thrown while preparing page: " . $e->getMessage());
    $smarty->display('error.t');
}
Ejemplo n.º 18
0
 function test_rss_version_10_not_default_ns_1()
 {
     $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/rdf/rss_version_10_not_default_ns.xml');
     $feed = new XML_Feed_Parser($content);
     $this->assertEquals('rss10', $feed->version());
 }
 function hookLeftColumn($params)
 {
     // Conf
     $title = strval(Configuration::get('RSS_FEED_TITLE'));
     $url = strval(Configuration::get('RSS_FEED_URL'));
     $nb = (int) Configuration::get('RSS_FEED_NBR');
     $cacheId = $this->getCacheId($this->name . '-' . date("YmdH"));
     if (!$this->isCached('blockrss.tpl', $cacheId)) {
         // Getting data
         $rss_links = array();
         if ($url && ($contents = Tools::file_get_contents($url))) {
             try {
                 if (@($src = new XML_Feed_Parser($contents))) {
                     for ($i = 0; $i < ($nb ? $nb : 5); $i++) {
                         if (@($item = $src->getEntryByOffset($i))) {
                             $xmlValues = array();
                             foreach (self::$xmlFields as $xmlField) {
                                 $xmlValues[$xmlField] = $item->__get($xmlField);
                             }
                             $xmlValues['enclosure'] = $item->getEnclosure();
                             // First image
                             if (isset($xmlValues['content']) && $xmlValues['content']) {
                                 preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/', $xmlValues['content'], $image);
                                 if (array_key_exists(1, $image) && $image[1]) {
                                     // Try if distant image exist : timeout 0.3s
                                     $context = stream_context_create(array('http' => array('timeout' => 0.3)));
                                     if (file_get_contents($image[1], false, $context, -1, 1) !== false) {
                                         $xmlValues['image'] = $image[1];
                                     }
                                 }
                             }
                             // Compatibility
                             $xmlValues['url'] = $xmlValues['link'];
                             $rss_links[] = $xmlValues;
                         }
                     }
                 }
             } catch (XML_Feed_Parser_Exception $e) {
                 Tools::dieOrLog(sprintf($this->l('Error: invalid RSS feed in "blockrss" module: %s'), $e->getMessage()), false);
             }
         }
         // Display smarty
         $this->smarty->assign(array('title' => $title ? $title : $this->l('RSS feed'), 'rss_links' => $rss_links));
     }
     return $this->display(__FILE__, 'blockrss.tpl', $cacheId);
 }
Ejemplo n.º 20
0
 function test_getsLinkWithoutRel()
 {
     $source = '<?xml version="1.0" ?>
     <entry xmlns="http://www.w3.org/2005/Atom">
     <link href="http://example.org/2005/04/02/atom" />
     </entry>
     ';
     $feed = new XML_Feed_Parser($source);
     $entry = $feed->getEntryByOffset(0);
     // Output
     $this->assertEquals("http://example.org/2005/04/02/atom", $entry->link(0, 'href', array('rel' => 'alternate')));
 }
Ejemplo n.º 21
0
 function hookLeftColumn($params)
 {
     // Conf
     $title = strval(Configuration::get('RSS_FEED_TITLE'));
     $url = strval(Configuration::get('RSS_FEED_URL'));
     $nb = (int) Configuration::get('RSS_FEED_NBR');
     // Getting data
     $rss_links = array();
     if ($url && ($contents = @file_get_contents($url))) {
         try {
             if (@($src = new XML_Feed_Parser($contents))) {
                 for ($i = 0; $i < ($nb ? $nb : 5); $i++) {
                     if (@($item = $src->getEntryByOffset($i))) {
                         $rss_links[] = array('title' => $item->title, 'url' => $item->link);
                     }
                 }
             }
         } catch (XML_Feed_Parser_Exception $e) {
             Tools::dieOrLog(sprintf($this->l('Error: invalid RSS feed in "blockrss" module: %s'), $e->getMessage()), false);
         }
     }
     // Display smarty
     $this->smarty->assign(array('title' => $title ? $title : $this->l('RSS feed'), 'rss_links' => $rss_links));
     return $this->display(__FILE__, 'blockrss.tpl');
 }
Ejemplo n.º 22
0
 function hookLeftColumn($params)
 {
     global $smarty;
     // Conf
     $title = strval(Configuration::get('RSS_FEED_TITLE'));
     $url = strval(Configuration::get('RSS_FEED_URL'));
     $nb = (int) Configuration::get('RSS_FEED_NBR');
     // Getting data
     $rss_links = array();
     if ($url && ($contents = @file_get_contents($url))) {
         if (@($src = new XML_Feed_Parser($contents))) {
             for ($i = 0; $i < ($nb ? $nb : 5); $i++) {
                 if (@($item = $src->getEntryByOffset($i))) {
                     $rss_links[] = array('title' => $item->title, 'url' => $item->link);
                 }
             }
         }
     }
     // Display smarty
     $smarty->assign(array('title' => $title ? $title : $this->l('RSS feed'), 'rss_links' => $rss_links));
     return $this->display(__FILE__, 'blockrss.tpl');
 }
Ejemplo n.º 23
0
 function test_amp64_1()
 {
     $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/amp/amp64.xml');
     $feed = new XML_Feed_Parser($content);
     $this->assertEquals('<div><strong>&amp;</strong></div>', $feed->getEntryByOffset(0)->title);
 }
Ejemplo n.º 24
0
 function test_http_text_xml_charset_overrides_encoding_2_1()
 {
     $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/encoding/http_text_xml_charset_overrides_encoding_2.xml');
     $feed = new XML_Feed_Parser($content, false, true);
     $this->assertEquals('This is a \\xa3\\u201ctest.\\u201d', $feed->getEntryByOffset(0)->description);
 }
Ejemplo n.º 25
0
 function test_rss2_0NSwithModulesNoDefNSLocalNameClash_1()
 {
     $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/namespace/rss2.0NSwithModulesNoDefNSLocalNameClash.xml');
     try {
         $feed = new XML_Feed_Parser($content);
     } catch (XML_Feed_Parser_Exception $e) {
         $this->assertTrue(false);
         return;
     }
     $this->assertEquals('correct description', $feed->getEntryByOffset(0)->description);
 }
Ejemplo n.º 26
0
 function test_item_xhtml_body_style_1()
 {
     $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/sanitize/item_xhtml_body_style.xml');
     try {
         $feed = new XML_Feed_Parser($content);
     } catch (XML_Feed_Parser_Exception $e) {
         $this->assertTrue(false);
         return;
     }
     $this->assertEquals('<a href="http://www.ragingplatypus.com/">never trust your upstream platypus</a>', $feed->getEntryByOffset(0)->description);
 }
Ejemplo n.º 27
0
 function test_feed_title_content_type_text_1()
 {
     $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/atom10/feed_title_content_type_text.xml');
     $feed = new XML_Feed_Parser($content);
     $this->assertEquals('text/plain', $feed->title(0, 'type'));
 }
Ejemplo n.º 28
0
 function test_getAlternativeLinkForItem()
 {
     $source = '<?xml version="1.0" ?>
     <entry xmlns="http://www.w3.org/2005/Atom">
     <link rel="replies" href="http://example.org/2005/04/02/atom/comments" />
     <link rel="edit" href="http://example.org/2005/04/02/atom/edit"/>
     <link rel="self" href="http://example.org/2005/04/02/atom/self"/>
     <link rel="alternate" href="http://example.org/2005/04/02/atom" />
     </entry>
     ';
     $feed = new XML_Feed_Parser($source);
     $entry = $feed->getEntryByOffset(0);
     // Output
     $this->assertEquals("http://example.org/2005/04/02/atom", $entry->link(0, 'href', array()));
 }
Ejemplo n.º 29
0
 function test_relative_xml_base_2_1()
 {
     $content = file_get_contents($this->fp_test_dir . DIRECTORY_SEPARATOR . 'wellformed/base/relative_xml_base_2.xml');
     $feed = new XML_Feed_Parser($content, true, true);
     $this->assertEquals('http://example.com/test/', $feed->getEntryByOffset(0)->title(0, 'base'));
 }
 function testEntryLink()
 {
     foreach ($this->files as $file) {
         $contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
         $feed = new XML_Feed_Parser($contents);
         $entry = $feed->getEntryByOffset(0);
         $this->assertTrue($this->checkString('link', $entry), "Failed for {$file}");
     }
 }