pepperstreet VIP
Total posts: 3,837
16 Sep 2013 16:03

(Recreation of C7 topic)

Hello,

this topic is about Cobalt integration in CommunityBuilder's Incubator project "CB Articles". Its an official CB Plugin, that lists the user's created articles in a CB Profile tab. The interesting part: It supports different "models". Which means different content sources...

Official description and backend screenshot:

"...Display users CMS articles within a template-able profile tab. Model based for allowing additional CMS or content extension support in future releases. Full pagination, display number, and searching capability.

This add-on is only available to Professional and Developer members..."

 

 

Maybe someone is interested and able to create a Cobalt "model" file...

I think, an excellent way to promote MJ Cobalt among CB users community. Since the plugin is for CBsubscribers only, i won't attach it for the public. I think, it is allowed to show the included model files as an example. See comments below...

Thanks in advance for any ideas and help.

Last Modified: 02 Mar 2014


pepperstreet VIP
Total posts: 3,837
16 Sep 2013 16:14

Here is the "Joomla25 Articles" model file from latest CB Articles v3.0.1:


<?php if ( ! ( defined( '_VALID_CB' ) || defined( '_JEXEC' ) || defined( '_VALID_MOS' ) ) ) { die( 'Direct Access to this location is not allowed.' ); } class cbarticlesArticle extends comprofilerDBTable { var $id = null; var $asset_id = null; var $title = null; var $alias = null; var $title_alias = null; var $introtext = null; var $fulltext = null; var $state = null; var $catid = null; var $created = null; var $created_by = null; var $created_by_alias = null; var $modified = null; var $modified_by = null; var $checked_out = null; var $checked_out_time = null; var $publish_up = null; var $publish_down = null; var $images = null; var $urls = null; var $attribs = null; var $version = null; var $parentid = null; var $ordering = null; var $metakey = null; var $metadesc = null; var $access = null; var $hits = null; var $metadata = null; var $featured = null; var $language = null; var $xreference = null; public function __construct( $db ) { $this->comprofilerDBTable( '#__content', 'id', $db ); } public function get( $var, $def = null ) { if ( isset( $this->$var ) ) { return $this->$var; } else { return $def; } } public function setPathway( $title = null, $url = null ) { global $_CB_framework; if ( $title !== false ) { if ( ! $title ) { $title = $this->getTitle(); } if ( $title ) { $_CB_framework->setPageTitle( htmlspecialchars( $title ) ); } } else { $title = $this->getTitle(); } if ( $this->getSection()->id ) { $_CB_framework->appendPathWay( $this->getSectionTitle(), cbarticlesModel::getUrl( $this, true, 'section' ) ); } if ( $this->getCategory()->id ) { $_CB_framework->appendPathWay( $this->getCategoryTitle(), cbarticlesModel::getUrl( $this, true, 'category' ) ); } if ( $url ) { if ( $this->get( 'id' ) ) { $_CB_framework->appendPathWay( $this->getTitle(), cbarticlesModel::getUrl( $this, true, 'article' ) ); } if ( $url === true ) { if ( $this->get( 'id' ) ) { $url = cbarticlesModel::getUrl( $this, true, 'article' ); } else { $url = cbarticlesModel::getUrl( $this, true, 'category' ); } } if ( $title ) { $_CB_framework->appendPathWay( htmlspecialchars( $title ), $url ); } } else { if ( $title ) { $_CB_framework->appendPathWay( htmlspecialchars( $title ), cbarticlesModel::getUrl( $this, true, 'article' ) ); } } } public function getArticle() { $section = $this->getSection(); $category = $this->getCategory(); $article = new stdClass(); $article->id = (int) $this->get( 'id' ); $article->alias = $this->get( 'alias' ); $article->slug = $this->get( 'id' ) . ':' . $this->get( 'alias' ); $article->user = (int) $this->get( 'created_by' ); $article->title = $this->get( 'title' ); $article->article_intro = $this->get( 'introtext' ); $article->article_full = $this->get( 'fulltext' ); $article->article_text = $this->get( 'introtext' ) . $this->get( 'fulltext' ); $article->section = (int) ( $section->id ? $section->id : 0 ); $article->section_alias = ( $section->id ? $section->alias : null ); $article->section_slug = ( $section->id ? $section->id . ':' . $section->alias : null ); $article->section_name = ( $section->id ? $section->title : CBTxt::T( 'Unknown' ) ); $article->section_access = (int) ( $section->id ? $section->access : 0 ); $article->section_published = (int) ( $section->id ? $section->published : 0 ); $article->category = (int) ( $category->id ? $category->id : null ); $article->category_alias = ( $category->id ? $category->alias : null ); $article->category_slug = ( $category->id ? $category->id . ':' . $category->alias : null ); $article->category_name = ( $category->id ? $category->title : CBTxt::T( 'Unknown' ) ); $article->category_access = (int) ( $category->id ? $category->access : 0 ); $article->category_published = (int) ( $category->id ? $category->published : 0 ); $article->created = $this->get( 'created' ); $article->modified = $this->get( 'modified' ); $article->access = (int) $this->get( 'access' ); $article->published = (int) $this->get( 'state' ); $article->ordering = (int) $this->get( 'ordering' ); return $article; } public function getTitle( $length = 0, $linked = false ) { static $cache = array(); $id = $this->get( 'id' ); if ( ! isset( $cache[$id] ) ) { $cache[$id] = htmlspecialchars( $this->get( 'title' ) ); } $title = $cache[$id]; if ( $title ) { $length = (int) $length; if ( $length && ( strlen( $title ) > $length ) ) { $title = rtrim( trim( substr( $title, 0, $length ) ), '.' ) . '...'; $short = true; } else { $short = false; } if ( $linked ) { $title = '<a href="' . cbarticlesModel::getUrl( $this, true, 'article' ) . '"' . ( $short ? ' title="' . $cache[$id] . '"' : null ) . '>' . $title . '</a>'; } } return $title; } public function getOwner() { static $cache = array(); $id = $this->get( 'created_by' ); if ( ! isset( $cache[$id] ) ) { $cache[$id] =& CBuser::getUserDataInstance( (int) $id ); } return $cache[$id]; } public function getOwnerName( $linked = false ) { static $cache = array(); $id = $this->get( 'created_by' ); if ( ! isset( $cache[$id] ) ) { $cbUser =& CBuser::getInstance( (int) $id ); if ( ! $cbUser ) { $cbUser =& CBuser::getInstance( null ); } $cache[$id] = $cbUser; } $name = null; if ( $cache[$id] ) { $user = $cache[$id]; if ( $linked ) { $name = $user->getField( 'formatname', null, 'html', 'none', 'list', 0, true ); } else { $name = $user->getField( 'formatname', null, 'html', 'none', 'profile', 0, true ); } } return $name; } public function getOwnerAvatar( $linked = false ) { static $cache = array(); $id = $this->get( 'created_by' ); if ( ! isset( $cache[$id] ) ) { $cbUser =& CBuser::getInstance( (int) $id ); if ( ! $cbUser ) { $cbUser =& CBuser::getInstance( null ); } $cache[$id] = $cbUser; } $name = null; if ( $cache[$id] ) { $user = $cache[$id]; if ( $linked ) { $name = $user->getField( 'avatar', null, 'html', 'none', 'list', 0, true ); } else { $name = $user->getField( 'avatar', null, 'html', 'none', 'profile', 0, true ); } } return $name; } public function getSection() { static $cache = array(); $category = $this->getCategory(); if ( $category->parent_id && ( $category->parent_id != 1 ) ) { $id = $category->parent_id; } else { $id = null; } if ( ! isset( $cache[$id] ) ) { $section = JTable::getInstance( 'category' ); $section->load( (int) $id ); $cache[$id] = $section; } return $cache[$id]; } public function getSectionTitle( $length = 0, $linked = false ) { static $cache = array(); $category = $this->getCategory(); if ( $category->parent_id && ( $category->parent_id != 1 ) ) { $id = $category->parent_id; } else { $id = null; } if ( ! isset( $cache[$id] ) ) { $section = $this->getSection(); $cache[$id] = ( $section->id ? htmlspecialchars( $section->title ) : null ); } $title = $cache[$id]; if ( $title ) { $length = (int) $length; if ( $length && ( strlen( $title ) > $length ) ) { $title = rtrim( trim( substr( $title, 0, $length ) ), '.' ) . '...'; $short = true; } else { $short = false; } if ( $linked ) { $title = '<a href="' . cbarticlesModel::getUrl( $this, true, 'section' ) . '"' . ( $short ? ' title="' . $cache[$id] . '"' : null ) . '>' . $title . '</a>'; } } return $title; } public function getCategory() { static $cache = array(); $id = $this->get( 'catid' ); if ( ! isset( $cache[$id] ) ) { $category = JTable::getInstance( 'category' ); $category->load( (int) $id ); $cache[$id] = $category; } return $cache[$id]; } public function getCategoryTitle( $length = 0, $linked = false ) { static $cache = array(); $id = $this->get( 'catid' ); if ( ! isset( $cache[$id] ) ) { $category = $this->getCategory(); $cache[$id] = ( $category->id ? htmlspecialchars( $category->title ) : null ); } $title = $cache[$id]; if ( $title ) { $length = (int) $length; if ( $length && ( strlen( $title ) > $length ) ) { $title = rtrim( trim( substr( $title, 0, $length ) ), '.' ) . '...'; $short = true; } else { $short = false; } if ( $linked ) { $title = '<a href="' . cbarticlesModel::getUrl( $this, true, 'category' ) . '"' . ( $short ? ' title="' . $cache[$id] . '"' : null ) . '>' . $title . '</a>'; } } return $title; } public function getAccess() { global $_CB_framework; static $cache = array(); $id = $this->get( 'access' ); if ( ! isset( $cache[$id] ) ) { $levels = $_CB_framework->acl->get_access_children_tree( true, false, false ); $access = CBTxt::T( 'Unknown' ); if ( $levels ) foreach ( $levels as $level ) { if ( $level->value == $id ) { $access = $level->text; } } $cache[$id] = $access; } return $cache[$id]; } } class cbarticlesModel { static public function getArticles( $join, $where, $orderby ) { global $_CB_database; $plugin = cbarticlesClass::getPlugin(); $sections = $plugin->params->get( 'article_section', null ); $categories = $plugin->params->get( 'article_category', null ); if ( $sections ) { $sections = explode( '|*|', $sections ); cbArrayToInts( $sections ); $join[] = 'c'; $where[] = '( c.' . $_CB_database->NameQuote( 'parent_id' ) . ' NOT IN ( ' . implode( ',', $sections ) . ' ) )'; } if ( $categories ) { $categories = explode( '|*|', $categories ); cbArrayToInts( $categories ); $where[] = '( a.' . $_CB_database->NameQuote( 'catid' ) . ' NOT IN ( ' . implode( ',', $categories ) . ' ) )'; } $query = 'SELECT a.*' . "\n FROM " . $_CB_database->NameQuote( '#__content' ) . " AS a"; if ( count( $join ) ) { if ( in_array( 'b', $join ) ) { $query .= "\n LEFT JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS b" . ' ON b.' . $_CB_database->NameQuote( 'id' ) . ' = a.' . $_CB_database->NameQuote( 'created_by' ); } if ( array_intersect( array( 'c', 'd' ), $join ) ) { $query .= "\n LEFT JOIN " . $_CB_database->NameQuote( '#__categories' ) . " AS c" . ' ON c.' . $_CB_database->NameQuote( 'id' ) . ' = a.' . $_CB_database->NameQuote( 'catid' ); } if ( in_array( 'd', $join ) ) { $query .= "\n LEFT JOIN " . $_CB_database->NameQuote( '#__categories' ) . " AS d" . ' ON d.' . $_CB_database->NameQuote( 'id' ) . ' = c.' . $_CB_database->NameQuote( 'parent_id' ); } } $query .= ( count( $where ) ? "\n WHERE " . implode( "\n AND ", $where ) : null ) . "\n ORDER BY " . ( count( $orderby ) ? implode( ', ', $orderby ) : "a." . $_CB_database->NameQuote( 'created' ) . " DESC" ); $_CB_database->setQuery( $query ); $rows = $_CB_database->loadObjectList( 'id', 'cbarticlesArticle', array( &$_CB_database ) ); return $rows; } static public function getSectionsList( $raw = false ) { return cbarticlesModel::getCategoriesList( $raw ); } static public function getCategoriesList( $raw = false ) { global $_CB_database; static $cache = null; if ( ! isset( $cache ) ) { $cache = array(); $query = 'SELECT ' . $_CB_database->NameQuote( 'id' ) . ', ' . $_CB_database->NameQuote( 'title' ) . ', ' . $_CB_database->NameQuote( 'level' ) . ', ' . $_CB_database->NameQuote( 'parent_id' ) . "\n FROM " . $_CB_database->NameQuote( '#__categories' ) . "\n WHERE " . $_CB_database->NameQuote( 'extension' ) . " = " . $_CB_database->Quote( 'com_content' ) . "\n AND " . $_CB_database->NameQuote( 'published' ) . " = 1" . "\n AND " . $_CB_database->NameQuote( 'parent_id' ) . " > 0" . "\n AND " . $_CB_database->NameQuote( 'access' ) . " IN ( " . implode( ',', JFactory::getUser()->getAuthorisedViewLevels() ) . " )" . "\n ORDER BY " . $_CB_database->NameQuote( 'lft' ); $_CB_database->setQuery( $query ); $categories = $_CB_database->loadObjectList( 'id' ); if ( $categories ) foreach ( $categories as $category ) { if ( cbarticlesModel::getParentAccess( $categories, $category ) ) { $cache[] = JHtml::_( 'select.option', $category->id, ( str_repeat( '- ', ( ( $category->level >= 0 ) ? $category->level : 0 ) ) . $category->title ) ); } } } $rows = $cache; if ( $rows ) { if ( $raw ) { $categories = array(); foreach ( $rows as $row ) { $categories[] = (int) $row->value; } $rows = $categories; } } else { $rows = array(); } return $rows; } static public function getParentAccess( $categories, $category ) { $parent = $category->parent_id; if ( $parent && ( $parent != 1 ) ) { if ( ! array_key_exists( $parent, $categories ) ) { return false; } else { return cbarticlesModel::getParentAccess( $categories, $categories[$parent] ); } } return true; } static public function getUrl( $row, $htmlspecialchars = true, $type = 'article' ) { global $_CB_framework; static $cache = array(); if ( ! is_object( $row ) ) { $row = cbarticlesData::getArticles( null, array( 'id', '=', $row ), null, null, false ); } $id = cbarticlesClass::getStaticID( array( $row, $type ) ); if ( ! isset( $cache[$id] ) ) { require_once ( $_CB_framework->getCfg( 'absolute_path' ) . '/components/com_content/helpers/route.php' ); switch ( $type ) { case 'section': $url = ContentHelperRoute::getCategoryRoute( $row->getArticle()->section ); break; case 'category': $url = ContentHelperRoute::getCategoryRoute( $row->getArticle()->category ); break; case 'article': default: $url = ContentHelperRoute::getArticleRoute( $row->getArticle()->id, $row->getArticle()->category ); break; } if ( ! stristr( $url, 'Itemid' ) ) { $url = $_CB_framework->getCfg( 'live_site' ) . '/' . $url; } else { $url = JRoute::_( $url, false ); } $cache[$id] = $url; } $url = $cache[$id]; if ( $url ) { if ( $htmlspecialchars ) { $url = htmlspecialchars( $url ); } } return $url; } } ?>

pepperstreet VIP
Total posts: 3,837
16 Sep 2013 16:16

Here is the included "K2" model file from latest CB Articles v3.0.1


<?php if ( ! ( defined( '_VALID_CB' ) || defined( '_JEXEC' ) || defined( '_VALID_MOS' ) ) ) { die( 'Direct Access to this location is not allowed.' ); } global $_CB_framework; JTable::addIncludePath( $_CB_framework->getCfg( 'absolute_path' ) . '/administrator/components/com_k2/tables' ); class cbarticlesArticle extends comprofilerDBTable { var $id = null; var $title = null; var $alias = null; var $catid = null; var $published = null; var $introtext = null; var $fulltext = null; var $video = null; var $gallery = null; var $extra_fields = null; var $extra_fields_search = null; var $created = null; var $created_by = null; var $created_by_alias = null; var $checked_out = null; var $checked_out_time = null; var $modified = null; var $modified_by = null; var $publish_up = null; var $publish_down = null; var $trash = null; var $access = null; var $ordering = null; var $featured = null; var $featured_ordering = null; var $image_caption = null; var $image_credits = null; var $video_caption = null; var $video_credits = null; var $hits = null; var $params = null; var $metadesc = null; var $metadata = null; var $metakey = null; var $plugins = null; var $language = null; public function __construct( $db ) { $this->comprofilerDBTable( '#__k2_items', 'id', $db ); } public function get( $var, $def = null ) { if ( isset( $this->$var ) ) { return $this->$var; } else { return $def; } } public function setPathway( $title = null, $url = null ) { global $_CB_framework; if ( $title !== false ) { if ( ! $title ) { $title = $this->getTitle(); } if ( $title ) { $_CB_framework->setPageTitle( htmlspecialchars( $title ) ); } } else { $title = $this->getTitle(); } if ( $this->getSection()->id ) { $_CB_framework->appendPathWay( $this->getSectionTitle(), cbarticlesModel::getUrl( $this, true, 'section' ) ); } if ( $this->getCategory()->id ) { $_CB_framework->appendPathWay( $this->getCategoryTitle(), cbarticlesModel::getUrl( $this, true, 'category' ) ); } if ( $url ) { if ( $this->get( 'id' ) ) { $_CB_framework->appendPathWay( $this->getTitle(), cbarticlesModel::getUrl( $this, true, 'article' ) ); } if ( $url === true ) { if ( $this->get( 'id' ) ) { $url = cbarticlesModel::getUrl( $this, true, 'article' ); } else { $url = cbarticlesModel::getUrl( $this, true, 'category' ); } } if ( $title ) { $_CB_framework->appendPathWay( htmlspecialchars( $title ), $url ); } } else { if ( $title ) { $_CB_framework->appendPathWay( htmlspecialchars( $title ), cbarticlesModel::getUrl( $this, true, 'article' ) ); } } } public function getArticle() { $section = $this->getSection(); $category = $this->getCategory(); $article = new stdClass(); $article->id = (int) $this->get( 'id' ); $article->alias = $this->get( 'alias' ); $article->slug = $this->get( 'id' ) . ':' . $this->get( 'alias' ); $article->user = (int) $this->get( 'created_by' ); $article->title = $this->get( 'title' ); $article->article_intro = $this->get( 'introtext' ); $article->article_full = $this->get( 'fulltext' ); $article->article_text = $this->get( 'introtext' ) . $this->get( 'fulltext' ); $article->section = (int) ( $section->id ? $section->id : 0 ); $article->section_alias = ( $section->id ? $section->alias : null ); $article->section_slug = ( $section->id ? $section->id . ':' . $section->alias : null ); $article->section_name = ( $section->id ? $section->name : CBTxt::T( 'Unknown' ) ); $article->section_access = (int) ( $section->id ? $section->access : 0 ); $article->section_published = (int) ( $section->id ? $section->published : 0 ); $article->category = (int) ( $category->id ? $category->id : null ); $article->category_alias = ( $category->id ? $category->alias : null ); $article->category_slug = ( $category->id ? $category->id . ':' . $category->alias : null ); $article->category_name = ( $category->id ? $category->name : CBTxt::T( 'Unknown' ) ); $article->category_access = (int) ( $category->id ? $category->access : 0 ); $article->category_published = (int) ( $category->id ? $category->published : 0 ); $article->created = $this->get( 'created' ); $article->modified = $this->get( 'modified' ); $article->access = (int) $this->get( 'access' ); $article->published = (int) $this->get( 'published' ); $article->ordering = (int) $this->get( 'ordering' ); return $article; } public function getTitle( $length = 0, $linked = false ) { static $cache = array(); $id = $this->get( 'id' ); if ( ! isset( $cache[$id] ) ) { $cache[$id] = htmlspecialchars( $this->get( 'title' ) ); } $title = $cache[$id]; if ( $title ) { $length = (int) $length; if ( $length && ( strlen( $title ) > $length ) ) { $title = rtrim( trim( substr( $title, 0, $length ) ), '.' ) . '...'; $short = true; } else { $short = false; } if ( $linked ) { $title = '<a href="' . cbarticlesModel::getUrl( $this, true, 'article' ) . '"' . ( $short ? ' title="' . $cache[$id] . '"' : null ) . '>' . $title . '</a>'; } } return $title; } public function getOwner() { static $cache = array(); $id = $this->get( 'created_by' ); if ( ! isset( $cache[$id] ) ) { $cache[$id] =& CBuser::getUserDataInstance( (int) $id ); } return $cache[$id]; } public function getOwnerName( $linked = false ) { static $cache = array(); $id = $this->get( 'created_by' ); if ( ! isset( $cache[$id] ) ) { $cbUser =& CBuser::getInstance( (int) $id ); if ( ! $cbUser ) { $cbUser =& CBuser::getInstance( null ); } $cache[$id] = $cbUser; } $name = null; if ( $cache[$id] ) { $user = $cache[$id]; if ( $linked ) { $name = $user->getField( 'formatname', null, 'html', 'none', 'list', 0, true ); } else { $name = $user->getField( 'formatname', null, 'html', 'none', 'profile', 0, true ); } } return $name; } public function getOwnerAvatar( $linked = false ) { static $cache = array(); $id = $this->get( 'created_by' ); if ( ! isset( $cache[$id] ) ) { $cbUser =& CBuser::getInstance( (int) $id ); if ( ! $cbUser ) { $cbUser =& CBuser::getInstance( null ); } $cache[$id] = $cbUser; } $name = null; if ( $cache[$id] ) { $user = $cache[$id]; if ( $linked ) { $name = $user->getField( 'avatar', null, 'html', 'none', 'list', 0, true ); } else { $name = $user->getField( 'avatar', null, 'html', 'none', 'profile', 0, true ); } } return $name; } public function getSection() { static $cache = array(); $plugin = cbarticlesClass::getPlugin(); $id = $plugin->params->get( 'blog_section', null ); if ( ! isset( $cache[$id] ) ) { $section = JTable::getInstance( 'K2Category', 'Table' ); $section->load( (int) $id ); $cache[$id] = $section; } return $cache[$id]; } public function getSectionTitle( $length = 0, $linked = false ) { static $cache = array(); $plugin = cbarticlesClass::getPlugin(); $id = $plugin->params->get( 'blog_section', null ); if ( ! isset( $cache[$id] ) ) { $section = $this->getSection(); $cache[$id] = ( $section->id ? htmlspecialchars( $section->name ) : null ); } $title = $cache[$id]; if ( $title ) { $length = (int) $length; if ( $length && ( strlen( $title ) > $length ) ) { $title = rtrim( trim( substr( $title, 0, $length ) ), '.' ) . '...'; $short = true; } else { $short = false; } if ( $linked ) { $title = '<a href="' . cbarticlesModel::getUrl( $this, true, 'section' ) . '"' . ( $short ? ' title="' . $cache[$id] . '"' : null ) . '>' . $title . '</a>'; } } return $title; } public function getCategory() { static $cache = array(); $id = $this->get( 'catid' ); if ( ! isset( $cache[$id] ) ) { $category = JTable::getInstance( 'K2Category', 'Table' ); $category->load( (int) $id ); $cache[$id] = $category; } return $cache[$id]; } public function getCategoryTitle( $length = 0, $linked = false ) { static $cache = array(); $id = $this->get( 'catid' ); if ( ! isset( $cache[$id] ) ) { $category = $this->getCategory(); $cache[$id] = ( $category->id ? htmlspecialchars( $category->name ) : null ); } $title = $cache[$id]; if ( $title ) { $length = (int) $length; if ( $length && ( strlen( $title ) > $length ) ) { $title = rtrim( trim( substr( $title, 0, $length ) ), '.' ) . '...'; $short = true; } else { $short = false; } if ( $linked ) { $title = '<a href="' . cbarticlesModel::getUrl( $this, true, 'category' ) . '"' . ( $short ? ' title="' . $cache[$id] . '"' : null ) . '>' . $title . '</a>'; } } return $title; } public function getAccess() { global $_CB_framework; static $cache = array(); $id = $this->get( 'access' ); if ( ! isset( $cache[$id] ) ) { $levels = $_CB_framework->acl->get_access_children_tree( true, ( checkJversion() >= 2 ? false : true ), false ); $access = CBTxt::T( 'Unknown' ); if ( $levels ) foreach ( $levels as $level ) { if ( $level->value == $id ) { $access = $level->text; } } $cache[$id] = $access; } return $cache[$id]; } } class cbarticlesModel { public function getArticles( $join, $where, $orderby ) { global $_CB_database; $plugin = cbarticlesClass::getPlugin(); $sections = $plugin->params->get( 'article_section', null ); $categories = $plugin->params->get( 'article_category', null ); if ( $sections ) { $sections = explode( '|*|', $sections ); cbArrayToInts( $sections ); $where[] = '( c.' . $_CB_database->NameQuote( 'parent' ) . ' NOT IN ( ' . implode( ',', $sections ) . ' ) )'; if ( ! in_array( 'c', $join ) ) { $join[] = 'c'; } } if ( $categories ) { $categories = explode( '|*|', $categories ); cbArrayToInts( $categories ); $where[] = '( a.' . $_CB_database->NameQuote( 'catid' ) . ' NOT IN ( ' . implode( ',', $categories ) . ' ) )'; } $query = 'SELECT a.*' . "\n FROM " . $_CB_database->NameQuote( '#__k2_items' ) . " AS a"; if ( count( $join ) ) { if ( in_array( 'b', $join ) ) { $query .= "\n LEFT JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS b" . ' ON b.' . $_CB_database->NameQuote( 'id' ) . ' = a.' . $_CB_database->NameQuote( 'created_by' ); } if ( array_intersect( array( 'c', 'd' ), $join ) ) { $query .= "\n LEFT JOIN " . $_CB_database->NameQuote( '#__k2_categories' ) . " AS c" . ' ON c.' . $_CB_database->NameQuote( 'id' ) . ' = a.' . $_CB_database->NameQuote( 'catid' ); } if ( in_array( 'd', $join ) ) { $query .= "\n LEFT JOIN " . $_CB_database->NameQuote( '#__k2_categories' ) . " AS d" . ' ON d.' . $_CB_database->NameQuote( 'id' ) . ' = c.' . $_CB_database->NameQuote( 'parent' ); } } $query .= ( count( $where ) ? "\n WHERE " . implode( "\n AND ", $where ) : null ) . "\n ORDER BY " . ( count( $orderby ) ? implode( ', ', $orderby ) : "a." . $_CB_database->NameQuote( 'created' ) . " DESC" ); $_CB_database->setQuery( $query ); $rows = $_CB_database->loadObjectList( 'id', 'cbarticlesArticle', array( &$_CB_database ) ); return $rows; } public function getSectionsList( $raw = false ) { return cbarticlesModel::getCategoriesList( $raw ); } public function getCategoriesList( $raw = false ) { global $_CB_framework; static $cache = null; if ( ! isset( $cache ) ) { require_once( $_CB_framework->getCfg( 'absolute_path' ) . '/administrator/components/com_k2/models/categories.php' ); $categories = new K2ModelCategories(); $cache = $categories->categoriesTree( null, true, true); } $rows = $cache; if ( $rows ) { if ( $raw ) { $categories = array(); foreach ( $rows as $row ) { $categories[] = (int) $row->value; } $rows = $categories; } } else { $rows = array(); } return $rows; } public function getUrl( $row, $htmlspecialchars = true, $type = 'article' ) { global $_CB_framework; static $cache = array(); if ( ! is_object( $row ) ) { $row = cbarticlesData::getArticle( null, array( 'id', '=', $row ), null, null, false ); } $id = cbarticlesClass::getStaticID( array( $row, $type ) ); if ( ! isset( $cache[$id] ) ) { require_once ( $_CB_framework->getCfg( 'absolute_path' ) . '/components/com_k2/helpers/route.php' ); switch ( $type ) { case 'section': $url = K2HelperRoute::getCategoryRoute( $row->getCategory()->parent ); break; case 'category': $url = K2HelperRoute::getCategoryRoute( $row->getArticle()->category ); break; case 'article': default: $url = K2HelperRoute::getItemRoute( $row->getArticle()->id, $row->getArticle()->category ); break; } if ( ! stristr( $url, 'Itemid' ) ) { $url = $_CB_framework->getCfg( 'live_site' ) . '/' . $url; } else { $url = JRoute::_( $url, false ); } $cache[$id] = $url; } $url = $cache[$id]; if ( $url ) { if ( $htmlspecialchars ) { $url = htmlspecialchars( $url ); } } return $url; } } ?>
Powered by Cobalt