From acb69b606234d1a8baef48d3ad38d1b60a15fce7 Mon Sep 17 00:00:00 2001 From: "Jon \"The Nice Guy\" Spriggs" Date: Mon, 13 Aug 2012 19:57:52 +0100 Subject: [PATCH] This allows CFM to post to Joind.in. It requires some SecureConfig values to be set, but then works. Many many thanks to Lorna Jane Mitchell for all her help getting this working! Even the basic code is hers!! I've just tweaked it to make it work with the data structures and plugin layout of CFM2. --- classes/Plugin/JoindIn/hook_loader.php | 108 +++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 classes/Plugin/JoindIn/hook_loader.php diff --git a/classes/Plugin/JoindIn/hook_loader.php b/classes/Plugin/JoindIn/hook_loader.php new file mode 100644 index 0000000..61f62dc --- /dev/null +++ b/classes/Plugin/JoindIn/hook_loader.php @@ -0,0 +1,108 @@ + + * @license http://www.gnu.org/licenses/agpl.html AGPLv3 + * @link https://github.com/JonTheNiceGuy/cfm2 Version Control Service + */ +/** + * This plugin is used to publish the talks to Joind.in on fixing + * + * @category Plugin_JoindIn + * @package CampFireManager2 + * @author Jon Spriggs + * @author Lorna Mitchell + * @license about:blank?tbc tbc + * @link https://github.com/JonTheNiceGuy/cfm2 Version Control Service + */ + +require_once dirname(__FILE__) . '/../../autoloader.php'; +Container_Config::LoadConfig(); +$hook = new Plugin_JoindIn(); +$talk = Object_Talk::brokerByID(2); +$hook->hook_talkFixed($talk); + +class Plugin_JoindIn +{ + /** + * This function sends a broadcast when the talk is fixed. + * + * @param object $object The talk object that has been fixed + * + * @return void + */ + function hook_talkFixed($object) + { + $system_state = Object_User::isSystem(); + try { + $object->setFull(true); + $arrTalk = $object->getSelf(); + + $oAuth_UserToken = Object_SecureConfig::brokerByID('Plugin_JoindIn_Token'); + if ($oAuth_UserToken != false) { + $oAuth_UserToken = $oAuth_UserToken->getKey('value'); + } + $strJoindInAPI = Object_SecureConfig::brokerByID('Plugin_JoindIn_API'); + if ($strJoindInAPI != false) { + $strJoindInAPI = $strJoindInAPI->getKey('value'); + } + $intEventID = Object_SecureConfig::brokerByID('Plugin_JoindIn_Event'); + if ($intEventID != false) { + $intEventID = $intEventID->getKey('value'); + } + + if ($oAuth_UserToken == false || $strJoindInAPI == false || $intEventID == false) { + return false; + } + + // set your own data as follows + $date = new DateTime($arrTalk['arrSlot']['dateStart'] . ' ' . $arrTalk['arrSlot']['timeStart'], new DateTimeZone('Europe/London')); + $presenters = array(); + foreach ($arrTalk['arrPresenters'] as $arrPresenter) { + $presenters[] = $arrPresenter['strUser']; + } + $talk_data = array( + 'talk_title' => $arrTalk['strTalk'], + 'talk_description' => $arrTalk['strTalkSummary'], + 'start_date' => $date->format('c'), + 'speakers' => $presenters, + ); + + $path = $strJoindInAPI . '/v2.1/events/' . $intEventID . '/talks'; + + $ch = curl_init($path); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: OAuth ' . $oAuth_UserToken)); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($talk_data)); + curl_setopt($ch, CURLOPT_HEADER, false); + $curl = curl_exec($ch); + + $data = json_decode($curl, true); + + var_dump($data); + if ($data != false && isset($data['talks'])) { + foreach ($data['talks'] as $talk) { + if (isset($talk['website_uri'])) { + $talk_url = $talk['website_uri']; + } + } + } + + Object_User::isSystem(true); + $object->setKey('jsonLinks', Base_GeneralFunctions::addJson($object->getKey('jsonLinks'), 'Joind.in', $talk_url)); + $object->write(); + Object_User::isSystem($system_state); + } catch (Exception $e) { + error_log($e->getMessage()); + Object_User::isSystem($system_state); + } + } +} \ No newline at end of file