예제 #1
0
	/**
	 * prepares and stores group logo
	 *
	 * @param  string $file
	 * @return string
	 */
	public function storeLogo( $file ) {
		global $ueConfig;

		if ( isset( $_FILES[$file]['tmp_name'] ) && ! empty( $_FILES[$file]['tmp_name'] ) && ( $_FILES[$file]['error'] == 0 ) && ( is_uploaded_file( $_FILES[$file]['tmp_name'] ) ) ) {
			$plugin							=	cbgjClass::getPlugin();
			$logoSize						=	$plugin->params->get( 'logo_size', 2000 );
			$logoWidth						=	$plugin->params->get( 'logo_width', 200 );
			$logoHeight						=	$plugin->params->get( 'logo_height', 500 );
			$logoThumbwidth					=	$plugin->params->get( 'logo_thumbwidth', 60 );
			$logoThumbheight				=	$plugin->params->get( 'logo_thumbheight', 86 );
			$categoryPath					=	$plugin->imgsAbs . '/' . (int) $this->get( 'category' );
			$groupPath						=	$categoryPath . '/' . (int) $this->get( 'id' );
			$mode							=	cbgjClass::getFilePerms();

			cbgjClass::createFolderPath( $plugin->imgsAbs, $categoryPath, $groupPath );

			$allwaysResize					=	( isset( $ueConfig['avatarResizeAlways'] ) ? $ueConfig['avatarResizeAlways'] : 1 );
			$fileNameInDir					=	preg_replace( '/[^-a-zA-Z0-9_]/', '', uniqid( (int) $this->get( 'user_id' ) . '_' ) );

			$imgToolBox						=	new imgToolBox();
			$imgToolBox->_conversiontype	=	$ueConfig['conversiontype'];
			$imgToolBox->_IM_path			=	$ueConfig['im_path'];
			$imgToolBox->_NETPBM_path		=	$ueConfig['netpbm_path'];
			$imgToolBox->_maxsize			=	(int) ( $logoSize ? $logoSize : $ueConfig['avatarSize'] );
			$imgToolBox->_maxwidth			=	(int) ( $logoWidth ? $logoWidth : $ueConfig['avatarWidth'] );
			$imgToolBox->_maxheight			=	(int) ( $logoHeight ? $logoHeight : $ueConfig['avatarHeight'] );
			$imgToolBox->_thumbwidth		=	(int) ( $logoThumbwidth ? $logoThumbwidth : $ueConfig['thumbWidth'] );
			$imgToolBox->_thumbheight		=	(int) ( $logoThumbheight ? $logoThumbheight : $ueConfig['thumbHeight'] );
			$imgToolBox->_debug				=	0;

			$newFileName					=	$imgToolBox->processImage( $_FILES[$file], $fileNameInDir, $groupPath . '/', 0, 0, 1, $allwaysResize );

			if ( $newFileName ) {
				if ( $this->get( 'logo' ) ) {
					if ( file_exists( $groupPath . '/' . $this->getCleanLogo() ) ) {
						@unlink( $groupPath . '/' . $this->getCleanLogo() );
					}

					if ( file_exists( $groupPath . '/tn' . $this->getCleanLogo() ) ) {
						@unlink( $groupPath . '/tn' . $this->getCleanLogo() );
					}
				}

				$this->set( 'logo', $newFileName );

				@chmod( $groupPath . '/', $this->getCleanLogo(), $mode );
				@chmod( $groupPath . '/tn', $this->getCleanLogo(), $mode );

				$this->store();
			} else {
				$this->set( '_error', CBTxt::T( str_replace( 'Error: ', '', $imgToolBox->_errMSG ) ) );
			}
		} elseif ( $this->get( 'logo' ) && isset( $this->_previousCategory ) && ( $this->_previousCategory != $this->get( 'category' ) ) ) {
			$plugin				=	cbgjClass::getPlugin();
			$categoryPath		=	$plugin->imgsAbs . '/' . (int) $this->get( 'category' );
			$groupPath			=	$categoryPath . '/' . (int) $this->get( 'id' );
			$oldCategoryPath	=	$plugin->imgsAbs . '/' . (int) $this->_previousCategory;
			$oldGroupPath		=	$oldCategoryPath . '/' . (int) $this->get( 'id' );

			if ( file_exists( $oldGroupPath ) ) {
				cbgjClass::createFolderPath( $plugin->imgsAbs, $categoryPath, $groupPath );
				cbgjClass::copyDirectory( $oldGroupPath, $groupPath );
				cbgjClass::deleteDirectory( $oldGroupPath );
			}
		}
	}