Exemplo n.º 1
0
	/**
	 * @param string    $type
	 * @param TabTable  $tab
	 * @param UserTable $user
	 * @param UserTable $viewer
	 * @return null|string
	 */
	private function getGallery( $type, $tab, $user, $viewer )
	{
		list( $folders, $foldersPageNav, $foldersSearching, $foldersInput )	=	$this->getFolders( $type, $tab, $user, $viewer );
		list( $items, $itemsPageNav, $itemsSearching, $itemsInput )			=	$this->getItems( $type, $tab, $user, $viewer );

		$input																=	array_merge( $foldersInput, $itemsInput );

		$showEmpty															=	(int) ( isset( $ueConfig['showEmptyTabs'] ) ? $ueConfig['showEmptyTabs'] : 1 );

		cbgalleryClass::getTemplate( array( 'items', 'folder', 'folders', $type ) );

		if ( ( ! $showEmpty ) && ( ! ( $folders || cbgalleryClass::canUserCreate( $viewer, $type, true ) ) ) && ( ! ( $items || cbgalleryClass::canUserCreate( $viewer, $type, false ) ) ) ) {
			return null;
		}

		return HTML_cbgalleryItems::showItems( $folders, $foldersPageNav, $foldersSearching, $items, $itemsPageNav, $itemsSearching, $type, $input, $viewer, $user, $tab, $this );
	}
	/**
	 * Displays a folders items
	 *
	 * @param int       $id
	 * @param string    $type
	 * @param TabTable  $tab
	 * @param UserTable $user
	 * @param UserTable $viewer
	 * @param bool|int  $start
	 */
	private function showFolder( $id, $type, $tab, $user, $viewer, $start = false )
	{
		global $_CB_framework, $_CB_database, $_PLUGINS;

		/** @var Registry $params */
		$params							=	$tab->params;

		$row							=	new cbgalleryFolderTable();

		$profileUrl						=	$_CB_framework->userProfileUrl( (int) $user->get( 'id' ), false, $tab->get( 'tabid' ) );

		if ( $id !== 0 ) {
			$row->load( (int) $id );

			$folders					=	array( $row );

			$_PLUGINS->trigger( 'gallery_onLoadFolders', array( &$folders, $user ) );

			$profileUrl					=	$_CB_framework->userProfileUrl( (int) $row->get( 'user_id', $user->get( 'id' ) ), false, $tab->get( 'tabid' ) );

			if ( ( empty( $folders ) ) || ( ! $row->get( 'id' ) ) || ( $row->get( 'type' ) != $type ) || ( ( ! $row->get( 'published' ) ) && ( ( $viewer->get( 'id' ) != $row->get( 'user_id' ) ) || ( ! Application::User( (int) $viewer->get( 'id' ) )->isGlobalModerator() ) ) ) ) {
				cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' );
			}
		} else {
			$allowFolders				=	$params->get( 'tab_' . $type . '_folders', 1 );

			$query						=	'SELECT COUNT(*)'
										.	"\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_gallery_items' )
										.	"\n WHERE " . $_CB_database->NameQuote( 'type' ) . " = " . $_CB_database->Quote( $type )
										.	"\n AND " . $_CB_database->NameQuote( 'user_id' ) . " = " . (int) $user->get( 'id' )
										.	"\n AND " . $_CB_database->NameQuote( 'folder' ) . " = 0";
			$_CB_database->setQuery( $query );
			$uncategorized				=	(int) $_CB_database->loadResult();

			if ( ( ( ! $allowFolders ) || ( $allowFolders && $params->get( 'tab_' . $type . '_uncategorized', 1 ) ) ) || ( ! $uncategorized ) ) {
				cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' );
			}

			$row->set( 'id', 0 );
			$row->set( 'user_id', (int) $user->get( 'id' ) );
			$row->set( 'title', CBTxt::T( 'Uncategorized' ) );
			$row->set( 'date', $_CB_framework->getUTCDate() );
		}

		$tabPrefix						=	'tab_' . (int) $tab->get( 'tabid' ) . '_';
		$publishedOnly					=	( ( $viewer->get( 'id' ) != $user->get( 'id' ) ) && ( ! Application::User( (int) $viewer->get( 'id' ) )->isGlobalModerator() ) );

		$typePrefix						=	$tabPrefix . $type . '_folder_items_';
		$limit							=	(int) $params->get( 'tab_' . $type . '_folder_items_limit', 30 );
		$limitstart						=	( $start !== false ? (int) $start : $_CB_framework->getUserStateFromRequest( $typePrefix . 'limitstart{com_comprofiler}', $typePrefix . 'limitstart' ) );
		$search							=	$_CB_framework->getUserStateFromRequest( $typePrefix . 'search{com_comprofiler}', $typePrefix . 'search' );
		$where							=	null;

		if ( $search && $params->get( 'tab_' . $type . '_folder_items_search', 1 ) ) {
			$where						.=	"\n AND ( " . $_CB_database->NameQuote( 'value' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $search, true ) . '%', false )
										.	" OR " . $_CB_database->NameQuote( 'title' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $search, true ) . '%', false )
										.	" OR " . $_CB_database->NameQuote( 'description' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $search, true ) . '%', false ) . " )";
		}

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

		$query							=	'SELECT COUNT(*)'
										.	"\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_gallery_items' )
										.	"\n WHERE " . $_CB_database->NameQuote( 'type' ) . " = " . $_CB_database->Quote( $type )
										.	"\n AND " . $_CB_database->NameQuote( 'user_id' ) . " = " . (int) $row->get( 'user_id', $user->get( 'id' ) )
										.	"\n AND " . $_CB_database->NameQuote( 'folder' ) . " = " . (int) $row->get( 'id' )
										.	( $publishedOnly ? "\n AND " . $_CB_database->NameQuote( 'published' ) . " = 1" : null )
										.	$where;
		$_CB_database->setQuery( $query );
		$total							=	(int) $_CB_database->loadResult();

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

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

		$itemsPageNav->setInputNamePrefix( $typePrefix );

		$orderBy						=	$params->get( 'tab_' . $type . '_folder_items_orderby', 'date_desc' );

		if ( ! $orderBy ) {
			$orderBy					=	'date_desc';
		}

		$orderBy						=	explode( '_', $orderBy );

		$query							=	'SELECT *'
										.	"\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_gallery_items' )
										.	"\n WHERE " . $_CB_database->NameQuote( 'type' ) . " = " . $_CB_database->Quote( $type )
										.	"\n AND " . $_CB_database->NameQuote( 'user_id' ) . " = " . (int) $row->get( 'user_id', $user->get( 'id' ) )
										.	"\n AND " . $_CB_database->NameQuote( 'folder' ) . " = " . (int) $row->get( 'id' )
										.	( $publishedOnly ? "\n AND " . $_CB_database->NameQuote( 'published' ) . " = 1" : null )
										.	$where
										.	"\n ORDER BY " . $_CB_database->NameQuote( $orderBy[0] ) . " " . strtoupper( $orderBy[1] );
		if ( $params->get( 'tab_' . $type . '_folder_items_paging', 1 ) ) {
			$_CB_database->setQuery( $query, $itemsPageNav->limitstart, $itemsPageNav->limit );
		} else {
			$_CB_database->setQuery( $query );
		}
		$items							=	$_CB_database->loadObjectList( null, 'cbgalleryItemTable', array( $_CB_database ) );
		$itemsCount						=	count( $items );

		$_PLUGINS->trigger( 'gallery_onLoadItems', array( &$items, $user ) );

		if ( $itemsCount && ( ! count( $items ) ) ) {
			$this->showFolder( $id, $type, $tab, $user, $viewer, ( $limitstart + $limit ) );
			return;
		}

		switch( $type ) {
			case 'photos':
				$placeholder			=	CBTxt::T( 'Search Photos...' );
				break;
			case 'files':
				$placeholder			=	CBTxt::T( 'Search Files...' );
				break;
			case 'videos':
				$placeholder			=	CBTxt::T( 'Search Videos...' );
				break;
			case 'music':
				$placeholder			=	CBTxt::T( 'Search Music...' );
				break;
			default:
				$placeholder			=	CBTxt::T( 'Search...' );
				break;
		}

		$input							=	array();
		$input['search_items']			=	'<input type="text" name="' . htmlspecialchars( $typePrefix . 'search' ) . '" value="' . htmlspecialchars( $search ) . '" onchange="document.' . htmlspecialchars( $type ) . 'ItemsForm.submit();" placeholder="' . htmlspecialchars( $placeholder ) . '" class="form-control" />';

		cbgalleryClass::getTemplate( array( 'items', 'folder', 'folders', $type ) );

		echo HTML_cbgalleryItems::showItems( $row, null, false, $items, $itemsPageNav, $itemsSearching, $type, $input, $viewer, $user, $tab, $this );
	}