Exemplo n.º 1
0
 public function _buildQueryLanguage()
 {
     $mainframe = JFactory::getApplication();
     $my = JFactory::getUser();
     $db = EB::db();
     $languageQ = '';
     // @rule: When language filter is enabled, we need to detect the appropriate contents
     $filterLanguage = JFactory::getApplication()->getLanguageFilter();
     if ($filterLanguage) {
         $languageQ .= EBR::getLanguageQuery('AND', 'a.language');
     }
     return $languageQ;
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 public function getArchivePostCounts($yearStart = '', $yearStop = '0', $excludeCats = '', $includeCats = '', $filter = '', $filterId = '')
 {
     $db = EB::db();
     $user = JFactory::getUser();
     $config = EB::config();
     $catAccess = array();
     if (empty($yearStart)) {
         $year = $this->getArchiveMinMaxYear();
         $yearStart = $year['maxyear'];
     }
     if (!empty($yearStop)) {
         $fr = $yearStart - 1;
         $to = $yearStop + 1;
     } else {
         $fr = $yearStart - 1;
         $to = $yearStart + 1;
     }
     if (!is_array($excludeCats) && !empty($excludeCats)) {
         $excludeCats = explode(',', $excludeCats);
     } else {
         if (!is_array($excludeCats) && empty($excludeCats)) {
             $excludeCats = array();
         }
     }
     if (!is_array($includeCats) && !empty($includeCats)) {
         $includeCats = explode(',', $includeCats);
     } else {
         if (!is_array($includeCats) && empty($includeCats)) {
             $includeCats = array();
         }
     }
     $includeCats = array_diff($includeCats, $excludeCats);
     if (!empty($excludeCats) && count($excludeCats) >= 1) {
         $catAccess['exclude'] = $excludeCats;
     }
     if (!empty($includeCats) && count($includeCats) >= 1) {
         $catAccess['include'] = $includeCats;
     }
     //blog privacy setting
     // @integrations: jomsocial privacy
     $privateBlog = '';
     $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_community' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'core.php';
     $easysocial = EasyBlogHelper::getHelper('EasySocial');
     if ($config->get('integrations_easysocial_privacy') && $easysocial->exists() && !EasyBlogHelper::isSiteAdmin()) {
         $esPrivacyQuery = $easysocial->buildPrivacyQuery('a');
         $privateBlog .= $esPrivacyQuery;
     } else {
         if ($config->get('main_jomsocial_privacy') && JFile::exists($file) && !EasyBlogHelper::isSiteAdmin()) {
             require_once $file;
             $jsFriends = CFactory::getModel('Friends');
             $friends = $jsFriends->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 (empty($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);
             }
         }
     }
     $joinTeam = '';
     $FilterSQL = '';
     if ($filter != '') {
         $FilterSQL = '';
         switch ($filter) {
             case 'blogger':
                 $FilterSQL = 'AND a.' . $db->nameQuote('created_by') . ' = ' . $db->Quote($filterId);
                 break;
             case 'team':
                 $FilterSQL = 'AND (a.' . $db->quoteName('source_type') . ' = ' . $db->Quote(EASYBLOG_POST_SOURCE_TEAM) . ' and a.' . $db->quoteName('source_id') . ' = ' . $db->Quote($filterId) . ')';
                 break;
             default:
                 break;
         }
     }
     $languageFilterSQL = '';
     // @rule: When language filter is enabled, we need to detect the appropriate contents
     $filterLanguage = JFactory::getApplication()->getLanguageFilter();
     if ($filterLanguage) {
         $languageFilterSQL .= EBR::getLanguageQuery('AND', 'a.language');
     }
     $catLib = EB::category();
     $catAccessSQL = $catLib->genAccessSQL('a.`id`', $catAccess);
     $query = 'SELECT COUNT(1) as count, MONTH( a.' . $db->nameQuote('created') . ' ) AS month, YEAR( a.' . $db->nameQuote('created') . ' ) AS year ' . 'FROM ' . $db->nameQuote('#__easyblog_post') . ' AS a ' . $joinTeam . ' ' . 'WHERE a.' . $db->nameQuote('published') . '=' . $db->Quote(EASYBLOG_POST_PUBLISHED) . ' ' . 'AND a.' . $db->nameQuote('state') . '=' . $db->Quote(EASYBLOG_POST_NORMAL) . ' ' . $privateBlog . ' ' . $languageFilterSQL . ' ' . $FilterSQL . ' ' . 'AND ( a.' . $db->nameQuote('created') . ' > ' . $db->Quote($fr . '-12-31 23:59:59') . ' AND a.' . $db->nameQuote('created') . ' < ' . $db->Quote($to . '-01-01 00:00:00') . ') ' . 'AND (' . $catAccessSQL . ') ' . 'GROUP BY year, month DESC ' . 'ORDER BY a.' . $db->nameQuote('created') . ' DESC ';
     $db->setQuery($query);
     $row = $db->loadAssocList();
     if (empty($row)) {
         return false;
     }
     $postCount = new stdClass();
     foreach ($row as $data) {
         if (!isset($postCount->{$data['year']})) {
             $postCount->{$data['year']} = new stdClass();
         }
         $postCount->{$data['year']}->{$data['month']} = $data['count'];
     }
     return $postCount;
 }
Exemplo n.º 4
0
 public static function getItemIdByEntry($blogId)
 {
     static $entriesItems = null;
     if (!isset($entriesItems[$blogId])) {
         $db = EasyBlogHelper::db();
         // We need to check against the correct latest entry to be used based on the category this article is in
         $query = 'SELECT ' . $db->nameQuote('id') . ',' . $db->nameQuote('params') . ' FROM ' . $db->nameQuote('#__menu') . 'WHERE ' . $db->nameQuote('link') . '=' . $db->Quote('index.php?option=com_easyblog&view=latest') . 'AND ' . $db->nameQuote('published') . '=' . $db->Quote('1') . EBR::getLanguageQuery();
         $db->setQuery($query);
         $menus = $db->loadObjectList();
         $blog = EB::table('Blog');
         $blog->load($blogId);
         if ($menus) {
             foreach ($menus as $menu) {
                 $params = EB::registry($menu->params);
                 $inclusion = EasyBlogHelper::getCategoryInclusion($params->get('inclusion'));
                 if (empty($inclusion)) {
                     continue;
                 }
                 if (!is_array($inclusion)) {
                     $inclusion = array($inclusion);
                 }
                 if (in_array($blog->category_id, $inclusion)) {
                     $entriesItems[$blogId] = $menu->id;
                 }
             }
         }
         // Test if there is any entry specific view as this will always override the latest above.
         $query = 'SELECT ' . $db->nameQuote('id') . ' FROM ' . $db->nameQuote('#__menu') . ' ' . 'WHERE ' . $db->nameQuote('link') . '=' . $db->Quote('index.php?option=com_easyblog&view=entry&id=' . $blogId) . ' ' . 'AND ' . $db->nameQuote('published') . '=' . $db->Quote('1') . EBR::getLanguageQuery() . ' LIMIT 1';
         $db->setQuery($query);
         $itemid = $db->loadResult();
         if ($itemid) {
             $entriesItems[$blogId] = $itemid;
         } else {
             // this is to check if we used category menu item from this post or not.
             // if yes, we do nothing. if not, we need to update the cache object so that the next checking will
             // not execute sql again.
             if (isset($entriesItems[$blogId])) {
                 return $entriesItems[$blogId];
             } else {
                 $entriesItems[$blogId] = '';
             }
         }
     }
     return $entriesItems[$blogId];
 }
Exemplo n.º 5
0
 /**
  * Retrieve menu items associated with team blogs
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return
  */
 public function getMenusByTeamId($id)
 {
     $db = EB::db();
     $query = array();
     $query[] = 'SELECT ' . $db->qn('id') . ' FROM ' . $db->qn('#__menu');
     $query[] = 'WHERE';
     $query[] = '(';
     $query[] = $db->qn('link') . '=' . $db->Quote('index.php?option=com_easyblog&view=teamblog&layout=listings&id=' . $id);
     $query[] = 'OR';
     $query[] = $db->qn('link') . ' LIKE ' . $db->Quote('index.php?option=com_easyblog&view=teamblog&layout=listings&id=' . $id . '&limit%');
     $query[] = ')';
     $query[] = 'AND ' . $db->qn('published') . '=' . $db->Quote(1);
     $query[] = EBR::getLanguageQuery();
     $query[] = 'LIMIT 1';
     $query = implode(' ', $query);
     $db->setQuery($query);
     $result = $db->loadResult();
     return $result;
 }
Exemplo n.º 6
0
 static function getPosts(&$params)
 {
     $db = EB::db();
     $config = EB::config();
     $type = $params->get('type');
     $joinQuery = '';
     $headQuery = 'SELECT a.* FROM ' . $db->qn('#__easyblog_post') . ' as a';
     // select valid latitude/longitude or address
     $query = ' WHERE ((TRIM(a.' . $db->qn('latitude') . ') != ' . $db->quote('') . ' AND TRIM(a.' . $db->qn('longitude') . ') != ' . $db->quote('') . ')';
     $query .= ' OR TRIM(a.' . $db->qn('address') . ') != ' . $db->quote('') . ')';
     $query .= ' AND a.' . $db->qn('published') . ' = ' . $db->quote(EASYBLOG_POST_PUBLISHED);
     $query .= ' AND a.' . $db->qn('state') . ' = ' . $db->quote(EASYBLOG_POST_NORMAL);
     // @rule: When language filter is enabled, we need to detect the appropriate contents
     $filterLanguage = JFactory::getApplication()->getLanguageFilter();
     if ($filterLanguage) {
         $queryWhere .= EBR::getLanguageQuery('AND', 'a.language');
     }
     switch ($type) {
         case '1':
             // by blogger
             $bloggers = self::join($params->get('bloggerid'));
             if (!empty($bloggers)) {
                 $query .= ' AND a.' . $db->qn('created_by') . ' IN (' . $bloggers . ')';
             }
             break;
         case '2':
             // by category
             $categories = self::join($params->get('categoryid'));
             if (!empty($categories)) {
                 $joinQuery .= ' INNER JOIN ' . $db->qn('#__easyblog_post_category') . ' as pc';
                 $joinQuery .= ' ON pc.' . $db->qn('post_id') . ' = a.' . $db->qn('id');
                 $query .= ' AND pc.' . $db->qn('category_id') . ' IN (' . $categories . ')';
             }
             break;
         case '3':
             // by tag
             $tags = self::join($params->get('tagid'));
             if (!empty($post_ids)) {
                 $joinQuery .= ' INNER JOIN ' . $db->qn('#__easyblog_post_tag') . ' as pt';
                 $joinQuery .= ' ON pt.' . $db->qn('post_id') . ' = a.' . $db->qn('id');
                 $query .= ' AND pt' . $db->qn('tag_id') . ' IN (' . $tags . ')';
             }
             break;
         case '4':
             // by team
             $teams = self::join($params->get('teamids'));
             if (!empty($post_ids)) {
                 $query .= ' AND a.' . $db->qn('source_type') . ' = ' . $db->Quote(EASYBLOG_POST_SOURCE_TEAM);
                 $query .= ' AND a.' . $db->qn('source_id') . ' IN (' . $post_ids . ')';
             }
             break;
         case '0':
         default:
             // by latest
             $featured = $params->get('usefeatured');
             if ($featured) {
                 $joinQuery .= ' INNER JOIN ' . $db->qn('#__easyblog_featured') . ' as f';
                 $joinQuery .= ' ON f.' . $db->qn('content_id') . ' = a.' . $db->qn('id');
                 $joinQuery .= ' AND f.' . $db->qn('type') . ' = ' . $db->Quote(EBLOG_FEATURED_BLOG);
             }
             break;
     }
     // always sort by latest
     $query .= ' ORDER BY a.' . $db->qn('created') . ' DESC';
     // set limit
     $query .= ' LIMIT ' . (int) $params->get('count', 5);
     // joins the strings.
     $query = $headQuery . $joinQuery . $query;
     $db->setQuery($query);
     $posts = $db->loadObjectList();
     $posts = self::processItems($posts, $params);
     return $posts;
 }