/** * @param TabTable $tab Current tab * @param UserTable $user Current user * @param int $ui 1 front, 2 admin UI * @param array $postdata Raw unfiltred POST data * @return string HTML */ public function getCBpluginComponent($tab, $user, $ui, $postdata) { global $_CB_framework; outputCbJs(1); outputCbTemplate(1); $plugin = cbblogsClass::getPlugin(); $model = cbblogsClass::getModel(); $action = $this->input('action', null, GetterInterface::STRING); $function = $this->input('func', null, GetterInterface::STRING); $id = $this->input('id', null, GetterInterface::INT); $user = CBuser::getUserDataInstance($_CB_framework->myId()); $tab = new TabTable(); $tab->load(array('pluginid' => (int) $plugin->id)); $profileUrl = $_CB_framework->userProfileUrl($user->get('id'), false, 'cbblogsTab'); if (!($tab->enabled && Application::MyUser()->canViewAccessLevel($tab->viewaccesslevel))) { cbRedirect($profileUrl, CBTxt::T('Not authorized.'), 'error'); } ob_start(); switch ($action) { case 'blogs': switch ($function) { case 'new': $this->showBlogEdit(null, $user, $model, $plugin); break; case 'edit': $this->showBlogEdit($id, $user, $model, $plugin); break; case 'save': cbSpoofCheck('plugin'); $this->saveBlogEdit($id, $user, $model, $plugin); break; case 'publish': $this->stateBlog(1, $id, $user, $model, $plugin); break; case 'unpublish': $this->stateBlog(0, $id, $user, $model, $plugin); break; case 'delete': $this->deleteBlog($id, $user, $model, $plugin); break; case 'show': default: if ($model->type != 2) { cbRedirect(cbblogsModel::getUrl((int) $id, false)); } else { $this->showBlog($id, $user, $model, $plugin); } break; } break; default: cbRedirect($profileUrl, CBTxt::T('Not authorized.'), 'error'); break; } $html = ob_get_contents(); ob_end_clean(); $class = $plugin->params->get('general_class', null); $return = '<div id="cbBlogs" class="cbBlogs' . ($class ? ' ' . htmlspecialchars($class) : null) . '">' . '<div id="cbBlogsInner" class="cbBlogsInner">' . $html . '</div>' . '</div>'; echo $return; }
/** * @param boolean $raw * @return array */ static public function getCategoriesList( $raw = false ) { global $_CB_database; static $cache = null; if ( ! isset( $cache ) ) { $plugin = cbblogsClass::getPlugin(); $section = $plugin->params->get( 'blog_j_section', null ); if ( $section ) { $query = 'SELECT cat.' . $_CB_database->NameQuote( 'id' ) . ' AS value' . ", IF( cat." . $_CB_database->NameQuote( 'level' ) . " = ( sec." . $_CB_database->NameQuote( 'level' ) . " + 1 ), cat." . $_CB_database->NameQuote( 'title' ) . ", CONCAT( REPEAT( '- ', cat." . $_CB_database->NameQuote( 'level' ) . " - ( sec." . $_CB_database->NameQuote( 'level' ) . " + 1 ) ), cat." . $_CB_database->NameQuote( 'title' ) . " ) ) AS text" . "\n FROM " . $_CB_database->NameQuote( '#__categories' ) . " AS cat" . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__categories' ) . " AS sec" . ' ON sec.' . $_CB_database->NameQuote( 'id' ) . ' = ' . (int) $section . "\n WHERE cat." . $_CB_database->NameQuote( 'lft' ) . " BETWEEN ( sec." . $_CB_database->NameQuote( 'lft' ) . " + 1 ) AND ( sec." . $_CB_database->NameQuote( 'rgt' ) . " - 1 )" . "\n AND sec." . $_CB_database->NameQuote( 'access' ) . " IN " . $_CB_database->safeArrayOfIntegers( Application::MyUser()->getAuthorisedViewLevels() ) . "\n AND sec." . $_CB_database->NameQuote( 'extension' ) . " = " . $_CB_database->Quote( 'com_content' ) . "\n AND cat." . $_CB_database->NameQuote( 'published' ) . " = 1" . "\n AND cat." . $_CB_database->NameQuote( 'access' ) . " IN " . $_CB_database->safeArrayOfIntegers( Application::MyUser()->getAuthorisedViewLevels() ) . "\n AND cat." . $_CB_database->NameQuote( 'extension' ) . " = " . $_CB_database->Quote( 'com_content' ); } else { $query = 'SELECT ' . $_CB_database->NameQuote( 'id' ) . ' AS value' . ", CONCAT( REPEAT( '- ', " . $_CB_database->NameQuote( 'level' ) . " ), " . $_CB_database->NameQuote( 'title' ) . " ) AS text" . "\n FROM " . $_CB_database->NameQuote( '#__categories' ) . "\n WHERE " . $_CB_database->NameQuote( 'published' ) . " = 1" . "\n AND " . $_CB_database->NameQuote( 'access' ) . " IN " . $_CB_database->safeArrayOfIntegers( Application::MyUser()->getAuthorisedViewLevels() ) . "\n AND " . $_CB_database->NameQuote( 'extension' ) . " = " . $_CB_database->Quote( 'com_content' ); } $_CB_database->setQuery( $query ); $cache = $_CB_database->loadObjectList(); } $rows = $cache; if ( $rows ) { if ( $raw === true ) { $categories = array(); foreach ( $rows as $row ) { $categories[] = (int) $row->value; } $rows = $categories; } } else { $rows = array(); } return $rows; }
/** * @param int|TableInterface $row * @param bool $htmlspecialchars * @param string $type * @return string */ static public function getUrl( $row, $htmlspecialchars = true, $type = 'article' ) { global $_CB_framework; $plugin = cbblogsClass::getPlugin(); if ( is_integer( $row ) ) { $rowId = $row; $row = new cbblogsBlogTable(); $row->load( (int) $rowId ); } $category = $row->getCategory(); /** @noinspection PhpIncludeInspection */ require_once ( $_CB_framework->getCfg( 'absolute_path' ) . '/components/com_k2/helpers/route.php' ); $categorySlug = $row->get( 'catid' ) . ( $category->get( 'alias' ) ? ':' . $category->get( 'alias' ) : null ); $articleSlug = $row->get( 'id' ) . ( $row->get( 'alias' ) ? ':' . $row->get( 'alias' ) : null ); switch ( $type ) { case 'section': /** @noinspection PhpUndefinedClassInspection */ $url = K2HelperRoute::getCategoryRoute( $plugin->params->get( 'blog_section', null ) ); break; case 'category': /** @noinspection PhpUndefinedClassInspection */ $url = K2HelperRoute::getCategoryRoute( $categorySlug ); break; case 'article': default: /** @noinspection PhpUndefinedClassInspection */ $url = K2HelperRoute::getItemRoute( $articleSlug, $categorySlug ); break; } if ( ! stristr( $url, 'Itemid' ) ) { $url = $_CB_framework->getCfg( 'live_site' ) . '/' . $url; } else { $url = JRoute::_( $url, false ); } if ( $url ) { if ( $htmlspecialchars ) { $url = htmlspecialchars( $url ); } } return $url; }
/** * @param boolean $raw * @return array */ static public function getCategoriesList( $raw = false ) { static $cache = null; if ( ! isset( $cache ) ) { $plugin = cbblogsClass::getPlugin(); $categories = explode( ',', $plugin->params->get( 'blog_categories', 'General,Movies,Music,Games,Sports' ) ); $cache = array(); if ( $categories ) foreach ( $categories as $category ) { $cache[] = moscomprofilerHTML::makeOption( $category, CBTxt::T( $category ) ); } } $rows = $cache; if ( $rows ) { if ( $raw === true ) { $categories = array(); foreach ( $rows as $row ) { $categories[] = $row->value; } $rows = $categories; } } else { $rows = array(); } return $rows; }
/** * @param UserTable $user * @param int $status */ public function deleteBlogs($user, $status) { $plugin = cbblogsClass::getPlugin(); if ($plugin->params->get('blog_delete', 1)) { cbblogsClass::getModel(); $blogs = cbblogsModel::getBlogs(null, null, $user, $user, $plugin); if ($blogs) { foreach ($blogs as $blog) { $blog->delete(); } } } }
/** * @param UserTable $user * @param int $status */ public function deleteBlogs( $user, /** @noinspection PhpUnusedParameterInspection */ $status ) { $plugin = cbblogsClass::getPlugin(); if ( $plugin->params->get( 'blog_delete', 1 ) ) { cbblogsClass::getModel(); $blogs = cbblogsModel::getBlogs( null, null, $user, $user, $plugin ); if ( $blogs ) foreach ( $blogs as $blog ) { $blog->delete(); } } }