private function getElementSource() { $element = $this->item->context; $uid = $this->item->contextId; // photos has the special threatment. if the item is a aggregated item, then the context is album and the uid is albumid. if ($element == 'photos') { if (count($this->item->contextIds) > 1) { $photo = FD::table('Photo'); $photo->load($uid); $element = 'albums'; $uid = $photo->album_id; } } if ($element == 'story' || $element == 'links') { $uid = $this->item->uid; } if ($element == 'badges') { $tbl = FD::table('StreamItem'); $tbl->load(array('uid' => $this->item->uid)); $element = SOCIAL_TYPE_ACTIVITY; $uid = $tbl->id; } $obj = new stdClass(); $obj->element = $element; $obj->uid = $uid; return $obj; }
/** * Validates the username. * * @since 1.0 * @access public * @param null * @return JSON A jsong encoded string. * * @author Jason Rey <*****@*****.**> */ public function isValid() { // Render the ajax lib. $ajax = FD::getInstance('Ajax'); // Get the userid $userid = JRequest::getInt('userid', 0); // Get the event $event = JRequest::getString('event'); // Set the current username $current = ''; if (!empty($userid)) { $user = FD::user($userid); $current = $user->username; } // Get the provided username that the user has typed. $username = JRequest::getVar('username', ''); // Username is required, check if username is empty if (JString::strlen($username) < $this->params->get('min')) { return $ajax->reject(JText::sprintf('PLG_FIELDS_JOOMLA_USERNAME_MIN_CHARACTERS', $this->params->get('min'))); } // Test if username is allowed (by pass for adminedit). if ($event !== 'onAdminEdit' && !SocialFieldsUserJoomlaUsernameHelper::allowed($username, $this->params)) { return $ajax->reject(JText::_('PLG_FIELDS_JOOMLA_USERNAME_NOT_ALLOWED')); } // Test if username exists. if (SocialFieldsUserJoomlaUsernameHelper::exists($username, $current)) { return $ajax->reject(JText::_('PLG_FIELDS_JOOMLA_USERNAME_NOT_AVAILABLE')); } // Test if the username is valid if (!SocialFieldsUserJoomlaUsernameHelper::isValid($username, $this->params)) { return $ajax->reject(JText::_('PLG_FIELDS_JOOMLA_USERNAME_IS_INVALID')); } $text = JText::_('PLG_FIELDS_JOOMLA_USERNAME_AVAILABLE'); return $ajax->resolve($text); }
/** * Some desc * * @since 1.0 * @access public * @param string * @return */ public function createCover($file, $inputName) { // Load our own image library $image = FD::image(); // Generates a unique name for this image. $name = $file['name']; // Load up the file. $image->load($file['tmp_name'], $name); // Ensure that the image is valid. if (!$image->isValid()) { // @TODO: Add some logging here. echo JText::_('PLG_FIELDS_AVATAR_VALIDATION_INVALID_IMAGE'); exit; } // Get the storage path $storage = SocialFieldsUserCoverHelper::getStoragePath($inputName); // Create a new avatar object. $photos = FD::get('Photos', $image); // Create avatars $sizes = $photos->create($storage); // We want to format the output to get the full absolute url. $base = basename($storage); $result = array(); foreach ($sizes as $size => $value) { $row = new stdClass(); $row->title = $file['name']; $row->file = $value; $row->path = JPATH_ROOT . '/media/com_easysocial/tmp/' . $base . '/' . $value; $row->uri = rtrim(JURI::root(), '/') . '/media/com_easysocial/tmp/' . $base . '/' . $value; $result[$size] = $row; } return $result; }
public function getItems($options = array()) { $db = FD::db(); $sql = $db->sql(); $sql->select('#__social_clusters_nodes', 'a'); $sql->column('a.*'); $eventid = isset($options['eventid']) ? $options['eventid'] : 0; $sql->where('cluster_id', $eventid); if (isset($options['state'])) { $sql->where('state', $state); } if (isset($options['admin'])) { $sql->where('admin', $options['admin']); } $ordering = $this->getState('ordering'); if (!empty($ordering)) { $direction = $this->getState('direction'); if ($ordering == 'username') { $sql->leftjoin('#__users', 'b'); $sql->on('a.uid', 'b.id'); $sql->order('b.username', $direction); } elseif ($ordering == 'name') { $sql->leftjoin('#__users', 'b'); $sql->on('a.uid', 'b.id'); $sql->order('b.name', $direction); } else { $sql->order($ordering, $direction); } } $this->setTotal($sql->getTotalSql()); $result = $this->getData($sql->getSql()); $guests = $this->bindTable('EventGuest', $result); return $guests; }
public function main() { $db = FD::db(); $sql = $db->sql(); // First we get the core.view privacy id $sql->select('#__social_privacy')->column('id')->where('type', 'core')->where('rule', 'view'); $db->setQuery($sql); $origId = $db->loadResult(); // Then we cache a copy of all the new field rules and the id $sql->clear(); $sql->select('#__social_privacy')->column('id')->column('rule')->where('type', 'field'); $db->setQuery($sql); $rules = $db->loadObjectList('rule'); // Then we get all the privacy items with this id and type = 'field' $sql->clear(); $sql->select('#__social_privacy_items', 'a')->column('a.*')->column('c.element')->leftjoin('#__social_fields', 'b')->on('b.id', 'a.uid')->leftjoin('#__social_apps', 'c')->on('b.app_id', 'c.id')->where('(')->where('a.type', 'field')->where('a.type', 'field.datetime.year', '=', 'OR')->where(')'); $db->setQuery($sql); $result = $db->loadObjectList(); // Based on the element, we need to find the new id to map it to the rule foreach ($result as $row) { if (isset($rules[$row->element])) { $table = FD::table('privacyitems'); $table->bind($row); $table->privacy_id = $rules[$row->element]->id; $table->store(); } } // field.datetime.year need to change to year $sql->clear(); $sql->update('#__social_privacy_items')->set('type', 'year')->where('type', 'field.datetime.year'); $db->setQuery($sql); $db->query(); return true; }
public function create_report() { $app = JFactory::getApplication(); $msg = $app->input->get('message', '', 'STRING'); $title = $app->input->get('user_title', '', 'STRING'); $item_id = $app->input->get('itemId', 0, 'INT'); $log_user = $this->plugin->get('user')->id; $data = array(); $data['message'] = $msg; $data['uid'] = $item_id; $data['type'] = 'stream'; $data['title'] = $title; $data['extension'] = 'com_easysocial'; //build share url use for share post through app $sharing = FD::get('Sharing', array('url' => FRoute::stream(array('layout' => 'item', 'id' => $item_id, 'external' => true, 'xhtml' => true)), 'display' => 'dialog', 'text' => JText::_('COM_EASYSOCIAL_STREAM_SOCIAL'), 'css' => 'fd-small')); $url = $sharing->url; $data['url'] = $url; // Get the reports model $model = FD::model('Reports'); // Determine if this user has the permissions to submit reports. $access = FD::access(); // Determine if this user has exceeded the number of reports that they can submit $total = $model->getCount(array('created_by' => $log_user)); if ($access->exceeded('reports.limit', $total)) { $final_result['message'] = "Limit exceeds"; $final_result['status'] = true; return $final_result; } // Create the report $report = FD::table('Report'); $report->bind($data); // Set the creator id. $report->created_by = $log_user; // Set the default state of the report to new $report->state = 0; // Try to store the report. $state = $report->store(); // If there's an error, throw it if (!$state) { $final_result['message'] = "Can't save report"; $final_result['status'] = true; return $final_result; } // @badge: reports.create // Add badge for the author when a report is created. $badge = FD::badges(); $badge->log('com_easysocial', 'reports.create', $log_user, JText::_('COM_EASYSOCIAL_REPORTS_BADGE_CREATED_REPORT')); // @points: reports.create // Add points for the author when a report is created. $points = FD::points(); $points->assign('reports.create', 'com_easysocial', $log_user); // Determine if we should send an email $config = FD::config(); if ($config->get('reports.notifications.moderators')) { $report->notify(); } $final_result['message'] = "Report logged successfully!"; $final_result['status'] = true; return $final_result; }
public function getResult($queries = array()) { $this->setQueries($queries); // There is 2 parts to this // nearbysearch // textsearch $nearbysearchUrl = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json'; $textsearchUrl = 'https://maps.googleapis.com/maps/api/place/textsearch/json'; $nearbysearchOptions = array('location' => $this->queries['location'], 'radius' => $this->queries['radius'], 'key' => $this->queries['key'], 'keyword' => $this->queries['keyword']); $textsearchOptions = array('query' => $this->queries['query'], 'key' => $this->queries['key']); $connector = FD::connector(); $connector->setMethod('GET'); $connector->addUrl($nearbysearchUrl . '?' . http_build_query($nearbysearchOptions)); if (!empty($this->queries['query'])) { $connector->addUrl($textsearchUrl . '?' . http_build_query($textsearchOptions)); } $connector->execute(); $results = $connector->getResults(); $venues = array(); foreach ($results as $result) { $obj = json_decode($result->contents); foreach ($obj->results as $row) { $obj = new SocialLocationData(); $obj->latitude = $row->geometry->location->lat; $obj->longitude = $row->geometry->location->lng; $obj->name = $row->name; $obj->address = isset($row->formatted_address) ? $row->formatted_address : ''; $obj->fulladdress = !empty($obj->address) ? $obj->name . ', ' . $obj->address : ''; $venues[$row->id] = $obj; } } $venues = array_values($venues); return $venues; }
/** * Returns an array of news item in JSON format. * * @since 1.0 * @access public * @param Array A list of news items. * @return SocialAjax * */ public function getNews($news, $appNews = array()) { $ajax = FD::ajax(); // Format the output of the news item since we need the following values // day,month foreach ($news as &$item) { $date = explode('/', $item->date); $item->day = $date[0]; $item->month = $date[1]; } $theme = FD::themes(); $theme->set('items', $news); $content = $theme->output('admin/news/items'); if ($appNews) { foreach ($appNews as &$appItem) { $date = FD::date($appItem->updated); $appItem->lapsed = $date->toLapsed(); $appItem->day = $date->format('d'); $appItem->month = $date->format('M'); } } $theme = FD::themes(); $theme->set('items', $appNews); $apps = $theme->output('admin/news/apps'); return $ajax->resolve($content, $apps); }
/** * Displays the application output in the canvas. * * @since 1.0 * @access public * @param int The user id that is currently being viewed. */ public function display($userId = null, $docType = null) { // Require user to be logged in FD::requireLogin(); $id = JRequest::getVar('schedule_id'); // Get the user that's being accessed. $user = FD::user($userId); $calendar = FD::table('Calendar'); $calendar->load($id); if (!$calendar->id || !$id) { FD::info()->set(false, JText::_('APP_CALENDAR_CANVAS_INVALID_SCHEDULE_ID'), SOCIAL_MSG_ERROR); return $this->redirect(FD::profile(array('id' => $user->getAlias()), false)); } $my = FD::user(); $privacy = FD::privacy($my->id); $result = $privacy->validate('apps.calendar', $calendar->id, 'view', $user->id); if (!$result) { FD::info()->set(false, JText::_('APP_CALENDAR_NO_ACCESS'), SOCIAL_MSG_ERROR); JFactory::getApplication()->redirect(FRoute::dashboard()); } FD::page()->title($calendar->title); // Render the comments and likes $likes = FD::likes(); $likes->get($id, 'calendar', 'create', SOCIAL_APPS_GROUP_USER); // Apply comments on the stream $comments = FD::comments($id, 'calendar', 'create', SOCIAL_APPS_GROUP_USER, array('url' => FRoute::albums(array('layout' => 'item', 'id' => $id)))); $params = $this->app->getParams(); $this->set('params', $params); $this->set('likes', $likes); $this->set('comments', $comments); $this->set('calendar', $calendar); $this->set('user', $user); echo parent::display('canvas/item/default'); }
/** * 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 = $this->input->get('urls', array(), 'array'); // Result placeholder $result = array(); if (!$urls) { $this->view->setMessage('COM_EASYSOCIAL_CRAWLER_INVALID_URL_PROVIDED', SOCIAL_MSG_ERROR); return $this->view->call(__FUNCTION__); } // Get the crawler $crawler = FD::get('crawler'); foreach ($urls as $url) { // Generate a hash for the 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); // Get the data from our crawler library $data = $crawler->getData(); // Now we need to cache the link so that the next time, we don't crawl it again. $link->hash = $hash; $link->data = json_encode($data); $link->store(); } $result[$url] = json_decode($link->data); } return $this->view->call(__FUNCTION__, $result); }
/** * Displays the application output in the canvas. * * @since 1.0 * @access public * @param int The user id that is currently being viewed. */ public function display($uid = null, $docType = null) { $event = FD::event($uid); $editor = JFactory::getEditor(); $guest = $event->getGuest(); // Only allow group admin to create or edit news if (!$guest->isAdmin() && !$this->my->isSiteAdmin()) { FD::info()->set(false, JText::_('COM_EASYSOCIAL_EVENTS_ONLY_GUEST_ARE_ALLOWED'), SOCIAL_MSG_ERROR); return $this->redirect($event->getPermalink(false)); } // Determines if this item is being edited $id = $this->input->get('newsId', 0, 'int'); $news = FD::table('EventNews'); $news->load($id); FD::page()->title(JText::_('APP_EVENT_NEWS_FORM_UPDATE_PAGE_TITLE')); // Determine if this is a new record or not if (!$id) { $news->comments = true; FD::page()->title(JText::_('APP_EVENT_NEWS_FORM_CREATE_PAGE_TITLE')); } // Get app params $params = $this->app->getParams(); $this->set('params', $params); $this->set('news', $news); $this->set('editor', $editor); $this->set('event', $event); echo parent::display('canvas/form'); }
public function load($path) { // Locate for the manifest file in the folder. $files = FD::get('Folders')->files($path, '.xml', self::RECURSIVE_SEARCH, self::RETRIEVE_FULL_PATH); $this->source = $path; if (!count($files)) { // Throw errors FD::get('Errors')->set('installer.xml', self::XML_NOT_FOUND); return false; } // Load through the list of manifest files to perform the installation. foreach ($files as $file) { $xml = JFactory::getXML($file); if (!$xml) { FD::get('Errors')->set('installer', self::XML_NOT_VALID); unset($xml); continue; } $this->type = (string) $xml->attributes()->type; if ($xml->getName() != 'social' || !in_array($this->type, $this->allowed)) { FD::get('Errors')->set('installer', self::XML_NOT_VALID); unset($parser); continue; } $this->parser = JFactory::getXMLParser('Simple'); $this->parser->loadFile($file); // Set the path of the current xml file. $this->path = $file; // Retrieves the element $this->element = $this->parser->document->getElementByPath('element')->data(); unset($xml); return true; } return false; }
/** * Displays the application output in the canvas. * * @since 1.0 * @access public * @param int The user id that is currently being viewed. */ public function display($uid = null, $docType = null) { $group = FD::group($uid); $editor = JFactory::getEditor(); // Only allow group admin to create or edit news if (!$group->isAdmin() && !$this->my->isSiteAdmin()) { FD::info()->set(false, JText::_('COM_EASYSOCIAL_GROUPS_ONLY_MEMBER_ARE_ALLOWED'), SOCIAL_MSG_ERROR); return $this->redirect($group->getPermalink(false)); } $id = JRequest::getInt('newsId'); $news = FD::table('GroupNews'); $news->load($id); FD::page()->title(JText::_('APP_GROUP_NEWS_FORM_UPDATE_PAGE_TITLE')); // Determine if this is a new record or not if (!$id) { $news->comments = true; FD::page()->title(JText::_('APP_GROUP_NEWS_FORM_CREATE_PAGE_TITLE')); } // Get app params $params = $this->app->getParams(); $this->set('params', $params); $this->set('news', $news); $this->set('editor', $editor); $this->set('group', $group); echo parent::display('canvas/form'); }
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); }
/** * Deletes a feed item * * @since 1.0 * @access public */ public function delete() { // Check for request forgeries. FD::checkToken(); // Ensure that the user is logged in. FD::requireLogin(); // Get the ajax object. $ajax = FD::ajax(); // Get current logged in user $my = FD::user(); // Get app's id. $id = JRequest::getInt('id'); // Get feed id. $feedId = JRequest::getInt('feedId'); // Get feed table $feed = $this->getTable('Feed'); $feed->load($feedId); if (!$feedId || !$feed->id) { return $ajax->reject(JText::_('APP_FEEDS_INVALID_ID_PROVIDED')); } // Ensure that the user is allowed to delete this feed. if ($feed->user_id != $my->id) { return $ajax->reject(JText::_('APP_FEEDS_NOT_ALLOWED_TO_DELETE')); } // Try to delete the feed now. $state = $feed->delete(); if (!$state) { return $ajax->reject($feed->getError()); } return $ajax->resolve(); }
public function getItems() { $db = FD::db(); $query = 'SELECT * FROM ' . $db->nameQuote('#__social_toolbar') . ' WHERE ' . $db->nameQuote('state') . '=' . $db->Quote(SOCIAL_STATE_PUBLISHED); $db->setQuery($query); return $db->loadObjectList(); }
public function onDisplay($user) { $regDate = FD::date($user->registerDate); $format = 'd M Y'; switch ($this->params->get('date_format')) { case 2: case '2': $format = 'M d Y'; break; case 3: case '3': $format = 'Y d M'; break; case 4: case '4': $format = 'Y M d'; break; } // linkage to advanced search page. // place the code here so that the timezone wont kick in. we search the date using GMT value. $field = $this->field; if ($field->searchable) { $date = $regDate->toFormat('Y-m-d'); $params = array('layout' => 'advanced'); $params['criterias[]'] = $field->unique_key . '|' . $field->element; $params['operators[]'] = 'between'; $params['conditions[]'] = $date . ' 00:00:00' . '|' . $date . ' 23:59:59'; $advsearchLink = FRoute::search($params); $this->set('advancedsearchlink', $advsearchLink); } $this->set('date', $regDate->toFormat($format)); return $this->display(); }
/** * Redirects a notification item to the intended location * * @since 1.0 * @access public * @param string * @return */ public function route() { // The user needs to be logged in to access notifications FD::requireLogin(); // Check for user profile completeness FD::checkCompleteProfile(); $id = JRequest::getInt('id'); $table = FD::table('Notification'); $table->load($id); if (!$id || !$table->id) { FD::info()->set(JText::_('COM_EASYSOCIAL_NOTIFICATIONS_INVALID_ID_PROVIDED'), SOCIAL_MSG_ERROR); return $this->redirect(FRoute::dashboard(array(), false)); } // Check if the user is allowed to view this notification item. $my = FD::user(); if ($table->target_id != $my->id) { FD::info()->set(JText::_('COM_EASYSOCIAL_NOTIFICATIONS_NOT_ALLOWED'), SOCIAL_MSG_ERROR); return $this->redirect(FRoute::dashboard(array(), false)); } // Mark the notification item as read $table->markAsRead(); // Ensure that all & are replaced with & $url = str_ireplace('&', '&', $table->url); $this->redirect(FRoute::_($url, false)); $this->close(); }
/** * Processes likes notifications * * @since 1.2 * @access public * @param string * @return */ public function execute(&$item) { // For rejection, we know that there's always only 1 target if ($item->cmd == 'groups.promoted') { // Get the group $group = FD::group($item->uid); $item->title = JText::sprintf('APP_GROUP_GROUPS_YOU_HAVE_BEEN_PROMOTED_AS_THE_GROUP_ADMIN', $group->getName()); $item->image = $group->getAvatar(); return; } // For rejection, we know that there's always only 1 target if ($item->cmd == 'groups.user.rejected') { // Get the group $group = FD::group($item->uid); $item->title = JText::sprintf('APP_GROUP_GROUPS_YOUR_APPLICATION_HAS_BEEN_REJECTED', $group->getName()); return; } // For user removal, we know that there's always only 1 target if ($item->cmd == 'groups.user.removed') { // Get the group $group = FD::group($item->uid); $item->title = JText::sprintf('APP_GROUP_GROUPS_YOU_HAVE_BEEN_REMOVED_FROM_GROUP', $group->getName()); return; } }
/** * Validates the username. * * @since 1.0 * @access public * @param null * @return JSON A jsong encoded string. * * @author Jason Rey <*****@*****.**> */ public function isValid() { // Render the ajax lib. $ajax = FD::ajax(); // Get the group id $groupId = JRequest::getInt('groupid', 0); // Set the current username $current = ''; if (!empty($groupId)) { $group = FD::group($groupId); $current = $group->alias; } // Get the provided permalink $permalink = JRequest::getVar('permalink', ''); // Check if the field is required if (!$this->field->isRequired() && empty($permalink)) { return true; } // Check if the permalink provided is valid if (!SocialFieldsGroupPermalinkHelper::valid($permalink, $this->params)) { return $ajax->reject(JText::_('PLG_FIELDS_GROUP_PERMALINK_INVALID_PERMALINK')); } // Test if permalink exists if (SocialFieldsGroupPermalinkHelper::exists($permalink) && $permalink != $current) { return $ajax->reject(JText::_('PLG_FIELDS_GROUP_PERMALINK_NOT_AVAILABLE')); } $text = JText::_('PLG_FIELDS_GROUP_PERMALINK_AVAILABLE'); return $ajax->resolve($text); }
public function execute($item, $calendar) { $model = FD::model('comments'); $users = $model->getParticipants($item->uid, $item->context_type); // Include the notification actor $users[] = $item->actor_id; // Exclude the current user $users = array_values(array_unique(array_diff($users, array(FD::user()->id)))); $names = FD::string()->namesToNotifications($users); $plurality = count($users) > 1 ? '_PLURAL' : '_SINGULAR'; $content = ''; if (count($users) == 1 && !empty($item->content)) { $content = JString::substr(strip_tags($item->content), 0, 30); if (JString::strlen($item->content) > 30) { $content .= JText::_('COM_EASYSOCIAL_ELLIPSES'); } } $item->content = $content; if ($calendar->user_id == $item->target_id && $item->target_type == SOCIAL_TYPE_USER) { $item->title = JText::sprintf('APP_USER_CALENDAR_USER_COMMENTED_ON_YOUR_EVENT' . $plurality, $names); return $item; } if ($calendar->user_id == $item->actor_id && count($users) == 1) { $item->title = JText::sprintf('APP_USER_CALENDAR_OWNER_COMMENTED_ON_EVENT' . FD::user($calendar->user_id)->getGendarLang(), $names); return $item; } $item->title = JText::sprintf('APP_USER_CALENDAR_USER_COMMENTED_ON_USER_EVENT' . $plurality, $names, FD::user($calendar->user_id)->getName()); return $item; }
/** * Allows remote user to authenticate via a normal http request and returns with an authentication code. * * @since 1.2.8 * @access public * @param string * @return */ public function auth() { $username = JRequest::getVar('username'); $password = JRequest::getVar('password'); $data = array('username' => $username, 'password' => $password); $app = JFactory::getApplication(); $state = $app->login($data); if ($state === false) { $this->set('code', 403); $this->set('message', JText::_('Invalid username or password provided')); return parent::display(); } // Get the user's id based on the username. $model = FD::model('Users'); $id = $model->getUserId('username', $username); if (!$id) { $this->set('code', 403); $this->set('message', JText::_('Unable to locate the user id with the given username.')); return parent::display(); } $user = FD::user($id); // User logs in successfully. Generate an authentication code for the user $user->auth = md5($user->password . JFactory::getDate()->toSql()); $user->store(); $this->set('auth', $user->auth); $this->set('code', 200); $this->set('id', $user->id); return parent::display(); }
/** * 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); }
/** * * * @since 1.2 * @access public * @param string * @return */ public function execute($item) { // Get the badge $badge = FD::table('Badge'); $badge->load($item->uid); // Break the namespace list($element, $group, $verb, $owner) = explode('.', $item->context_type); // Get the permalink of the achievement item which is the stream item $streamItem = FD::table('StreamItem'); $streamItem->load(array('context_type' => $element, 'verb' => $verb, 'actor_type' => $group, 'actor_id' => $owner)); // Get comment participants $model = FD::model('Comments'); $users = $model->getParticipants($item->uid, $item->context_type); $users[] = $item->actor_id; $users = array_values(array_unique(array_diff($users, array(FD::user()->id)))); // Convert the names to stream-ish $names = FD::string()->namesToNotifications($users); // Get the badge image $item->image = $badge->getAvatar(); $plurality = count($users) > 1 ? '_PLURAL' : '_SINGULAR'; // We need to generate the notification message differently for the author of the item and the recipients of the item. if ($owner == $item->target_id && $item->target_type == SOCIAL_TYPE_USER) { $item->title = JText::sprintf('APP_USER_BADGES_USER_COMMENTED_ON_YOUR_ACHIEVEMENT' . $plurality, $names, $badge->get('title')); return $item; } if ($owner == $item->actor_id && count($users) == 1) { $item->title = JText::sprintf('APP_USER_BADGES_OWNER_COMMENTED_ON_ACHIEVEMENT' . FD::user($owner)->getGenderLang(), $names, $badge->get('title')); return $item; } // This is for 3rd party viewers $item->title = JText::sprintf('APP_USER_BADGES_USER_COMMENTED_ON_USERS_ACHIEVEMENT' . $plurality, $names, FD::user($stream->actor_id)->getName(), $badge->get('title')); return $item; }
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 execute($item) { $model = FD::model('likes'); $users = $model->getLikerIds($item->uid, $item->context_type); $users[] = $item->actor_id; $users = array_values(array_unique(array_diff($users, array(FD::user()->id)))); $names = FD::string()->namesToNotifications($users); $plurality = count($users) > 1 ? '_PLURAL' : '_SINGULAR'; list($element, $group, $verb) = explode('.', $item->context_type); $streamItem = FD::table('streamitem'); $state = $streamItem->load(array('context_type' => $element, 'actor_type' => $group, 'verb' => $verb, 'context_id' => $item->uid)); if (!$state) { return; } $owner = $streamItem->actor_id; if ($item->target_type === SOCIAL_TYPE_USER && $item->target_id == $owner) { $item->title = JText::sprintf('APP_USER_ARTICLE_USER_LIKES_YOUR_ITEM' . $plurality, $names); return $item; } if ($item->actor_id == $owner && count($users) == 1) { $item->title = JText::sprintf('APP_USER_ARTICLE_OWNER_LIKES_ITEM' . FD::user($owner)->getGenderLang(), $names); return $item; } $item->title = JText::sprintf('APP_USER_ARTICLE_USER_LIKES_USER_ITEM' . $plurality, $names, FD::user($owner)->getName()); return $item; }
/** * 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 == 'news.event.create') { // We do not want to display any content if the person likes a event announcement $item->content = ''; // Get the news object $news = FD::table('EventNews'); $news->load($item->uid); // Get the event from the stream $event = FD::event($news->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 ($news->created_by == $item->target_id && $item->target_type == SOCIAL_TYPE_USER) { $langString = FD::string()->computeNoun('APP_EVENT_NEWS_USER_LIKES_YOUR_ANNOUNCEMENT', count($users)); $item->title = JText::sprintf($langString, $names, $event->getName()); return $item; } // This is for 3rd party viewers $langString = FD::string()->computeNoun('APP_EVENT_NEWS_USER_LIKES_USER_ANNOUNCEMENT', count($users)); $item->title = JText::sprintf($langString, $names, FD::user($news->created_by)->getName(), $event->getName()); return; } return; }
/** * Delete's the location from the database. * * @since 1.0 * @access public */ public function delete() { // Check for valid token FD::checkToken(); // Guest users shouldn't be allowed to delete any location at all. FD::requireLogin(); $my = FD::user(); $id = JRequest::getInt('id'); $view = FD::getInstance('View', 'Location', false); $location = FD::table('Location'); $location->load($id); // If id is invalid throw errors. if (!$location->id) { $view->setErrors(JText::_('COM_EASYSOCIAL_LOCATION_INVALID_ID')); } // If user do not own item, throw errors. if ($my->id !== $location->user_id) { $view->setErrors(JText::_('COM_EASYSOCIAL_LOCATION_ERROR_YOU_ARE_NOT_OWNER')); } // Try to delete location. if (!$location->delete()) { $view->setErrors($location->getError()); } return $view->delete(); }
/** * Method to get the field input markup. * * @return string The field input markup. * @since 1.6 */ protected function getInput() { // Load the language file. FD::language()->loadAdmin(); // Render the headers FD::page()->start(); // Attach dialog's css file. JFactory::getDocument()->addStylesheet(rtrim(JURI::root(), '/') . '/administrator/components/com_easysocial/themes/default/styles/style.css'); $theme = FD::themes(); $label = (string) $this->element['label']; $name = (string) $this->name; $title = JText::_('COM_EASYSOCIAL_JFIELD_SELECT_BADGE'); if ($this->value) { $badge = FD::table('Badge'); $badge->load($this->value); $title = $badge->get('title'); } $theme->set('name', $name); $theme->set('id', $this->id); $theme->set('value', $this->value); $theme->set('label', $label); $theme->set('title', $title); $output = $theme->output('admin/jfields/badge'); // We do not want to process stylesheets on Joomla 2.5 and below. $options = array(); if (FD::version()->getVersion() < 3) { $options['processStylesheets'] = false; } FD::page()->end($options); return $output; }
/** * Displays the dialog to allow user to crop avatar * * @since 1.2 * @access public * @param string * @return */ public function crop() { // Require the user to be logged in FD::requireLogin(); // Load up the ajax library $ajax = FD::ajax(); // Get the unique object. $uid = JRequest::getInt('uid'); $type = JRequest::getCmd('type'); // Get photo id $id = JRequest::getInt('id'); $table = FD::table('Photo'); $table->load($id); $redirectUrl = JRequest::getVar('redirectUrl', ''); // Load up the library $lib = FD::photo($table->uid, $table->type, $table); if (!$table->id) { return $this->deleted($lib); } // Check if the user is really allowed to upload avatar if (!$lib->canUseAvatar()) { return $ajax->reject(); } $redirect = JRequest::getInt('redirect', 1); $theme = FD::themes(); $theme->set('uid', $uid); $theme->set('type', $type); $theme->set('redirectUrl', $redirectUrl); $theme->set('photo', $lib->data); $theme->set('redirect', $redirect); $output = $theme->output('site/avatar/crop'); return $ajax->resolve($output); }