Пример #1
0
 /**
  * Given a path to the file, install the points.
  *
  * @since	1.0
  * @access	public
  * @param	string		The path to the .points file.
  * @return	bool		True if success false otherwise.
  */
 public function install($file)
 {
     // Import platform's file library.
     jimport('joomla.filesystem.file');
     // Convert the contents to an object
     $alerts = FD::makeObject($file);
     $result = array();
     if ($alerts) {
         foreach ($alerts as $alert) {
             $table = FD::table('Alert');
             $exists = $table->load(array('element' => $alert->element, 'rule' => $alert->rule));
             if (!$exists) {
                 $table->element = $alert->element;
                 $table->rule = $alert->rule;
                 $table->created = FD::date()->toSql();
                 if (!isset($alert->value)) {
                     $table->email = true;
                     $table->system = true;
                 } else {
                     $table->email = $alert->value->email;
                     $table->system = $alert->value->system;
                 }
             }
             $table->app = isset($alert->app) ? $alert->app : false;
             $table->field = isset($alert->field) ? $alert->field : false;
             $table->group = isset($alert->group) ? $alert->group : false;
             $table->extension = isset($alert->extension) ? $alert->extension : false;
             $table->core = isset($alert->core) ? $alert->core : 0;
             $table->app = isset($alert->app) ? $alert->app : 0;
             $table->field = isset($alert->field) ? $alert->field : 0;
             $result[] = $table->store();
         }
     }
     return $result;
 }
 public function main()
 {
     $db = FD::db();
     $sql = $db->sql();
     // For country field
     $sql->select('#__social_fields_data', 'a')->column('a.*')->leftjoin('#__social_fields', 'b')->on('b.id', 'a.field_id')->leftjoin('#__social_apps', 'c')->on('c.id', 'b.app_id')->where('a.datakey', '')->where('c.type', 'fields')->where('c.element', 'country');
     $db->setQuery($sql);
     $result = $db->loadObjectList();
     $json = FD::json();
     // Load up the list of countries
     $file = SOCIAL_ADMIN_DEFAULTS . '/countries.json';
     $list = FD::makeObject($file);
     foreach ($result as $row) {
         if ($json->isJsonString($row->data)) {
             $data = $json->decode($row->data);
             // Split json object into each individual row
             foreach ($data as $k => $v) {
                 if (!empty($v)) {
                     $table = $this->getTable($row->field_id, $row->uid, $row->type, $k);
                     $country = $list->{$v};
                     $table->data = $country;
                     $table->raw = $country;
                     $table->store();
                 }
             }
         }
         // Remove the row with empty key
         $sql->clear();
         $sql->delete('#__social_fields_data')->where('id', $row->id);
         $db->setQuery($sql);
         $db->query();
     }
     return true;
 }
Пример #3
0
 public function profileHeaderB($key, $user, $field)
 {
     // Get the data
     $data = $field->data;
     if (!$data) {
         return;
     }
     $my = FD::user();
     $privacyLib = FD::privacy($my->id);
     if (!$privacyLib->validate('core.view', $field->id, SOCIAL_TYPE_FIELD, $user->id)) {
         return;
     }
     $obj = FD::makeObject($data);
     $theme = FD::themes();
     $hide = true;
     foreach ($obj as $k => &$v) {
         $v = $theme->html('string.escape', $v);
         if (!empty($v)) {
             $hide = false;
         }
     }
     if ($hide) {
         return true;
     }
     $params = $field->getParams();
     // Convert country to full text
     if (!empty($obj->country)) {
         $obj->country_code = $obj->country;
         $obj->country = SocialFieldsUserAddressHelper::getCountryName($obj->country, $params->get('data_source'));
     }
     $theme->set('value', $obj);
     $theme->set('params', $field->getParams());
     echo $theme->output('fields/user/address/widgets/display');
 }
 public function main()
 {
     $db = FD::db();
     $sql = $db->sql();
     $sql->select('#__social_fields_data', 'a');
     $sql->column('a.id');
     $sql->column('a.data');
     $sql->leftjoin('#__social_fields', 'b');
     $sql->on('a.field_id', 'b.id');
     $sql->leftjoin('#__social_apps', 'c');
     $sql->on('b.app_id', 'c.id');
     $sql->where('c.type', 'fields');
     $sql->where('c.element', 'address');
     $sql->where('a.datakey', '');
     $db->setQuery($sql);
     $result = $db->loadObjectList();
     $json = FD::json();
     // Load up the list of countries
     $file = SOCIAL_ADMIN_DEFAULTS . '/countries.json';
     $list = FD::makeObject($file);
     foreach ($result as $row) {
         if (!$json->isJsonString($row->data)) {
             continue;
         }
         $data = $json->decode($row->data);
         if ($data->city) {
             $data->city = str_replace('`', '\'', $data->city);
         }
         if ($data->state) {
             $data->state = str_replace('`', '\'', $data->state);
         }
         if ($data->zip) {
             $data->zip = str_replace('`', '\'', $data->zip);
         }
         if (!empty($data->country) && strlen($data->country) === 2 && isset($list->{$data->country})) {
             $data->country = $list->{$data->country};
         }
         // Recreate the json string
         $string = $json->encode($data);
         // Recreate the raw data
         unset($data->latitude);
         unset($data->longitude);
         $raw = implode(array_values((array) $data), ' ');
         $raw = str_replace('`', '\'', $raw);
         $sql->clear();
         $sql->update('#__social_fields_data');
         $sql->set('data', $string);
         $sql->set('raw', $raw);
         $sql->where('id', $row->id);
         $db->setQuery($sql);
         $db->query();
     }
     return true;
 }
Пример #5
0
 /**
  * Installs the core rules
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function installCoreRules()
 {
     $file = SOCIAL_ADMIN_DEFAULTS . '/alerts.json';
     // Convert the contents to an object
     $alerts = FD::makeObject($file);
     if ($alerts) {
         foreach ($alerts as $element => $rules) {
             $registry = $this->getRegistry($element);
             foreach ($rules as $item) {
                 $registry->register($item->key, $item->value->email, $item->value->system, array('core' => $item->value->core));
             }
         }
     }
     return true;
 }
Пример #6
0
 /**
  * Processes likes notifications
  *
  * @since   1.2
  * @access  public
  * @param   string
  * @return
  */
 public function execute(&$item)
 {
     // Get likes participants
     $model = FD::model('Likes');
     $users = $model->getLikerIds($item->uid, $item->context_type);
     // Include the actor of the stream item as the recipient
     $users = array_merge(array($item->actor_id), $users);
     // Ensure that the values are unique
     $users = array_unique($users);
     $users = array_values($users);
     // Exclude myself from the list of users.
     $index = array_search(FD::user()->id, $users);
     if ($index !== false) {
         unset($users[$index]);
         $users = array_values($users);
     }
     // Convert the names to stream-ish
     $names = FD::string()->namesToNotifications($users);
     // Load the stream object
     $stream = FD::table('Stream');
     $stream->load($item->uid);
     // Get the link assets
     $assets = $stream->getAssets(SOCIAL_TYPE_LINKS);
     if (!empty($assets)) {
         $asset = $assets[0];
         $link = FD::makeObject($asset->data);
         if ($link) {
             if ($link->link) {
                 $item->content = $link->link;
             }
             if ($link->image) {
                 $item->image = $link->image;
             }
         }
     }
     // We need to determine if the user is the owner
     if ($stream->actor_id == $item->target_id && $item->target_type == SOCIAL_TYPE_USER) {
         $langString = FD::string()->computeNoun('APP_USER_LINKS_NOTIFICATIONS_USER_LIKES_YOUR_LINK_UPDATE', count($users));
         $item->title = JText::sprintf($langString, $names);
         return;
     }
     // For other users, we just post a generic message
     $langString = FD::string()->computeNoun('APP_USER_LINKS_NOTIFICATIONS_USER_LIKES_USERS_LINK_UPDATE', count($users));
     $item->title = JText::sprintf($langString, $names, FD::user($stream->actor_id)->getName());
     return;
 }
Пример #7
0
 /**
  * Retrieve updates from news update servers.
  *
  * @since	1.0
  * @access	public
  * @param	string	The name of the app.
  * @return	Array	An array of news objects.
  *
  * @author	Mark Lee <*****@*****.**>
  */
 public function getNews($app = 'easysocial')
 {
     switch ($app) {
         // This is the core news item.
         case 'easysocial':
             $url = SOCIAL_SERVICE_NEWS;
             break;
     }
     $connector = FD::get('Connector');
     $connector->addUrl($url);
     $connector->connect();
     // Get the json contents
     $contents = $connector->getResult($url);
     // Convert the json string to an object.
     $obj = FD::makeObject($contents);
     return $obj;
 }
 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;
 }
Пример #9
0
 /**
  * Checks if this field is filled in.
  *
  * @author Jason Rey <*****@*****.**>
  * @since  1.3
  * @access public
  * @param  array        $data   The post data.
  * @param  SocialUser   $user   The user being checked.
  */
 public function onProfileCompleteCheck($user)
 {
     if (!FD::config()->get('user.completeprofile.strict') && !$this->isRequired()) {
         return true;
     }
     if (empty($this->value)) {
         return false;
     }
     $obj = FD::makeObject($this->value);
     if (empty($obj->first) && empty($user->name)) {
         return false;
     }
     return true;
 }
Пример #10
0
 /**
  * Processes likes notifications
  *
  * @since   1.2
  * @access  public
  * @param   string
  * @return
  */
 public function execute(&$item)
 {
     // Get likes participants
     $model = FD::model('Likes');
     $users = $model->getLikerIds($item->uid, $item->context_type);
     // Merge to include actor, diff to exclude self, unique to remove dups, and values to reset the index
     $users = array_values(array_unique(array_diff(array_merge($users, array($item->actor_id)), array(FD::user()->id))));
     // Convert the names to stream-ish
     $names = FD::string()->namesToNotifications($users);
     // When someone likes on the photo that you have uploaded in a event
     if ($item->context_type == 'photos.event.share') {
         $this->notificationPhotos($names, $users, $item);
         return;
     }
     // When someone likes your post in a event
     if ($item->context_type == 'story.event.create') {
         // Get the owner of the stream item since we need to notify the person
         $stream = FD::table('Stream');
         $stream->load($item->uid);
         // Get the event from the stream
         $event = FD::event($stream->cluster_id);
         // Set the content
         if ($event) {
             $item->image = $event->getAvatar();
         }
         // We need to generate the notification message differently for the author of the item and the recipients of the item.
         if ($stream->actor_id == $item->target_id && $item->target_type == SOCIAL_TYPE_USER) {
             $langString = FD::string()->computeNoun('APP_EVENT_STORY_USER_LIKES_YOUR_POST', count($users));
             $item->title = JText::sprintf($langString, $names, $event->getName());
             return $item;
         }
         // This is for 3rd party viewers
         $langString = FD::string()->computeNoun('APP_EVENT_STORY_USER_LIKES_USERS_POST', count($users));
         $item->title = JText::sprintf($langString, $names, FD::user($stream->actor_id)->getName(), $event->getName());
         return;
     }
     if ($item->context_type == 'links.create') {
         // Get the owner of the stream item since we need to notify the person
         $stream = FD::table('Stream');
         $stream->load($item->uid);
         // Get the event from the stream
         $event = FD::event($stream->cluster_id);
         // Set the content
         if ($event) {
             $item->image = $event->getAvatar();
         }
         // Get the link object
         $model = FD::model('Stream');
         $links = $model->getAssets($item->uid, SOCIAL_TYPE_LINKS);
         if ($links) {
             $link = FD::makeObject($links[0]->data);
             $item->content = $link->link;
             $item->image = $link->image;
         }
         // We need to generate the notification message differently for the author of the item and the recipients of the item.
         if ($stream->actor_id == $item->target_id && $item->target_type == SOCIAL_TYPE_USER) {
             $langString = FD::string()->computeNoun('APP_EVENT_STORY_USER_LIKES_YOUR_LINK', count($users));
             $item->title = JText::sprintf($langString, $names, $event->getName());
             return $item;
         }
         // This is for 3rd party viewers
         $langString = FD::string()->computeNoun('APP_EVENT_STORY_USER_LIKES_USERS_LINK', count($users));
         $item->title = JText::sprintf($langString, $names, FD::user($stream->actor_id)->getName(), $event->getName());
         return;
     }
     return $item;
 }
Пример #11
0
 public function load($data)
 {
     $obj = FD::makeObject($data);
     if ($obj) {
         foreach ($obj as $key => $value) {
             $this->helper->set($key, $value);
         }
         // exit;
     }
     return true;
 }
Пример #12
0
 /**
  * Loads the form data
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function load($data = null)
 {
     $this->form = FD::makeObject($data);
 }
Пример #13
0
 /**
  * Processes likes notifications
  *
  * @since   1.2
  * @access  public
  * @param   string
  * @return
  */
 public function execute(&$item)
 {
     // Get likes participants
     $model = FD::model('Likes');
     $users = $model->getLikerIds($item->uid, $item->context_type);
     // Include the actor of the stream item as the recipient
     $users = array_merge(array($item->actor_id), $users);
     // Ensure that the values are unique
     $users = array_unique($users);
     $users = array_values($users);
     // Exclude myself from the list of users.
     $my = FD::user();
     $index = array_search($my->id, $users);
     if ($index !== false) {
         unset($users[$index]);
         $users = array_values($users);
     }
     if (!$users) {
         return false;
     }
     // Convert the names to stream-ish
     $names = FD::string()->namesToNotifications($users);
     // When someone likes on the photo that you have uploaded in a group
     if ($item->context_type == 'photos.group.share') {
         $this->notificationPhotos($names, $users, $item);
         return;
     }
     // When someone likes your post in a group
     if ($item->context_type == 'story.group.create') {
         // Get the owner of the stream item since we need to notify the person
         $stream = FD::table('Stream');
         $stream->load($item->uid);
         // Get the group from the stream
         $group = FD::group($stream->cluster_id);
         // Set the content
         if ($group) {
             $item->image = $group->getAvatar();
         }
         // We need to generate the notification message differently for the author of the item and the recipients of the item.
         if ($stream->actor_id == $item->target_id && $item->target_type == SOCIAL_TYPE_USER) {
             $langString = FD::string()->computeNoun('APP_GROUP_STORY_USER_LIKES_YOUR_POST', count($users));
             $item->title = JText::sprintf($langString, $names, $group->getName());
             return $item;
         }
         // This is for 3rd party viewers
         $langString = FD::string()->computeNoun('APP_GROUP_STORY_USER_LIKES_USERS_POST', count($users));
         $item->title = JText::sprintf($langString, $names, FD::user($stream->actor_id)->getName(), $group->getName());
         return;
     }
     if ($item->context_type == 'links.create') {
         // Get the owner of the stream item since we need to notify the person
         $stream = FD::table('Stream');
         $stream->load($item->uid);
         // Get the group from the stream
         $group = FD::group($stream->cluster_id);
         // Set the content
         if ($group) {
             $item->image = $group->getAvatar();
         }
         // Get the link object
         $model = FD::model('Stream');
         $links = $model->getAssets($item->uid, SOCIAL_TYPE_LINKS);
         if ($links) {
             $link = FD::makeObject($links[0]->data);
             $item->content = $link->link;
             $item->image = $link->image;
         }
         // We need to generate the notification message differently for the author of the item and the recipients of the item.
         if ($stream->actor_id == $item->target_id && $item->target_type == SOCIAL_TYPE_USER) {
             $langString = FD::string()->computeNoun('APP_GROUP_STORY_USER_LIKES_YOUR_LINK', count($users));
             $item->title = JText::sprintf($langString, $names, $group->getName());
             return $item;
         }
         // This is for 3rd party viewers
         $langString = FD::string()->computeNoun('APP_GROUP_STORY_USER_LIKES_USERS_LINK', count($users));
         $item->title = JText::sprintf($langString, $names, FD::user($stream->actor_id)->getName(), $group->getName());
         return;
     }
     return $item;
 }
Пример #14
0
 /**
  * Processes comment notifications
  *
  * @since   1.2
  * @access  public
  * @param   string
  * @return
  */
 public function execute(SocialTableNotification &$item)
 {
     // Get the owner of the stream item since we need to notify the person
     $stream = FD::table('Stream');
     $stream->load($item->uid);
     // Get the event from the stream
     $event = FD::event($stream->cluster_id);
     // Get comment participants
     $model = FD::model('Comments');
     $users = $model->getParticipants($item->uid, $item->context_type);
     // Merge to include actor, diff to exclude self, unique to remove dups, and values to reset the index
     $users = array_values(array_unique(array_diff(array_merge($users, array($item->actor_id)), array(FD::user()->id))));
     // By default content is always empty;
     $content = '';
     // Only show the content when there is only 1 item
     if (count($users) == 1) {
         // Legacy fix for prior to 1.2 as there is no content stored.
         if (!empty($item->content)) {
             $content = JString::substr(strip_tags($item->content), 0, 30);
             if (JString::strlen($item->content) > 30) {
                 $content .= JText::_('COM_EASYSOCIAL_ELLIPSES');
             }
         }
     }
     // Set the content to the stream
     $item->content = $content;
     // Convert the names to stream-ish
     $names = FD::string()->namesToNotifications($users);
     if ($item->context_type == 'photos.event.share') {
         $this->notificationPhotos($names, $users, $item);
         return;
     }
     // When someone comments on your status update in a event.
     if ($item->context_type == 'story.event.create') {
         // We need to generate the notification message differently for the author of the item and the recipients of the item.
         if ($stream->actor_id == $item->target_id && $item->target_type == SOCIAL_TYPE_USER) {
             $item->title = JText::sprintf(FD::string()->computeNoun('APP_EVENT_STORY_USER_POSTED_COMMENT_ON_YOUR_POST', count($users)), $names, $event->getName());
             return $item;
         }
         // This is for 3rd party viewers
         $item->title = JText::sprintf(FD::string()->computeNoun('APP_EVENT_STORY_USER_POSTED_COMMENT_ON_USERS_POST', count($users)), $names, FD::user($stream->actor_id)->getName(), $event->getName());
         return $item;
     }
     // When someone comments on the link you shared in the event
     if ($item->context_type == 'links.event.create') {
         // Get the stream object
         $stream = FD::table('Stream');
         $stream->load($item->uid);
         // Get the event object
         $event = FD::event($stream->cluster_id);
         // Get the link object
         $model = FD::model('Stream');
         $links = $model->getAssets($item->uid, SOCIAL_TYPE_LINKS);
         if ($links) {
             $link = FD::makeObject($links[0]->data);
             $item->content = $link->link;
             $item->image = $link->image;
         }
         // We need to generate the notification message differently for the author of the item and the recipients of the item.
         if ($stream->actor_id == $item->target_id && $item->target_type == SOCIAL_TYPE_USER) {
             $item->title = JText::sprintf(FD::string()->computeNoun('APP_EVENT_STORY_USER_COMMENTED_ON_YOUR_LINK', count($users)), $names, $event->getName());
             return $item;
         }
         // This is for 3rd party viewers
         $item->title = JText::sprintf(FD::string()->computeNoun('APP_EVENT_STORY_USER_COMMENTED_ON_USERS_LINK', count($users)), $names, FD::user($stream->actor_id)->getName(), $event->getName());
         return;
     }
 }
Пример #15
0
 public function load($data)
 {
     if (empty($data)) {
         return false;
     }
     $data = FD::makeObject($data);
     if (!$data) {
         return false;
     }
     $json = FD::json();
     foreach ($data as $key => $val) {
         if ($key == 'daily') {
             $val = FD::makeArray($val);
         }
         $this->{$key} = $val;
     }
     return true;
 }
Пример #16
0
 /**
  * Render's application parameters form.
  *
  * @since	1.0
  * @access	public
  * @param	null
  * @return	string	HTML codes.
  *
  * @author	Mark Lee <*****@*****.**>
  */
 public function renderForm($type = 'form', $params = null, $prefix = '', $tabs = false)
 {
     // Get the manifest path.
     $file = $this->getManifestPath($type);
     if ($file === false) {
         return false;
     }
     $registry = FD::makeObject($file);
     // Check for custom callbacks
     foreach ($registry as &$section) {
         foreach ($section->fields as &$field) {
             if (isset($field->callback)) {
                 $callable = FD::apps()->getCallable($field->callback);
                 if (!$callable) {
                     continue;
                 }
                 $field->options = call_user_func_array($callable, array($this));
             }
         }
     }
     // Get the parameter object.
     $form = FD::get('Form');
     $form->load($registry);
     if ($params) {
         $form->bind($params);
     } else {
         // Bind the stored data with the params.
         $form->bind($this->params);
     }
     // Get the HTML output.
     return $form->render($tabs, false, '', $prefix);
 }
Пример #17
0
 /**
  * Responsible to create the default custom fields for a profile.
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function createDefaultItems($categoryId, $categoryType, $nodeType)
 {
     // $categoryId is the id on the category
     // $categoryType is the type of the category, eg: profiles, clusters
     // $nodeType is the unit within the category instead of the category representation, eg: user, group, event
     // This is because while events and groups is considered clusters, they have different sets of "default fields" to init
     $path = SOCIAL_ADMIN_DEFAULTS . '/fields/' . $nodeType . '.json';
     if (!JFile::exists($path)) {
         return false;
     }
     $defaults = FD::makeObject($path);
     // If there's a problem decoding the file, log some errors here.
     if (!$defaults) {
         $this->setError('Empty default object');
         return false;
     }
     // Init sequence
     $sequence = 1;
     // Init uniquekeys
     $uniqueKeys = array();
     // Let's go through each of the default items.
     foreach ($defaults as $step) {
         // Create default step for this profile.
         $stepTable = FD::table('FieldStep');
         $stepTable->bind($step);
         // Set the sequence
         $stepTable->sequence = $sequence++;
         // Map the correct uid and type.
         $stepTable->uid = $categoryId;
         $stepTable->type = $categoryType;
         // Set the state
         $stepTable->state = isset($step->state) ? $step->state : SOCIAL_STATE_PUBLISHED;
         // Set this to show in registration by default
         $stepTable->visible_registration = isset($step->visible_registration) ? $step->visible_registration : SOCIAL_STATE_PUBLISHED;
         // Set this to show in edit by default
         $stepTable->visible_edit = isset($step->visible_edit) ? $step->visible_edit : SOCIAL_STATE_PUBLISHED;
         // Set this to show in display by default
         $stepTable->visible_display = isset($step->visible_display) ? $step->visible_display : SOCIAL_STATE_PUBLISHED;
         // Try to store the default steps.
         $state = $stepTable->store();
         if (!$state || !$step->fields) {
             continue;
         }
         // Now we need to create all the fields that are in the current step
         // Init ordering
         $ordering = 0;
         foreach ($step->fields as $field) {
             $appTable = FD::table('App');
             $state = $appTable->load(array('element' => $field->element, 'group' => $nodeType, 'type' => SOCIAL_APPS_TYPE_FIELDS));
             // If the app doesn't exist, we shouldn't add it.
             if ($state && ($appTable->state == SOCIAL_STATE_PUBLISHED || $appTable->core == SOCIAL_STATE_PUBLISHED)) {
                 $fieldTable = FD::table('Field');
                 $fieldTable->bind($field);
                 // Set the ordering
                 $fieldTable->ordering = $ordering++;
                 // Ensure that the main items are being JText correctly.
                 $fieldTable->title = $field->title;
                 $fieldTable->description = $field->description;
                 $fieldTable->default = isset($field->default) ? $field->default : '';
                 // Set the app id.
                 $fieldTable->app_id = $appTable->id;
                 // Set the step.
                 $fieldTable->step_id = $stepTable->id;
                 // Set this to show title by default
                 $fieldTable->display_title = isset($field->display_title) ? $field->display_title : SOCIAL_STATE_PUBLISHED;
                 // Set this to show description by default
                 $fieldTable->display_description = isset($field->display_description) ? $field->display_description : SOCIAL_STATE_PUBLISHED;
                 // Set this to be published by default.
                 $fieldTable->state = isset($field->state) ? $field->state : SOCIAL_STATE_PUBLISHED;
                 // Set this to be searchable by default.
                 $fieldTable->searchable = isset($field->searchable) ? $field->searchable : SOCIAL_STATE_PUBLISHED;
                 // Set this to be required by default.
                 $fieldTable->required = isset($field->required) ? $field->required : SOCIAL_STATE_PUBLISHED;
                 // Set this to show in registration by default
                 $fieldTable->visible_registration = isset($field->visible_registration) ? $field->visible_registration : SOCIAL_STATE_PUBLISHED;
                 // Set this to show in edit by default
                 $fieldTable->visible_edit = isset($field->visible_edit) ? $field->visible_edit : SOCIAL_STATE_PUBLISHED;
                 // Set this to show in display by default
                 $fieldTable->visible_display = isset($field->visible_display) ? $field->visible_display : SOCIAL_STATE_PUBLISHED;
                 // Check if the default items has a params.
                 if (isset($field->params)) {
                     $fieldTable->params = FD::json()->encode($field->params);
                 }
                 // Store the field item.
                 $fieldTable->store();
                 // Generate unique key for this field after store (this is so that we have the field id)
                 $keys = !empty($uniqueKeys[$stepTable->id][$fieldTable->id]) ? $uniqueKeys[$stepTable->id][$fieldTable->id] : null;
                 $fieldTable->generateUniqueKey($keys);
                 // Store the unique key into list of unique keys to prevent querying for keys unnecessarily
                 $uniqueKeys[$stepTable->id][$fieldTable->id][] = $fieldTable->unique_key;
                 // We store again to save the unique key
                 $fieldTable->store();
             }
         }
     }
     return true;
 }
Пример #18
0
 /**
  * Processes comment notifications
  *
  * @since   1.2
  * @access  public
  * @param   string
  * @return
  */
 public function execute(SocialTableNotification &$item)
 {
     // Get the group item
     $group = FD::group($item->context_ids);
     // Get the actor
     $actor = FD::user($item->actor_id);
     // Format the title
     if ($item->context_type == 'story.group.create') {
         $item->title = JText::sprintf('APP_GROUP_STORY_USER_POSTED_IN_GROUP', $actor->getName(), $group->getName());
         $item->image = $group->getAvatar();
         // Ensure that the content is properly formatted
         $item->content = JString::substr(strip_tags($item->content), 0, 80) . JText::_('COM_EASYSOCIAL_ELLIPSES');
         return $item;
     }
     if ($item->context_type == 'links.group.create') {
         $model = FD::model('Stream');
         $links = $model->getAssets($item->uid, SOCIAL_TYPE_LINKS);
         if (!$links) {
             return;
         }
         $link = FD::makeObject($links[0]->data);
         $item->image = $link->image;
         $item->content = $link->link;
         $item->title = JText::sprintf('APP_GROUP_STORY_USER_SHARED_LINK_IN_GROUP', $actor->getName(), $group->getName());
     }
     // Someone shared a file in a group
     if ($item->context_type == 'file.group.uploaded') {
         // Get the file object
         $file = FD::table('File');
         $file->load($item->context_ids);
         $group = FD::group($item->uid);
         $item->title = JText::sprintf('APP_GROUP_STORY_USER_SHARED_FILE_IN_GROUP', $actor->getName(), $group->getName());
         $item->content = $file->name;
         if ($file->hasPreview()) {
             $item->image = $file->getPreviewURI();
         }
         return;
     }
     // Someone shared a photo in a group
     if ($item->context_type == 'photos.group.share') {
         // Based on the stream id, we need to get the stream item id.
         $stream = FD::table('Stream');
         $stream->load($item->uid);
         // Get child items
         $streamItems = $stream->getItems();
         // Since we got all the child of stream, we can get the correct count
         $count = count($streamItems);
         if ($count <= 1) {
             $photo = FD::table('Photo');
             $photo->load($streamItems[0]->id);
             $item->title = JText::sprintf('APP_GROUP_STORY_USER_SHARED_SINGLE_PHOTO_IN_GROUP', $actor->getName(), $group->getName());
             $item->image = $photo->getSource();
             $item->content = '';
             return;
         }
         $item->title = JText::sprintf('APP_GROUP_STORY_USER_SHARED_MULTIPLE_PHOTOS_IN_GROUP', $actor->getName(), $count, $group->getName());
         $item->content = '';
         return;
     }
     return $item;
 }
Пример #19
0
 /**
  * Method for caller to retrieve errors during registration.
  *
  * Example:
  * <code>
  * </code>
  *
  * @since   1.0
  * @access  public
  * @param   null
  * @return  Array|bool  An array of standard objects or false when there are no errors.
  *
  * @author  Mark Lee <*****@*****.**>
  */
 public function getErrors($key = null)
 {
     // If there's no errors,
     if (!$this->errors || is_null($this->errors)) {
         return false;
     }
     // Error code is always a JSON string. Decode the error string.
     $obj = FD::makeObject($this->errors);
     // Get the vars from the object since they are stored in key/value form.
     $errors = get_object_vars($obj);
     if (!is_null($key)) {
         if (!isset($errors[$key])) {
             return false;
         }
         return $errors[$key];
     }
     return $errors;
 }
Пример #20
0
 /**
  * Retrieves the city value if available.
  *
  * @since   1.2
  * @access  public
  * @return  mixed   String if state is found, false otherwise.
  */
 public function getCity()
 {
     $params = FD::makeObject($this->params);
     if (isset($params->address_components[2]) && $params->address_components[2]->types[0] == 'locality') {
         return $params->address_components[2]->short_name;
     }
     return false;
 }
Пример #21
0
 public function install($path)
 {
     jimport('joomla.filesystem.file');
     $data = FD::makeObject($path);
     if (empty($data)) {
         FD::logError(__FILE__, __LINE__, 'ACCESS: Unable to read the file ' . $path);
         $this->setError(JText::_('Unable to read access file'));
         return false;
     }
     $json = FD::json();
     $now = FD::date()->toSQL();
     $result = array();
     foreach ($data as $row) {
         if (empty($row->name)) {
             continue;
         }
         $name = $row->name;
         unset($row->name);
         $element = '';
         if (!empty($row->element)) {
             $element = $row->element;
         } else {
             // If no element is defined, then we check if the name has a . starting from index 1 to get the first segment
             if (strpos($name, '.') > 0) {
                 $tmp = explode('.', $name);
                 $element = $tmp[0];
             }
         }
         unset($row->element);
         $group = !empty($row->group) ? $row->group : SOCIAL_TYPE_USER;
         unset($row->group);
         $extension = !empty($row->extension) ? $row->extension : SOCIAL_COMPONENT_NAME;
         unset($row->extension);
         $table = FD::table('accessrules');
         $state = $table->load(array('name' => $name, 'element' => $element, 'group' => $group, 'extension' => $extension));
         if ($state) {
             continue;
         }
         $table->name = $name;
         $table->element = $element;
         $table->group = $group;
         $table->extension = $extension;
         $this->loadLanguage($extension);
         // JText here because the title/description is not used in frontend, and also due to "search" using SQL like to perform, we should store translated text into db
         $table->title = !empty($row->title) ? JText::_($row->title) : '';
         $table->description = !empty($row->description) ? JText::_($row->description) : '';
         unset($row->title);
         unset($row->description);
         $table->state = SOCIAL_STATE_PUBLISHED;
         $table->created = $now;
         $table->params = $json->encode($row);
         $table->store();
         $result[] = $table->title;
     }
     return $result;
 }
Пример #22
0
 public function saveCover(&$post, $uid, $type)
 {
     $coverData = !empty($post[$this->inputName]) ? $post[$this->inputName] : '';
     unset($post[$this->inputName]);
     if (empty($coverData)) {
         return true;
     }
     $coverData = FD::makeObject($coverData);
     // Get the cover table.
     $cover = FD::table('Cover');
     // Try to load existing cover
     $state = $cover->load(array('uid' => $uid, 'type' => $type));
     // If no existing cover, then we set the uid and type.
     if (!$state) {
         $cover->uid = $uid;
         $cover->type = $type;
     }
     // If both data does not exist, then we don't proceed to store the data.
     if (empty($coverData->data) && empty($coverData->position)) {
         return true;
     }
     if (!empty($coverData->data)) {
         if ($coverData->data === 'delete') {
             $cover->delete();
             return true;
         }
         $coverObj = FD::makeObject($coverData->data);
         // Get the cover album.
         $album = SocialFieldsUserCoverHelper::getDefaultAlbum($uid, $type);
         // Create the photo object.
         $photo = SocialFieldsUserCoverHelper::createPhotoObject($uid, $type, $album->id, $coverObj->stock->title, false);
         // If there are no cover set for this album, set it as cover.
         if (empty($album->cover_id)) {
             $album->cover_id = $photo->id;
             $album->store();
         }
         // Construct the path to where the photo is temporarily uploaded.
         // $tmpPath = SocialFieldsUserCoverHelper::getPath($this->inputName);
         $tmpPath = dirname($coverObj->stock->path);
         // Get the supposed path of where the cover should be
         // Instead of doing SocialPhotos::getStoragePath, I copied the logic from there but only to create the folders up until albumId section.
         // We do not want JPATH_ROOT to be included in the $storage variable
         $storage = '/' . FD::cleanPath(FD::config()->get('photos.storage.container'));
         FD::makeFolder(JPATH_ROOT . $storage);
         $storage .= '/' . $album->id;
         FD::makeFolder(JPATH_ROOT . $storage);
         $storage .= '/' . $photo->id;
         FD::makeFolder(JPATH_ROOT . $storage);
         // Copy the photo from the temporary path to the storage folder.
         $state = JFolder::copy($tmpPath, JPATH_ROOT . $storage, '', true);
         // If cannot copy out the photo, then don't proceed
         if ($state !== true) {
             $this->setError(JText::_('PLG_FIELDS_COVER_ERROR_UNABLE_TO_MOVE_FILE'));
             return false;
         }
         // Create the photo meta for each available sizes.
         foreach ($coverObj as $key => $value) {
             SocialFieldsUserCoverHelper::createPhotoMeta($photo, $key, $storage . '/' . $value->file);
         }
         // Set the uploaded photo as cover for this user.
         $cover->setPhotoAsCover($photo->id);
     }
     // Set the position of the cover if available.
     if (!empty($coverData->position)) {
         $position = FD::makeObject($coverData->position);
         if (isset($position->x)) {
             $cover->x = $position->x;
         }
         if (isset($position->y)) {
             $cover->y = $position->y;
         }
     }
     // Store the cover object
     $cover->store();
     // And we're done.
     return true;
 }
Пример #23
0
 /**
  * Prepares the stream item
  *
  * @since	1.0
  * @access	public
  * @param	SocialStreamItem	The stream object.
  * @param	bool				Determines if we should respect the privacy
  */
 public function onPrepareStream(SocialStreamItem &$item, $includePrivacy = true)
 {
     if ($item->context !== 'feeds') {
         return;
     }
     // Get app params
     $params = $this->getParams();
     if (!$params->get('stream_create', true)) {
         return;
     }
     // Get the feed table
     $obj = FD::makeObject($item->params);
     $feed = $this->getTable('Feed');
     $feed->bind($obj);
     $actor = $item->actor;
     $app = $this->getApp();
     $this->set('app', $app);
     $this->set('feed', $feed);
     $this->set('actor', $actor);
     $item->color = '#e67e22';
     $item->display = SOCIAL_STREAM_DISPLAY_FULL;
     $item->fonticon = 'ies-feed';
     $item->label = FD::_('APP_USER_FEED_STREAM_TOOLTIP', true);
     $item->title = parent::display('streams/' . $item->verb . '.title');
     $item->content = parent::display('streams/' . $item->verb . '.content');
 }
Пример #24
0
 /**
  * Retrieves the latest version of EasySocial from the server
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public static function getOnlineVersion()
 {
     $connector = FD::get('Connector');
     $connector->addUrl(SOCIAL_SERVICE_NEWS);
     $connector->connect();
     $contents = $connector->getResult(SOCIAL_SERVICE_NEWS);
     $obj = FD::makeObject($contents);
     if (empty($obj->version)) {
         return '';
     }
     return $obj->version;
 }
Пример #25
0
 public function synchronizeDatabase()
 {
     $version = $this->input->getString('version');
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     // Explicitly check for 1.0.0 since it is a flag to execute table creation
     if ($version === '1.0.0') {
         $path = SOCIAL_ADMIN . '/queries';
         if (!JFolder::exists($path)) {
             return $this->view->call(__FUNCTION__);
         }
         $files = JFolder::files($path, '.sql$', true, true);
         $result = array();
         $db = FD::db();
         foreach ($files as $file) {
             $contents = JFile::read($file);
             $queries = JInstallerHelper::splitSql($contents);
             foreach ($queries as $query) {
                 $query = trim($query);
                 if (!empty($query)) {
                     $db->setQuery($query);
                     $db->execute();
                 }
             }
         }
         return $this->view->call(__FUNCTION__);
     }
     $path = SOCIAL_ADMIN . '/updates/' . $version;
     $files = JFolder::files($path, '.json$', true, true);
     $result = array();
     foreach ($files as $file) {
         $result = array_merge($result, FD::makeObject($file));
     }
     $tables = array();
     $indexes = array();
     $affected = 0;
     $db = FD::db();
     foreach ($result as $row) {
         $columnExist = true;
         $indexExist = true;
         if (isset($row->column)) {
             // Store the list of tables that needs to be queried
             if (!isset($tables[$row->table])) {
                 $tables[$row->table] = $db->getTableColumns($row->table);
             }
             // Check if the column is in the fields or not
             $columnExist = in_array($row->column, $tables[$row->table]);
         }
         if (isset($row->index)) {
             if (!isset($indexes[$row->table])) {
                 $indexes[$row->table] = $db->getTableIndexes($row->table);
             }
             $indexExist = in_array($row->index, $indexes[$row->table]);
         }
         if (!$columnExist || !$indexExist) {
             $sql = $db->sql();
             $sql->raw($row->query);
             $db->setQuery($sql);
             $db->query();
             $affected += 1;
         }
     }
     return $this->view->call(__FUNCTION__);
 }
Пример #26
0
 /**
  * Retrieves the language that the user is currently using
  *
  * @since	1.2
  * @access	public
  * @return	string	The locale of the language.
  */
 public function getLanguage()
 {
     static $params = array();
     if (!isset($params[$this->id])) {
         $obj = FD::makeObject($this->params);
         // Get the locale the user is using
         $locale = !empty($obj->language) ? $obj->language : '';
         // If the user configures to use the site language, get the default language of the site.
         if (empty($locale)) {
             $jConfig = FD::jConfig();
             $locale = $jConfig->getValue('language');
         }
         $params[$this->id] = $locale;
     }
     return $params[$this->id];
 }
Пример #27
0
 /**
  * Get a list of preset moods
  *
  * @since	1.2
  * @access	public
  * @param	string
  * @return
  */
 public function getMoods($gender = "_NOGENDER")
 {
     $moods = array();
     // @TODO: In the future, we could scan for moods
     $verbs = array('feeling');
     foreach ($verbs as $verb) {
         $file = dirname(__FILE__) . '/moods/' . $verb . '.mood';
         $verb = FD::makeObject($file);
         // Apppend gender suffix to language keys
         foreach ($verb->moods as $mood) {
             $mood->text .= $gender;
             $mood->subject .= $gender;
         }
         $moods[$verb->key] = $verb;
     }
     return $moods;
 }
Пример #28
0
 /**
  * Process any translations in the email templates
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function translate($content, $arguments)
 {
     // Need to JText first as we start to pass in raw key for multilinguage purposes
     $output = JText::_($content);
     // Ensure that the params are always in object form
     $arguments = FD::makeObject($arguments);
     // Get the list of arguments
     if (is_object($arguments)) {
         $arguments = get_object_vars($arguments);
     }
     if (isset($arguments['_tbl_keys'])) {
         //most likely this key get added using jtable object.
         // we need to exclude this key
         unset($arguments['_tbl_keys']);
     }
     // Get a list of keys so we can prepend it with { and prepend it with }
     $keys = array_keys($arguments);
     foreach ($keys as &$key) {
         $key = '{' . $key . '}';
     }
     // Get the list of values
     $values = array_values($arguments);
     // Perform a search / replace of strings based on the arguments.
     $output = JString::str_ireplace($keys, $values, $output);
     // // Process translations
     // preg_match_all( '/%TRANSLATE\{(.*)\}%/i' , $content , $matches );
     // // Let's perform the translations first.
     // if( isset( $matches[ 1 ] ) && !empty( $matches[ 1 ] ) )
     // {
     // 	$translations   = $matches[ 0 ];
     // 	for( $i = 0; $i < count( $translations ); $i++ )
     // 	{
     // 		$str        = explode( ',' , $matches[ 1 ][ $i ] );
     // 		if( count( $str ) > 1 )
     // 		{
     // 			$content    = str_ireplace( $translations[ $i ] , call_user_func_array( array( 'JText' , 'sprintf' ) , $str )  , $content );
     // 		}
     // 		else
     // 		{
     // 			$content    = str_ireplace( $translations[ $i ] , JText::_( $matches[ 1 ][ $i ] ) , $content );
     // 		}
     // 	}
     // }
     return $output;
 }
Пример #29
0
 /**
  * Reverse geocode the
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function reverse($latitude, $longitude)
 {
     $url = $this->getURL(self::METHOD_REVERSE, $latitude . ',' . $longitude);
     $connector = FD::get('Connector');
     $connector->addUrl($url);
     $connector->connect();
     // Get the result
     $result = $connector->getResult($url);
     // Since the result is in json string, we need to decode it back to a proper php object.
     $obj = FD::makeObject($result);
     if ($obj->status !== 'OK') {
         return false;
     }
     return $obj->results[0]->formatted_address;
 }
Пример #30
0
 public function createAvatar($value, $uid, $createStream = true, $deleteImage = true)
 {
     $value = FD::makeObject($value);
     if (!empty($value->data)) {
         $value->data = FD::makeObject($value->data);
     }
     if ($value->type === 'remove') {
         $table = FD::table('avatar');
         $state = $table->load(array('uid' => $uid, 'type' => $this->group));
         if ($state) {
             $table->delete();
             if ($this->group == SOCIAL_TYPE_USER) {
                 $user = FD::user($uid);
                 // Prepare the dispatcher
                 FD::apps()->load(SOCIAL_TYPE_USER);
                 $dispatcher = FD::dispatcher();
                 $args = array(&$user, &$table);
                 // @trigger: onUserAvatarRemove
                 $dispatcher->trigger(SOCIAL_TYPE_USER, 'onUserAvatarRemove', $args);
             }
         }
         return true;
     }
     if ($value->type === 'gallery') {
         $table = FD::table('avatar');
         $state = $table->load(array('uid' => $uid, 'type' => $this->group));
         if (!$state) {
             $table->uid = $uid;
             $table->type = $this->group;
         }
         $table->avatar_id = $value->source;
         $table->store();
         return true;
     }
     if ($value->type === 'upload') {
         $data = new stdClass();
         if (!empty($value->path)) {
             $image = FD::image();
             $image->load($value->path);
             $avatar = FD::avatar($image, $uid, $this->group);
             // Check if there's a profile photos album that already exists.
             $albumModel = FD::model('Albums');
             // Retrieve the user's default album
             $album = $albumModel->getDefaultAlbum($uid, $this->group, SOCIAL_ALBUM_PROFILE_PHOTOS);
             $photo = FD::table('Photo');
             $photo->uid = $uid;
             $photo->type = $this->group;
             $photo->user_id = $this->group == SOCIAL_TYPE_USER ? $uid : FD::user()->id;
             $photo->album_id = $album->id;
             $photo->title = $value->name;
             $photo->caption = '';
             $photo->ordering = 0;
             // We need to set the photo state to "SOCIAL_PHOTOS_STATE_TMP"
             $photo->state = SOCIAL_PHOTOS_STATE_TMP;
             // Try to store the photo first
             $state = $photo->store();
             if (!$state) {
                 $this->setError(JText::_('PLG_FIELDS_AVATAR_ERROR_CREATING_PHOTO_OBJECT'));
                 return false;
             }
             // Push all the ordering of the photo down
             $photosModel = FD::model('photos');
             $photosModel->pushPhotosOrdering($album->id, $photo->id);
             // If album doesn't have a cover, set the current photo as the cover.
             if (!$album->hasCover()) {
                 $album->cover_id = $photo->id;
                 // Store the album
                 $album->store();
             }
             // Get the photos library
             $photoLib = FD::get('Photos', $image);
             $storage = $photoLib->getStoragePath($album->id, $photo->id);
             $paths = $photoLib->create($storage);
             // Create metadata about the photos
             foreach ($paths as $type => $fileName) {
                 $meta = FD::table('PhotoMeta');
                 $meta->photo_id = $photo->id;
                 $meta->group = SOCIAL_PHOTOS_META_PATH;
                 $meta->property = $type;
                 $meta->value = $storage . '/' . $fileName;
                 $meta->store();
             }
             // Synchronize Indexer
             $indexer = FD::get('Indexer');
             $template = $indexer->getTemplate();
             $template->setContent($photo->title, $photo->caption);
             //$url 	= FRoute::photos(array('layout' => 'item', 'id' => $photo->getAlias()));
             $url = $photo->getPermalink();
             $url = '/' . ltrim($url, '/');
             $url = str_replace('/administrator/', '/', $url);
             $template->setSource($photo->id, SOCIAL_INDEXER_TYPE_PHOTOS, $photo->uid, $url);
             $template->setThumbnail($photo->getSource('thumbnail'));
             $indexer->index($template);
             // Crop the image to follow the avatar format. Get the dimensions from the request.
             if (!empty($value->data) && is_object($value->data)) {
                 $width = $value->data->width;
                 $height = $value->data->height;
                 $top = $value->data->top;
                 $left = $value->data->left;
                 $avatar->crop($top, $left, $width, $height);
             }
             $options = array();
             // Create the avatars now
             if (!$createStream) {
                 $options = array('addstream' => false);
             }
             $options['deleteimage'] = false;
             $avatar->store($photo, $options);
         }
         return true;
     }
 }