Created
June 17, 2011 21:07
-
-
Save atbradley/1032355 to your computer and use it in GitHub Desktop.
Sample event to demonstrate importing outside data (Delicious links from RSS) into the Symphony CMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once(TOOLKIT . '/class.event.php'); | |
Class eventimport_links_from_delicious extends Event{ | |
const ROOTELEMENT = 'import-links-from-delicious'; | |
public $eParamFILTERS = array( | |
'xss-fail', | |
'expect-multiple' | |
); | |
public static function about(){ | |
return array( | |
'name' => 'Import Links From Delicious', | |
'author' => array( | |
'name' => 'Adam Bradley', | |
'website' => 'http://www.webepvd.com', | |
'email' => '[email protected]'), | |
'version' => '1.0', | |
'release-date' => '2011-05-31T01:51:52+00:00', | |
'trigger-condition' => 'action[import-from-delicious]' | |
); | |
} | |
public static function getSource(){ | |
return '8'; | |
} | |
public static function allowEditorToParse(){ | |
return true; | |
} | |
public static function documentation(){ | |
return '<p>This is an example of how to pull data from outside | |
sources and plug them into Symphony (http://www.symphonycms.com). | |
All the real magic happens in the __trigger() function.</p>'; | |
} | |
public function load(){ | |
return $this->__trigger(); | |
} | |
protected function __trigger(){ | |
$did = daydreamlab; //Username to import from. | |
$result = new XMLElement(self::ROOTELEMENT); | |
$index = 0; | |
$fields = array(); | |
$sql = <<<'EOD' | |
SELECT `gmt` | |
FROM `sym_entries_data_33` | |
ORDER BY `gmt` DESC | |
LIMIT 1 | |
EOD; | |
$sql = sprintf($sql, $idrow['entry_id']); | |
$lastdate = Symphony::Database()->fetchRow(0, $sql); | |
$lastdate = !$lastdate ? 0 : $lastdate['gmt']; | |
$url = "http://feeds.delicious.com/v2/rss/$did?count=10"; | |
if ( !$data = @simplexml_load_file($url) ) { | |
$result->appendChild(new XMLElement('error', 'Unable to retrieve data from Delicious.')); | |
return $result; | |
} | |
//TODO:Get all items dated after the most recent we have. (edit the xpath below.) | |
$ditems = $data->xpath('/rss/channel/item'); | |
//Put each item into $_POST['fields']. $_POST['fields'] should | |
//be an int-indexed array of associative post item arrays. | |
foreach ( $ditems as $item ) { | |
//Untested. Inefficient, but the best we can do with RFC822 times | |
//and without being able to limit by date (Delicious doesn't let us). | |
if ( strtotime($item->pubDate) > $lastdate ) { | |
$fields[$index] = array(); | |
$fields[$index]['title'] = (string)$item->title; | |
$fields[$index]['description'] = (string)$item->description; | |
$fields[$index]['url'] = (string)$item->link; | |
$fields[$index]['date-published'] = $item->pubDate; | |
$tags = array(); | |
foreach ( $item->category as $tag ) | |
{ array_push($tags, (string)$tag); } | |
$fields[$index]['tags'] = implode(', ', $tags); | |
$fields[$index]['shared'] = 'yes'; | |
$fields[$index]['visible'] = 'yes'; | |
$index++; | |
} | |
} | |
$_POST['fields'] = $fields; | |
$_POST['action']['import-from-delicious'] = 'Submit'; | |
//Once the above is done, Symphony can do the rest: | |
include(TOOLKIT . '/events/event.section.php'); | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment