Skip to content

Commit

Permalink
Fixes to the Feeds parser - Tumblr
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimateprogramer committed Jun 7, 2011
1 parent aefd07a commit 4d7b438
Showing 1 changed file with 53 additions and 9 deletions.
62 changes: 53 additions & 9 deletions Modules/SiSPS/Parsers/FeedsParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private function GetXMLContentEntries($channel, $config, $logger, $feedUrl)

foreach($simple_xml_document->posts->post as $simple_xml_post) {
$contentdate = intval($simple_xml_post["unix-timestamp"]);
$contenttype = $simple_xml_post["type"];

if(isset($lastSuccess) && is_numeric($lastSuccess) && isset($contentdate) && is_numeric($contentdate)) {
$lastSuccessGMTime = strtotime(gmdate("M d Y H:i:s", $lastSuccess));
Expand All @@ -101,18 +102,46 @@ private function GetXMLContentEntries($channel, $config, $logger, $feedUrl)

//Get source data
$source_name = "Tumblr";

$source_name = ($source_name == null || $source_name == "") ? $feedUrl : $source_name . " @ " . $feedUrl;
$source = \Swiftriver\Core\ObjectModel\ObjectFactories\SourceFactory::CreateSourceFromIdentifier($source_name, $channel->trusted);
$source->name = $source_name;
$source->parent = $channel->id;
$source->type = $channel->type;
$source->subType = $channel->subType;

//Extract all the relevant feedItem info
$array_post = (array) $simple_xml_post;
$title = isset($array_post["regular-title"]) ? $array_post["regular-title"] : $simple_xml_post["slug"];
$description = isset($array_post["regular-body"]) ? $array_post["regular-body"] : $array_post["photo-caption"];
$contentLink = $simple_xml_post["url"];
if($contenttype == "regular") {
$source->name = $source_name;
$source->parent = $channel->id;
$source->type = $channel->type;
$source->subType = $channel->subType;

//Extract all the relevant feedItem info
$array_post = (array) $simple_xml_post;
$title = isset($array_post["regular-title"]) ? $array_post["regular-title"] : $simple_xml_post["slug"];
$description = isset($array_post["regular-body"]) ? $array_post["regular-body"] : $array_post["photo-caption"];
$contentLink = $simple_xml_post["url"];
}
else if($contenttype == "photo") {
$source->name = $source_name;
$source->parent = $channel->id;
$source->type = $channel->type;
$source->subType = $channel->subType;

//Extract all the relevant feedItem info
$array_post = (array) $simple_xml_post;
$title = isset($array_post["photo-caption"]) ? "Image posted: ".$this->GenerateTextFromPhotoComment($array_post["photo-caption"])." ".$this->GenerateLink($simple_xml_post["url"]) : "No image description supplied";
$description = isset($array_post["photo-caption"]) ? $array_post["photo-caption"] : null;
$contentLink = $simple_xml_post["url"];
}
else if($contenttype == "video") {
$source->name = $source_name;
$source->parent = $channel->id;
$source->type = $channel->type;
$source->subType = $channel->subType;

//Extract all the relevant feedItem info
$array_post = (array) $simple_xml_post;
$title = isset($array_post["video-source"]) ? "Video posted: ".$array_post["video-source"] : "No video posted";
$description = isset($array_post["video-source"]) ? $array_post["video-source"] : null;
$contentLink = $simple_xml_post["url"];
}

//Create a new Content item
$item = \Swiftriver\Core\ObjectModel\ObjectFactories\ContentFactory::CreateContent($source);
Expand Down Expand Up @@ -239,6 +268,21 @@ private function GetSimplePieContentEntries($channel, $config, $logger, $feedUrl
return $contentItems;
}

private function GenerateImageTag($image_url) {
return "<img src='".$image_url."'/>";
}

private function GenerateLink($link_url) {
return "<a href='$link_url' target='_blank'>Find it here</a>";
}

private function GenerateTextFromPhotoComment($comment) {
$photo_comment = ltrim($comment, "<p>");
$photo_comment = rtrim($photo_comment, "</p>");

return $photo_comment;
}

/**
* This method returns a string array with the names of all
* the source types this parser is designed to parse. For example
Expand Down

0 comments on commit 4d7b438

Please sign in to comment.