Exemple #1
0
	/**
	 * Generates the HTML to display the user profile tab
	 *
	 * @param  \CB\Database\Table\TabTable   $tab       the tab database entry
	 * @param  \CB\Database\Table\UserTable  $user      the user being displayed
	 * @param  int                           $ui        1 for front-end, 2 for back-end
	 * @return string|boolean                           Either string HTML for tab content, or false if ErrorMSG generated
	 */
	public function getDisplayTab( $tab, $user, $ui )
	{
		global $_CB_framework, $_CB_database, $_LANG;

		outputCbJs( 1 );
		outputCbTemplate( 1 );
		cbimport( 'cb.pagination' );
                
                

		$plugin				=	cbhangoutClass::getPlugin();
		$model				=	cbhangoutClass::getModel();
		$viewer				=	CBuser::getMyUserDataInstance();

		cbhangoutClass::getTemplate( 'tab' );

		$limit				=	(int) $this->params->get( 'tab_limit', 15 );
		$limitstart			=	$_CB_framework->getUserStateFromRequest( 'tab_hangout_limitstart{com_comprofiler}', 'tab_hangout_limitstart' );
		$filterSearch		=	$_CB_framework->getUserStateFromRequest( 'tab_hangout_search{com_comprofiler}', 'tab_hangout_search' );
		$where				=	null;

		if ( isset( $filterSearch ) && ( $filterSearch != '' ) ) {
			if ( $model->type != 2 ) {
				$where		.=	"\n AND ( a." . $_CB_database->NameQuote( 'title' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $filterSearch, true ) . '%', false )
							.	" OR a." . $_CB_database->NameQuote( 'introtext' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $filterSearch, true ) . '%', false )
							.	" OR a." . $_CB_database->NameQuote( 'fulltext' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $filterSearch, true ) . '%', false ) . " )";
			} else {
				$where		.=	"\n AND ( a." . $_CB_database->NameQuote( 'title' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $filterSearch, true ) . '%', false )
							.	" OR a." . $_CB_database->NameQuote( 'hangout_intro' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $filterSearch, true ) . '%', false )
							.	" OR a." . $_CB_database->NameQuote( 'hangout_full' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $filterSearch, true ) . '%', false ) . " )";
			}
		}

		$searching			=	( $where ? true : false );

		$total				=	cbhangoutModel::getHangoutTotal( $where, $viewer, $user, $plugin );

		if ( $total <= $limitstart ) {
			$limitstart		=	0;
		}

		$pageNav			=	new cbPageNav( $total, $limitstart, $limit );

		$pageNav->setInputNamePrefix( 'tab_hangout_' );

		$rows				=	cbhangoutModel::getHangout( ( $this->params->get( 'tab_paging', 1 ) ? array( $pageNav->limitstart, $pageNav->limit ) : null ), $where, $viewer, $user, $plugin );

		$input				=	array();
		$input['search']	=	'<input type="text" name="tab_hangout_search" value="' . htmlspecialchars( $filterSearch ) . '" onchange="document.hangoutForm.submit();" placeholder="' . htmlspecialchars( CBTxt::T( 'Поиск...' ) ) . '" class="form-control" />';

		$tab->params		=	$this->params;

		$class				=	$plugin->params->get( 'general_class', null );

		$return				=	'<div id="cbHangout" class="cbBlogs' . ( $class ? ' ' . htmlspecialchars( $class ) : null ) . '">'
							.		'<div id="cbHangoutsInner" class="cbBlogsInner">'
							.			HTML_cbhangoutTab::showHangoutTab( $rows, $pageNav, $searching, $input, $viewer, $user, $model, $tab, $plugin )
							.		'</div>'
							.	'</div>';

		return $return;
	}
	/**
	 * @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, $_LANG;

		$blogLimit						=	(int) $plugin->params->get( 'hangout_limit', null );
		$blogMode						=	$plugin->params->get( 'hangout_mode', 1 );
		$cbModerator					=	Application::User( (int) $user->get( 'id' ) )->isGlobalModerator();

		$row							=	new cbhangoutBlogTable();

		$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( 'hangout_create_access', 2 ) ) ) {
					if ( ( ! $blogLimit ) || ( $blogLimit && ( cbhangoutModel::getHangoutTotal( 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, 'cbhangoutTab' );

		if ( $canAccess ) {
			cbhangoutClass::getTemplate( 'blog_edit' );

			$input						=	array();

			$publishedTooltip			=	cbTooltip( $_CB_framework->getUi(), CBTxt::T( 'Select publish status of the blog. Unpublished hangout 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( 'hangout_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				=	cbhangoutModel::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( 'hangout_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( 'hangout_intro', $this->input( 'post/hangout_intro', $row->get( 'hangout_intro' ), GetterInterface::HTML ), 400, 200, 40, 7 );

				$input['hangout_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( 'hangout_full', $this->input( 'post/hangout_full', $row->get( 'hangout_full' ), GetterInterface::HTML ), 400, 200, 40, 7 );

				$input['hangout_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;"' );
                                $input['price']				=	'<input type="text" id="price" name="price" value="' . htmlspecialchars( $this->input( 'post/price', $row->get( 'price' ), GetterInterface::STRING ) ) . '" class="required form-control" size="30"' . ( $priceTooltip ? ' ' . $priceTooltip : null ) . ' />';

			}

			$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_cbhangoutBlogEdit::showBlogEdit( $row, $input, $user, $model, $plugin );
		} else {
			cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' );
		}
	}