add('name', PLUGIN_AGGREGATOR_TITLE);
$propbag->add('description', PLUGIN_AGGREGATOR_DESC);
$propbag->add('requirements', array(
'serendipity' => '0.8',
'smarty' => '2.6.7',
'php' => '4.1.0'
));
$propbag->add('version', '0.34');
$propbag->add('author', 'Evan Nemerson, Garvin Hicking, Kristian Koehntopp, Thomas Schulz, Claus Schmidt');
$propbag->add('stackable', false);
$propbag->add('event_hooks', array(
'external_plugin' => true,
'backend_sidebar_entries' => true,
'backend_sidebar_entries_event_display_aggregator' => true,
'cronjob' => true,
'aggregator_feedlist' => true
)
);
$propbag->add('configuration', array('cronjob', 'engine', 'publishflag', 'expire', 'expire_md5', 'ignore_updates', 'delete_dependencies', 'allow_comments', 'markup', 'debug'));
$propbag->add('groups', array('FRONTEND_FULL_MODS'));
$propbag->add('license', 'GPL');
$this->dependencies = array('serendipity_event_entryproperties' => 'keep');
}
function introspect_config_item($name, &$propbag)
{
switch($name) {
case 'publishflag':
$propbag->add('type', 'radio');
$propbag->add('name', PLUGIN_AGGREGATOR_PUBLISH);
$propbag->add('description', '');
$propbag->add('radio', array(
'value' => array('true', 'false'),
'desc' => array(PUBLISH, DRAFT)
));
$propbag->add('default', 'true');
break;
case 'cronjob':
if (class_exists('serendipity_event_cronjob')) {
$propbag->add('type', 'select');
$propbag->add('name', PLUGIN_EVENT_CRONJOB_CHOOSE);
$propbag->add('description', '');
$propbag->add('default', 'daily');
$propbag->add('select_values', serendipity_event_cronjob::getValues());
} else {
$propbag->add('type', 'content');
$propbag->add('default', PLUGIN_AGGREGATOR_CRONJOB);
}
break;
case 'debug':
$propbag->add('type', 'boolean');
$propbag->add('name', PLUGIN_AGGREGATOR_DEBUG);
$propbag->add('description', PLUGIN_AGGREGATOR_DEBUG_BLAHBLAH);
$propbag->add('default', false);
break;
case 'markup':
$plugins = serendipity_plugin_api::get_event_plugins();
$markups = array();
if (is_array($plugins)) {
// foreach() operates on copies of values, but we want to operate on references, so we use while()
@reset($plugins);
while(list($plugin, $plugin_data) = each($plugins)) {
if (!is_array($plugin_data['p']->markup_elements)) {
continue;
}
$markups[$plugin_data['p']->instance] = (function_exists('serendipity_specialchars') ? serendipity_specialchars($plugin_data['p']->title) : htmlspecialchars($plugin_data['p']->title, ENT_COMPAT, LANG_CHARSET));
}
}
$propbag->add('type', 'multiselect');
$propbag->add('name', PLUGIN_AGGREGATOR_MARKUP_DISABLE);
$propbag->add('description', PLUGIN_AGGREGATOR_MARKUP_DISABLE_DESC);
$propbag->add('select_values', $markups);
$propbag->add('select_size', 6);
$propbag->add('default', '');
break;
case 'engine':
$propbag->add('type', 'radio');
$propbag->add('radio', array('value' => array('onyx', 'magpierss','simplepie'),
'desc' => array('Onyx [BSD]', 'MagpieRSS [GPL]', 'SimplePie')));
$propbag->add('name', PLUGIN_AGGREGATOR_CHOOSE_ENGINE);
$propbag->add('description', PLUGIN_AGGREGATOR_CHOOSE_ENGINE_DESC);
$propbag->add('default', 'onyx');
break;
case 'delete_dependencies':
$propbag->add('type', 'boolean');
$propbag->add('name', PLUGIN_AGGREGATOR_DELETEDEPENDENCIES);
$propbag->add('description', PLUGIN_AGGREGATOR_DELETEDEPENDENCIES_DESC);
$propbag->add('default', true);
break;
case 'expire':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_AGGREGATOR_EXPIRE);
$propbag->add('description', PLUGIN_AGGREGATOR_EXPIRE_BLAHBLAH);
$propbag->add('default', 2);
break;
case 'expire_md5':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_AGGREGATOR_EXPIRE_MD5);
$propbag->add('description', PLUGIN_AGGREGATOR_EXPIRE_MD5_BLAHBLAH);
$propbag->add('default', 90);
break;
case 'ignore_updates':
$propbag->add('type', 'boolean');
$propbag->add('name', PLUGIN_AGGREGATOR_IGNORE_UPDATES);
$propbag->add('description', PLUGIN_AGGREGATOR_IGNORE_UPDATES_DESC);
$propbag->add('default', false);
break;
case 'allow_comments':
$propbag->add('type', 'boolean');
$propbag->add('name', COMMENTS_ENABLE);
$propbag->add('description', '');
$propbag->add('default', false);
break;
default:
return false;
}
return true;
}
function setupDB() {
global $serendipity;
# Old Schema
if (! serendipity_db_bool($this->get_config('db_built', false))) {
$sql = "CREATE TABLE {$serendipity['dbPrefix']}aggregator_feeds (
feedid {AUTOINCREMENT} {PRIMARY},
feedname varchar(255) NOT NULL default '',
feedurl varchar(255) NOT NULL default '',
htmlurl varchar(255) NOT NULL default '',
categoryid int(11) default NULL,
last_update int(10) {UNSIGNED} default null,
charset varchar(255) NOT NULL default ''
);";
serendipity_db_schema_import($sql);
$this->set_config('db_built', 'true');
}
# Schema extension (version 2)
if ($this->get_config('db_version') < 2) {
echo "*** setup DB version " . $this->get_config('db_version'). "
\n";
$sql = "CREATE TABLE {$serendipity['dbPrefix']}aggregator_md5 (
entryid {AUTOINCREMENT} {PRIMARY},
md5 varchar(32) NOT NULL default '',
timestamp int(10) {UNSIGNED} default null,
key md5_idx (md5),
key timestamp_idx (timestamp)
);";
serendipity_db_schema_import($sql);
$sql = "INSERT INTO {$serendipity['dbPrefix']}aggregator_md5
( entryid, md5, timestamp )
SELECT entryid, value, " . time() .
" FROM {$serendipity['dbPrefix']}entryproperties
WHERE property = 'ep_aggregator_md5'";
serendipity_db_query($sql);
$sql = "DELETE FROM {$serendipity['dbPrefix']}entryproperties
WHERE property = 'ep_aggregator_md5'";
serendipity_db_query($sql);
$this->set_config('db_version', '2');
}
# Schema extension (version 3)
if ($this->get_config('db_version') < 3) {
echo "*** setup DB version " . $this->get_config('db_version'). "
\n";
$sql = "CREATE TABLE {$serendipity['dbPrefix']}aggregator_feedcat (
feedid int(11) not null,
categoryid int(11) not null
);";
serendipity_db_schema_import($sql);
$sql = "CREATE UNIQUE INDEX feedid_idx
ON {$serendipity['dbPrefix']}aggregator_feedcat (feedid, categoryid);";
serendipity_db_schema_import($sql);
$sql = "INSERT INTO {$serendipity['dbPrefix']}aggregator_feedcat
( feedid, categoryid )
SELECT feedid, categoryid
FROM {$serendipity['dbPrefix']}aggregator_feeds";
serendipity_db_query($sql);
$sql = "DELETE FROM {$serendipity['dbPrefix']}entryproperties
WHERE property = 'ep_aggregator_md5'";
serendipity_db_query($sql);
$sql = "ALTER TABLE {$serendipity['dbPrefix']}aggregator_feeds
DROP categoryid;";
serendipity_db_schema_import($sql);
$this->set_config('db_version', '3');
}
# Schema extension (version 4)
if ($this->get_config('db_version') < 4) {
$sql = "ALTER TABLE {$serendipity['dbPrefix']}aggregator_feeds
ADD COLUMN charset varchar(255);";
serendipity_db_schema_import($sql);
$this->set_config('db_version', '4');
}
# Schema extension (version 5)
if ($this->get_config('db_version') < 5) {
$sql = "ALTER TABLE {$serendipity['dbPrefix']}aggregator_feeds
ADD COLUMN match_expression varchar(255);";
serendipity_db_schema_import($sql);
$this->set_config('db_version', '5');
}
# Schema extension (version 6)
if ($this->get_config('db_version') < 6) {
$sql = "CREATE TABLE {$serendipity['dbPrefix']}aggregator_feedlist (
id {AUTOINCREMENT} {PRIMARY},
feedid int(11) not null,
categoryid int(11) not null,
entrydate int(11) not null,
entrytitle text,
entrybody longtext,
entryurl text
);";
serendipity_db_schema_import($sql);
$sql = "ALTER TABLE {$serendipity['dbPrefix']}aggregator_feeds
ADD COLUMN feedicon text;";
serendipity_db_schema_import($sql);
$this->set_config('db_version', '6');
}
if ($this->get_config('db_version') < 7) {
$sql = "CREATE INDEX fl_feedid ON {$serendipity['dbPrefix']}aggregator_feedlist (feedid)";
serendipity_db_schema_import($sql);
$sql = "CREATE INDEX fl_entrydate ON {$serendipity['dbPrefix']}aggregator_feedlist (entrydate)";
serendipity_db_schema_import($sql);
$sql = "CREATE INDEX fl_categoryid ON {$serendipity['dbPrefix']}aggregator_feedlist (categoryid)";
serendipity_db_schema_import($sql);
$sql = "CREATE INDEX fl_feedid_2 ON {$serendipity['dbPrefix']}aggregator_feedlist (feedid, entrydate)";
serendipity_db_schema_import($sql);
$sql = "CREATE INDEX fl_feedid_3 ON {$serendipity['dbPrefix']}aggregator_feedlist (feedid, entrydate, categoryid)";
serendipity_db_schema_import($sql);
$this->set_config('db_version', '7');
}
}
function &getFeeds($opt = null) {
global $serendipity;
$this->setupDB();
if ($opt['category'] > 0) {
$where = "WHERE fc.categoryid IN (" . $opt['category'] . ")";
}
$sql = "SELECT f.feedid, f.feedname, f.feedurl, f.htmlurl, fc.categoryid, f.last_update, f.charset, f.feedicon, f.match_expression
FROM {$serendipity['dbPrefix']}aggregator_feeds AS f
LEFT OUTER JOIN {$serendipity['dbPrefix']}aggregator_feedcat AS fc
ON f.feedid = fc.feedid
$where
ORDER BY feedname, f.feedid
";
$feeds = serendipity_db_query($sql, false, 'assoc');
// prepare array
$ret = array();
if (is_array($feeds)) {
foreach ($feeds as $feed) {
$category = $feed['categoryid'];
if (!isset($ret[$feed['feedid']])) {
unset($feed['categoryid']);
$ret[$feed['feedid']] = $feed;
}
$ret[$feed['feedid']]['categoryids'][] = $category;
}
}
$feeds = array_values($ret);
if (!is_array($feeds)) {
return array();
} else {
return $feeds;
}
}
function removeFeeds() {
global $serendipity;
if (!serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}aggregator_feedcat")) {
return false;
}
return serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}aggregator_feeds");
}
function createFeeds() {
global $serendipity;
$this->setupDB();
$feeds = $this->getFeeds();
foreach($serendipity['POST']['feed'] AS $idx => $array) {
if (empty($idx)) {
if (empty($array['feedurl']) && empty($array['feedname']) && empty($array['htmlurl'])) {
continue;
} elseif (empty($array['feedurl']) || empty($array['feedname'])) {
echo '