Esempio n. 1
0
	public function getAccess( $trigger, $fbConfig, $params ) {
		if ( $trigger == 'getAllowedForumsRead' ) {
			$plugin						=	cbgjClass::getPlugin();
			$forum						=	$plugin->params->get( 'forum_id', null );

			if ( $forum ) {
				$forums					=	array();

				$categories				=	cbgjData::getCategories( array( 'forum_cat_read' ), array( 'params', 'REGEX', 'forum_id=[[:digit:]]+' ) );

				if ( $categories ) foreach ( $categories as $category ) {
					$cat_params			=	$category->getParams();

					$forums[]			=	$cat_params->get( 'forum_id', null );
				}

				$groups					=	cbgjData::getGroups( array( 'forum_grp_read' ), array( 'params', 'REGEX', 'forum_id=[[:digit:]]+' ) );

				if ( $groups ) foreach ( $groups as $group ) {
					$grp_params			=	$group->getParams();

					$forums[]			=	$grp_params->get( 'forum_id', null );
				}

				if ( ! empty( $forums ) ) {
					$forums[]			=	$forum;
					$existingAccess		=	explode( ',', $params[1] );
					$cleanAccess		=	array_diff( $forums, $existingAccess );
					$newAccess			=	array_merge( $existingAccess, $cleanAccess );

					cbArrayToInts( $newAccess );

					$params[1]			=	implode( ',', $newAccess );
				}
			}
		} elseif ( $trigger == 'authoriseUsers' ) {
			$plugin						=	cbgjClass::getPlugin();
			$forum						=	$plugin->params->get( 'forum_id', null );

			if ( $forum ) {
				$forumId				=	$params['category']->id;
				$users					=	$params['userids'];
				$ids					=	array();

				if ( $forumId && $users ) foreach ( $users as $user ) {
					$category			=	cbgjData::getCategories( array( array( 'forum_cat_access' ), $user ), array( 'params', 'REGEX', 'forum_id=[[:<:]]' . (int) $forumId . '[[:>:]]' ), null, null, false );

					if ( $category->get( 'id' ) ) {
						$ids[]			=	$user;
					}

					$group				=	cbgjData::getGroups( array( array( 'forum_grp_access' ), $user ), array( 'params', 'REGEX', 'forum_id=[[:<:]]' . (int) $forumId . '[[:>:]]' ), null, null, false );

					if ( $group->get( 'id' ) ) {
						$ids[]			=	$user;
					}
				}

				if ( ! empty( $ids ) ) {
					cbArrayToInts( $ids );

					$params['allow']	=	$ids;
				}
			}
		} elseif ( ( $trigger == 'onStart' ) && ( ( in_array( cbGetParam( $_REQUEST, 'view', null ), array( 'category', 'topic' ) ) ) && cbGetParam( $_REQUEST, 'catid', 0 ) ) ) {
			$plugin						=	cbgjClass::getPlugin();
			$backlink					=	$plugin->params->get( 'forum_backlink', 1 );
			$forum						=	$plugin->params->get( 'forum_id', null );

			if ( $backlink && $forum ) {
				cbgjClass::getTemplate( 'cbgroupjiveforums' );

				$catid					=	(int) cbGetParam( $_REQUEST, 'catid', 0 );

				if ( $forum == $catid ) {
					echo '<div id="cbGj"><div id="cbGjInner"><div class="gjTop gjTopCenter"><a href="' . cbgjClass::getPluginURL( array( 'overview' ) ) . '" role="button" class="gjButton btn"><i class="icon-share-alt"></i> ' . CBTxt::P( 'Back to [overview]', array( '[overview]' => cbgjClass::getOverride( 'overview' ) ) ) . '</a></div></div></div>';
				} else {
					$category			=	cbgjData::getCategories( array( 'cat_access', 'mod_lvl1' ), array( 'params', 'REGEX', 'forum_id=[[:<:]]' . (int) $catid . '[[:>:]]' ), null, null, false );

					if ( $category->get( 'id' ) ) {
						echo '<div id="cbGj"><div id="cbGjInner"><div class="gjTop gjTopCenter"><a href="' . $category->getUrl() . '" role="button" class="gjButton btn"><i class="icon-share-alt"></i> ' . CBTxt::P( 'Back to [category]', array( '[category]' => cbgjClass::getOverride( 'category' ) ) ) . '</a></div></div></div>';
					} else {
						$group			=	cbgjData::getGroups( array( 'grp_access', 'mod_lvl2' ), array( 'params', 'REGEX', 'forum_id=[[:<:]]' . (int) $catid . '[[:>:]]' ), null, null, false );

						if ( $group->get( 'id' ) ) {
							echo '<div id="cbGj"><div id="cbGjInner"><div class="gjTop gjTopCenter"><a href="' . $group->getUrl() . '" role="button" class="gjButton btn"><i class="icon-share-alt"></i> ' . CBTxt::P( 'Back to [group]', array( '[group]' => cbgjClass::getOverride( 'group' ) ) ) . '</a></div></div></div>';
						}
					}
				}
			}
		} elseif ( $trigger == 'loadGroups' ) {
			$items						=	cbgjClass::getCategoryGroupOptions();
			$itemsArray					=	array();

			foreach ( $items as $item ) {
				$id						=	$item->value;

				$row					=	new stdClass();
				$row->id				=	$id;
				$row->parent_id			=	0;
				$row->name				=	$item->text;

				$itemsArray[$id]		=	$row;
			}

			$params['groups']			=	$itemsArray;
		}
	}