public function GetUrlText() { //Validation checks if (!isset($this->content)) { return null; } //Get the title for the content $urlText = $this->content->GetTitle(); //Get the lines of text $textLines = $this->content->GetText(); //Loop through all text from the content if (isset($textLines)) { foreach ($textLines as $text) { $urlText .= " " . $text; } } //encode the text ready for transmission $urlText = utf8_encode($urlText); $urlText = urlencode($urlText); //If the text is long, truncate it to the apache standard length (2000) if (strlen($urlText) > 2000) { $urlText = substr($urlText, 0, 2000); } //Return the url text return $urlText; }
/** * Given a content ite, * @return string */ public function GetCurrentState() { $state = $this->content->GetState(); if (!isset($state) || !is_numeric($state) || $state >= count($this->States)) { $state = 0; } return $this->States[$state]; }
/** * Using the constructor parameters, this method * decodes the JSON and applies any tags that could be * extracted from the content. It returns the content * with taggs. * * @return \Swiftriver\Core\ObjectModel\Content */ public function GetTaggedContent() { //Validity Checks if (!isset($this->content)) { return null; } if (!isset($this->json)) { return $this->content; } if ($this->json == "") { return $this->content; } //decode the JSON string $objects = json_decode($this->json, true); //Check for malformed JSON if (!isset($objects)) { return $this->content; } //Array to hold the tags for this content $tags = array(); //Get the tops form the JSON $topics = $objects["memes"][0]["dimensions"]["topic"]; if (isset($topics) && is_array($topics)) { foreach ($topics as $topic) { $tags[] = new \Swiftriver\Core\ObjectModel\Tag($topic, "what"); } } //Get the locatioins from the JSON $locations = $objects["memes"][0]["dimensions"]["location"]; if (isset($locations) && is_array($locations)) { foreach ($locations as $location) { $tags[] = new \Swiftriver\Core\ObjectModel\Tag($location, "where"); } } //Get the people from the JSON $persons = $objects["memes"][0]["dimensions"]["person"]; if (isset($persons) && is_array($persons)) { foreach ($persons as $person) { $tags[] = new \Swiftriver\Core\ObjectModel\Tag($person, "who"); } } //Add the tags to the content $this->content->SetTags($tags); //return the tagged content return $this->content; }
/** * 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; }