/** * Display the list of photos a user has uploaded * * @since 1.0 * @access public * @param string * @return */ public function getAlbums($user) { $params = $this->getUserParams($user->id); $appParam = $this->app->getParams(); $albums = array(); // Load up albums model $model = FD::model('Albums'); $sorting = $params->get('ordering', $appParam->get('ordering', 'latest')); $options = array('order' => 'assigned_date', 'direction' => $sorting == 'latest' ? 'desc' : 'asc'); $options['excludeblocked'] = 1; // privacy lib $privacy = Foundry::privacy(Foundry::user()->id); $results = $model->getAlbums($user->id, SOCIAL_TYPE_USER, $options); if ($results) { foreach ($results as $item) { // we need to check the photo's album privacy to see if user allow to view or not. if ($privacy->validate('albums.view', $item->id, SOCIAL_TYPE_ALBUM, $item->user_id)) { $albums[] = $item; } } } if (empty($albums)) { return; } // If sorting is set to random, then we shuffle the albums if ($sorting == 'random') { shuffle($albums); } // since we are getting all albums belong to user, // we do not need to run another query to count the albums. // just do array count will be fine. // $total = $model->getTotalAlbums($options); $total = count($albums); $limit = $params->get('limit', $appParam->get('limit', 10)); $this->set('total', $total); $this->set('appParams', $appParam); $this->set('params', $params); $this->set('user', $user); $this->set('albums', $albums); $this->set('limit', $limit); $this->set('privacy', $privacy); return parent::display('widgets/profile/albums'); }
/** * Return a list of privacy options * * @param none * @return array An array of select options **/ public function getOptions($type = '', $userId = '') { $config = EasyBlogHelper::getConfig(); $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_community' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'core.php'; $options = array(); if ($type != 'category') { if ($config->get('main_jomsocial_privacy') && JFile::exists($file)) { $options[] = JHTML::_('select.option', '0', JText::_('COM_EASYBLOG_PRIVACY_JOMSOCIAL_ALL')); $options[] = JHTML::_('select.option', '20', JText::_('COM_EASYBLOG_PRIVACY_JOMSOCIAL_MEMBERS')); $options[] = JHTML::_('select.option', '30', JText::_('COM_EASYBLOG_PRIVACY_JOMSOCIAL_FRIENDS')); $options[] = JHTML::_('select.option', '40', JText::_('COM_EASYBLOG_PRIVACY_JOMSOCIAL_ONLY_ME')); } $easysocial = EasyBlogHelper::getHelper('EasySocial'); if ($config->get('integrations_easysocial_privacy') && $easysocial->exists()) { $my = JFactory::getUser(); $userId = $userId ? $userId : $my->id; $privacyLib = Foundry::privacy($userId, 'user'); $esOptions = $privacyLib->getOption('0', 'blog', $userId, 'easyblog.blog.view'); if (isset($esOptions->option) && count($esOptions->option) > 0) { foreach ($esOptions->option as $optionKey => $optionVal) { $valueInt = $privacyLib->toValue($optionKey); $options[] = JHTML::_('select.option', $valueInt, JText::_('COM_EASYBLOG_PRIVACY_EASYSOCIAL_' . strtoupper($optionKey))); } } } } // Default values if (empty($options)) { $options[] = JHTML::_('select.option', '0', JText::_('COM_EASYBLOG_PRIVACY_VIEWABLE_ALL')); $options[] = JHTML::_('select.option', '1', JText::_('COM_EASYBLOG_PRIVACY_VIEWABLE_MEMBERS')); if ($type == 'category') { $options[] = JHTML::_('select.option', '2', JText::_('COM_EASYBLOG_PRIVACY_VIEWABLE_CATEGORY_ACL')); } } return $options; }
public function updateBlogPrivacy($blog) { $privacyLib = Foundry::privacy($blog->created_by, SOCIAL_PRIVACY_TYPE_USER); $privacyLib->add('easyblog.blog.view', $blog->id, 'blog', $blog->private); }
/** * Trigger for onPrepareStream * * @since 1.0 * @access public * @param string * @return */ public function onPrepareStream(SocialStreamItem &$item, $includePrivacy = true) { // We only want to process related items if ($item->context != 'photos') { return; } // If photos has been disabled, there's no point showing any stream $config = Foundry::config(); // Do not allow user to access photos if it's not enabled if (!$config->get('photos.enabled') && $item->verb != 'uploadAvatar' && $item->verb != 'updateCover') { return; } // Get current logged in user. $my = Foundry::user(); // Get user's privacy. $privacy = Foundry::privacy($my->id); $element = $item->context; $uid = $item->contextId; $useAlbum = count($item->contextIds) > 1 ? true : false; // Decorate the stream $item->color = '#F8829C'; $item->fonticon = 'ies-picture'; $item->label = FD::_('APP_USER_PHOTOS_STREAM_TOOLTIP', true); $item->display = SOCIAL_STREAM_DISPLAY_FULL; // Load the photo object $photo = Foundry::table('Photo'); $photoId = $item->contextId; $photoParams = isset($item->contextParams[$photoId]) ? $item->contextParams[$photoId] : ''; if ($photoParams) { $obj = FD::json()->decode($photoParams); if (!$obj) { $photo->load($photoId); } else { // Bind the photo data $photo->bind($obj); if (!$photo->id) { $photo->load($photoId); } } } else { $photo->load($photoId); } // If this is a group, we need to prepare accordingly. if ($item->cluster_id && $item->cluster_type == SOCIAL_TYPE_GROUP) { $group = Foundry::group($item->cluster_id); // If we can't locate the group, skip this. if (!$group) { return; } // Check if the user can really view this stream if (!$group->isOpen() && !$group->isMember()) { return; } // Check if the group is private or invite, dont show the sharing button if (!$group->isOpen()) { $item->sharing = false; } // We need a different label for group items $item->color = '#303229'; $item->fonticon = 'ies-users'; $item->label = FD::_('APP_USER_PHOTOS_GROUPS_STREAM_TOOLTIP', true); } // If this is an event, we need to prepare accordingly. if ($item->cluster_id && $item->cluster_type == SOCIAL_TYPE_EVENT) { $event = FD::event($item->cluster_id); if (empty($event) || empty($event->id)) { return; } if (!$event->isOpen() && !$event->getGuest()->isGuest()) { return; } // Check if the event is private or invite, dont show the sharing button if (!$event->isOpen()) { $item->sharing = false; } $item->color = '#f06050'; $item->fonticon = 'ies-calendar'; $item->label = FD::_('APP_USER_EVENTS_STREAM_TOOLTIP', true); } // Process actions on the stream $this->processActions($item, $privacy); $privacyRule = $useAlbum ? 'albums.view' : 'photos.view'; if ($item->verb == 'uploadAvatar' || $item->verb == 'updateCover') { $privacyRule = 'core.view'; } if ($includePrivacy) { if ($privacyRule == 'photos.view') { // we need to check the photo's album privacy to see if user allow to view or not. // if( !$privacy->validate( 'albums.view' , $photo->album_id, SOCIAL_TYPE_ALBUM, $item->actor->id ) ) if (!$privacy->validate('photos.view', $photo->id, SOCIAL_TYPE_PHOTO, $item->actor->id)) { return; } } else { if ($useAlbum && $privacyRule == 'albums.view') { $uid = $photo->album_id; $element = 'albums'; } // Determine if the user can view this current context if (!$privacy->validate($privacyRule, $uid, $element, $item->actor->id)) { return; } } } // Get the single context id $id = $item->contextId; $albumId = ''; $params = $this->getApp()->getParams(); // Process group avatar updates if ($item->verb == 'uploadAvatar' && $item->cluster_id && $item->cluster_type == SOCIAL_TYPE_GROUP && $params->get('uploadAvatar', true)) { $this->prepareGroupUploadAvatarStream($item, $privacy, $includePrivacy); } // Process event avatar updates if ($item->verb == 'uploadAvatar' && $item->cluster_id && $item->cluster_type == SOCIAL_TYPE_EVENT && $params->get('uploadAvatar', true)) { $this->prepareEventUploadAvatarStream($item, $privacy, $includePrivacy); } // Process user avatar updates if ($item->verb == 'uploadAvatar' && !$item->cluster_id && $params->get('uploadAvatar', true)) { $this->prepareUploadAvatarStream($item, $privacy, $includePrivacy); } // Process group cover updates if ($item->verb == 'updateCover' && $item->cluster_id && $item->cluster_type == SOCIAL_TYPE_GROUP && $params->get('uploadCover', true)) { $this->prepareGroupUpdateCoverStream($item, $privacy, $includePrivacy); } // Process event cover updates if ($item->verb == 'updateCover' && $item->cluster_id && $item->cluster_type == SOCIAL_TYPE_EVENT && $params->get('uploadCover', true)) { $this->prepareEventUpdateCoverStream($item, $privacy, $includePrivacy); } // Process user cover updates if ($item->verb == 'updateCover' && !$item->cluster_id && $params->get('uploadCover', true)) { $this->prepareUpdateCoverStream($item, $privacy, $includePrivacy); } // Photo stream types. Uploaded via the story form $photoStreams = array('add', 'create', 'share'); // Old data compatibility $item->verb = $item->verb == 'create' ? 'add' : $item->verb; // Process photo streams for groups if (in_array($item->verb, $photoStreams) && $item->cluster_id && $item->cluster_type == SOCIAL_TYPE_GROUP && $params->get('uploadPhotos', true)) { $this->prepareGroupPhotoStream($item, $privacy, $includePrivacy, $useAlbum); } // Process photo streams for events if (in_array($item->verb, $photoStreams) && $item->cluster_id && $item->cluster_type == SOCIAL_TYPE_EVENT && $params->get('uploadPhotos', true)) { $this->prepareEventPhotoStream($item, $privacy, $includePrivacy, $useAlbum); } // Process photo streams for users if (in_array($item->verb, $photoStreams) && !$item->cluster_id && $params->get('uploadPhotos', true)) { $this->preparePhotoStream($item, $privacy, $includePrivacy, $useAlbum); } // set opengraph description if ($item->content) { $item->opengraph->addDescription($item->content); } else { $item->opengraph->addDescription($item->title); } return; }
public function bindStreamAccess() { if (!$this->actor_id) { // this is a guest. // let get the privacy id for the keys that passed in. $keys = $this->_public_rule['key']; $rules = explode('.', $keys); $key = array_shift($rules); $rule = implode('.', $rules); $currentRule = FD::table('Privacy'); $currentRule->load(array('type' => $key, 'rule' => $rule)); if (!$currentRule->id) { // lets load the core.view privacy. $currentRule->load(array('type' => 'core', 'rule' => 'view')); } $this->privacy_id = $currentRule->id; $this->access = 0; // always default to public $this->custom_access = ''; } else { $privacyLib = Foundry::privacy($this->actor_id); $privacyData = $privacyLib->getData(); $core = $privacyData['core']['view']; if ($this->_public_rule) { $keys = $this->_public_rule['key']; $access = $this->_public_rule['value']; $custom = isset($this->_public_rule['custom']) ? $this->_public_rule['custom'] : ''; if ($this->actor_type == SOCIAL_STREAM_ACTOR_TYPE_USER) { // we need to test the user privacy for this rule. $rules = explode('.', $keys); $key = array_shift($rules); $rule = implode('.', $rules); // if current passed in rule not found, we will use the core.view instead. $currentRule = $core; if (isset($privacyData[$key]) && isset($privacyData[$key][$rule])) { $currentRule = $privacyData[$key][$rule]; } $this->privacy_id = $currentRule->id; $this->access = !is_null($access) ? $access : $currentRule->default; $this->custom_access = ''; if ($this->access == SOCIAL_PRIVACY_CUSTOM) { $tmp = array(); if ($custom) { $tmp = $custom; } else { if ($currentRule->custom) { foreach ($currentRule->custom as $cc) { $tmp[] = $cc->user_id; } } } if ($tmp) { $this->custom_access = ',' . implode(',', $tmp) . ','; } } } } else { $this->privacy_id = $core->id; $this->access = !empty($access) ? $access : $core->default; $this->custom_access = ''; if ($this->access == SOCIAL_PRIVACY_CUSTOM) { $tmp = array(); if ($custom) { $tmp = $custom; } else { if ($core->custom) { foreach ($core->custom as $cc) { $tmp[] = $cc->user_id; } } } if ($tmp) { $this->custom_access = ',' . implode(',', $tmp) . ','; } } } } }
public function updateBlogPrivacy($blog) { if (!$this->exists() || !$this->config->get('integrations_easysocial_privacy')) { return false; } $privacyLib = Foundry::privacy($blog->created_by, SOCIAL_PRIVACY_TYPE_USER); $privacyLib->add('easyblog.blog.view', $blog->id, 'blog', $blog->access); }