/** * prepare frontend photos render * * @param string $return * @param GroupTable $group * @param string $users * @param string $invites * @param array $counters * @param array $buttons * @param array $menu * @param cbTabs $tabs * @param UserTable $user * @return array|null */ public function showPhotos( &$return, &$group, &$users, &$invites, &$counters, &$buttons, &$menu, &$tabs, $user ) { global $_CB_framework, $_CB_database; CBGroupJive::getTemplate( 'photos', true, true, $this->element ); $canModerate = ( CBGroupJive::isModerator( $user->get( 'id' ) ) || ( CBGroupJive::getGroupStatus( $user, $group ) >= 2 ) ); $limit = (int) $this->params->get( 'groups_photo_limit', 15 ); $limitstart = $_CB_framework->getUserStateFromRequest( 'gj_group_photo_limitstart{com_comprofiler}', 'gj_group_photo_limitstart' ); $search = $_CB_framework->getUserStateFromRequest( 'gj_group_photo_search{com_comprofiler}', 'gj_group_photo_search' ); $where = null; if ( $search && $this->params->get( 'groups_photo_search', 1 ) ) { $where .= "\n AND ( p." . $_CB_database->NameQuote( 'title' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $search, true ) . '%', false ) . " OR p." . $_CB_database->NameQuote( 'filename' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $search, true ) . '%', false ) . " OR p." . $_CB_database->NameQuote( 'description' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $search, true ) . '%', false ) . " )"; } $searching = ( $where ? true : false ); $query = 'SELECT COUNT(*)' . "\n FROM " . $_CB_database->NameQuote( '#__groupjive_plugin_photo' ) . " AS p" . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__comprofiler' ) . " AS cb" . ' ON cb.' . $_CB_database->NameQuote( 'id' ) . ' = p.' . $_CB_database->NameQuote( 'user_id' ) . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS j" . ' ON j.' . $_CB_database->NameQuote( 'id' ) . ' = cb.' . $_CB_database->NameQuote( 'id' ) . "\n WHERE p." . $_CB_database->NameQuote( 'group' ) . " = " . (int) $group->get( 'id' ) . "\n AND cb." . $_CB_database->NameQuote( 'approved' ) . " = 1" . "\n AND cb." . $_CB_database->NameQuote( 'confirmed' ) . " = 1" . "\n AND j." . $_CB_database->NameQuote( 'block' ) . " = 0"; if ( ! $canModerate ) { $query .= "\n AND ( p." . $_CB_database->NameQuote( 'user_id' ) . " = " . (int) $user->get( 'id' ) . ' OR p.' . $_CB_database->NameQuote( 'published' ) . ' = 1 )'; } $query .= $where; $_CB_database->setQuery( $query ); $total = (int) $_CB_database->loadResult(); if ( ( ! $total ) && ( ! $searching ) && ( ! CBGroupJive::canCreateGroupContent( $user, $group, 'photo' ) ) ) { return null; } $pageNav = new cbPageNav( $total, $limitstart, $limit ); $pageNav->setInputNamePrefix( 'gj_group_photo_' ); switch( (int) $this->params->get( 'groups_photo_orderby', 2 ) ) { case 1: $orderBy = 'p.' . $_CB_database->NameQuote( 'date' ) . ' ASC'; break; case 3: $orderBy = 'p.' . $_CB_database->NameQuote( 'filename' ) . ' ASC'; break; case 4: $orderBy = 'p.' . $_CB_database->NameQuote( 'filename' ) . ' DESC'; break; case 2: default: $orderBy = 'p.' . $_CB_database->NameQuote( 'date' ) . ' DESC'; break; } $query = 'SELECT p.*' . "\n FROM " . $_CB_database->NameQuote( '#__groupjive_plugin_photo' ) . " AS p" . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__comprofiler' ) . " AS cb" . ' ON cb.' . $_CB_database->NameQuote( 'id' ) . ' = p.' . $_CB_database->NameQuote( 'user_id' ) . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS j" . ' ON j.' . $_CB_database->NameQuote( 'id' ) . ' = cb.' . $_CB_database->NameQuote( 'id' ) . "\n WHERE p." . $_CB_database->NameQuote( 'group' ) . " = " . (int) $group->get( 'id' ) . "\n AND cb." . $_CB_database->NameQuote( 'approved' ) . " = 1" . "\n AND cb." . $_CB_database->NameQuote( 'confirmed' ) . " = 1" . "\n AND j." . $_CB_database->NameQuote( 'block' ) . " = 0"; if ( ! $canModerate ) { $query .= "\n AND ( p." . $_CB_database->NameQuote( 'user_id' ) . " = " . (int) $user->get( 'id' ) . ' OR p.' . $_CB_database->NameQuote( 'published' ) . ' = 1 )'; } $query .= $where . "\n ORDER BY " . $orderBy; if ( $this->params->get( 'groups_photo_paging', 1 ) ) { $_CB_database->setQuery( $query, $pageNav->limitstart, $pageNav->limit ); } else { $_CB_database->setQuery( $query ); } $rows = $_CB_database->loadObjectList( null, '\CB\Plugin\GroupJivePhoto\Table\PhotoTable', array( $_CB_database ) ); $input = array(); $input['search'] = '<input type="text" name="gj_group_photo_search" value="' . htmlspecialchars( $search ) . '" onchange="document.gjGroupPhotoForm.submit();" placeholder="' . htmlspecialchars( CBTxt::T( 'Search Photos...' ) ) . '" class="form-control" />'; CBGroupJivePhoto::getPhoto( $rows ); CBGroupJive::preFetchUsers( $rows ); $group->set( '_photos', $pageNav->total ); return array( 'id' => 'photo', 'title' => CBTxt::T( 'Photos' ), 'content' => HTML_groupjivePhoto::showPhotos( $rows, $pageNav, $searching, $input, $counters, $group, $user, $this ) ); }
/** * output photo * * @param bool $preview * @param bool $thumbnail * @param int $id * @param UserTable $user */ private function outputPhoto( $preview, $thumbnail, $id, $user ) { global $_CB_framework; $row = CBGroupJivePhoto::getPhoto( (int) $id ); $returnUrl = $_CB_framework->pluginClassUrl( $this->_gjPlugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $row->get( 'group' ) ) ); if ( $row->get( 'id' ) ) { if ( ! CBGroupJive::canAccessGroup( $row->group(), $user ) ) { cbRedirect( $returnUrl, CBTxt::T( 'Group does not exist.' ), 'error' ); } elseif ( ! CBGroupJive::isModerator( $user->get( 'id' ) ) ) { if ( ( $row->get( 'published' ) != 1 ) && ( CBGroupJive::getGroupStatus( $user, $row->group() ) < 2 ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have access to this photo.' ), 'error' ); } } } else { cbRedirect( $returnUrl, CBTxt::T( 'Photo does not exist.' ), 'error' ); } if ( $preview ) { $row->preview( $thumbnail ); } else { $row->download(); } }