Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+326 -93
View File
@@ -11,7 +11,7 @@
namespace IPS\core\modules\front\clubs;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -66,8 +66,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
/* Sort out the breadcrumb */
\IPS\Output::i()->breadcrumb = array(
array( \IPS\Http\Url::internal( 'app=core&module=clubs&controller=directory', 'front', 'clubs_list' ), \IPS\Member::loggedIn()->language()->addToStack('module__core_clubs') ),
array( $this->club->url(), $this->club->name )
array( \IPS\Http\Url::internal( 'app=core&module=clubs&controller=directory', 'front', 'clubs_list' ), \IPS\Member::loggedIn()->language()->addToStack('module__core_clubs') )
);
/* Add a "Search in this club" contextual search option */
@@ -92,6 +91,29 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
{
\IPS\Session::i()->setLocation( \IPS\Http\Url::internal( 'app=core&module=clubs&controller=directory', 'front', 'clubs_list' ), array(), 'loc_clubs_directory' );
}
\IPS\Output::i()->sidebar['contextual'] = '';
/* Club info in sidebar */
if ( \IPS\Settings::i()->clubs_header == 'sidebar' )
{
\IPS\Output::i()->sidebar['contextual'] .= \IPS\Theme::i()->getTemplate( 'clubs', 'core' )->header( $this->club, NULL, 'sidebar' );
}
$club = $this->club;
if( ( \IPS\GeoLocation::enabled() and \IPS\Settings::i()->clubs_locations AND $location = $this->club->location() ) )
{
\IPS\Output::i()->sidebar['contextual'] .= \IPS\Theme::i()->getTemplate( 'clubs', 'core' )->clubLocationBox( $this->club, $location );
}
if( $this->club->type != $club::TYPE_PUBLIC AND $this->club->canViewMembers() )
{
\IPS\Output::i()->sidebar['contextual'] .= \IPS\Theme::i()->getTemplate( 'clubs', 'core' )->clubMemberBox( $this->club );
}
}
if ( !\in_array( \IPS\Request::i()->do, array( 'rules', 'leave', 'embed' ) ) AND $this->club->memberStatus( \IPS\Member::loggedIn() ) !== NULL AND !$this->club->rulesAcknowledged() )
{
\IPS\Output::i()->redirect( $this->club->url()->setQueryString( 'do', 'rules' )->addRef( \IPS\Request::i()->url() ) );
}
/* Pass upwards */
@@ -105,10 +127,13 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
*/
protected function manage()
{
/* Club info in sidebar */
if ( \IPS\Settings::i()->clubs_header == 'sidebar' )
$firstTab = $this->club->firstTab();
$key = key($firstTab);
if ( !\in_array( $key, array( 'club_home', 'club_members') ) )
{
\IPS\Output::i()->sidebar['contextual'] = \IPS\Theme::i()->getTemplate( 'clubs', 'core' )->header( $this->club, NULL, 'sidebar' );
\IPS\Output::i()->redirect( (string) $firstTab[ $key ]['href'] );
}
/* If this is a closed club, and we don't have permission to read it, show the member page instead */
@@ -117,10 +142,30 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
$this->members();
return;
}
else
{
if( $key == 'club_members' )
{
$this->members();
}
else
{
$this->overview();
}
return;
}
}
/**
* Overview page
*
* @return void
*/
protected function overview()
{
/* Get the activity stream */
$activity = \IPS\Content\Search\Query::init()->filterByClub( $this->club )->setOrder( \IPS\Content\Search\Query::ORDER_NEWEST_CREATED )->search();
/* Get who joined the club in between those results */
if ( $this->club->type != \IPS\Member\Club::TYPE_PUBLIC )
{
@@ -137,23 +182,28 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
}
}
$joins = array();
$joinWhere = array( array( 'club_id=?', $this->club->id ), array( \IPS\Db::i()->in( 'status', array( \IPS\Member\Club::STATUS_MEMBER, \IPS\Member\Club::STATUS_MODERATOR, \IPS\Member\Club::STATUS_LEADER ) ) ) );
if ( $lastTime )
if( $this->club->canViewMembers() )
{
$joinWhere[] = array( 'core_clubs_memberships.joined>?', $lastTime );
$joinWhere = array( array( 'club_id=?', $this->club->id ), array( \IPS\Db::i()->in( 'status', array( \IPS\Member\Club::STATUS_MEMBER, \IPS\Member\Club::STATUS_MODERATOR, \IPS\Member\Club::STATUS_LEADER ) ) ) );
if ( $lastTime )
{
$joinWhere[] = array( 'core_clubs_memberships.joined>?', $lastTime );
}
$select = 'core_clubs_memberships.joined' . ',' . implode( ',', array_map( function( $column ) {
return 'core_members.' . $column;
}, \IPS\Member::columnsForPhoto() ) );
foreach ( \IPS\Db::i()->select( $select, 'core_clubs_memberships', $joinWhere, 'joined DESC', array( 0, 50 ), NULL, NULL, \IPS\Db::SELECT_MULTIDIMENSIONAL_JOINS )->join( 'core_members', 'core_members.member_id=core_clubs_memberships.member_id' ) as $join )
{
$joins[] = new \IPS\Content\Search\Result\Custom(
\IPS\DateTime::ts( $join['core_clubs_memberships']['joined'] ),
\IPS\Member::loggedIn()->language()->addToStack( 'clubs_activity_joined', FALSE, array( 'htmlsprintf' => \IPS\Theme::i()->getTemplate( 'global', 'core', 'front' )->userLinkFromData( $join['core_members']['member_id'], $join['core_members']['name'], $join['core_members']['members_seo_name'] ) ) ),
\IPS\Theme::i()->getTemplate( 'global', 'core', 'front' )->userPhotoFromData( $join['core_members']['member_id'], $join['core_members']['name'], $join['core_members']['members_seo_name'], \IPS\Member::photoUrl( $join['core_members'] ), 'tiny' )
);
}
}
$select = 'core_clubs_memberships.joined' . ',' . implode( ',', array_map( function( $column ) {
return 'core_members.' . $column;
}, \IPS\Member::columnsForPhoto() ) );
foreach ( \IPS\Db::i()->select( $select, 'core_clubs_memberships', $joinWhere, 'joined DESC', array( 0, 50 ), NULL, NULL, \IPS\Db::SELECT_MULTIDIMENSIONAL_JOINS )->join( 'core_members', 'core_members.member_id=core_clubs_memberships.member_id' ) as $join )
{
$joins[] = new \IPS\Content\Search\Result\Custom(
\IPS\DateTime::ts( $join['core_clubs_memberships']['joined'] ),
\IPS\Member::loggedIn()->language()->addToStack( 'clubs_activity_joined', FALSE, array( 'htmlsprintf' => \IPS\Theme::i()->getTemplate( 'global', 'core', 'front' )->userLinkFromData( $join['core_members']['member_id'], $join['core_members']['name'], $join['core_members']['members_seo_name'] ) ) ),
\IPS\Theme::i()->getTemplate( 'global', 'core', 'front' )->userPhotoFromData( $join['core_members']['member_id'], $join['core_members']['name'], $join['core_members']['members_seo_name'], \IPS\Member::photoUrl( $join['core_members'] ), 'tiny' )
);
}
/* Merge them in */
if ( !empty( $joins ) )
{
@@ -175,11 +225,24 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
} );
}
}
/* Display */
\IPS\Output::i()->linkTags['canonical'] = (string) $this->club->url();
\IPS\Output::i()->title = $this->club->name;
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clubs')->view( $this->club, $activity, $this->club->fieldValues() );
if( $firstTab = $this->club->firstTab() AND !isset( $firstTab['club_home'] ) )
{
\IPS\Output::i()->breadcrumb[] = array( $this->club->url(), $this->club->name );
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Member::loggedIn()->language()->addToStack( 'club_home' ) );
}
else
{
\IPS\Output::i()->breadcrumb[] = array( NULL, $this->club->name );
}
/* Set some meta tags for the club */
$this->_setDefaultMetaTags();
}
/**
@@ -199,7 +262,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
*/
protected function edit()
{
if ( !( $this->club->owner and $this->club->owner == \IPS\Member::loggedIn() ) and !\IPS\Member::loggedIn()->modPermission('can_access_all_clubs') )
if ( !( $this->club->owner and $this->club->owner->member_id == \IPS\Member::loggedIn()->member_id ) and !\IPS\Member::loggedIn()->modPermission('can_access_all_clubs') )
{
\IPS\Output::i()->error( 'no_module_permission', '2C350/A', 403, '' );
}
@@ -209,7 +272,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
\IPS\Output::i()->title = $this->club->name;
if( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
}
else
{
@@ -237,7 +300,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
$form = new \IPS\Helpers\Form( 'club_profile_photo', 'continue' );
$form->ajaxOutput = TRUE;
$form->add( new \IPS\Helpers\Form\Upload( 'club_profile_photo', $this->club->profile_photo_uncropped ? \IPS\File::get( 'core_Clubs', $this->club->profile_photo_uncropped ) : NULL, FALSE, array( 'storageExtension' => 'core_Clubs', 'image' => array( 'maxWidth' => 200, 'maxHeight' => 200 ) ) ) );
$form->add( new \IPS\Helpers\Form\Upload( 'club_profile_photo', $this->club->profile_photo_uncropped ? \IPS\File::get( 'core_Clubs', $this->club->profile_photo_uncropped ) : NULL, FALSE, array( 'storageExtension' => 'core_Clubs', 'allowStockPhotos' => TRUE, 'image' => array( 'maxWidth' => 200, 'maxHeight' => 200 ) ) ) );
if ( $values = $form->values() )
{
if ( !$values['club_profile_photo'] or $this->club->profile_photo_uncropped != (string) $values['club_profile_photo'] )
@@ -275,7 +338,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
}
}
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
}
/**
@@ -285,7 +348,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
*/
protected function cropPhoto()
{
if ( !( $this->club->owner and $this->club->owner == \IPS\Member::loggedIn() ) and !\IPS\Member::loggedIn()->modPermission('can_access_all_clubs') )
if ( !$this->club->isLeader() )
{
\IPS\Output::i()->error( 'no_module_permission', '2C350/V', 403, '' );
}
@@ -349,7 +412,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
}
/* Display */
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
}
/**
@@ -375,7 +438,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
protected function members()
{
/* Public groups have no member list */
if ( $this->club->type === \IPS\Member\Club::TYPE_PUBLIC )
if ( !$this->club->canViewMembers() )
{
\IPS\Output::i()->error( 'node_error', '2C350/H', 404, '' );
}
@@ -451,9 +514,9 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
}
/* Sort out the offset */
$perPage = 28;
$perPage = $this->club->membersPerPage();
$activePage = isset( \IPS\Request::i()->page ) ? intval( \IPS\Request::i()->page ) : 1;
$activePage = isset( \IPS\Request::i()->page ) ? \intval( \IPS\Request::i()->page ) : 1;
if( $activePage < 1 )
{
@@ -481,9 +544,22 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
$clubStaff = $this->club->members( $staffStatuses, NULL, "IF(core_clubs_memberships.status='leader',0,1), core_clubs_memberships.joined ASC", $this->club->isLeader( \IPS\Member::loggedIn() ) ? 5 : 3 );
\IPS\Output::i()->title = $this->club->name;
\IPS\Output::i()->breadcrumb[] = array( $this->club->url()->setQueryString( 'do', 'members' ), \IPS\Member::loggedIn()->language()->addToStack('club_members') );
if( $firstTab = $this->club->firstTab() AND !isset( $firstTab['club_members'] ) )
{
\IPS\Output::i()->breadcrumb[] = array( $this->club->url(), $this->club->name );
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Member::loggedIn()->language()->addToStack( 'club_members' ) );
}
else
{
\IPS\Output::i()->breadcrumb[] = array( NULL, $this->club->name );
}
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'clubs' )->members( $this->club, $members, $pagination, $sortBy, $filter, $clubStaff );
}
/* Set some meta tags for the club */
$this->_setDefaultMetaTags();
}
/**
@@ -533,7 +609,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
$notification->recipients->attach( $leader );
}
}
if ( count( $notification->recipients ) )
if ( \count( $notification->recipients ) )
{
$notification->send();
}
@@ -546,7 +622,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
{
/* If other requests are pending, send us back, otherwise take us to the main member list */
$url = $this->club->url()->setQueryString( 'do', 'members' );
if ( count( $this->club->members( array( \IPS\Member\Club::STATUS_REQUESTED ) ) ) )
if ( \count( $this->club->members( array( \IPS\Member\Club::STATUS_REQUESTED ) ) ) )
{
\IPS\Output::i()->redirect( $url->setQueryString( 'filter', \IPS\Member\Club::STATUS_REQUESTED ) );
}
@@ -596,7 +672,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
{
/* If other requests are pending, send us back, otherwise take us to the main member list */
$url = $this->club->url()->setQueryString( 'do', 'members' );
if ( count( $this->club->members( array( \IPS\Member\Club::STATUS_REQUESTED ) ) ) )
if ( \count( $this->club->members( array( \IPS\Member\Club::STATUS_REQUESTED ) ) ) )
{
\IPS\Output::i()->redirect( $url->SetQueryString( 'filter', \IPS\Member\Club::STATUS_REQUESTED ) );
}
@@ -625,13 +701,14 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
/* Get member */
$member = \IPS\Member::load( \IPS\Request::i()->member );
if ( !in_array( $this->club->memberStatus( $member ), array( \IPS\Member\Club::STATUS_MEMBER, \IPS\Member\Club::STATUS_EXPIRED, \IPS\Member\Club::STATUS_MODERATOR, \IPS\Member\Club::STATUS_EXPIRED_MODERATOR ) ) )
if ( !\in_array( $this->club->memberStatus( $member ), array( \IPS\Member\Club::STATUS_MEMBER, \IPS\Member\Club::STATUS_EXPIRED, \IPS\Member\Club::STATUS_MODERATOR, \IPS\Member\Club::STATUS_EXPIRED_MODERATOR ) ) )
{
\IPS\Output::i()->error( 'node_error', '2C350/7', 403, '' );
}
/* Promote */
$this->club->addMember( $member, \IPS\Member\Club::STATUS_LEADER, TRUE );
$this->club->recountMembers();
/* Redirect */
\IPS\Output::i()->redirect( $this->club->url()->setQueryString( 'do', 'members' ) );
@@ -675,6 +752,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
/* Promote */
$this->club->addMember( $member, $status, TRUE );
$this->club->recountMembers();
/* Redirect */
\IPS\Output::i()->redirect( $this->club->url()->setQueryString( 'do', 'members' ) );
@@ -698,7 +776,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
/* Get member */
$member = ( \IPS\Application::appIsEnabled('nexus') and \IPS\Settings::i()->clubs_paid_on ) ? \IPS\nexus\Customer::load( \IPS\Request::i()->member ) : \IPS\Member::load( \IPS\Request::i()->member );
if ( !in_array( $this->club->memberStatus( $member ), array( \IPS\Member\Club::STATUS_MEMBER, \IPS\Member\Club::STATUS_EXPIRED, \IPS\Member\Club::STATUS_LEADER ) ) )
if ( !\in_array( $this->club->memberStatus( $member ), array( \IPS\Member\Club::STATUS_MEMBER, \IPS\Member\Club::STATUS_EXPIRED, \IPS\Member\Club::STATUS_LEADER ) ) )
{
\IPS\Output::i()->error( 'node_error', '2C350/L', 403, '' );
}
@@ -718,6 +796,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
/* Promote */
$this->club->addMember( $member, $status, TRUE );
$this->club->recountMembers();
/* Redirect */
\IPS\Output::i()->redirect( $this->club->url()->setQueryString( 'do', 'members' ) );
@@ -741,7 +820,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
/* Get member */
$member = ( \IPS\Application::appIsEnabled('nexus') and \IPS\Settings::i()->clubs_paid_on ) ? \IPS\nexus\Customer::load( \IPS\Request::i()->member ) : \IPS\Member::load( \IPS\Request::i()->member );
if ( !in_array( $this->club->memberStatus( $member ), array( \IPS\Member\Club::STATUS_MODERATOR, \IPS\Member\Club::STATUS_EXPIRED_MODERATOR ) ) )
if ( !\in_array( $this->club->memberStatus( $member ), array( \IPS\Member\Club::STATUS_MODERATOR, \IPS\Member\Club::STATUS_EXPIRED_MODERATOR ) ) )
{
\IPS\Output::i()->error( 'node_error', '2C350/N', 403, '' );
}
@@ -761,6 +840,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
/* Promote */
$this->club->addMember( $member, $status, TRUE );
$this->club->recountMembers();
/* Redirect */
\IPS\Output::i()->redirect( $this->club->url()->setQueryString( 'do', 'members' ) );
@@ -787,15 +867,15 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
$status = $this->club->memberStatus( $member );
/* If this was just an invite, then just remove that */
if ( in_array( $status, array( \IPS\Member\Club::STATUS_INVITED, \IPS\Member\Club::STATUS_INVITED_BYPASSING_PAYMENT ) ) )
if ( \in_array( $status, array( \IPS\Member\Club::STATUS_INVITED, \IPS\Member\Club::STATUS_INVITED_BYPASSING_PAYMENT ) ) )
{
$this->club->removeMember( $member );
\IPS\Db::i()->delete( 'core_notifications', array( 'member=? AND notification_app=? AND notification_key=? and item_id=?', $member->member_id, 'core', 'club_invitation', $this->club->id ) );
\IPS\Db::i()->delete( 'core_notifications', array( '`member`=? AND notification_app=? AND notification_key=? and item_id=?', $member->member_id, 'core', 'club_invitation', $this->club->id ) );
$member->recountNotifications();
}
/* If they were previously accepted and waiting for payment, treat it as a decline */
elseif ( in_array( $status, array( \IPS\Member\Club::STATUS_WAITING_PAYMENT ) ) )
elseif ( \in_array( $status, array( \IPS\Member\Club::STATUS_WAITING_PAYMENT ) ) )
{
/* Decline them */
$this->club->addMember( $member, \IPS\Member\Club::STATUS_DECLINED, TRUE, \IPS\Member::loggedIn() );
@@ -809,7 +889,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
/* Otherwise check they are actually a member that can be removed */
else
{
if ( !in_array( $status, array( \IPS\Member\Club::STATUS_MEMBER, \IPS\Member\Club::STATUS_MODERATOR, \IPS\Member\Club::STATUS_LEADER, \IPS\Member\Club::STATUS_EXPIRED, \IPS\Member\Club::STATUS_EXPIRED_MODERATOR ) ) )
if ( !\in_array( $status, array( \IPS\Member\Club::STATUS_MEMBER, \IPS\Member\Club::STATUS_MODERATOR, \IPS\Member\Club::STATUS_LEADER, \IPS\Member\Club::STATUS_EXPIRED, \IPS\Member\Club::STATUS_EXPIRED_MODERATOR ) ) )
{
\IPS\Output::i()->error( 'node_error', '2C350/9', 403, '' );
}
@@ -1003,6 +1083,59 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
\IPS\Output::i()->redirect( $this->club->url()->setQueryString( 'do', 'members' ) );
}
/**
* Rules
*
* @return void
*/
protected function rules()
{
if ( $this->club->rules_required AND !$this->club->rulesAcknowledged() )
{
$form = new \IPS\Helpers\Form( 'form', 'accept' );
$form->hiddenValues['accepted'] = 1;
if ( $referrer = \IPS\Request::i()->referrer() )
{
$form->hiddenValues['ref'] = base64_encode( (string) $referrer );
}
$form->class = 'ipsForm_vertical';
if ( $this->club->memberStatus( \IPS\Member::loggedIn() ) === NULL )
{
$form->addButton( 'cancel', 'link', $this->club->url() );
}
else
{
$form->addButton( 'club_leave', 'link', $this->club->url()->setQueryString( 'do', 'leave' )->csrf() );
}
if ( $values = $form->values() )
{
/* If we're not a member of this club yet, send us back to the join form */
if( $this->club->memberStatus( \IPS\Member::loggedIn() ) === NULL AND $referrer = \IPS\Request::i()->referrer() )
{
\IPS\Output::i()->redirect( $referrer->setQueryString( 'rulesAcknowledged', 1 ), 'accepted' );
}
$this->club->acknowledgeRules( \IPS\Member::loggedIn() );
if ( $referrer = \IPS\Request::i()->referrer() )
{
\IPS\Output::i()->redirect( $referrer, 'accepted' );
}
\IPS\Output::i()->redirect( $this->club->url(), 'accepted' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'club_rules' );
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'clubs', 'core' ), 'rulesForm' ), $this->club );
}
else
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'club_rules' );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'clubs', 'core' )->clubRules( $this->club );
}
}
/**
* Join
*
@@ -1015,48 +1148,29 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
{
\IPS\Output::i()->error( 'no_module_permission', '2C350/I', 403, '' );
}
/* Are there rules that need to be acknowledged which we haven't acknowledged yet? */
if( $this->club->rules_required AND !\IPS\Request::i()->rulesAcknowledged )
{
$ref = \IPS\Request::i()->url()->addRef( \IPS\Request::i()->referrer() );
\IPS\Output::i()->redirect( $this->club->url()->setQueryString( 'do', 'rules' )->addRef( $ref ) );
}
/* CSRF Check */
\IPS\Session::i()->csrfCheck();
/* If this is an open club, or the member was invited, or they have mod access anyway go ahead and add them */
if ( in_array( $this->memberStatus, array( \IPS\Member\Club::STATUS_INVITED, \IPS\Member\Club::STATUS_INVITED_BYPASSING_PAYMENT, \IPS\Member\Club::STATUS_WAITING_PAYMENT ) ) or $this->club->type === \IPS\Member\Club::TYPE_OPEN or \IPS\Member::loggedIn()->modPermission('can_access_all_clubs') )
if ( \in_array( $this->memberStatus, array( \IPS\Member\Club::STATUS_INVITED, \IPS\Member\Club::STATUS_INVITED_BYPASSING_PAYMENT, \IPS\Member\Club::STATUS_WAITING_PAYMENT ) ) or $this->club->type === \IPS\Member\Club::TYPE_OPEN or \IPS\Member::loggedIn()->modPermission('can_access_all_clubs') )
{
/* Unless they have to pay */
if ( $this->club->isPaid() and $this->memberStatus !== \IPS\Member\Club::STATUS_INVITED_BYPASSING_PAYMENT )
{
if ( $fee = $this->club->joiningFee() )
if ( $this->club->joiningFee() )
{
/* Create the item */
$item = new \IPS\core\extensions\nexus\Item\ClubMembership( $this->club->name, $fee );
$item->id = $this->club->id;
try
{
$item->tax = \IPS\Settings::i()->clubs_paid_tax ? \IPS\nexus\Tax::load( \IPS\Settings::i()->clubs_paid_tax ) : NULL;
}
catch ( \OutOfRangeException $e ) { }
if ( \IPS\Settings::i()->clubs_paid_gateways )
{
$item->paymentMethodIds = explode( ',', \IPS\Settings::i()->clubs_paid_gateways );
}
$item->renewalTerm = $this->club->renewalTerm( $fee->currency );
$item->payTo = $this->club->owner;
$item->commission = \IPS\Settings::i()->clubs_paid_commission;
if ( $fees = \IPS\Settings::i()->clubs_paid_transfee and isset( $fees[ $fee->currency ] ) )
{
$item->fee = new \IPS\nexus\Money( $fees[ $fee->currency ]['amount'], $fee->currency );
}
/* Generate the invoice */
$invoice = new \IPS\nexus\Invoice;
$invoice->currency = $fee->currency;
$invoice->member = \IPS\nexus\Customer::loggedIn();
$invoice->addItem( $item );
$invoice->return_uri = "app=core&module=clubs&controller=view&id={$this->club->id}";
$invoice->save();
$invoiceUrl = $this->club->generateInvoice();
/* Take them to it */
\IPS\Output::i()->redirect( $invoice->checkoutUrl() );
\IPS\Output::i()->redirect( $invoiceUrl );
}
else
{
@@ -1078,15 +1192,35 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
}
/* Send a notification to any leaders */
$notification = new \IPS\Notification( \IPS\Application::load('core'), $notificationKey, $this->club, array( $this->club, \IPS\Member::loggedIn() ) );
$notification = new \IPS\Notification( \IPS\Application::load('core'), $notificationKey, $this->club, array( $this->club, \IPS\Member::loggedIn() ), array( \IPS\Member::loggedIn()->member_id ) );
foreach ( $this->club->members( array( \IPS\Member\Club::STATUS_LEADER ), NULL, NULL, 2 ) as $member )
{
$notification->recipients->attach( \IPS\Member::constructFromData( $member ) );
}
$notification->send();
/* If we just accepted the rules, set the flag */
if( \IPS\Request::i()->rulesAcknowledged )
{
$this->club->acknowledgeRules( \IPS\Member::loggedIn() );
}
/* Redirect */
\IPS\Output::i()->redirect( $this->club->url() );
if ( ! $this->club->rulesAcknowledged() )
{
\IPS\Output::i()->redirect( $this->club->url()->setQueryString( 'do', 'rules' ) );
}
else
{
if ( $url = \IPS\Request::i()->referrer() )
{
\IPS\Output::i()->redirect( $url );
}
else
{
\IPS\Output::i()->redirect( $this->club->url() );
}
}
}
/**
@@ -1097,7 +1231,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
protected function leave()
{
/* Can we leave? */
if ( !in_array( $this->club->memberStatus( \IPS\Member::loggedIn() ), array( \IPS\Member\Club::STATUS_MEMBER, \IPS\Member\Club::STATUS_MODERATOR, \IPS\Member\Club::STATUS_LEADER, \IPS\Member\Club::STATUS_EXPIRED, \IPS\Member\Club::STATUS_EXPIRED_MODERATOR, \IPS\Member\Club::STATUS_WAITING_PAYMENT, \IPS\Member\Club::STATUS_INVITED ) ) or ( $this->club->owner and $this->club->owner->member_id == \IPS\Member::loggedIn()->member_id ) )
if ( !\in_array( $this->club->memberStatus( \IPS\Member::loggedIn() ), array( \IPS\Member\Club::STATUS_MEMBER, \IPS\Member\Club::STATUS_MODERATOR, \IPS\Member\Club::STATUS_LEADER, \IPS\Member\Club::STATUS_EXPIRED, \IPS\Member\Club::STATUS_EXPIRED_MODERATOR, \IPS\Member\Club::STATUS_WAITING_PAYMENT, \IPS\Member\Club::STATUS_INVITED, \IPS\Member\Club::STATUS_REQUESTED ) ) or ( $this->club->owner and $this->club->owner->member_id == \IPS\Member::loggedIn()->member_id ) )
{
\IPS\Output::i()->error( 'no_module_permission', '2C350/S', 403, '' );
}
@@ -1123,13 +1257,40 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
$this->club->save();
/* Delete the invitation */
\IPS\Db::i()->delete( 'core_notifications', array( 'member=? AND notification_app=? AND notification_key=? and item_id=?', \IPS\Member::loggedIn()->member_id, 'core', 'club_invitation', $this->club->id ) );
\IPS\Db::i()->delete( 'core_notifications', array( '`member`=? AND notification_app=? AND notification_key=? and item_id=?', \IPS\Member::loggedIn()->member_id, 'core', 'club_invitation', $this->club->id ) );
\IPS\Member::loggedIn()->recountNotifications();
/* Redirect */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=clubs&controller=directory', 'front', 'clubs_list' ) );
}
/**
* Cancel Join Request
*
* @return void
*/
protected function cancelJoin()
{
/* CSRF Check */
\IPS\Session::i()->csrfCheck();
/* Leave */
$this->club->removeMember( \IPS\Member::loggedIn() );
$this->club->recountMembers();
$this->club->save();
/* Update notification counts */
\IPS\Db::i()->delete( 'core_notifications', array( 'notification_key=? and item_id=? and extra=?', 'club_request', $this->club->id, json_encode( array( \IPS\Member::loggedIn()->member_id ) ) ) );
foreach( $this->club->members( array( 'moderator', 'leader' ), 250, NULL, 2 ) as $member )
{
$member = \IPS\Member::constructFromData( $member );
$member->recountNotifications();
}
/* Redirect */
\IPS\Output::i()->redirect( $this->club->url(), 'clubs_request_cancelled' );
}
/**
* Renew
*
@@ -1138,7 +1299,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
protected function renew()
{
/* Can we renew? */
if ( !in_array( $this->club->memberStatus( \IPS\Member::loggedIn() ), array( \IPS\Member\Club::STATUS_EXPIRED, \IPS\Member\Club::STATUS_EXPIRED_MODERATOR ) ) )
if ( !\in_array( $this->club->memberStatus( \IPS\Member::loggedIn() ), array( \IPS\Member\Club::STATUS_EXPIRED, \IPS\Member\Club::STATUS_EXPIRED_MODERATOR ) ) )
{
\IPS\Output::i()->error( 'no_module_permission', '2C350/Y', 403, '' );
}
@@ -1187,27 +1348,25 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
{
$status = \IPS\Member\Club::STATUS_INVITED_BYPASSING_PAYMENT;
}
$notification = new \IPS\Notification( \IPS\Application::load('core'), 'club_invitation', $this->club, array( $this->club, \IPS\Member::loggedIn() ), array( 'invitedBy' => \IPS\Member::loggedIn()->member_id ) );
foreach ( $values['members'] as $member )
{
if ( $member instanceof \IPS\Member )
{
$memberStatus = $this->club->memberStatus( $member );
if ( !$memberStatus or in_array( $memberStatus, array( \IPS\Member\Club::STATUS_INVITED, \IPS\Member\Club::STATUS_REQUESTED, \IPS\Member\Club::STATUS_DECLINED, \IPS\Member\Club::STATUS_BANNED ) ) )
if ( !$memberStatus or \in_array( $memberStatus, array( \IPS\Member\Club::STATUS_INVITED, \IPS\Member\Club::STATUS_REQUESTED, \IPS\Member\Club::STATUS_DECLINED, \IPS\Member\Club::STATUS_BANNED ) ) )
{
$this->club->addMember( $member, $status, TRUE, NULL, \IPS\Member::loggedIn(), TRUE );
$notification->recipients->attach( $member );
}
}
}
$notification->send();
$this->club->sendInvitation( \IPS\Member::loggedIn(), $values['members'] );
\IPS\Output::i()->redirect( $this->club->url(), 'club_notifications_sent' );
}
\IPS\Output::i()->title = $this->club->name;
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
}
/**
@@ -1228,7 +1387,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
/* Check the member needs to be reinvited */
$member = \IPS\Member::load( \IPS\Request::i()->member );
if ( !in_array( $this->club->memberStatus( $member ), array( \IPS\Member\Club::STATUS_DECLINED, \IPS\Member\Club::STATUS_BANNED ) ) )
if ( !\in_array( $this->club->memberStatus( $member ), array( \IPS\Member\Club::STATUS_DECLINED, \IPS\Member\Club::STATUS_BANNED ) ) )
{
\IPS\Output::i()->error( 'node_error', '2C350/K', 403, '' );
}
@@ -1245,7 +1404,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
/* If other requests are banned, send us back, otherwise take us to the main member list */
$url = $this->club->url()->setQueryString( 'do', 'members' );
if ( count( $this->club->members( array( \IPS\Member\Club::STATUS_DECLINED, \IPS\Member\Club::STATUS_BANNED ) ) ) )
if ( \count( $this->club->members( array( \IPS\Member\Club::STATUS_DECLINED, \IPS\Member\Club::STATUS_BANNED ) ) ) )
{
\IPS\Output::i()->redirect( $url->SetQueryString( 'filter', \IPS\Member\Club::STATUS_BANNED ) );
}
@@ -1346,7 +1505,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
{
/* Permission check */
$class = \IPS\Request::i()->type;
if ( !$this->club->isLeader() or !in_array( $class, \IPS\Member\Club::availableNodeTypes( \IPS\Member::loggedIn() ) ) or ( \IPS\Settings::i()->clubs_require_approval and !$this->club->approved ) )
if ( !$this->club->isLeader() or !\in_array( $class, \IPS\Member\Club::availableNodeTypes( \IPS\Member::loggedIn() ) ) or ( \IPS\Settings::i()->clubs_require_approval and !$this->club->approved ) )
{
\IPS\Output::i()->error( 'no_module_permission', '2C350/T', 403, '' );
}
@@ -1382,12 +1541,12 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
if ( $values = $form->values() )
{
$node->saveClubForm( $this->club, $values );
\IPS\Output::i()->redirect( $this->club->url() );
\IPS\Output::i()->redirect( $node->url() );
}
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('club_create_node');
\IPS\Output::i()->output = \IPS\Request::i()->isAjax() ? $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) ) : $form;
\IPS\Output::i()->output = \IPS\Request::i()->isAjax() ? $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) ) : $form;
}
/**
@@ -1423,7 +1582,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
/* Permission check */
$itemClass = $node::$contentItemClass;
if ( !$node->modPermission( 'delete', \IPS\Member::loggedIn() ) and $itemClass::contentCount( $node, TRUE, TRUE, TRUE, 1 ) )
if ( !$node->modPermission( 'delete', \IPS\Member::loggedIn(), $itemClass ) and $itemClass::contentCount( $node, TRUE, TRUE, TRUE, 1 ) )
{
\IPS\Output::i()->error( 'no_module_permission', '2C350/AC', 403, '' );
}
@@ -1436,6 +1595,34 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
\IPS\Output::i()->redirect( $club->url() );
}
/**
* Add a page
*
* @return void
*/
public function addPage()
{
/* Init form */
$form = new \IPS\Helpers\Form;
$form->class = 'ipsForm_vertical';
\IPS\Member\Club\Page::form( $form, $this->club );
/* Form Submission */
if ( $values = $form->values() )
{
$page = new \IPS\Member\Club\Page;
$page->formatFormValues( $values );
$page->save();
\IPS\File::claimAttachments( 'club-page-new', $page->id );
\IPS\Output::i()->redirect( $page->url() );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( "add_page_to_club", NULL, array( "sprintf" => array( $this->club->name ) ) );
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
}
/* !Cover Photo */
/**
@@ -1521,6 +1708,52 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, $embedCss );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'styles/embeds.css', 'core', 'front' ) );
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core', 'front' )->embedInternal( $output, $js ), 200, 'text/html', \IPS\Output::i()->httpHeaders );
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core', 'front' )->embedInternal( $output, $js ), 200, 'text/html' );
}
/**
* Save the club menu order
*
* @return void
*/
protected function saveMenu()
{
\IPS\Session::i()->csrfCheck();
/* Permission check */
if ( !$this->club->canManageNavigation() )
{
\IPS\Output::i()->error( 'no_module_permission', '1C350/O', 403, '' );
}
if ( \is_array( \IPS\Request::i()->tabOrder ) )
{
$tabs = \IPS\Request::i()->tabOrder;
$this->club->menu_tabs = json_encode( $tabs );
$this->club->save();
}
\IPS\Output::i()->json( 'ok' );
}
/**
* Set some default meta tags for the club
*
* @return void
*/
protected function _setDefaultMetaTags()
{
if( $this->club->cover_photo )
{
\IPS\Output::i()->metaTags['og:image'] = \IPS\File::get( 'core_Clubs', $this->club->cover_photo )->url;
}
\IPS\Output::i()->metaTags['og:title'] = $this->club->name;
if( $this->club->about )
{
\IPS\Output::i()->metaTags['description'] = $this->club->about;
\IPS\Output::i()->metaTags['og:description'] = $this->club->about;
}
}
}