public function fetchStatus($providerUserId) { $status = ""; $url = 'https://api.vk.com/method/wall.get'; $url .= '?owner_id=' . $providerUserId; $url .= '&count=10&extended=0&filter=owner'; try { $data = $this->provider->client->query($url); if ($data->code == 200) { $posts = json_decode($data->body, true); foreach ($posts['response'] as $post) { if (is_array($post)) { if ($post['post_type'] == 'post' && $post['text'] !== "") { $status = $post['text']; break; } } } } } catch (Exception $e) { if (JFBCFactory::config()->get('facebook_display_errors')) { JFBCFactory::log($e->getMessage()); } } return $status; }
function apply() { $app = JFactory::getApplication(); $configs = JRequest::get('POST'); $model = JFBCFactory::config(); JPluginHelper::importPlugin('socialprofiles'); $profilePlugins = $app->triggerEvent('socialProfilesGetPlugins'); foreach ($profilePlugins as $plugin) { $pluginName = $plugin->getName(); $settings = new JRegistry(); $search = "profiles_" . $pluginName . "_"; $stdFields = JRequest::getVar('profiles_' . $pluginName); $settings->loadArray($stdFields); foreach ($configs as $key => $value) { $pos = strpos($key, $search); if ($pos === 0) { $key = str_replace($search, "", $key); if (strpos($key, "field_map") != false) { $key = str_replace("_field_map", ".", $key); $settings->set('field_map.' . $key, $value); } } } $model->update("profile_" . $pluginName, $settings->toString()); } JFBCFactory::log(JText::_('COM_JFBCONNECT_MSG_SETTINGS_UPDATED')); $this->display(); }
function apply() { $configs = JRequest::get('POST', 4); $model = $this->getModel('config'); $model->saveSettings($configs); JFBCFactory::log(JText::_('COM_JFBCONNECT_MSG_SETTINGS_UPDATED')); $this->setRedirect('index.php?option=com_jfbconnect&view=canvas'); }
function importConnections() { $app = JFactory::getApplication(); JPluginHelper::importPlugin('socialprofiles'); $profilePlugins = $app->triggerEvent('jfbcImportConnections'); $msg = JText::_('COM_JFBCONNECT_MSG_IMPORT_SUCCESS'); JFBCFactory::log($msg); $this->display(); }
public function unlink() { JSession::checkToken('get') or die('Invalid Token'); $provider = JRequest::getString('provider', ''); $user = JFactory::getUser(); $userModel = JFBConnectModelUserMap::getUser($user->get('id'), $provider); $provider_user_id = $userModel->getProviderUserId($user->get('id'), $provider); $userModel->deleteMapping($provider_user_id, $provider); JFBCFactory::log(JText::sprintf('COM_JFBCONNECT_ACCOUNT_LINKED_ACCOUNTS_UNLINK_MESSAGE', $provider)); $this->setRedirect(JRoute::_('index.php?option=com_jfbconnect&view=account')); }
protected function getTagHtml() { JFBCFactory::log('Deprecated Like Box called. Use Page Plugin instead.', 'warning', true); $tag = '<div class="fb-page"'; $tag .= $this->getField('show_faces', null, 'boolean', 'true', 'data-show-facepile'); $tag .= $this->getField('stream', null, 'boolean', 'false', 'data-show-posts'); $tag .= $this->getField('hide_cover', null, 'boolean', 'false', 'data-hide-cover'); $tag .= $this->getField('width', null, null, '', 'data-width'); $tag .= $this->getField('height', null, null, '', 'data-height'); $tag .= $this->getField('href', 'url', null, '', 'data-href'); $tag .= '></div>'; return $tag; }
public function fetchProfile($userId, $fields) { $profile = new JFBConnectProfileDataWindowsLive(); $url = 'https://apis.live.net/v5.0/' . $userId; try { $jdata = $this->provider->client->query($url); if ($jdata->code == 200) { $data = json_decode($jdata->body, true); $profile->loadObject($data); } } catch (Exception $e) { if (JFBCFactory::config()->get('facebook_display_errors')) { JFBCFactory::log($e->getMessage()); } } return $profile; }
public function fetchProfile($userId, $fields) { $profile = new JFBConnectProfileDataInstagram(); $url = 'https://api.instagram.com/v1/users/' . $userId; // get the current user try { $jdata = $this->provider->client->query($url); if ($jdata->code == 200) { $data = json_decode($jdata->body, true); $profile->loadObject($data['data']); } } catch (Exception $e) { if (JFBCFactory::config()->get('facebook_display_errors')) { JFBCFactory::log($e->getMessage()); } } return $profile; }
public function fetchProfile($user, $fields) { $profile = new JFBConnectProfileDataAmazon(); $url = 'https://api.amazon.com/user/profile'; // get the current user try { $jdata = $this->provider->client->query($url); $data = json_decode($jdata->body, true); if (is_array($data)) { $profile->loadObject($data); } } catch (Exception $e) { if (JFBCFactory::config()->get('facebook_display_errors')) { JFBCFactory::log($e->getMessage()); } } return $profile; }
public function loginMap() { JRequest::checkToken('post') or jexit(JText::_('JInvalid_Token')); $app = JFactory::getApplication(); $provider = JFactory::getApplication()->input->getCmd('provider'); $provider = JFBCFactory::provider($provider); SCSocialUtilities::setJFBCNewMappingEnabled(); $loginRegisterModel = $this->getModel('LoginRegister', 'JFBConnectModel'); $redirect = $loginRegisterModel->getLoginRedirect($provider); $returnParam = '&return=' . base64_encode($redirect); $providerUserId = $provider->getProviderUserId(); if (!$providerUserId) { $app->redirect(JRoute::_('index.php?option=com_jfbconnect&view=loginregister&provider=' . $provider->systemName . $returnParam, false)); } // Populate the data array: $data = array(); $data['username'] = JRequest::getVar('username', '', 'method', 'username'); $data['password'] = JRequest::getString('password', '', 'post', 'string', JREQUEST_ALLOWRAW); // Perform the log in. $error = $app->login($data); // Check if the log in succeeded. if (JError::isError($error) || $error == false) { $app->redirect(JRoute::_('index.php?option=com_jfbconnect&view=loginregister&provider=' . $provider->systemName . $returnParam, false)); } else { $jUser = JFactory::getUser(); if (JFBCFactory::usermap()->map($jUser->get('id'), $providerUserId, $provider->systemName, $provider->client->getToken())) { JFBCFactory::log(JText::sprintf('COM_JFBCONNECT_MAP_USER_SUCCESS', $provider->name)); } /* Don't import on just a mapping update, for now. Need to investigate. $jUser = JFactory::getUser(); $jfbcLibrary = JFBConnectFacebookLibrary::getInstance(); $fbUserId = $jfbcLibrary->getMappedFbUserId(); $args = array($jUser->get('id'), $fbUserId); JPluginHelper::importPlugin('jfbcprofiles'); $app->triggerEvent('scProfilesImportProfile', $args); JFBCFactory::log('Profile Imported!');*/ JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_jfbconnect/' . 'models'); $loginRegisterModel = JModelLegacy::getInstance('LoginRegister', 'JFBConnectModel'); $redirect = $loginRegisterModel->getLoginRedirect($provider); $app->redirect($redirect); } }
public function migrate() { $app = JFactory::getApplication(); $migration = $app->input->getCmd('migration'); $parts = explode('.', $migration); if ($parts[0]) { include_once JPATH_ADMINISTRATOR . '/components/com_jfbconnect/helpers/migrator/' . $parts[0] . '.php'; $class = 'JFBConnectMigrator' . $parts[0]; $migrator = new $class(); $subtask = isset($parts[1]) ? $parts[1] : 'migrate'; $result = $migrator->{$subtask}(); if ($result) { JFBCFactory::log(JText::_('COM_JFBCONNECT_MSG_MIGRATION_COMPLETE')); } else { JFBCFactory::log(JText::_('COM_JFBCONNECT_MSG_MIGRATION_ERROR'), 'error'); } } $this->setRedirect('index.php?option=com_jfbconnect&view=config'); }
function api($api, $params = null, $callAsUser = true, $method = null, $suppressErrors = false) { $this->apiError = null; if (!$method) { if ($params) { $method = "POST"; } else { $method = "GET"; } } if (!$callAsUser) { $params['access_token'] = $this->appId . "|" . $this->secretKey; } /* else if (!$params || (is_array($params) && (!array_key_exists('access_token', $params)))) { // Get the access token for the current user $jUser = JFactory::getUser(); $userMapModel = new JFBConnectModelUserMap(); $userMapModel->getData($jUser->get('id')); $accessToken = $userMapModel->_data->access_token; if ($accessToken != '' && $accessToken != null) $params['access_token'] = $accessToken; }*/ try { if ($params != null) { // Graph API call with paramters (either App call or POST call) $apiData = $this->client->api($api, $method, $params); } else { // Graph API call to only get data $apiData = $this->client->api($api); } } catch (JFBCFacebookApiException $e) { $this->apiError = $e->getMessage(); // Only display errors on the front-end if the config is set to do so $app = JFactory::getApplication(); if (!$suppressErrors && ($app->isAdmin() || $this->configModel->get('facebook_display_errors'))) { JFBCFactory::log(JText::_('COM_JFBCONNECT_FB_API_ERROR') . $e->getMessage(), 'error'); } $apiData = null; } return $apiData; }
public function fetchProfile($userId, $fields) { if (!is_array($fields)) { $fields = array($fields); } if (in_array('first_name', $fields)) { $fields[] = 'first-name'; unset($fields[array_search('first_name', $fields)]); } if (in_array('last_name', $fields)) { $fields[] = 'last-name'; unset($fields[array_search('last_name', $fields)]); } if (in_array('full_name', $fields)) { $fields[] = 'first-name'; $fields[] = 'last-name'; unset($fields[array_search('full_name', $fields)]); } if (in_array('email', $fields)) { $fields[] = 'email-address'; unset($fields[array_search('email', $fields)]); } if (in_array('middle_name', $fields)) { unset($fields[array_search('middle_name', $fields)]); } $fields = array_unique($fields); $profile = new JFBConnectProfileDataLinkedin(); if (!empty($fields)) { $url = 'https://api.linkedin.com/v1/people/' . $userId . ':(' . implode(',', $fields) . ')'; try { $data = $this->provider->client->query($url); $data = json_decode($data->body, true); $profile->loadObject($data); } catch (Exception $e) { if (JFBCFactory::config()->get('facebook_display_errors')) { JFBCFactory::log($e->getMessage()); } } } return $profile; }
public function __construct(JRegistry $options = null, JHttp $http = null, JInput $input = null, JApplicationWeb $application = null) { // We want to use cURL, so need to build this all up. This also helps poke into each of the things when debugging $httpOptions = new JRegistry(); $httpOptions->set('follow_location', false); try { $transport = new JFBConnectJoomlaHttpTransportCurl($httpOptions); } catch (Exception $e) { JFBCFactory::log('JFBConnect requires the CURL PHP extension to be installed and callable.', 'error'); $transport = null; } $http = new JHttp($httpOptions, $transport); $this->transport = $transport; $options = isset($options) ? $options : new JRegistry(); $options->set('state', JSession::getFormToken()); // This is sent back to us to identify the provider if (!$options->exists('sendheaders')) { $options->set('sendheaders', true); } parent::__construct($options, $http, $input, $application); }
public function callback() { $input = JFactory::getApplication()->input; // Have to do our own token checking here. Redirect shouldn't happen to normal users since token was just inserted // when they tried to authenticate $token = JSession::getFormToken(); $returnToken = $input->get('state', '', 'alnum'); if ($token != $returnToken) { $this->setRedirect('index.php', JText::_('JLIB_ENVIRONMENT_SESSION_EXPIRED')); $this->redirect(); } $provider = $this->getProvider(); try { $provider->client->authenticate(); } catch (Exception $e) { JFBCFactory::log(JText::sprintf('COM_JFBCONNECT_UNABLE_TO_RETRIEVE_USER', ucwords($provider->name)), 'warning'); if (JFBCFactory::config()->getSetting('facebook_display_errors')) { JFBCFactory::log($e->getMessage(), 'error'); } $this->redirectOnFailedAuth(); } $this->doLogin($provider); }
public function fetchProfile($userId, $fields = array(), $only = array()) { if (!is_array($fields)) { $fields = array($fields); } $unsetFields = array('full_name', 'first_name', 'last_name', 'middle_name'); foreach ($unsetFields as $unsetField) { if (in_array($unsetField, $fields)) { unset($fields[array_search($unsetField, $fields)]); } } $fields = array_unique($fields); $profile = new JFBConnectProfileDataMeetup(); $url = 'https://api.meetup.com/2/member/' . $userId; if (!empty($fields)) { $url .= '?fields=' . implode(',', $fields); } if (!empty($only)) { if (!is_array($only)) { $only = array($only); } $only = array_unique($only); $url .= empty($fields) ? '?only=' . implode(',', $only) : '&only=' . implode(',', $only); } try { $jdata = $this->provider->client->query($url); if ($jdata->code == 200) { $data = json_decode($jdata->body, true); $profile->loadObject($data); } } catch (Exception $e) { if (JFBCFactory::config()->get('facebook_display_errors')) { JFBCFactory::log($e->getMessage()); } } return $profile; }
public function getData() { try { $key = strtolower($this->systemName) . '.' . strtolower($this->provider->systemName); $key .= '.' . strtolower(str_replace(' ', '_', $this->name)) . '.' . md5($this->options->toString()); //add caching capability $this->response = JFBCFactory::cache()->get($key); if ($this->response === false) { $data = $this->query(); if ($data->code == 200) { $this->response = json_decode($data->body, true); if (is_array($this->response)) { $this->response = (object) $this->response; } // Perform the curl Request and get $response JFBCFactory::cache()->store($this->response, $key); } } } catch (Exception $e) { if (JFBCFactory::config()->get('facebook_display_errors')) { JFBCFactory::log($e->getMessage()); } } }
function display($tpl = null) { $configModel = JFBCFactory::config(); $usermapModel = JFBCFactory::usermap(); $autotuneModel = JModelLegacy::getInstance('AutoTune', 'JFBConnectModel'); if (JFBCFactory::provider('facebook')->appId) { $appConfig = JFBCFactory::config()->get('autotune_app_config', null); if (!$appConfig || count($appConfig) == 0) { JFBCFactory::log(JText::sprintf('COM_JFBCONNECT_MSG_RUN_AUTOTUNE', '<a href="index.php?option=com_jfbconnect&view=autotune">AutoTune</a>'), 'error'); } } $userCounts = array(); foreach (JFBCFactory::getAllProviders() as $p) { if ($p->appId) { $userCounts[$p->systemName] = $usermapModel->getTotalMappings($p->systemName); } } $this->configModel = $configModel; $this->autotuneModel = $autotuneModel; $this->usermapModel = $usermapModel; $this->userCounts = $userCounts; $this->addToolbar(); parent::display($tpl); }
function saveSettings() { $configs = JRequest::get('POST', 4); $model = $this->getModel('config'); $model->saveSettings($configs); JFBCFactory::log(JText::_('COM_JFBCONNECT_MSG_SETTINGS_UPDATED')); return 'index.php?option=com_jfbconnect&view=opengraph&task=settings'; }
function delete() { $row =& $this->getTable("JFBConnectRequest", "Table"); $cids = JRequest::getVar('cid', array(0), 'post', 'array'); if (count($cids)) { foreach ($cids as $cid) { $pendingNotifications = $this->getPendingNotifications($cid); if ($pendingNotifications > 0) { $message = JText::sprintf('COM_JFBCONNECT_MSG_REQUEST_DELETE_FAIL', $pendingNotifications); JFBCFactory::log($message); return false; } if (!$row->delete($cid)) { $this->setError($this->_db->getErrorMsg()); return false; } if (!$this->deleteRequestNotifications($cid)) { $message = JText::_('COM_JFBCONNECT_MSG_REQUEST_DELETE_FAIL_ASSOCIATED'); JFBCFactory::log($message); return false; } } } return true; }
/** Activation and new user email functions *****/ private function activateUser() { $useractivation = $this->getActivationMode(); $language = JFactory::getLanguage(); # Send out the new registration email // figure out activation $language->load('com_users'); if ($useractivation == 2) { JFBCFactory::log(JText::_('COM_USERS_REGISTRATION_COMPLETE_VERIFY')); } else { if ($useractivation == 1) { JFBCFactory::log(JText::_('COM_USERS_REGISTRATION_COMPLETE_ACTIVATE')); } } if ($useractivation == 0) { return true; } else { return false; } }
/** * Method to validate a response. * * @param string $url The request URL. * @param JHttpResponse $response The response to validate. * * @return void * * @since 13.1 * @throws DomainException */ public function validateResponse($url, $response) { if (!($code = $this->getOption('success_code'))) { $code = 200; } if (strpos($url, '::(~)') === false && $response->code != $code) { if ($error = json_decode($response->body)) { if (isset($error->errors)) { $error = $error->errors; if (is_array($error)) { $error = $error[0]; } } if (JFBCFactory::config()->get('facebook_display_errors')) { JFBCFactory::log('Yahoo API Error: Code ' . $response->code . ' received with message: ' . $error->detail . '.', 'error'); } } else { JFBCFactory::log('Yahoo API Error: ' . $response->body, 'error'); } return false; } return true; }
private function setupIntroPage() { $phpVersion = phpversion(); $errorsFound = false; if (version_compare($phpVersion, '5.0.0') >= 0) { $phpVersion .= '<td><img src="components/com_jfbconnect/assets/images/icon-16-allow.png" /></td>'; } else { $phpVersion .= '<td><img src="components/com_jfbconnect/assets/images/icon-16-deny.png" /></td>'; $errorsFound = true; } $this->view->assignRef('phpVersion', $phpVersion); // cURL check $disableFunctions = ini_get('disable_functions'); if (in_array('curl', get_loaded_extensions()) && strpos($disableFunctions, 'curl_exec') === false) { $curlCheck = 'Enabled <td><img src="components/com_jfbconnect/assets/images/icon-16-allow.png" /></td>'; } else { $curlCheck = '<strong>Disabled</strong> <td><img src="components/com_jfbconnect/assets/images/icon-16-deny.png" /></td>'; $errorsFound = true; } if ($errorsFound) { JFBCFactory::log(JText::_('COM_JFBCONNECT_MSG_ERROR_SERVER_CONFIG'), 'error'); } $this->view->assignRef('curlCheck', $curlCheck); $this->view->assignRef('errorsFound', $errorsFound); }
protected function getURL($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-Charset: utf-8")); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $content = curl_exec($ch); if (curl_errno($ch)) { $error = curl_error($ch); curl_close($ch); if (JFBCFactory::config()->get('facebook_display_errors')) { JFBCFactory::log("Meetup Widget Error: Failed retrieving '" . $url . "' because of ' " . $error . "'.", 'error'); } } $response = json_decode($content); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($status != 200) { $error = 'Meetup Widget Error ' . $status; if (isset($response->problem)) { $error .= ': ' . $response->problem; } if (isset($response->details)) { $error .= '<br/>' . $response->details; } if (isset($response->errors[0]->message)) { $error .= '<br/>' . $response->errors[0]->message; } if (JFBCFactory::config()->get('facebook_display_errors')) { JFBCFactory::log($error); } } if (isset($response) == false) { switch (json_last_error()) { case JSON_ERROR_NONE: $error = 'No errors'; break; case JSON_ERROR_DEPTH: $error = 'Maximum stack depth exceeded'; break; case JSON_ERROR_STATE_MISMATCH: $error = ' Underflow or the modes mismatch'; break; case JSON_ERROR_CTRL_CHAR: $error = 'Unexpected control character found'; break; case JSON_ERROR_SYNTAX: $error = 'Syntax error, malformed JSON'; break; case JSON_ERROR_UTF8: $error = 'Malformed UTF-8 characters, possibly incorrectly encoded'; break; default: $error = 'Unknown error'; break; } if (JFBCFactory::config()->get('facebook_display_errors')) { JFBCFactory::log("Meetup Widget Error: Cannot read response by '" . $url . "' because of: '" . $error . "'.", 'error'); } } return $response; }
private function deleteAction($id) { $ogActivityModel = $this->getModel('opengraphactivity', 'JFBConnectModel'); $activity = $ogActivityModel->getActivity($id); $user = JFactory::getUser(); if ($activity->user_id == $user->get('id')) { // Delete the action from Facebook and then from the database $result = JFBCFactory::provider('facebook')->api('/' . $activity->response, null, false, 'DELETE'); $error = JFBCFactory::provider('facebook')->getLastError(); $ogActivityModel->userdelete($id); if ($result) { JFBCFactory::log(JText::_('COM_JFBCONNECT_TIMELINE_EVENT_DELETE_SUCCESS')); } else { JFBCFactory::log(JText::sprintf('COM_JFBCONNECT_TIMELINE_EVENT_DELETE_FAIL', $error), 'error'); } } return $result; }
/** * Makes an HTTP request. This method can be overridden by subclasses if * developers want to do fancier things or use something other than curl to * make the request. * * @param string $url The URL to make the request to * @param array $params The parameters to use for the POST body * @param CurlHandler $ch Initialized curl handle * * @return string The response text */ protected function makeRequest($url, $params, $ch = null) { if (!$ch) { $ch = curl_init(); } $opts = self::$CURL_OPTS; // SourceCoast - JFBConnect - Use setting to always include the Cert instead of failing and retrying every time. $jfbcConfigModel = JFBCFactory::config(); if ($jfbcConfigModel->getSetting('facebook_curl_disable_ssl', false)) { $opts[CURLOPT_SSL_VERIFYPEER] = false; } // End SourceCoast if ($this->getFileUploadSupport()) { $opts[CURLOPT_POSTFIELDS] = $params; } else { $opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&'); } $opts[CURLOPT_URL] = $url; // disable the 'Expect: 100-continue' behaviour. This causes CURL to wait // for 2 seconds if the server does not support this header. if (isset($opts[CURLOPT_HTTPHEADER])) { $existing_headers = $opts[CURLOPT_HTTPHEADER]; $existing_headers[] = 'Expect:'; $opts[CURLOPT_HTTPHEADER] = $existing_headers; } else { $opts[CURLOPT_HTTPHEADER] = array('Expect:'); } curl_setopt_array($ch, $opts); $result = curl_exec($ch); $errno = curl_errno($ch); // CURLE_SSL_CACERT || CURLE_SSL_CACERT_BADFILE if ($errno == 60 || $errno == 77) { JFBCFactory::log("SSL Verification Failed. Set 'Disable SSL Certificate Validation' to Yes in the JFBConnect Configuration", 'error'); /* self::errorLog('Invalid or no certificate authority found, ' . 'using bundled information'); curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . DIRECTORY_SEPARATOR . 'fb_ca_chain_bundle.crt'); $result = curl_exec($ch); */ } // With dual stacked DNS responses, it's possible for a server to // have IPv6 enabled but not have IPv6 connectivity. If this is // the case, curl will try IPv4 first and if that fails, then it will // fall back to IPv6 and the error EHOSTUNREACH is returned by the // operating system. if ($result === false && empty($opts[CURLOPT_IPRESOLVE])) { $matches = array(); $regex = '/Failed to connect to ([^:].*): Network is unreachable/'; if (preg_match($regex, curl_error($ch), $matches)) { if (strlen(@inet_pton($matches[1])) === 16) { if ($jfbcConfigModel->getSetting('facebook_display_errors')) { JFBCFactory::log('Invalid IPv6 configuration on server. Please disable or get native IPv6 on your server.'); } self::$CURL_OPTS[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4; curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); $result = curl_exec($ch); } } } if ($result === false) { $e = new JFBCFacebookApiException(array('error_code' => curl_errno($ch), 'error' => array('message' => curl_error($ch), 'type' => 'CurlException'))); curl_close($ch); throw $e; } curl_close($ch); return $result; }
private function fetchFieldDescriptors() { static $updatePerformed; if ($updatePerformed) { return; } $updatePerformed = true; $fields = $this->makeSourceCoastRequest('getFieldList'); $app = JFactory::getApplication(); if ($fields) { JFBCFactory::log(JText::_('COM_JFBCONNECT_MSG_FETCH_SUCCESS')); $this->configModel->update('autotune_field_descriptors', $fields); } else { JFBCFactory::log(JText::_('COM_JFBCONNECT_MSG_FETCH_FAIL')); } }
public function apply() { $canvasSettings = $this->getCanvasSettings(); if (!empty($canvasSettings)) { $model = $this->getModel('request'); $model->store(); JFBCFactory::log(JText::_('COM_JFBCONNECT_MSG_REQUEST_SAVE_SUCCESS')); } else { JFBCFactory::log(JText::_('COM_JFBCONNECT_MSG_REQUEST_SAVE_FAIL'), 'error'); } $this->setRedirect('index.php?option=com_jfbconnect&controller=request'); }
public function getStream($stream) { $user = $this->options->get('user_id'); if (!$user) { return; } $companyId = $this->options->get('company_id'); $feed = JFBCFactory::cache()->get('linkedin.stream.' . $companyId); if ($feed === false) { $access_token = JFBCFactory::usermap()->getUserAccessToken($user, 'linkedin'); if (!is_object($access_token) || $access_token->created + $access_token->expires_in < time()) { return; } $url = 'https://api.linkedin.com/v1/companies/' . $companyId . '/updates'; $this->provider->client->setToken((array) $access_token); try { $feedResponse = $this->provider->client->query($url, json_encode(array()), array(), 'get'); if ($feedResponse->code != 200) { return; } $feed = json_decode($feedResponse->body); JFBCFactory::cache()->store($feed, 'linkedin.stream.' . $companyId); } catch (Exception $e) { if (JFBCFactory::config()->get('facebook_display_errors')) { JFBCFactory::log('LinkedIn Stream: ' . $e->getMessage(), 'error'); } return; } } if (isset($feed->values) && $feed->values) { foreach ($feed->values as $data) { $post = new JFBConnectPost(); $post->authorScreenName = $data->updateContent->company->name; if (isset($data->updateContent->companyJobUpdate)) { $post->type = 'job-posting'; $post->message = isset($data->updateContent->companyJobUpdate->job->description) ? $data->updateContent->companyJobUpdate->job->description : ""; $post->jobLocation = isset($data->updateContent->companyJobUpdate->job->locationDescription) ? $data->updateContent->companyJobUpdate->job->locationDescription : ""; $post->jobPosition = isset($data->updateContent->companyJobUpdate->job->position->title) ? $data->updateContent->companyJobUpdate->job->position->title : ""; $post->link = isset($data->updateContent->companyJobUpdate->job->siteJobRequest->url) ? $data->updateContent->companyJobUpdate->job->siteJobRequest->url : ""; } elseif (isset($data->updateContent->companyStatusUpdate)) { $post->type = 'status-update'; $post->message = isset($data->updateContent->companyStatusUpdate->share->comment) ? $data->updateContent->companyStatusUpdate->share->comment : ""; $post->thumbLink = isset($data->updateContent->companyStatusUpdate->share->content->submittedUrl) ? $data->updateContent->companyStatusUpdate->share->content->submittedUrl : ""; $post->thumbPicture = isset($data->updateContent->companyStatusUpdate->share->content->submittedImageUrl) ? $data->updateContent->companyStatusUpdate->share->content->submittedImageUrl : ""; $post->thumbDescription = isset($data->updateContent->companyStatusUpdate->share->content->description) ? $data->updateContent->companyStatusUpdate->share->content->description : ""; $post->thumbCaption = isset($data->updateContent->companyStatusUpdate->share->content->eyebrowUrl) ? $data->updateContent->companyStatusUpdate->share->content->eyebrowUrl : ""; $post->thumbTitle = isset($data->updateContent->companyStatusUpdate->share->content->title) ? $data->updateContent->companyStatusUpdate->share->content->title : ""; $post->link = ''; //check if we have the correct update-key format // update key format will be UPDATE-c[company_id]-[topic_id].. ex. UPDATE-c1441-5965553136775999488 if (isset($data->updateKey)) { $keyA = explode('-', $data->updateKey); if (strpos($data->updateKey, 'UPDATE') !== false && count($keyA) == 3) { $post->link = 'https://www.linkedin.com/nhome/updates?topic=' . $keyA[2]; } } } if (isset($data->timestamp)) { $timestamp = intval($data->timestamp / 1000); $post->updatedTime = gmdate($stream->options->get('datetime_format'), $timestamp); } else { $post->updatedTime = ""; } $stream->addPost($post); } } }
function onUserAuthenticate($credentials, $options, &$response) { $response->type = 'JFBConnectAuth'; # authentication via facebook for Joomla always uses the FB API and secret keys # When this is present, the user's FB uid is used to look up their Joomla uid and log that user in jimport('joomla.filesystem.file'); $provider = null; if (isset($options['provider'])) { $provider = $options['provider']; } if (class_exists('JFBCFactory') && $provider) { # always check the secret username and password to indicate this is a JFBConnect login #echo "Entering JFBConnectAuth<br>"; if ($credentials['username'] != $provider->appId || $credentials['password'] != $provider->secretKey) { $response->status = JAuthentication::STATUS_FAILURE; return false; } #echo "Passed API/Secret key check, this is a FB login<br>"; include_once JPATH_ADMINISTRATOR . '/components/com_jfbconnect/models/usermap.php'; $userMapModel = new JFBConnectModelUserMap(); $providerUserId = $provider->getProviderUserId(); $app = JFactory::getApplication(); #echo "Facebook user = ".$fbUserId; # test if user is logged into Facebook if ($providerUserId) { # Test if user has a Joomla mapping $jUserId = $userMapModel->getJoomlaUserId($providerUserId, $provider->name); if ($jUserId) { $jUser = JUser::getInstance($jUserId); if ($jUser->id == null) { $userMapModel->deleteMapping($providerUserId, $provider->name); return false; } if ($jUser->block) { $isAllowed = false; JFBCFactory::log(JText::_('JERROR_NOLOGIN_BLOCKED'), 'error'); } else { JPluginHelper::importPlugin('socialprofiles'); $args = array($provider->name, $jUserId, $providerUserId); $responses = $app->triggerEvent('socialProfilesOnAuthenticate', $args); $isAllowed = true; foreach ($responses as $prResponse) { if (is_object($prResponse) && !$prResponse->status) { $isAllowed = false; JFBCFactory::log($prResponse->message, 'error'); } } } if ($isAllowed) { $response->status = JAuthentication::STATUS_SUCCESS; $response->username = $jUser->username; $response->language = $jUser->getParam('language'); $response->email = $jUser->email; $response->fullname = $jUser->name; $response->error_message = ''; return true; } } } } # catch everything else as an authentication failure $response->status = JAuthentication::STATUS_FAILURE; return false; }