Example #1
0
 /**
  * Stores the theme settings in the database
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return	bool		True if success, false otherwise.
  */
 public function update($element, $data)
 {
     $db = FD::db();
     $sql = $db->sql();
     // Check if the records exists first or not.
     $sql->select('#__social_themes');
     $sql->column('COUNT(1)');
     $sql->where('element', $element);
     $db->setQuery($sql);
     $exists = $db->loadResult();
     // Clear previous results
     $sql->clear();
     // Convert the array into a standard json string.
     $params = FD::makeJSON($data);
     $obj = new stdClass();
     $obj->element = $element;
     $obj->params = $params;
     if (!$exists) {
         // Insert
         $state = $db->insertObject('#__social_themes', $obj);
     } else {
         // Update
         $state = $db->updateObject('#__social_themes', $obj, 'element');
     }
     if (!$state) {
         $this->setError(JText::_('There was an error when saving the theme parameters.'));
         return false;
     }
     return true;
 }
Example #2
0
 /**
  * Allows user to save settings
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function saveSettings()
 {
     // Check for request forgeries
     FD::checkToken();
     // Ensure that the user is logged in.
     FD::requireLogin();
     // Get current view.
     $view = $this->getCurrentView();
     // Get current logged in user
     $my = FD::user();
     // Get the app id from request.
     $id = JRequest::getInt('id');
     // Try to load the app
     $app = FD::table('App');
     $app->load($id);
     if (!$id || !$app->id) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_APPS_INVALID_ID_PROVIDED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Ensure that the user can really access this app settings.
     if (!$app->isInstalled()) {
         return $ajax->reject(FD::info()->set(JText::_('COM_EASYSOCIAL_APPS_SETTINGS_NOT_INSTALLED'), SOCIAL_MSG_ERROR));
     }
     $data = JRequest::getVar('data', '');
     // Convert the object to proper json string
     $raw = FD::makeJSON($data);
     $map = FD::table('AppsMap');
     $map->load(array('uid' => $my->id, 'app_id' => $app->id));
     $map->params = $raw;
     // Store user params
     $map->store();
     return $view->call(__FUNCTION__);
 }
Example #3
0
 public function send($data)
 {
     // For json responses, "application/json; charset=utf-8" is the standard content type.
     // Using "application/json" causes IE9 to download the response as a file.
     // Using "text/html" causes unterminated string literal when parsing json response in IE9.
     // Using "text/plain" causes Firebug not to syntax highlight json response.
     // Using anything other than "application/json" causes older Chrome to make warnings that the content-type is obselete.
     header('Content-type: text/plain; UTF-8');
     echo FD::makeJSON($data);
     exit;
 }
 public function main()
 {
     $db = FD::db();
     $sql = $db->sql();
     $sql->select('#__social_config');
     $sql->column('value');
     $sql->where('type', 'site');
     $db->setQuery($sql);
     $value = $db->loadResult();
     $obj = FD::makeObject($value);
     $default = FD::makeObject(SOCIAL_ADMIN_DEFAULTS . '/site.json');
     $obj->avatars->default = $default->avatars->default;
     $obj->covers->default = $default->covers->default;
     $string = FD::makeJSON($obj);
     $sql->clear();
     $sql->update('#__social_config');
     $sql->set('value', $string);
     $sql->where('type', 'site');
     $db->setQuery($sql);
     $db->query();
     return true;
 }
Example #5
0
 /**
  * Method for caller to set errors during registration.
  *
  * Example:
  * <code>
  * </code>
  *
  * @since   1.0
  * @access  public
  * @param   mixed   Array or boolean or string.
  * @return  bool    True if success.
  *
  * @author  Mark Lee <*****@*****.**>
  */
 public function setErrors($errors)
 {
     // If there's no errors, then we should reset the form.
     if (!$errors) {
         $this->set('errors', '');
         return true;
     }
     // Set the error messages.
     $this->errors = FD::makeJSON($errors);
     return true;
 }
Example #6
0
 /**
  * Removes a permission
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function removePermissions($scope)
 {
     $state = $this->api('/me/permissions/' . $scope, 'delete');
     // Update the permissions list.
     $oauthId = $this->getUserId();
     // Load the table as we need to update with the new permissions
     $oauthTable = FD::table('OAuth');
     $oauthTable->load(array('oauth_id' => $oauthId));
     $permissions = FD::json()->decode($oauthTable->permissions);
     $index = array_search($scope, $permissions, false);
     if ($index !== false) {
         unset($permissions[$index]);
     }
     $permissions = array_values($permissions);
     if ($scope == 'publish_actions') {
         $oauthTable->push = false;
     }
     $oauthTable->permissions = FD::makeJSON($permissions);
     // Store the permission here.
     $oauthTable->store();
 }
Example #7
0
 /**
  * Links a user account with an oauth client.
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function linkOAuthUser(SocialOAuth $client, SocialUser $user, $pull = true, $push = true)
 {
     $accessToken = $client->getAccess();
     $oauth = FD::table('OAuth');
     $oauth->uid = $user->id;
     $oauth->type = SOCIAL_TYPE_USER;
     $oauth->client = $client->getType();
     $oauth->oauth_id = $client->getUser();
     $oauth->token = $accessToken->token;
     $oauth->secret = $accessToken->secret;
     $oauth->expires = $accessToken->expires;
     $oauth->pull = $pull;
     $oauth->push = $push;
     // Store the user's meta here.
     try {
         $meta = $client->getUserMeta();
     } catch (Exception $e) {
         $app = JFactory::getApplication();
         // Use dashboard here instead of login because api error calls might come from after user have successfully logged in
         $url = FRoute::dashboard(array(), false);
         $message = (object) array('message' => JText::sprintf('COM_EASYSOCIAL_OAUTH_FACEBOOK_ERROR_MESSAGE', $e->getMessage()), 'type' => SOCIAL_MSG_ERROR);
         FD::info()->set($message);
         $app->redirect($url);
         $app->close();
     }
     $params = FD::registry();
     $params->bind($meta);
     // Store the permissions
     $oauth->permissions = FD::makeJSON($client->getPermissions());
     // Set the params
     $oauth->params = $params->toString();
     // Store oauth record
     $state = $oauth->store();
     if (!$state) {
         $this->setError($oauth->getError());
         return false;
     }
     // Trigger fields to do necessary linking
     // Load profile type.
     // Get all published fields apps.
     $fieldsModel = FD::model('Fields');
     $fields = $fieldsModel->getCustomFields(array('profile_id' => $user->profile_id, 'state' => SOCIAL_STATE_PUBLISHED));
     // Prepare the arguments
     $args = array(&$meta, &$client, &$user);
     // Get the fields library
     $lib = FD::fields();
     // Get the trigger handler
     $handler = $lib->getHandler();
     // Trigger onRegisterOAuthBeforeSave
     $errors = $lib->trigger('onLinkOAuthAfterSave', SOCIAL_FIELDS_GROUP_USER, $fields, $args);
     // @TODO: Send email notification to admin that a user linked their social account with an existing account
     // @TODO: Send email notification to the account owner that they have successfully associated their social account.
     return $state;
 }
Example #8
0
 /**
  * Apps system title (assuming that app itself have already loaded the language file before calling this function)
  * APP_ELEMENT_RULENAME_EMAIL_TITLE
  *
  * Core system title
  * COM_EASYSOCIAL_ELEMENT_RULENAME_SYSTEM_TITLE
  *
  * @since 1.0
  * @access	public
  * @param	array	$participants	The array of participants (user id) of the action
  * @param	array	$options		Custom options of the system notification
  *
  * @return	boolean		State of the system notification
  *
  * @author	Jason Rey <*****@*****.**>
  */
 public function sendSystem($participants, $options = array())
 {
     $users = $this->getUsers('system', $participants);
     if (empty($users)) {
         return false;
     }
     if (is_object($options)) {
         $options = FD::makeArray($options);
     }
     // If params is not set, just give it an empty array
     if (!isset($options['params'])) {
         $options['params'] = array();
     }
     // Assign any non-table key into params automatically
     $columns = FD::db()->getTableColumns('#__social_notifications');
     foreach ($options as $key => $val) {
         if (!in_array($key, $columns)) {
             $options['params'][$key] = $val;
         }
     }
     if (!isset($options['uid'])) {
         $options['uid'] = 0;
     }
     if (!isset($options['type'])) {
         $options['type'] = $this->element;
     }
     if (!isset($options['cmd'])) {
         $options['cmd'] = $options['type'] . '.' . $this->rule;
     }
     if (!isset($options['title'])) {
         $options['title'] = $this->getNotificationTitle('system');
     }
     if (!isset($options['actor_id'])) {
         $options['actor_id'] = FD::user()->id;
     }
     if (!isset($options['actor_type'])) {
         $options['actor_type'] = SOCIAL_TYPE_USER;
     }
     if (!isset($options['target_type'])) {
         $options['target_type'] = SOCIAL_TYPE_USER;
     }
     if (!isset($options['url'])) {
         $options['url'] = JRequest::getURI();
     }
     $notification = FD::notification();
     $data = $notification->getTemplate();
     $data->setObject($options['uid'], $options['type'], $options['cmd']);
     $data->setTitle($options['title']);
     // Only bind content if it's being set
     if (isset($options['content'])) {
         $data->setContent($options['content']);
     }
     // Determines if caller wants aggregation to happen for this system notifications.
     if (isset($options['aggregate'])) {
         $data->setAggregation();
     }
     // Determines if the app wants to set a context_type
     if (isset($options['context_type'])) {
         $data->setContextType($options['context_type']);
     }
     // Determines if the app wants to set a context_type
     if (isset($options['context_ids'])) {
         $data->setContextId($options['context_ids']);
     }
     if (isset($options['actor_id'])) {
         $data->setActor($options['actor_id'], $options['actor_type']);
     }
     if (isset($options['image'])) {
         $data->setImage($options['image']);
     }
     if (isset($options['params'])) {
         $data->setParams(FD::makeJSON($options['params']));
     }
     if (isset($options['url'])) {
         $data->setUrl($options['url']);
     }
     foreach ($users as $uid) {
         // Empty target shouldn't have notification
         if (!empty($uid)) {
             $data->setTarget($uid, $options['target_type']);
             $notification->create($data);
         }
     }
     return true;
 }