Skip to content

Commit

Permalink
send notifications for cron-created imports if plugin setting allows
Browse files Browse the repository at this point in the history
  • Loading branch information
beck24 committed Dec 16, 2015
1 parent 5fd13db commit b8a8d50
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

x.x:

2.1.1 (12/16/2015):
- send notifications for cron-created imports if plugin setting allows

2.1.0 (12/10/2015):
- remove group options if not enabled globally
- added plugin setting for optional river entries on import
Expand Down
31 changes: 26 additions & 5 deletions lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,41 @@ function cron_import($period) {
if (!RSSImport::groupGatekeeper($rssimport->getContainerEntity(), $rssimport->import_into, false)) {
continue;
}

// need to log in as the rssimport owner in case notifications are enabled
$logged_in_user = elgg_get_logged_in_user_entity();

// also need to prevent any login/logout forwards that can interrupt us
elgg_register_plugin_hook_handler('forward', 'all', __NAMESPACE__ . '\\prevent_forward');

$owner = $rssimport->getOwnerEntity();
if ($owner) {
login($owner);
}

//get the feed
$feed = $rssimport->getFeed();
$history = array();
$items = $feed->get_items(0, 0);
if (is_array($items)) {
foreach ($items as $item) {
if (!$rssimport->isAlreadyImported($item) && !$rssimport->isBlacklisted($item)) {
$history[] = $rssimport->importItem($item);
}
}
foreach ($items as $item) {
if (!$rssimport->isAlreadyImported($item) && !$rssimport->isBlacklisted($item)) {
$history[] = $rssimport->importItem($item);
}
}
}

$rssimport->addToHistory($history);

if ($owner) {
logout();
}

if ($logged_in_user) {
login($logged_in_user);
}

elgg_unregister_plugin_hook_handler('forward', 'all', __NAMESPACE__ . '\\prevent_forward');
}

elgg_set_ignore_access(false);
Expand Down
13 changes: 13 additions & 0 deletions lib/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,17 @@ function prevent_notifications($hook, $type, $return, $params) {
}

return $return;
}

/**
* called on the forward plugin hook, prevents the forward
*
* @param type $hook
* @param type $type
* @param type $return
* @param type $params
* @return boolean
*/
function prevent_forward($hook, $type, $return, $params) {
return false; // no forwarding
}
2 changes: 1 addition & 1 deletion manifest.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0" encoding="UTF-8"?><plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8"> <name>RSS Import</name> <id>rssimport</id> <author>Matt Beckett ([email protected])</author> <version>2.1.0</version> <description>Import rss feed items into blogs, bookmarks, and pages</description> <website>http://mattbecket.me</website> <copyright>(C) Athabasca University</copyright> <license>GNU Public License version 2</license> <!-- All plugins must require either elgg_version or elgg_release. --> <requires> <type>elgg_release</type> <version>1.9</version> </requires> <suggests> <type>plugin</type> <name>blog</name> </suggests> <suggests> <type>plugin</type> <name>bookmarks</name> </suggests> <suggests> <type>plugin</type> <name>pages</name> </suggests> <screenshot> <description>Import option available on content creation and personal listings</description> <path>screenshots/rssimport1.jpg</path> </screenshot> <screenshot> <description>Feed creation form</description> <path>screenshots/rssimport2.jpg</path> </screenshot> <screenshot> <description>Content in a feed, ready to be imported</description> <path>screenshots/rssimport3.jpg</path> </screenshot> <screenshot> <description>Content imported into a blog</description> <path>screenshots/rssimport4.jpg</path> </screenshot> <category>rss</category></plugin_manifest>
<?xml version="1.0" encoding="UTF-8"?><plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8"> <name>RSS Import</name> <id>rssimport</id> <author>Matt Beckett ([email protected])</author> <version>2.1.1</version> <description>Import rss feed items into blogs, bookmarks, and pages</description> <website>http://mattbecket.me</website> <copyright>(C) Athabasca University</copyright> <license>GNU Public License version 2</license> <!-- All plugins must require either elgg_version or elgg_release. --> <requires> <type>elgg_release</type> <version>1.9</version> </requires> <suggests> <type>plugin</type> <name>blog</name> </suggests> <suggests> <type>plugin</type> <name>bookmarks</name> </suggests> <suggests> <type>plugin</type> <name>pages</name> </suggests> <screenshot> <description>Import option available on content creation and personal listings</description> <path>screenshots/rssimport1.jpg</path> </screenshot> <screenshot> <description>Feed creation form</description> <path>screenshots/rssimport2.jpg</path> </screenshot> <screenshot> <description>Content in a feed, ready to be imported</description> <path>screenshots/rssimport3.jpg</path> </screenshot> <screenshot> <description>Content imported into a blog</description> <path>screenshots/rssimport4.jpg</path> </screenshot> <category>rss</category></plugin_manifest>
Expand Down

0 comments on commit b8a8d50

Please sign in to comment.