Exemplo n.º 1
0
	/**
	 * @param UserTable  $user
	 * @param GroupTable $group
	 * @param array      $counters
	 * @return array|null
	 */
	public function getTopics( $user, &$group, &$counters )
	{
		global $_CB_framework, $_CB_database;

		$categoryId					=	(int) $group->params()->get( 'forum_id' );

		if ( ( ! $categoryId ) || ( ! $group->params()->get( 'forums', 1 ) ) || ( $group->category()->get( 'id' ) && ( ! $group->category()->params()->get( 'forums', 1 ) ) ) ) {
			return null;
		}

		CBGroupJive::getTemplate( 'forums', true, true, $this->plugin->element );

		$limit						=	(int) $this->params->get( 'groups_forums_limit', 15 );
		$limitstart					=	$_CB_framework->getUserStateFromRequest( 'gj_group_forums_limitstart{com_comprofiler}', 'gj_group_forums_limitstart' );
		$search						=	$_CB_framework->getUserStateFromRequest( 'gj_group_forums_search{com_comprofiler}', 'gj_group_forums_search' );
		$where						=	null;

		if ( $search && $this->params->get( 'groups_forums_search', 1 ) ) {
			$where					.=	'( m.' . $_CB_database->NameQuote( 'subject' ) . ' LIKE ' . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $search, true ) . '%', false )
									.	' OR t.' . $_CB_database->NameQuote( 'message' ) . ' LIKE ' . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $search, true ) . '%', false ) . ' )';
		}

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

		$params						=	array(	'starttime' => -1,
												'where' => $where
											);

		$posts						=	\KunenaForumMessageHelper::getLatestMessages( $categoryId, 0, 0, $params );
		$total						=	array_shift( $posts );

		if ( ( ! $total ) && ( ! $searching ) && ( ! CBGroupJive::canCreateGroupContent( $user, $group, 'forums' ) ) ) {
			return null;
		}

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

		$pageNav->setInputNamePrefix( 'gj_group_forums_' );

		switch( (int) $this->params->get( 'groups_forums_orderby', 2 ) ) {
			case 1:
				$params['orderby']	=	'm.' . $_CB_database->NameQuote( 'time' ) . ' ASC';
				break;
		}

		if ( $this->params->get( 'groups_forums_paging', 1 ) ) {
			$posts					=	\KunenaForumMessageHelper::getLatestMessages( $categoryId, (int) $pageNav->limitstart, (int) $pageNav->limit, $params );
			$posts					=	array_pop( $posts );
		} else {
			$posts					=	array_pop( $posts );
		}

		$rows						=	array();

		/** @var \KunenaForumMessage[] $posts */
		foreach ( $posts as $post ) {
			$row					=	new PostTable();

			$row->post( $post );

			$rows[]					=	$row;
		}

		$input						=	array();

		$input['search']			=	'<input type="text" name="gj_group_forums_search" value="' . htmlspecialchars( $search ) . '" onchange="document.gjGroupForumsForm.submit();" placeholder="' . htmlspecialchars( CBTxt::T( 'Search Posts...' ) ) . '" class="form-control" />';

		CBGroupJive::preFetchUsers( $rows );

		$group->set( '_forums', $pageNav->total );

		return array(	'id'		=>	'forums',
						'title'		=>	CBTxt::T( 'Forums' ),
						'content'	=>	\HTML_groupjiveForums::showForums( $rows, $pageNav, $searching, $input, $counters, $group, $user, $this )
					);
	}
Exemplo n.º 2
0
	/**
	 * @param GroupTable  $group
	 * @param UserTable   $user
	 * @return bool
	 */
	static public function canAccessGroup( $group, $user )
	{
		global $_PLUGINS;

		if ( ! $group->get( 'id' ) ) {
			return false;
		} elseif ( CBGroupJive::isModerator( $user->get( 'id' ) ) ) {
			return true;
		}

		static $params					=	null;

		if ( ! $params ) {
			$plugin						=	$_PLUGINS->getLoadedPlugin( 'user', 'cbgroupjive' );
			$params						=	$_PLUGINS->getPluginParams( $plugin );
		}

		static $cache					=	array();

		$groupId						=	(int) $group->get( 'id' );
		$userId							=	(int) $user->get( 'id' );

		if ( ! isset( $cache[$userId][$groupId] ) ) {
			$access						=	true;

			if ( ( ! $group->category()->get( 'id' ) ) && ( ! $params->get( 'groups_uncategorized', 1 ) ) ) {
				$access					=	false;
			} elseif ( $group->category()->get( 'id' ) && ( ( ! $group->category()->get( 'published' ) ) || ( ! CBGroupJive::canAccess( (int) $group->category()->get( 'access' ), (int) $user->get( 'id' ) ) ) ) ) {
				$access					=	false;
			} elseif ( ( $group->get( 'published' ) != 1 ) && ( $user->get( 'id' ) != $group->get( 'user_id' ) ) ) {
				$access					=	false;
			} elseif ( $user->get( 'id' ) != $group->get( 'user_id' ) ) {
				$userStatus				=	CBGroupJive::getGroupStatus( $user, $group );

				if ( $userStatus == -1 ) {
					$access				=	false;
				} elseif ( ( $group->get( 'type' ) == 3 ) && ( ( $userStatus === false ) || ( $userStatus === null ) ) && ( ! CBGroupJive::getGroupInvited( $user, $group ) ) ) {
					$access				=	false;
				}
			}

			$cache[$userId][$groupId]	=	$access;
		}

		return $cache[$userId][$groupId];
	}
Exemplo n.º 3
0
	/**
	 * store the forum category for the group or category that was deleted
	 *
	 * @param GroupTable|CategoryTable $row
	 */
	public function storeForum( $row )
	{
		if ( ( ! $this->_forumModel ) || $row->get( '_skipForums' ) ) {
			return;
		}

		$parent					=	(int) $this->params->get( 'groups_forums_category' );

		if ( ! $parent ) {
			return;
		}

		if ( ( $row instanceof GroupTable ) && $row->category()->get( 'id' ) ) {
			$parentCategory		=	$this->_forumModel->getCategory( (int) $row->category()->params()->get( 'forum_id' ) );

			if ( ! $parentCategory->get( 'id' ) ) {
				$parentCategory->set( 'parent', $parent );
				$parentCategory->set( 'name', $row->category()->get( 'name' ) );
				$parentCategory->set( 'alias', $row->category()->get( 'id' ) . '-' . $row->category()->get( 'name' ) );
				$parentCategory->set( 'description', $row->category()->get( 'description' ) );
				$parentCategory->set( 'published', ( ! $row->category()->params()->get( 'forums', 1 ) ? 0 : $row->category()->get( 'published' ) ) );

				$parentCategory->access( $row->category() );

				if ( ! $parentCategory->check() ) {
					return;
				}

				if ( ! $parentCategory->store() ) {
					return;
				}

				$row->category()->set( '_skipForums', true );

				$row->category()->params()->set( 'forum_id', (int) $parentCategory->get( 'id' ) );

				$row->category()->set( 'params', $row->category()->params()->asJson() );

				$row->category()->store();

				$row->category()->set( '_skipForums', false );
			}

			$parent				=	(int) $parentCategory->get( 'id' );
		}

		$category				=	$this->_forumModel->getCategory( (int) $row->params()->get( 'forum_id' ) );

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

		$category->set( 'parent', $parent );
		$category->set( 'name', $row->get( 'name' ) );
		$category->set( 'alias', $row->get( 'id' ) . '-' . $row->get( 'name' ) );
		$category->set( 'description', $row->get( 'description' ) );
		$category->set( 'published', ( ! $row->params()->get( 'forums', 1 ) ? 0 : $row->get( 'published' ) ) );

		$category->access( $row );

		if ( ! $category->check() ) {
			return;
		}

		if ( ! $category->store() ) {
			return;
		}

		if ( ( $row instanceof GroupTable ) && ( ! CBGroupJive::isModerator( $row->get( 'user_id' ) ) ) ) {
			$moderators			=	$category->moderators();

			if ( ! in_array( $row->get( 'user_id' ), $moderators ) ) {
				$category->moderators( $row->get( 'user_id' ) );
			}
		}

		if ( $new ) {
			$row->set( '_skipForums', true );

			$row->params()->set( 'forum_id', (int) $category->get( 'id' ) );

			$row->set( 'params', $row->params()->asJson() );

			$row->store();

			$row->set( '_skipForums', false );
		}
	}