/** * Does a remote call to the server to fetch contents of a given url. * * @since 1.0 * @access public */ public function fetch() { // Check for request forgeries! $urls = JRequest::getVar('urls'); // Ensure that the urls are in an array FD::makeArray($urls); // Get the current view. $view = $this->getCurrentView(); // Result placeholder $result = array(); if (!$urls || empty($urls)) { $view->setMessage(JText::_('COM_EASYSOCIAL_CRAWLER_INVALID_URL_PROVIDED'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } $crawler = FD::get('Crawler'); foreach ($urls as $url) { $hash = md5($url); $link = FD::table('Link'); $exists = $link->load(array('hash' => $hash)); // If it doesn't exist, store it. if (!$exists) { $crawler->crawl($url); $data = $crawler->getData(); $link->hash = $hash; $link->data = FD::json()->encode($data); // Store the new link $link->store(); } $result[$url] = FD::json()->decode($link->data); } return $view->call(__FUNCTION__, $result); }
/** * Renders the user group tree listing. * * @since 1.0 * @access public * @param object The object to check against. * @param string The controller to be called. * @param string The key for the object. * * @author Mark Lee <*****@*****.**> */ public static function groups($name = 'gid', $selected = '', $exclude = array(), $checkSuperAdmin = false) { static $count; $count++; // If selected value is a string, we assume that it's a json object. if (is_string($selected)) { $json = FD::json(); $selected = $json->decode($selected); } $version = FD::getInstance('Version')->getVersion(); if ($version >= '1.6') { $groups = self::getGroups(); $theme = FD::themes(); $selected = FD::makeArray($selected); $isSuperAdmin = JFactory::getUser()->authorise('core.admin'); $theme->set('name', $name); $theme->set('checkSuperAdmin', $checkSuperAdmin); $theme->set('isSuperAdmin', $isSuperAdmin); $theme->set('selected', $selected); $theme->set('count', $count); $theme->set('groups', $groups); return $theme->output('admin/html/tree.groups'); } return JHTML::_('select.genericlist', JFactory::getAcl()->get_group_children_tree(null, 'USERS', false), 'gid', 'size="10"', 'value', 'text', $selected); }
/** * Retrieves a list of participants from a discussion * * @since 1.2 * @access public * @param int The discussion id. * @return */ public function getParticipants($id, $options = array()) { $db = FD::db(); $sql = $db->sql(); $sql->column('DISTINCT( a.created_by )'); $sql->select('#__social_discussions', 'a'); if (FD::config()->get('users.blocking.enabled') && !JFactory::getUser()->guest) { $sql->leftjoin('#__social_block_users', 'bus'); $sql->on('a.created_by', 'bus.user_id'); $sql->on('bus.target_id', JFactory::getUser()->id); $sql->isnull('bus.id'); } $sql->where('('); $sql->where('a.parent_id', $id); $sql->where('a.id', $id, '=', 'OR'); $sql->where(')'); $sql->where('a.state', SOCIAL_STATE_PUBLISHED); $exclude = isset($options['exclude']) ? $options['exclude'] : ''; if ($exclude) { $exclude = FD::makeArray($exclude); $sql->where('a.created_by', $exclude, 'NOT IN'); } $db->setQuery($sql); $rows = $db->loadColumn(); if (!$rows) { return $rows; } $users = FD::user($rows); return $users; }
public function onBeforeSave(&$post, &$group) { $value = !empty($post['eventcreate']) ? $post['eventcreate'] : '[]'; $params = $group->getParams(); $params->set('eventcreate', FD::makeArray($value)); $group->params = $params->toString(); unset($post['eventcreate']); }
public function __construct($string = '', $args = array()) { if (!empty($string)) { $this->string = $string; } if (!empty($args)) { $this->arguments = FD::makeArray($args); } }
public function togglePublish() { FD::checkToken(); $action = $this->getTask(); $ids = JRequest::getVar('cid'); $ids = FD::makeArray($ids); $table = FD::table('Region'); $table->{$action}($ids); $message = JText::_($action === 'publish' ? 'COM_EASYSOCIAL_REGIONS_PUBLISHED_SUCCESS' : 'COM_EASYSOCIAL_REGIONS_UNPUBLISHED_SUCCESS'); $this->view->setMessage($message, SOCIAL_MSG_SUCCESS); return $this->view->call(__FUNCTION__); }
public function form() { // Check for request forgeries FD::checkToken(); $ids = JRequest::getVar('cid'); $ids = FD::makeArray($ids); if (empty($ids)) { $this->view->setMessage(JText::_('COM_EASYSOCIAL_MAINTENANCE_NO_SCRIPT_SELECTED')); return $this->view->call(__FUNCTION__); } return $this->view->call(__FUNCTION__, $ids); }
/** * Initializes files that are required by the module * * @since 1.0 * @access public * @param string * @return */ public function addDependency($dependencies = array()) { $dependencies = FD::makeArray($dependencies); if (!$dependencies) { return false; } // Determine what dependencies are required foreach ($dependencies as $dependency) { if (!method_exists($this, $dependency)) { continue; } $this->{$dependency}(); } }
/** * Determines if the username is allowed * * @since 1.0 * @access public * @param string The username to check against. * @param JRegistry The field's registry. * @return bool True if username is allowed, false otherwise. */ public static function allowed($username, &$params) { $disallowed = trim($params->get('disallowed', '')); // If nothing is defined as allowed if (empty($disallowed)) { return true; } $disallowed = FD::makeArray($disallowed, ','); if (empty($disallowed)) { return true; } if (!in_array($username, $disallowed)) { return true; } return false; }
public function publish() { FD::checkToken(); $ids = FD::makeArray(JRequest::getVar('cid')); $view = $this->getCurrentView(); $task = $this->getTask(); if (empty($ids)) { $view->setMessage(JText::_('COM_EASYSOCIAL_ACCESS_INVALID_ID_PROVIDED'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } foreach ($ids as $id) { $acc = FD::table('accessrules'); $acc->load($id); $acc->{$task}(); } $message = $task === 'publish' ? 'COM_EASYSOCIAL_ACCESS_PUBLISHED_SUCCESSFULLY' : 'COM_EASYSOCIAL_ACCESS_UNPUBLISHED_SUCCESSFULLY'; $view->setMessage(JText::_($message), SOCIAL_MSG_SUCCESS); return $view->call(__FUNCTION__); }
/** * Deletes a label * * @since 1.0 * @access public * @param string * @return */ public function delete() { // Check for request forgeries FD::checkToken(); $ids = JRequest::getVar('cid'); $ids = FD::makeArray($ids); $view = $this->getCurrentView(); if (empty($ids)) { $view->setMessage(JText::_('COM_EASYSOCIAL_LABELS_EMPTY_ID_PROVIDED'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } foreach ($ids as $id) { $label = FD::table('Label'); $label->load($id); $label->delete(); } $view->setMessage(JText::_('COM_EASYSOCIAL_LABELS_LABEL_DELETED_SUCCESSFULLY'), SOCIAL_MSG_SUCCESS); return $view->call(__FUNCTION__); }
/** * Determines if the username is allowed * * @since 1.0 * @access public * @param string The username to check against. * @param JRegistry The field's registry. * @return bool True if username is allowed, false otherwise. */ public static function allowed($username, &$params, $current = '') { // Exception for current if (!empty($current) && $username === $current) { return true; } $disallowed = trim($params->get('disallowed', '')); // If nothing is defined as allowed if (empty($disallowed)) { return true; } $disallowed = FD::makeArray($disallowed, ','); if (empty($disallowed)) { return true; } if (!in_array($username, $disallowed)) { return true; } return false; }
/** * Deletes an album from the site * * @since 1.0 * @access public */ public function remove() { // Check for request forgeries FD::checkToken(); // Get the current view $view = $this->getCurrentView(); // Get the list of ids $ids = JRequest::getVar('cid'); // Ensure that the id's are in an array $ids = FD::makeArray($ids); foreach ($ids as $id) { $album = FD::table('Album'); $album->load($id); $album->delete(); // @points: photos.albums.delete // Deduct points from creator when his album is deleted. $album->assignPoints('photos.albums.delete', $album->uid); } $view->setMessage(JText::_('COM_EASYSOCIAL_ALBUMS_ALBUM_DELETED_SUCCESSFULLY'), SOCIAL_MSG_SUCCESS); return $view->call(__FUNCTION__); }
/** * Retrieves the stream contents. * * @since 1.0 * @access public */ public function getStream($stream, $type = '', $hashtags = array()) { $ajax = FD::ajax(); if ($this->hasErrors()) { return $ajax->reject($this->getMessage()); } $streamCnt = $stream->getCount(); // Initialize the default ids $groupId = false; $eventId = false; // Retrieve the story lib $story = FD::get('Story', SOCIAL_TYPE_USER); // Get the tags if ($hashtags) { $hashtags = FD::makeArray($hashtags); $story->setHashtags($hashtags); } if ($type == SOCIAL_TYPE_GROUP) { $story = FD::get('Story', $type); $groupId = $this->input->getInt('id', 0); $story->setCluster($groupId, $type); $story->showPrivacy(false); } if ($type == SOCIAL_TYPE_EVENT) { $story = FD::get('Story', $type); $eventId = $this->input->getInt('id', 0); $story->setCluster($eventId, $type); $story->showPrivacy(false); } $stream->story = $story; $theme = FD::themes(); $theme->set('eventId', $eventId); $theme->set('groupId', $groupId); $theme->set('hashtag', false); $theme->set('stream', $stream); $theme->set('story', $story); $theme->set('streamcount', $streamCnt); $contents = $theme->output('site/dashboard/feeds'); return $ajax->resolve($contents, $streamCnt); }
/** * Removes a file from a group. * * @since 1.2 * @access public * @return mixed True if success, exception if false. */ public function removeFile() { // Check if the user has access to delete files from this group if (!$this->group->isMember()) { return FD::exception(JText::_('COM_EASYSOCIAL_EXPLORER_NO_ACCESS_TO_DELETE')); } // Get the file id $ids = JRequest::getInt('id'); $ids = FD::makeArray($ids); foreach ($ids as $id) { $file = FD::table('File'); $file->load($id); if (!$id || !$file->id) { return FD::exception(JText::_('COM_EASYSOCIAL_EXPLORER_INVALID_FILE_ID_PROVIDED')); } $state = $file->delete(); if (!$state) { return FD::exception(JText::_($file->getError())); } } return true; }
/** * Publishes a point * * @since 1.0 * @access public */ public function publish() { // Check for request forgeries. FD::checkToken(); $id = JRequest::getVar('cid'); // Get current view $view = $this->getCurrentView(); // Get current task $task = $this->getTask(); // Ensure that it's an array. $ids = FD::makeArray($id); if (empty($id)) { $view->setMessage(JText::_('COM_EASYSOCIAL_POINTS_INVALID_ID_PROVIDED'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } foreach ($ids as $id) { $point = FD::table('Points'); $point->load($id); $point->{$task}(); } $message = $task == 'publish' ? 'COM_EASYSOCIAL_POINTS_PUBLISHED_SUCCESSFULLY' : 'COM_EASYSOCIAL_POINTS_UNPUBLISHED_SUCCESSFULLY'; $view->setMessage(JText::_($message), SOCIAL_MSG_SUCCESS); return $view->call(__FUNCTION__); }
/** * Creates a new stream item * * @since 1.0 * @access public * @param string * @return */ public function create($args = array()) { // The content of the story $content = isset($args['content']) ? $args['content'] : ''; // Context ids, and type that are related to the story $contextIds = isset($args['contextIds']) ? $args['contextIds'] : ''; $contextType = isset($args['contextType']) ? $args['contextType'] : ''; // The person that created this new story $actorId = isset($args['actorId']) ? $args['actorId'] : ''; // If the object is posting on another object, the target object id should be passed in here. $targetId = isset($args['targetId']) ? $args['targetId'] : null; // If the story is associated with a location, it should be processed. $location = isset($args['location']) ? $args['location'] : null; // If the story is being tagged with other users. $with = isset($args['with']) ? $args['with'] : null; // If the content of the story contains mentions using @ and # tags. $mentions = isset($args['mentions']) ? $args['mentions'] : array(); // If the story belongs in a cluster $cluster = isset($args['cluster']) ? $args['cluster'] : ''; $clusterType = isset($args['clusterType']) ? $args['clusterType'] : SOCIAL_TYPE_GROUP; // If the story contains a mood $mood = isset($args['mood']) ? $args['mood'] : null; // Store this into the stream now. $stream = FD::stream(); // Ensure that context ids are always array $contextIds = FD::makeArray($contextIds); // Determines which trigger group to call $group = $cluster ? $clusterType : SOCIAL_TYPE_USER; // Load apps FD::apps()->load($group); // Load up the dispatcher so that we can trigger this. $dispatcher = FD::dispatcher(); // This is to satisfy the setContext method. $contextId = isset($contextIds[0]) ? $contextIds[0] : 0; // Get the stream template $template = $stream->getTemplate(); $template->setActor($actorId, $this->type); $template->setContext($contextId, $contextType); $template->setContent($content); $verb = $contextType == 'photos' ? 'share' : 'create'; $template->setVerb($verb); $privacyRule = isset($args['privacyRule']) ? $args['privacyRule'] : null; $privacyValue = isset($args['privacyValue']) ? $args['privacyValue'] : null; $privacyCustom = isset($args['privacyCustom']) ? $args['privacyCustom'] : null; if (!$privacyRule) { $privacyRule = $contextType == 'photos' ? 'photos.view' : 'story.view'; } if ($privacyValue && is_string($privacyValue)) { $privacyValue = FD::privacy()->toValue($privacyValue); } if ($privacyCustom) { $privacyCustom = explode(',', $privacyCustom); } // Set this stream to be public $template->setAccess($privacyRule, $privacyValue, $privacyCustom); // Set mentions $template->setMentions($mentions); // Set the users tagged in the stream. $template->setWith($with); // Set the location of the stream $template->setLocation($location); // Set the mood if (!is_null($mood)) { $template->setMood($mood); } // If there's a target, we want it to appear on their stream too if ($targetId) { $template->setTarget($targetId); } if ($contextType == 'photos') { if (count($contextIds) > 0) { foreach ($contextIds as $photoId) { $template->setChild($photoId); } } } if ($cluster) { $clusterObj = FD::cluster($clusterType, $cluster); if ($clusterObj) { // Set the params to cache the group data $registry = FD::registry(); $registry->set($clusterType, $clusterObj); // Set the params to cache the group data $template->setParams($registry); $template->setCluster($cluster, $clusterType, $clusterObj->type); } else { $template->setCluster($cluster, $clusterType, 1); } } // Build the arguments for the trigger $args = array(&$template, &$stream, &$content); // @trigger onBeforeStorySave $dispatcher->trigger($group, 'onBeforeStorySave', $args); // Create the new stream item. $streamItem = $stream->add($template); // Store link items $this->storeLinks($stream, $streamItem, $template); // Set the notification type $notificationType = SOCIAL_TYPE_STORY; // Construct our new arguments $args = array(&$stream, &$streamItem, &$template); // @trigger onAfterStorySave $dispatcher->trigger($group, 'onAfterStorySave', $args); // Send a notification to the recipient if needed. if ($targetId && $actorId != $targetId) { $this->notify($targetId, $streamItem, $template->content, $contextIds, $contextType, $notificationType); } // Send a notification alert if there are mentions if ($mentions && !empty($mentions)) { $this->notifyMentions($streamItem, $mentions, $contextType, $contextIds, $template->content, $targetId); } return $streamItem; }
/** * Retrieves a list of stream item. * * @since 1.0 * @access public * @param string * @return */ public function get($options = array(), $displayOptions = array()) { $users = array(); // Lets process default values $actorId = isset($options['actorId']) ? $options['actorId'] : null; $userId = isset($options['userId']) ? $options['userId'] : null; $listId = isset($options['listId']) ? $options['listId'] : null; $profileId = isset($options['profileId']) ? $options['profileId'] : null; $context = isset($options['context']) ? $options['context'] : SOCIAL_STREAM_CONTEXT_TYPE_ALL; $type = isset($options['type']) ? $options['type'] : SOCIAL_TYPE_USER; $limitStart = isset($options['limitStart']) ? $options['limitStart'] : ''; $limitEnd = isset($options['limitEnd']) ? $options['limitEnd'] : ''; $direction = isset($options['direction']) ? $options['direction'] : 'older'; $viewerId = isset($options['viewerId']) ? $options['viewerId'] : null; $guest = isset($options['guest']) ? $options['guest'] : false; $tag = isset($options['tag']) ? $options['tag'] : false; $ignoreUser = isset($options['ignoreUser']) ? $options['ignoreUser'] : false; $onlyModerated = isset($options['onlyModerated']) ? $options['onlyModerated'] : false; $noSticky = isset($options['nosticky']) ? $options['nosticky'] : false; // Cluster stream items $clusterId = isset($options['clusterId']) ? $options['clusterId'] : null; $clusterType = isset($options['clusterType']) ? $options['clusterType'] : null; $clusterCategory = isset($options['clusterCategory']) ? $options['clusterCategory'] : null; // Pagination stuffs $limit = isset($options['limit']) ? $options['limit'] : FD::config()->get('stream.pagination.pagelimit', 10); $startlimit = isset($options['startlimit']) ? $options['startlimit'] : 0; if (!is_array($context) && strpos($context, '|') !== false) { $context = explode('|', $context); } // If viewer is null, we assume the caller wants to fetch from the current user's perspective. if (is_null($viewerId)) { $viewerId = FD::user()->id; } // Ensure that the user id's are in an array form. $user = FD::user(); $userId = empty($userId) ? $user->id : $userId; $userId = FD::makeArray($userId); if (empty($context)) { $context = SOCIAL_STREAM_CONTEXT_TYPE_ALL; } $isFollow = false; if ($type == 'follow') { $this->filter = 'follow'; // reset the type to user and update the isFollow flag. $type = SOCIAL_TYPE_USER; $isFollow = true; } $isBookmark = false; if ($type == 'bookmarks') { $this->filter = 'bookmarks'; $isBookmark = true; } $isSticky = false; $userStickyOnly = false; if ($type == 'sticky') { $this->filter = 'sticky'; // reset the type to user and update the isSticky flag. $type = SOCIAL_TYPE_USER; $isSticky = true; $userStickyOnly = true; } if ($listId) { $this->filter = 'list'; } if ($guest) { $this->filter = 'everyone'; } // Ensure that the tag is an array $tag = FD::makeArray($tag); if ($tag) { $this->filter = 'custom'; } // Get stream model to fetch those records. $model = FD::model('Stream'); $data = array(); //$this->data = $this->format( $result , $context, $viewerId ); $keepSearching = true; $tryLimit = 2; $options = array('actorid' => $actorId, 'userid' => $userId, 'list' => $listId, 'profileId' => $profileId, 'context' => $context, 'type' => $type, 'limitstart' => $limitStart, 'limitend' => $limitEnd, 'viewer' => $viewerId, 'isfollow' => $isFollow, 'isbookmark' => $isBookmark, 'issticky' => $isSticky, 'nosticky' => $noSticky, 'userstickyonly' => $userStickyOnly, 'direction' => $direction, 'guest' => $guest, 'tag' => $tag, 'ignoreUser' => $ignoreUser, 'clusterId' => $clusterId, 'clusterType' => $clusterType, 'clusterCategory' => $clusterCategory, 'startlimit' => $startlimit, 'limit' => $limit, 'onlyModerated' => $onlyModerated); //trigger onBeforeGetStream $this->triggerBeforeGetStream($options); // Bind the context to the object $tmpContext = $options['context']; if (is_array($options['context'])) { $tmpContext = count($options['context']) > 1 ? implode('|', $options['context']) : $options['context'][0]; } $this->currentContext = $tmpContext; // since we allow options override, we need to perform checking only after the triggering $isCluster = $options['clusterId'] || $options['clusterType'] || $options['clusterCategory'] ? true : false; $this->isCluster = $isCluster; $this->options = $options; $this->startlimit = $startlimit; $result = null; if ($isCluster) { $result = $model->getClusterStreamData($options); } else { $result = $model->getStreamData($options); } // If there's nothing, just return a boolean value. if (!$result) { $this->startlimit = ''; return $this; } // we need to get the pagination and total first before u can execute the format. // this is because during the format, the shares context type might overwrite the total due // to another call to stream lib the get function. $this->pagination = $model->getPagination(); //determine if loadmore show be displayed or not. $total = $model->getTotalCount(); // if ($total && ($total - ($startlimit + $limit)) >= 1) { if ($total && $total >= 1) { $this->startlimit = $startlimit + $limit; } else { $this->startlimit = ''; } if ($direction == 'later') { $this->nextdate = $model->getCurrentStartDate(); } $this->uids = $model->getUids(); // now we are safe to run the format function. $requireSearch = $this->format($result, $context, $viewerId, true, 'onPrepareStream', $displayOptions); $this->data = $requireSearch; // triggering onAfterGetStream $this->triggerAfterGetStream($this->data); return $this; }
/** * Toggle publish button * * @since 1.0 * @access public * @param null */ public function togglePublish() { JRequest::checkToken('get') or JRequest::checkToken() or die('Invalid token'); $task = $this->getTask(); $method = strtolower($task); $ids = JRequest::getVar('cid'); $ids = FD::makeArray($ids); // Get the view object. $view = FD::getInstance('View', 'Mailer'); // Test if there's any id's being passed in. if (empty($ids)) { $view->setError(JText::_('COM_EASYSOCIAL_ERRORS_MAILER_NO_ID')); return $view->call($task); } foreach ($ids as $id) { $mailer = FD::table('Mailer'); $mailer->load($id); // When there's an error, just break out of the loop. if (!$mailer->{$method}()) { $view->setError($mailer->getError()); return $view->call($task); } } $info = FD::getInstance('Info'); $message = $task == 'publish' ? JText::_('COM_EASYSOCIAL_MAILER_ITEMS_MARKED_AS_SENT') : JText::_('COM_EASYSOCIAL_MAILER_ITEMS_MARKED_AS_PENDING'); $info->set($message, SOCIAL_MSG_SUCCESS); return $view->call($method); }
/** * Processes email notifications * * @since 1.0 * @access public * @param string * @return */ public function notify() { // Set all properties from this table into the mail template $params = FD::makeArray($this); //remove this _tbl_keys unset($params['_tbl_keys']); // Additional parameters. $user = FD::user($this->created_by); $params['reporter'] = $user->getName(); $params['reporterLink'] = $user->getPermalink(true, true); $params['item'] = $this->title; // Get a list of super admins on the site. $usersModel = FD::model('Users'); // We need to merge admin and custom emails $admins = $usersModel->getSiteAdmins(); $config = FD::config(); $custom = $config->get('reports.notifications.emails', ''); $recipients = array(); foreach ($admins as $user) { $recipients[] = $user->email; } if (!empty($custom)) { foreach ($custom as $email) { $recipients[] = $email; } } // Ensure for uniqueness here. $recipients = array_unique($recipients); // Get mailer object $mailer = FD::mailer(); $templates = array(); foreach ($recipients as $recipient) { // Get boilerplate $template = $mailer->getTemplate(); // Set recipient $template->setRecipient('', $recipient); // Set title of email $template->setTitle('COM_EASYSOCIAL_EMAILS_NEW_REPORT_SUBJECT'); // Set template file. $template->setTemplate('site/reports/moderator', $params); $mailer->create($template); } }
/** * Displays the field input for user when they edit their profile. * * @since 1.0 * @access public * @param Array The post data * @param SocialUser The user object * @param Array The error data. * @return string The html output. * * @author Jason Rey <*****@*****.**> */ public function onEdit(&$post, &$user, $errors) { $postArray = array(); if (!empty($post[$this->inputName]) && FD::json()->isJsonString($post[$this->inputName])) { $postArray = FD::makeArray($post[$this->inputName]); } $value = !empty($postArray['date']) ? $postArray['date'] : isset($this->value['date']) ? $this->value['date'] : ''; $string = ''; $date = $this->getDatetimeValue($value); if ($date->isValid()) { $string = $date->toSql(); } $this->set('date', $string); $this->set('dateObject', $date); $error = $this->getError($errors); $this->set('error', $error); $this->set('yearPrivacy', $this->params->get('year_privacy')); $yearRange = $this->getYearRange(); $this->set('yearRange', $yearRange); if ($this->params->get('allow_timezone')) { $this->set('timezones', $this->getTimezones()); } $timezone = !empty($postArray['timezone']) ? $postArray['timezone'] : !empty($this->value['timezone']) ? $this->value['timezone'] : $this->getUserTimezone($user); $this->set('timezone', $timezone); $calendarDateFormat = $this->getCalendarDateFormat(); $this->set('calendarDateFormat', $calendarDateFormat); // Display the output. return $this->display(); }
/** * Determines if an email is forbidden * * @since 1.0 * @access public * @author Jason Rey <*****@*****.**> */ public static function isForbidden($email, &$params) { // Detect forbidden words. $forbidden = trim($params->get('forbidden', '')); if (empty($forbidden)) { return false; } // Ensure that the text is in an array. $forbidden = FD::makeArray($forbidden, ','); // Check for forbidden foreach ($forbidden as $word) { if (stristr($email, $word) !== false) { return true; } } return false; }
public function publish() { $ids = JRequest::getVar('cid'); $ids = FD::makeArray($ids); if (empty($ids)) { $view->setMessage(JText::_('COM_EASYSOCIAL_ALERTS_INVALID_ID_PROVIDED'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } $state = $this->getTask() === 'publish'; foreach ($ids as $id) { $table = FD::table('alert'); $table->load($id); $table->published = $state; $table->store(); } $message = $state ? 'COM_EASYSOCIAL_ALERTS_PUBLISHED_SUCCESS' : 'COM_EASYSOCIAL_ALERTS_UNPUBLISHED_SUCCESS'; $view = $this->getCurrentView(); $view->setMessage(JText::_($message), SOCIAL_MSG_SUCCESS); return $view->call(__FUNCTION__); }
/** * Retrieves a list of avatars on the site * * @since 1.0 * @access public * @param string * @return */ public function getAvatars($options = array()) { $db = FD::db(); $sql = $db->sql(); $sql->select('#__social_avatars'); $storage = isset($options['storage']) ? $options['storage'] : ''; if ($storage) { $sql->where('storage', $storage); } $uploaded = isset($options['uploaded']) ? $options['uploaded'] : ''; if ($uploaded) { $sql->where('avatar_id', 0); $sql->where('small', '', '!='); } $limit = isset($options['limit']) ? $options['limit'] : 10; $sql->limit($limit); // Determines if we should order by specific ordering $ordering = isset($options['ordering']) ? $options['ordering'] : ''; if ($ordering) { $sorting = isset($options['sort']) ? $options['sort'] : 'DESC'; if ($ordering == 'random') { $sql->order('', '', 'RAND'); } if ($ordering == 'id') { $sql->order('id', $sorting); } } // If there's an exclusion list, exclude it $exclusion = isset($options['exclusion']) ? $options['exclusion'] : ''; if (!empty($exclusion)) { // Ensure that it's an array $exclusion = FD::makeArray($exclusion); foreach ($exclusion as $id) { $sql->where('id', $id, '!=', 'AND'); } } $db->setQuery($sql); $rows = $db->loadObjectList(); if (!$rows) { return $rows; } $avatars = array(); foreach ($rows as $row) { $avatar = FD::table('Avatar'); $avatar->bind($row); $avatars[] = $avatar; } return $avatars; }
/** * 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); }
public function post() { $app = JFactory::getApplication(); //$share_for = $app->input->get('share_for','','CMD'); $type = $app->input->get('type', 'story', 'STRING'); $content = $app->input->get('content', '', 'RAW'); //$targetId = $app->input->get('target_user','All','raw'); $targetId = $app->input->get('target_user', 0, 'INT'); $cluster = $app->input->get('cluster_id', null, 'INT'); $clusterType = $app->input->get('cluster_type', null, 'STRING'); $friends_tags = $app->input->get('friends_tags', null, 'ARRAY'); $log_usr = intval($this->plugin->get('user')->id); //now take login user stream for target $targetId = $targetId != $log_usr ? $targetId : $log_usr; $valid = 1; $result = new stdClass(); $story = FD::story(SOCIAL_TYPE_USER); // Check whether the user can really post something on the target if ($targetId) { $tuser = FD::user($targetId); $allowed = $tuser->getPrivacy()->validate('profiles.post.status', $targetId, SOCIAL_TYPE_USER); if (!$allowed) { $result->id = 0; $result->status = 0; $result->message = 'User not allowed any post in share'; $valid = 0; } } if (empty($type)) { $result->id = 0; $result->status = 0; $result->message = 'Empty type not allowed'; $valid = 0; } else { if ($valid) { // Determines if the current posting is for a cluster $cluster = isset($cluster) ? $cluster : 0; //$clusterType = ($cluster) ? 'group' : null; $isCluster = $cluster ? true : false; if ($isCluster) { $group = FD::group($cluster); $permissions = $group->getParams()->get('stream_permissions', null); if ($permissions != null) { // If the user is not an admin, ensure that permissions has member if ($group->isMember() && !in_array('member', $permissions) && !$group->isOwner() && !$group->isAdmin()) { $result->message = 'This group memder do not have share data permission'; } // If the user is an admin, ensure that permissions has admin if ($group->isAdmin() && !in_array('admin', $permissions) && !$group->isOwner()) { $result->message = 'This group admin do not have share data permission'; } $result->id = 0; $result->status = 0; $this->plugin->setResponse($result); return; } } //validate friends $friends = array(); if (!empty($friends_tags)) { // Get the friends model $model = FD::model('Friends'); // Check if the user is really a friend of him / her. foreach ($friends_tags as $id) { if (!$model->isFriends($log_usr, $id)) { continue; } $friends[] = $id; } } else { $friends = null; } $privacyRule = $type == 'photos' ? 'photos.view' : 'story.view'; //for hashtag mentions $mentions = null; //if($type == 'hashtag' || !empty($content)) if (!empty($content)) { //$type = 'story'; $start = 0; $posn = array(); //code adjust for 0 position hashtag $content = 'a ' . $content; while ($pos = strpos($content, '#', $start)) { //echo 'Found # at position '.$pos."\n"; $posn[] = $pos - 2; $start = $pos + 1; } $content = substr($content, 2); // //$pos = strpos(($content),'#',$start); $cont_arr = explode(' ', $content); $indx = 0; foreach ($cont_arr as $val) { if (preg_match('/[\'^#,|=_+¬-]/', $val)) { //$vsl = substr_count($val,'#'); $val_arr = array_filter(explode('#', $val)); foreach ($val_arr as $subval) { $subval = '#' . $subval; $mention = new stdClass(); $mention->start = $posn[$indx++]; $mention->length = strlen($subval) - 0; $mention->value = str_replace('#', '', $subval); $mention->type = 'hashtag'; $mentions[] = $mention; } } } //print_r( $mentions );die("in share api"); } $contextIds = 0; if ($type == 'photos') { $photo_obj = $this->uploadPhoto($log_usr, 'user'); $photo_ids[] = $photo_obj->id; $contextIds = count($photo_ids) ? $photo_ids : null; } else { $type = 'story'; } // Process moods here $mood = FD::table('Mood'); // Options that should be sent to the stream lib $args = array('content' => $content, 'actorId' => $log_usr, 'targetId' => $targetId, 'location' => null, 'with' => $friends, 'mentions' => $mentions, 'cluster' => $cluster, 'clusterType' => $clusterType, 'mood' => null, 'privacyRule' => $privacyRule, 'privacyValue' => 'public', 'privacyCustom' => ''); $photo_ids = array(); $args['actorId'] = $log_usr; $args['contextIds'] = $contextIds; $args['contextType'] = $type; // Create the stream item $stream = $story->create($args); // Privacy is only applicable to normal postings if (!$isCluster) { $privacyLib = FD::privacy(); if ($type == 'photos') { $photoIds = FD::makeArray($contextIds); foreach ($photoIds as $photoId) { $privacyLib->add($privacyRule, $photoId, $type, 'public', null, ''); } } else { $privacyLib->add($privacyRule, $stream->uid, $type, 'public', null, ''); } } // Add badge for the author when a report is created. $badge = FD::badges(); $badge->log('com_easysocial', 'story.create', $log_usr, JText::_('Posted a new update')); // @points: story.create // Add points for the author when a report is created. $points = FD::points(); $points->assign('story.create', 'com_easysocial', $log_usr); if ($stream->id) { $result->id = $stream->id; $result->status = 1; $result->message = 'data share successfully'; } } } $this->plugin->setResponse($result); }
/** * Helper function to translate any config parameters text * * @author Jason Rey <*****@*****.**> * @since 1.1 * @access private * @param SocialTableField $field The field table item */ private function translateConfigParams(&$field) { // Only try to JText the label field if it exists. if (isset($field->label)) { $field->label = JText::_($field->label); } // Only try to JText the tooltip field if it exists. if (isset($field->tooltip)) { $field->tooltip = JText::_($field->tooltip); } // Do not translate the default value of the field because the default might be a language key // if( isset( $field->default ) && is_string( $field->default ) ) // { // $field->default = JText::_( $field->default ); // } // If there are options set, we need to jtext them as well. if (isset($field->option)) { $field->option = FD::makeArray($field->option); foreach ($field->option as &$option) { $option->label = JText::_($option->label); } } // Only try to JText the info value if it exist if (isset($field->info)) { $field->info = JText::_($field->info); } }
public function upload() { $ajax = FD::ajax(); $tmp = JRequest::getVar($this->inputName, '', 'FILES'); $key = JRequest::getInt('key', 0); // Reconstruct the file array $file = array(); foreach ($tmp as $k => $v) { $file[$k] = $v[$key]; } // Check for file validity if (empty($file['tmp_name'])) { $ajax->reject($this->getErrorHtml(JText::_('PLG_FIELDS_FILE_VALIDATION_INVALID_FILE'))); return false; } $maths = FD::math(); $limit = $this->params->get('size_limit', 2); $limit = $maths->convertUnits($limit, 'MB', 'B'); $size = filesize($file['tmp_name']); if ($size > $limit) { $ajax->reject($this->getErrorHtml(JText::_('PLG_FIELDS_FILE_VALIDATION_FILE_SIZE_EXCEEDED'))); return false; } $allowed = $this->params->get('allowed'); $allowed = FD::makeArray($allowed, ','); $info = pathinfo($file['name']); if (!isset($info['extension']) || !empty($allowed) && !in_array($info['extension'], $allowed)) { $ajax->reject($this->getErrorHtml(JText::_('PLG_FIELDS_FILE_VALIDATION_FILE_EXTENSION_NOT_ALLOWED'))); return false; } $base = SOCIAL_TMP; if (!JFolder::exists($base) && !JFolder::create($base)) { $ajax->reject($this->getErrorHtml(JText::_('PLG_FIELDS_FILE_ERROR_UNABLE_TO_CREATE_TEMPORARY_LOCATION'))); return false; } $session = JFactory::getSession()->getId(); $hash = md5($session . $this->inputName . $file['name']); // Import necessary library jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); $state = JFile::copy($file['tmp_name'], $base . '/' . $hash); if (!$state) { $ajax->reject($this->getErrorHtml(JText::_('PLG_FIELDS_FILE_ERROR_UNABLE_TO_MOVE_FILE'))); return false; } // Store this data into temporary table $tmp = FD::table('tmp'); $tmp->uid = $this->field->id; $tmp->type = SOCIAL_APPS_TYPE_FIELDS; $tmp->key = $this->inputName; $tmp->value = array('name' => $file['name'], 'mime' => $file['type'], 'size' => $file['size'], 'hash' => $hash, 'path' => $base); $state = $tmp->store(); if (!$state) { $ajax->reject($this->getErrorHtml(JText::_('PLG_FIELDS_FILE_ERROR_UNABLE_TO_STORE_FILE_DATA'))); return false; } $data = new stdClass(); $data->name = $file['name']; $data->id = $tmp->id; $theme = FD::themes(); $theme->set('file', $data); $theme->set('tmp', true); $theme->set('key', $key); $theme->set('inputName', $this->inputName); $theme->set('field', $this->field); $theme->set('params', $this->params); $html = $theme->output('fields/user/file/control'); $ajax->resolve($html); return true; }
/** * Retrieves a list of users who are participating in a conversation. * * @since 1.0 * @access public * @param int The conversation id. * @param Array An array of excluded users. * @return Array An array of @{Socialusers} */ public function getParticipants($conversationId, $excludeUsers = array(), $includeBlockedUser = false) { // Ensure excluded users is an array. $excludeUsers = FD::makeArray($excludeUsers); $db = FD::db(); $sql = $db->sql(); $sql->select('#__social_conversations_participants', 'a'); // $sql->column( 'DISTINCT( a.`user_id` )' ); $sql->column('a.user_id'); if (FD::config()->get('users.blocking.enabled') && !$includeBlockedUser && !JFactory::getUser()->guest) { $sql->leftjoin('#__social_block_users', 'bus'); $sql->on('a.user_id', 'bus.user_id'); $sql->on('bus.target_id', JFactory::getUser()->id); $sql->isnull('bus.id'); } $sql->where('a.conversation_id', $conversationId); $sql->where('a.state', SOCIAL_STATE_PUBLISHED); if (!empty($excludeUsers)) { foreach ($excludeUsers as $userId) { $sql->where('a.user_id', $userId, '!='); } } $db->setQuery($sql); // Load the data. $rows = $db->loadColumn(); if (!$rows) { return false; } // Load the list of users. $users = FD::user($rows); return $users; }
/** * Binds any temporary files to the message. * * @since 1.0 * @access public * @param string * @return */ public function bindTemporaryFiles($ids) { // This should only be executed with a valid conversation. if (!$this->id) { $this->setError(JText::_('COM_EASYSOCIAL_CONVERSATIONS_ERROR_STORE_CONVERSATION_FIRST')); return false; } // Ensure that they are in an array form. $ids = FD::makeArray($ids); foreach ($ids as $id) { $file = FD::table('File'); $file->uid = $this->id; $file->type = SOCIAL_TYPE_CONVERSATIONS; // Copy some of the data from the temporary table. $file->copyFromTemporary($id); $file->store(); } return true; }