/** * Default feed display method * * @since 5.0 * @access public * @param string * @return */ public function display($tmpl = null) { // Ensure that rss is enabled if (!$this->config->get('main_rss')) { return JError::raiseError(404, JText::_('COM_EASYBLOG_FEEDS_DISABLED')); } $id = $this->input->get('id', '', 'cmd'); $category = EB::table('Category'); $category->load($id); // Private category shouldn't allow to access. $privacy = $category->checkPrivacy(); if (!$privacy->allowed) { return JError::raiseError(500, JText::_('COM_EASYBLOG_NOT_ALLOWED_HERE')); } // Get the nested categories $category->childs = null; EB::buildNestedCategories($category->id, $category); $linkage = ''; EB::accessNestedCategories($category, $linkage, '0', '', 'link', ', '); $catIds = array(); $catIds[] = $category->id; EB::accessNestedCategoriesId($category, $catIds); $category->nestedLink = $linkage; $model = EB::model('Blog'); $sort = $this->input->get('sort', $this->config->get('layout_postorder'), 'cmd'); $posts = $model->getBlogsBy('category', $catIds, $sort); $posts = EB::formatter('list', $posts); $this->doc->link = EBR::_('index.php?option=com_easyblog&view=categories&id=' . $id . '&layout=listings'); $this->doc->setTitle($this->escape($category->getTitle())); $this->doc->setDescription(JText::sprintf('COM_EASYBLOG_FEEDS_CATEGORY_DESC', $this->escape($category->getTitle()))); if (!$posts) { return; } $uri = JURI::getInstance(); $scheme = $uri->toString(array('scheme')); $scheme = str_replace('://', ':', $scheme); foreach ($posts as $post) { $image = ''; if ($post->hasImage()) { $image = '<img src="' . $post->getImage('medium', true, true) . '" width="250" align="left" />'; } $item = new JFeedItem(); $item->title = $this->escape($post->title); $item->link = $post->getPermalink(); $item->description = $image . $post->getIntro(); // replace the image source to proper format so that feed reader can view the image correctly. $item->description = str_replace('src="//', 'src="' . $scheme . '//', $item->description); $item->description = str_replace('href="//', 'href="' . $scheme . '//', $item->description); $item->date = $post->getCreationDate()->toSql(); $item->category = $post->getPrimaryCategory()->getTitle(); $item->author = $post->author->getName(); $item->authorEmail = $this->getRssEmail($post->author); $this->doc->addItem($item); } // exit; }
/** * Displays blog posts from a specific category * * @since 4.0 * @access public * @param string * @return */ public function listings() { // Get the main category $id = $this->input->get('id', 0, 'int'); $category = EB::table('Category'); $category->load($id); // Check for the category privacy if (!$category->checkPrivacy()) { // @TODO: Display proper error message return; } $catIds = array(); $catIds[] = $category->id; EB::accessNestedCategoriesId($category, $catIds); $model = EB::model('Category'); $posts = $model->getPosts($catIds); $posts = EB::formatter('list', $posts); $this->set('category', $category); $this->set('posts', $posts); return parent::display(); }
public function execute() { if (!$this->items) { return $this->items; } $limit = EB::call('Pagination', 'getLimit', array(EBLOG_PAGINATION_CATEGORIES)); // lets cache these categories EB::cache()->insertCategories($this->items); $categories = array(); // Get the category model $model = EB::model('Category'); foreach ($this->items as $row) { // We want to load the table objects $category = EB::table('Category'); $category->bind($row); // binding the extra info if (isset($row->cnt)) { $category->cnt = $row->cnt; } // Format the childs $category->childs = array(); // Build childs list EB::buildNestedCategories($category->id, $category, false, true); // Parameterize initial subcategories to display. Ability to configure from backend. $nestedLinks = ''; $subcategoryLimit = $this->app->getCfg('list_limit') == 0 ? 5 : $this->app->getCfg('list_limit'); if (count($category->childs) > $subcategoryLimit) { $initialNestedLinks = ''; $initialRow = new stdClass(); $initialRow->childs = array_slice($category->childs, 0, $subcategoryLimit); EB::accessNestedCategories($initialRow, $initialNestedLinks, '0', '', 'link', ', '); $moreNestedLinks = ''; $moreRow = new stdClass(); $moreRow->childs = array_slice($category->childs, $initialLimit); EB::accessNestedCategories($moreRow, $moreNestedLinks, '0', '', 'link', ', '); // Hide more nested links until triggered $nestedLinks .= $initialNestedLinks; $nestedLinks .= '<span class="more-subcategories-toggle"> ' . JText::_('COM_EASYBLOG_AND') . ' <a href="javascript:void(0);" onclick="eblog.categories.loadMore( this );">' . JText::sprintf('COM_EASYBLOG_OTHER_SUBCATEGORIES', count($row->childs) - $initialLimit) . '</a></span>'; $nestedLinks .= '<span class="more-subcategories" style="display: none;">, ' . $moreNestedLinks . '</span>'; } else { EB::accessNestedCategories($category, $nestedLinks, '0', '', 'link', ', '); } // Set the nested links $category->nestedLink = $nestedLinks; // Get a list of nested categories and itself. $filterCategories = array($category->id); EB::accessNestedCategoriesId($category, $filterCategories); // Get a list of blog posts from this category $blogs = array(); if (EB::cache()->exists($category->id, 'cats')) { $data = EB::cache()->get($category->id, 'cats'); if (isset($data['post'])) { $blogs = $data['post']; } } else { $blogs = $model->getPosts($filterCategories, $limit); } // Format the blog posts $blogs = EB::formatter('list', $blogs); // Assign other attributes to the category object $category->blogs = $blogs; // Get the total number of posts in the category if (!isset($category->cnt)) { $category->cnt = $model->getTotalPostCount($filterCategories); } // Get a list of active authors within this category. $category->authors = $category->getActiveBloggers(); // Check isCategorySubscribed $category->isCategorySubscribed = $model->isCategorySubscribedEmail($category->id, $this->my->email); $categories[] = $category; } return $categories; }
public static function accessNestedCategoriesId($arr, &$newArr) { if (isset($arr->childs) && is_array($arr->childs)) { for ($j = 0; $j < count($arr->childs); $j++) { $child = $arr->childs[$j]; $newArr[] = $child->id; EB::accessNestedCategoriesId($child, $newArr); } } else { return false; } }
/** * Displays a list of blog posts on the site filtered by a category. * * @since 4.0 * @access public * @param string * @return */ public function listings() { // Retrieve sorting options $sort = $this->input->get('sort', $this->config->get('layout_postorder'), 'cmd'); $id = $this->input->get('id', 0, 'int'); // Try to load the category $category = EB::table('Category'); $category->load($id); // If the category isn't found on the site throw an error. if (!$id || !$category->id) { return JError::raiseError(404, JText::_('COM_EASYBLOG_CATEGORY_NOT_FOUND')); } // Set the meta description for the category EB::setMeta($category->id, META_TYPE_CATEGORY); // Set a canonical link for the category page. $this->canonical($category->getExternalPermalink()); // Get the privacy $privacy = $category->checkPrivacy(); if ($privacy->allowed || EB::isSiteAdmin() || !$this->my->guest && $this->config->get('main_allowguestsubscribe')) { $this->doc->addHeadLink($category->getRSS(), 'alternate', 'rel', array('type' => 'application/rss+xml', 'title' => 'RSS 2.0')); $this->doc->addHeadLink($category->getAtom(), 'alternate', 'rel', array('type' => 'application/atom+xml', 'title' => 'Atom 1.0')); } // Set views breadcrumbs $this->setViewBreadcrumb($this->getName()); // Set the breadcrumb for this category if (!EBR::isCurrentActiveMenu('categories', $category->id)) { // Always add the final pathway to the category title. $this->setPathway($category->title, ''); } //get the nested categories $category->childs = null; // Build nested childsets EB::buildNestedCategories($category->id, $category, false, true); // Parameterize initial subcategories to display. Ability to configure from backend. $nestedLinks = ''; $initialLimit = $this->app->getCfg('list_limit') == 0 ? 5 : $this->app->getCfg('list_limit'); if (count($category->childs) > $initialLimit) { $initialNestedLinks = ''; $initialRow = new stdClass(); $initialRow->childs = array_slice($category->childs, 0, $initialLimit); EB::accessNestedCategories($initialRow, $initialNestedLinks, '0', '', 'link', ', '); $moreNestedLinks = ''; $moreRow = new stdClass(); $moreRow->childs = array_slice($category->childs, $initialLimit); EB::accessNestedCategories($moreRow, $moreNestedLinks, '0', '', 'link', ', '); // Hide more nested links until triggered $nestedLinks .= $initialNestedLinks; $nestedLinks .= '<span class="more-subcategories-toggle" data-more-categories-link> ' . JText::_('COM_EASYBLOG_AND') . ' <a href="javascript:void(0);">' . JText::sprintf('COM_EASYBLOG_OTHER_SUBCATEGORIES', count($category->childs) - $initialLimit) . '</a></span>'; $nestedLinks .= '<span class="more-subcategories" style="display: none;" data-more-categories>, ' . $moreNestedLinks . '</span>'; } else { EB::accessNestedCategories($category, $nestedLinks, '0', '', 'link', ', '); } $catIds = array(); $catIds[] = $category->id; EB::accessNestedCategoriesId($category, $catIds); $category->nestedLink = $nestedLinks; // Get the category model $model = EB::model('Category'); // Get total posts in this category $category->cnt = $model->getTotalPostCount($category->id); // Get teamblog posts count // $teamBlogCount = $model->getTeamBlogCount($category->id); $limit = EB::call('Pagination', 'getLimit', array(EBLOG_PAGINATION_CATEGORIES)); // Get the posts in the category $data = $model->getPosts($catIds, $limit); // Get the pagination $pagination = $model->getPagination(); // Get allowed categories $allowCat = $model->allowAclCategory($category->id); // Format the data that we need $posts = array(); // Ensure that the user is really allowed to view the blogs if (!empty($data)) { $posts = EB::formatter('list', $data); } // Check isCategorySubscribed $isCategorySubscribed = $model->isCategorySubscribedEmail($category->id, $this->my->email); // If this category has a different theme, we need to output it differently if (!empty($category->theme)) { $this->setTheme($category->theme); } // Set the page title $title = EB::getPageTitle(JText::_($category->title)); $this->setPageTitle($title, $pagination, $this->config->get('main_pagetitle_autoappend')); // Set the return url $return = base64_encode($category->getExternalPermalink()); // Get the pagination $pagination = $pagination->getPagesLinks(); $this->set('allowCat', $allowCat); $this->set('category', $category); $this->set('sort', $sort); $this->set('posts', $posts); $this->set('return', $return); $this->set('pagination', $pagination); // $this->set('teamBlogCount', $teamBlogCount); $this->set('privacy', $privacy); $this->set('isCategorySubscribed', $isCategorySubscribed); parent::display('blogs/categories/item'); }
/** * Retrieves a list of parent categories with posts * * @since 4.0 * @access public * @param string * @return */ public function getParentCategoriesWithPost($accessible = array()) { $db = EB::db(); $my = JFactory::getUser(); // Build the initial query $query = 'SELECT * FROM ' . $db->quoteName('#__easyblog_category'); $query .= ' WHERE ' . $db->quoteName('published') . '=' . $db->Quote(1); $query .= ' AND ' . $db->quoteName('parent_id') . '=' . $db->Quote(0); // If caller provides us with specific category id's that are accessible by the user if (!empty($accessible)) { $tmp = ''; foreach ($accessible as $category) { $tmp .= $db->Quote($category->id); if (next($accessible) !== false) { $tmp .= ','; } } $query .= ' AND ' . $db->quoteName('id') . ' IN(' . $tmp . ')'; } $db->setQuery($query); $result = $db->loadObjectList(); if (!$result) { return array(); } $categories = array(); foreach ($result as &$row) { $row->childs = null; // Build the childs for this category EB::buildNestedCategories($row->id, $row); // Emm... what is this? $catIds = array(); $catIds[] = $row->id; EB::accessNestedCategoriesId($row, $catIds); // Get the total number of posts for this category $row->cnt = $this->getTotalPostCount($catIds); if ($row->cnt > 0) { $categories[] = $row->id; } } return $categories; }
if ($category->private != 0 && $my->guest) { $privacy = $category->checkPrivacy(); if (!$privacy->allowed) { echo JText::_('MOD_LATESTBLOGS_CATEGORY_IS_CURRENTLY_SET_TO_PRIVATE'); return; } } // Initialize the default list of categories. $catIds = array($category->id); // If configured to display subcategory items if ($params->get('includesubcategory', 0)) { // Why??? $category->childs = null; // Build nested category level EB::buildNestedCategories($category->id, $category, false, true); EB::accessNestedCategoriesId($category, $catIds); } // Get the list of blog posts associated with the category $posts = modLatestBlogsHelper::getLatestPost($params, $catIds, 'category'); // Determines if the admin wants to display the counter $total = count($posts); if ($total > 0 && $params->get('showccount', '')) { $model = EB::model('Category'); $categoryTotalPostCnt = $model->getTotalPostCount($catIds); } // Let the template know which header we want to use. $templateForHeader = 'category'; } // Filter blog posts by tags if ($filterType == 3 || $filterType == 'tags') { $tagId = $params->get('tagid', '');
static function getLatestPost(&$params, $id = null, $type = 'latest') { $db = EB::db(); $config = EB::config(); $count = (int) $params->get('count', 0); $model = EB::model('Blog'); $posts = ''; $sort = $params->get('sortby', 'latest') == 'latest' ? 'latest' : 'modified'; switch ($type) { case 'blogger': $posts = $model->getBlogsBy('blogger', $id, $sort, $count, EBLOG_FILTER_PUBLISHED, null, false); break; case 'category': $posts = $model->getBlogsBy('category', $id, $sort, $count, EBLOG_FILTER_PUBLISHED, null, false); break; case 'tag': $posts = $model->getTaggedBlogs($id, $count); break; case 'team': $posts = $model->getBlogsBy('teamblog', $id, $sort, $count, EBLOG_FILTER_PUBLISHED, null, false); break; case 'latest': default: if ($params->get('usefeatured')) { $posts = $model->getFeaturedBlog(array(), $count); } else { $categories = EB::getCategoryInclusion($params->get('catid')); $catIds = array(); if (!empty($categories)) { if (!is_array($categories)) { $categories = array($categories); } foreach ($categories as $item) { $category = new stdClass(); $category->id = trim($item); $catIds[] = $category->id; if ($params->get('includesubcategory', 0)) { $category->childs = null; EB::buildNestedCategories($category->id, $category, false, true); EB::accessNestedCategoriesId($category, $catIds); } } $catIds = array_unique($catIds); } $cid = $catIds; if (!empty($cid)) { $type = 'category'; } $postType = null; if ($params->get('postType') != 'all') { $postType = $params->get('postType'); } $posts = $model->getBlogsBy($type, $cid, 'latest', $count, EBLOG_FILTER_PUBLISHED, null, false, array(), false, false, true, array(), $cid, $postType); } break; } if (count($posts) > 0) { $posts = EB::modules()->processItems($posts, $params); } return $posts; }
public function get() { $input = JFactory::getApplication()->input; $model = EasyBlogHelper::getModel('Blog'); $category = EasyBlogHelper::table('Category', 'Table'); $id = $input->get('id', null, 'INT'); $search = $input->get('search', null, 'STRING'); $posts = array(); if (!isset($id)) { $categoriesmodel = EasyBlogHelper::getModel('Categories'); $categories = $categoriesmodel->getCategoryTree('ordering'); $this->plugin->setResponse($categories); return; } $category->load($id); // private category shouldn't allow to access. $privacy = $category->checkPrivacy(); if (!$category->id || !$privacy->allowed) { $this->plugin->setResponse($this->getErrorResponse(404, 'Category not found')); return; } //new code $category = EB::table('Category'); $category->load($id); //get the nested categories $category->childs = null; // Build nested childsets EB::buildNestedCategories($category->id, $category, false, true); $catIds = array(); $catIds[] = $category->id; EB::accessNestedCategoriesId($category, $catIds); // Get the category model $model = EB::model('Category'); // Get total posts in this category $category->cnt = $model->getTotalPostCount($category->id); // Get teamblog posts count // $teamBlogCount = $model->getTeamBlogCount($category->id); $limit = EB::call('Pagination', 'getLimit', array(EBLOG_PAGINATION_CATEGORIES)); // Get the posts in the category $data = $model->getPosts($catIds, $limit); $rows = EB::formatter('list', $data); //end foreach ($rows as $k => $v) { //$item = EasyBlogHelper::getHelper( 'SimpleSchema' )->mapPost($v, '', 100, array('text')); $scm_obj = new EasyBlogSimpleSchema_plg(); $item = $scm_obj->mapPost($v, '', 100, array('text')); $item->isowner = $v->created_by == $this->plugin->get('user')->id ? true : false; if ($v->blogpassword != '') { $item->ispassword = true; } else { $item->ispassword = false; } $item->blogpassword = $v->blogpassword; $model = EasyBlogHelper::getModel('Ratings'); $ratingValue = $model->getRatingValues($item->postid, 'entry'); $item->rate = $ratingValue; $item->isVoted = $model->hasVoted($item->postid, 'entry', $this->plugin->get('user')->id); if ($item->rate->ratings == 0) { $item->rate->ratings = -2; } $posts[] = $item; } $this->plugin->setResponse($posts); }
/** * Displays the frontpage blog listings on the site. * * @since 5.0 * @access public */ public function display($tmpl = null) { // Add the RSS headers on the page EB::feeds()->addHeaders('index.php?option=com_easyblog'); // Add breadcrumbs on the site menu. $this->setPathway('COM_EASYBLOG_LATEST_BREADCRUMB'); // Get the current active menu's properties. $params = $this->theme->params; $inclusion = ''; if ($params) { // Get a list of category inclusions $inclusion = EB::getCategoryInclusion($params->get('inclusion')); if ($params->get('includesubcategories', 0) && !empty($inclusion)) { $tmpInclusion = array(); foreach ($inclusion as $includeCatId) { // Retrieve nested categories $category = new stdClass(); $category->id = $includeCatId; $category->childs = null; EB::buildNestedCategories($category->id, $category); $linkage = ''; EB::accessNestedCategories($category, $linkage, '0', '', 'link', ', '); $catIds = array(); $catIds[] = $category->id; EB::accessNestedCategoriesId($category, $catIds); $tmpInclusion = array_merge($tmpInclusion, $catIds); } $inclusion = $tmpInclusion; } } // Sorting for the posts $sort = $this->input->get('sort', $this->config->get('layout_postorder'), 'cmd'); $model = EB::model('Blog'); $tobeCached = array(); // Retrieve a list of featured blog posts on the site. $featured = $model->getFeaturedBlog($inclusion); $excludeIds = array(); // Test if user also wants the featured items to be appearing in the blog listings on the front page. // Otherwise, we'll need to exclude the featured id's from appearing on the front page. if (!$this->theme->params->get('post_include_featured', true)) { foreach ($featured as $item) { $excludeIds[] = $item->id; } } // Admin might want to display the featured blogs on all pages. $start = $this->input->get('start', 0, 'int'); $limitstart = $this->input->get('limitstart', 0, 'int'); if (!$this->theme->params->get('featured_slider_all_pages') && ($start != 0 || $limitstart != 0)) { $featured = array(); } if ($featured) { $tobeCached = array_merge($tobeCached, $featured); } // Try to retrieve any categories to be excluded. $excludedCategories = $this->config->get('layout_exclude_categories'); $excludedCategories = empty($excludedCategories) ? '' : explode(',', $excludedCategories); // Fetch the blog entries. $data = $model->getBlogsBy('', '', $sort, 0, EBLOG_FILTER_PUBLISHED, null, true, $excludeIds, false, false, true, $excludedCategories, $inclusion, null, 'listlength', $this->theme->params->get('post_pin_featured', false)); if ($data) { $tobeCached = array_merge($tobeCached, $data); } // we will cache it here. if ($tobeCached) { EB::cache()->insert($tobeCached); } // Get the pagination $pagination = $model->getPagination(); if ($featured) { // Format the featured items without caching $featured = EB::formatter('featured', $featured, false); } // Perform blog formatting without caching $posts = EB::formatter('list', $data, false); // Update the title of the page if navigating on different pages to avoid Google marking these title's as duplicates. $title = EB::getPageTitle(JText::_('COM_EASYBLOG_LATEST_PAGE_TITLE')); // Set the page title $this->setPageTitle($title, $pagination, $this->config->get('main_pagetitle_autoappend')); // Add canonical URLs. $this->canonical('index.php?option=com_easyblog'); // Retrieve the pagination for the latest view $pagination = $pagination->getPagesLinks(); // Meta should be set later because formatter would have cached the post already. EB::setMeta(META_ID_LATEST, META_TYPE_VIEW); // Get the current url $return = EBR::_('index.php?option=com_easyblog', false); $this->set('return', $return); $this->set('posts', $posts); $this->set('featured', $featured); $this->set('pagination', $pagination); parent::display('blogs/latest/default'); }