Exemple #1
0
 /**
  * Get nested categories
  */
 public function accessNestedCategories($category, $deep = '0')
 {
     if (isset($category->childs) && is_array($category->childs)) {
         $sup = '- ';
         $deep++;
         for ($d = 0; $d < $deep; $d++) {
             $sup .= '- ';
         }
         for ($j = 0; $j < count($category->childs); $j++) {
             $child = $category->childs[$j];
             $this->options[] = JHtml::_('select.option', $child->id, $sup . JText::_($child->title));
             EasyBlogHelper::accessNestedCategories($child, $deep);
         }
     } else {
         return false;
     }
 }
Exemple #2
0
 /**
  * Generates a html code for category selection.
  *
  * @access	public
  * @param	int		$parentId	if this option spcified, it will list the parent and all its childs categories.
  * @param	int		$userId		if this option specified, it only return categories created by this userId
  * @param	string	$outType	The output type. Currently supported links and drop down selection
  * @param	string	$eleName	The element name of this populated categeries provided the outType os dropdown selection.
  * @param	string	$default	The default selected value. If given, it used at dropdown selection (auto select)
  * @param	boolean	$isWrite	Determine whether the categories list used in write new page or not.
  * @param	boolean	$isPublishedOnly	If this option is true, only published categories will fetched.
  * @param	array 	$exclusion	A list of excluded categories that it should not be including
  */
 public static function populateCategories($parentId, $userId, $outType, $eleName, $default, $isWrite = false, $isPublishedOnly = false, $isFrontendWrite = false, $exclusion = array(), $attributes = '')
 {
     $catModel = EB::model('Category');
     $parentCat = null;
     if (!empty($userId)) {
         $parentCat = $catModel->getParentCategories($userId, 'blogger', $isPublishedOnly, $isFrontendWrite, $exclusion);
     } else {
         if (!empty($parentId)) {
             $parentCat = $catModel->getParentCategories($parentId, 'category', $isPublishedOnly, $isFrontendWrite, $exclusion);
         } else {
             $parentCat = $catModel->getParentCategories('', 'all', $isPublishedOnly, $isFrontendWrite, $exclusion);
         }
     }
     $ignorePrivate = false;
     switch ($outType) {
         case 'link':
             $ignorePrivate = false;
             break;
         case 'popup':
         case 'select':
         default:
             $ignorePrivate = true;
             break;
     }
     // Now let's do a loop to find it's child categories.
     if (!empty($parentCat)) {
         for ($i = 0; $i < count($parentCat); $i++) {
             $parent =& $parentCat[$i];
             //reset
             $parent->childs = null;
             EasyBlogHelper::buildNestedCategories($parent->id, $parent, $ignorePrivate, $isPublishedOnly, $isFrontendWrite, $exclusion);
         }
     }
     if ($isWrite) {
         $defaultCatId = EasyBlogHelper::getDefaultCategoryId();
         $default = empty($default) ? $defaultCatId : $default;
     }
     $formEle = '';
     if ($outType == 'select' && $isWrite) {
         $selected = !$default ? ' selected="selected"' : '';
         $formEle .= '<option value="0"' . $selected . '>' . JText::_('COM_EASYBLOG_SELECT_A_CATEGORY') . '</option>';
     }
     if ($parentCat) {
         foreach ($parentCat as $category) {
             if ($outType == 'popup') {
                 $formEle .= '<div class="category-list-item" id="' . $category->id . '"><a href="javascript:void(0);" onclick="eblog.dashboard.selectCategory(\'' . $category->id . '\')">' . $category->title . '</a>';
                 $formEle .= '<input type="hidden" id="category-list-item-' . $category->id . '" value="' . $category->title . '" />';
                 $formEle .= '</div>';
             } else {
                 $selected = $category->id == $default ? ' selected="selected"' : '';
                 $formEle .= '<option value="' . $category->id . '" ' . $selected . '>' . JText::_($category->title) . '</option>';
             }
             EasyBlogHelper::accessNestedCategories($category, $formEle, '0', $default, $outType);
         }
     }
     $html = '';
     $html .= '<select name="' . $eleName . '" id="' . $eleName . '" class="form-control" ' . $attributes . '>';
     if (!$isWrite) {
         $html .= '<option value="0">' . JText::_('COM_EASYBLOG_SELECT_PARENT_CATEGORY') . '</option>';
     }
     $html .= $formEle;
     $html .= '</select>';
     return $html;
 }
Exemple #3
0
 public static function accessNestedCategories($arr, &$html, $deep = '0', $default = '0', $type = 'select', $linkDelimiter = '')
 {
     if (isset($arr->childs) && is_array($arr->childs)) {
         $sup = '<sup>|_</sup>';
         $space = '';
         $ld = empty($linkDelimiter) ? '>' : $linkDelimiter;
         if ($type == 'select' || $type == 'popup') {
             $deep++;
             for ($d = 0; $d < $deep; $d++) {
                 $space .= '&nbsp;&nbsp;&nbsp;';
             }
         }
         for ($j = 0; $j < count($arr->childs); $j++) {
             $child = $arr->childs[$j];
             if ($type == 'select') {
                 $selected = $child->id == $default ? ' selected="selected"' : '';
                 $html .= '<option value="' . $child->id . '" ' . $selected . '>' . $space . $sup . JText::_($child->title) . '</option>';
             } else {
                 if ($type == 'popup') {
                     $html .= '<div class="category-list-item" id="' . $child->id . '">' . $space . $sup . '<a href="javascript:void(0);" onclick="eblog.dashboard.selectCategory(\'' . $child->id . '\')">' . JText::_($child->title) . '</a>';
                     $html .= '<input type="hidden" id="category-list-item-' . $child->id . '" value="' . JText::_($child->title) . '" />';
                     $html .= '</div>';
                 } else {
                     $str = '<a href="' . EasyBlogRouter::_('index.php?option=com_easyblog&view=categories&layout=listings&id=' . $child->id) . '">' . JText::_($child->title) . '</a>';
                     $html .= empty($html) ? $str : $ld . $str;
                 }
             }
             EasyBlogHelper::accessNestedCategories($child, $html, $deep, $default, $type, $linkDelimiter);
         }
     } else {
         return false;
     }
 }
Exemple #4
0
 function listings()
 {
     $app = JFactory::getApplication();
     $doc = JFactory::getDocument();
     $config = EasyBlogHelper::getConfig();
     $my = JFactory::getUser();
     $acl = EasyBlogACLHelper::getRuleSet();
     $sort = JRequest::getCmd('sort', $config->get('layout_postorder'));
     $catId = JRequest::getCmd('id', '0');
     $category = EasyBlogHelper::getTable('Category', 'Table');
     $category->load($catId);
     if ($category->id == 0) {
         $category->title = JText::_('COM_EASYBLOG_UNCATEGORIZED');
     }
     // Set the meta description for the category
     EasyBlogHelper::setMeta($category->id, META_TYPE_CATEGORY);
     // Set the meta description for the category
     // $doc->setMetadata( 'description' , strip_tags( $category->description ) );
     //setting pathway
     $pathway = $app->getPathway();
     $privacy = $category->checkPrivacy();
     $addRSS = true;
     if (!$privacy->allowed) {
         if ($my->id == 0 && !$config->get('main_allowguestsubscribe')) {
             $addRSS = false;
         }
     }
     if ($addRSS) {
         // Add rss feed link
         $doc->addHeadLink($category->getRSS(), 'alternate', 'rel', array('type' => 'application/rss+xml', 'title' => 'RSS 2.0'));
         $doc->addHeadLink($category->getAtom(), 'alternate', 'rel', array('type' => 'application/atom+xml', 'title' => 'Atom 1.0'));
     }
     if (!EasyBlogRouter::isCurrentActiveMenu('categories', $category->id)) {
         if (!EasyBlogRouter::isCurrentActiveMenu('categories')) {
             $this->setPathway(JText::_('COM_EASYBLOG_CATEGORIES_BREADCRUMB'), EasyBlogRouter::_('index.php?option=com_easyblog&view=categories'));
         }
         //add the pathway for category
         $this->setPathway($category->title, '');
     }
     //get the nested categories
     $category->childs = null;
     EasyBlogHelper::buildNestedCategories($category->id, $category, false, true);
     // TODO: Parameterize initial subcategories to display. Ability to configure from backend.
     $nestedLinks = '';
     $initialLimit = $app->getCfg('list_limit') == 0 ? 5 : $app->getCfg('list_limit');
     if (count($category->childs) > $initialLimit) {
         $initialNestedLinks = '';
         $initialRow = new stdClass();
         $initialRow->childs = array_slice($category->childs, 0, $initialLimit);
         EasyBlogHelper::accessNestedCategories($initialRow, $initialNestedLinks, '0', '', 'link', ', ');
         $moreNestedLinks = '';
         $moreRow = new stdClass();
         $moreRow->childs = array_slice($category->childs, $initialLimit);
         EasyBlogHelper::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($category->childs) - $initialLimit) . '</a></span>';
         $nestedLinks .= '<span class="more-subcategories" style="display: none;">, ' . $moreNestedLinks . '</span>';
     } else {
         EasyBlogHelper::accessNestedCategories($category, $nestedLinks, '0', '', 'link', ', ');
     }
     $catIds = array();
     $catIds[] = $category->id;
     EasyBlogHelper::accessNestedCategoriesId($category, $catIds);
     $category->nestedLink = $nestedLinks;
     $modelC = $this->getModel('Category');
     $category->cnt = $modelC->getTotalPostCount($category->id);
     $modelPT = $this->getModel('PostTag');
     $model = $this->getModel('Blog');
     $modelCat = $this->getModel('Category');
     $data = $model->getBlogsBy('category', $catIds, $sort, null, null, null, null, array(), null, null, null, array(), array(), null, EBLOG_PAGINATION_CATEGORIES);
     $pagination = $model->getPagination();
     $allowCat = $modelCat->allowAclCategory($category->id);
     //for trigger
     $params = $app->getParams('com_easyblog');
     $limitstart = JRequest::getVar('limitstart', 0, '', 'int');
     if (!empty($data)) {
         $data = EasyBlogHelper::formatBlog($data, false, true, true, true);
         if ($config->get('layout_showcomment', false)) {
             for ($i = 0; $i < count($data); $i++) {
                 $row =& $data[$i];
                 $maxComment = $config->get('layout_showcommentcount', 3);
                 $comments = EasyBlogHelper::getHelper('Comment')->getBlogComment($row->id, $maxComment, 'desc');
                 $comments = EasyBlogHelper::formatBlogCommentsLite($comments);
                 $row->comments = $comments;
             }
         }
     }
     $teamBlogCount = $modelCat->getTeamBlogCount($category->id);
     $title = EasyBlogHelper::getPageTitle(JText::_($category->title));
     // @task: Set the page title
     parent::setPageTitle($title, $pagination, $config->get('main_pagetitle_autoappend'));
     $themes = new CodeThemes();
     $themes->set('allowCat', $allowCat);
     $themes->set('category', $category);
     $themes->set('sort', $sort);
     $themes->set('blogs', $data);
     $themes->set('currentURL', 'index.php?option=com_easyblog&view=categories&layout=listings&id=' . $category->id);
     $themes->set('pagination', $pagination->getPagesLinks());
     $themes->set('config', $config);
     $themes->set('teamBlogCount', $teamBlogCount);
     $themes->set('my', $my);
     $themes->set('acl', $acl);
     $themes->set('privacy', $privacy);
     echo $themes->fetch('blog.category.php');
 }
Exemple #5
0
 /**
  * Responsible to display the front page of the blog listings
  *
  * @access	public
  */
 function display($tmpl = null)
 {
     // @task: Set meta tags for latest post
     EasyBlogHelper::setMeta(META_ID_LATEST, META_TYPE_VIEW);
     // @task: Set rss links into headers.
     EasyBlogHelper::getHelper('Feeds')->addHeaders('index.php?option=com_easyblog&view=latest');
     $app = JFactory::getApplication();
     $doc = JFactory::getDocument();
     $config = EasyBlogHelper::getConfig();
     $my = JFactory::getUser();
     $acl = EasyBlogACLHelper::getRuleSet();
     // @task: Add a breadcrumb if the current menu that's being accessed is not from the latest view.
     if (!EasyBlogRouter::isCurrentActiveMenu('latest')) {
         $this->setPathway(JText::_('COM_EASYBLOG_LATEST_BREADCRUMB'), '');
     }
     // @task: Get the current active menu's properties.
     $menu = $app->getMenu()->getActive();
     $menu = JFactory::getApplication()->getMenu()->getActive();
     $inclusion = '';
     if (is_object($menu)) {
         $params = EasyBlogHelper::getRegistry();
         $params->load($menu->params);
         $inclusion = EasyBlogHelper::getCategoryInclusion($params->get('inclusion'));
         if ($params->get('includesubcategories', 0) && !empty($inclusion)) {
             $tmpInclusion = array();
             foreach ($inclusion as $includeCatId) {
                 //get the nested categories
                 $category = new stdClass();
                 $category->id = $includeCatId;
                 $category->childs = null;
                 EasyBlogHelper::buildNestedCategories($category->id, $category);
                 $linkage = '';
                 EasyBlogHelper::accessNestedCategories($category, $linkage, '0', '', 'link', ', ');
                 $catIds = array();
                 $catIds[] = $category->id;
                 EasyBlogHelper::accessNestedCategoriesId($category, $catIds);
                 $tmpInclusion = array_merge($tmpInclusion, $catIds);
             }
             $inclusion = $tmpInclusion;
         }
     }
     // @task: Necessary filters
     $sort = JRequest::getCmd('sort', $config->get('layout_postorder'));
     $model = $this->getModel('Blog');
     // @task: Retrieve the list of featured blog posts.
     $featured = $model->getFeaturedBlog($inclusion);
     $excludeIds = array();
     // @task: Add canonical URLs.
     if ($config->get('main_canonical_entry')) {
         $canonicalUrl = EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=latest', false, true, true);
         $doc->addCustomTag('<link rel="canonical" href="' . $canonicalUrl . '"/>');
     }
     // 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 (!$config->get('layout_featured_frontpage')) {
         foreach ($featured as $item) {
             $excludeIds[] = $item->id;
         }
     }
     // @task: Admin might want to display the featured blogs on all pages.
     if (!$config->get('layout_featured_allpages') && (JRequest::getInt('start', 0) != 0 || JRequest::getInt('limitstart', 0) != 0)) {
         $featured = array();
     } else {
         for ($i = 0; $i < count($featured); $i++) {
             $row = $featured[$i];
             $row->featuredImage = EasyBlogHelper::getFeaturedImage($row->intro . $row->content);
         }
         $featured = EasyBlogHelper::formatBlog($featured, true, false, false, false, false);
     }
     // @task: Try to retrieve any categories to be excluded.
     $excludedCategories = $config->get('layout_exclude_categories');
     $excludedCategories = empty($excludedCategories) ? '' : explode(',', $excludedCategories);
     // @task: Fetch the blog entries.
     $data = $model->getBlogsBy('', '', $sort, 0, EBLOG_FILTER_PUBLISHED, null, true, $excludeIds, false, false, true, $excludedCategories, $inclusion);
     $pagination = $model->getPagination();
     $params = $app->getParams('com_easyblog');
     // @task: Perform necessary formatting here.
     $data = EasyBlogHelper::formatBlog($data, true, true, true, true);
     // @task: Update the title of the page if navigating on different pages to avoid Google marking these title's as duplicates.
     $title = EasyBlogHelper::getPageTitle(JText::_('COM_EASYBLOG_LATEST_PAGE_TITLE'));
     // @task: Set the page title
     parent::setPageTitle($title, $pagination, $config->get('main_pagetitle_autoappend'));
     // @task: Get pagination output here.
     $paginationHTML = $pagination->getPagesLinks();
     $theme = new CodeThemes();
     $theme->set('data', $data);
     $theme->set('featured', $featured);
     $theme->set('currentURL', EasyBlogRouter::_('index.php?option=com_easyblog&view=latest', false));
     $theme->set('pagination', $paginationHTML);
     // @task: Send back response to the browser.
     echo $theme->fetch('blog.latest.php');
 }
Exemple #6
0
 function display($tmpl = null)
 {
     $config = EasyBlogHelper::getConfig();
     $jConfig = EasyBlogHelper::getJConfig();
     if (!$config->get('main_rss')) {
         return;
     }
     $id = JRequest::getCmd('id', '0');
     $category = EasyBlogHelper::getTable('Category', 'Table');
     $category->load($id);
     // private category shouldn't allow to access.
     $privacy = $category->checkPrivacy();
     if (!$privacy->allowed) {
         return;
     }
     if ($category->id == 0) {
         $category->title = JText::_('COM_EASYBLOG_UNCATEGORIZED');
     }
     //get the nested categories
     $category->childs = null;
     EasyBlogHelper::buildNestedCategories($category->id, $category);
     $linkage = '';
     EasyBlogHelper::accessNestedCategories($category, $linkage, '0', '', 'link', ', ');
     $catIds = array();
     $catIds[] = $category->id;
     EasyBlogHelper::accessNestedCategoriesId($category, $catIds);
     $category->nestedLink = $linkage;
     $model = $this->getModel('Blog');
     $sort = JRequest::getCmd('sort', $config->get('layout_postorder'));
     $data = $model->getBlogsBy('category', $catIds, $sort);
     $document = JFactory::getDocument();
     $document->link = EasyBlogRouter::_('index.php?option=com_easyblog&view=categories&id=' . $id . '&layout=listings');
     $document->setTitle($this->escape($category->title));
     $document->setDescription(JText::sprintf('COM_EASYBLOG_FEEDS_CATEGORY_DESC', $this->escape($category->title)));
     if (empty($data)) {
         return;
     }
     for ($i = 0; $i < count($data); $i++) {
         $row =& $data[$i];
         $blog = EasyBlogHelper::getTable('Blog');
         $blog->load($row->id);
         $user = JFactory::getUser($row->created_by);
         $profile = EasyBlogHelper::getTable('Profile', 'Table');
         $profile->load($user->id);
         $created = EasyBlogHelper::getDate($row->created);
         $formatDate = true;
         if (EasyBlogHelper::getJoomlaVersion() >= '1.6') {
             $langCode = EasyBlogStringHelper::getLangCode();
             if ($langCode != 'en-GB' || $langCode != 'en-US') {
                 $formatDate = false;
             }
         }
         //$row->created       = ( $formatDate ) ? $created->toFormat( $config->get('layout_dateformat', '%A, %d %B %Y') ) : $created->toFormat();
         $row->created = $created->toMySQL();
         if ($config->get('main_rss_content') == 'introtext') {
             $row->text = !empty($row->intro) ? $row->intro : $row->content;
         } else {
             $row->text = $row->intro . $row->content;
         }
         $row->text = EasyBlogHelper::getHelper('Videos')->strip($row->text);
         $row->text = EasyBlogGoogleAdsense::stripAdsenseCode($row->text);
         $image = '';
         if ($blog->getImage()) {
             $image = '<img src="' . $blog->getImage()->getSource('frontpage') . '" />';
         }
         // load individual item creator class
         $item = new JFeedItem();
         $item->title = html_entity_decode($this->escape($row->title));
         $item->link = EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $row->id);
         $item->description = $image . $row->text;
         $item->date = $row->created;
         $item->category = $category->title;
         $item->author = $profile->getName();
         if ($jConfig->get('feed_email') == 'author') {
             $item->authorEmail = $profile->user->email;
         } else {
             $item->authorEmail = $jConfig->get('mailfrom');
         }
         $document->addItem($item);
     }
 }