/** * displayFoursquareSubmit * * The submit screen for saving foursquare data. * * @return void */ function displayFoursquareSubmit() { $r = getFoursquareConfigData(); $id = cleanOutput($r['fs_client_id']); $secret = cleanOutput($r['fs_client_secret']); $url = cleanOutput($r['fs_callback_url']); $fsObj = new EpiFoursquare($id, $secret); $token = $fsObj->getAccessToken($_GET['code'], $url); $fsObjAuth = new EpiFoursquare($id, $secret, $token->access_token); $self = $fsObjAuth->get('/users/self'); $sql = "UPDATE `fcms_user_settings`\n SET `fs_user_id` = ?,\n `fs_access_token` = ?\n WHERE `user` = ?"; $params = array($self->response->user->id, $token->access_token, $this->fcmsUser->id); if (!$this->fcmsDatabase->update($sql, $params)) { $this->displayHeader(); $this->fcmsError->displayError(); $this->displayFooter(); return; } header("Location: settings.php?view=foursquare"); }
* @since 2.4 */ session_start(); define('URL_PREFIX', ''); define('GALLERY_PREFIX', 'gallery/'); require 'fcms.php'; load('datetime', 'socialmedia', 'foursquare'); init(); $templateParams = array('currentUserId' => $fcmsUser->id, 'sitename' => getSiteName(), 'nav-link' => getNavLinks(), 'pagetitle' => T_('Where Is Everyone'), 'pageId' => 'whereiseveryone-page', 'path' => URL_PREFIX, 'displayname' => $fcmsUser->displayName, 'version' => getCurrentVersion(), 'year' => date('Y')); $options = array('modules' => array('livevalidation')); displayPageHeader($templateParams, $options); //------------------------------------- // Show Latest checkins //------------------------------------- $users = getFoursquareUsersData(); $config = getFoursquareConfigData(); if (count($users[0]) <= 0) { echo ' <div class="info-alert"> <p>' . T_('No users with foursquare data found.') . '</p> </div>'; loadTemplate('global', 'footer', $templateParams); return; } // Foursquare hasn't been setup or is invalid if (empty($config['fs_client_id']) or empty($config['fs_client_secret'])) { // If admin is viewing, alert them that the config is missing/messed up if ($fcmsUser->access < 2) { echo ' <div class="info-alert"> <h2>' . T_('Foursquare is not configured correctly.') . '</h2>
/** * displayFormPage * * @param string $displayMessage * * @return void */ function displayFormPage($displayMessage = '') { $this->displayHeader(); if (isset($_SESSION['success'])) { echo ' <div class="alert-message success"> <a class="close" href="#" onclick="$(this).up(\'div\').hide(); return false;">×</a> ' . T_('Changes Updated Successfully') . ' </div>'; unset($_SESSION['success']); } $r = getFoursquareConfigData(); $id = isset($r['fs_client_id']) ? cleanOutput($r['fs_client_id']) : ''; $secret = isset($r['fs_client_secret']) ? cleanOutput($r['fs_client_secret']) : ''; $url = isset($r['fs_callback_url']) ? cleanOutput($r['fs_callback_url']) : ''; if (empty($id) || empty($secret) || empty($url)) { echo ' <div class="row"> <div class="span4"> <h2>' . T_('Step 1') . '</h2> <p>' . T_('Go to Foursquare and register a new app.') . '</p> </div> <div class="span12"> <h3><a href="https://foursquare.com/developers/register">' . T_('Register a new foursquare app.') . '</a></h3> <p> ' . T_('Be sure to include settings.php as part of your callback url. For example: if your site is located at http://www.my-awesome-site.com/fcms/index.php then your callback url should be http://www.my-awesome-site.com/fcms/settings.php') . ' </p> </div><!-- /span12 --> </div><!-- /row --> <p> </p> <p> </p> <p> </p> <div class="row"> <div class="span4"> <h2>' . T_('Step 2') . '</h2> <p>' . T_('Fill out the form below with the information you provided in Step 1.') . '</p> </div> <div class="span12">'; } echo ' <form action="foursquare.php" method="post"> <fieldset> <legend>' . T_('Foursquare Confirguration') . '</legend> <div class="clearfix"> <label for="id">' . T_('Client ID') . '</label> <div class="input"> <input type="text" name="id" id="id" size="50" value="' . $id . '"/> </div> </div> <div class="clearfix"> <label for="secret">' . T_('Client Secret') . '</label> <div class="input"> <input type="text" name="secret" id="secret" size="50" value="' . $secret . '"/> </div> </div> <div class="clearfix"> <label for="url">' . T_('Callback URL') . '</label> <div class="input"> <input class="frm_text" type="text" name="url" id="url" size="50" value="' . $url . '"/> </div> </div> <div class="actions"> <input class="btn primary" type="submit" name="submit" value="' . T_('Save') . '"/> </div> </fieldset> </form>'; if (empty($id) || empty($secret) || empty($url)) { echo ' </div><!-- /span12 --> </div><!-- /row -->'; } $this->displayFooter(); }
/** * getFoursquareWhatsNewData * * Adds foursquare data to the whats new data array. * * @param array $whatsNewData * * @return mixed - array on success or false on failure */ function getFoursquareWhatsNewData($whatsNewData) { $fcmsError = FCMS_Error::getInstance(); $fcmsDatabase = Database::getInstance($fcmsError); $fcmsUser = User::getInstance($fcmsError, $fcmsDatabase); include_once 'socialmedia.php'; include_once 'thirdparty/foursquare/EpiFoursquare.php'; include_once 'thirdparty/foursquare/EpiCurl.php'; $users = getFoursquareUsersData(); $config = getFoursquareConfigData(); // TODO // Move this check inside the getFoursquareConfigData and have it return false on failure. // Foursquare hasn't been setup or is invalid if (empty($config['fs_client_id']) or empty($config['fs_client_secret'])) { // If admin is viewing, alert them that the config is missing/messed up if ($fcmsUser->access < 2) { echo ' <div class="info-alert"> <h2>' . T_('Foursquare is not configured correctly.') . '</h2> <p>' . T_('The "Where Is Everyone" feature cannot work without Foursquare. Please configure Foursquare or turn off "Where Is Everyone".') . '</p> <p><a href="admin/foursquare.php">' . T_('Configure Foursquare') . '</a></p> <p><a href="admin/config.php?view=plugins">' . T_('Turn Off "Where is Everyone"') . '</a></p> </div>'; } return $whatsNewData; } $foursquareData = array(); if (count($users[0]) > 0) { $timeago = gmmktime(0, 0, 0, gmdate('m'), gmdate('d'), gmdate('Y')); $i = 0; foreach ($users as $k => $data) { // Skip users who don't have foursquare setup if (empty($data['access_token'])) { continue; } $fsObj = new EpiFoursquare($config['fs_client_id'], $config['fs_client_secret'], $data['access_token']); try { $params = array('afterTimestamp' => $timeago); $creds = $fsObj->get('/users/' . $data['user_id'] . '/checkins', $params); } catch (EpiFoursquareException $e) { echo 'We caught an EpiOAuthException'; echo $e->getMessage(); return false; } catch (Exception $e) { echo 'We caught an unexpected Exception'; echo $e->getMessage(); return false; } foreach ($creds->response->checkins->items as $checkin) { // Skip shouts, etc if ($checkin->type != 'checkin') { continue; } $date = date('Y-m-d H:i:s', $checkin->createdAt); $sort = $checkin->createdAt; $shout = isset($checkin->shout) ? $checkin->shout : ''; // Save data $whatsNewData[] = array('id' => '', 'date' => $date, 'title' => $checkin->venue->name, 'userid' => $data['fcms_user_id'], 'id2' => $shout, 'id3' => '', 'type' => 'WHEREISEVERYONE'); } } } // Order is messed up now, so fix it $whatsNewData = subval_sort($whatsNewData, 'date'); $whatsNewData = array_reverse($whatsNewData); return $whatsNewData; }