public function testCroppingOfText()
 {
     $item = new \Swiftriver\Core\ObjectModel\Content();
     $title = "x";
     for ($i = 0; $i < 2500; $i++) {
         $title .= " x";
     }
     $item->SetTitle($title);
     $parser = new TextForUrlParser($item);
     $this->assertEquals(2000, strlen($parser->GetUrlText()));
 }
 public function testWithGoodButSmallJSON()
 {
     $content = new \Swiftriver\Core\ObjectModel\Content();
     $content->SetId("testId");
     $json = '{"memes":[{"source":"http://www.knallgrau.at/en","updated":"Mon May 15 13:38:14 CEST 2006","dimensions":{"topic":["knallgrau","twoday","platform","Contact","content","software","management","blog","business","company"]}}]}';
     $parser = new ContentFromJSONParser($content, $json);
     $item = $parser->GetTaggedContent();
     $this->assertEquals(10, count($item->GetTags()));
     $tags = $item->GetTags();
     $firsttag = $tags[0];
     $this->assertEquals("what", $firsttag->GetType());
     $this->assertEquals("knallgrau", $firsttag->GetText());
     $lasttag = $tags[9];
     $this->assertEquals("what", $lasttag->GetType());
     $this->assertEquals("company", $lasttag->GetText());
 }
Esempio n. 3
0
 /**
  * Implementation of IParser::GetAndParse
  * @param string[][] $parameters
  * Required Parameter Values =
  *  'feedUrl' = The url to the RSS feed
  */
 public function GetAndParse($parameters)
 {
     //Extract the required variables
     $feedUrl = $parameters["feedUrl"];
     if (!isset($feedUrl) || $feedUrl == "") {
         return null;
     }
     //Create the source that will be used by all the content items
     //Passing in the feed uri which can be used to uniquly
     //identify the source of the content
     $source = new \Swiftriver\Core\ObjectModel\Source($feedUrl);
     //Include the Simple Pie Framework to get and parse feeds
     $config = \Swiftriver\Core\Setup::Configuration();
     include_once $config->ModulesDirectory . "/SimplePie/simplepie.inc";
     //Construct a new SimplePie Parsaer
     $feed = new \SimplePie();
     //Set the caching directory
     $feed->set_cache_location($config->CachingDirectory);
     //Pass the feed URL to the SImplePie object
     $feed->set_feed_url($feedUrl);
     //Run the SimplePie
     $feed->init();
     //Create the Content array
     $contentItems = array();
     //Loop throught the Feed Items
     foreach ($feed->get_items() as $feedItem) {
         //Extract all the relevant feedItem info
         $id = \Swiftriver\Core\ObjectModel\Content::GenerateUniqueId();
         $title = $feedItem->get_title();
         $description = $feedItem->get_description();
         $contentLink = $feedItem->get_permalink();
         //Create a new Content item
         $item = new \Swiftriver\Core\ObjectModel\Content();
         //Fill the COntenty Item
         $item->SetId($id);
         $item->SetTitle($title);
         $item->SetLink($contentLink);
         $item->SetText(array($description));
         $item->SetSource($source);
         //Add the item to the Content array
         $contentItems[] = $item;
     }
     //return the content array
     return $contentItems;
 }
 public function testParseWithOneContentItemWithNoDifs()
 {
     $content = new \Swiftriver\Core\ObjectModel\Content();
     $content->SetId("testId");
     $contentItems = array($content);
     $json = $this->object->Parse($contentItems);
     $this->assertEquals(null, $json);
 }
Esempio n. 5
0
 public function GetAndParse($parameters)
 {
     $item = new \Swiftriver\Core\ObjectModel\Content();
     $item->SetId("testId");
     return array($item);
 }