예제 #1
0
 /**
  * Determines if JomSocial Exists
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return
  */
 public function exists()
 {
     if (!EB::jomsocial()->exists()) {
         return false;
     }
     return true;
 }
예제 #2
0
 public function getPermalink()
 {
     $exists = EB::jomsocial()->exists();
     if (!$exists) {
         return;
     }
     return $this->event->getLink();
 }
예제 #3
0
 /**
  * Retrieves the profile link
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return	
  */
 public function getLink()
 {
     if (!EB::jomsocial()->exists()) {
         return parent::getLink();
     }
     $link = CRoute::_('index.php?option=com_community&view=profile&userid=' . $this->profile->id);
     return $link;
 }
예제 #4
0
 public function getAvatar($profile)
 {
     $jomsocial = EB::jomsocial();
     if (!$jomsocial->exists()) {
         return false;
     }
     $user = CFactory::getUser($profile->id);
     $avatar = $user->getThumbAvatar();
     return $avatar;
 }
예제 #5
0
 /**
  * Displays the friend link for the author
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return	
  */
 public function html(EasyBlogTableProfile $author)
 {
     // Do not display the link if the user is trying to view his own post
     if ($author->id == $this->my->id) {
         return;
     }
     if ($this->config->get('integrations_easysocial_friends')) {
         return EB::easysocial()->getFriendsHtml($author->id);
     }
     if ($this->config->get('main_jomsocial_friends')) {
         return EB::jomsocial()->getFriendsHtml($author->id);
     }
     return;
 }
예제 #6
0
 /**
  * Displays the html code for sending a message to a friend
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return	
  */
 public function html(EasyBlogTableProfile $author)
 {
     // Why would they want to send a message to themselves.
     if ($this->my->id == $author->id) {
         return;
     }
     // Ensure that JomSocial really exists
     if ($this->config->get('main_jomsocial_messaging') && EB::jomsocial()->exists()) {
         return EB::jomsocial()->getMessagingHtml($author->id);
     }
     // Ensure that JomSocial really exists
     if ($this->config->get('integrations_easysocial_conversations') && EB::easysocial()->exists()) {
         return EB::easysocial()->getMessagingHtml($author->id);
     }
 }
예제 #7
0
 /**
  * Override parent's implementation of store
  *
  * @since	4.0
  * @access	public
  * @param	string
  * @return
  */
 public function store($updateNulls = false)
 {
     if (!$this->created) {
         $this->created = EB::date()->toSql();
     }
     // Generate an alias if alias is empty
     if (!$this->alias) {
         $this->alias = EBR::normalizePermalink($this->title);
     }
     $my = JFactory::getUser();
     // Add point integrations for new categories
     if ($this->id == 0 && $my->id > 0) {
         EB::loadLanguages();
         // Integrations with EasyDiscuss
         EB::easydiscuss()->log('easyblog.new.category', $my->id, JText::sprintf('COM_EASYBLOG_EASYDISCUSS_HISTORY_NEW_CATEGORY', $this->title));
         EB::easydiscuss()->addPoint('easyblog.new.category', $my->id);
         EB::easydiscuss()->addBadge('easyblog.new.category', $my->id);
         // AlphaUserPoints
         EB::aup()->assign('plgaup_easyblog_add_category', '', 'easyblog_add_category_' . $this->id, JText::sprintf('COM_EASYBLOG_AUP_NEW_CATEGORY_CREATED', $this->title));
         // JomSocial integrations
         EB::jomsocial()->assignPoints('com_easyblog.category.add', $my->id);
         // Assign EasySocial points
         EB::easysocial()->assignPoints('category.create', $my->id);
     }
     // Figure out the proper nested set model
     if ($this->id == 0 && $this->lft == 0) {
         // No parent id, we use the current lft,rgt
         if ($this->parent_id) {
             $left = $this->getLeft($this->parent_id);
             $this->lft = $left;
             $this->rgt = $this->lft + 1;
             // Update parent's right
             $this->updateRight($left);
             $this->updateLeft($left);
         } else {
             $this->lft = $this->getLeft() + 1;
             $this->rgt = $this->lft + 1;
         }
     }
     if ($this->id == 0) {
         // new cats. we need to store the ordering.
         $this->ordering = $this->getOrdering($this->parent_id) + 1;
     }
     $isNew = !$this->id ? true : false;
     $state = parent::store();
     return $state;
 }
예제 #8
0
 /**
  * Retrieves the next post in line
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return
  */
 public function getPostNavigation(EasyBlogPost $post, $navigationType)
 {
     $db = EB::db();
     $my = JFactory::getUser();
     $config = EB::config();
     $keys = array('prev', 'next');
     $nav = new stdClass();
     // Get the active menu
     $active = JFactory::getApplication()->getMenu()->getActive();
     $catAccess = array();
     $queryInclude = '';
     $teamId = $post->getTeamAssociation();
     $author = $post->getAuthor();
     // // If there is an active menu for EasyBlog, check if there's any filtering by categories
     // if ($active) {
     // 	$cats = EB::getCategoryInclusion($active->params->get('inclusion'));
     // 	if ($cats && !is_array($cats)) {
     // 		$cats = array($cats);
     // 	}
     // 	$catAccess['include'] = $cats;
     // }
     // // sql for category access
     // $catLib = EB::category();
     // $catAccessSQL = $catLib->genAccessSQL( 'a.`id`', $catAccess);
     foreach ($keys as $key) {
         $query = array();
         $query[] = 'SELECT a.`id`, a.`title`';
         $query[] = ' FROM `#__easyblog_post` AS `a`';
         $query[] = ' WHERE a.`published` = ' . $db->Quote(EASYBLOG_POST_PUBLISHED);
         $query[] = ' AND a.`state` = ' . $db->Quote(EASYBLOG_POST_NORMAL);
         // EasySocial integrations
         $query[] = EB::easysocial()->buildPrivacyQuery('a');
         // Jomsocial integrations
         $query[] = EB::jomsocial()->buildPrivacyQuery();
         // Blog privacy settings
         if ($my->guest) {
             $query[] = 'AND a.' . $db->qn('access') . '=' . $db->Quote(BLOG_PRIVACY_PUBLIC);
         }
         // Exclude private categories
         // $query[] = 'AND (' . $catAccessSQL . ')';
         // If the current menu is blogger mode, we need to respect this by only loading author related items
         $isBloggerMode = EBR::isBloggerMode();
         if ($isBloggerMode !== false) {
             $query[] = 'AND a.' . $db->qn('created_by') . '=' . $db->Quote($isBloggerMode);
             $query[] = 'AND a.' . $db->qn('source_type') . '=' . $db->Quote(EASYBLOG_POST_SOURCE_SITEWIDE);
         }
         // Filter the next / previous link by team
         if ($navigationType == 'team' && $teamId) {
             $query[] = 'AND (a.' . $db->qn('source_type') . '=' . $db->Quote(EASYBLOG_POST_SOURCE_TEAM) . ' AND a.' . $db->qn('source_id') . '=' . $db->Quote($teamId) . ')';
         }
         // Filter the next / previous by author
         if ($navigationType == 'author') {
             $query[] = 'AND a.' . $db->qn('created_by') . '=' . $db->Quote($author->id);
             $query[] = 'AND a.' . $db->qn('source_type') . '=' . $db->Quote(EASYBLOG_POST_SOURCE_SITEWIDE);
         }
         // Filter the next / previous post items from site wide
         if ($navigationType == 'site') {
             $query[] = 'AND a.' . $db->qn('source_type') . '=' . $db->Quote(EASYBLOG_POST_SOURCE_SITEWIDE);
         }
         // When language filter is enabled, we need to detect the appropriate contents
         $filterLanguage = JFactory::getApplication()->getLanguageFilter();
         if ($filterLanguage) {
             $query[] = EBR::getLanguageQuery('AND', 'a.language');
         }
         if ($key == 'prev') {
             $query[] = ' AND a.`created` < ' . $db->Quote($post->created);
             $query[] = ' ORDER BY a.`created` DESC';
         }
         if ($key == 'next') {
             $query[] = ' AND a.`created` > ' . $db->Quote($post->created);
             $query[] = ' ORDER BY a.`created` ASC';
         }
         $query[] = 'LIMIT 1';
         $query = implode(' ', $query);
         $db->setQuery($query);
         $result = $db->loadObject();
         $nav->{$key} = $result;
     }
     return $nav;
 }
예제 #9
0
 /**
  * Overrides the parent's delete method
  *
  * @since	4.0
  * @access	public
  * @param	string
  * @return
  */
 public function delete($pk = null)
 {
     // Try to delete the comment item first
     $state = parent::delete($pk);
     // Get the current logged in user
     $my = JFactory::getUser();
     // Remove comment's stream
     $this->removeStream();
     if ($this->created_by != 0 && $this->published == '1') {
         // Get the blog post
         $post = $this->getBlog();
         // Load language
         EB::loadLanguages();
         $config = EB::config();
         // Integrations with EasyDiscuss
         EB::easydiscuss()->log('easyblog.delete.comment', $this->created_by, JText::sprintf('COM_EASYBLOG_EASYDISCUSS_HISTORY_DELETE_COMMENT', $post->title));
         EB::easydiscuss()->addPoint('easyblog.delete.comment', $this->created_by);
         EB::easydiscuss()->addBadge('easyblog.delete.comment', $this->created_by);
         // AlphaUserPoints
         EB::aup()->assign('plgaup_easyblog_delete_comment', $this->created_by, JText::_('COM_EASYBLOG_AUP_COMMENT_DELETED'));
         // Assign EasySocial points
         EB::easysocial()->assignPoints('comments.remove', $this->created_by);
         // Deduct points from the comment author
         EB::jomsocial()->assignPoints('com_easyblog.comments.remove', $this->created_by);
         // Deduct points from the blog post author
         if ($my->id != $post->created_by) {
             // Deduct EasySocial points
             EB::easysocial()->assignPoints('comments.remove.author', $post->created_by);
             // JomSocial
             EB::jomsocial()->assignPoints('com_easyblog.comments.removeblogger', $post->created_by);
             // AUP
             EB::aup()->assignPoints('plgaup_easyblog_delete_comment_blogger', $post->created_by, JText::sprintf('COM_EASYBLOG_AUP_COMMENT_DELETED_BLOGGER', $url, $post->title));
         }
     }
     return $state;
 }
예제 #10
0
 /**
  * Retrieves a list of blog posts by specific month
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return
  */
 public function getArchivePostByMonth($month = '', $year = '', $showPrivate = false)
 {
     $db = EB::db();
     $user = JFactory::getUser();
     $config = EB::config();
     // used for privacy
     $queryWhere = '';
     $queryExclude = '';
     $queryExcludePending = '';
     $excludeCats = array();
     if ($user->id == 0) {
         $showPrivate = false;
     }
     // Blog privacy setting
     // @integrations: jomsocial privacy
     $privateBlog = '';
     if (EB::easysocial()->exists() && $config->get('integrations_easysocial_privacy') && !EB::isSiteAdmin()) {
         $esPrivacyQuery = EB::easysocial()->buildPrivacyQuery('a');
         $privateBlog .= $esPrivacyQuery;
     } else {
         if ($config->get('main_jomsocial_privacy') && EB::jomsocial()->exists() && !EB::isSiteAdmin()) {
             $friendsModel = CFactory::getModel('Friends');
             $friends = $friendsModel->getFriendIds($user->id);
             // Insert query here.
             $privateBlog .= ' AND (';
             $privateBlog .= ' (a.`access`= 0 ) OR';
             $privateBlog .= ' ( (a.`access` = 20) AND (' . $db->Quote($user->id) . ' > 0 ) ) OR';
             if (!$friends) {
                 $privateBlog .= ' ( (a.`access` = 30) AND ( 1 = 2 ) ) OR';
             } else {
                 $privateBlog .= ' ( (a.`access` = 30) AND ( a.' . $db->nameQuote('created_by') . ' IN (' . implode(',', $friends) . ') ) ) OR';
             }
             $privateBlog .= ' ( (a.`access` = 40) AND ( a.' . $db->nameQuote('created_by') . '=' . $user->id . ') )';
             $privateBlog .= ' )';
         } else {
             if ($user->id == 0) {
                 $privateBlog .= ' AND a.`access` = ' . $db->Quote(0);
             }
         }
     }
     // Join the query ?
     $privateBlog = $showPrivate ? '' : $privateBlog;
     $isJSGrpPluginInstalled = false;
     $isJSGrpPluginInstalled = JPluginHelper::isEnabled('system', 'groupeasyblog');
     $isEventPluginInstalled = JPluginHelper::isEnabled('system', 'eventeasyblog');
     $isJSInstalled = false;
     // need to check if the site installed jomsocial.
     if (EB::jomsocial()->exists()) {
         $isJSInstalled = true;
     }
     $includeJSGrp = $isJSGrpPluginInstalled && $isJSInstalled ? true : false;
     $includeJSEvent = $isEventPluginInstalled && $isJSInstalled ? true : false;
     // contribution type sql
     $contributor = EB::contributor();
     $contributeSQL = ' AND ( (a.`source_type` = ' . $db->Quote(EASYBLOG_POST_SOURCE_SITEWIDE) . ') ';
     if ($config->get('main_includeteamblogpost')) {
         $contributeSQL .= $contributor::genAccessSQL(EASYBLOG_POST_SOURCE_TEAM, 'a');
     }
     if ($includeJSEvent) {
         $contributeSQL .= $contributor::genAccessSQL(EASYBLOG_POST_SOURCE_JOMSOCIAL_EVENT, 'a');
     }
     if ($includeJSGrp) {
         $contributeSQL .= $contributor::genAccessSQL(EASYBLOG_POST_SOURCE_JOMSOCIAL_GROUP, 'a');
     }
     if (EB::easysocial()->exists()) {
         $contributeSQL .= $contributor::genAccessSQL(EASYBLOG_POST_SOURCE_EASYSOCIAL_GROUP, 'a');
         $contributeSQL .= $contributor::genAccessSQL(EASYBLOG_POST_SOURCE_EASYSOCIAL_EVENT, 'a');
     }
     $contributeSQL .= ')';
     $queryWhere .= $contributeSQL;
     //get teamblogs id.
     $query = '';
     $extraSQL = '';
     // If this is on blogger mode, we need to only pick items from the blogger.
     $blogger = EBR::isBloggerMode();
     if ($blogger !== false) {
         $extraSQL = ' AND a.`created_by` = ' . $db->Quote($blogger);
     }
     $tzoffset = EB::date()->getOffSet(true);
     $query = 'SELECT a.*, DAY( DATE_ADD(a.`created`, INTERVAL ' . $tzoffset . ' HOUR) ) AS day,';
     $query .= ' MONTH( DATE_ADD(a.`created`, INTERVAL ' . $tzoffset . ' HOUR) ) AS month,';
     $query .= ' YEAR( DATE_ADD(a.`created`, INTERVAL ' . $tzoffset . ' HOUR) ) AS year ';
     $query .= ' FROM ' . $db->nameQuote('#__easyblog_post') . ' as a';
     $query .= ' WHERE a.`published` = ' . $db->Quote(EASYBLOG_POST_PUBLISHED) . ' ';
     $query .= ' AND a.' . $db->quoteName('state') . ' = ' . $db->Quote(EASYBLOG_POST_NORMAL) . ' ';
     $query .= $privateBlog . ' ';
     $query .= ' AND (a.`created` > ' . $db->Quote($year . '-' . $month . '-01 00:00:00') . ' AND a.`created` < ' . $db->Quote($year . '-' . $month . '-31 23:59:59') . ') ';
     // If do not display private posts, we need to append additional queries here.
     if (!$showPrivate) {
         // sql for category access
         $catLib = EB::category();
         $catAccessSQL = $catLib->genAccessSQL('a.`id`');
         $query .= ' AND (' . $catAccessSQL . ')';
     }
     $query .= $extraSQL . ' ';
     $query .= $queryWhere;
     $query .= ' ORDER BY a.`created` ASC ';
     // echo $query;exit;
     $db->setQuery($query);
     $result = $db->loadObjectList();
     $postCount = new EasyblogCalendarObject($month, $year);
     if (!empty($result)) {
         foreach ($result as $row) {
             $post = EB::post($row->id);
             // $post->bind($row);
             $post = EB::formatter('entry', $post);
             // var_dump($row);exit;
             if ($postCount->{$year}->{$month}->{$row->day} == 0) {
                 $postCount->{$year}->{$month}->{$row->day} = array($post);
             } else {
                 array_push($postCount->{$year}->{$month}->{$row->day}, $post);
             }
         }
     }
     return $postCount;
 }
예제 #11
0
 /**
  * Retrieve a list of blog posts from a specific list of categories
  *
  * @since	4.0
  * @access	public
  * @param	string
  * @return
  */
 public function getPosts($categories, $limit = null)
 {
     $db = EB::db();
     $my = JFactory::getUser();
     $config = EB::config();
     // Determines if this is currently on blogger mode
     $isBloggerMode = EasyBlogRouter::isBloggerMode();
     // use in generating category access sql
     $catAccess = array();
     $catAccess['include'] = $categories;
     $isJSGrpPluginInstalled = false;
     $isJSGrpPluginInstalled = JPluginHelper::isEnabled('system', 'groupeasyblog');
     $isEventPluginInstalled = JPluginHelper::isEnabled('system', 'eventeasyblog');
     $isJSInstalled = false;
     // need to check if the site installed jomsocial.
     if (EB::jomsocial()->exists()) {
         $isJSInstalled = true;
     }
     $includeJSGrp = $isJSGrpPluginInstalled && $isJSInstalled ? true : false;
     $includeJSEvent = $isEventPluginInstalled && $isJSInstalled ? true : false;
     // contribution type sql
     $contributor = EB::contributor();
     $contributeSQL = ' AND ( (a.`source_type` = ' . $db->Quote(EASYBLOG_POST_SOURCE_SITEWIDE) . ') ';
     if ($config->get('main_includeteamblogpost')) {
         $contributeSQL .= $contributor::genAccessSQL(EASYBLOG_POST_SOURCE_TEAM, 'a');
     }
     if ($includeJSEvent) {
         $contributeSQL .= $contributor::genAccessSQL(EASYBLOG_POST_SOURCE_JOMSOCIAL_EVENT, 'a');
     }
     if ($includeJSGrp) {
         $contributeSQL .= $contributor::genAccessSQL(EASYBLOG_POST_SOURCE_JOMSOCIAL_GROUP, 'a');
     }
     // Test if easysocial exists on the site
     if (EB::easysocial()->exists()) {
         $contributeSQL .= $contributor::genAccessSQL(EASYBLOG_POST_SOURCE_EASYSOCIAL_GROUP, 'a');
         $contributeSQL .= $contributor::genAccessSQL(EASYBLOG_POST_SOURCE_EASYSOCIAL_EVENT, 'a');
     }
     $contributeSQL .= ')';
     $query = array();
     $query[] = 'SELECT a.* FROM ' . $db->quoteName('#__easyblog_post') . ' AS a';
     // Build the WHERE clauses
     $query[] = 'WHERE a.' . $db->quoteName('published') . '=' . $db->Quote(EASYBLOG_POST_PUBLISHED);
     $query[] = 'AND a.' . $db->quoteName('state') . '=' . $db->Quote(EASYBLOG_POST_NORMAL);
     // If this is on blogger mode, fetch items created by the current author only
     if ($isBloggerMode !== false) {
         $query[] = ' AND a.' . $db->quoteName('created_by') . '=' . $db->Quote($isBloggerMode);
     } else {
         // Get the author id based on the category menu
         $authorId = EB::getCategoryMenuBloggerId();
         if ($authorId) {
             $query[] = ' AND a.' . $db->quoteName('created_by') . '=' . $db->Quote($authorId);
         }
     }
     //sql for blog contribution
     $query[] = $contributeSQL;
     // sql for category access
     $catLib = EB::category();
     $catAccessSQL = $catLib->genAccessSQL('a.`id`', $catAccess);
     $query[] = 'AND (' . $catAccessSQL . ')';
     // If user is a guest, ensure that they can really view the blog post
     if ($this->my->guest) {
         $query[] = 'AND a.' . $db->quoteName('access') . '=' . $db->Quote(BLOG_PRIVACY_PUBLIC);
     }
     // Ensure that the blog posts is available site wide
     // $query[] = 'AND a.' . $db->quoteName('source_id') . '=' . $db->Quote('0');
     // Filter by language
     $language = EB::getCurrentLanguage();
     if ($language) {
         $query[] = 'AND (a.' . $db->quoteName('language') . '=' . $db->Quote($language) . ' OR a.' . $db->quoteName('language') . '=' . $db->Quote('*') . ' OR a.' . $db->quoteName('language') . '=' . $db->Quote('') . ')';
     }
     // Ordering options
     $ordering = $config->get('layout_postsort', 'DESC');
     // Order the posts
     $query[] = 'ORDER BY a.' . $db->quoteName('created') . ' ' . $ordering;
     // Set the pagination
     if (!is_null($limit)) {
         // Glue back the sql queries into a single string.
         $queryCount = implode(' ', $query);
         $queryCount = str_ireplace('SELECT a.*', 'SELECT COUNT(1)', $queryCount);
         $db->setQuery($queryCount);
         $count = $db->loadResult();
         $limit = $limit == 0 ? $this->getState('limit') : $limit;
         $limitstart = $this->input->get('limitstart', $this->getState('limitstart'), 'int');
         // Set the limit
         $query[] = 'LIMIT ' . $limitstart . ',' . $limit;
         $this->_pagination = EB::pagination($count, $limitstart, $limit);
     }
     // Glue back the sql queries into a single string.
     $query = implode(' ', $query);
     // Debug
     // echo str_ireplace('#__', 'jos_', $query);exit;
     $db->setQuery($query);
     if ($db->getErrorNum() > 0) {
         JError::raiseError($db->getErrorNum(), $db->getErrorMsg() . $db->stderr());
     }
     $result = $db->loadObjectList();
     return $result;
 }
예제 #12
0
 /**
  * Renders a list of associates the author has to the site
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return
  */
 public function listAssociates()
 {
     // Associates may compromise of teams, groups, events etc.
     $associates = array('teams' => array(), 'events' => array(), 'groups' => array());
     // @TODO: Check if the user is really allowed to use this
     if (!$this->my->id) {
         return $this->ajax->reject(JText::_('COM_EASYBLOG_NOT_ALLOWED'));
     }
     // Get a list of selected items
     $source_id = $this->input->get('source_id', 0, 'int');
     $source_type = $this->input->get('source_type', '', 'default');
     // List teams the user joined on the site
     $model = EB::model('TeamBlogs');
     $teams = $model->getTeamJoined($this->my->id);
     if ($teams) {
         foreach ($teams as $team) {
             $obj = new stdClass();
             $obj->title = $team->title;
             $obj->source_id = $team->id;
             $obj->source_type = EASYBLOG_POST_SOURCE_TEAM;
             $obj->type = 'team';
             $obj->avatar = $team->getAvatar();
             $associates['teams'][] = $obj;
         }
     }
     // EasySocial groups
     $groups = EB::easysocial()->getGroups();
     $events = EB::easysocial()->getEvents();
     // List groups the user joined on the site
     $groups = array_merge($groups, EB::jomsocial()->getGroups());
     $events = array_merge($events, EB::jomsocial()->getEvents());
     // Assign them into the main object.
     $associates['groups'] = $groups;
     $associates['events'] = $events;
     $template = EB::template();
     $template->set('source_id', $source_id);
     $template->set('source_type', $source_type);
     $template->set('associates', $associates);
     $output = $template->output('site/composer/form/associates');
     return $this->ajax->resolve($output);
 }
예제 #13
0
 /**
  * Sets this post as a featured post
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return
  */
 public function setFeatured()
 {
     $model = EB::model('Featured');
     $state = $model->makeFeatured(EBLOG_FEATURED_BLOG, $this->id);
     if (!$state) {
         return false;
     }
     // @EasySocial Integrations
     EB::easysocial()->createFeaturedBlogStream($this);
     // @JomSocial Integrations
     EB::jomsocial()->createFeaturedBlogStream($this);
     // Notify author of the blog post that their blog post is featured on the site
     $this->notify(false, 0, true);
     return true;
 }
예제 #14
0
 /**
  * Uploads a user avatar
  *
  * @since	4.0
  * @access	public
  * @param	string
  * @return
  */
 public function upload($fileData, $userId = false)
 {
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     // Check if the user is allowed to upload avatar
     $acl = EB::acl();
     // Ensure that the user really has access to upload avatar
     if (!$acl->get('upload_avatar')) {
         $this->setError('COM_EASYBLOG_NO_PERMISSION_TO_UPLOAD_AVATAR');
         return false;
     }
     // Get the current user
     $user = JFactory::getUser();
     // If there is userId passed, means this is from backend.
     // We cannot get the current logged in user because it will always be the admin.
     if ($userId) {
         $user = JFactory::getUser($userId);
     }
     $app = JFactory::getApplication();
     $config = EB::config();
     $path = $config->get('main_avatarpath');
     $path = rtrim($path, '/');
     $relativePath = $path;
     $absolutePath = JPATH_ROOT . '/' . $path;
     // If the absolute path does not exist, create it first
     if (!JFolder::exists($absolutePath)) {
         JFolder::create($absolutePath);
         // Copy the index.html file over to this new folder
         JFile::copy(JPATH_ROOT . '/components/com_easyblog/index.html', $absolutePath . '/index.html');
     }
     // The file data should have a name
     if (!isset($fileData['name'])) {
         return false;
     }
     // Generate a better name for the file
     $fileData['name'] = $user->id . '_' . JFile::makeSafe($fileData['name']);
     // Get the relative path
     $relativeFile = $relativePath . '/' . $fileData['name'];
     // Get the absolute file path
     $absoluteFile = $absolutePath . '/' . $fileData['name'];
     // Test if the file is upload-able
     $message = '';
     if (!EB::image()->canUpload($fileData, $message)) {
         $this->setError($message);
         return false;
     }
     // Determines if the web server is generating errors
     if ($fileData['error'] != 0) {
         $this->setError($fileData['error']);
         return false;
     }
     // We need to delete the old avatar
     $profile = EB::user($user->id);
     // Get the old avatar
     $oldAvatar = $profile->avatar;
     $isNew = false;
     // Delete the old avatar first
     if ($oldAvatar != 'default.png' && $oldAvatar != 'default_blogger.png') {
         $session = JFactory::getSession();
         $sessionId = $session->getToken();
         $oldAvatarPath = $absolutePath . '/' . $oldAvatar;
         if (JFile::exists($oldAvatarPath)) {
             JFile::delete($oldAvatarPath);
         }
     } else {
         $isNew = true;
     }
     $width = EBLOG_AVATAR_LARGE_WIDTH;
     $height = EBLOG_AVATAR_LARGE_HEIGHT;
     $image = EB::simpleimage();
     $image->load($fileData['tmp_name']);
     $image->resizeToFill($width, $height);
     $image->save($absoluteFile, $image->type);
     if ($isNew && $config->get('main_jomsocial_userpoint')) {
         EB::jomsocial()->assignPoints('com_easyblog.avatar.upload', $user->id);
     }
     return $fileData['name'];
 }
예제 #15
0
 /**
  * Stores the blog post
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return
  */
 public function store($log = true)
 {
     // Load language file from the front end.
     EB::loadLanguages();
     // Whenever the blog post is stored, we need to clear the cache.
     $cache = EB::getCache();
     $cache->clean('com_easyblog');
     $cache->clean('_system');
     $cache->clean('page');
     // Get easyblog's config
     $config = EB::config();
     // Get the current logged in user.
     $my = JFactory::getUser();
     // @rule: no guest allowed to create blog post.
     if (JRequest::getVar('task', '') != 'cron' && JRequest::getVar('task', '') != 'cronfeed' && empty($my->id)) {
         $this->setError(JText::_('COM_EASYBLOG_YOU_ARE_NOT_LOGIN'));
         return false;
     }
     $under_approval = false;
     if (isset($this->under_approval)) {
         $under_approval = true;
         // now we need to reset this variable from the blog object.
         unset($this->under_approval);
     }
     // @trigger: onBeforeSave
     $this->triggerBeforeSave();
     // @rule: Determine if this record is new or not.
     if (empty($this->isnew)) {
         $isNew = empty($this->id) ? true : false;
     } else {
         $isNew = true;
     }
     // @rule: Get the rulesets for this user.
     $acl = EB::acl();
     // @rule: Process badword filters for title here.
     $blockedWord = EasyBlogHelper::getHelper('String')->hasBlockedWords($this->title);
     if ($blockedWord !== false) {
         $this->setError(JText::sprintf('COM_EASYBLOG_BLOG_TITLE_CONTAIN_BLOCKED_WORDS', $blockedWord));
         return false;
     }
     // @rule: Check for minimum words in the content if required.
     if ($config->get('main_post_min') && $this->_checkLength) {
         $minimum = $config->get('main_post_length');
         $total = JString::strlen(strip_tags($this->intro . $this->content));
         if ($total < $minimum) {
             $this->setError(JText::sprintf('COM_EASYBLOG_CONTENT_LESS_THAN_MIN_LENGTH', $minimum));
             return false;
         }
     }
     // @rule: Check for invalid title
     if (empty($this->title) || $this->title == JText::_('COM_EASYBLOG_DASHBOARD_WRITE_DEFAULT_TITLE')) {
         $this->setError(JText::_('COM_EASYBLOG_DASHBOARD_SAVE_EMPTY_TITLE_ERROR'));
         return false;
     }
     // @rule: For edited blogs, ensure that they have permissions to edit it.
     if (!$isNew && $this->created_by != JFactory::getUser()->id && !EasyBlogHelper::isSiteAdmin() && !$acl->get('moderate_entry')) {
         // @task: Only throw error when this blog post is not a team blog post and it's not owned by the current logged in user.
         $model = EB::model('TeamBlogs');
         $contribution = $model->getBlogContributed($this->id);
         if (!$contribution || !$model->checkIsTeamAdmin(JFactory::getUser()->id, $contribution->team_id)) {
             $this->setError(JText::_('COM_EASYBLOG_NO_PERMISSION_TO_EDIT_BLOG'));
             return false;
         }
     }
     // Filter / strip contents that are not allowed
     $filterTags = EasyBlogHelper::getHelper('Acl')->getFilterTags();
     $filterAttributes = EasyBlogHelper::getHelper('Acl')->getFilterAttributes();
     // @rule: Apply filtering on contents
     jimport('joomla.filter.filterinput');
     $inputFilter = JFilterInput::getInstance($filterTags, $filterAttributes, 1, 1, 0);
     $inputFilter->tagBlacklist = $filterTags;
     $inputFilter->attrBlacklist = $filterAttributes;
     $filterTpe = EasyBlogHelper::getJoomlaVersion() >= '1.6' ? 'html' : 'string';
     if (count($filterTags) > 0 && !empty($filterTags[0]) || count($filterAttributes) > 0 && !empty($filterAttributes[0])) {
         $this->intro = $inputFilter->clean($this->intro, $filterTpe);
         $this->content = $inputFilter->clean($this->content, $filterTpe);
     }
     // @rule: Process badword filters for content here.
     $blockedWord = EasyBlogHelper::getHelper('String')->hasBlockedWords($this->intro . $this->content);
     if ($blockedWord !== false) {
         $this->setError(JText::sprintf('COM_EASYBLOG_BLOG_POST_CONTAIN_BLOCKED_WORDS', $blockedWord));
         return false;
     }
     // @rule: Test for the empty-ness
     if (empty($this->intro) && empty($this->content)) {
         $this->setError(JText::_('COM_EASYBLOG_DASHBOARD_SAVE_CONTENT_ERROR'));
     }
     $state = parent::store();
     $source = JRequest::getVar('blog_contribute_source', 'easyblog');
     // if this is blog edit, then we should see the column isnew to determine
     // whether the post is really new or not.
     if (!$isNew) {
         $isNew = $this->isnew;
     }
     // this one is needed for the trigger to work properly.
     $this->isnew = $isNew;
     // @trigger: onAfterSave
     $this->triggerAfterSave();
     // @task: If auto featured is enabled, we need to feature the blog post automatically since the blogger is featured.
     if ($config->get('main_autofeatured', 0) && EB::isFeatured('blogger', $this->created_by) && !EB::isFeatured('post', $this->id)) {
         // just call the model file will do as we do not want to create stream on featured action at this migration.
         $modelF = EB::model('Featured');
         $modelF->makeFeatured('post', $this->id);
     }
     // @task: This is when the blog is either created or updated.
     if ($source == 'easyblog' && $state && $this->published == EASYBLOG_POST_PUBLISHED && $log) {
         $category = EB::table('Category');
         $category->load($this->category_id);
         $easysocial = EasyBlogHelper::getHelper('EasySocial');
         if ($category->private == 0) {
             // @rule: Add new stream item in jomsocial
             EB::jomsocial()->addBlogActivity($this, $isNew);
         }
         // @rule: Add stream for easysocial
         if ($config->get('integrations_easysocial_stream_newpost') && $easysocial->exists() && $isNew) {
             $easysocial->createBlogStream($this, $isNew);
         }
         // update privacy in easysocial.
         if ($config->get('integrations_easysocial_privacy') && $easysocial->exists()) {
             $easysocial->updateBlogPrivacy($this);
         }
     }
     if ($source == 'easyblog' && $state && $this->published == EASYBLOG_POST_PUBLISHED && $isNew && $log) {
         // @rule: Send email notifications out to subscribers.
         $author = EB::user($this->created_by);
         // Ping pingomatic
         EB::pingomatic()->ping($this);
         // Assign EasySocial points
         $easysocial = EasyBlogHelper::getHelper('EasySocial');
         if ($easysocial->exists()) {
             $easysocial->assignPoints('blog.create', $this->created_by);
         }
         // @rule: Add userpoints for jomsocial
         if ($config->get('main_jomsocial_userpoint')) {
             $path = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_community' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'userpoints.php';
             if (JFile::exists($path)) {
                 require_once $path;
                 CUserPoints::assignPoint('com_easyblog.blog.add', $this->created_by);
             }
         }
         $link = $this->getExternalBlogLink('index.php?option=com_easyblog&view=entry&id=' . $this->id);
         // @rule: Add notifications for jomsocial 2.6
         if ($config->get('integrations_jomsocial_notification_blog')) {
             // Get list of users who subscribed to this blog.
             $target = $this->getRegisteredSubscribers('new', array($this->created_by));
             EasyBlogHelper::getHelper('JomSocial')->addNotification(JText::sprintf('COM_EASYBLOG_JOMSOCIAL_NOTIFICATIONS_NEW_BLOG', str_replace("administrator/", "", $author->getProfileLink()), $author->getName(), $link, $this->title), 'easyblog_new_blog', $target, $author, $link);
         }
         // Get list of users who subscribed to this blog.
         // @rule: Add notifications for easysocial
         if ($config->get('integrations_easysocial_notifications_newpost') && $easysocial->exists()) {
             $easysocial->notifySubscribers($this, 'new.post');
         }
         // @rule: Add indexer for easysocial
         if ($config->get('integrations_easysocial_indexer_newpost') && $easysocial->exists()) {
             $easysocial->addIndexerNewBlog($this);
         }
         // @rule: Integrations with EasyDiscuss
         EasyBlogHelper::getHelper('EasyDiscuss')->log('easyblog.new.blog', $this->created_by, JText::sprintf('COM_EASYBLOG_EASYDISCUSS_HISTORY_NEW_BLOG', $this->title));
         EasyBlogHelper::getHelper('EasyDiscuss')->addPoint('easyblog.new.blog', $this->created_by);
         EasyBlogHelper::getHelper('EasyDiscuss')->addBadge('easyblog.new.blog', $this->created_by);
         // Assign badge for users that report blog post.
         // Only give points if the viewer is viewing another person's blog post.
         EasyBlogHelper::getHelper('EasySocial')->assignBadge('blog.create', JText::_('COM_EASYBLOG_EASYSOCIAL_BADGE_CREATE_BLOG_POST'));
         if ($config->get('integrations_easydiscuss_notification_blog')) {
             // Get list of users who subscribed to this blog.
             $target = $this->getRegisteredSubscribers('new', array($this->created_by));
             EasyBlogHelper::getHelper('EasyDiscuss')->addNotification($this, JText::sprintf('COM_EASYBLOG_EASYDISCUSS_NOTIFICATIONS_NEW_BLOG', $author->getName(), $this->title), EBLOG_NOTIFICATIONS_TYPE_BLOG, $target, $this->created_by, $link);
         }
         // AUP
         EB::aup()->assignPoints('plgaup_easyblog_add_blog', $this->created_by, JText::sprintf('COM_EASYBLOG_AUP_NEW_BLOG_CREATED', $this->getPermalink(), $this->title));
         // Update the isnew column so that if user edits this entry again, it doesn't send any notifications the second time.
         $this->isnew = $this->published && $this->isnew ? 0 : 1;
         $this->store(false);
     }
     return $state;
 }
예제 #16
0
 /**
  * Responsible to display the entire component output
  *
  * @since	4.0
  * @access	public
  * @param	string
  * @return
  */
 public function display($tpl = null)
 {
     if ($this->doc->getType() == 'html') {
         // Render headers on the site
         $this->renderHeaders();
         // Get the contents from the view
         $namespace = 'site/' . $tpl;
         $contents = $this->theme->output($namespace);
         // Get menu suffix
         $suffix = $this->getMenuSuffix();
         // Get the current view.
         $view = $this->getName();
         // Get the current task
         $layout = $this->getLayout();
         // If this is a dashboard theme, we need to let the theme object know
         $options = array();
         if ($this->getName() == 'dashboard') {
             $options['dashboard'] = true;
         }
         // We need to append the contents back into the main structure
         $theme = EB::template(null, $options);
         // $theme = $this->theme;
         $tmpl = $this->input->get('tmpl');
         // Get the toolbar
         $toolbar = '';
         if ($tmpl != 'component' && $view == 'dashboard') {
             $toolbar = $this->getDashboardToolbar();
         }
         if ($tmpl != 'component' && $view != 'dashboard') {
             $toolbar = $this->getToolbar();
         }
         if ($view == 'entry' && $layout != 'preview') {
             $id = $this->input->get('id', 0, 'int');
             $post = EB::post($id);
             if (!$post->isStandardSource()) {
                 $contribution = $post->getBlogContribution();
                 $contributionHeader = $contribution->getHeader();
                 if ($contributionHeader) {
                     $toolbar = '';
                 }
             }
         }
         // Get the theme name
         $themeName = $theme->getName();
         // There is a possibility that the site uses a different font heading
         $headingFont = $this->getHeadingFont();
         // We attach the script tags on the bottom of the page
         $scripts = EB::helper('Scripts')->getScripts();
         // Jomsocial toolbar
         $jsToolbar = EB::jomsocial()->getToolbar();
         $theme->set('jsToolbar', $jsToolbar);
         $lang = JFactory::getLanguage();
         $rtl = $lang->isRTL();
         if ($rtl) {
             $this->doc->addStyleSheet(JURI::root() . 'components/com_easyblog/themes/' . $themeName . '/styles/style-rtl.css');
         }
         $theme->set('rtl', $rtl);
         $theme->set('bootstrap', '');
         $theme->set('themeName', $themeName);
         $theme->set('headingFont', $headingFont);
         $theme->set('jscripts', $scripts);
         $theme->set('toolbar', $toolbar);
         $theme->set('contents', $contents);
         $theme->set('suffix', $suffix);
         $theme->set('layout', $layout);
         $theme->set('view', $view);
         $output = $theme->output('site/structure/default');
         echo $output;
         return;
     }
     if ($this->doc->getType() == 'json') {
         // Determines if the json result should be wrapped with a callback.
         $callback = $this->input->get('callback', '', 'cmd');
         $output = json_encode($this->props);
         if ($callback) {
             $output = $callback . '(' . $output . ')';
         }
         header('Content-type: text/x-json; UTF-8');
         echo $output;
         exit;
     }
     // dump($tpl);
 }
예제 #17
0
 /**
  * Retrieve a list of places on the site.
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return
  */
 public static function getPlaces($user = null, EasyBlogPost $post = null)
 {
     $config = EB::config();
     $acl = EB::acl();
     // Get the current logged in user
     $my = JFactory::getUser($user);
     $places = array();
     // Get the current post's folder
     $places[] = self::getPlace('post');
     // All articles created by the author or admin
     $places[] = self::getPlace('posts');
     // My Media
     $places[] = self::getPlace('user:'******'main_media_manager_place_shared_media') && $acl->get('media_places_shared')) {
         $places[] = self::getPlace('shared');
     }
     // Flickr Integrations
     if ($config->get('layout_media_flickr') && $config->get('integrations_flickr_api_key') != '' && $config->get('integrations_flickr_secret_key') && $acl->get('media_places_flickr')) {
         $places[] = self::getPlace('flickr');
     }
     // EasySocial
     if ($config->get('integrations_easysocial_album') && $acl->get('media_places_album') && EB::easysocial()->exists()) {
         $places[] = self::getPlace('easysocial');
     }
     // JomSocial
     if ($config->get('integrations_jomsocial_album') && $acl->get('media_places_album') && EB::jomsocial()->exists()) {
         $places[] = self::getPlace('jomsocial');
     }
     // If the user is allowed
     if (EB::isSiteAdmin()) {
         // All Users
         $places[] = self::getPlace('users');
     }
     return $places;
 }
예제 #18
0
 public function preloadPosts($catIds)
 {
     $db = EB::db();
     $config = EB::config();
     $limit = EB::call('Pagination', 'getLimit', array(EBLOG_PAGINATION_CATEGORIES));
     // Determines if this is currently on blogger mode
     $isBloggerMode = EasyBlogRouter::isBloggerMode();
     $query = array();
     $i = 1;
     foreach ($catIds as $cid => $cIds) {
         $p = 'p' . $i;
         $a = 'a' . $i;
         $f = 'f' . $i;
         $isJSGrpPluginInstalled = false;
         $isJSGrpPluginInstalled = JPluginHelper::isEnabled('system', 'groupeasyblog');
         $isEventPluginInstalled = JPluginHelper::isEnabled('system', 'eventeasyblog');
         $isJSInstalled = false;
         // need to check if the site installed jomsocial.
         if (EB::jomsocial()->exists()) {
             $isJSInstalled = true;
         }
         $includeJSGrp = $isJSGrpPluginInstalled && $isJSInstalled ? true : false;
         $includeJSEvent = $isEventPluginInstalled && $isJSInstalled ? true : false;
         // contribution type sql
         $contributor = EB::contributor();
         $contributeSQL = " AND ( ({$p}.`source_type` = " . $db->Quote(EASYBLOG_POST_SOURCE_SITEWIDE) . ") ";
         if ($config->get('main_includeteamblogpost')) {
             $contributeSQL .= $contributor::genAccessSQL(EASYBLOG_POST_SOURCE_TEAM, $p);
         }
         if ($includeJSEvent) {
             $contributeSQL .= $contributor::genAccessSQL(EASYBLOG_POST_SOURCE_JOMSOCIAL_EVENT, $p);
         }
         if ($includeJSGrp) {
             $contributeSQL .= $contributor::genAccessSQL(EASYBLOG_POST_SOURCE_JOMSOCIAL_GROUP, $p);
         }
         // Test if easysocial exists on the site
         if (EB::easysocial()->exists()) {
             $contributeSQL .= $contributor::genAccessSQL(EASYBLOG_POST_SOURCE_EASYSOCIAL_GROUP, $p);
             $contributeSQL .= $contributor::genAccessSQL(EASYBLOG_POST_SOURCE_EASYSOCIAL_EVENT, $p);
         }
         $contributeSQL .= ")";
         $tmp = "(select {$p}.*, " . $db->Quote($cid) . " as `category_id`, {$f}.`id` as `featured`";
         $tmp .= "\tfrom `#__easyblog_post` as {$p}";
         $tmp .= "\t\tinner join `#__easyblog_post_category` as {$a} on {$p}.`id` = {$a}.`post_id`";
         $tmp .= " LEFT JOIN `#__easyblog_featured` AS {$f}";
         $tmp .= " \tON {$p}.`id` = {$f}.`content_id` AND {$f}.`type` = " . $db->Quote('post');
         if (count($cIds) == 1) {
             $tmp .= " where {$a}.`category_id` = " . $db->Quote($cIds[0]);
         } else {
             $tmp .= " where {$a}.`category_id` IN (" . implode(',', $cIds) . ")";
         }
         $tmp .= " and {$p}.`published` = " . $db->Quote(EASYBLOG_POST_PUBLISHED);
         $tmp .= " and {$p}.`state` = " . $db->Quote(EASYBLOG_POST_NORMAL);
         if ($isBloggerMode !== false) {
             $tmp .= " AND {$p}." . $db->qn('created_by') . " = " . $db->Quote($isBloggerMode);
         } else {
             // Get the author id based on the category menu
             $authorId = EB::getCategoryMenuBloggerId();
             if ($authorId) {
                 $tmp .= " AND {$p}." . $db->qn('created_by') . " = " . $db->Quote($authorId);
             }
         }
         // If user is a guest, ensure that they can really view the blog post
         if ($this->my->guest) {
             $tmp .= " AND {$p}." . $db->qn('access') . " = " . $db->Quote(BLOG_PRIVACY_PUBLIC);
         }
         // Ensure that the blog posts is available site wide
         $tmp .= $contributeSQL;
         // $tmp .= " AND $p." . $db->qn('source_id') . " = " . $db->Quote("0");
         // Filter by language
         $language = EB::getCurrentLanguage();
         if ($language) {
             $tmp .= " AND ({$p}." . $db->qn('language') . "=" . $db->Quote($language) . " OR {$p}." . $db->qn('language') . "=" . $db->Quote('*') . " OR {$p}." . $db->qn('language') . "=" . $db->Quote('') . ")";
         }
         $tmp .= " order by {$p}.`created` desc";
         $tmp .= " limit " . $limit . ")";
         $query[] = $tmp;
         $i++;
     }
     $query = implode(' UNION ALL ', $query);
     // echo $query;exit;
     $db->setQuery($query);
     $results = $db->loadObjectList();
     $posts = array();
     if ($results) {
         foreach ($results as $row) {
             $posts[$row->category_id][] = $row;
         }
     }
     return $posts;
 }