Example #1
0
 public function __construct()
 {
     // Define Joomla's app
     $this->app = JFactory::getApplication();
     $this->input = $this->app->input;
     // Load configuration object.
     $config = FD::config();
     $jConfig = FD::jconfig();
     // Define the current logged in user or guest
     if (is_null(self::$user)) {
         self::$user = FD::user();
     }
     // Define the current logged in user's access.
     if (is_null(self::$userAccess)) {
         self::$userAccess = FD::access();
     }
     if (is_null(self::$tmplMode)) {
         self::$tmplMode = $this->input->get('tmpl', '', 'default');
     }
     // Get the current access
     $this->my = self::$user;
     $this->access = self::$userAccess;
     // Define our own configuration
     $this->config = $config;
     // Define template's own configuration
     if (is_null(self::$templateConfig)) {
         self::$templateConfig = $this->getConfig();
     }
     $this->template = self::$templateConfig;
     // Define Joomla's configuration so the world can use it.
     $this->jConfig = $jConfig;
     // Determine if the current request has tmpl=xxx
     $this->tmpl = self::$tmplMode;
 }
Example #2
0
 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;
 }
Example #3
0
 /**
  * Dialog to confirm a report.
  *
  * @since	1.0
  * @access	public
  */
 public function confirmReport()
 {
     $ajax = FD::ajax();
     // Determine if the user is a guest
     $my = FD::user();
     $config = FD::config();
     if (!$my->id) {
         if (!$config->get('reports.guests', false)) {
             return;
         }
     } else {
         // Check if user is really allowed to submit any reports.
         $access = FD::access();
         if (!$access->allowed('reports.submit')) {
             $this->setMessage(JText::_('COM_EASYSOCIAL_REPORTS_NOT_ALLOWED_TO_SUBMIT_REPORTS'), SOCIAL_MSG_ERROR);
             return $ajax->reject($this->getMessage());
         }
     }
     $title = JRequest::getVar('title', JText::_('COM_EASYSOCIAL_REPORTS_DIALOG_TITLE'));
     $description = JRequest::getVar('description', '');
     $theme = FD::themes();
     $theme->set('title', $title);
     $theme->set('description', $description);
     $html = $theme->output('site/reports/dialog.form');
     return $ajax->resolve($html);
 }
Example #4
0
 public function __construct()
 {
     $this->doc = JFactory::getDocument();
     $this->config = FD::config();
     $this->app = JFactory::getApplication();
     $this->input = FD::request();
     $this->my = FD::user();
     $this->access = FD::access();
 }
Example #5
0
 /**
  * Displays the comments title in the stream.
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function getTitle()
 {
     $config = FD::config();
     $access = FD::access();
     if (!$config->get('stream.comments.enabled') || !$access->allowed('comments.add')) {
         return false;
     }
     $my = FD::user();
     return JText::_('Comment');
 }
Example #6
0
 public function onRegister(&$post, &$session)
 {
     // Get access
     $access = FD::access($session->uid, SOCIAL_TYPE_CLUSTERS);
     if (!$access->get('events.groupevent', true)) {
         return;
     }
     $value = !empty($post['eventcreate']) ? $post['eventcreate'] : '[]';
     $value = FD::makeArray($value);
     $this->set('value', $value);
     return $this->display();
 }
Example #7
0
 /**
  * Generates the report link to allow users to report on an item
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function getForm($extension, $type, $uid, $itemTitle, $text, $title = '', $description = '', $url = '', $icon = false)
 {
     // Determine if the user is a guest
     $my = FD::user();
     $config = FD::config();
     if (!$my->id) {
         if (!$config->get('reports.guests', false)) {
             return;
         }
     } else {
         // Check if user is allowed to report.
         $access = FD::access();
         // @access: reports.submit
         // Check if user is allowed to create reports
         if (!$access->allowed('reports.submit')) {
             return;
         }
         $model = FD::model('Reports');
         $usage = $model->getCount(array('created_by' => $my->id));
         // Check if the current user exceeded the reports limit
         if ($access->exceeded('reports.limit', $usage)) {
             return;
         }
     }
     $theme = FD::themes();
     // Set a default text if API wasn't provided with a custom text.
     if (empty($text)) {
         $text = JText::_('COM_EASYSOCIAL_REPORTS_REPORT_ITEM');
     }
     // If url is not provided, use the current URL.
     if (empty($url)) {
         $url = JRequest::getURI();
     }
     // If title is not supplied, we use the text
     if (empty($title)) {
         $title = $text;
     }
     $theme->set('url', $url);
     $theme->set('extension', $extension);
     $theme->set('itemTitle', $itemTitle);
     $theme->set('title', $title);
     $theme->set('text', $text);
     $theme->set('type', $type);
     $theme->set('uid', $uid);
     $theme->set('description', $description);
     $theme->set('icon', $icon);
     $contents = $theme->output('site/reports/default.link');
     return $contents;
 }
Example #8
0
 public function upload()
 {
     // Get the ajax library
     $ajax = FD::ajax();
     // Get the file
     $tmp = JRequest::getVar($this->inputName, '', 'FILES');
     $file = array();
     foreach ($tmp as $k => $v) {
         $file[$k] = $v['file'];
     }
     // Check if it is a valid file
     if (empty($file['tmp_name'])) {
         return $ajax->reject(JText::_('PLG_FIELDS_AVATAR_ERROR_INVALID_FILE'));
     }
     // Get user access
     $access = FD::access($this->uid, SOCIAL_TYPE_CLUSTERS);
     // Check if the filesize is too large
     $maxFilesize = $access->get('photos.maxsize');
     $maxFilesizeBytes = (int) $maxFilesize * 1048576;
     if ($file['size'] > $maxFilesizeBytes) {
         return $ajax->reject(JText::sprintf('COM_EASYSOCIAL_PHOTOS_UPLOAD_ERROR_FILE_SIZE_LIMIT_EXCEEDED', $maxFilesize . 'mb'));
     }
     // Load up the image library so we can get the appropriate extension
     $image = FD::image();
     $image->load($file['tmp_name']);
     // Copy this to temporary location first
     $tmpPath = SocialFieldsUserAvatarHelper::getStoragePath($this->inputName);
     $tmpName = md5($file['name'] . $this->inputName . FD::date()->toMySQL()) . $image->getExtension();
     $source = $file['tmp_name'];
     $target = $tmpPath . '/' . $tmpName;
     $state = JFile::copy($source, $target);
     if (!$state) {
         return $ajax->reject(JText::_('PLG_FIELDS_AVATAR_ERROR_UNABLE_TO_MOVE_FILE'));
     }
     $tmpUri = SocialFieldsUserAvatarHelper::getStorageURI($this->inputName);
     $uri = $tmpUri . '/' . $tmpName;
     return $ajax->resolve($file, $uri, $target);
 }
Example #9
0
 /**
  * Performs the file uploading here when the user selects their profile picture.
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function upload()
 {
     // Get the ajax library
     $ajax = FD::ajax();
     $tmp = JRequest::getVar($this->inputName, '', 'FILES');
     $file = array();
     foreach ($tmp as $k => $v) {
         $file[$k] = $v['file'];
     }
     if (!isset($file['tmp_name']) || empty($file['tmp_name'])) {
         return $ajax->reject(JText::_('PLG_FIELDS_COVER_VALIDATION_INVALID_IMAGE'));
     }
     // Get user access
     $access = FD::access($this->uid, SOCIAL_TYPE_PROFILES);
     // Check if the filesize is too large
     $maxFilesize = $access->get('photos.uploader.maxsize');
     $maxFilesizeBytes = (int) $access->get('photos.uploader.maxsize') * 1048576;
     if ($file['size'] > $maxFilesizeBytes) {
         return $ajax->reject(JText::sprintf('COM_EASYSOCIAL_PHOTOS_UPLOAD_ERROR_FILE_SIZE_LIMIT_EXCEEDED', $maxFilesize . 'mb'));
     }
     $result = $this->createCover($file, $this->inputName);
     return $ajax->resolve($result);
 }
Example #10
0
 /**
  * Gets the @SocialAccess object.
  *
  * @since	1.0
  * @access	public
  * @param	null
  * @return	SocialAccess
  *
  * @author	Mark Lee <*****@*****.**>
  */
 public function getAccess()
 {
     static $data = null;
     if (!isset($data[$this->id])) {
         $access = FD::access($this->id, SOCIAL_TYPE_USER);
         $data[$this->id] = $access;
     }
     return $data[$this->id];
 }
Example #11
0
 public function uploadPhoto($log_usr = 0, $type = null)
 {
     // Get current logged in user.
     $my = FD::user($log_usr);
     // Get user access
     $access = FD::access($my->id, SOCIAL_TYPE_USER);
     // Load up the photo library
     $lib = FD::photo($log_usr, $type);
     // Define uploader options
     $options = array('name' => 'file', 'maxsize' => $lib->getUploadFileSizeLimit());
     // Get uploaded file
     $file = FD::uploader($options)->getFile();
     // Load the iamge object
     $image = FD::image();
     $image->load($file['tmp_name'], $file['name']);
     // Detect if this is a really valid image file.
     if (!$image->isValid()) {
         return "invalid image";
     }
     // Load up the album's model.
     $albumsModel = FD::model('Albums');
     // Create the default album if necessary
     $album = $albumsModel->getDefaultAlbum($log_usr, $type, SOCIAL_ALBUM_STORY_ALBUM);
     // Bind photo data
     $photo = FD::table('Photo');
     $photo->uid = $log_usr;
     $photo->type = $type;
     $photo->user_id = $my->id;
     $photo->album_id = $album->id;
     $photo->title = $file['name'];
     $photo->caption = '';
     $photo->state = 1;
     $photo->ordering = 0;
     // Set the creation date alias
     $photo->assigned_date = FD::date()->toMySQL();
     // Trigger rules that should occur before a photo is stored
     $photo->beforeStore($file, $image);
     // Try to store the photo.
     $state = $photo->store();
     // Load the photos model
     $photosModel = FD::model('Photos');
     // Get the storage path for this photo
     $storage = FD::call('Photos', 'getStoragePath', array($album->id, $photo->id));
     // Get the photos library
     $photoLib = FD::get('Photos', $image);
     $paths = $photoLib->create($storage);
     // Create metadata about the photos
     if ($paths) {
         foreach ($paths as $type => $fileName) {
             $meta = FD::table('PhotoMeta');
             $meta->photo_id = $photo->id;
             $meta->group = SOCIAL_PHOTOS_META_PATH;
             $meta->property = $type;
             $meta->value = $storage . '/' . $fileName;
             $meta->store();
             // We need to store the photos dimension here
             list($width, $height, $imageType, $attr) = getimagesize(JPATH_ROOT . $storage . '/' . $fileName);
             // Set the photo dimensions
             $meta = FD::table('PhotoMeta');
             $meta->photo_id = $photo->id;
             $meta->group = SOCIAL_PHOTOS_META_WIDTH;
             $meta->property = $type;
             $meta->value = $width;
             $meta->store();
             $meta = FD::table('PhotoMeta');
             $meta->photo_id = $photo->id;
             $meta->group = SOCIAL_PHOTOS_META_HEIGHT;
             $meta->property = $type;
             $meta->value = $height;
             $meta->store();
         }
     }
     // After storing the photo, trigger rules that should occur after a photo is stored
     //$photo->afterStore( $file , $image );
     //$sphoto = new SocialPhotos($photo_obj->id);
     return $photo;
 }
Example #12
0
 /**
  * Gets the SocialAccess object.
  *
  * @author  Mark Lee <*****@*****.**>
  * @since   1.2
  * @access  public
  * @return  SocialAccess The SocialAccess object.
  *
  */
 public function getAccess()
 {
     static $data = null;
     if (!isset($data[$this->category_id])) {
         $access = FD::access($this->category_id, SOCIAL_TYPE_CLUSTERS);
         $data[$this->category_id] = $access;
     }
     return $data[$this->category_id];
 }
Example #13
0
 public function getReplies()
 {
     FD::checkToken();
     $view = $this->getCurrentView();
     // Check for permission first
     $access = FD::access();
     if (!$access->allowed('comments.read')) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_COMMENTS_NOT_ALLOWED_TO_READ'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     $id = JRequest::getInt('id', 0);
     if (empty($id)) {
         return $view->call(__FUNCTION__, array());
     }
     $start = JRequest::getInt('start', '');
     $limit = JRequest::getInt('length', '');
     $model = FD::model('comments');
     $replies = $model->getComments(array('parentid' => $id, 'start' => $start, 'limit' => $limit));
     $view->call(__FUNCTION__, $replies);
 }
Example #14
0
 /**
  * Stores a submitted report
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function store()
 {
     // Check for request forgeries
     FD::checkToken();
     // Get data from $_POST
     $post = JRequest::get('post');
     // Get current view.
     $view = $this->getCurrentView();
     // Get the current logged in user
     $my = FD::user();
     // Determine if the user is a guest
     $config = FD::config();
     if (!$my->id && !$config->get('reports.guests', false)) {
         return;
     }
     // Determine if this user has the permissions to submit reports.
     $access = FD::access();
     if (!$access->allowed('reports.submit')) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_REPORTS_NOT_ALLOWED_TO_SUBMIT_REPORTS'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Get the reports model
     $model = FD::model('Reports');
     // Determine if this user has exceeded the number of reports that they can submit
     $total = $model->getCount(array('created_by' => $my->id));
     if ($access->exceeded('reports.limit', $total)) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_REPORTS_LIMIT_EXCEEDED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Create the report
     $report = FD::table('Report');
     $report->bind($post);
     // Try to get the user's ip address.
     $report->ip = JRequest::getVar('REMOTE_ADDR', '', 'SERVER');
     // Set the creator id.
     $report->created_by = $my->id;
     // 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) {
         $view->setMessage($report->getError(), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // @badge: reports.create
     // Add badge for the author when a report is created.
     $badge = FD::badges();
     $badge->log('com_easysocial', 'reports.create', $my->id, 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', $my->id);
     // Determine if we should send an email
     $config = FD::config();
     if ($config->get('reports.notifications.moderators')) {
         $report->notify();
     }
     $view->setMessage(JText::_('COM_EASYSOCIAL_REPORTS_STORED_SUCCESSFULLY'), SOCIAL_MSG_SUCCESS);
     return $view->call(__FUNCTION__);
 }
Example #15
0
 /**
  * Logics to create a new conversations.
  *
  * @since	1.0
  * @access	public
  */
 public function store()
 {
     // Check for request forgeries.
     FD::checkToken();
     // Ensure that the user is logged in.
     FD::requireLogin();
     // Get the current logged in user.
     $my = FD::user();
     // Get list of recipients.
     $recipients = JRequest::getVar('uid');
     // Ensure that the recipients is an array.
     $recipients = FD::makeArray($recipients);
     // The user might be writing to a friend list.
     $lists = JRequest::getVar('list_id');
     // Go through each of the list and find the member id's.
     if ($lists) {
         $ids = array();
         $listModel = FD::model('Lists');
         foreach ($lists as $listId) {
             $members = $listModel->getMembers($listId, true);
             // Merge the result set.
             $ids = array_merge($ids, $members);
         }
         if ($recipients === false) {
             $recipients = array();
         }
         // Merge the id's with the recipients and ensure that they are all unique
         $recipients = array_merge($ids, $recipients);
         $recipients = array_unique($recipients);
     }
     // Get the view.
     $view = $this->getCurrentView();
     // Get configuration
     $config = FD::config();
     // Check if user is allowed to create new conversations
     $access = FD::access();
     if (!$access->allowed('conversations.create')) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_CONVERSATIONS_ERROR_NOT_ALLOWED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // If recipients is not provided, we need to throw an error.
     if (empty($recipients)) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_CONVERSATIONS_ERROR_EMPTY_RECIPIENTS'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Get the total number of message sent in a day
     $model = FD::model('Conversations');
     $totalSent = $model->getTotalSentDaily($my->id);
     // We need to calculate the amount of users they are sending to
     $totalSent = $totalSent + count($recipients);
     if ($access->exceeded('conversations.send.daily', $totalSent)) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_CONVERSATIONS_EXCEEDED_DAILY_SEND_LIMIT'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Check if the creator is allowed to send a message to the target
     $privacy = $my->getPrivacy();
     // Ensure that the recipients is not only itself.
     foreach ($recipients as $recipient) {
         // When user tries to enter it's own id, we should just break out of this function.
         if ($recipient == $my->id) {
             $view->setMessage(JText::_('COM_EASYSOCIAL_CONVERSATIONS_ERROR_CANNOT_SEND_TO_SELF'), SOCIAL_MSG_ERROR);
             return $view->call(__FUNCTION__);
         }
         // Check if the creator is allowed
         if (!$privacy->validate('profiles.post.message', $recipient, SOCIAL_TYPE_USER)) {
             $view->setMessage(JText::_('COM_EASYSOCIAL_CONVERSATIONS_ERROR_CANNOT_SEND_TO_USER_DUE_TO_PRIVACY'), SOCIAL_MSG_ERROR);
             return $view->call(__FUNCTION__);
         }
     }
     // Get the message that is being posted.
     $msg = JRequest::getVar('message', '', 'REQUEST', 'none', JREQUEST_ALLOWHTML);
     // Normalize CRLF (\r\n) to just LF (\n)
     $msg = str_ireplace("\r\n", "\n", $msg);
     // Message should not be empty.
     if (empty($msg)) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_CONVERSATIONS_ERROR_EMPTY_MESSAGE'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Filter recipients and ensure all the user id's are proper!
     $total = count($recipients);
     // If there is more than 1 recipient and group conversations is disabled, throw some errors
     if ($total > 1 && !$config->get('conversations.multiple')) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_CONVERSATIONS_GROUP_CONVERSATIONS_DISABLED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Go through all the recipient and make sure that they are valid.
     for ($i = 0; $i < $total; $i++) {
         $userId = $recipients[$i];
         $user = FD::user($userId);
         if (!$user || empty($userId)) {
             unset($recipients[$i]);
         }
     }
     // After processing the recipients list, and no longer has any recipients, stop the user.
     if (empty($recipients)) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_CONVERSATIONS_ERROR_EMPTY_RECIPIENTS'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Get the conversation table.
     $conversation = FD::table('Conversation');
     // Determine the type of message this is by the number of recipients.
     $type = count($recipients) > 1 ? SOCIAL_CONVERSATION_MULTIPLE : SOCIAL_CONVERSATION_SINGLE;
     // For single recipients, we try to reuse back previous conversations
     // so that it will be like a long chat of history.
     if ($type == SOCIAL_CONVERSATION_SINGLE) {
         // We know that the $recipients[0] is always the target user.
         $state = $conversation->loadByRelation($my->id, $recipients[0], SOCIAL_CONVERSATION_SINGLE);
     }
     // @points: conversation.create.group
     // Assign points when user starts new group conversation
     if (count($recipients) > 1) {
         $points = FD::points();
         $points->assign('conversation.create.group', 'com_easysocial', $my->id);
     }
     // Set the conversation creator.
     $conversation->created_by = $my->id;
     // Set the last replied date.
     $conversation->lastreplied = FD::date()->toMySQL();
     // Set the conversation type.
     $conversation->type = $type;
     // Let's try to create the conversation now.
     $state = $conversation->store();
     // If there's an error storing the conversation, break.
     if (!$state) {
         $view->setMessage(JText::_($conversation->getError()), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // @rule: Store conversation message
     $message = FD::table('ConversationMessage');
     $post = JRequest::get('POST');
     // Bind the message data.
     $message->bind($post);
     // Set the message because we normalized the CRLF (\r\n) to LF (\n)
     $message->message = $msg;
     // Set the conversation id since we have the conversation id now.
     $message->conversation_id = $conversation->id;
     // Sets the message type.
     $message->type = SOCIAL_CONVERSATION_TYPE_MESSAGE;
     // Set the creation date.
     $message->created = FD::date()->toMySQL();
     // Set the creator.
     $message->created_by = $my->id;
     // Try to store the message now.
     $state = $message->store();
     // Once the message is saved, we need to process any tags
     $tags = JRequest::getVar('tags');
     if ($tags) {
         foreach ($tags as $raw) {
             $object = FD::json()->decode($raw);
             $tag = FD::table('Tag');
             $tag->offset = $object->start;
             $tag->length = $object->length;
             $tag->type = $object->type;
             if ($tag->type == 'hashtag') {
                 $tag->title = $object->value;
             }
             if ($tag->type == 'entity') {
                 list($entityType, $entityId) = explode(':', $object->value);
                 $tag->item_id = $entityId;
                 $tag->item_type = $entityType;
             }
             $tag->creator_id = $my->id;
             $tag->creator_type = SOCIAL_TYPE_USER;
             $tag->target_id = $message->id;
             $tag->target_type = 'conversations';
             $tag->store();
         }
     }
     if (!$state) {
         $view->setMessage(JText::_($message->getError()), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Add users to the message maps.
     array_unshift($recipients, $my->id);
     $model = FD::model('Conversations');
     // Add the recipient as a participant of this conversation.
     $model->addParticipants($conversation->id, $recipients);
     // Add the message maps so that the recipient can view the message
     $model->addMessageMaps($conversation->id, $message->id, $recipients, $my->id);
     // Process attachments here.
     if ($config->get('conversations.attachments.enabled')) {
         $attachments = JRequest::getVar('upload-id');
         // If there are attachments, store them appropriately.
         if ($attachments) {
             $message->bindTemporaryFiles($attachments);
         }
     }
     // Bind message location if necessary.
     if ($config->get('conversations.location')) {
         $address = JRequest::getVar('address', '');
         $latitude = JRequest::getVar('latitude', '');
         $longitude = JRequest::getVar('longitude', '');
         if (!empty($address) && !empty($latitude) && !empty($longitude)) {
             $location = FD::table('Location');
             $location->loadByType($message->id, SOCIAL_TYPE_CONVERSATIONS, $my->id);
             $location->address = $address;
             $location->latitude = $latitude;
             $location->longitude = $longitude;
             $location->user_id = $this->created_by;
             $location->type = SOCIAL_TYPE_CONVERSATIONS;
             $location->uid = $message->id;
             $state = $location->store();
         }
     }
     // Send notification email to recipients
     foreach ($recipients as $recipientId) {
         // We should not send a notification to ourself.
         if ($recipientId != $my->id) {
             $recipient = FD::user($recipientId);
             // Add new notification item
             $mailParams = array();
             $mailParams['title'] = 'COM_EASYSOCIAL_EMAILS_NEW_CONVERSATION_SUBJECT';
             $mailparams['actor'] = $my->getName();
             $mailParams['authorName'] = $my->getName();
             $mailParams['authorAvatar'] = $my->getAvatar();
             $mailParams['authorLink'] = $my->getPermalink(true, true);
             $mailParams['message'] = $message->message;
             $mailParams['messageDate'] = $message->created;
             $mailParams['conversationLink'] = $conversation->getPermalink(true, true);
             // Send a notification for all participants in this thread.
             $state = FD::notify('conversations.new', array($recipientId), $mailParams, false);
         }
     }
     $view->setMessage(JText::_('COM_EASYSOCIAL_CONVERSATIONS_MESSAGE_SENT'), SOCIAL_MSG_SUCCESS);
     // Pass this back to the view.
     return $view->call(__FUNCTION__, $conversation);
 }
Example #16
0
 /**
  * Posting photos via story
  *
  * @since   1.0
  * @access  public
  */
 public function uploadStory()
 {
     // Check for request forgeries
     FD::checkToken();
     // Only registered users should be allowed to upload photos
     FD::requireLogin();
     // Get the current view
     $view = $this->getCurrentView();
     // Get current logged in user.
     $my = FD::user();
     // Get user access
     $access = FD::access($my->id, SOCIAL_TYPE_USER);
     // Get the uid and type
     $uid = $this->input->get('uid', 0, 'int');
     $type = $this->input->get('type', '', 'cmd');
     // Load up the photo library
     $lib = FD::photo($uid, $type);
     // Determines if the person exceeded their upload limit
     if ($lib->exceededUploadLimit()) {
         $view->setMessage($lib->getError(), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Determines if the person exceeded their daily upload limit
     if ($lib->exceededDailyUploadLimit()) {
         $view->setMessage($lib->getError(), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Define uploader options
     $options = array('name' => 'file', 'maxsize' => $lib->getUploadFileSizeLimit());
     // Get uploaded file
     $file = FD::uploader($options)->getFile();
     // If there was an error getting uploaded file, stop.
     if ($file instanceof SocialException) {
         $view->setMessage($file, SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Load the iamge object
     $image = FD::image();
     $image->load($file['tmp_name'], $file['name']);
     // Detect if this is a really valid image file.
     if (!$image->isValid()) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_PHOTOS_INVALID_FILE_PROVIDED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Load up the album's model.
     $albumsModel = FD::model('Albums');
     // Create the default album if necessary
     $album = $albumsModel->getDefaultAlbum($uid, $type, SOCIAL_ALBUM_STORY_ALBUM);
     // Bind photo data
     $photo = FD::table('Photo');
     $photo->uid = $uid;
     $photo->type = $type;
     $photo->user_id = $my->id;
     $photo->album_id = $album->id;
     $photo->title = $file['name'];
     $photo->caption = '';
     $photo->ordering = 0;
     // Set the creation date alias
     $photo->assigned_date = FD::date()->toMySQL();
     // Trigger rules that should occur before a photo is stored
     $photo->beforeStore($file, $image);
     // Try to store the photo.
     $state = $photo->store();
     if (!$state) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_PHOTOS_UPLOAD_ERROR_STORING_DB'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Load the photos model
     $photosModel = FD::model('Photos');
     // Get the storage path for this photo
     $storage = FD::call('Photos', 'getStoragePath', array($album->id, $photo->id));
     // Get the photos library
     $photoLib = FD::get('Photos', $image);
     $paths = $photoLib->create($storage);
     // Create metadata about the photos
     if ($paths) {
         foreach ($paths as $type => $fileName) {
             $meta = FD::table('PhotoMeta');
             $meta->photo_id = $photo->id;
             $meta->group = SOCIAL_PHOTOS_META_PATH;
             $meta->property = $type;
             $meta->value = $storage . '/' . $fileName;
             $meta->store();
             // We need to store the photos dimension here
             list($width, $height, $imageType, $attr) = getimagesize(JPATH_ROOT . $storage . '/' . $fileName);
             // Set the photo dimensions
             $meta = FD::table('PhotoMeta');
             $meta->photo_id = $photo->id;
             $meta->group = SOCIAL_PHOTOS_META_WIDTH;
             $meta->property = $type;
             $meta->value = $width;
             $meta->store();
             $meta = FD::table('PhotoMeta');
             $meta->photo_id = $photo->id;
             $meta->group = SOCIAL_PHOTOS_META_HEIGHT;
             $meta->property = $type;
             $meta->value = $height;
             $meta->store();
         }
     }
     // After storing the photo, trigger rules that should occur after a photo is stored
     $photo->afterStore($file, $image);
     return $view->call(__FUNCTION__, $photo, $paths, $width, $height);
 }
Example #17
0
 /**
  * Displays the compose conversation view.
  *
  * @access	public
  * @param	$conversation
  * @return	null
  */
 public function compose($conversation = null)
 {
     // @task: Prevent unauthorized access.
     FD::requireLogin();
     // Check for user profile completeness
     FD::checkCompleteProfile();
     // Check if user has access to create new conversations
     $access = FD::access();
     if (!$access->allowed('conversations.create')) {
         $this->setMessage(JText::_('COM_EASYSOCIAL_CONVERSATIONS_ERROR_NOT_ALLOWED'), SOCIAL_MSG_ERROR);
         FD::info()->set($this->getMessage());
         return $this->redirect(FRoute::conversations(array(), false));
     }
     // Set the page title
     $title = JText::_('COM_EASYSOCIAL_PAGE_TITLE_CONVERSATIONS_COMPOSE');
     FD::page()->title($title);
     // Set breadcrumbs
     FD::page()->breadcrumb($title);
     // Get current logged in user.
     $my = FD::user();
     // There could be errors on the form, we need to reset the message
     $message = JRequest::getVar('message', '');
     // Get a list of friend list from the current user.
     $listModel = FD::model('Lists');
     $lists = $listModel->getLists(array('user_id' => $my->id));
     $this->set('lists', $lists);
     $this->set('message', $message);
     echo parent::display('site/conversations/compose');
 }
Example #18
0
 /**
  * Retrieves the ACL for this category
  *
  * @since   1.3
  * @access  public
  * @param   string
  * @return  
  */
 public function getAcl()
 {
     $acl = FD::access($this->id, SOCIAL_TYPE_CLUSTERS);
     return $acl;
 }
Example #19
0
 /**
  * Creates a new friend list.
  *
  * @since	1.0
  * @access	public
  * @return
  */
 public function storeList()
 {
     // Check for request forgeries.
     FD::checkToken();
     // Check if user is valid.
     FD::requireLogin();
     // Check if friends list is enabled
     $config = FD::config();
     // Get the current view.
     $view = $this->getCurrentView();
     // Get current logged in user.
     $my = FD::user();
     // @friends.list.enabled
     // Check if the friend list feature is enabled
     if (!$config->get('friends.list.enabled')) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_FRIENDS_LIST_DISABLED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Get post data.
     $data = JRequest::get('POST');
     // Detect if this is an edited list or a new list
     $id = JRequest::getVar('id');
     // Generate a new list.
     $list = FD::table('List');
     // Get the access
     $access = FD::access();
     // @access friends.list.enabled
     // Check if the user is allowed to create friend lists
     if (!$access->allowed('friends.list.enabled')) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_FRIENDS_LISTS_ACCESS_NOT_ALLOWED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Check for title
     if (empty($data['title'])) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_FRIENDS_LISTS_TITLE_REQUIRED'), SOCIAL_MSG_ERROR);
         return $view->call('listForm');
     }
     if (!empty($id)) {
         $list->load($id);
     } else {
         // This will be a new friend list, check if the user has already reached the limit
         $listModel = FD::model('Lists');
         // Get the total friends list a user has
         $totalFriendsList = $listModel->getTotalLists($my->id);
         if ($access->exceeded('friends.list.limit', $totalFriendsList)) {
             $view->setMessage(JText::_('COM_EASYSOCIAL_FRIENDS_LISTS_ACCESS_LIMIT_EXCEEDED'));
             return $view->call(__FUNCTION__);
         }
     }
     // Bind the list with the posted data.
     $list->bind($data);
     // Check if the user owns this list item.
     if (!empty($list->id) && $my->id != $list->user_id) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_LISTS_ERROR_LIST_IS_NOT_OWNED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Set the creator of the list.
     $list->user_id = $my->id;
     // Prepare the dispatcher
     FD::apps()->load(SOCIAL_TYPE_USER);
     $dispatcher = FD::dispatcher();
     $args = array(&$list);
     // @trigger: onFriendListBeforeSave
     $dispatcher->trigger(SOCIAL_TYPE_USER, 'onFriendListBeforeSave', $args);
     // Try to store the list.
     $state = $list->store();
     // @trigger: onFriendListBeforeSave
     $dispatcher->trigger(SOCIAL_TYPE_USER, 'onFriendListAfterSave', $args);
     if (!$state) {
         FD::logError(__FILE__, __LINE__, 'FRIENDS: Unable to create new friend list for user ' . $my->id);
         $view->setMessage(JText::_('COM_EASYSOCIAL_LISTS_ERROR_CREATING_LIST'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__, $list);
     }
     // Get friends from this list
     $friends = JRequest::getVar('uid');
     // Assign these friends into the list.
     $list->addFriends($friends);
     $view->setMessage(JText::_('COM_EASYSOCIAL_LISTS_CREATED_SUCCESSFULLY'), SOCIAL_MSG_SUCCESS);
     return $view->call(__FUNCTION__, $list);
 }