/** * Set's the template as the default template * * @since 1.0 * @access public * @param string * @return */ public function makeDefault() { // Check for request forgeries FD::checkToken(); $element = JRequest::getVar('cid'); $element = $element[0]; $element = strtolower($element); // Get the current view $view = $this->getCurrentView(); // Get the configuration object $configTable = FD::table('Config'); $config = FD::registry(); if ($configTable->load('site')) { $config->load($configTable->value); } // Convert the config object to a json string. $config->set('theme.site', $element); // Convert the configuration to string $jsonString = $config->toString(); // Store the setting $configTable->value = $jsonString; if (!$configTable->store()) { $view->setMessage($configTable->getError(), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } return $view->call(__FUNCTION__); }
public function createStream($verb) { // Create a new stream item for this discussion $stream = FD::stream(); // Get the stream template $tpl = $stream->getTemplate(); // Someone just joined the event $tpl->setActor($this->created_by, SOCIAL_TYPE_USER); // Set the params to cache the event data $registry = FD::registry(); $registry->set('news', $this); // Set the context $tpl->setContext($this->id, 'news'); $event = FD::event($this->cluster_id); // Set the cluster $tpl->setCluster($this->cluster_id, SOCIAL_TYPE_EVENT, $event->type); // Set the verb $tpl->setVerb($verb); // Set the params $tpl->setParams($registry); if ($this->_stream_date) { $tpl->setDate($this->_stream_date); } $tpl->setAccess('core.view'); // Add the stream $stream->add($tpl); }
/** * Displays the registration request * * @since 1.3 * @access public * @param string * @return */ public function request() { $id = $this->input->getInt('id'); $table = JTable::getInstance('Module'); $table->load($id); FD::language()->load('mod_easysocial_registration_requester', JPATH_SITE); $params = FD::registry($table->params); $profileId = $params->get('profile_id'); // If there's no profile id, then we automatically assign the default profile id if (empty($profileId)) { $profileModel = FD::model('profiles'); $defaultProfile = $profileModel->getDefaultProfile(); $profileId = $defaultProfile->id; } $fieldsModel = FD::model('fields'); $options = array('visible' => SOCIAL_PROFILES_VIEW_MINI_REGISTRATION, 'profile_id' => $profileId); $fields = $fieldsModel->getCustomFields($options); if (!empty($fields)) { FD::language()->loadAdmin(); $fieldsLib = FD::fields(); $session = JFactory::getSession(); $registration = FD::table('Registration'); $registration->load($session->getId()); $data = $registration->getValues(); $args = array(&$data, &$registration); $fieldsLib->trigger('onRegisterMini', SOCIAL_FIELDS_GROUP_USER, $fields, $args); } $theme = FD::themes(); $theme->set('params', $params); $theme->set('config', FD::config()); $theme->set('fields', $fields); $output = $theme->output('site/registration/dialog.request'); return $this->ajax->resolve($output); }
public function onPrepareStream(SocialStreamItem &$stream, $includePrivacy = true) { if ($stream->context != 'relationship') { return; } $params = $this->getParams(); if (!$params->get('stream_approve', true)) { return; } // Get the actor $actor = $stream->actor; // check if the actor is ESAD profile or not, if yes, we skip the rendering. if (!$actor->hasCommunityAccess()) { $stream->title = ''; return; } $my = FD::user(); $privacy = FD::privacy($my->id); if ($includePrivacy && !$privacy->validate('core.view', $stream->contextId, 'relationship', $stream->actor->id)) { return; } $stream->color = '#DC554F'; $stream->fonticon = 'ies-heart'; $stream->label = FD::_('APP_USER_RELATIONSHIP_STREAM_TOOLTIP', true); $stream->display = SOCIAL_STREAM_DISPLAY_FULL; $registry = FD::registry($stream->params); $this->set('type', $registry->get('type')); $this->set('actor', $stream->actor); $this->set('target', $stream->targets[0]); $stream->title = parent::display('streams/' . $stream->verb . '.title'); if ($includePrivacy) { $stream->privacy = $privacy->form($stream->contextId, 'relationship', $stream->actor->id, 'core.view', false, $stream->uid); } return true; }
/** * Construct and initialise this event class per single event class. * * @author Jason Rey <*****@*****.**> * @since 1.3 * @access public * @param array $params The parameters to init. */ public function __construct($params = array()) { // Create the user parameters object $this->_params = FD::registry(); // Initialize user's property locally. $this->initParams($params); $this->table = FD::table('Event'); $this->table->bind($this); $this->meta = FD::Table('EventMeta'); $this->meta->load(array('cluster_id' => $this->id)); }
/** * Bind the params * * @since 1.0 * @access public * @param string * @return */ public function bind($params = null) { if (is_object($params)) { $this->params = $params; return; } if (is_file($params)) { $params = JFile::read($params); } $this->params = FD::registry($params); }
/** * Displays the field for creation. * * @author Jason Rey <*****@*****.**> * @since 1.3 * @access public * @param array $post The posted data. * @param SocialTableStepSession $session The session table. * @return string The html codes for this field. */ public function onRegister(&$post, &$session) { // Support for group event // If this is a group event, we do not allow user to change the type as the type follows the group $reg = FD::registry(); $reg->load($session->values); if ($reg->exists('group_id')) { return; } $value = isset($post['event_type']) ? $post['event_type'] : $this->params->get('default'); $this->set('value', $value); return $this->display(); }
public function onRegister(&$post, &$session) { $reg = FD::registry(); $reg->load($session->values); $groupId = $reg->get('group_id'); if (empty($groupId)) { return; } $value = isset($post['member_transfer']) ? $post['member_transfer'] : $this->params->get('default', 'invite'); $this->set('value', $value); $allowed = $this->params->get('allowed', array()); $this->set('allowed', $allowed); return $this->display(); }
private function getImage(SocialTableNotification &$item) { // Get the links that are posted for this stream $model = FD::model('Stream'); $links = $model->getAssets($item->uid, SOCIAL_TYPE_LINKS); if (!isset($links[0])) { return; } // Initialize default values $link = $links[0]; $actor = FD::user($item->actor_id); $meta = FD::registry($link->data); $item->content = $meta->get('link'); // If there's an image, use it if ($meta->get('image')) { return $meta->get('image'); } return false; }
/** * Processes a saved story. * * @since 1.0 * @access public * @param string * @return */ public function onAfterStorySave(&$stream, &$streamItem, &$template) { // Get the link information from the request $link = JRequest::getVar('links_url', ''); $title = JRequest::getVar('links_title', ''); $content = JRequest::getVar('links_description', ''); $image = JRequest::getVar('links_image', ''); $video = JRequest::getVar('links_video', ''); // If there's no data, we don't need to store in the assets table. if (empty($title) && empty($content) && empty($image)) { return; } $registry = FD::registry(); $registry->set('title', $title); $registry->set('content', $content); $registry->set('image', $image); $registry->set('link', $link); return true; }
/** * Triggered to validate the stream item whether should put the item as valid count or not. * * @since 1.2 * @access public * @param jos_social_stream, boolean * @return 0 or 1 */ public function onStreamCountValidation(&$item, $includePrivacy = true) { // If this is not it's context, we don't want to do anything here. if ($item->context_type != 'story') { return false; } // if this is a cluster stream, let check if user can view this stream or not. $params = FD::registry($item->params); $group = FD::group($params->get('group')); if (!$group) { return; } $item->cnt = 1; if ($group->type != SOCIAL_GROUPS_PUBLIC_TYPE) { if (!$group->isMember(FD::user()->id)) { $item->cnt = 0; } } return true; }
public function setValue($key, $value) { $reg = FD::registry(); if (!empty($this->values)) { $reg->load($this->values); } $reg->set($key, $value); $this->values = $reg->toString(); }
private function prepareCreateStream(SocialStreamItem &$item, SocialGroup $group) { if (!$group->canViewItem()) { return; } $params = FD::registry($item->params); $data = $params->get('news'); // Load the group $group = FD::group($data->cluster_id); $news = FD::table('GroupNews'); $news->load($data->id); // Get the permalink $permalink = FRoute::apps(array('layout' => 'canvas', 'customView' => 'item', 'uid' => $group->getAlias(), 'type' => SOCIAL_TYPE_GROUP, 'id' => $this->getApp()->getAlias(), 'newsId' => $news->id), false); // Get the app params $appParams = $this->getApp()->getParams(); // Format the content $this->format($news, $appParams->get('stream_length')); // Attach actions to the stream $this->attachActions($item, $news, $permalink, $appParams); $this->set('group', $group); $this->set('appParams', $appParams); $this->set('permalink', $permalink); $this->set('news', $news); $this->set('actor', $item->actor); // Load up the contents now. $item->title = parent::display('streams/create.title'); $item->content = parent::display('streams/create.content'); }
/** * Processes the saving of the settings. * * @since 1.0 * @access public * @param null * @author Mark Lee <*****@*****.**> */ public function save() { // Check for request forgeries. FD::checkToken(); // Since there are more than 1 tasks are linked here, get the appropriate task here. $task = $this->getTask(); $method = $task; $page = JRequest::getVar('page', ''); $view = FD::view('Settings'); // Get the posted data. $post = JRequest::get('POST'); // Only load the config that is already stored. // We don't want to store everything as we want to have hidden settings. $configTable = FD::table('Config'); $config = FD::registry(); if ($configTable->load('site')) { $config->load($configTable->value); } $token = FD::token(); if (!$post) { $view->setMessage(JText::_('COM_EASYSOCIAL_INVALID_POST_DATA'), SOCIAL_MSG_ERROR); return $view->call($method, $page); } // Some post vars are unwanted / unecessary because of the hidden inputs. $ignored = array('task', 'option', 'controller', 'view', $token, 'page'); $updatedUserIndexing = false; foreach ($post as $key => $value) { if (!in_array($key, $ignored)) { // Replace all _ with . $key = str_ireplace('_', '.', $key); // If the value is an array, and there's only 1 index, // the input might need to be checked if it needs to be in an array form. // E.g: some,values,here,should,be,an,array if (is_array($value) && count($value) == 1) { $value = FD::makeArray($value[0], ','); } if ($key == 'users.indexer.name' || $key == 'users.indexer.email') { $previousVal = $config->get($key); if ($previousVal != $value) { $updatedUserIndexing = true; } } $config->set($key, $value); } } // Convert the config object to a json string. $jsonString = $config->toString(); $configTable = FD::table('Config'); if (!$configTable->load('site')) { $configTable->type = 'site'; } $configTable->set('value', $jsonString); // Try to store the configuration. if (!$configTable->store()) { $view->setMessage($configTable->getError(), SOCIAL_MSG_ERROR); return $view->call($method, $page); } // Check if any of the configurations are stored as non local if (($config->get('storage.photos') == 'amazon' || $config->get('storage.conversations') == 'amazon') && $config->get('storage.amazon.bucket') == '') { // Initialize the storage $bucket = FD::storage('Amazon')->init(); $config->set('storage.amazon.bucket', $bucket); $configTable->set('value', $config->toString()); $configTable->store(); } $message = $updatedUserIndexing ? JText::_('COM_EASYSOCIAL_SETTINGS_SAVED_SUCCESSFULLY_WITH_USER_INDEXING_UPDATED') : JText::_('COM_EASYSOCIAL_SETTINGS_SAVED_SUCCESSFULLY'); $view->setMessage($message, SOCIAL_MSG_SUCCESS); return $view->call($method, $page); }
/** * Creates a new discussion * * @since 1.2 * @access public * @param string * @return */ public function save() { // Check for request forgeriess FD::checkToken(); // Ensure that the user is logged in. FD::requireLogin(); // Load up ajax lib $ajax = FD::ajax(); // Load the discussion $id = JRequest::getInt('id'); $discussion = FD::table('Discussion'); $discussion->load($id); // Get the current logged in user. $my = FD::user(); // Get the group $groupId = JRequest::getInt('cluster_id', 0); $group = FD::group($groupId); // Only allow owner and admin to modify the if ($discussion->id) { if ($discussion->created_by != $my->id && !$group->isAdmin() && !$my->isSiteAdmin()) { return $this->redirect($group->getPermalink(false)); } } // Check if the user is allowed to create a discussion if (!$group->isMember()) { FD::info()->set(JText::_('APP_GROUP_DISCUSSIONS_NOT_ALLOWED_CREATE'), SOCIAL_MSG_ERROR); // Perform a redirection return JFactory::getApplication()->redirect(FRoute::dashboard()); } // Assign discussion properties $discussion->uid = $group->id; $discussion->type = SOCIAL_TYPE_GROUP; $discussion->title = JRequest::getVar('title', ''); $discussion->content = JRequest::getVar('content', '', 'POST', 'none', JREQUEST_ALLOWRAW); // If discussion is edited, we don't want to modify the following items if (!$discussion->id) { $discussion->created_by = $my->id; $discussion->parent_id = 0; $discussion->hits = 0; $discussion->state = SOCIAL_STATE_PUBLISHED; $discussion->votes = 0; $discussion->lock = false; } $app = $this->getApp(); // Ensure that the title is valid if (!$discussion->title) { Foundry::info()->set(JText::_('APP_GROUP_DISCUSSIONS_INVALID_TITLE'), SOCIAL_MSG_ERROR); // Get the redirection url $url = FRoute::apps(array('layout' => 'canvas', 'customView' => 'create', 'uid' => $group->getAlias(), 'type' => SOCIAL_TYPE_GROUP, 'id' => $app->getAlias()), false); return $this->redirect($url); } // Lock the discussion $state = $discussion->store(); if (!$state) { FD::info()->set(JText::_('APP_GROUP_DISCUSSIONS_DISCUSSION_CREATED_FAILED')); // Get the redirection url $url = FRoute::apps(array('layout' => 'canvas', 'customView' => 'form', 'uid' => $group->getAlias(), 'type' => SOCIAL_TYPE_GROUP, 'id' => $app->getAlias()), false); return $this->redirect($url); } // Process any files that needs to be created. $discussion->mapFiles(); // Get the app $app = $this->getApp(); // If it is a new discussion, we want to run some other stuffs here. if (!$id) { // @points: groups.discussion.create // Add points to the user that updated the group $points = FD::points(); $points->assign('groups.discussion.create', 'com_easysocial', $my->id); // Create a new stream item for this discussion $stream = FD::stream(); // Get the stream template $tpl = $stream->getTemplate(); // Someone just joined the group $tpl->setActor($my->id, SOCIAL_TYPE_USER); // Set the context $tpl->setContext($discussion->id, 'discussions'); // Set the cluster $tpl->setCluster($group->id, SOCIAL_TYPE_GROUP, $group->type); // Set the verb $tpl->setVerb('create'); // Set the params to cache the group data $registry = FD::registry(); $registry->set('group', $group); $registry->set('discussion', $discussion); $tpl->setParams($registry); $tpl->setAccess('core.view'); // Add the stream $stream->add($tpl); // Set info message FD::info()->set(false, JText::_('APP_GROUP_DISCUSSIONS_DISCUSSION_CREATED_SUCCESS'), SOCIAL_MSG_SUCCESS); // Send notification to group members only if it is new discussion $options = array(); $options['permalink'] = FRoute::apps(array('layout' => 'canvas', 'customView' => 'item', 'uid' => $group->getAlias(), 'type' => SOCIAL_TYPE_GROUP, 'id' => $app->getAlias(), 'discussionId' => $discussion->id, 'external' => true), false); $options['discussionId'] = $discussion->id; $options['discussionTitle'] = $discussion->title; $options['discussionContent'] = $discussion->getContent(); $options['userId'] = $discussion->created_by; $group->notifyMembers('discussion.create', $options); } // Get the redirection url $url = FRoute::apps(array('layout' => 'canvas', 'customView' => 'item', 'uid' => $group->getAlias(), 'type' => SOCIAL_TYPE_GROUP, 'id' => $app->getAlias(), 'discussionId' => $discussion->id), false); // Perform a redirection $this->redirect($url); }
private function processGroups() { $config = FD::config(); $db = FD::db(); $sql = $db->sql(); $query = 'select a.*, c.uid as `escatid`'; $query .= ' from `#__community_groups` as a'; $query .= ' inner join `#__social_migrators` as c on a.`categoryid` = c.`oid` and c.`element` = ' . $db->Quote('groupcategory') . ' and c.`component` = ' . $db->Quote('com_community'); $query .= ' where not exists ( '; $query .= ' select b.`id` from `#__social_migrators` as b'; $query .= ' where a.`id` = b.`oid` and b.`element` = ' . $db->Quote('groups') . ' and b.`component` = ' . $db->Quote($this->name); $query .= ' )'; $query .= ' ORDER BY a.`id` ASC'; $query .= ' LIMIT ' . $this->limit; $sql->raw($query); $db->setQuery($sql); $jsGroups = $db->loadObjectList(); if (count($jsGroups) <= 0) { return null; } foreach ($jsGroups as $jsGroup) { $esGroup = FD::table('Cluster'); $esGroup->category_id = $jsGroup->escatid; $esGroup->cluster_type = SOCIAL_TYPE_GROUP; $esGroup->creator_type = SOCIAL_TYPE_USER; $esGroup->creator_uid = $jsGroup->ownerid; $esGroup->title = $jsGroup->name; $esGroup->description = $jsGroup->description; $esGroup->alias = JFilterOutput::stringURLSafe($jsGroup->name); $esGroup->state = $jsGroup->published; $esGroup->created = $jsGroup->created; $esGroup->params = null; // TODO: check what params we need to store. $esGroup->hits = 0; $esGroup->type = $jsGroup->approvals == 1 ? SOCIAL_GROUPS_PRIVATE_TYPE : SOCIAL_GROUPS_PUBLIC_TYPE; $esGroup->key = ''; // TODO: check what is this key for $state = $esGroup->store(); if ($state) { // Add group creation stream. if ($config->get('groups.stream.create')) { $stream = FD::stream(); $streamTemplate = $stream->getTemplate(); // Set the actor $streamTemplate->setActor($jsGroup->ownerid, SOCIAL_TYPE_USER); // Set the context $streamTemplate->setContext($esGroup->id, SOCIAL_TYPE_GROUPS); $streamTemplate->setVerb('create'); $streamTemplate->setSiteWide(); // $streamTemplate->setPublicStream( 'core.view' ); // Set the params to cache the group data $registry = FD::registry(); $registry->set('group', $esGroup); // Set the params to cache the group data $streamTemplate->setParams($registry); $streamTemplate->setDate($jsGroup->created); $streamTemplate->setAccess('core.view'); // Add stream template. $stream->add($streamTemplate); } //end add stream $this->log('groups', $jsGroup->id, $esGroup->id); $this->info->setInfo('Group \'' . $jsGroup->name . '\' has migrated succefully into EasySocial.'); } } //end foreach return $this->info; }
public function prepareCreateMilestoneStream(SocialStreamItem $streamItem, $includePrivacy = true) { $params = FD::registry($streamItem->params); $milestone = FD::table('Milestone'); $milestone->bind($params->get('milestone')); // Get the group data FD::load('event'); $event = new SocialEvent(); $event->bind($params->get('event')); // Get the actor $actor = $streamItem->actor; $app = $this->getApp(); $permalink = FRoute::apps(array('layout' => 'canvas', 'customView' => 'item', 'uid' => $event->getAlias(), 'type' => SOCIAL_TYPE_EVENT, 'id' => $app->getAlias(), 'milestoneId' => $milestone->id)); $this->set('permalink', $permalink); $this->set('milestone', $milestone); $this->set('actor', $actor); $this->set('event', $event); $streamItem->title = parent::display('streams/create.milestone.title'); $streamItem->content = parent::display('streams/create.milestone.content'); $streamItem->opengraph->addDescription(JText::sprintf('APP_EVENT_TASKS_STREAM_OPENGRAPH_CREATE_MILESTONE', $streamItem->actor->getName(), $event->getName())); }
/** * Stores any link assets * * @since 1.0 * @access public * @param string * @return */ public function storeLinks($stream, $streamItem, $template) { // Get the link information from the request $link = $this->app->input->get('links_url', '', 'default'); $title = $this->app->input->get('links_title', '', 'default'); $content = $this->app->input->get('links_description', '', 'default'); $image = $this->app->input->get('links_image', '', 'default'); // If there's no data, we don't need to store in the assets table. if (empty($title) && empty($content) && empty($image)) { return false; } // Cache the image if necessary $links = FD::links(); $uri = $links->cache($image); $registry = FD::registry(); $registry->set('title', $title); $registry->set('content', $content); $registry->set('image', $image); $registry->set('link', $link); $registry->set('cached', false); // Image link should only be modified when the file exists if ($uri !== false) { $registry->set('cached', true); $registry->set('image', $uri); } // Store the link object into the assets table $assets = FD::table('StreamAsset'); $assets->stream_id = $streamItem->uid; $assets->type = 'links'; $assets->data = $registry->toString(); // Store the assets $state = $assets->store(); return $state; }
/** * Submits a reply * * @since 1.2 * @access public * @return */ public function submit() { // Check for request forgeriess FD::checkToken(); // Ensure that the user is logged in. FD::requireLogin(); // Load up ajax lib $ajax = FD::ajax(); // Get the group $groupId = JRequest::getInt('groupId'); $group = FD::group($groupId); // Get the discussion $id = JRequest::getInt('id'); $discussion = FD::table('Discussion'); $discussion->load($id); // Get the current user $my = FD::user(); // Check whether the viewer can really reply to the discussion if (!$group->isMember()) { return $this->reject(); } // Test for locked discussion. if ($discussion->lock && !$group->isAdmin()) { $obj = new stdClass(); $obj->message = JText::_('APP_GROUP_DISCUSSIONS_DISCUSSION_IS_LOCKED'); $obj->type = SOCIAL_MSG_ERROR; return $ajax->reject($obj); } // Get the content // $content = JRequest::getVar( 'content' , '' ); $content = JRequest::getVar('content', '', 'post', 'none', JREQUEST_ALLOWRAW); if (empty($content)) { $obj = new stdClass(); $obj->message = JText::_('APP_GROUP_DISCUSSIONS_EMPTY_REPLY_ERROR'); $obj->type = SOCIAL_MSG_ERROR; return $ajax->reject($obj); } $reply = FD::table('Discussion'); $reply->uid = $discussion->uid; $reply->type = $discussion->type; $reply->content = $content; $reply->created_by = $my->id; $reply->parent_id = $discussion->id; $reply->state = SOCIAL_STATE_PUBLISHED; // Save the reply. $reply->store(); if (!$id) { // @points: groups.discussion.reply // Earn points when posting a reply $points = FD::points(); $points->assign('groups.discussion.reply', 'com_easysocial', $reply->created_by); } // Create a new stream item for this discussion $stream = FD::stream(); // Get the stream template $tpl = $stream->getTemplate(); // Someone just joined the group $tpl->setActor($my->id, SOCIAL_TYPE_USER); // Set the context $tpl->setContext($discussion->id, 'discussions'); // Set the cluster $tpl->setCluster($group->id, SOCIAL_TYPE_GROUP, $group->type); // Set the verb $tpl->setVerb('reply'); // Set the params to cache the group data $registry = FD::registry(); $registry->set('group', $group); $registry->set('reply', $reply); $registry->set('discussion', $discussion); $tpl->setParams($registry); $tpl->setAccess('core.view'); // Add the stream $stream->add($tpl); // Update the parent's reply counter. $discussion->sync($reply); // Before we populate the output, we need to format it according to the theme's specs. $reply->author = $my; // Load the contents $theme = FD::themes(); // Since this reply is new, we don't have an answer for this item. $answer = false; $theme->set('question', $discussion); $theme->set('group', $group); $theme->set('answer', $answer); $theme->set('reply', $reply); $contents = $theme->output('apps/group/discussions/canvas/item.reply'); // Send notification to group members $options = array(); $options['permalink'] = FRoute::apps(array('layout' => 'canvas', 'customView' => 'item', 'uid' => $group->getAlias(), 'type' => SOCIAL_TYPE_GROUP, 'id' => $this->getApp()->getAlias(), 'discussionId' => $discussion->id, 'external' => true), false); $options['title'] = $discussion->title; $options['content'] = $reply->getContent(); $options['discussionId'] = $reply->id; $options['userId'] = $reply->created_by; $options['targets'] = $discussion->getParticipants(array($reply->created_by)); $group->notifyMembers('discussion.reply', $options); return $ajax->resolve($contents); }
/** * Retrieves a field configuration. * * @since 1.0 * @access public * @param int The key to #__social_apps * @param int Optional field id. If there's no field id, we assume that it's a new field being added to the form. * @return JRegistry Registry of the field configuration */ public function getFieldConfigValues($appId, $fieldId = 0) { $field = null; // If first parameter is object, we assume caller pass in field table if (is_object($appId)) { // Reassign appid accordingly $field = $appId; $appId = $field->app_id; } $defaults = $this->getFieldConfigParameters($appId); // If the first parameter is appId, then $field should be null by now, and if second parameter is valid, then we load the table if (empty($field) && !empty($fieldId)) { $field = FD::table('field'); $field->load($fieldId); } // Initialise a registry first $params = FD::registry(); // Initialise a string library $string = FD::string(); // If $field is still empty then we shouldn't get the field parameters if (!empty($field)) { // Get the params from the table $params = $field->getParams(); // Get the choices $choices = $field->getOptions(); // Manually merge in the choices into the parameter object foreach ($choices as $choice => $values) { foreach ($values as $id => &$value) { // $value->label = JText::_( $value->label ); // $value->title = JText::_( $value->title ); $value->label = $string->escape($value->label); } $params->set($choice, $values); } } // This is to get the default values of the params and // merge it in as the value if the value does not exist yet foreach ($defaults as $name => $obj) { // Check if this name exists in the params if (!$params->exists($name)) { $default = ''; if (is_bool($obj)) { $default = $obj; } if (isset($obj->default)) { $default = $obj->default; } $params->set($name, $default); } if (isset($obj->subfields)) { foreach ($obj->subfields as $subname => $subfield) { if (!$params->exists($name . '_' . $subname)) { $default = isset($subfield->default) ? $subfield->default : ''; $params->set($name . '_' . $subname, $default); } } } } return $params; }
private function prepareCreateStream(SocialStreamItem &$item) { $groupId = $item->contextId; $params = FD::registry($item->params); $obj = $params->get('group'); $group = new SocialGroup(); $group->bind($obj); if (!$group) { return; } // We don't want to display groups that are invitation only. if ($group->type == SOCIAL_GROUPS_INVITE_TYPE) { return; } $actor = $item->actor; $this->set('group', $group); $this->set('actor', $actor); $item->title = parent::display('streams/create.title'); $item->content = parent::display('streams/create.content'); $item->opengraph->addDescription(JText::sprintf('APP_GROUP_GROUPS_STREAM_CREATED_GROUP', $actor->getName(), $group->getName())); }
public function addTostream($my, $group, $registry) { $stream = FD::stream(); $streamTemplate = $stream->getTemplate(); // Set the actor $streamTemplate->setActor($my->id, SOCIAL_TYPE_USER); // Set the context $streamTemplate->setContext($group->id, SOCIAL_TYPE_GROUPS); $streamTemplate->setVerb('create'); $streamTemplate->setSiteWide(); $streamTemplate->setAccess('core.view'); $streamTemplate->setCluster($group->id, SOCIAL_TYPE_GROUP, $group->type); // Set the params to cache the group data $registry = FD::registry(); $registry->set('group', $group); // Set the params to cache the group data $streamTemplate->setParams($registry); // Add stream template. $stream->add($streamTemplate); return true; }
/** * Returns the content of the mail with the entire structure * * @since 1.0 * @access public * @param string * @return */ public function getEmailContents($mail) { // Process mail contents $contents = $this->getContents($mail); $theme = FD::get('Themes'); $theme->set('contents', $contents); $app = JFactory::getApplication(); $assets = FD::assets(); // Load up the mail params $params = FD::registry($mail->params); // Determines if we should display the manage alerts $manageAlerts = $params->get('manageAlerts', true); // Set the logo for the generic email template $override = JPATH_ROOT . '/templates/' . $assets->getJoomlaTemplate() . '/html/com_easysocial/emails/logo.png'; $logo = rtrim(JURI::root(), '/') . '/components/com_easysocial/themes/wireframe/images/emails/logo.png'; if (JFile::exists($override)) { $logo = rtrim(JURI::root(), '/') . '/templates/' . $assets->getJoomlaTemplate() . '/html/com_easysocial/emails/logo.png'; } // Set the logo uri $theme->set('logo', $logo); $theme->set('manageAlerts', $manageAlerts); $output = $theme->output('site/emails/html/template'); return $output; }
/** * Method to index an item. The item must be a FinderIndexerResult object. * * @param FinderIndexerResult $item The item to index as an FinderIndexerResult object. * @param string $format The item format * * @return void * * @since 2.5 * @throws Exception on database error. */ protected function index(FinderIndexerResult $item, $format = 'html') { // Check if the extension is enabled if (JComponentHelper::isEnabled($this->extension) == false) { return; } $access = 1; if (is_null($item->privacy)) { $privacy = FD::privacy($item->user_id); $privacyValue = $privacy->getValue('photos', 'view'); $item->privacy = $privacyValue; } if ($item->privacy == SOCIAL_PRIVACY_PUBLIC) { $access = 1; } else { if ($item->privacy == SOCIAL_PRIVACY_MEMBER) { $access = 2; } else { // this is not public / member items. do not index this item return; } } // $sql->select('a.id, a.title, a.alias, a.introtext AS summary, a.fulltext AS body'); // $sql->select('a.state, a.catid, a.created AS start_date, a.created_by'); // $sql->select('a.created_by_alias, a.modified, a.modified_by, a.attribs AS params'); // $sql->select('a.metakey, a.metadesc, a.metadata, a.language, a.access, a.version, a.ordering'); // $sql->select('a.publish_up AS publish_start_date, a.publish_down AS publish_end_date'); // $sql->select('c.title AS category, c.published AS cat_state, c.access AS cat_access'); // album onwer $user = FD::user($item->user_id); $userAlias = $user->getAlias(false); $photo = FD::table('Photo'); $photo->load($item->id); // Build the necessary route and path information. // index.php?option=com_easysocial&view=photos&layout=item&id=510:00000690&type=user&uid=84:jenny-siew $item->url = 'index.php?option=com_easysocial&view=photos&layout=item&id=' . $photo->getAlias() . '&type=' . $photo->type . '&uid=' . $userAlias; $item->route = $photo->getPermalink(); $item->route = $this->removeAdminSegment($item->route); $item->path = FinderIndexerHelper::getContentPath($item->route); $category = 'user photo'; if ($item->type == SOCIAL_TYPE_GROUP) { $category = 'group photo'; } $item->access = $access; $item->alias = $photo->getAlias(); $item->state = 1; $item->catid = $photo->type == SOCIAL_TYPE_GROUP ? 2 : 1; $item->start_date = $photo->created; $item->created_by = $photo->user_id; $item->created_by_alias = $userAlias; $item->modified = $photo->assigned_date == '0000-00-00 00:00:00' ? $photo->created : $photo->assigned_date; $item->modified_by = $photo->user_id; $item->params = ''; $item->metakey = $category . ' ' . $photo->title; $item->metadesc = $category . ' ' . $photo->title; $item->metadata = ''; $item->publish_start_date = $item->modified; $item->category = $category; $item->cat_state = 1; $item->cat_access = 0; $item->summary = $photo->title; $item->body = $photo->title; // Add the meta-author. $item->metaauthor = $userAlias; $item->author = $userAlias; // add image param $registry = FD::registry(); $registry->set('image', $photo->getSource()); $item->params = $registry; // Add the meta-data processing instructions. $item->addInstruction(FinderIndexer::META_CONTEXT, 'metakey'); $item->addInstruction(FinderIndexer::META_CONTEXT, 'metadesc'); $item->addInstruction(FinderIndexer::META_CONTEXT, 'metaauthor'); $item->addInstruction(FinderIndexer::META_CONTEXT, 'author'); // Add the type taxonomy data. $item->addTaxonomy('Type', 'EasySocial.Photos'); // Add the author taxonomy data. $item->addTaxonomy('Author', $userAlias); // Add the category taxonomy data. $item->addTaxonomy('Category', $item->category, $item->cat_state, $item->cat_access); // Add the language taxonomy data. $langParams = JComponentHelper::getParams('com_languages'); $item->language = $langParams->get('site', 'en-GB'); $item->addTaxonomy('Language', $item->language); // Get content extras. FinderIndexerHelper::getContentExtras($item); // Index the item. if (FD::isJoomla30()) { $this->indexer->index($item); } else { FinderIndexer::index($item); } }
/** * Binds the access for this group category * * @since 1.0 * @access public * @param string * @return */ public function bindAccess($post) { if (!is_array($post) || empty($post)) { return false; } // Load up the access table binding. $access = FD::table('Access'); // Try to load the access records. $access->load(array('uid' => $this->id, 'type' => SOCIAL_TYPE_CLUSTERS)); // Load the registry $registry = FD::registry($access->params); foreach ($post as $key => $value) { $key = str_ireplace('_', '.', $key); $registry->set($key, $value); } $access->uid = $this->id; $access->type = SOCIAL_TYPE_CLUSTERS; $access->params = $registry->toString(); // Try to store the access item if (!$access->store()) { $this->setError($access->getError()); return false; } return true; }
/** * Override parent's implementation as we need to generate the stream * * @since 1.2 * @access public * @param string * @return */ public function addFile($title = null) { // Run the parent's logics first $result = parent::addFile($title); if ($result instanceof SocialException) { return $result; } // Create a stream item for the groups now $stream = FD::stream(); $tpl = $stream->getTemplate(); $actor = FD::user(); // this is a cluster stream and it should be viewable in both cluster and user page. $tpl->setCluster($this->group->id, SOCIAL_TYPE_GROUP, $this->group->type); // Set the actor $tpl->setActor($actor->id, SOCIAL_TYPE_USER); // Set the context $tpl->setContext($result->id, SOCIAL_TYPE_FILES); // Set the verb $tpl->setVerb('uploaded'); $file = FD::table('File'); $file->load($result->id); // Set the params to cache the group data $registry = FD::registry(); $registry->set('group', $this->group); $registry->set('file', $file); // Set the params to cache the group data $tpl->setParams($registry); // since this is a cluster and user stream, we need to call setPublicStream // so that this stream will display in unity page as well // This stream should be visible to the public $tpl->setAccess('core.view'); $streamItem = $stream->add($tpl); // Prepare the stream permalink $permalink = FRoute::stream(array('layout' => 'item', 'id' => $streamItem->uid)); // Notify group members when a new file is uploaded $this->group->notifyMembers('file.uploaded', array('fileId' => $file->id, 'fileName' => $file->name, 'fileSize' => $file->getSize(), 'permalink' => $permalink, 'userId' => $file->user_id)); return $result; }
/** * Prepares the stream item for new discussion creation * * @since 1.3 * @access public * @param SocialStreamItem $item The stream item. */ private function prepareLockedStream(&$item) { // Get the context params $params = FD::registry($item->params); $event = FD::event($params->get('event')->id); $discussion = FD::table('Discussion'); $discussion->bind($params->get('discussion')); $permalink = FRoute::apps(array('layout' => 'canvas', 'customView' => 'item', 'uid' => $event->getAlias(), 'type' => SOCIAL_TYPE_EVENT, 'id' => $this->getApp()->getAlias(), 'discussionId' => $discussion->id), false); $item->display = SOCIAL_STREAM_DISPLAY_MINI; $this->set('permalink', $permalink); $this->set('actor', $item->actor); $this->set('discussion', $discussion); // Load up the contents now. $item->title = parent::display('streams/locked.title'); }
/** * Processes mentions in a stream object * * @since 1.0 * @access public * @param string * @return */ public function formatMentions(SocialStreamItem &$stream) { // Get the current view $view = JRequest::getCmd('view', ''); // Get the stream's content $content = $stream->content; // Get tags for the stream $tags = isset($stream->tags) ? $stream->tags : array(); // If there is no tags, just skip this and escape the content if (!$tags) { return FD::string()->escape($content); } // We need to store the changes in an array and replace it accordingly based on the counter. $items = array(); // We need to merge the mentions and hashtags since we are based on the offset. $i = 0; foreach ($tags as $tag) { if ($tag->type == 'user') { $replace = '<a href="' . $tag->user->getPermalink() . '" data-popbox="module://easysocial/profile/popbox" data-popbox-position="top-left" data-user-id="' . $tag->user->id . '" class="mentions-user">' . $tag->user->getName() . '</a>'; } if ($tag->type == 'hashtag') { // $alias = JFilterOutput::stringURLSafe($tag->title); $alias = $tag->title; $url = ''; if ($view == 'groups') { $clusterReg = FD::registry($stream->params); $object = $clusterReg->get($stream->cluster_type); switch ($stream->cluster_type) { case SOCIAL_TYPE_GROUP: // for now we assume all is group type. $group = new SocialGroup(); $group->bind($object); $url = FRoute::groups(array('layout' => 'item', 'id' => $group->getAlias(), 'tag' => $alias)); break; case SOCIAL_TYPE_EVENT: $event = new SocialEvent(); $event->bind($object); $url = FRoute::events(array('layout' => 'item', 'id' => $event->getAlias(), 'tag' => $alias)); break; default: FRoute::dashboard(array('layout' => 'hashtag', 'tag' => $alias)); break; } } else { $url = FRoute::dashboard(array('layout' => 'hashtag', 'tag' => $alias)); } $replace = '<a href="' . $url . '" class="mentions-hashtag">#' . $tag->title . '</a>'; } $links[$i] = $replace; $replace = '[si:mentions]' . $i . '[/si:mentions]'; $content = JString::substr_replace($content, $replace, $tag->offset, $tag->length); $i++; } // Once we have the content, escape it $content = FD::string()->escape($content); if ($links) { for ($x = 0; $x < count($links); $x++) { $content = str_ireplace('[si:mentions]' . $x . '[/si:mentions]', $links[$x], $content); } } return $content; }
/** * Triggered to prepare the stream item * * @since 1.0 * @access public * @param string * @return */ public function onPrepareStream(SocialStreamItem &$stream, $includePrivacy = true) { // If this is not it's context, we don't want to do anything here. if ($stream->context != 'story') { return; } $uid = $stream->uid; $my = FD::user(); $privacy = FD::privacy($my->id); if ($stream->cluster_id) { // Group access checking $cluster = FD::cluster($stream->cluster_type, $stream->cluster_id); if (!$cluster) { return; } if (!$cluster->canViewItem()) { return; } // Allow editing of the stream item $stream->editable = $my->isSiteAdmin() || $cluster->isAdmin() || $stream->actor->id == $my->id; } else { // Allow editing of the stream item $stream->editable = $my->isSiteAdmin() || $stream->actor->id == $my->id; } // we stil need to check for the privacy because the context might come from the 'repost' if ($includePrivacy && !$privacy->validate('story.view', $uid, SOCIAL_TYPE_STORY, $stream->actor->id)) { return; } // Actor of this stream $actor = $stream->actor; $target = count($stream->targets) > 0 ? $stream->targets[0] : ''; $stream->display = SOCIAL_STREAM_DISPLAY_FULL; $stream->color = '#16a085'; $stream->fonticon = 'ies-pencil-2'; $stream->label = FD::_('APP_USER_STORY_UPDATES_STREAM_TOOLTIP', true); if ($stream->cluster_id) { if ($stream->cluster_type == SOCIAL_TYPE_GROUP) { $stream->color = '#303229'; $stream->fonticon = 'ies-users'; $stream->label = FD::_('APP_USER_STORY_GROUPS_STREAM_TOOLTIP', true); } if ($stream->cluster_type == SOCIAL_TYPE_EVENT) { $stream->color = '#f06050'; $stream->fonticon = 'ies-calendar'; $stream->label = FD::_('APP_USER_STORY_EVENTS_STREAM_TOOLTIP', true); } } $appGroup = SOCIAL_APPS_GROUP_USER; if ($stream->cluster_id) { if ($stream->cluster_type == SOCIAL_TYPE_EVENT) { $appGroup = SOCIAL_APPS_GROUP_EVENT; } else { $appGroup = SOCIAL_APPS_GROUP_GROUP; } } // Apply likes on the stream $likes = FD::likes(); $likes->get($stream->uid, $stream->context, $stream->verb, $appGroup, $stream->uid); $stream->likes = $likes; // Apply comments on the stream $comments = FD::comments($stream->uid, $stream->context, $stream->verb, $appGroup, array('url' => FRoute::stream(array('layout' => 'item', 'id' => $stream->uid))), $stream->uid); $stream->comments = $comments; // Apply repost on the stream $repost = FD::get('Repost', $stream->uid, SOCIAL_TYPE_STREAM, $appGroup); $stream->repost = $repost; // If this is a group type, and the viewer is not a member of the group, we need to hide these data if ($stream->cluster_id) { $cluster = FD::cluster($stream->cluster_type, $stream->cluster_id); if (!$cluster->isMember()) { $stream->commentLink = false; $stream->repost = false; $stream->commentForm = false; } // Sharing only show in public group if (!$cluster->isOpen()) { $stream->sharing = false; } } // Get application params $params = $this->getParams(); $this->set('params', $params); $this->set('actor', $actor); $this->set('target', $target); $this->set('stream', $stream); if ($stream->cluster_id) { $clusterReg = FD::registry($stream->params); $object = $clusterReg->get($stream->cluster_type); $cluster = FD::cluster($stream->cluster_type); if ($object) { // If have the object only bind $cluster->bind($object); } else { $cluster = $stream->getCluster(); } $this->set('cluster', $cluster); } $titleFileName = $stream->cluster_type ? $stream->cluster_type . '.' . $stream->verb : $stream->verb; $stream->title = parent::display('streams/title.' . $titleFileName); $stream->content = parent::display('streams/content.' . $stream->verb); $stream->opengraph->addDescription($stream->content); if ($includePrivacy) { $stream->privacy = $privacy->form($uid, SOCIAL_TYPE_STORY, $stream->actor->id, 'story.view', false, $stream->uid); } return true; }
/** * Save user's information. * * @since 1.0 * @access public */ public function save() { // Check for request forgeries. FD::checkToken(); // Ensure that the user is registered FD::requireLogin(); // Clear previous session $session = JFactory::getSession(); $session->clear('easysocial.profile.errors', SOCIAL_SESSION_NAMESPACE); // Get post data. $post = JRequest::get('POST'); // Get the current view. $view = $this->getCurrentView(); // Get all published fields apps that are available in the current form to perform validations $fieldsModel = FD::model('Fields'); // Get current user. $my = FD::user(); // Only fetch relevant fields for this user. $options = array('profile_id' => $my->getProfile()->id, 'data' => true, 'dataId' => $my->id, 'dataType' => SOCIAL_TYPE_USER, 'visible' => SOCIAL_PROFILES_VIEW_EDIT, 'group' => SOCIAL_FIELDS_GROUP_USER); $fields = $fieldsModel->getCustomFields($options); // Load json library. $json = FD::json(); // Initialize default registry $registry = FD::registry(); // Get disallowed keys so we wont get wrong values. $disallowed = array(FD::token(), 'option', 'task', 'controller'); // Process $_POST vars foreach ($post as $key => $value) { if (!in_array($key, $disallowed)) { if (is_array($value)) { $value = $json->encode($value); } $registry->set($key, $value); } } // Convert the values into an array. $data = $registry->toArray(); // Perform field validations here. Validation should only trigger apps that are loaded on the form // @trigger onRegisterValidate $fieldsLib = FD::fields(); // Get the general field trigger handler $handler = $fieldsLib->getHandler(); // Build arguments to be passed to the field apps. $args = array(&$data, &$my); // Ensure that there is no errors. // @trigger onEditValidate $errors = $fieldsLib->trigger('onEditValidate', SOCIAL_FIELDS_GROUP_USER, $fields, $args, array($handler, 'validate')); // If there are errors, we should be exiting here. if (is_array($errors) && count($errors) > 0) { $view->setMessage(JText::_('COM_EASYSOCIAL_PROFILE_SAVE_ERRORS'), SOCIAL_MSG_ERROR); // We need to set the proper vars here so that the es-wrapper contains appropriate class JRequest::setVar('view', 'profile', 'POST'); JRequest::setVar('layout', 'edit', 'POST'); // We need to set the data into the post again because onEditValidate might have changed the data structure JRequest::set($data, 'post'); return $view->call('edit', $errors, $data); } // @trigger onEditBeforeSave $errors = $fieldsLib->trigger('onEditBeforeSave', SOCIAL_FIELDS_GROUP_USER, $fields, $args, array($handler, 'beforeSave')); if (is_array($errors) && count($errors) > 0) { $view->setMessage(JText::_('COM_EASYSOCIAL_PROFILE_ERRORS_IN_FORM'), SOCIAL_MSG_ERROR); // We need to set the proper vars here so that the es-wrapper contains appropriate class JRequest::setVar('view', 'profile'); JRequest::setVar('layout', 'edit'); // We need to set the data into the post again because onEditValidate might have changed the data structure JRequest::set($data, 'post'); return $view->call('edit', $errors); } // Bind the my object with appropriate data. $my->bind($data); // Save the user object. $my->save(); // Reconstruct args $args = array(&$data, &$my); // @trigger onEditAfterSave $fieldsLib->trigger('onEditAfterSave', SOCIAL_FIELDS_GROUP_USER, $fields, $args); // Bind custom fields for the user. $my->bindCustomFields($data); // Reconstruct args $args = array(&$data, &$my); // @trigger onEditAfterSaveFields $fieldsLib->trigger('onEditAfterSaveFields', SOCIAL_FIELDS_GROUP_USER, $fields, $args); // Now we update the Facebook details if it is available $associatedFacebook = $this->input->get('associatedFacebook', 0, 'int'); if (!empty($associatedFacebook)) { $facebookPull = $this->input->get('oauth_facebook_pull', null, 'default'); $facebookPush = $this->input->get('oauth_facebook_push', null, 'default'); $my = FD::user(); $facebookTable = $my->getOAuth(SOCIAL_TYPE_FACEBOOK); if ($facebookTable) { $facebookTable->pull = $facebookPull; $facebookTable->push = $facebookPush; $facebookTable->store(); } } // Add stream item to notify the world that this user updated their profile. $my->addStream('updateProfile'); // Update indexer $my->syncIndex(); // @points: profile.update // Assign points to the user when their profile is updated $points = FD::points(); $points->assign('profile.update', 'com_easysocial', $my->id); // Prepare the dispatcher FD::apps()->load(SOCIAL_TYPE_USER); $dispatcher = FD::dispatcher(); $args = array(&$user, &$fields, &$data); // @trigger: onUserProfileUpdate $dispatcher->trigger(SOCIAL_TYPE_USER, 'onUserProfileUpdate', $args); // @trigger onProfileCompleteCheck // This should return an array of booleans to state which field is filled in. // We count the returned result since it will be an array of trues that marks the field that have data for profile completeness checking. // We do this after all the data has been saved, and we reget the fields from the model again. // We also need to reset the cached field data SocialTableField::$_fielddata = array(); $fields = $fieldsModel->getCustomFields(array('profile_id' => $my->getProfile()->id, 'data' => true, 'dataId' => $my->id, 'dataType' => SOCIAL_TYPE_USER, 'visible' => SOCIAL_PROFILES_VIEW_EDIT, 'group' => SOCIAL_FIELDS_GROUP_USER)); $args = array(&$my); $completedFields = $fieldsLib->trigger('onProfileCompleteCheck', SOCIAL_FIELDS_GROUP_USER, $fields, $args); $table = FD::table('Users'); $table->load(array('user_id' => $my->id)); $table->completed_fields = count($completedFields); $table->store(); $view->setMessage(JText::_('COM_EASYSOCIAL_PROFILE_ACCOUNT_UPDATED_SUCCESSFULLY'), SOCIAL_MSG_SUCCESS); return $view->call(__FUNCTION__, $my); }