public function check( ) { if ( $this->get( 'title' ) == '' ) { $this->setError( CBTxt::T( 'Title not specified!' ) ); return false; } elseif ( ! $this->get( 'created_by' ) ) { $this->setError( CBTxt::T( 'User not specified!' ) ); return false; } elseif ( $this->get( 'created_by' ) && ( ! CBuser::getUserDataInstance( (int) $this->get( 'created_by' ) )->id ) ) { $this->setError( CBTxt::T( 'User specified does not exist!' ) ); return false; } elseif ( $this->get( 'access' ) === '' ) { $this->setError( CBTxt::T( 'Access not specified!' ) ); return false; } elseif ( ! $this->get( 'catid' ) ) { $this->setError( CBTxt::T( 'Category not specified!' ) ); return false; } elseif ( ! in_array( $this->get( 'catid' ), cbblogsModel::getCategoriesList( true ) ) ) { $this->setError( CBTxt::T( 'Category not allowed!' ) ); return false; } return true; }
/** * @return array */ public function categories() { $options = array(); if ( $this->installed() ) { $options = cbblogsModel::getCategoriesList(); } return $options; }
/** * @param int[] $paging * @param string $where * @param UserTable $viewer * @param UserTable $user * @param PluginTable $plugin * @return cbblogsBlogTable[] */ static public function getBlogs( $paging, $where, $viewer, $user, /** @noinspection PhpUnusedParameterInspection */ $plugin ) { global $_CB_database; $categories = cbblogsModel::getCategoriesList( true ); $blogs = array(); if ( $categories ) { $query = 'SELECT a.*' . ', a.' . $_CB_database->NameQuote( 'created_by' ) . ' AS user' . ', a.' . $_CB_database->NameQuote( 'introtext' ) . ' AS blog_intro' . ', a.' . $_CB_database->NameQuote( 'fulltext' ) . ' AS blog_full' . ', b.' . $_CB_database->NameQuote( 'name' ) . ' AS category' . ', b.' . $_CB_database->NameQuote( 'published' ) . ' AS category_published' . ', b.' . $_CB_database->NameQuote( 'alias' ) . ' AS category_alias' . "\n FROM " . $_CB_database->NameQuote( '#__k2_items' ) . " AS a" . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__k2_categories' ) . " AS b" . ' ON b.' . $_CB_database->NameQuote( 'id' ) . ' = a.' . $_CB_database->NameQuote( 'catid' ) . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS c" . ' ON c.' . $_CB_database->NameQuote( 'id' ) . ' = a.' . $_CB_database->NameQuote( 'created_by' ) . "\n WHERE a." . $_CB_database->NameQuote( 'catid' ) . " IN ( " . implode( ',', $categories ) . " )" . "\n AND a." . $_CB_database->NameQuote( 'created_by' ) . " = " . (int) $user->get( 'id' ) . ( ( $viewer->get( 'id' ) != $user->get( 'id' ) ) && ( ! Application::User( (int) $viewer->get( 'id' ) )->isGlobalModerator() ) ? "\n AND a." . $_CB_database->NameQuote( 'published' ) . " = 1" : null ) . ( ! Application::Cms()->getClientId() ? "\n AND a." . $_CB_database->NameQuote( 'trash' ) . " = 0" : null ) . "\n AND a." . $_CB_database->NameQuote( 'access' ) . " IN " . $_CB_database->safeArrayOfIntegers( Application::MyUser()->getAuthorisedViewLevels() ) . $where . "\n ORDER BY a." . $_CB_database->NameQuote( 'created' ) . " DESC"; if ( $paging ) { $_CB_database->setQuery( $query, $paging[0], $paging[1] ); } else { $_CB_database->setQuery( $query ); } $blogs = $_CB_database->loadObjectList( null, 'cbblogsBlogTable', array( $_CB_database ) ); } return $blogs; }
/** * @param null|int $id * @param UserTable $user * @param stdClass $model * @param PluginTable $plugin * @param null|string $message * @param null|string $messageType */ public function showBlogEdit( $id, $user, $model, $plugin, $message = null, $messageType = 'error' ) { global $_CB_framework; $blogLimit = (int) $plugin->params->get( 'blog_limit', null ); $blogMode = $plugin->params->get( 'blog_mode', 1 ); $cbModerator = Application::User( (int) $user->get( 'id' ) )->isGlobalModerator(); $row = new cbblogsBlogTable(); $canAccess = false; if ( $row->load( (int) $id ) ) { if ( ! $row->get( 'id' ) ) { if ( $cbModerator ) { $canAccess = true; } elseif ( $user->get( 'id' ) && Application::MyUser()->canViewAccessLevel( $plugin->params->get( 'blog_create_access', 2 ) ) ) { if ( ( ! $blogLimit ) || ( $blogLimit && ( cbblogsModel::getBlogsTotal( null, $user, $user, $plugin ) < $blogLimit ) ) ) { $canAccess = true; } } } elseif ( $cbModerator || ( $row->get( 'user' ) == $user->get( 'id' ) ) ) { $canAccess = true; } } $profileUrl = $_CB_framework->userProfileUrl( $row->get( 'user', $user->get( 'id' ) ), false, 'cbblogsTab' ); if ( $canAccess ) { cbblogsClass::getTemplate( 'blog_edit' ); $input = array(); $publishedTooltip = cbTooltip( $_CB_framework->getUi(), CBTxt::T( 'Select publish status of the blog. Unpublished blogs will not be visible to the public.' ), null, null, null, null, null, 'data-hascbtooltip="true"' ); $input['published'] = moscomprofilerHTML::yesnoSelectList( 'published', 'class="form-control"' . ( $publishedTooltip ? ' ' . $publishedTooltip : null ), (int) $this->input( 'post/published', $row->get( 'published', ( $cbModerator || ( ! $plugin->params->get( 'blog_approval', 0 ) ) ? 1 : 0 ) ), GetterInterface::INT ) ); $categoryTooltip = cbTooltip( $_CB_framework->getUi(), CBTxt::T( 'Select blog category. Select the category that best describes your blog.' ), null, null, null, null, null, 'data-hascbtooltip="true"' ); $listCategory = cbblogsModel::getCategoriesList(); $input['category'] = moscomprofilerHTML::selectList( $listCategory, 'category', 'class="form-control"' . ( $categoryTooltip ? ' ' . $categoryTooltip : null ), 'value', 'text', $this->input( 'post/category', $row->get( 'category' ), GetterInterface::STRING ), 1, false, false ); $accessTooltip = cbTooltip( $_CB_framework->getUi(), CBTxt::T( 'Select access to blog; all groups above that level will also have access to the blog.' ), null, null, null, null, null, 'data-hascbtooltip="true"' ); $listAccess = Application::CmsPermissions()->getAllViewAccessLevels( true, Application::MyUser() ); $input['access'] = moscomprofilerHTML::selectList( $listAccess, 'access', 'class="form-control"' . ( $accessTooltip ? ' ' . $accessTooltip : null ), 'value', 'text', (int) $this->input( 'post/access', $row->get( 'access', $plugin->params->get( 'blog_access_default', 1 ) ), GetterInterface::INT ), 1, false, false ); $titleTooltip = cbTooltip( $_CB_framework->getUi(), CBTxt::T( 'Input blog title. This is the title that will distinguish this blog from others. Suggested to input something unique and intuitive.' ), null, null, null, null, null, 'data-hascbtooltip="true"' ); $input['title'] = '<input type="text" id="title" name="title" value="' . htmlspecialchars( $this->input( 'post/title', $row->get( 'title' ), GetterInterface::STRING ) ) . '" class="required form-control" size="30"' . ( $titleTooltip ? ' ' . $titleTooltip : null ) . ' />'; if ( in_array( $blogMode, array( 1, 2 ) ) ) { $blogIntro = $_CB_framework->displayCmsEditor( 'blog_intro', $this->input( 'post/blog_intro', $row->get( 'blog_intro' ), GetterInterface::HTML ), 400, 200, 40, 7 ); $input['blog_intro'] = cbTooltip( $_CB_framework->getUi(), CBTxt::T( 'Input HTML supported blog intro contents. Suggested to use minimal but well formatting for easy readability.' ), null, null, null, $blogIntro, null, 'style="display:block;"' ); } if ( in_array( $blogMode, array( 1, 3 ) ) ) { $blogFull = $_CB_framework->displayCmsEditor( 'blog_full', $this->input( 'post/blog_full', $row->get( 'blog_full' ), GetterInterface::HTML ), 400, 200, 40, 7 ); $input['blog_full'] = cbTooltip( $_CB_framework->getUi(), CBTxt::T( 'Input HTML supported blog contents. Suggested to use minimal but well formatting for easy readability.' ), null, null, null, $blogFull, null, 'style="display:block;"' ); } $userTooltip = cbTooltip( $_CB_framework->getUi(), CBTxt::T( 'Input owner of blog as single integer user_id.' ), null, null, null, null, null, 'data-hascbtooltip="true"' ); $input['user'] = '******' . (int) ( $cbModerator ? $this->input( 'post/user', $row->get( 'user', $user->get( 'id' ) ), GetterInterface::INT ) : $user->get( 'id' ) ) . '" class="digits required form-control" size="4"' . ( $userTooltip ? ' ' . $userTooltip : null ) . ' />'; if ( $message ) { $_CB_framework->enqueueMessage( $message, $messageType ); } HTML_cbblogsBlogEdit::showBlogEdit( $row, $input, $user, $model, $plugin ); } else { cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' ); } }