示例#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 );
	}
	/**
	 * Saves a folder
	 *
	 * @param int       $id
	 * @param string    $type
	 * @param TabTable  $tab
	 * @param UserTable $user
	 * @param UserTable $viewer
	 */
	private function saveFolderEdit( $id, $type, $tab, $user, $viewer )
	{
		global $_CB_framework, $_PLUGINS;

		$row						=	new cbgalleryFolderTable();

		$row->load( (int) $id );

		$cbModerator				=	Application::User( (int) $viewer->get( 'id' ) )->isGlobalModerator();
		$canAccess					=	false;

		if ( ! $row->get( 'id' ) ) {
			if ( ( $user->get( 'id' ) != $viewer->get( 'id' ) ) && ( ! $cbModerator ) ) {
				$user				=	$viewer;
			}

			$canAccess				=	cbgalleryClass::canUserCreate( $viewer, $type, true );
		} elseif ( ( $row->get( 'type' ) == $type ) && ( $cbModerator || ( $viewer->get( 'id' ) == $row->get( 'user_id' ) ) ) ) {
			$canAccess				=	true;
		}

		if ( $this->input( 'folder', false, GetterInterface::BOOLEAN ) ) {
			$returnUrl				=	$_CB_framework->pluginClassUrl( $this->element, false, array( 'action' => 'folders', 'func' => 'show', 'type' => $type, 'id' => (int) $row->get( 'id' ), 'user' => (int) $user->get( 'id' ), 'tab' => (int) $tab->get( 'tabid' ) ) );
		} else {
			$returnUrl				=	$_CB_framework->userProfileUrl( (int) $row->get( 'user_id', $user->get( 'id' ) ), false, $tab->get( 'tabid' ) );
		}

		if ( ! $canAccess ) {
			cbRedirect( $returnUrl, CBTxt::T( 'Not authorized.' ), 'error' );
		}

		switch( $type ) {
			case 'photos':
			case 'videos':
			case 'music':
				$typeTranslated		=	CBTxt::T( 'Album' );
				break;
			default:
				$typeTranslated		=	CBTxt::T( 'Folder' );
				break;
		}

		if ( $cbModerator || ( ! $this->params->get( $type . '_folder_approval', 0 ) ) || ( $row->get( 'id' ) && ( $row->get( 'published' ) != -1 ) ) ) {
			$row->set( 'published', $this->input( 'post/published', $row->get( 'published', 1 ), GetterInterface::INT ) );
		} else {
			$row->set( 'published', ( $this->params->get( $type . '_folder_approval', 0 ) ? -1 : $row->get( 'published', 1 ) ) );
		}

		$row->set( 'type', $type );
		$row->set( 'title', $this->input( 'post/title', $row->get( 'title' ), GetterInterface::STRING ) );
		$row->set( 'description', $this->input( 'post/description', $row->get( 'description' ), GetterInterface::STRING ) );

		if ( $cbModerator ) {
			$row->set( 'user_id', $this->input( 'post/user_id', $row->get( 'user_id', $viewer->get( 'id' ) ), GetterInterface::INT ) );
		} else {
			$row->set( 'user_id', $row->get( 'user_id', $viewer->get( 'id' ) ) );
		}

		if ( $this->params->get( $type . '_folder_captcha', 0 ) && ( ! $cbModerator ) ) {
			$_PLUGINS->loadPluginGroup( 'user' );

			$_PLUGINS->trigger( 'onCheckCaptchaHtmlElements', array() );

			if ( $_PLUGINS->is_errors() ) {
				$row->setError( $_PLUGINS->getErrorMSG() );
			}
		}

		$new						=	( $row->get( 'id' ) ? false : true );

		if ( $row->getError() || ( ! $row->check() ) ) {
			$this->showItemEdit( $id, $type, $tab, $user, $viewer, CBTxt::T( 'FOLDER_FAILED_TO_SAVE', '[type] failed to save! Error: [error]', array( '[type]' => $typeTranslated, '[error]' => $row->getError() ) ) );
			return;
		}

		if ( $row->getError() || ( ! $row->store() ) ) {
			$this->showItemEdit( $id, $type, $tab, $user, $viewer, CBTxt::T( 'FOLDER_FAILED_TO_SAVE', '[type] failed to save! Error: [error]', array( '[type]' => $typeTranslated, '[error]' => $row->getError() ) ) );
			return;
		}

		if ( $row->get( 'published' ) == -1 ) {
			if ( $new && ( ! $cbModerator ) && $this->params->get( $type . '_folder_approval_notify', 1 ) ) {
				$cbUser				=	CBuser::getInstance( (int) $row->get( 'user_id' ), false );

				$extraStrings		=	array(	'folder_id' => (int) $row->get( 'id' ),
												'folder_title' => ( $row->get( 'title' ) ? $row->get( 'title' ) : $row->get( 'date' ) ),
												'folder_description' => $row->get( 'description' ),
												'folder_date' => $row->get( 'date' ),
												'folder_url' => $_CB_framework->pluginClassUrl( $this->element, true, array( 'action' => 'folders', 'func' => 'show', 'type' => $type, 'id' => (int) $row->get( 'id' ), 'user' => (int) $row->get( 'user_id' ), 'tab' => (int) $tab->get( 'tabid' ) ) ),
												'folder_type' => $typeTranslated,
												'folder_tab_url' => $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ), 'tab' => (int) $tab->get( 'tabid' ) ) ),
												'gallery_photos_url' => $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ), 'tab' => 'cbgalleryTabPhotos' ) ),
												'gallery_videos_url' => $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ), 'tab' => 'cbgalleryTabVideos' ) ),
												'gallery_music_url' => $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ), 'tab' => 'cbgalleryTabMusic' ) ),
												'gallery_files_url' => $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ), 'tab' => 'cbgalleryTabFiles' ) ),
												'user_url' => $_CB_framework->viewUrl( 'userprofile', true, array( 'user' => (int) $row->get( 'user_id' ) ) )
											);

				$subject			=	$cbUser->replaceUserVars( CBTxt::T( 'NOTIFY_NEW_FOLDER_CREATED_SUBJECT', 'Gallery - New [type] Created!', array( '[type]' => $typeTranslated ) ), false, true, $extraStrings, false );
				$message			=	$cbUser->replaceUserVars( CBTxt::T( 'NOTIFY_NEW_FOLDER_CREATED_BODY', '<a href="[user_url]">[formatname]</a> created [folder_type] <a href="[folder_url]">[folder_title]</a> and requires <a href="[folder_tab_url]">approval</a>!' ), false, true, $extraStrings, false );

				$notifications		=	new cbNotification();

				$notifications->sendToModerators( $subject, $message, false, 1 );
			}

			cbRedirect( $returnUrl, CBTxt::T( 'FOLDER_SAVED_SUCCESSFULLY_AND_AWAITING_APPROVAL', '[type] saved successfully and awaiting approval!', array( '[type]' => $typeTranslated ) ) );
		} else {
			cbRedirect( $returnUrl, CBTxt::T( 'FOLDER_SAVED_SUCCESSFULLY', '[type] saved successfully!', array( '[type]' => $typeTranslated ) ) );
		}
	}
示例#3
0
	/**
	 * Returns the fontawesome icon based off extension and that extensions mimetype
	 *
	 * @param string $extension
	 * @return string
	 */
	static public function getFileIcon( $extension )
	{
		$type							=	'file-o';

		if ( ! $extension ) {
			return $type;
		}

		static $cache					=	array();

		if ( ! isset( $cache[$extension] ) ) {
			$mimeParts					=	explode( '/', cbgalleryClass::getMimeTypes( $extension ) );

			switch ( $mimeParts[0] ) {
				case 'text':
					switch ( $extension ) {
						case 'csv':
							$type		=	'file-excel-o';
							break;
						case 'css':
						case 'html':
						case 'htm':
							$type		=	'file-code-o';
							break;
						default:
							$type		=	'file-text-o';
							break;
					}
					break;
				case 'video':
					$type				=	'file-video-o';
					break;
				case 'audio':
					$type				=	'file-audio-o';
					break;
				case 'image':
					$type				=	'file-image-o';
					break;
				default:
					switch ( $extension ) {
						case 'pdf':
							$type		=	'file-pdf-o';
							break;
						case 'zip':
						case '7z':
						case 'rar':
						case 'tar':
						case 'iso':
							$type		=	'file-archive-o';
							break;
						case 'js':
						case 'php':
						case 'xml':
						case 'java':
							$type		=	'file-code-o';
							break;
						case 'ods':
						case 'xls':
						case 'xlsx':
						case 'xlt':
							$type		=	'file-excel-o';
							break;
						case 'doc':
						case 'docx':
						case 'odt':
						case 'dot':
							$type		=	'file-word-o';
							break;
					}
					break;
			}

			$cache[$extension]			=	$type;
		}

		return $cache[$extension];
	}
示例#4
0
	/**
	 * @param cbgalleryFolderTable|cbgalleryFolderTable[] $folders        cbgalleryFolderTable: we're IN a folder; cbgalleryFolderTable[]: we're on profile
	 * @param null|cbPageNav                              $foldersPageNav Null: we're IN a folder; cbPageNav: we're on profile
	 * @param bool                                        $foldersSearching
	 * @param cbgalleryItemTable[]                        $items
	 * @param cbPageNav                                   $itemsPageNav
	 * @param bool                                        $itemsSearching
	 * @param string                                      $type
	 * @param array                                       $input
	 * @param UserTable                                   $viewer
	 * @param UserTable                                   $user
	 * @param TabTable                                    $tab
	 * @param cbTabHandler                                $plugin
	 * @return string
	 */
	static public function showItems( $folders, $foldersPageNav, $foldersSearching, $items, $itemsPageNav, $itemsSearching, $type, $input, $viewer, $user, $tab, $plugin )
	{
		global $_CB_framework, $_PLUGINS;

		$_PLUGINS->trigger( 'gallery_onBeforeDisplayItems', array( &$folders, $foldersPageNav, $foldersSearching, &$items, $itemsPageNav, $itemsSearching, $type, &$input, $viewer, $user, $tab, $plugin ) );

		switch( $type ) {
			case 'photos':
				$typeTranslated				=	CBTxt::T( 'Photo' );
				break;
			case 'files':
				$typeTranslated				=	CBTxt::T( 'File' );
				break;
			case 'videos':
				$typeTranslated				=	CBTxt::T( 'Video' );
				break;
			case 'music':
				$typeTranslated				=	CBTxt::T( 'Music' );
				break;
			default:
				$typeTranslated				=	CBTxt::T( 'Item' );
				break;
		}

		switch( $type ) {
			case 'photos':
			case 'videos':
			case 'music':
				$folderType					=	CBTxt::T( 'Album' );
				break;
			default:
				$folderType					=	CBTxt::T( 'Folder' );
				break;
		}

		/** @var Registry $params */
		$params								=	$tab->params;
		$folder								=	( is_object( $folders ) ? $folders : null );
		$allowFolders						=	( $params->get( 'tab_' . $type . '_folders', 1 ) && ( ! $folder ) );
		$showFolders						=	( $allowFolders && $folders );
		$showItems							=	( ( ! $allowFolders ) || ( $allowFolders && $params->get( 'tab_' . $type . '_uncategorized', 1 ) ) );
		$canSearchFolders					=	( $showFolders ? ( $params->get( 'tab_' . $type . '_folders_search', 1 ) && ( $foldersSearching || $foldersPageNav->total ) ) : false );
		$canSearchItems						=	( $showItems ? ( $params->get( ( $folder ? 'tab_' . $type . '_folder_items_search' : 'tab_' . $type . '_items_search' ), 1 ) && ( $itemsSearching || $itemsPageNav->total ) ) : false );
		$profileOwner						=	( $viewer->get( 'id' ) == $user->get( 'id' ) );
		$cbModerator						=	Application::User( (int) $viewer->get( 'id' ) )->isGlobalModerator();
		$canCreateFolders					=	( ( $profileOwner || $cbModerator ) && $allowFolders ? cbgalleryClass::canUserCreate( $viewer, $type, true ) : false );
		$canCreateItems						=	( $profileOwner || $cbModerator ? cbgalleryClass::canUserCreate( $viewer, $type, false ) : false );

		if ( $folder ) {
			$formUrl						=	$_CB_framework->pluginClassUrl( $plugin->element, true, array( 'action' => 'folders', 'func' => 'show', 'type' => $type, 'id' => (int) $folders->get( 'id' ), 'user' => (int) $user->get( 'id' ), 'tab' => (int) $tab->get( 'tabid' ) ) );
		} else {
			$formUrl						=	$_CB_framework->userProfileUrl( (int) $user->get( 'id' ), true, (int) $tab->get( 'tabid' ) );
		}

		$return								=	'<div class="' . htmlspecialchars( $type ) . 'ItemsTab">'
											.		'<form action="' . $formUrl . '" method="post" name="' . htmlspecialchars( $type ) . 'ItemsForm" id="' . htmlspecialchars( $type ) . 'ItemsForm" class="' . htmlspecialchars( $type ) . 'ItemsForm galleryItemsForm">';

		if ( $folder ) {
			$return							.=			HTML_cbgalleryFolder::showFolder( $folders, $type, $viewer, $user, $tab, $plugin );
		}

		if ( ( $showFolders && ( $canCreateFolders || $canSearchFolders ) ) || ( ( ! $showItems ) && $canCreateItems ) ) {
			$return							.=			'<div class="galleryItemsHeader row" style="margin-bottom: 10px;">';

			if ( $canCreateFolders || ( ( ! $showItems ) && $canCreateItems ) ) {
				$return						.=				'<div class="' . ( ! $canSearchFolders ? 'col-sm-12' : 'col-sm-8' ) . ' text-left">'
											.					'<div class="btn-group">'
											.						( ( ! $showItems ) && $canCreateItems ? '<button type="button" onclick="location.href=\'' . $_CB_framework->pluginClassUrl( $plugin->element, false, array( 'action' => 'items', 'func' => 'new', 'type' => $type, 'user' => (int) $user->get( 'id' ), 'tab' => (int) $tab->get( 'tabid' ), 'folder' => ( $folder ? (int) $folders->get( 'id' ) : 0 ) ) ) . '\';" class="galleryButton galleryButtonNewItem btn btn-success"><span class="fa fa-plus-circle"></span> ' . CBTxt::T( 'NEW_ITEM_TYPE', 'New [type]', array( '[type]' => $typeTranslated ) ) . '</button>' : null )
											.						( $canCreateFolders ? '<button type="button" onclick="location.href=\'' . $_CB_framework->pluginClassUrl( $plugin->element, false, array( 'action' => 'folders', 'func' => 'new', 'type' => $type, 'user' => (int) $user->get( 'id' ), 'tab' => (int) $tab->get( 'tabid' ) ) ) . '\';" class="galleryButton galleryButtonNewItem btn btn-success"><span class="fa fa-plus-circle"></span> ' . CBTxt::T( 'NEW_FOLDER_TYPE', 'New [type]', array( '[type]' => $folderType ) ) . '</button>' : null )
											.					'</div>'
											.				'</div>';
			}

			if ( $canSearchFolders ) {
				$return						.=				'<div class="' . ( ! ( $canCreateFolders || ( ( ! $showItems ) && $canCreateItems ) ) ? 'col-sm-offset-8 ' : null ) . 'col-sm-4 text-right">'
											.					'<div class="input-group">'
											.						'<span class="input-group-addon"><span class="fa fa-search"></span></span>'
											.						$input['search_folders']
											.					'</div>'
											.				'</div>';
			}

			$return							.=			'</div>';
		} elseif ( ( ! $showFolders ) && ( $canCreateFolders || $canCreateItems || $canSearchItems ) ) {
			$return							.=			'<div class="galleryItemsHeader row" style="margin-bottom: 10px;">';

			if ( $canCreateFolders || $canCreateItems ) {
				$return						.=				'<div class="' . ( ! $canSearchItems ? 'col-sm-12' : 'col-sm-8' ) . ' text-left">'
											.					'<div class="btn-group">'
											.						( $canCreateItems ? '<button type="button" onclick="location.href=\'' . $_CB_framework->pluginClassUrl( $plugin->element, false, array( 'action' => 'items', 'func' => 'new', 'type' => $type, 'user' => (int) $user->get( 'id' ), 'tab' => (int) $tab->get( 'tabid' ), 'folder' => ( $folder ? (int) $folders->get( 'id' ) : 0 ) ) ) . '\';" class="galleryButton galleryButtonNewItem btn btn-success"><span class="fa fa-plus-circle"></span> ' . CBTxt::T( 'NEW_ITEM_TYPE', 'New [type]', array( '[type]' => $typeTranslated ) ) . '</button>' : null )
											.						( $canCreateFolders ? '<button type="button" onclick="location.href=\'' . $_CB_framework->pluginClassUrl( $plugin->element, false, array( 'action' => 'folders', 'func' => 'new', 'type' => $type, 'user' => (int) $user->get( 'id' ), 'tab' => (int) $tab->get( 'tabid' ) ) ) . '\';" class="galleryButton galleryButtonNewItem btn btn-success"><span class="fa fa-plus-circle"></span> ' . CBTxt::T( 'NEW_FOLDER_TYPE', 'New [type]', array( '[type]' => $folderType ) ) . '</button>' : null )
											.					'</div>'
											.				'</div>';
			}

			if ( $canSearchItems ) {
				$return						.=				'<div class="' . ( ! ( $canCreateFolders || $canCreateItems ) ? 'col-sm-offset-8 ' : null ) . 'col-sm-4 text-right">'
											.					'<div class="input-group">'
											.						'<span class="input-group-addon"><span class="fa fa-search"></span></span>'
											.						$input['search_items']
											.					'</div>'
											.				'</div>';
			}

			$return							.=			'</div>';
		}

		if ( $showFolders || ( ! $showItems ) ) {
			$return							.=			HTML_cbgalleryFolders::showFolders( $folders, $foldersPageNav, ( ! $showItems ? $itemsPageNav->total : 0 ), $type, $viewer, $user, $tab, $plugin );
		}

		if ( $showItems ) {
			if ( $showFolders && ( $canCreateItems || $canSearchItems ) ) {
				$return						.=			'<div class="galleryItemsHeader row" style="margin-bottom: 10px;">';

				if ( $canCreateItems ) {
					$return					.=				'<div class="' . ( ! $canSearchItems ? 'col-sm-12' : 'col-sm-8' ) . ' text-left">'
											.					'<button type="button" onclick="location.href=\'' . $_CB_framework->pluginClassUrl( $plugin->element, false, array( 'action' => 'items', 'func' => 'new', 'type' => $type, 'user' => (int) $user->get( 'id' ), 'tab' => (int) $tab->get( 'tabid' ), 'folder' => ( $folder ? (int) $folders->get( 'id' ) : 0 ) ) ) . '\';" class="galleryButton galleryButtonNewItem btn btn-success"><span class="fa fa-plus-circle"></span> ' . CBTxt::T( 'NEW_ITEM_TYPE', 'New [type]', array( '[type]' => $typeTranslated ) ) . '</button>'
											.				'</div>';
				}

				if ( $canSearchItems ) {
					$return					.=				'<div class="' . ( ! $canCreateItems ? 'col-sm-offset-8 ' : null ) . 'col-sm-4 text-right">'
											.					'<div class="input-group">'
											.						'<span class="input-group-addon"><span class="fa fa-search"></span></span>'
											.						$input['search_items']
											.					'</div>'
											.				'</div>';
				}

				$return						.=			'</div>';
			}

			switch( $type ) {
				case 'photos':
					$return					.=			HTML_cbgalleryPhotos::showPhotos( $items, $itemsPageNav, $folder, $itemsSearching, $viewer, $user, $tab, $plugin );
					break;
				case 'files':
					$return					.=			HTML_cbgalleryFiles::showFiles( $items, $itemsPageNav, $folder, $itemsSearching, $viewer, $user, $tab, $plugin );
					break;
				case 'videos':
					$return					.=			HTML_cbgalleryVideos::showVideos( $items, $itemsPageNav, $folder, $itemsSearching, $viewer, $user, $tab, $plugin );
					break;
				case 'music':
					$return					.=			HTML_cbgalleryMusic::showMusic( $items, $itemsPageNav, $folder, $itemsSearching, $viewer, $user, $tab, $plugin );
					break;
			}
		}

		$return								.=		'</form>'
											.	'</div>';

		return $return;
	}