Exemple #1
0
 public static function filesBulletinAdd($userId, $bulletinId)
 {
     if ($userId == 0) {
         CAccess::setError('blockUnregister');
         return false;
     }
     $table = JTable::getInstance('Bulletin', 'CTable');
     $table->load($bulletinId);
     //CFactory::load( 'libraries' , 'limits' );
     $groupModel = CFactory::getModel('groups');
     $bulletinParams = $table->getParams();
     if (!CLimitsHelper::exceededGroupFileUpload($table->groupid)) {
         return false;
     }
     if (CLimitsLibrary::exceedDaily('files', $userId)) {
         return false;
     }
     if (COwnerHelper::isCommunityAdmin() || $groupModel->isAdmin($userId, $table->groupid) || $groupModel->isMember($userId, $table->groupid) && $bulletinParams->get('filepermission-member')) {
         return true;
     }
     return false;
 }
Exemple #2
0
 /**
  * Called during photo uploading.
  * @return type
  */
 public function upload()
 {
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     // If user is using a flash browser, their session might get reset when mod_security is around
     if ($my->id == 0) {
         $tokenId = $jinput->request->get('token', '', 'NONE');
         $userId = $jinput->request->get('uploaderid', '', 'NONE');
         $my = CFactory::getUserFromTokenId($tokenId, $userId);
         $session = JFactory::getSession();
         $session->set('user', $my);
     }
     if (CLimitsLibrary::exceedDaily('photos', $my->id)) {
         $this->_showUploadError(true, JText::_('COM_COMMUNITY_PHOTOS_LIMIT_PERDAY_REACHED'));
         return;
     }
     // We can't use blockUnregister here because practically, the CFactory::getUser() will return 0
     if ($my->id == 0) {
         return;
     }
     // Load up required models and properties
     $photos = JRequest::get('Files');
     $albumId = $jinput->request->get('albumid', '', 'INT');
     $album = $this->_getRequestUserAlbum($albumId);
     // Uploaded images count in this batch
     $batchCount = $jinput->request->get('batchcount', '', 'INT');
     $handler = $this->_getHandler($album);
     /* Do process for all photos */
     foreach ($photos as $imageFile) {
         /* Validating */
         $result = $this->_checkUploadedFile($imageFile, $album, $handler);
         if (!$result['photoTable']) {
             continue;
         }
         //assign the result of the array and assigned to the right variable
         $photoTable = $result['photoTable'];
         $storage = $result['storage'];
         $albumPath = $result['albumPath'];
         $hashFilename = $result['hashFilename'];
         $thumbPath = $result['thumbPath'];
         $originalPath = $result['originalPath'];
         $imgType = $result['imgType'];
         $isDefaultPhoto = $result['isDefaultPhoto'];
         // Remove the filename extension from the caption
         if (JString::strlen($photoTable->caption) > 4) {
             $photoTable->caption = JString::substr($photoTable->caption, 0, JString::strlen($photoTable->caption) - 4);
         }
         // @todo: configurable options?
         // Permission should follow album permission
         $photoTable->published = '1';
         $photoTable->permissions = $album->permissions;
         // Set the relative path.
         // @todo: configurable path?
         $storedPath = $handler->getStoredPath($storage, $album->id);
         $storedPath = $storedPath . '/' . $albumPath . $hashFilename . CImageHelper::getExtension($imageFile['type']);
         $photoTable->image = CString::str_ireplace(JPATH_ROOT . '/', '', $storedPath);
         $photoTable->thumbnail = CString::str_ireplace(JPATH_ROOT . '/', '', $thumbPath);
         //In joomla 1.6, CString::str_ireplace is not replacing the path properly. Need to do a check here
         if ($photoTable->image == $storedPath) {
             $photoTable->image = str_ireplace(JPATH_ROOT . '/', '', $storedPath);
         }
         if ($photoTable->thumbnail == $thumbPath) {
             $photoTable->thumbnail = str_ireplace(JPATH_ROOT . '/', '', $thumbPath);
         }
         //photo filesize, use sprintf to prevent return of unexpected results for large file.
         $photoTable->filesize = sprintf("%u", filesize($originalPath));
         // @rule: Set the proper ordering for the next photo upload.
         $photoTable->setOrdering();
         // Store the object
         $photoTable->store();
         // We need to see if we need to rotate this image, from EXIF orientation data
         // Only for jpeg image.
         if ($config->get('photos_auto_rotate') && $imgType == 'image/jpeg') {
             $this->_rotatePhoto($imageFile, $photoTable, $storedPath, $thumbPath);
         }
         // Trigger for onPhotoCreate
         $apps = CAppPlugins::getInstance();
         $apps->loadApplications();
         $params = array();
         $params[] = $photoTable;
         $apps->triggerEvent('onPhotoCreate', $params);
         // Set image as default if necessary
         // Load photo album table
         if ($isDefaultPhoto) {
             // Set the photo id
             $album->photoid = $photoTable->id;
             $album->store();
         }
         // @rule: Set first photo as default album cover if enabled
         if (!$isDefaultPhoto && $config->get('autoalbumcover')) {
             $photosModel = CFactory::getModel('Photos');
             $totalPhotos = $photosModel->getTotalPhotos($album->id);
             if ($totalPhotos <= 1) {
                 $album->photoid = $photoTable->id;
                 $album->store();
             }
         }
         // Set the upload count per session
         $session = JFactory::getSession();
         $uploadSessionCount = $session->get('album-' . $album->id . '-upload', 0);
         $uploadSessionCount++;
         $session->set('album-' . $album->id . '-upload', $uploadSessionCount);
         //add user points
         CUserPoints::assignPoint('photo.upload');
         // Photo upload was successfull, display a proper message
         $this->_showUploadError(false, JText::sprintf('COM_COMMUNITY_PHOTO_UPLOADED_SUCCESSFULLY', $photoTable->caption), $photoTable->getThumbURI(), $album->id, $photoTable->id);
     }
     $this->cacheClean(array(COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_ACTIVITIES));
     exit;
 }
Exemple #3
0
 /**
  * Called by status box to add new stream data
  *
  * @param type $message
  * @param type $attachment
  * @return type
  */
 public function ajaxStreamAdd($message, $attachment, $streamFilter = FALSE)
 {
     $streamHTML = '';
     // $attachment pending filter
     $cache = CFactory::getFastCache();
     $cache->clean(array('activities'));
     $my = CFactory::getUser();
     $userparams = $my->getParams();
     if (!COwnerHelper::isRegisteredUser()) {
         return $this->ajaxBlockUnregister();
     }
     //@rule: In case someone bypasses the status in the html, we enforce the character limit.
     $config = CFactory::getConfig();
     if (JString::strlen($message) > $config->get('statusmaxchar')) {
         $message = JHTML::_('string.truncate', $message, $config->get('statusmaxchar'));
     }
     $message = JString::trim($message);
     $objResponse = new JAXResponse();
     $rawMessage = $message;
     // @rule: Autolink hyperlinks
     // @rule: Autolink to users profile when message contains @username
     // $message     = CUserHelper::replaceAliasURL($message); // the processing is done on display side
     $emailMessage = CUserHelper::replaceAliasURL($rawMessage, true);
     // @rule: Spam checks
     if ($config->get('antispam_akismet_status')) {
         $filter = CSpamFilter::getFilter();
         $filter->setAuthor($my->getDisplayName());
         $filter->setMessage($message);
         $filter->setEmail($my->email);
         $filter->setURL(CRoute::_('index.php?option=com_community&view=profile&userid=' . $my->id));
         $filter->setType('message');
         $filter->setIP($_SERVER['REMOTE_ADDR']);
         if ($filter->isSpam()) {
             $objResponse->addAlert(JText::_('COM_COMMUNITY_STATUS_MARKED_SPAM'));
             return $objResponse->sendResponse();
         }
     }
     $attachment = json_decode($attachment, true);
     switch ($attachment['type']) {
         case 'message':
             //if (!empty($message)) {
             switch ($attachment['element']) {
                 case 'profile':
                     //only update user status if share messgage is on his profile
                     if (COwnerHelper::isMine($my->id, $attachment['target'])) {
                         //save the message
                         $status = $this->getModel('status');
                         /* If no privacy in attachment than we apply default: Public */
                         if (!isset($attachment['privacy'])) {
                             $attachment['privacy'] = COMMUNITY_STATUS_PRIVACY_PUBLIC;
                         }
                         $status->update($my->id, $rawMessage, $attachment['privacy']);
                         //set user status for current session.
                         $today = JFactory::getDate();
                         $message2 = empty($message) ? ' ' : $message;
                         $my->set('_status', $rawMessage);
                         $my->set('_posted_on', $today->toSql());
                         // Order of replacement
                         $order = array("\r\n", "\n", "\r");
                         $replace = '<br />';
                         // Processes \r\n's first so they aren't converted twice.
                         $messageDisplay = str_replace($order, $replace, $message);
                         $messageDisplay = CKses::kses($messageDisplay, CKses::allowed());
                         //update user status
                         $objResponse->addScriptCall("joms.jQuery('#profile-status span#profile-status-message').html('" . addslashes($messageDisplay) . "');");
                     }
                     //if actor posted something to target, the privacy should be under target's profile privacy settings
                     if (!COwnerHelper::isMine($my->id, $attachment['target']) && $attachment['target'] != '') {
                         $attachment['privacy'] = CFactory::getUser($attachment['target'])->getParams()->get('privacyProfileView');
                     }
                     //push to activity stream
                     $act = new stdClass();
                     $act->cmd = 'profile.status.update';
                     $act->actor = $my->id;
                     $act->target = $attachment['target'];
                     $act->title = $message;
                     $act->content = '';
                     $act->app = $attachment['element'];
                     $act->cid = $my->id;
                     $act->access = $attachment['privacy'];
                     $act->comment_id = CActivities::COMMENT_SELF;
                     $act->comment_type = 'profile.status';
                     $act->like_id = CActivities::LIKE_SELF;
                     $act->like_type = 'profile.status';
                     $activityParams = new CParameter('');
                     /* Save cords if exists */
                     if (isset($attachment['location'])) {
                         /* Save geo name */
                         $act->location = $attachment['location'][0];
                         $act->latitude = $attachment['location'][1];
                         $act->longitude = $attachment['location'][2];
                     }
                     $headMeta = new CParameter('');
                     if (isset($attachment['fetch'])) {
                         $headMeta->set('title', $attachment['fetch'][2]);
                         $headMeta->set('description', $attachment['fetch'][3]);
                         $headMeta->set('image', $attachment['fetch'][1]);
                         $headMeta->set('link', $attachment['fetch'][0]);
                         //do checking if this is a video link
                         $video = JTable::getInstance('Video', 'CTable');
                         $isValidVideo = @$video->init($attachment['fetch'][0]);
                         if ($isValidVideo) {
                             $headMeta->set('type', 'video');
                             $headMeta->set('video_provider', $video->type);
                             $headMeta->set('video_id', $video->getVideoId());
                             $headMeta->set('height', $video->getHeight());
                             $headMeta->set('width', $video->getWidth());
                         }
                         $activityParams->set('headMetas', $headMeta->toString());
                     }
                     //Store mood in paramm
                     if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') {
                         $activityParams->set('mood', $attachment['mood']);
                     }
                     $act->params = $activityParams->toString();
                     //CActivityStream::add($act);
                     //check if the user points is enabled
                     if (CUserPoints::assignPoint('profile.status.update')) {
                         /* Let use our new CApiStream */
                         $activityData = CApiActivities::add($act);
                         CTags::add($activityData);
                         $recipient = CFactory::getUser($attachment['target']);
                         $params = new CParameter('');
                         $params->set('actorName', $my->getDisplayName());
                         $params->set('recipientName', $recipient->getDisplayName());
                         $params->set('url', CUrlHelper::userLink($act->target, false));
                         $params->set('message', $message);
                         $params->set('stream', JText::_('COM_COMMUNITY_SINGULAR_STREAM'));
                         $params->set('stream_url', CRoute::_('index.php?option=com_community&view=profile&userid=' . $activityData->actor . '&actid=' . $activityData->id));
                         CNotificationLibrary::add('profile_status_update', $my->id, $attachment['target'], JText::sprintf('COM_COMMUNITY_FRIEND_WALL_POST', $my->getDisplayName()), '', 'wall.post', $params);
                         //email and add notification if user are tagged
                         CUserHelper::parseTaggedUserNotification($message, $my, $activityData, array('type' => 'post-comment'));
                     }
                     break;
                     // Message posted from Group page
                 // Message posted from Group page
                 case 'groups':
                     //
                     $groupLib = new CGroups();
                     $group = JTable::getInstance('Group', 'CTable');
                     $group->load($attachment['target']);
                     // Permission check, only site admin and those who has
                     // mark their attendance can post message
                     if (!COwnerHelper::isCommunityAdmin() && !$group->isMember($my->id) && $config->get('lockgroupwalls')) {
                         $objResponse->addScriptCall("alert('permission denied');");
                         return $objResponse->sendResponse();
                     }
                     $act = new stdClass();
                     $act->cmd = 'groups.wall';
                     $act->actor = $my->id;
                     $act->target = 0;
                     $act->title = $message;
                     $act->content = '';
                     $act->app = 'groups.wall';
                     $act->cid = $attachment['target'];
                     $act->groupid = $group->id;
                     $act->group_access = $group->approvals;
                     $act->eventid = 0;
                     $act->access = 0;
                     $act->comment_id = CActivities::COMMENT_SELF;
                     $act->comment_type = 'groups.wall';
                     $act->like_id = CActivities::LIKE_SELF;
                     $act->like_type = 'groups.wall';
                     $activityParams = new CParameter('');
                     /* Save cords if exists */
                     if (isset($attachment['location'])) {
                         /* Save geo name */
                         $act->location = $attachment['location'][0];
                         $act->latitude = $attachment['location'][1];
                         $act->longitude = $attachment['location'][2];
                     }
                     $headMeta = new CParameter('');
                     if (isset($attachment['fetch'])) {
                         $headMeta->set('title', $attachment['fetch'][2]);
                         $headMeta->set('description', $attachment['fetch'][3]);
                         $headMeta->set('image', $attachment['fetch'][1]);
                         $headMeta->set('link', $attachment['fetch'][0]);
                         //do checking if this is a video link
                         $video = JTable::getInstance('Video', 'CTable');
                         $isValidVideo = @$video->init($attachment['fetch'][0]);
                         if ($isValidVideo) {
                             $headMeta->set('type', 'video');
                             $headMeta->set('video_provider', $video->type);
                             $headMeta->set('video_id', $video->getVideoId());
                             $headMeta->set('height', $video->getHeight());
                             $headMeta->set('width', $video->getWidth());
                         }
                         $activityParams->set('headMetas', $headMeta->toString());
                     }
                     //Store mood in paramm
                     if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') {
                         $activityParams->set('mood', $attachment['mood']);
                     }
                     $act->params = $activityParams->toString();
                     $activityData = CApiActivities::add($act);
                     CTags::add($activityData);
                     CUserPoints::assignPoint('group.wall.create');
                     $recipient = CFactory::getUser($attachment['target']);
                     $params = new CParameter('');
                     $params->set('message', $emailMessage);
                     $params->set('group', $group->name);
                     $params->set('group_url', 'index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id);
                     $params->set('url', CRoute::getExternalURL('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id, false));
                     //Get group member emails
                     $model = CFactory::getModel('Groups');
                     $members = $model->getMembers($attachment['target'], null, true, false, true);
                     $membersArray = array();
                     if (!is_null($members)) {
                         foreach ($members as $row) {
                             if ($my->id != $row->id) {
                                 $membersArray[] = $row->id;
                             }
                         }
                     }
                     $groupParams = new CParameter($group->params);
                     if ($groupParams->get('wallnotification')) {
                         CNotificationLibrary::add('groups_wall_create', $my->id, $membersArray, JText::sprintf('COM_COMMUNITY_NEW_WALL_POST_NOTIFICATION_EMAIL_SUBJECT', $my->getDisplayName(), $group->name), '', 'groups.post', $params);
                     }
                     //@since 4.1 when a there is a new post in group, dump the data into group stats
                     $statsModel = CFactory::getModel('stats');
                     $statsModel->addGroupStats($group->id, 'post');
                     // Add custom stream
                     // Reload the stream with new stream data
                     $streamHTML = $groupLib->getStreamHTML($group, array('showLatestActivityOnTop' => true));
                     break;
                     // Message posted from Event page
                 // Message posted from Event page
                 case 'events':
                     $eventLib = new CEvents();
                     $event = JTable::getInstance('Event', 'CTable');
                     $event->load($attachment['target']);
                     // Permission check, only site admin and those who has
                     // mark their attendance can post message
                     if (!COwnerHelper::isCommunityAdmin() && !$event->isMember($my->id) && $config->get('lockeventwalls')) {
                         $objResponse->addScriptCall("alert('permission denied');");
                         return $objResponse->sendResponse();
                     }
                     // If this is a group event, set the group object
                     $groupid = $event->type == 'group' ? $event->contentid : 0;
                     //
                     $groupLib = new CGroups();
                     $group = JTable::getInstance('Group', 'CTable');
                     $group->load($groupid);
                     $act = new stdClass();
                     $act->cmd = 'events.wall';
                     $act->actor = $my->id;
                     $act->target = 0;
                     $act->title = $message;
                     $act->content = '';
                     $act->app = 'events.wall';
                     $act->cid = $attachment['target'];
                     $act->groupid = $event->type == 'group' ? $event->contentid : 0;
                     $act->group_access = $group->approvals;
                     $act->eventid = $event->id;
                     $act->event_access = $event->permission;
                     $act->access = 0;
                     $act->comment_id = CActivities::COMMENT_SELF;
                     $act->comment_type = 'events.wall';
                     $act->like_id = CActivities::LIKE_SELF;
                     $act->like_type = 'events.wall';
                     $activityParams = new CParameter('');
                     /* Save cords if exists */
                     if (isset($attachment['location'])) {
                         /* Save geo name */
                         $act->location = $attachment['location'][0];
                         $act->latitude = $attachment['location'][1];
                         $act->longitude = $attachment['location'][2];
                     }
                     $headMeta = new CParameter('');
                     if (isset($attachment['fetch'])) {
                         $headMeta->set('title', $attachment['fetch'][2]);
                         $headMeta->set('description', $attachment['fetch'][3]);
                         $headMeta->set('image', $attachment['fetch'][1]);
                         $headMeta->set('link', $attachment['fetch'][0]);
                         //do checking if this is a video link
                         $video = JTable::getInstance('Video', 'CTable');
                         $isValidVideo = @$video->init($attachment['fetch'][0]);
                         if ($isValidVideo) {
                             $headMeta->set('type', 'video');
                             $headMeta->set('video_provider', $video->type);
                             $headMeta->set('video_id', $video->getVideoId());
                             $headMeta->set('height', $video->getHeight());
                             $headMeta->set('width', $video->getWidth());
                         }
                         $activityParams->set('headMetas', $headMeta->toString());
                     }
                     //Store mood in paramm
                     if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') {
                         $activityParams->set('mood', $attachment['mood']);
                     }
                     $act->params = $activityParams->toString();
                     $activityData = CApiActivities::add($act);
                     CTags::add($activityData);
                     // add points
                     CUserPoints::assignPoint('event.wall.create');
                     $params = new CParameter('');
                     $params->set('message', $emailMessage);
                     $params->set('event', $event->title);
                     $params->set('event_url', 'index.php?option=com_community&view=events&task=viewevent&eventid=' . $event->id);
                     $params->set('url', CRoute::getExternalURL('index.php?option=com_community&view=events&task=viewevent&eventid=' . $event->id, false));
                     //Get event member emails
                     $members = $event->getMembers(COMMUNITY_EVENT_STATUS_ATTEND, 12, CC_RANDOMIZE);
                     $membersArray = array();
                     if (!is_null($members)) {
                         foreach ($members as $row) {
                             if ($my->id != $row->id) {
                                 $membersArray[] = $row->id;
                             }
                         }
                     }
                     CNotificationLibrary::add('events_wall_create', $my->id, $membersArray, JText::sprintf('COM_COMMUNITY_NEW_WALL_POST_NOTIFICATION_EMAIL_SUBJECT_EVENTS', $my->getDisplayName(), $event->title), '', 'events.post', $params);
                     //@since 4.1 when a there is a new post in event, dump the data into event stats
                     $statsModel = CFactory::getModel('stats');
                     $statsModel->addEventStats($event->id, 'post');
                     // Reload the stream with new stream data
                     $streamHTML = $eventLib->getStreamHTML($event, array('showLatestActivityOnTop' => true));
                     break;
             }
             $objResponse->addScriptCall('__callback', '');
             // /}
             break;
         case 'photo':
             switch ($attachment['element']) {
                 case 'profile':
                     $photoIds = $attachment['id'];
                     //use User Preference for Privacy
                     //$privacy = $userparams->get('privacyPhotoView'); //$privacy = $attachment['privacy'];
                     $photo = JTable::getInstance('Photo', 'CTable');
                     if (!isset($photoIds[0]) || $photoIds[0] <= 0) {
                         //$objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_PHOTO_UPLOADED_SUCCESSFULLY', $photo->caption));
                         exit;
                     }
                     //always get album id from the photo itself, do not let it assign by params from user post data
                     $photoModel = CFactory::getModel('photos');
                     $photo = $photoModel->getPhoto($photoIds[0]);
                     /* OK ! If album_id is not provided than we use album id from photo ( it should be default album id ) */
                     $albumid = isset($attachment['album_id']) ? $attachment['album_id'] : $photo->albumid;
                     $album = JTable::getInstance('Album', 'CTable');
                     $album->load($albumid);
                     $privacy = $album->permissions;
                     //limit checking
                     //                        $photoModel = CFactory::getModel( 'photos' );
                     //                        $config       = CFactory::getConfig();
                     //                        $total        = $photoModel->getTotalToday( $my->id );
                     //                        $max      = $config->getInt( 'limit_photo_perday' );
                     //                        $remainingUploadCount = $max - $total;
                     $params = array();
                     foreach ($photoIds as $key => $photoId) {
                         if (CLimitsLibrary::exceedDaily('photos')) {
                             unset($photoIds[$key]);
                             continue;
                         }
                         $photo->load($photoId);
                         $photo->permissions = $privacy;
                         $photo->published = 1;
                         $photo->status = 'ready';
                         $photo->albumid = $albumid;
                         /* We must update this photo into correct album id */
                         $photo->store();
                         $params[] = clone $photo;
                     }
                     if ($config->get('autoalbumcover') && !$album->photoid) {
                         $album->photoid = $photoIds[0];
                         $album->store();
                     }
                     // Break if no photo added, which is likely because of daily limit.
                     if (count($photoIds) < 1) {
                         $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_PHOTO_UPLOAD_LIMIT_EXCEEDED'));
                         return $objResponse->sendResponse();
                     }
                     // Trigger onPhotoCreate
                     //
                     $apps = CAppPlugins::getInstance();
                     $apps->loadApplications();
                     $apps->triggerEvent('onPhotoCreate', array($params));
                     $act = new stdClass();
                     $act->cmd = 'photo.upload';
                     $act->actor = $my->id;
                     $act->access = $privacy;
                     //$attachment['privacy'];
                     $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target'];
                     $act->title = $message;
                     $act->content = '';
                     // Generated automatically by stream. No need to add anything
                     $act->app = 'photos';
                     $act->cid = $albumid;
                     $act->location = $album->location;
                     /* Comment and like for individual photo upload is linked
                      * to the photos itsel
                      */
                     $act->comment_id = $photo->id;
                     $act->comment_type = 'photos';
                     $act->like_id = $photo->id;
                     $act->like_type = 'photo';
                     $albumUrl = 'index.php?option=com_community&view=photos&task=album&albumid=' . $album->id . '&userid=' . $my->id;
                     $albumUrl = CRoute::_($albumUrl);
                     $photoUrl = 'index.php?option=com_community&view=photos&task=photo&albumid=' . $album->id . '&userid=' . $photo->creator . '&photoid=' . $photo->id;
                     $photoUrl = CRoute::_($photoUrl);
                     $params = new CParameter('');
                     $params->set('multiUrl', $albumUrl);
                     $params->set('photoid', $photo->id);
                     $params->set('action', 'upload');
                     $params->set('stream', '1');
                     $params->set('photo_url', $photoUrl);
                     $params->set('style', COMMUNITY_STREAM_STYLE);
                     $params->set('photosId', implode(',', $photoIds));
                     if (count($photoIds > 1)) {
                         $params->set('count', count($photoIds));
                         $params->set('batchcount', count($photoIds));
                     }
                     //Store mood in param
                     if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') {
                         $params->set('mood', $attachment['mood']);
                     }
                     // Add activity logging
                     // CActivityStream::remove($act->app, $act->cid);
                     $activityData = CActivityStream::add($act, $params->toString());
                     // Add user points
                     CUserPoints::assignPoint('photo.upload');
                     //add a notification to the target user if someone posted photos on target's profile
                     if ($my->id != $attachment['target']) {
                         $recipient = CFactory::getUser($attachment['target']);
                         $params = new CParameter('');
                         $params->set('actorName', $my->getDisplayName());
                         $params->set('recipientName', $recipient->getDisplayName());
                         $params->set('url', CUrlHelper::userLink($act->target, false));
                         $params->set('message', $message);
                         $params->set('stream', JText::_('COM_COMMUNITY_SINGULAR_STREAM'));
                         $params->set('stream_url', CRoute::_('index.php?option=com_community&view=profile&userid=' . $activityData->actor . '&actid=' . $activityData->id));
                         CNotificationLibrary::add('profile_status_update', $my->id, $attachment['target'], JText::sprintf('COM_COMMUNITY_NOTIFICATION_STREAM_PHOTO_POST', count($photoIds)), '', 'wall.post', $params);
                     }
                     //email and add notification if user are tagged
                     CUserHelper::parseTaggedUserNotification($message, $my, $activityData, array('type' => 'post-comment'));
                     $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_PHOTO_UPLOADED_SUCCESSFULLY', $photo->caption));
                     break;
                 case 'events':
                     $event = JTable::getInstance('Event', 'CTable');
                     $event->load($attachment['target']);
                     $privacy = 0;
                     //if this is a group event, we need to follow the group privacy
                     if ($event->type == 'group' && $event->contentid) {
                         $group = JTable::getInstance('Group', 'CTable');
                         $group->load(${$event}->contentid);
                         $privacy = $group->approvals ? PRIVACY_GROUP_PRIVATE_ITEM : 0;
                     }
                     $photoIds = $attachment['id'];
                     $photo = JTable::getInstance('Photo', 'CTable');
                     $photo->load($photoIds[0]);
                     $albumid = isset($attachment['album_id']) ? $attachment['album_id'] : $photo->albumid;
                     $album = JTable::getInstance('Album', 'CTable');
                     $album->load($albumid);
                     $params = array();
                     foreach ($photoIds as $photoId) {
                         $photo->load($photoId);
                         $photo->caption = $message;
                         $photo->permissions = $privacy;
                         $photo->published = 1;
                         $photo->status = 'ready';
                         $photo->albumid = $albumid;
                         $photo->store();
                         $params[] = clone $photo;
                     }
                     // Trigger onPhotoCreate
                     //
                     $apps = CAppPlugins::getInstance();
                     $apps->loadApplications();
                     $apps->triggerEvent('onPhotoCreate', array($params));
                     $act = new stdClass();
                     $act->cmd = 'photo.upload';
                     $act->actor = $my->id;
                     $act->access = $privacy;
                     $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target'];
                     $act->title = $message;
                     //JText::sprintf('COM_COMMUNITY_ACTIVITIES_UPLOAD_PHOTO' , '{photo_url}', $album->name );
                     $act->content = '';
                     // Generated automatically by stream. No need to add anything
                     $act->app = 'photos';
                     $act->cid = $album->id;
                     $act->location = $album->location;
                     $act->eventid = $event->id;
                     $act->group_access = $privacy;
                     // just in case this event belongs to a group
                     //$act->access      = $attachment['privacy'];
                     /* Comment and like for individual photo upload is linked
                      * to the photos itsel
                      */
                     $act->comment_id = $photo->id;
                     $act->comment_type = 'photos';
                     $act->like_id = $photo->id;
                     $act->like_type = 'photo';
                     $albumUrl = 'index.php?option=com_community&view=photos&task=album&albumid=' . $album->id . '&userid=' . $my->id;
                     $albumUrl = CRoute::_($albumUrl);
                     $photoUrl = 'index.php?option=com_community&view=photos&task=photo&albumid=' . $album->id . '&userid=' . $photo->creator . '&photoid=' . $photo->id;
                     $photoUrl = CRoute::_($photoUrl);
                     $params = new CParameter('');
                     $params->set('multiUrl', $albumUrl);
                     $params->set('photoid', $photo->id);
                     $params->set('action', 'upload');
                     $params->set('stream', '1');
                     // this photo uploaded from status stream
                     $params->set('photo_url', $photoUrl);
                     $params->set('style', COMMUNITY_STREAM_STYLE);
                     // set stream style
                     $params->set('photosId', implode(',', $photoIds));
                     // Add activity logging
                     if (count($photoIds > 1)) {
                         $params->set('count', count($photoIds));
                         $params->set('batchcount', count($photoIds));
                     }
                     //Store mood in paramm
                     if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') {
                         $params->set('mood', $attachment['mood']);
                     }
                     // CActivityStream::remove($act->app, $act->cid);
                     $activityData = CActivityStream::add($act, $params->toString());
                     // Add user points
                     CUserPoints::assignPoint('photo.upload');
                     // Reload the stream with new stream data
                     $eventLib = new CEvents();
                     $event = JTable::getInstance('Event', 'CTable');
                     $event->load($attachment['target']);
                     $streamHTML = $eventLib->getStreamHTML($event, array('showLatestActivityOnTop' => true));
                     $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_PHOTO_UPLOADED_SUCCESSFULLY', $photo->caption));
                     break;
                 case 'groups':
                     //
                     $groupLib = new CGroups();
                     $group = JTable::getInstance('Group', 'CTable');
                     $group->load($attachment['target']);
                     $photoIds = $attachment['id'];
                     $privacy = $group->approvals ? PRIVACY_GROUP_PRIVATE_ITEM : 0;
                     $photo = JTable::getInstance('Photo', 'CTable');
                     $photo->load($photoIds[0]);
                     $albumid = isset($attachment['album_id']) ? $attachment['album_id'] : $photo->albumid;
                     $album = JTable::getInstance('Album', 'CTable');
                     $album->load($albumid);
                     $params = array();
                     foreach ($photoIds as $photoId) {
                         $photo->load($photoId);
                         $photo->caption = $message;
                         $photo->permissions = $privacy;
                         $photo->published = 1;
                         $photo->status = 'ready';
                         $photo->albumid = $albumid;
                         $photo->store();
                         $params[] = clone $photo;
                     }
                     // Trigger onPhotoCreate
                     //
                     $apps = CAppPlugins::getInstance();
                     $apps->loadApplications();
                     $apps->triggerEvent('onPhotoCreate', array($params));
                     $act = new stdClass();
                     $act->cmd = 'photo.upload';
                     $act->actor = $my->id;
                     $act->access = $privacy;
                     $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target'];
                     $act->title = $message;
                     //JText::sprintf('COM_COMMUNITY_ACTIVITIES_UPLOAD_PHOTO' , '{photo_url}', $album->name );
                     $act->content = '';
                     // Generated automatically by stream. No need to add anything
                     $act->app = 'photos';
                     $act->cid = $album->id;
                     $act->location = $album->location;
                     $act->groupid = $group->id;
                     $act->group_access = $group->approvals;
                     $act->eventid = 0;
                     //$act->access      = $attachment['privacy'];
                     /* Comment and like for individual photo upload is linked
                      * to the photos itsel
                      */
                     $act->comment_id = $photo->id;
                     $act->comment_type = 'photos';
                     $act->like_id = $photo->id;
                     $act->like_type = 'photo';
                     $albumUrl = 'index.php?option=com_community&view=photos&task=album&albumid=' . $album->id . '&userid=' . $my->id;
                     $albumUrl = CRoute::_($albumUrl);
                     $photoUrl = 'index.php?option=com_community&view=photos&task=photo&albumid=' . $album->id . '&userid=' . $photo->creator . '&photoid=' . $photo->id;
                     $photoUrl = CRoute::_($photoUrl);
                     $params = new CParameter('');
                     $params->set('multiUrl', $albumUrl);
                     $params->set('photoid', $photo->id);
                     $params->set('action', 'upload');
                     $params->set('stream', '1');
                     // this photo uploaded from status stream
                     $params->set('photo_url', $photoUrl);
                     $params->set('style', COMMUNITY_STREAM_STYLE);
                     // set stream style
                     $params->set('photosId', implode(',', $photoIds));
                     // Add activity logging
                     if (count($photoIds > 1)) {
                         $params->set('count', count($photoIds));
                         $params->set('batchcount', count($photoIds));
                     }
                     //Store mood in paramm
                     if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') {
                         $params->set('mood', $attachment['mood']);
                     }
                     // CActivityStream::remove($act->app, $act->cid);
                     $activityData = CActivityStream::add($act, $params->toString());
                     // Add user points
                     CUserPoints::assignPoint('photo.upload');
                     // Reload the stream with new stream data
                     $streamHTML = $groupLib->getStreamHTML($group, array('showLatestActivityOnTop' => true));
                     $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_PHOTO_UPLOADED_SUCCESSFULLY', $photo->caption));
                     break;
                     dafault:
                     return;
             }
             break;
         case 'video':
             switch ($attachment['element']) {
                 case 'profile':
                     // attachment id
                     $fetch = $attachment['fetch'];
                     $cid = $fetch[0];
                     $privacy = isset($attachment['privacy']) ? $attachment['privacy'] : COMMUNITY_STATUS_PRIVACY_PUBLIC;
                     $video = JTable::getInstance('Video', 'CTable');
                     $video->load($cid);
                     $video->set('creator_type', VIDEO_USER_TYPE);
                     $video->set('status', 'ready');
                     $video->set('permissions', $privacy);
                     $video->set('title', $fetch[3]);
                     $video->set('description', $fetch[4]);
                     $video->set('category_id', $fetch[5]);
                     /* Save cords if exists */
                     if (isset($attachment['location'])) {
                         $video->set('location', $attachment['location'][0]);
                         $video->set('latitude', $attachment['location'][1]);
                         $video->set('longitude', $attachment['location'][2]);
                     }
                     // Add activity logging
                     $url = $video->getViewUri(false);
                     $act = new stdClass();
                     $act->cmd = 'videos.linking';
                     $act->actor = $my->id;
                     $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target'];
                     $act->access = $privacy;
                     //filter empty message
                     $act->title = $message;
                     $act->app = 'videos.linking';
                     $act->content = '';
                     $act->cid = $video->id;
                     $act->location = $video->location;
                     /* Save cords if exists */
                     if (isset($attachment['location'])) {
                         /* Save geo name */
                         $act->location = $attachment['location'][0];
                         $act->latitude = $attachment['location'][1];
                         $act->longitude = $attachment['location'][2];
                     }
                     $act->comment_id = $video->id;
                     $act->comment_type = 'videos.linking';
                     $act->like_id = $video->id;
                     $act->like_type = 'videos.linking';
                     $params = new CParameter('');
                     $params->set('video_url', $url);
                     $params->set('style', COMMUNITY_STREAM_STYLE);
                     // set stream style
                     //Store mood in paramm
                     if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') {
                         $params->set('mood', $attachment['mood']);
                     }
                     //
                     $activityData = CActivityStream::add($act, $params->toString());
                     //this video must be public because it's posted on someone else's profile
                     if ($my->id != $attachment['target']) {
                         $video->set('permissions', COMMUNITY_STATUS_PRIVACY_PUBLIC);
                         $params = new CParameter();
                         $params->set('activity_id', $activityData->id);
                         // activity id is used to remove the activity if someone deleted this video
                         $params->set('target_id', $attachment['target']);
                         $video->params = $params->toString();
                         //also send a notification to the user
                         $recipient = CFactory::getUser($attachment['target']);
                         $params = new CParameter('');
                         $params->set('actorName', $my->getDisplayName());
                         $params->set('recipientName', $recipient->getDisplayName());
                         $params->set('url', CUrlHelper::userLink($act->target, false));
                         $params->set('message', $message);
                         $params->set('stream', JText::_('COM_COMMUNITY_SINGULAR_STREAM'));
                         $params->set('stream_url', CRoute::_('index.php?option=com_community&view=profile&userid=' . $activityData->actor . '&actid=' . $activityData->id));
                         CNotificationLibrary::add('profile_status_update', $my->id, $attachment['target'], JText::_('COM_COMMUNITY_NOTIFICATION_STREAM_VIDEO_POST'), '', 'wall.post', $params);
                     }
                     $video->store();
                     // @rule: Add point when user adds a new video link
                     //
                     CUserPoints::assignPoint('video.add', $video->creator);
                     //email and add notification if user are tagged
                     CUserHelper::parseTaggedUserNotification($message, $my, $activityData, array('type' => 'post-comment'));
                     // Trigger for onVideoCreate
                     //
                     $apps = CAppPlugins::getInstance();
                     $apps->loadApplications();
                     $params = array();
                     $params[] = $video;
                     $apps->triggerEvent('onVideoCreate', $params);
                     $this->cacheClean(array(COMMUNITY_CACHE_TAG_VIDEOS, COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_FEATURED, COMMUNITY_CACHE_TAG_VIDEOS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES));
                     $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_VIDEOS_UPLOAD_SUCCESS', $video->title));
                     break;
                 case 'groups':
                     // attachment id
                     $fetch = $attachment['fetch'];
                     $cid = $fetch[0];
                     $privacy = 0;
                     //$attachment['privacy'];
                     $video = JTable::getInstance('Video', 'CTable');
                     $video->load($cid);
                     $video->set('status', 'ready');
                     $video->set('groupid', $attachment['target']);
                     $video->set('permissions', $privacy);
                     $video->set('creator_type', VIDEO_GROUP_TYPE);
                     $video->set('title', $fetch[3]);
                     $video->set('description', $fetch[4]);
                     $video->set('category_id', $fetch[5]);
                     /* Save cords if exists */
                     if (isset($attachment['location'])) {
                         $video->set('location', $attachment['location'][0]);
                         $video->set('latitude', $attachment['location'][1]);
                         $video->set('longitude', $attachment['location'][2]);
                     }
                     $video->store();
                     //
                     $groupLib = new CGroups();
                     $group = JTable::getInstance('Group', 'CTable');
                     $group->load($attachment['target']);
                     // Add activity logging
                     $url = $video->getViewUri(false);
                     $act = new stdClass();
                     $act->cmd = 'videos.linking';
                     $act->actor = $my->id;
                     $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target'];
                     $act->access = $privacy;
                     //filter empty message
                     $act->title = $message;
                     $act->app = 'videos';
                     $act->content = '';
                     $act->cid = $video->id;
                     $act->groupid = $video->groupid;
                     $act->group_access = $group->approvals;
                     $act->location = $video->location;
                     /* Save cords if exists */
                     if (isset($attachment['location'])) {
                         /* Save geo name */
                         $act->location = $attachment['location'][0];
                         $act->latitude = $attachment['location'][1];
                         $act->longitude = $attachment['location'][2];
                     }
                     $act->comment_id = $video->id;
                     $act->comment_type = 'videos';
                     $act->like_id = $video->id;
                     $act->like_type = 'videos';
                     $params = new CParameter('');
                     $params->set('video_url', $url);
                     $params->set('style', COMMUNITY_STREAM_STYLE);
                     // set stream style
                     //Store mood in paramm
                     if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') {
                         $params->set('mood', $attachment['mood']);
                     }
                     $activityData = CActivityStream::add($act, $params->toString());
                     // @rule: Add point when user adds a new video link
                     CUserPoints::assignPoint('video.add', $video->creator);
                     // Trigger for onVideoCreate
                     $apps = CAppPlugins::getInstance();
                     $apps->loadApplications();
                     $params = array();
                     $params[] = $video;
                     $apps->triggerEvent('onVideoCreate', $params);
                     $this->cacheClean(array(COMMUNITY_CACHE_TAG_VIDEOS, COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_FEATURED, COMMUNITY_CACHE_TAG_VIDEOS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES));
                     $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_VIDEOS_UPLOAD_SUCCESS', $video->title));
                     // Reload the stream with new stream data
                     $streamHTML = $groupLib->getStreamHTML($group, array('showLatestActivityOnTop' => true));
                     break;
                 case 'events':
                     //event videos
                     $fetch = $attachment['fetch'];
                     $cid = $fetch[0];
                     $privacy = 0;
                     //$attachment['privacy'];
                     $video = JTable::getInstance('Video', 'CTable');
                     $video->load($cid);
                     $video->set('status', 'ready');
                     $video->set('eventid', $attachment['target']);
                     $video->set('permissions', $privacy);
                     $video->set('creator_type', VIDEO_EVENT_TYPE);
                     $video->set('title', $fetch[3]);
                     $video->set('description', $fetch[4]);
                     $video->set('category_id', $fetch[5]);
                     /* Save cords if exists */
                     if (isset($attachment['location'])) {
                         $video->set('location', $attachment['location'][0]);
                         $video->set('latitude', $attachment['location'][1]);
                         $video->set('longitude', $attachment['location'][2]);
                     }
                     $video->store();
                     //
                     $eventLib = new CEvents();
                     $event = JTable::getInstance('Event', 'CTable');
                     $event->load($attachment['target']);
                     $group = new stdClass();
                     if ($event->type == 'group' && $event->contentid) {
                         // check if this a group event, and follow the permission
                         $group = JTable::getInstance('Group', 'CTable');
                         $group->load($event->contentid);
                     }
                     // Add activity logging
                     $url = $video->getViewUri(false);
                     $act = new stdClass();
                     $act->cmd = 'videos.linking';
                     $act->actor = $my->id;
                     $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target'];
                     $act->access = $privacy;
                     //filter empty message
                     $act->title = $message;
                     $act->app = 'videos';
                     $act->content = '';
                     $act->cid = $video->id;
                     $act->groupid = 0;
                     $act->group_access = isset($group->approvals) ? $group->approvals : 0;
                     // if this is a group event
                     $act->location = $video->location;
                     /* Save cords if exists */
                     if (isset($attachment['location'])) {
                         /* Save geo name */
                         $act->location = $attachment['location'][0];
                         $act->latitude = $attachment['location'][1];
                         $act->longitude = $attachment['location'][2];
                     }
                     $act->eventid = $event->id;
                     $act->comment_id = $video->id;
                     $act->comment_type = 'videos';
                     $act->like_id = $video->id;
                     $act->like_type = 'videos';
                     $params = new CParameter('');
                     $params->set('video_url', $url);
                     $params->set('style', COMMUNITY_STREAM_STYLE);
                     // set stream style
                     //Store mood in paramm
                     if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') {
                         $params->set('mood', $attachment['mood']);
                     }
                     $activityData = CActivityStream::add($act, $params->toString());
                     // @rule: Add point when user adds a new video link
                     CUserPoints::assignPoint('video.add', $video->creator);
                     // Trigger for onVideoCreate
                     $apps = CAppPlugins::getInstance();
                     $apps->loadApplications();
                     $params = array();
                     $params[] = $video;
                     $apps->triggerEvent('onVideoCreate', $params);
                     $this->cacheClean(array(COMMUNITY_CACHE_TAG_VIDEOS, COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_FEATURED, COMMUNITY_CACHE_TAG_VIDEOS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES));
                     $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_VIDEOS_UPLOAD_SUCCESS', $video->title));
                     // Reload the stream with new stream data
                     $streamHTML = $eventLib->getStreamHTML($event, array('showLatestActivityOnTop' => true));
                     break;
                 default:
                     return;
             }
             break;
         case 'event':
             switch ($attachment['element']) {
                 case 'profile':
                     require_once COMMUNITY_COM_PATH . '/controllers/events.php';
                     $eventController = new CommunityEventsController();
                     // Assign default values where necessary
                     $attachment['description'] = $message;
                     $attachment['ticket'] = 0;
                     $attachment['offset'] = 0;
                     $event = $eventController->ajaxCreate($attachment, $objResponse);
                     $objResponse->addScriptCall('window.location="' . $event->getLink() . '";');
                     if (CFactory::getConfig()->get('event_moderation')) {
                         $objResponse->addAlert(JText::sprintf('COM_COMMUNITY_EVENTS_MODERATION_NOTICE', $event->title));
                     }
                     break;
                 case 'groups':
                     require_once COMMUNITY_COM_PATH . '/controllers/events.php';
                     $eventController = new CommunityEventsController();
                     //
                     $groupLib = new CGroups();
                     $group = JTable::getInstance('Group', 'CTable');
                     $group->load($attachment['target']);
                     // Assign default values where necessary
                     $attachment['description'] = $message;
                     $attachment['ticket'] = 0;
                     $attachment['offset'] = 0;
                     $event = $eventController->ajaxCreate($attachment, $objResponse);
                     CEvents::addGroupNotification($event);
                     $objResponse->addScriptCall('window.location="' . $event->getLink() . '";');
                     // Reload the stream with new stream data
                     $streamHTML = $groupLib->getStreamHTML($group, array('showLatestActivityOnTop' => true));
                     if (CFactory::getConfig()->get('event_moderation')) {
                         $objResponse->addAlert(JText::sprintf('COM_COMMUNITY_EVENTS_MODERATION_NOTICE', $event->title));
                     }
                     break;
             }
             break;
         case 'link':
             break;
     }
     //no matter what kind of message it is, always filter the hashtag if there's any
     if (!empty($act->title) && isset($activityData->id) && $activityData->id) {
         //use model to check if this has a tag in it and insert into the table if possible
         $hashtags = CContentHelper::getHashTags($act->title);
         if (count($hashtags)) {
             //$hashTag
             $hashtagModel = CFactory::getModel('hashtags');
             foreach ($hashtags as $tag) {
                 $hashtagModel->addActivityHashtag($tag, $activityData->id);
             }
         }
     }
     // Frontpage filter
     if ($streamFilter != false) {
         $streamFilter = json_decode($streamFilter);
         $filter = $streamFilter->filter;
         $value = $streamFilter->value;
         $extra = false;
         // Append added data to the list.
         if (isset($activityData) && $activityData->id) {
             $model = CFactory::getModel('Activities');
             $extra = $model->getActivity($activityData->id);
         }
         switch ($filter) {
             case 'privacy':
                 if ($value == 'me-and-friends' && $my->id != 0) {
                     $streamHTML = CActivities::getActivitiesByFilter('active-user-and-friends', $my->id, 'frontpage', true, array(), $extra);
                 } else {
                     $streamHTML = CActivities::getActivitiesByFilter('all', $my->id, 'frontpage', true, array(), $extra);
                 }
                 break;
             case 'apps':
                 $streamHTML = CActivities::getActivitiesByFilter('all', $my->id, 'frontpage', true, array('apps' => array($value)), $extra);
                 break;
             case 'hashtag':
                 $streamHTML = CActivities::getActivitiesByFilter('all', $my->id, 'frontpage', true, array($filter => $value), $extra);
                 break;
             default:
                 $defaultFilter = $config->get('frontpageactivitydefault');
                 if ($defaultFilter == 'friends' && $my->id != 0) {
                     $streamHTML = CActivities::getActivitiesByFilter('active-user-and-friends', $my->id, 'frontpage', true, array(), $extra);
                 } else {
                     $streamHTML = CActivities::getActivitiesByFilter('all', $my->id, 'frontpage', true, array(), $extra);
                 }
                 break;
         }
     }
     if (!isset($attachment['filter'])) {
         $attachment['filter'] = '';
         $filter = $config->get('frontpageactivitydefault');
         $filter = explode(':', $filter);
         $attachment['filter'] = isset($filter[1]) ? $filter[1] : $filter[0];
     }
     if (empty($streamHTML)) {
         if (!isset($attachment['target'])) {
             $attachment['target'] = '';
         }
         if (!isset($attachment['element'])) {
             $attachment['element'] = '';
         }
         $streamHTML = CActivities::getActivitiesByFilter($attachment['filter'], $attachment['target'], $attachment['element'], true, array('show_featured' => true, 'showLatestActivityOnTop' => true));
     }
     $objResponse->addAssign('activity-stream-container', 'innerHTML', $streamHTML);
     // Log user engagement
     CEngagement::log($attachment['type'] . '.share', $my->id);
     return $objResponse->sendResponse();
 }
Exemple #4
0
    /**
     * Show the connection request box
     */
    public function ajaxConnect($friendId)
    {
        // Block unregistered users.
        if (!COwnerHelper::isRegisteredUser()) {
            return $this->ajaxBlockUnregister();
        }
        $objResponse = new JAXResponse();
        $filter = JFilterInput::getInstance();
        $friendId = $filter->clean($friendId, 'int');
        //@todo filter paramater
        $model =& $this->getModel('friends');
        $blockModel =& $this->getModel('block');
        $my = CFactory::getUser();
        $view = $this->getView('friends');
        $user = CFactory::getUser($friendId);
        CFactory::load('libraries', 'block');
        $blockUser = new blockUser();
        $config = CFactory::getConfig();
        CFactory::load('helpers', 'owner');
        CFactory::load('libraries', 'limits');
        if (CLimitsLibrary::exceedDaily('friends')) {
            $actions = '<form method="post" action="" style="float:right;">';
            $actions .= '<input type="button" class="button" onclick="cWindowHide();return false;" name="cancel" value="' . JText::_('COM_COMMUNITY_BUTTON_CLOSE_BUTTON') . '" />';
            $actions .= '</form>';
            $html = JText::_('COM_COMMUNITY_LIMIT_FRIEND_REQUEST_REACHED');
            $objResponse->addScriptCall('cWindowAddContent', $html, $actions);
            return $objResponse->sendResponse();
        }
        // Block blocked users
        if ($blockModel->getBlockStatus($my->id, $friendId) && !COwnerHelper::isCommunityAdmin()) {
            $blockUser->ajaxBlockMessage();
        }
        // Warn owner that the user has been blocked, cannot add as friend
        if ($blockModel->getBlockStatus($friendId, $my->id)) {
            $blockUser->ajaxBlockWarn();
        }
        $connection = $model->getFriendConnection($my->id, $friendId);
        $html = '';
        $actions = '';
        CFactory::load('helpers', 'string');
        //@todo disallow self add as a friend
        //@todo disallow add existing friend
        if ($my->id == $friendId) {
            $html = JText::_('COM_COMMUNITY_FRIENDS_CANNOT_ADD_SELF');
        } elseif ($user->isBlocked()) {
            $html = JText::_('COM_COMMUNITY_FRIENDS_CANNOT_ADD_INACTIVE_USER');
        } elseif (count($connection) > 0) {
            if ($connection[0]->connect_from == $my->id) {
                $html = JText::sprintf('COM_COMMUNITY_FRIENDS_REQUEST_ALREADY_SENT', $user->getDisplayName());
            } else {
                $html = JText::sprintf('COM_COMMUNITY_FRIEND_REQUEST_ALREADY_RECEIVED', $user->getDisplayName());
            }
        } else {
            ob_start();
            ?>
			<div id="addFriendContainer">
				<p><?php 
            echo JText::sprintf('COM_COMMUNITY_CONFIRM_ADD_FRIEND', $user->getDisplayName());
            ?>
</p>
				<form name="addfriend" id="addfriend" method="post" action="">				
			        <img class="cAvatar" src="<?php 
            echo $user->getThumbAvatar();
            ?>
" alt="<?php 
            echo CStringHelper::escape($user->getDisplayName());
            ?>
" alt=""/>
					<textarea class="inputbox" name="msg"><?php 
            echo JText::_('COM_COMMUNITY_PROFILE_ADD_FRIEND_DEFAULT');
            ?>
</textarea>
					<input type="hidden" class="button" name="userid" value="<?php 
            echo $user->id;
            ?>
"/>
				</form>
			</div>
		<?php 
            $html = ob_get_contents();
            ob_end_clean();
            $actions = '<button class="button" onclick="joms.friends.addNow();" name="save">' . JText::_('COM_COMMUNITY_FRIENDS_ADD_BUTTON') . '</button>';
            $actions .= '<button class="button" onclick="javascript:cWindowHide();" name="cancel">' . JText::_('COM_COMMUNITY_CANCEL_BUTTON') . '</button>';
        }
        $objResponse->addAssign('cwin_logo', 'innerHTML', JText::_('COM_COMMUNITY_FRIENDS_ADD_NEW_FRIEND'));
        $objResponse->addScriptCall('cWindowAddContent', $html, $actions);
        return $objResponse->sendResponse();
    }
Exemple #5
0
 public function multiUpload()
 {
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     $type = $jinput->get('type', NULL, 'NONE');
     $id = $jinput->get('id', '0', 'Int');
     if ($my->id == 0) {
         $tokenId = $jinput->request->get('token', '', 'STRING');
         $userId = $jinput->request->get('uploaderid', '', 'INT');
         $my = CFactory::getUserFromTokenId($tokenId, $userId);
         $session = JFactory::getSession();
         $session->set('user', $my);
     }
     $parentTable = JTable::getInstance(ucfirst($type), 'CTable');
     $parentTable->load($id);
     $table = JTable::getInstance('File', 'CTable');
     $_file = $jinput->files->get('file');
     $fileLib = new CFilesLibrary();
     if (CLimitsLibrary::exceedDaily('files', $my->id)) {
         $json = array('msg' => JText::_('COM_COMMUNITY_FILES_LIMIT_REACHED'));
         echo json_encode($json);
         exit;
     }
     if ($type == 'discussion' && !CLimitsHelper::exceededGroupFileUpload($parentTable->groupid)) {
         $json = array('msg' => JText::_('COM_COMMUNITY_FILES_LIMIT_REACHED'));
         echo json_encode($json);
         exit;
     }
     $now = new JDate();
     $ext = pathinfo($_file['name']);
     $file = new stdClass();
     $file->creator = $my->id;
     $file->filesize = sprintf("%u", $_file['size']);
     $file->name = JString::substr($_file['name'], 0, JString::strlen($_file['name']) - (JString::strlen($ext['extension']) + 1));
     $file->created = $now->toSql();
     $file->type = CFileHelper::getExtensionIcon(CFileHelper::getFileExtension($_file['name']));
     $fileName = JApplication::getHash($_file['name'] . time()) . JString::substr($_file['name'], JString::strlen($_file['name']) - (JString::strlen($ext['extension']) + 1));
     if ($_file['error'] > 0 && $_file['error'] !== 'UPLOAD_ERR_OK') {
         $json = array('msg' => JText::sprintf('COM_COMMUNITY_PHOTOS_UPLOAD_ERROR', $_file['error']));
         echo json_encode($json);
         exit;
     }
     if (!$fileLib->checkType($_file['name'])) {
         $json = array('msg' => JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED'));
         echo json_encode($json);
         exit;
     }
     switch ($type) {
         case 'discussion':
             $file->discussionid = $parentTable->id;
             $file->groupid = $parentTable->groupid;
             $file->filepath = 'images/files' . '/' . $type . '/' . $file->discussionid . '/' . $fileName;
             break;
         case 'bulletin':
             $file->bulletinid = $parentTable->id;
             $file->groupid = $parentTable->groupid;
             $file->filepath = 'images/files' . '/' . $type . '/' . $file->bulletinid . '/' . $fileName;
             break;
         case 'message':
             $file->messageid = -1;
             // set as -1 just in case this is not used and cron can clear it later
             if ($id) {
                 $file->filepath = 'images/files/' . $type . '/' . $id . '/' . $fileName;
                 if (!JFolder::exists(JPATH_ROOT . '/images/files/' . $type . '/' . $id)) {
                     JFolder::create(JPATH_ROOT . '/images/files/' . $type . '/' . $id, (int) octdec($config->get('folderpermissionsphoto')));
                     JFile::copy(JPATH_ROOT . '/components/com_community/index.html', JPATH_ROOT . '/images/files/' . $type . '/' . $id . '/index.html');
                 }
                 JFile::copy($_file['tmp_name'], JPATH_ROOT . '/' . $file->filepath);
             } else {
                 //this could be from new message, and there is no id given
                 $file->filepath = 'images/files/' . $type . '/temp/' . $fileName;
                 //create the folder here as the logic for bulletin and discussion is not the same
                 if (!JFolder::exists(JPATH_ROOT . '/' . $type . '/temp')) {
                     JFolder::create(JPATH_ROOT . '/images/files' . '/' . $type . '/temp', (int) octdec($config->get('folderpermissionsphoto')));
                     JFile::copy(JPATH_ROOT . '/components/com_community/index.html', JPATH_ROOT . '/files' . '/' . $type . '/temp/index.html');
                 }
                 JFile::copy($_file['tmp_name'], JPATH_ROOT . '/images/files' . '/' . $type . '/temp/' . $fileName);
             }
             break;
     }
     if ($type != 'message') {
         if (!JFolder::exists(JPATH_ROOT . '/' . $type . '/' . $parentTable->id)) {
             JFolder::create(JPATH_ROOT . '/images/files' . '/' . $type . '/' . $parentTable->id, (int) octdec($config->get('folderpermissionsphoto')));
             JFile::copy(JPATH_ROOT . '/components/com_community/index.html', JPATH_ROOT . '/files' . '/' . $type . '/' . $parentTable->id . '/index.html');
         }
         JFile::copy($_file['tmp_name'], JPATH_ROOT . '/images/files' . '/' . $type . '/' . $parentTable->id . '/' . $fileName);
     }
     $table->bind($file);
     $table->store();
     $params = new CParameter('');
     switch ($type) {
         case 'discussion':
             // Get repliers for this discussion and notify the discussion creator too
             $discussionModel = CFactory::getModel('Discussions');
             $discussion = JTable::getInstance('Discussion', 'CTable');
             $discussion->load($parentTable->id);
             $users = $discussionModel->getRepliers($discussion->id, $discussion->groupid);
             $users[] = $discussion->creator;
             // The person who post this, should not be getting notification email
             $key = array_search($my->id, $users);
             if ($key !== false && isset($users[$key])) {
                 unset($users[$key]);
             }
             $params->set('url', 'index.php?option=com_community&view=groups&task=viewdiscussion&groupid=' . $discussion->groupid . '&topicid=' . $discussion->id);
             $params->set('filename', $_file['name']);
             $params->set('discussion', $discussion->title);
             $params->set('discussion_url', 'index.php?option=com_community&view=groups&task=viewdiscussion&groupid=' . $discussion->groupid . '&topicid=' . $discussion->id);
             CNotificationLibrary::add('groups_discussion_newfile', $my->id, $users, JText::sprintf('COM_COMMUNITY_GROUP_DISCUSSION_NEW_FILE_SUBJECT'), '', 'groups.discussion.newfile', $params);
             break;
         case 'bulletin':
             break;
     }
     $json = array('id' => $table->id);
     die(json_encode($json));
 }
Exemple #6
0
 public function upload()
 {
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     // If user is using a flash browser, their session might get reset when mod_security is around
     if ($my->id == 0) {
         $tokenId = JRequest::getVar('token', '', 'REQUEST');
         $userId = JRequest::getVar('uploaderid', '', 'REQUEST');
         $my = CFactory::getUserFromTokenId($tokenId, $userId);
         $session =& JFactory::getSession();
         $session->set('user', $my);
     }
     CFactory::load('libraries', 'limits');
     if (CLimitsLibrary::exceedDaily('photos', $my->id)) {
         $this->_showUploadError(true, JText::_('COM_COMMUNITY_PHOTOS_LIMIT_PERDAY_REACHED'));
         return;
     }
     // We can't use blockUnregister here because practically, the CFactory::getUser() will return 0
     if ($my->id == 0) {
         return;
     }
     // Load up required models and properties
     CFactory::load('libraries', 'photos');
     CFactory::load('models', 'photos');
     CFactory::load('helpers', 'image');
     $photos = JRequest::get('Files');
     $albumId = JRequest::getVar('albumid', '', 'REQUEST');
     $album =& JTable::getInstance('Album', 'CTable');
     $album->load($albumId);
     $handler = $this->_getHandler($album);
     foreach ($photos as $imageFile) {
         $result = $this->_checkUploadedFile($imageFile, $album, $handler);
         if (!$result['photoTable']) {
             continue;
         }
         //assign the result of the array and assigned to the right variable
         $photoTable = $result['photoTable'];
         $storage = $result['storage'];
         $albumPath = $result['albumPath'];
         $hashFilename = $result['hashFilename'];
         $thumbPath = $result['thumbPath'];
         $originalPath = $result['originalPath'];
         $imgType = $result['imgType'];
         $isDefaultPhoto = $result['isDefaultPhoto'];
         // Remove the filename extension from the caption
         if (JString::strlen($photoTable->caption) > 4) {
             $photoTable->caption = JString::substr($photoTable->caption, 0, JString::strlen($photoTable->caption) - 4);
         }
         // @todo: configurable options?
         // Permission should follow album permission
         $photoTable->published = '1';
         $photoTable->permissions = $album->permissions;
         // Set the relative path.
         // @todo: configurable path?
         $storedPath = $handler->getStoredPath($storage, $albumId);
         $storedPath = $storedPath . DS . $albumPath . $hashFilename . CImageHelper::getExtension($imageFile['type']);
         $photoTable->image = CString::str_ireplace(JPATH_ROOT . DS, '', $storedPath);
         $photoTable->thumbnail = CString::str_ireplace(JPATH_ROOT . DS, '', $thumbPath);
         //In joomla 1.6, CString::str_ireplace is not replacing the path properly. Need to do a check here
         if ($photoTable->image == $storedPath) {
             $photoTable->image = str_ireplace(JPATH_ROOT . DS, '', $storedPath);
         }
         if ($photoTable->thumbnail == $thumbPath) {
             $photoTable->thumbnail = str_ireplace(JPATH_ROOT . DS, '', $thumbPath);
         }
         //photo filesize, use sprintf to prevent return of unexpected results for large file.
         $photoTable->filesize = sprintf("%u", filesize($originalPath));
         // @rule: Set the proper ordering for the next photo upload.
         $photoTable->setOrdering();
         // Store the object
         $photoTable->store();
         // We need to see if we need to rotate this image, from EXIF orientation data
         // Only for jpeg image.
         if ($config->get('photos_auto_rotate') && $imgType == 'image/jpeg') {
             $this->_rotatePhoto($imageFile, $photoTable, $storedPath, $thumbPath);
         }
         // Trigger for onPhotoCreate
         CFactory::load('libraries', 'apps');
         $apps =& CAppPlugins::getInstance();
         $apps->loadApplications();
         $params = array();
         $params[] =& $photoTable;
         $apps->triggerEvent('onPhotoCreate', $params);
         // Set image as default if necessary
         // Load photo album table
         if ($isDefaultPhoto) {
             // Set the photo id
             $album->photoid = $photoTable->id;
             $album->store();
         }
         // @rule: Set first photo as default album cover if enabled
         if (!$isDefaultPhoto && $config->get('autoalbumcover')) {
             $photosModel = CFactory::getModel('Photos');
             $totalPhotos = $photosModel->getTotalPhotos($album->id);
             if ($totalPhotos <= 1) {
                 $album->photoid = $photoTable->id;
                 $album->store();
             }
         }
         // Generate activity stream
         $act = new stdClass();
         $act->cmd = 'photo.upload';
         $act->actor = $my->id;
         $act->access = $album->permissions;
         $act->target = 0;
         //$act->title	  	= JText::sprintf( $handler->getUploadActivityTitle() , '{photo_url}', $album->name );
         $act->title = JText::sprintf($handler->getUploadActivityTitle(), '{multiUrl}', $album->name);
         $act->content = '';
         // Gegenerated automatically by stream. No need to add anything
         $act->app = 'photos';
         $act->cid = $albumId;
         $act->location = $album->location;
         // Store group info
         // I hate to load group here, but unfortunately, album does
         // not store group permission setting
         $group =& JTable::getInstance('Group', 'CTable');
         $group->load($album->groupid);
         $act->groupid = $album->groupid;
         $act->group_access = $group->approvals;
         // Allow comment on the album
         $act->comment_type = 'photos.album';
         $act->comment_id = $albumId;
         // Allow like on the album
         $act->like_type = 'photos.album';
         $act->like_id = $albumId;
         $params = new CParameter('');
         $params->set('multiUrl', $handler->getAlbumURI($albumId, false));
         $params->set('photoid', $photoTable->id);
         $params->set('action', 'upload');
         $params->set('photo_url', $photoTable->getThumbURI());
         // Add activity logging
         CFactory::load('libraries', 'activities');
         CActivityStream::add($act, $params->toString());
         //add user points
         CFactory::load('libraries', 'userpoints');
         CUserPoints::assignPoint('photo.upload');
         // Photo upload was successfull, display a proper message
         $this->_showUploadError(false, JText::sprintf('COM_COMMUNITY_PHOTO_UPLOADED_SUCCESSFULLY', $photoTable->caption), $photoTable->getThumbURI(), $albumId, $photoTable->id);
     }
     $this->cacheClean(array(COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_ACTIVITIES));
     exit;
 }
Exemple #7
0
 private function _checkUploadLimit()
 {
     if (CLimitsLibrary::exceedDaily('videos')) {
         $json = array('title' => JText::_('COM_COMMUNITY_VIDEOS_ADD'), 'error' => JText::_('COM_COMMUNITY_VIDEOS_LIMIT_REACHED'));
         die(json_encode($json));
     }
 }
Exemple #8
0
 /**
  * Method to display the create group form
  **/
 public function create()
 {
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     CFactory::load('helpers', 'owner');
     if ($my->authorise('community.add', 'groups')) {
         $model = CFactory::getModel('Groups');
         $mainframe =& JFactory::getApplication();
         CFactory::load('libraries', 'limits');
         if (CLimitsLibrary::exceedDaily('groups')) {
             $mainframe->redirect(CRoute::_('index.php?option=com_community&view=groups', false), JText::_('COM_COMMUNITY_GROUPS_LIMIT_REACHED'), 'error');
         }
         $model =& $this->getModel('groups');
         $data = new stdClass();
         $data->categories = $model->getCategories();
         if (JRequest::getVar('action', '', 'POST') == 'save') {
             CFactory::load('libraries', 'apps');
             $appsLib =& CAppPlugins::getInstance();
             $saveSuccess = $appsLib->triggerEvent('onFormSave', array('jsform-groups-forms'));
             if (empty($saveSuccess) || !in_array(false, $saveSuccess)) {
                 $gid = $this->save();
                 if ($gid !== FALSE) {
                     $mainframe =& JFactory::getApplication();
                     $group =& JTable::getInstance('Group', 'CTable');
                     $group->load($gid);
                     //trigger for onGroupCreate
                     $this->triggerGroupEvents('onGroupCreate', $group);
                     if ($config->get('moderategroupcreation')) {
                         $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_GROUPS_MODERATION_MSG', $group->name), $group->name);
                         return;
                     }
                     $url = CRoute::_('index.php?option=com_community&view=groups&task=created&groupid=' . $gid, false);
                     $mainframe->redirect($url, JText::sprintf('COM_COMMUNITY_GROUPS_CREATE_SUCCESS', $group->name));
                     return;
                 }
             }
         }
     } else {
         $errorMsg = $my->authoriseErrorMsg();
         if ($errorMsg == 'blockUnregister') {
             return $this->blockUnregister();
         } else {
             echo $errorMsg;
         }
         return;
     }
     //Clear Cache in front page
     $this->cacheClean(array(COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_GROUPS, COMMUNITY_CACHE_TAG_GROUPS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES));
     $this->renderView(__FUNCTION__, $data);
 }
Exemple #9
0
 /**
  * Show the connection request box
  */
 public function ajaxConnect($friendId)
 {
     // Block unregistered users.
     if (!COwnerHelper::isRegisteredUser()) {
         return $this->ajaxBlockUnregister();
     }
     $filter = JFilterInput::getInstance();
     $friendId = $filter->clean($friendId, 'int');
     //@todo filter paramater
     $model = $this->getModel('friends');
     $blockModel = $this->getModel('block');
     $my = CFactory::getUser();
     $view = $this->getView('friends');
     $user = CFactory::getUser($friendId);
     $blockUser = new blockUser();
     $config = CFactory::getConfig();
     if (CLimitsLibrary::exceedDaily('friends')) {
         $json = array('title' => JText::_('COM_COMMUNITY_FRIENDS_ADD_NEW_FRIEND'), 'error' => JText::_('COM_COMMUNITY_LIMIT_FRIEND_REQUEST_REACHED'));
         die(json_encode($json));
     }
     // Block blocked users
     if ($blockModel->getBlockStatus($my->id, $friendId) && !COwnerHelper::isCommunityAdmin()) {
         $blockUser->ajaxBlockMessage();
     }
     // Warn owner that the user has been blocked, cannot add as friend
     if ($blockModel->getBlockStatus($friendId, $my->id)) {
         $blockUser->ajaxBlockWarn();
     }
     $connection = $model->getFriendConnection($my->id, $friendId);
     $html = '';
     $actions = '';
     //@todo disallow self add as a friend
     //@todo disallow add existing friend
     if ($my->id == $friendId) {
         $json = array('title' => JText::_('COM_COMMUNITY_FRIENDS_ADD_NEW_FRIEND'), 'error' => JText::_('COM_COMMUNITY_FRIENDS_CANNOT_ADD_SELF'));
     } elseif ($user->isBlocked()) {
         $json = array('title' => JText::_('COM_COMMUNITY_FRIENDS_ADD_NEW_FRIEND'), 'error' => JText::_('COM_COMMUNITY_FRIENDS_CANNOT_ADD_INACTIVE_USER'));
     } elseif (count($connection) > 0) {
         if ($connection[0]->connect_from == $my->id) {
             $json = array('title' => JText::_('COM_COMMUNITY_FRIENDS_ADD_NEW_FRIEND'), 'error' => JText::sprintf('COM_COMMUNITY_FRIENDS_REQUEST_ALREADY_SENT', $user->getDisplayName()));
         } else {
             $json = array('title' => JText::_('COM_COMMUNITY_PROFILE_PENDING_FRIEND_REQUEST'), 'avatar' => $user->getThumbAvatar(), 'desc' => str_replace('{actor}', '<strong>' . $user->getDisplayName() . '</strong>', JText::_('COM_COMMUNITY_FRIEND_ADD_REQUEST')), 'message' => nl2br($connection[0]->msg), 'connection_id' => $connection[0]->connection_id, 'btnAccept' => JText::_('COM_COMMUNITY_PENDING_ACTION_APPROVE'), 'btnReject' => JText::_('COM_COMMUNITY_FRIENDS_PENDING_ACTION_REJECT'), 'error' => JText::sprintf('COM_COMMUNITY_FRIEND_REQUEST_ALREADY_RECEIVED', $user->getDisplayName()));
         }
     } else {
         $json = array('title' => JText::_('COM_COMMUNITY_FRIENDS_ADD_NEW_FRIEND'), 'avatar' => $user->getThumbAvatar(), 'desc' => JText::sprintf('COM_COMMUNITY_CONFIRM_ADD_FRIEND', $user->getDisplayName()), 'message' => JText::_('COM_COMMUNITY_PROFILE_ADD_FRIEND_DEFAULT'), 'btnAdd' => JText::_('COM_COMMUNITY_FRIENDS_ADD_BUTTON'), 'btnCancel' => JText::_('COM_COMMUNITY_CANCEL_BUTTON'));
     }
     die(json_encode($json));
 }
Exemple #10
0
 /**
  * Method to display the create group form
  * */
 public function create()
 {
     $my = CFactory::getUser();
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     $config = CFactory::getConfig();
     if ($my->authorise('community.add', 'groups')) {
         $model = CFactory::getModel('Groups');
         if (CLimitsLibrary::exceedDaily('groups')) {
             $mainframe->redirect(CRoute::_('index.php?option=com_community&view=groups', false), JText::_('COM_COMMUNITY_GROUPS_LIMIT_REACHED'), 'error');
         }
         $model = $this->getModel('groups');
         $data = new stdClass();
         $data->categories = $model->getCategories();
         if ($jinput->post->get('action', '', 'STRING') == 'save') {
             $appsLib = CAppPlugins::getInstance();
             $saveSuccess = $appsLib->triggerEvent('onFormSave', array('jsform-groups-forms'));
             if (empty($saveSuccess) || !in_array(false, $saveSuccess)) {
                 $gid = $this->save();
                 if ($gid !== FALSE) {
                     $mainframe = JFactory::getApplication();
                     $group = JTable::getInstance('Group', 'CTable');
                     $group->load($gid);
                     // Set the user as group member
                     $my->updateGroupList();
                     //lets create the default avatar for the group
                     $avatarAlbum = JTable::getInstance('Album', 'CTable');
                     $avatarAlbum->addAvatarAlbum($group->id, 'group');
                     $coverAlbum = JTable::getInstance('Album', 'CTable');
                     $coverAlbum->addCoverAlbum('group', $group->id);
                     $defaultAlbum = JTable::getInstance('Album', 'CTable');
                     $defaultAlbum->addDefaultAlbum($group->id, 'group');
                     //trigger for onGroupCreate
                     $this->triggerGroupEvents('onGroupCreate', $group);
                     if ($config->get('moderategroupcreation')) {
                         $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_GROUPS_MODERATION_MSG', $group->name), $group->name);
                         $mainframe->redirect(CRoute::_('index.php?option=com_community&view=groups'));
                         return;
                     }
                     $url = CRoute::_('index.php?option=com_community&view=groups&task=created&groupid=' . $gid, false);
                     $mainframe->redirect($url);
                     return;
                 }
             }
         }
     } else {
         $errorMsg = $my->authoriseErrorMsg();
         if ($errorMsg == 'blockUnregister') {
             return $this->blockUnregister();
         } else {
             echo $errorMsg;
         }
         return;
     }
     //Clear Cache in front page
     $this->cacheClean(array(COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_GROUPS, COMMUNITY_CACHE_TAG_GROUPS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES));
     $this->renderView(__FUNCTION__, $data);
 }