public function checkPrivacy() { $obj = new stdClass(); $obj->allowed = true; $obj->message = ''; $my = JFactory::getUser(); if ($this->private == '1' && $my->id == 0) { $obj->allowed = false; $obj->error = EB::privacy()->getErrorHTML(); } else { if ($this->private == '2') { $cats = EasyBlogHelper::getPrivateCategories(); if (in_array($this->id, $cats)) { $obj->allowed = false; $obj->error = JText::_('COM_EASYBLOG_PRIVACY_NOT_AUTHORIZED_ERROR'); } } } return $obj; }
function _buildQuery() { $db = EasyBlogHelper::db(); $my = JFactory::getUser(); $config = EasyBlogHelper::getConfig(); // used for privacy $queryWhere = ''; $queryExclude = ''; $queryExcludePending = ''; $excludeCats = array(); $isBloggerMode = EasyBlogRouter::isBloggerMode(); $where = array(); $where2 = array(); $text = JRequest::getVar('query'); $words = explode(' ', $text); $wheres = array(); foreach ($words as $word) { $word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false); $where[] = 'a.`title` LIKE ' . $word; $where[] = 'a.`content` LIKE ' . $word; $where[] = 'a.`intro` LIKE ' . $word; $where2[] = 't.title LIKE ' . $word; $wheres2[] = implode(' OR ', $where2); $wheres[] = implode(' OR ', $where); } $where = '(' . implode(') OR (', $wheres) . ')'; $where2 = '(' . implode(') OR (', $wheres2) . ')'; //get teamblogs id. $teamBlogIds = ''; $query = ''; if ($config->get('main_includeteamblogpost')) { $teamBlogIds = EasyBlogHelper::getViewableTeamIds(); if (count($teamBlogIds) > 0) { $teamBlogIds = implode(',', $teamBlogIds); } } // get all private categories id $excludeCats = EasyBlogHelper::getPrivateCategories(); if (!empty($excludeCats)) { $queryWhere .= ' AND a.`category_id` NOT IN (' . implode(',', $excludeCats) . ')'; } $jsPostIds = self::getJomSocialPosts(); if ($config->get('main_includeteamblogpost') && !empty($teamBlogIds)) { if (!empty($jsPostIds)) { $tmpIds = implode(',', $jsPostIds); $queryWhere .= ' AND (u.team_id IN (' . $teamBlogIds . ') OR a.id IN (' . $tmpIds . ') OR a.`issitewide` = ' . $db->Quote('1') . ')'; } else { $queryWhere .= ' AND (u.team_id IN (' . $teamBlogIds . ') OR a.`issitewide` = ' . $db->Quote('1') . ')'; } } else { if (!empty($jsPostIds)) { $tmpIds = implode(',', $jsPostIds); $queryWhere .= ' AND (a.id IN (' . $tmpIds . ') OR a.`issitewide` = ' . $db->Quote('1') . ')'; } else { $queryWhere .= ' AND a.`issitewide` = ' . $db->Quote('1'); } } if ($isBloggerMode) { $queryWhere .= ' AND a.`created_by`=' . $db->Quote($isBloggerMode); } $query = 'SELECT a.*, b.`title` AS `category` , CONCAT(a.`content` , a.`intro`) AS text'; $query .= ' FROM `#__easyblog_post` as a USE INDEX (`easyblog_post_search`)'; if ($config->get('main_includeteamblogpost')) { $query .= ' LEFT JOIN `#__easyblog_team_post` AS u ON a.id = u.post_id'; } $query .= ' LEFT JOIN `#__easyblog_category` AS b'; $query .= ' ON a.category_id = b.id'; // Always inner join with jos_users and a.created_by so that only valid blogs are loaded $query .= ' INNER JOIN ' . EasyBlogHelper::getHelper('SQL')->nameQuote('#__users') . ' AS c ON a.`created_by`=c.`id`'; $query .= ' WHERE (' . $where; $query .= ' OR a.`id` IN( '; $query .= ' SELECT tp.`post_id` FROM `#__easyblog_tag` AS t '; $query .= ' INNER JOIN `#__easyblog_post_tag` AS tp ON tp.`tag_id` = t.`id` '; $query .= ' WHERE ' . $where2; $query .= ') )'; if ($my->id < 1) { //guest should only see public post. $query .= ' AND a.`private` = ' . $db->Quote('0'); } //do not show unpublished post $query .= ' AND a.`published` = ' . $db->Quote('1'); $query .= $queryWhere; $query .= ' ORDER BY a.`created` DESC'; // echo $query; return $query; }
public static function getCategories(&$params) { //blog privacy setting $db = EasyBlogHelper::db(); $my = JFactory::getUser(); $top_level = 1; $onlyTheseCatIds = $params->get('catid', ''); $mainframe = JFactory::getApplication(); $order = $params->get('order', 'popular'); $sort = $params->get('sort', 'desc'); $count = (int) trim($params->get('count', 0)); $hideEmptyPost = $params->get('hideemptypost', '0'); $query = 'SELECT a.`id`, a.`title`, a.`parent_id`, a.`alias`, a.`avatar`, COUNT(b.`id`) AS `cnt`' . ' , ' . $db->quote($top_level) . ' AS level' . ' FROM ' . $db->nameQuote('#__easyblog_category') . ' AS `a`' . ' LEFT JOIN ' . $db->nameQuote('#__easyblog_post') . ' AS b' . ' ON a.`id` = b.`category_id`' . ' AND b.`published` = ' . $db->Quote('1'); $menu = JFactory::getApplication()->getMenu()->getActive(); if (EasyBlogHelper::getJoomlaVersion() >= '1.6') { $menuParams = new JRegistry(); $menuParams->loadString($menu->params); } else { $menuParams = new JParameter($menu->params); } $isBloggerMode = $menuParams->get('standalone_blog'); if ($isBloggerMode) { $uid = $menu->query['id']; $query .= ' AND a.`created_by`=' . $db->Quote($uid); } if ($my->id == 0) { $query .= ' AND b.`private` = ' . $db->Quote(BLOG_PRIVACY_PUBLIC); } if (EasyBlogHelper::getJoomlaVersion() >= '1.6') { // @rule: When language filter is enabled, we need to detect the appropriate contents $filterLanguage = JFactory::getApplication()->getLanguageFilter(); if ($filterLanguage) { $query .= ' AND ('; $query .= ' b.`language`=' . $db->Quote(JFactory::getLanguage()->getTag()); $query .= ' OR b.`language`=' . $db->Quote(''); $query .= ' OR b.`language`=' . $db->Quote('*'); $query .= ' )'; } } $query .= ' WHERE a.`published` = 1'; // get all private categories id $excludeCats = EasyBlogHelper::getPrivateCategories(); $queryExclude = ''; if (!empty($excludeCats)) { $queryExclude .= ' AND a.`id` NOT IN ('; for ($i = 0; $i < count($excludeCats); $i++) { $queryExclude .= $db->Quote($excludeCats[$i]); if (next($excludeCats) !== false) { $queryExclude .= ','; } } $queryExclude .= ')'; } $query .= ' AND a.`parent_id`=' . $db->Quote(0); if (!empty($onlyTheseCatIds)) { $filterStr = ''; $filterCats = explode(',', $onlyTheseCatIds); foreach ($filterCats as $cat) { $filterStr .= empty($filterStr) ? $db->Quote(trim($cat)) : ',' . $db->Quote(trim($cat)); } $query .= ' AND a.`id` IN ( ' . $filterStr . ' )'; } $query .= $queryExclude; if (!$hideEmptyPost) { $query .= ' GROUP BY a.`id`'; } else { $query .= ' GROUP BY a.`id` HAVING (COUNT(b.`id`) > 0)'; } switch ($order) { case 'ordering': $orderBy = ' ORDER BY `lft` '; break; case 'popular': $orderBy = ' ORDER BY `cnt` '; break; case 'alphabet': $orderBy = ' ORDER BY a.`title` '; break; case 'latest': default: $orderBy = ' ORDER BY a.`created` '; break; } $query .= $orderBy . $sort; if (!empty($count)) { $query .= ' LIMIT ' . $count; } // echo $query;exit; $db->setQuery($query); $result = $db->loadObjectList(); $categories = array(); modEasyBlogCategoriesHelper::getChildCategories($result, $params, $categories, ++$top_level); // Since running the iteration will invert the ordering, we'll need to reverse it back. // $categories = array_reverse( $categories ); return $categories; }
/** * ********************************************************************* * These part of codes will used in tag clod tags. * ********************************************************************* */ function getTagPrivateBlogCount($tagId) { $db = EasyBlogHelper::db(); $queryExclude = ''; $excludeCats = array(); $isBloggerMode = EasyBlogRouter::isBloggerMode(); // get all private categories id $excludeCats = EasyBlogHelper::getPrivateCategories(); if (!empty($excludeCats)) { $queryExclude .= ' AND a.`category_id` NOT IN (' . implode(',', $excludeCats) . ')'; } $query = 'select count(1) from `#__easyblog_post` as a'; $query .= ' inner join `#__easyblog_post_tag` as b'; $query .= ' on a.`id` = b.`post_id`'; $query .= ' and b.`tag_id` = ' . $db->Quote($tagId); $query .= ' where a.`private` = ' . $db->Quote(BLOG_PRIVACY_PRIVATE); if ($isBloggerMode !== false) { $query .= ' and a.`created_by` = ' . $db->Quote($isBloggerMode); } $query .= $queryExclude; $db->setQuery($query); $result = $db->loadResult(); return empty($result) ? '0' : $result; }
public static function getBlogNavigation($blogId, $creationDate, $typeId = '0', $type = 'sitewide') { $db = EasyBlogHelper::db(); $my = JFactory::getUser(); $config = EasyBlogHelper::getConfig(); $keys = array('prev', 'next'); $nav = array(); $nav['prev'] = null; $nav['next'] = null; $isBloggerMode = EasyBlogRouter::isBloggerMode(); $menus = JFactory::getApplication()->getMenu(); $menu = $menus->getActive(); $queryInclude = ''; if (is_object($menu)) { $params = EasyBlogHelper::getRegistry(); $params->load($menu->params); $cats = EasyBlogHelper::getCategoryInclusion($params->get('inclusion')); if ($cats) { if (!is_array($cats)) { $cats = array($cats); } $queryInclude = ' AND a.`category_id` IN ('; foreach ($cats as $allowedCat) { $queryInclude .= $db->Quote($allowedCat); if (next($cats) !== false) { $queryInclude .= ','; } } $queryInclude .= ')'; } } // get all private categories id $excludeCats = EasyBlogHelper::getPrivateCategories(); $queryExclude = ''; if (!empty($excludeCats)) { $queryExclude .= ' AND a.`category_id` NOT IN ('; for ($i = 0; $i < count($excludeCats); $i++) { $queryExclude .= $db->Quote($excludeCats[$i]); if (next($excludeCats) !== false) { $queryExclude .= ','; } } $queryExclude .= ')'; } foreach ($keys as $key) { $query = 'SELECT a.`id`, a.`title`'; $query .= ' FROM `#__easyblog_post` AS `a`'; if ($type == 'team' && !empty($typeId)) { $query .= ' INNER JOIN `#__easyblog_team_post` AS `b`'; $query .= ' ON a.`id` = b.`post_id`'; } $query .= ' WHERE a.`published` = ' . $db->Quote('1'); $query .= ' AND a.`ispending` = ' . $db->Quote('0'); //blog privacy setting // @integrations: jomsocial privacy $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'); $query .= $esPrivacyQuery; } else { if ($config->get('main_jomsocial_privacy') && JFile::exists($file) && !EasyBlogHelper::isSiteAdmin()) { require_once $file; $my = JFactory::getUser(); $jsFriends = CFactory::getModel('Friends'); $friends = $jsFriends->getFriendIds($my->id); // Insert query here. $query .= ' AND ('; $query .= ' (a.`private`= 0 ) OR'; $query .= ' ( (a.`private` = 20) AND (' . $db->Quote($my->id) . ' > 0 ) ) OR'; if (empty($friends)) { $query .= ' ( (a.`private` = 30) AND ( 1 = 2 ) ) OR'; } else { $query .= ' ( (a.`private` = 30) AND ( a.' . $db->nameQuote('created_by') . ' IN (' . implode(',', $friends) . ') ) ) OR'; } $query .= ' ( (a.`private` = 40) AND ( a.' . $db->nameQuote('created_by') . '=' . $my->id . ') )'; $query .= ' )'; } else { //blog privacy setting if ($my->id == 0) { $query .= ' AND a.`private` = ' . $db->Quote(BLOG_PRIVACY_PUBLIC); } } } //include categories if (!empty($queryInclude)) { $query .= $queryInclude; } //exclude private categories $query .= $queryExclude; if ($isBloggerMode !== false) { $query .= ' AND a.`created_by` = ' . $db->Quote($isBloggerMode); } if ($type == 'team' && !empty($typeId)) { $query .= ' AND b.`team_id` = ' . $db->Quote($typeId); } else { $query .= ' AND a.`issitewide` = ' . $db->Quote('1'); } //language filtering if (EasyBlogHelper::getJoomlaVersion() >= '1.6') { // @rule: When language filter is enabled, we need to detect the appropriate contents $filterLanguage = JFactory::getApplication()->getLanguageFilter(); if ($filterLanguage) { $query .= ' AND ('; $query .= ' a.`language`=' . $db->Quote(JFactory::getLanguage()->getTag()); $query .= ' OR a.`language`=' . $db->Quote(''); $query .= ' OR a.`language`=' . $db->Quote('*'); $query .= ' )'; } } if ($key == 'prev') { $query .= ' AND a.`created` < ' . $db->Quote($creationDate); $query .= ' ORDER BY a.`created` DESC'; } else { if ($key == 'next') { $query .= ' AND a.`created` > ' . $db->Quote($creationDate); $query .= ' ORDER BY a.`created` ASC'; } } $query .= ' LIMIT 1'; $db->setQuery($query); $result = $db->loadObjectList(); $nav[$key] = $result; } return $nav; }
function getArchivePostByMonth($month = '', $year = '', $showPrivate = false) { $db = EasyBlogHelper::db(); $user = JFactory::getUser(); $config = EasyBlogHelper::getConfig(); // used for privacy $queryWhere = ''; $queryExclude = ''; $queryExcludePending = ''; $excludeCats = array(); if ($user->id == 0) { $showPrivate = false; } if (!$showPrivate) { $excludeCats = EasyBlogHelper::getPrivateCategories(); } //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.`private`= 0 ) OR'; $privateBlog .= ' ( (a.`private` = 20) AND (' . $db->Quote($user->id) . ' > 0 ) ) OR'; if (empty($friends)) { $privateBlog .= ' ( (a.`private` = 30) AND ( 1 = 2 ) ) OR'; } else { $privateBlog .= ' ( (a.`private` = 30) AND ( a.' . EasyBlogHelper::getHelper('SQL')->nameQuote('created_by') . ' IN (' . implode(',', $friends) . ') ) ) OR'; } $privateBlog .= ' ( (a.`private` = 40) AND ( a.' . EasyBlogHelper::getHelper('SQL')->nameQuote('created_by') . '=' . $user->id . ') )'; $privateBlog .= ' )'; } else { if ($user->id == 0) { $privateBlog .= ' AND a.`private` = ' . $db->Quote(0); } } } $privateBlog = $showPrivate ? '' : $privateBlog; //get teamblogs id. $teamBlogIds = ''; $query = ''; if ($config->get('main_includeteamblogpost')) { $teamBlogIds = EasyBlogHelper::getViewableTeamIds(); if (count($teamBlogIds) > 0) { $teamBlogIds = implode(',', $teamBlogIds); } } if (!empty($excludeCats)) { $queryWhere .= ' AND a.`category_id` NOT IN (' . implode(',', $excludeCats) . ')'; } $jsPostIds = self::getJomSocialPosts(); if ($config->get('main_includeteamblogpost') && !empty($teamBlogIds)) { if (!empty($jsPostIds)) { $tmpIds = implode(',', $jsPostIds); $queryWhere .= ' AND (u.team_id IN (' . $teamBlogIds . ') OR a.id IN (' . $tmpIds . ') OR a.`issitewide` = ' . $db->Quote('1') . ')'; } else { $queryWhere .= ' AND (u.team_id IN (' . $teamBlogIds . ') OR a.`issitewide` = ' . $db->Quote('1') . ')'; } } else { if (!empty($jsPostIds)) { $tmpIds = implode(',', $jsPostIds); $queryWhere .= ' AND (a.id IN (' . $tmpIds . ') OR a.`issitewide` = ' . $db->Quote('1') . ')'; } else { $queryWhere .= ' AND a.`issitewide` = ' . $db->Quote('1'); } } $extraSQL = ''; $blogger = EasyBlogRouter::isBloggerMode(); if ($blogger !== false) { $extraSQL = ' AND a.`created_by` = ' . $db->Quote($blogger); } $tzoffset = EasyBlogDateHelper::getOffSet(true); $query = 'SELECT *, 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 ' . EasyBlogHelper::getHelper('SQL')->nameQuote('#__easyblog_post') . ' as a'; if ($config->get('main_includeteamblogpost')) { $query .= ' LEFT JOIN `#__easyblog_team_post` AS u ON a.id = u.post_id'; } $query .= ' WHERE a.`published` = ' . $db->Quote(true) . ' '; $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') . ') '; $query .= $extraSQL . ' '; $query .= $queryWhere; $query .= ' ORDER BY a.`created` ASC '; $db->setQuery($query); $row = $db->loadObjectList(); $postCount = new EasyblogCalendarObject($month, $year); if (!empty($row)) { foreach ($row as $data) { if ($postCount->{$year}->{$month}->{$data->day} == 0) { $postCount->{$year}->{$month}->{$data->day} = array($data); } else { array_push($postCount->{$year}->{$month}->{$data->day}, $data); } } } return $postCount; }
public function getCategoryTree($sort = 'latest') { $db = EasyBlogHelper::db(); $my = JFactory::getUser(); $config = EasyBlogHelper::getConfig(); $queryExclude = ''; $excludeCats = array(); // get all private categories id $excludeCats = EasyBlogHelper::getPrivateCategories(); if (!empty($excludeCats)) { $queryExclude .= ' AND a.`id` NOT IN (' . implode(',', $excludeCats) . ')'; } $query = 'SELECT a.*, '; $query .= ' ( SELECT COUNT(id) FROM ' . EasyBlogHelper::getHelper('SQL')->nameQuote('#__easyblog_category'); $query .= ' WHERE lft < a.lft AND rgt > a.rgt AND a.lft != ' . $db->Quote(0) . ' ) AS depth '; $query .= ' FROM ' . EasyBlogHelper::getHelper('SQL')->nameQuote('#__easyblog_category') . ' AS a '; $query .= ' WHERE a.`published`=' . $db->Quote('1'); $query .= $queryExclude; switch ($sort) { case 'ordering': $query .= ' ORDER BY `lft`, `ordering`'; break; case 'alphabet': $query .= ' ORDER BY `title`, `lft`'; break; case 'latest': default: $query .= ' ORDER BY `rgt` DESC'; break; } // echo $query; $db->setQuery($query); $rows = $db->loadObjectList(); $total = count($rows); $categories = array(); for ($i = 0; $i < $total; $i++) { $category = EasyBlogHelper::getTable('Category'); $category->bind($rows[$i]); $category->depth = $rows[$i]->depth; $categories[] = $category; } return $categories; }
/** * Method to retrieve blog posts based on the given tag id. * * @access public * @param int $tagId The tag id. * @return array $rows An array of blog objects. */ function getTaggedBlogs($tagId = 0, $limit = false, $includeCatIds = '') { if ($tagId == 0) { return false; } $my = JFactory::getUser(); $db = EasyBlogHelper::db(); $config = EasyBlogHelper::getConfig(); if ($limit === false) { if ($config->get('layout_listlength') == 0) { $limit = $this->getState('limit'); } else { $limit = $config->get('layout_listlength'); } } $limitstart = $this->getState('limitstart'); $isBloggerMode = EasyBlogRouter::isBloggerMode(); $queryExclude = ''; $excludeCats = array(); $isJSGrpPluginInstalled = false; $isJSGrpPluginInstalled = JPluginHelper::isEnabled('system', 'groupeasyblog'); $isEventPluginInstalled = JPluginHelper::isEnabled('system', 'eventeasyblog'); $isJSInstalled = false; // need to check if the site installed jomsocial. if (JFile::exists(JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_community' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'core.php')) { $isJSInstalled = true; } $includeJSGrp = $isJSGrpPluginInstalled && $isJSInstalled ? true : false; $includeJSEvent = $isEventPluginInstalled && $isJSInstalled ? true : false; $jsGrpPostIds = ''; $jsEventPostIds = ''; if ($includeJSEvent) { $queryEvent = 'SELECT ' . EasyBlogHelper::getHelper('SQL')->nameQuote('post_id') . ' FROM'; $queryEvent .= ' ' . EasyBlogHelper::getHelper('SQL')->nameQuote('#__easyblog_external') . ' AS ' . EasyBlogHelper::getHelper('SQL')->nameQuote('a'); $queryEvent .= ' INNER JOIN' . EasyBlogHelper::getHelper('SQL')->nameQuote('#__community_events') . ' AS ' . EasyBlogHelper::getHelper('SQL')->nameQuote('b'); $queryEvent .= ' ON ' . EasyBlogHelper::getHelper('SQL')->nameQuote('a') . '.uid = ' . EasyBlogHelper::getHelper('SQL')->nameQuote('b') . '.id'; $queryEvent .= ' AND ' . EasyBlogHelper::getHelper('SQL')->nameQuote('a') . '.' . EasyBlogHelper::getHelper('SQL')->nameQuote('source') . '=' . $db->Quote('jomsocial.event'); $queryEvent .= ' WHERE ' . EasyBlogHelper::getHelper('SQL')->nameQuote('b') . '.' . EasyBlogHelper::getHelper('SQL')->nameQuote('permission') . '=' . $db->Quote(0); $db->setQuery($queryEvent); $jsEventPostIds = $db->loadResultArray(); if (!empty($excludeBlogs) && !empty($jsEventPostIds)) { $jsEventPostIds = array_diff($jsEventPostIds, $excludeBlogs); } } if ($includeJSGrp) { $queryJSGrp = 'select `post_id` from `#__easyblog_external_groups` as exg inner join `#__community_groups` as jsg'; $queryJSGrp .= ' on exg.group_id = jsg.id '; $queryJSGrp .= ' where jsg.`approvals` = 0'; $db->setQuery($queryJSGrp); $jsGrpPostIds = $db->loadResultArray(); if (!empty($excludeBlogs) && !empty($jsGrpPostIds)) { $jsGrpPostIds = array_diff($jsGrpPostIds, $excludeBlogs); } } //get teamblogs id. if ($config->get('main_includeteamblogpost')) { $teamBlogIds = EasyBlogHelper::getViewableTeamIds(); if (count($teamBlogIds) > 0) { $teamBlogIds = implode(',', $teamBlogIds); } } // get all private categories id $excludeCats = EasyBlogHelper::getPrivateCategories(); if (!empty($excludeCats)) { $queryExclude .= ' AND b.`category_id` NOT IN (' . implode(',', $excludeCats) . ')'; } $query = 'SELECT b.*, c.`title` as `category`'; if ($config->get('main_includeteamblogpost') && !empty($teamBlogIds)) { $query .= ' ,u.`team_id`'; } $query .= ' FROM ' . EasyBlogHelper::getHelper('SQL')->nameQuote('#__easyblog_post_tag') . ' AS a '; $query .= ' INNER JOIN ' . EasyBlogHelper::getHelper('SQL')->nameQuote('#__easyblog_post') . ' AS b '; $query .= ' ON a.post_id=b.id '; $query .= ' LEFT JOIN `#__easyblog_category` AS c'; $query .= ' ON b.category_id = c.id'; if ($config->get('main_includeteamblogpost') && !empty($teamBlogIds)) { $query .= ' LEFT JOIN `#__easyblog_team_post` AS u ON b.id = u.post_id'; } $query .= ' WHERE a.tag_id = ' . $db->Quote($tagId); $query .= ' AND b.`published` = ' . $db->Quote('1'); if (EasyBlogHelper::getJoomlaVersion() >= '1.6') { // @rule: When language filter is enabled, we need to detect the appropriate contents $filterLanguage = JFactory::getApplication()->getLanguageFilter(); if ($filterLanguage) { $query .= ' AND ('; $query .= ' b.`language`=' . $db->Quote(JFactory::getLanguage()->getTag()); $query .= ' OR b.`language`=' . $db->Quote(''); $query .= ' OR b.`language`=' . $db->Quote('*'); $query .= ' )'; } } $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_community' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'core.php'; //blog privacy setting if ($config->get('main_jomsocial_privacy') && JFile::exists($file) && !EasyBlogHelper::isSiteAdmin()) { require_once $file; $jsFriends = CFactory::getModel('Friends'); $friends = $jsFriends->getFriendIds($my->id); array_push($friends, $my->id); // Insert query here. $query .= ' AND ('; $query .= ' (b.`private`= 0 ) OR'; $query .= ' ( (b.`private` = 20) AND (' . $db->Quote($my->id) . ' > 0 ) ) OR'; if (empty($friends)) { $query .= ' ( (b.`private` = 30) AND ( 1 = 2 ) ) OR'; } else { $query .= ' ( (b.`private` = 30) AND ( b.' . EasyBlogHelper::getHelper('SQL')->nameQuote('created_by') . ' IN (' . implode(',', $friends) . ') ) ) OR'; } $query .= ' ( (b.`private` = 40) AND ( b.' . EasyBlogHelper::getHelper('SQL')->nameQuote('created_by') . '=' . $my->id . ') )'; $query .= ' )'; } else { if ($my->id == 0) { $query .= ' AND b.`private` = ' . $db->Quote(BLOG_PRIVACY_PUBLIC); } } if ($isBloggerMode !== false) { $query .= ' AND b.`created_by` = ' . $db->Quote($isBloggerMode); } // if( !empty( $jsGrpPostIds ) ) // { // $tmpIds = implode( ',', $jsGrpPostIds); // $query .= ' AND ( b.id IN (' . $tmpIds . ') OR b.`issitewide` = ' . $db->Quote('1') . ')'; // } $jsTmpIds = array(); if ($jsGrpPostIds) { $jsTmpIds = array_merge($jsGrpPostIds, $jsTmpIds); } if ($jsEventPostIds) { $jsTmpIds = array_merge($jsEventPostIds, $jsTmpIds); } if ($jsTmpIds) { $jsTmpIds = array_unique($jsTmpIds); $extmpIds = implode(',', $jsTmpIds); $query .= ' AND ( b.id IN (' . $extmpIds . ') OR b.`issitewide` = ' . $db->Quote('1') . ')'; } if ($config->get('main_includeteamblogpost') && (!empty($teamBlogIds) || !empty($jsTmpIds))) { $query .= ' AND ('; if (!empty($teamBlogIds)) { $query .= ' u.`team_id` IN (' . $teamBlogIds . ')'; } if ($jsTmpIds) { $extmpIds = implode(',', $jsTmpIds); $query .= $teamBlogIds ? ' OR' : ''; $query .= ' b.`id` IN(' . $extmpIds . ')'; } $query .= ' OR b.`issitewide`=' . $db->Quote(1); $query .= ')'; } else { $query .= ' AND b.`issitewide` = ' . $db->Quote('1'); } $includeCats = array(); $includeCatIds = trim($includeCatIds); if (!empty($includeCatIds)) { $includeCats = explode(',', $includeCatIds); if (!empty($excludeCats)) { $includeCats = array_diff($includeCats, $excludeCats); } if (!empty($includeCats)) { $query .= ' AND b.`category_id` IN (' . implode(',', $includeCats) . ')'; } } $query .= $queryExclude; //$query .= ' ORDER BY `created` DESC'; $sort = $config->get('layout_postorder', 'latest'); $defaultSorting = $config->get('layout_postsort', 'desc'); switch ($sort) { case 'latest': $queryOrder = ' ORDER BY b.`created` ' . $defaultSorting; break; case 'published': $queryOrder = ' ORDER BY b.`publish_up` ' . $defaultSorting; break; case 'popular': $queryOrder = ' ORDER BY b.`hits` ' . $defaultSorting; break; case 'active': $queryOrder = ' ORDER BY b.`publish_down` ' . $defaultSorting; break; case 'alphabet': $queryOrder = ' ORDER BY b.`title` ' . $defaultSorting; break; case 'modified': $queryOrder = ' ORDER BY b.`modified` ' . $defaultSorting; break; case 'random': $queryOrder = ' ORDER BY RAND() '; break; default: break; } $query .= $queryOrder; //total tag's post sql $totalQuery = 'SELECT COUNT(1) FROM ('; $totalQuery .= $query; $totalQuery .= ') as x'; $query .= ' LIMIT ' . $limitstart . ',' . $limit; $db->setQuery($query); $rows = $db->loadObjectList(); $db->setQuery($totalQuery); $db->loadResult(); $this->_total = $db->loadResult(); jimport('joomla.html.pagination'); $this->_pagination = EasyBlogHelper::getPagination($this->_total, $limitstart, $limit); return $rows; }