Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robert Soden
committed
Feb 19, 2010
1 parent
805fff6
commit 98f93c5
Showing
9 changed files
with
382 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
// $Id$ | ||
|
||
/** | ||
* Helper to implementation of hook_ctools_plugin_api(). | ||
*/ | ||
function _mn_slingshot_ctools_plugin_api() { | ||
$args = func_get_args(); | ||
$module = array_shift($args); | ||
$api = array_shift($args); | ||
if ($module == "feeds" && $api == "feeds_importer_default") { | ||
return array("version" => 1); | ||
} | ||
else if ($module == "keyauth" && $api == "keyauth_key_default") { | ||
return array("version" => 1); | ||
} | ||
else if ($module == "strongarm" && $api == "strongarm") { | ||
return array("version" => 1); | ||
} | ||
} | ||
|
||
/** | ||
* Helper to implementation of hook_feeds_importer_default(). | ||
*/ | ||
function _mn_slingshot_feeds_importer_default() { | ||
$export = array(); | ||
$feeds_importer = new stdClass; | ||
$feeds_importer->disabled = FALSE; /* Edit this to true to make a default feeds_importer disabled initially */ | ||
$feeds_importer->api_version = 1; | ||
$feeds_importer->id = 'slingshot'; | ||
$feeds_importer->config = array( | ||
'name' => 'Slingshot', | ||
'description' => 'Imports items from SMS', | ||
'fetcher' => array( | ||
'plugin_key' => 'FeedsSlingshotFetcher', | ||
'config' => array( | ||
'auto_detect_feeds' => FALSE, | ||
'use_keyauth' => FALSE, | ||
'keyauth_public' => '', | ||
'subscription_period' => 86400, | ||
), | ||
), | ||
'parser' => array( | ||
'plugin_key' => 'FeedsSlingshotParser', | ||
'config' => array(), | ||
), | ||
'processor' => array( | ||
'plugin_key' => 'FeedsDataProcessor', | ||
'config' => array( | ||
'update_existing' => 0, | ||
'expire' => -1, | ||
'mappings' => array( | ||
'0' => array( | ||
'source' => 'timestamp', | ||
'target' => 'timestamp', | ||
'unique' => 0, | ||
), | ||
'1' => array( | ||
'source' => 'title', | ||
'target' => 'title', | ||
'unique' => 0, | ||
), | ||
'2' => array( | ||
'source' => 'description', | ||
'target' => 'description', | ||
'unique' => FALSE, | ||
), | ||
), | ||
), | ||
), | ||
'content_type' => 'slingshot_feed', | ||
'update' => 0, | ||
'import_period' => '-1', | ||
'expire_period' => 3600, | ||
'import_on_create' => 0, | ||
); | ||
|
||
$export['slingshot'] = $feeds_importer; | ||
return $export; | ||
} | ||
|
||
/** | ||
* Helper to implementation of hook_keyauth_key_default(). | ||
*/ | ||
function _mn_slingshot_keyauth_key_default() { | ||
$export = array(); | ||
$keyauth_keys = new stdClass; | ||
$keyauth_keys->disabled = FALSE; /* Edit this to true to make a default keyauth_keys disabled initially */ | ||
$keyauth_keys->api_version = 1; | ||
$keyauth_keys->title = 'Slingshot'; | ||
$keyauth_keys->public_key = 'acf8b2bb295ccb58c1ad4e3a376a81cb'; | ||
$keyauth_keys->private_key = 'cdb9381bfde2d9a14acf62c42345da5907b7aa14'; | ||
|
||
$export['acf8b2bb295ccb58c1ad4e3a376a81cb'] = $keyauth_keys; | ||
return $export; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
// $Id$ | ||
|
||
/** | ||
* Implementation of hook_ctools_plugin_api(). | ||
*/ | ||
function mn_slingshot_ctools_plugin_api() { | ||
module_load_include('inc', 'mn_slingshot', 'mn_slingshot.defaults'); | ||
$args = func_get_args(); | ||
return call_user_func_array('_mn_slingshot_ctools_plugin_api', $args); | ||
} | ||
|
||
/** | ||
* Implementation of hook_feeds_importer_default(). | ||
*/ | ||
function mn_slingshot_feeds_importer_default() { | ||
module_load_include('inc', 'mn_slingshot', 'mn_slingshot.defaults'); | ||
$args = func_get_args(); | ||
return call_user_func_array('_mn_slingshot_feeds_importer_default', $args); | ||
} | ||
|
||
/** | ||
* Implementation of hook_keyauth_key_default(). | ||
*/ | ||
function mn_slingshot_keyauth_key_default() { | ||
module_load_include('inc', 'mn_slingshot', 'mn_slingshot.defaults'); | ||
$args = func_get_args(); | ||
return call_user_func_array('_mn_slingshot_keyauth_key_default', $args); | ||
} | ||
|
||
/** | ||
* Implementation of hook_node_info(). | ||
*/ | ||
function mn_slingshot_node_info() { | ||
module_load_include('inc', 'mn_slingshot', 'mn_slingshot.features.node'); | ||
$args = func_get_args(); | ||
return call_user_func_array('_mn_slingshot_node_info', $args); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
// $Id$ | ||
|
||
/** | ||
* Helper to implementation of hook_node_info(). | ||
*/ | ||
function _mn_slingshot_node_info() { | ||
$items = array( | ||
'slingshot_feed' => array( | ||
'name' => t('Slingshot Feed'), | ||
'module' => 'features', | ||
'description' => '', | ||
'has_title' => '1', | ||
'title_label' => t('Title'), | ||
'has_body' => '1', | ||
'body_label' => t('Body'), | ||
'min_word_count' => '0', | ||
'help' => '', | ||
), | ||
); | ||
return $items; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
// $Id$ | ||
|
||
/** | ||
* Implementation of hook_strongarm(). | ||
*/ | ||
function mn_slingshot_strongarm() { | ||
$export = array(); | ||
$strongarm = new stdClass; | ||
$strongarm->disabled = FALSE; | ||
$strongarm->api_version = 1; | ||
$strongarm->name = 'feeds_data_slingshot'; | ||
$strongarm->value = 'feeds_data_syndication'; | ||
$export['feeds_data_slingshot'] = $strongarm; | ||
return $export; | ||
} | ||
|
||
/** | ||
* Implementation of hook_enable(). | ||
*/ | ||
function mn_slingshot_enable() { | ||
// Create an example channel. | ||
$nid = db_result( | ||
db_query_range("SELECT nid FROM {node} WHERE type = 'slingshot_feed'", 0, 1) | ||
); | ||
if (!$nid) { | ||
global $user; | ||
$node = new stdClass(); | ||
$node->uid = $user->uid; | ||
$node->title = "mn_slingshot"; | ||
$node->type = 'slingshot_feed'; | ||
$node->body = "The default mn_slingshot Feed"; | ||
node_save($node); | ||
variable_set('mn_slingshot_feed_nid', $node->nid); | ||
} | ||
} | ||
|
||
/** | ||
* Implementation of hook_menu() | ||
*/ | ||
function mn_slingshot_menu() { | ||
$items = array(); | ||
|
||
// Slingshot Configuration Page | ||
$items['admin/settings/slingshot'] = array( | ||
'title' => 'Slingshot', | ||
'description' => 'Assistance for associating a mn_slingshot server', | ||
'page callback' => 'drupal_get_form', | ||
'page arguments' => array('slingshot_config_form'), | ||
'access arguments' => array('access content'), | ||
'file' => 'mn_slingshot_ui.inc', | ||
'type' => MENU_NORMAL_ITEM | ||
); | ||
// Slingshot endpoints and callback for processing | ||
$items['slingshot/%mn_slingshot_slingshot_feed/%'] = array( | ||
'page callback' => 'mn_slingshot_receive', | ||
'page arguments' => array(1, 2), | ||
'access arguments' => array('access content'), | ||
'file' => 'mn_slingshot.inc', | ||
'type' => MENU_NORMAL_ITEM | ||
); | ||
return $items; | ||
} | ||
|
||
/** | ||
* Handle a mn_slingshot notification. | ||
* @param $importer | ||
* FeedsImporter object | ||
* @param $feed_nid | ||
* The node id of the feed node | ||
*/ | ||
function mn_slingshot_receive($importer, $feed_nid = 0) { | ||
if ($importer->fetcher instanceof FeedsSlingshotFetcher) { | ||
// No subscription notification has ben sent, we are being notified. | ||
try { | ||
feeds_source($importer->id, $feed_nid)->import(); | ||
} | ||
catch (Exception $e) { | ||
// In case of an error, respond with a 503 Service (temporary) unavailable. | ||
header('HTTP/1.1 503 "Not Found"', null, 503); | ||
exit(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Menu loader for slingshot feeds | ||
* @param $feed_id | ||
* Assumed to be the feed id | ||
*/ | ||
function mn_slingshot_slingshot_feed_load($feed_id) { | ||
return feeds_importer($feed_id); | ||
} | ||
|
||
/** | ||
* Implementation of hook_feeds_importer_default(). | ||
*/ | ||
function mn_slingshot_feeds_plugins() { | ||
module_load_include('inc', 'mn_slingshot', 'mn_slingshot.plugins'); | ||
$args = func_get_args(); | ||
return call_user_func_array('_mn_slingshot_feeds_plugins', $args); | ||
} | ||
|
||
/** | ||
* Implementation of hook_views_default_views_alter(). | ||
*/ | ||
function mn_slingshot_views_default_views_alter(&$views) { | ||
// Add Slingshot Feeds to sidbar feed block | ||
$views['mn_feeds']->display['default']->display_options['filters']['type']['value'] = array( | ||
'feed' => 'feed', | ||
'slingshot_feed' => 'slingshot_feed', | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
core = "6.x" | ||
dependencies[] = "feeds" | ||
dependencies[] = "strongarm" | ||
dependencies[] = "features" | ||
dependencies[] = "keyauth" | ||
description = "Integration with SlingshotSMS Input" | ||
features[ctools][] = "feeds_importer" | ||
features[ctools][] = "keyauth_keys" | ||
features[ctools][] = "variable" | ||
features[feeds_importer][] = "slingshot" | ||
features[keyauth_keys][] = "acf8b2bb295ccb58c1ad4e3a376a81cb" | ||
features[node][] = "slingshot_feed" | ||
name = "MN Slingshot" | ||
package = "Managing News Extras" | ||
project = "mn_slingshot" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
// $Id$ | ||
|
||
include_once('mn_slingshot.inc'); | ||
include_once('mn_slingshot.features.inc'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
// $Id$ | ||
|
||
/** | ||
* @file | ||
* CTools plugins declarations. | ||
*/ | ||
|
||
/** | ||
* Break out for feeds_feed_plugins(). | ||
*/ | ||
function _mn_slingshot_feeds_plugins() { | ||
$path = drupal_get_path('module', 'mn_slingshot') .'/includes'; | ||
|
||
$info = array(); | ||
|
||
$info['FeedsSlingshotFetcher'] = array( | ||
'name' => 'Slingshot Fetcher', | ||
'description' => 'Receive slingshot items', | ||
'handler' => array( | ||
'parent' => 'FeedsHTTPFetcher', | ||
'class' => 'FeedsSlingshotFetcher', | ||
'file' => 'FeedsSlingshotFetcher.inc', | ||
'path' => $path, | ||
), | ||
); | ||
$info['FeedsSlingshotParser'] = array( | ||
'name' => 'Slingshot parser', | ||
'description' => 'Parse SMS Data from Slingshot.', | ||
'handler' => array( | ||
'parent' => 'FeedsParser', | ||
'class' => 'FeedsSlingshotParser', | ||
'file' => 'FeedsSlingshotParser.inc', | ||
'path' => $path, | ||
), | ||
); | ||
return $info; | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
// $Id$ | ||
|
||
define('PACKAGED_PRIVATE_KEY', '6d4c2ff9361f6a0f778794994af952defab4e1df'); | ||
define('PACKAGED_PUBLIC_KEY_NAME', 'Slingshot'); | ||
|
||
/** | ||
* @file | ||
* Minimal Slingshot UI | ||
*/ | ||
|
||
/** | ||
* Filter keys to select the slingshot key | ||
*/ | ||
function is_slingshot_key($key) { | ||
return $key['title'] == 'Slingshot'; | ||
} | ||
|
||
/** | ||
* Main slingshot configuration form | ||
*/ | ||
function slingshot_config_form() { | ||
global $base_root; | ||
keyauth_include(); | ||
$all_keys = keyauth_all_keys(); | ||
$slingshot_key = current(array_filter($all_keys, 'is_slingshot_key')); | ||
|
||
// Regenerate key on first pageload so that each installation | ||
// is secure | ||
if ($slingshot_key['private_key'] == PACKAGED_PRIVATE_KEY) { | ||
keyauth_save($slingshot_key); | ||
keyauth_regenerate($slingshot_key['public_key']); | ||
return slingshot_config_form(); | ||
} | ||
|
||
$endpoint = $base_root . base_path() . | ||
'slingshot/slingshot/' . variable_get('mn_slingshot_feed_nid', ''); | ||
$form = array(); | ||
$form['slingshot_help'] = array( | ||
'#value' => '<p>' . t('MN Slingshot Configuration: Copy and paste the | ||
code below into slingshotsms.txt for your modem | ||
server') . '</p>' | ||
); | ||
$form['slingshot_snippet'] = array( | ||
'#value' => "<textarea cols='80' rows='5'> | ||
[hmac] | ||
endpoint=$endpoint | ||
public_key=$slingshot_key[public_key] | ||
private_key=$slingshot_key[private_key]</textarea>" | ||
); | ||
// Make a system setting form and return | ||
return system_settings_form($form); | ||
} |