public static function getChildCategories(&$result, $params, &$categories, $level = 1) { $db = EB::db(); $my = JFactory::getUser(); $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'); $language = EB::getCurrentLanguage(); foreach ($result as $row) { if ($row->parent_id == 0) { $categories[$row->id] = $row; $categories[$row->id]->childs = array(); } else { $categories[$row->id] = $row; $categories[$row->id]->childs = array(); } $query = 'SELECT ' . $db->qn('a.id') . ', ' . $db->qn('a.title') . ', ' . $db->qn('a.parent_id') . ', ' . $db->qn('a.alias') . ', ' . $db->qn('a.avatar') . ', COUNT(b.`id`) AS `cnt`' . ' , ' . $db->quote($level) . ' AS level' . ' FROM ' . $db->qn('#__easyblog_category') . ' AS `a`' . ' LEFT JOIN ' . $db->qn('#__easyblog_post_category') . ' AS pc' . ' ON a.`id` = pc.`category_id`' . ' LEFT JOIN ' . $db->qn('#__easyblog_post') . ' AS b' . ' ON b.`id` = pc.`post_id`' . ' AND b.`published` = ' . $db->Quote(EASYBLOG_POST_PUBLISHED) . ' AND b.`state` = ' . $db->Quote(EASYBLOG_POST_NORMAL); $query .= ' WHERE a.`published` = 1'; $query .= ' AND a.`parent_id`=' . $db->Quote($row->id); if ($language) { $query .= 'AND('; $query .= ' a.' . $db->quoteName('language') . '=' . $db->Quote($language); $query .= ' OR'; $query .= ' a.' . $db->quoteName('language') . '=' . $db->Quote(''); $query .= ' OR'; $query .= ' a.' . $db->quoteName('language') . '=' . $db->Quote('*'); $query .= ')'; } if (!$hideEmptyPost) { $query .= ' GROUP BY a.`id` '; } else { $query .= ' GROUP BY a.`id` HAVING (COUNT(b.`id`) > 0)'; } if ($order == 'ordering') { $orderBy = ' ORDER BY `lft` ' . $sort; } if ($order == 'popular') { $orderBy = ' ORDER BY `cnt` ' . $sort; } if ($order == 'alphabet') { $orderBy = ' ORDER BY a.`title` ' . $sort; } if ($order == 'latest') { $orderBy = ' ORDER BY a.`created` ' . $sort; } $query .= $orderBy; $db->setQuery($query); $records = $db->loadObjectList(); if ($records) { modEasyBlogCategoriesHelper::getChildCategories($records, $params, $categories[$row->id]->childs, ++$level); // foreach ($records as $childrec) { // $categories[$row->id]->cnt += $childrec->cnt; // } } } }
/** * Retrieve a list of blog posts from a specific list of categories * * @since 4.0 * @access public * @param string * @return */ public function getPosts($categories = array(), $limit = null) { $db = EB::db(); $my = JFactory::getUser(); $config = EB::config(); $catAccess = array(); $query = array(); if ($categories) { $catAccess['include'] = $categories; } $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_ARCHIVED); // 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 blogger mode is respected // Determines if this current request is standalone mode $blogger = EB::isBloggerMode(); if ($blogger !== false) { $query[] = 'AND a.' . $db->quoteName('created_by') . '=' . $db->Quote($blogger); } // 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('') . ')'; } // sql for category access $catLib = EB::category(); $catAccessSQL = $catLib->genAccessSQL('a.`id`', $catAccess); $query[] = 'AND (' . $catAccessSQL . ')'; // 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)) { $query[] = 'LIMIT ' . $limit; $limit = $limit == 0 ? $this->getState('limit') : $limit; $limitstart = $this->app->get('limitstart', $this->getState('limitstart'), 'int'); $this->_pagination = EB::pagination(0, $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; }
/** * Retrieves posts that is related to the given blog post * * @since 5.0 * @access public * @param string * @return */ public function getRelatedPosts($id, $max = 0) { $db = EB::db(); $config = EB::config(); $result = array(); $query = array(); // Get a list of tags $query[] = 'SELECT ' . $db->quoteName('tag_id') . ' FROM ' . $db->quoteName('#__easyblog_post_tag'); $query[] = 'WHERE ' . $db->quoteName('post_id') . '=' . $db->Quote($id); $query = implode(' ', $query); $db->setQuery($query); $tags = $db->loadColumn(); if (!$tags) { return $tags; } $query = array(); $query[] = 'SELECT DISTINCT c.*, l.' . $db->quoteName('title') . ' AS ' . $db->quoteName('category'); $query[] = 'FROM ' . $db->quoteName('#__easyblog_post_tag') . ' AS a'; $query[] = 'INNER JOIN ' . $db->quoteName('#__easyblog_post_tag') . ' AS a1'; $query[] = 'ON a.' . $db->quoteName('tag_id') . ' = a1.' . $db->quoteName('tag_id'); $query[] = 'AND a1.' . $db->quoteName('post_id') . '=' . $db->Quote($id); $query[] = 'INNER JOIN ' . $db->quoteName('#__easyblog_post') . ' AS c'; $query[] = 'ON a.' . $db->quoteName('post_id') . ' = c.' . $db->quoteName('id'); $query[] = 'LEFT JOIN ' . $db->quoteName('#__easyblog_post_category') . ' AS k'; $query[] = 'ON k.' . $db->quoteName('post_id') . ' = c.' . $db->quoteName('id'); $query[] = 'LEFT JOIN ' . $db->quoteName('#__easyblog_category') . ' AS l'; $query[] = 'ON c.' . $db->quoteName('category_id') . ' = l.' . $db->quoteName('id'); $query[] = 'WHERE a.' . $db->quoteName('post_id') . '!=' . $db->Quote($id); $query[] = 'AND c.' . $db->quoteName('published') . '=' . $db->Quote(EASYBLOG_POST_PUBLISHED); $query[] = 'AND c.' . $db->quoteName('state') . '=' . $db->Quote(EASYBLOG_POST_NORMAL); // When language filter is enabled, we need to detect the appropriate contents $language = EB::getCurrentLanguage(); if ($language) { $query[] = 'AND('; $query[] = 'c.' . $db->quoteName('language') . '=' . $db->Quote($language); $query[] = 'OR'; $query[] = 'c.' . $db->quoteName('language') . '=' . $db->Quote(''); $query[] = 'OR'; $query[] = 'c.' . $db->quoteName('language') . '=' . $db->Quote('*'); $query[] = ')'; } $query[] = 'LIMIT ' . $max; $query = implode(' ', $query); $db->setQuery($query); $result = $db->loadObjectList(); if (!$result) { return $result; } $posts = array(); foreach ($result as $row) { $post = EB::post(); $post->bind($row, array('force' => true)); $posts[] = $post; } return $posts; }
/** * 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; }
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; }
public function preloadPosts($teamIds, $limit = EASYBLOG_TEAMBLOG_LISTING_NO_POST) { $db = EB::db(); $query = array(); foreach ($teamIds as $cid) { $tmp = '(SELECT a.*, f.`id` as `featured` FROM ' . $db->qn('#__easyblog_post') . ' AS a'; $tmp .= ' LEFT JOIN `#__easyblog_featured` AS f'; $tmp .= ' ON a.`id` = f.`content_id` AND f.`type` = ' . $db->Quote('post'); $tmp .= ' where a.' . $db->qn('published') . '=' . $db->Quote(EASYBLOG_POST_PUBLISHED); $tmp .= ' and a.' . $db->qn('state') . '=' . $db->Quote(EASYBLOG_POST_NORMAL); $tmp .= ' and a.' . $db->qn('source_type') . ' = ' . $db->Quote(EASYBLOG_POST_SOURCE_TEAM); $tmp .= ' and a.' . $db->qn('source_id') . ' = ' . $db->Quote($cid); // category access here $catLib = EB::category(); $catAccessSQL = $catLib->genAccessSQL('a.`id`'); $tmp .= ' AND (' . $catAccessSQL . ')'; // Filter by language $language = EB::getCurrentLanguage(); if ($language) { $tmp .= ' AND (a.' . $db->qn('language') . '=' . $db->Quote($language) . ' OR a.' . $db->qn('language') . '=' . $db->Quote('*') . ' OR a.' . $db->qn('language') . '=' . $db->Quote('') . ')'; } $tmp .= ' order by a.`created` desc'; $tmp .= ' limit ' . $limit . ')'; $query[] = $tmp; } $query = implode(' UNION ALL ', $query); $db->setQuery($query); $results = $db->loadObjectList(); $posts = array(); if ($results) { foreach ($results as $row) { $posts[$row->source_id][] = $row; } } return $posts; }
/** * Retrieves a list of featured posts from the site * * @since 1.3 * @access public * @param string * @return */ public function getFeaturedBlog($categories = array(), $limit = null) { $my = JFactory::getUser(); $db = EB::db(); $max = is_null($limit) ? EBLOG_MAX_FEATURED_POST : $limit; // Determine if this is blogger mode $isBloggerMode = EBR::isBloggerMode(); $query = array(); $query[] = 'SELECT a.*, 1 as `featured` FROM ' . $db->quoteName('#__easyblog_post') . ' AS a'; $query[] = 'INNER JOIN ' . $db->quoteName('#__easyblog_featured') . ' AS c'; $query[] = 'ON a.' . $db->quoteName('id') . ' = c.' . $db->quoteName('content_id'); $query[] = 'AND c.' . $db->quoteName('type') . '=' . $db->Quote('post'); $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 blogger mode, we need to filter by author if ($isBloggerMode !== false) { $query[] = 'AND a.' . $db->quoteName('created_by') . '=' . $db->Quote($isBloggerMode); } // When language filter is enabled, we need to detect the appropriate contents $language = EB::getCurrentLanguage(); if ($language) { $query[] = 'AND('; $query[] = 'a.' . $db->quoteName('language') . '=' . $db->Quote($language); $query[] = 'OR'; $query[] = 'a.' . $db->quoteName('language') . '=' . $db->Quote(''); $query[] = 'OR'; $query[] = 'a.' . $db->quoteName('language') . '=' . $db->Quote('*'); $query[] = ')'; } // Explicitly include posts only from these categories if (!empty($categories)) { // To support both comma separated categories an array of categories if (!is_array($categories)) { $categories = explode(',', $categories); } } // Privacy for blog if ($my->guest) { $query[] = 'AND a.' . $db->quoteName('access') . '=' . $db->Quote(BLOG_PRIVACY_PUBLIC); } // category access // sql for category access $catLib = EB::category(); $options = array(); if ($categories) { $options['include'] = $categories; } $catAccessSQL = $catLib->genAccessSQL('a.`id`', $options); $query[] = 'AND (' . $catAccessSQL . ')'; // Ordering $query[] = 'ORDER BY a.' . $db->quoteName('created') . ' DESC'; if ($max > 0) { $query[] = 'LIMIT ' . $max; } $query = implode(' ', $query); $db->setQuery($query); $result = $db->loadObjectList(); return $result; }
public function preloadCategoryChilds($catIds) { $db = EB::db(); $language = EB::getCurrentLanguage(); $query = "select a.id as category_id, b.`id`, b.`title`, b.`alias`, b.`private`, b.`parent_id`"; $query .= " from `#__easyblog_category` as a"; $query .= " inner join `#__easyblog_category` as b on a.`lft` < b.`lft` and a.`rgt` > b.`lft`"; $query .= " where a.`id` in (" . implode(',', $catIds) . ")"; $query .= " and a.`published` = " . $db->Quote('1'); if ($language) { $query .= ' AND('; $query .= ' b.' . $db->quoteName('language') . '=' . $db->Quote($language); $query .= ' OR'; $query .= ' b.' . $db->quoteName('language') . '=' . $db->Quote(''); $query .= ' OR'; $query .= ' b.' . $db->quoteName('language') . '=' . $db->Quote('*'); $query .= ')'; } $catLib = EB::category(); $catAccess = $catLib::genCatAccessSQL('b.`private`', 'b.`id`'); $query .= " AND ({$catAccess})"; $db->setQuery($query); $results = $db->loadObjectList(); $childs = array(); if ($results) { foreach ($results as $child) { $childs[$child->category_id][] = $child; } } return $childs; }