Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

@@ -60,6 +60,10 @@ class _directory extends \IPS\Dispatcher\Controller
protected function manage()
{
$baseUrl = \IPS\Http\Url::internal( 'app=core&module=clubs&controller=directory', 'front', 'clubs_list' );
if ( isset( \IPS\Request::i()->view ) and in_array( \IPS\Request::i()->view, array( 'grid', 'list' ) ) )
{
$baseUrl = $baseUrl->setQueryString( 'view', \IPS\Request::i()->view );
}
/* All Clubs: Sort */
$sortOption = \IPS\Settings::i()->clubs_default_sort;
@@ -71,11 +75,25 @@ class _directory extends \IPS\Dispatcher\Controller
/* All Clubs: Filters */
$filters = array();
$mineOnly = FALSE;
$extraWhere = NULL;
if ( isset( \IPS\Request::i()->filter ) and \IPS\Request::i()->filter === 'mine' )
{
$mineOnly = TRUE;
$baseUrl = $baseUrl->setQueryString( 'filter', 'mine' );
}
if ( isset( \IPS\Request::i()->type ) and in_array( \IPS\Request::i()->type, array( 'free', 'paid' ) ) )
{
$baseUrl = $baseUrl->setQueryString( 'type', \IPS\Request::i()->type );
if ( \IPS\Request::i()->type === 'free' )
{
$extraWhere[] = array( 'fee IS NULL' );
}
else
{
$extraWhere[] = array( 'fee IS NOT NULL' );
}
}
foreach ( \IPS\Member\Club\CustomField::fields() as $field )
{
$k = "f{$field->id}";
@@ -100,7 +118,14 @@ class _directory extends \IPS\Dispatcher\Controller
{
if ( isset( $options[ $id ] ) )
{
$filters[ $field->id ][ $id ] = $options[ $id ];
if( $field->type == 'CheckboxSet' )
{
$filters[ $field->id ][ $id ] = $id;
}
else
{
$filters[ $field->id ][ $id ] = $options[ $id ];
}
}
}
$baseUrl = $baseUrl->setQueryString( 'f' . $field->id, array_keys( $filters[ $field->id ] ) );
@@ -116,8 +141,8 @@ class _directory extends \IPS\Dispatcher\Controller
/* Get All Clubs */
$perPage = 24;
$page = isset( \IPS\Request::i()->page ) ? intval( \IPS\Request::i()->page ) : 1;
$allClubs = \IPS\Member\Club::clubs( \IPS\Member::loggedIn(), array( ( $page - 1 ) * $perPage, $perPage ), $sortOption, $mineOnly, $filters );
$pagination = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination( $baseUrl, ceil( $allClubs->count( TRUE ) / $perPage ), $page, $perPage );
$allClubs = \IPS\Member\Club::clubs( \IPS\Member::loggedIn(), array( ( $page - 1 ) * $perPage, $perPage ), $sortOption, $mineOnly, $filters, $extraWhere );
$pagination = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination( $baseUrl, ceil( ( is_object( $allClubs ) ? $allClubs->count( TRUE ) : 0 ) / $perPage ), $page, $perPage );
/* Get my clubs */
$myClubsActivity = NULL;
@@ -128,7 +153,7 @@ class _directory extends \IPS\Dispatcher\Controller
/* Build Map */
$mapMarkers = NULL;
if ( \IPS\Settings::i()->googlemaps and \IPS\Settings::i()->google_maps_api_key )
if ( \IPS\GeoLocation::enabled() )
{
$mapMarkers = array();
@@ -139,7 +164,7 @@ class _directory extends \IPS\Dispatcher\Controller
}
elseif ( !\IPS\Member::loggedIn()->modPermission('can_access_all_clubs') )
{
$where[] = array( "( type<>? OR status IN('" . \IPS\Member\Club::STATUS_MEMBER . "','" . \IPS\Member\Club::STATUS_MODERATOR . "','" . \IPS\Member\Club::STATUS_LEADER . "') )", \IPS\Member\Club::TYPE_PRIVATE );
$where[] = array( "( type<>? OR status IN('" . \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::TYPE_PRIVATE );
}
$select = \IPS\Db::i()->select( array( 'id', 'name', 'location_lat', 'location_long' ), 'core_clubs', $where );
@@ -164,8 +189,21 @@ class _directory extends \IPS\Dispatcher\Controller
}
/* Display */
$view = \IPS\Settings::i()->clubs_default_view;
if ( \IPS\Settings::i()->clubs_allow_view_change )
{
if ( isset( \IPS\Request::i()->view ) and in_array( \IPS\Request::i()->view, array( 'grid', 'list' ) ) )
{
\IPS\Request::i()->setCookie( 'clubs_view', \IPS\Request::i()->view, \IPS\DateTime::create()->add( new \DateInterval('P1Y' ) ) );
$view = \IPS\Request::i()->view;
}
elseif ( isset( \IPS\Request::i()->cookie['clubs_view'] ) and in_array( \IPS\Request::i()->cookie['clubs_view'], array( 'grid', 'list' ) ) )
{
$view = \IPS\Request::i()->cookie['clubs_view'];
}
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('module__core_clubs');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clubs')->directory( $featuredClubs, $allClubs, $pagination, $baseUrl, $sortOption, $myClubsActivity, $mapMarkers );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clubs')->directory( $featuredClubs, $allClubs, $pagination, $baseUrl, $sortOption, $myClubsActivity, $mapMarkers, $view );
}
/**
@@ -187,6 +225,15 @@ class _directory extends \IPS\Dispatcher\Controller
) ) ) );
}
if ( \IPS\Application::appIsEnabled( 'nexus' ) and \IPS\Settings::i()->clubs_paid_on )
{
$form->add( new \IPS\Helpers\Form\Radio( 'club_membership_fee', isset( \IPS\Request::i()->type ) ? \IPS\Request::i()->type : 'all', TRUE, array( 'options' => array(
'all' => 'all_clubs',
'free' => 'club_membership_free',
'paid' => 'club_membership_paid'
) ) ) );
}
foreach ( $fields as $field )
{
if ( $field->filterable )
@@ -225,6 +272,11 @@ class _directory extends \IPS\Dispatcher\Controller
$url = $url->setQueryString( 'filter', 'mine' );
}
if ( \IPS\Application::appIsEnabled( 'nexus' ) and \IPS\Settings::i()->clubs_paid_on and $values['club_membership_fee'] !== 'all' )
{
$url = $url->setQueryString( 'type', $values['club_membership_fee'] );
}
foreach ( $fields as $field )
{
if ( $field->filterable )
@@ -273,11 +325,14 @@ class _directory extends \IPS\Dispatcher\Controller
protected function create()
{
$availableTypes = array();
foreach ( explode( ',', \IPS\Member::loggedIn()->group['g_create_clubs'] ) as $type )
if ( \IPS\Member::loggedIn()->member_id ) // Guests can't create any type of clubs
{
if ( $type !== '' )
foreach ( explode( ',', \IPS\Member::loggedIn()->group['g_create_clubs'] ) as $type )
{
$availableTypes[ $type ] = 'club_type_' . $type;
if ( $type !== '' )
{
$availableTypes[ $type ] = 'club_type_' . $type;
}
}
}
if ( !$availableTypes )
@@ -285,6 +340,14 @@ class _directory extends \IPS\Dispatcher\Controller
\IPS\Output::i()->error( \IPS\Member::loggedIn()->member_id ? 'no_module_permission' : 'no_module_permission_guest', '2C349/1', 403, '' );
}
if ( \IPS\Member::loggedIn()->group['g_club_limit'] )
{
if ( \IPS\Db::i()->select( 'COUNT(*)', 'core_clubs', array( 'owner=?', \IPS\Member::loggedIn()->member_id ) )->first() >= \IPS\Member::loggedIn()->group['g_club_limit'] )
{
\IPS\Output::i()->error( \IPS\Member::loggedIn()->language()->addToStack( 'too_many_clubs', FALSE, array( 'pluralize' => array( \IPS\Member::loggedIn()->group['g_club_limit'] ) ) ), '2C349/3', 403, '' );
}
}
$club = new \IPS\Member\Club;
if ( $form = $club->form( FALSE, TRUE, $availableTypes ) )
{
+473 -36
View File
@@ -105,6 +105,12 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
*/
protected function manage()
{
/* 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' );
}
/* If this is a closed club, and we don't have permission to read it, show the member page instead */
if ( $this->club->type == \IPS\Member\Club::TYPE_CLOSED && !$this->club->canRead() )
{
@@ -113,7 +119,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
}
/* Get the activity stream */
$activity = \IPS\Content\Search\Query::init()->filterByClub( $this->club )->setOrder( \IPS\Content\Search\Query::ORDER_NEWEST_UPDATED )->search();
$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 )
@@ -121,7 +127,14 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
$lastTime = NULL;
foreach ( $activity as $key => $result )
{
$lastTime = $result->createdDate->getTimestamp();
if ( $result !== NULL )
{
$lastTime = $result->createdDate->getTimestamp();
}
else
{
unset( $activity[ $key ] );
}
}
$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 ) ) ) );
@@ -132,7 +145,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
$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', NULL, NULL, NULL, \IPS\Db::SELECT_MULTIDIMENSIONAL_JOINS )->join( 'core_members', 'core_members.member_id=core_clubs_memberships.member_id' ) as $join )
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'] ),
@@ -144,7 +157,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
/* Merge them in */
if ( !empty( $joins ) )
{
$activity = array_merge( iterator_to_array( $activity ), $joins );
$activity = array_filter( array_merge( iterator_to_array( $activity ), $joins ) );
uasort( $activity, function( $a, $b )
{
if ( $a->createdDate->getTimestamp() == $b->createdDate->getTimestamp() )
@@ -163,7 +176,8 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
}
}
/* Display */
/* 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() );
}
@@ -215,7 +229,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
*/
protected function editPhoto()
{
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/R', 403, '' );
}
@@ -301,7 +315,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
$form->add( new \IPS\Helpers\Form\Custom('photo_crop', array( 0, 0, $suggestedWidth, $suggestedHeight ), FALSE, array(
'getHtml' => function( $field ) use ( $original )
{
return \IPS\Theme::i()->getTemplate('profile')->photoCrop( $field->name, $field->value, $this->club->url()->setQueryString( 'do', 'cropPhotoGetPhoto' )->csrf() );
return \IPS\Theme::i()->getTemplate('members', 'core', 'global')->photoCrop( $field->name, $field->value, $this->club->url()->setQueryString( 'do', 'cropPhotoGetPhoto' )->csrf() );
}
) ) );
@@ -323,7 +337,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
/* Save it */
$croppedFilename = mb_substr( $original->originalFilename, 0, mb_strrpos( $original->originalFilename, '.' ) ) . '.cropped' . mb_substr( $original->originalFilename, mb_strrpos( $original->originalFilename, '.' ) );
$cropped = \IPS\File::create( 'core_Profile', $original->originalFilename, (string) $image );
$cropped = \IPS\File::create( 'core_Clubs', $croppedFilename, (string) $image );
$this->club->profile_photo = (string) $cropped;
$this->club->save();
@@ -389,12 +403,21 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
}
break;
case \IPS\Member\Club::STATUS_WAITING_PAYMENT:
if ( $this->club->isLeader() )
{
$filter = \IPS\Member\Club::STATUS_WAITING_PAYMENT;
$statuses = array( \IPS\Member\Club::STATUS_WAITING_PAYMENT );
$baseUrl = $baseUrl->setQueryString( 'filter', \IPS\Member\Club::STATUS_WAITING_PAYMENT );
}
break;
case \IPS\Member\Club::STATUS_BANNED:
if ( $this->club->isLeader() )
{
$filter = \IPS\Member\Club::STATUS_BANNED;
$statuses = array( \IPS\Member\Club::STATUS_DECLINED, \IPS\Member\Club::STATUS_BANNED );
$baseUrl = $baseUrl->setQueryString( 'filter', \IPS\Member\Club::STATUS_REQUESTED );
$baseUrl = $baseUrl->setQueryString( 'filter', \IPS\Member\Club::STATUS_BANNED );
}
break;
@@ -402,10 +425,19 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
if ( $this->club->isLeader() )
{
$filter = \IPS\Member\Club::STATUS_INVITED;
$statuses = array( \IPS\Member\Club::STATUS_INVITED );
$statuses = array( \IPS\Member\Club::STATUS_INVITED, \IPS\Member\Club::STATUS_INVITED_BYPASSING_PAYMENT );
$baseUrl = $baseUrl->setQueryString( 'filter', \IPS\Member\Club::STATUS_INVITED );
}
break;
case \IPS\Member\Club::STATUS_EXPIRED:
if ( $this->club->isLeader() )
{
$filter = \IPS\Member\Club::STATUS_EXPIRED;
$statuses = array( \IPS\Member\Club::STATUS_EXPIRED, \IPS\Member\Club::STATUS_EXPIRED_MODERATOR );
$baseUrl = $baseUrl->setQueryString( 'filter', \IPS\Member\Club::STATUS_EXPIRED );
}
break;
}
}
@@ -420,11 +452,18 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
/* Sort out the offset */
$perPage = 28;
$activePage = isset( \IPS\Request::i()->page ) ? intval( \IPS\Request::i()->page ) : 1;
if( $activePage < 1 )
{
$activePage = 1;
}
$offset = ( $activePage - 1 ) * $perPage;
/* Fetch them */
$members = $this->club->members( $statuses, array( $offset, $perPage ), $orderByClause, $this->club->isLeader() ? 3 : 1 );
$members = $this->club->members( $statuses, array( $offset, $perPage ), $orderByClause, $this->club->isLeader() ? 5 : 1 );
$pagination = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination( $baseUrl, ceil( $members->count(TRUE) / $perPage ), $activePage, $perPage );
/* Display */
@@ -434,9 +473,16 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
}
else
{
$staffStatuses = array( \IPS\Member\Club::STATUS_LEADER, \IPS\Member\Club::STATUS_MODERATOR );
if ( $this->club->isLeader( \IPS\Member::loggedIn() ) )
{
$staffStatuses[] = \IPS\Member\Club::STATUS_EXPIRED_MODERATOR;
}
$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') );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'clubs' )->members( $this->club, $members, $pagination, $sortBy, $filter );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'clubs' )->members( $this->club, $members, $pagination, $sortBy, $filter, $clubStaff );
}
}
@@ -464,7 +510,12 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
}
/* Add them */
$this->club->addMember( $member, \IPS\Member\Club::STATUS_MEMBER, TRUE, \IPS\Member::loggedIn(), NULL, TRUE );
$status = \IPS\Member\Club::STATUS_MEMBER;
if ( $this->club->isPaid() and !isset( \IPS\Request::i()->waiveFee ) )
{
$status = \IPS\Member\Club::STATUS_WAITING_PAYMENT;
}
$this->club->addMember( $member, $status, TRUE, \IPS\Member::loggedIn(), NULL, TRUE );
$this->club->recountMembers();
/* Notify the member */
@@ -574,7 +625,7 @@ 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_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, '' );
}
@@ -603,14 +654,27 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
}
/* Get member */
$member = \IPS\Member::load( \IPS\Request::i()->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 ( $this->club->memberStatus( $member ) != \IPS\Member\Club::STATUS_LEADER )
{
\IPS\Output::i()->error( 'node_error', '2C350/9', 403, '' );
}
/* Are they expired? */
$status = \IPS\Member\Club::STATUS_MEMBER;
if ( \IPS\Application::appIsEnabled('nexus') and \IPS\Settings::i()->clubs_paid_on and $this->club->renewal_price )
{
foreach ( \IPS\core\extensions\nexus\Item\ClubMembership::getPurchases( $member, $this->club->id ) as $purchase )
{
if ( $purchase->expire and $purchase->expire->getTimestamp() < time() )
{
$status = \IPS\Member\Club::STATUS_EXPIRED;
}
}
}
/* Promote */
$this->club->addMember( $member, \IPS\Member\Club::STATUS_MEMBER, TRUE );
$this->club->addMember( $member, $status, TRUE );
/* Redirect */
\IPS\Output::i()->redirect( $this->club->url()->setQueryString( 'do', 'members' ) );
@@ -633,14 +697,27 @@ 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_LEADER ) ) )
$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 ) ) )
{
\IPS\Output::i()->error( 'node_error', '2C350/L', 403, '' );
}
/* Are they expired? */
$status = \IPS\Member\Club::STATUS_MODERATOR;
if ( \IPS\Application::appIsEnabled('nexus') and \IPS\Settings::i()->clubs_paid_on and $this->club->renewal_price )
{
foreach ( \IPS\core\extensions\nexus\Item\ClubMembership::getPurchases( $member, $this->club->id ) as $purchase )
{
if ( $purchase->expire and $purchase->expire->getTimestamp() < time() )
{
$status = \IPS\Member\Club::STATUS_EXPIRED_MODERATOR;
}
}
}
/* Promote */
$this->club->addMember( $member, \IPS\Member\Club::STATUS_MODERATOR, TRUE );
$this->club->addMember( $member, $status, TRUE );
/* Redirect */
\IPS\Output::i()->redirect( $this->club->url()->setQueryString( 'do', 'members' ) );
@@ -663,14 +740,27 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
}
/* Get member */
$member = \IPS\Member::load( \IPS\Request::i()->member );
if ( $this->club->memberStatus( $member ) != \IPS\Member\Club::STATUS_MODERATOR )
$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 ) ) )
{
\IPS\Output::i()->error( 'node_error', '2C350/N', 403, '' );
}
/* Are they expired? */
$status = \IPS\Member\Club::STATUS_MEMBER;
if ( \IPS\Application::appIsEnabled('nexus') and \IPS\Settings::i()->clubs_paid_on and $this->club->renewal_price )
{
foreach ( \IPS\core\extensions\nexus\Item\ClubMembership::getPurchases( $member, $this->club->id ) as $purchase )
{
if ( $purchase->expire and $purchase->expire->getTimestamp() < time() )
{
$status = \IPS\Member\Club::STATUS_EXPIRED;
}
}
}
/* Promote */
$this->club->addMember( $member, \IPS\Member\Club::STATUS_MEMBER, TRUE );
$this->club->addMember( $member, $status, TRUE );
/* Redirect */
\IPS\Output::i()->redirect( $this->club->url()->setQueryString( 'do', 'members' ) );
@@ -695,17 +785,218 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
/* Get member */
$member = \IPS\Member::load( \IPS\Request::i()->member );
$status = $this->club->memberStatus( $member );
if ( !in_array( $status, array( \IPS\Member\Club::STATUS_MEMBER, \IPS\Member\Club::STATUS_MODERATOR, \IPS\Member\Club::STATUS_LEADER ) ) )
/* 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 ) ) )
{
\IPS\Output::i()->error( 'node_error', '2C350/9', 403, '' );
}
if ( $this->club->owner and $this->club->owner->member_id === $member->member_id )
{
\IPS\Output::i()->error( 'club_cannot_remove_owner', '2C350/E', 403, '' );
$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 ) );
$member->recountNotifications();
}
/* Remove */
$this->club->addMember( $member, \IPS\Member\Club::STATUS_BANNED, TRUE, \IPS\Member::loggedIn() );
/* 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 ) ) )
{
/* Decline them */
$this->club->addMember( $member, \IPS\Member\Club::STATUS_DECLINED, TRUE, \IPS\Member::loggedIn() );
/* Notify the member */
$notification = new \IPS\Notification( \IPS\Application::load('core'), 'club_response', $this->club, array( $this->club, FALSE ) );
$notification->recipients->attach( $member );
$notification->send();
}
/* 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 ) ) )
{
\IPS\Output::i()->error( 'node_error', '2C350/9', 403, '' );
}
if ( $this->club->owner and $this->club->owner->member_id === $member->member_id )
{
\IPS\Output::i()->error( 'club_cannot_remove_owner', '2C350/E', 403, '' );
}
/* Cancel purchase */
if ( \IPS\Application::appIsEnabled('nexus') and \IPS\Settings::i()->clubs_paid_on )
{
foreach ( \IPS\core\extensions\nexus\Item\ClubMembership::getPurchases( \IPS\nexus\Customer::load( \IPS\Request::i()->member ), $this->club->id ) as $purchase )
{
$purchase->cancelled = TRUE;
$purchase->member->log( 'purchase', array( 'type' => 'cancel', 'id' => $purchase->id, 'name' => $purchase->name ) );
$purchase->can_reactivate = FALSE;
$purchase->save();
}
}
/* Remove */
$this->club->addMember( $member, \IPS\Member\Club::STATUS_BANNED, TRUE, \IPS\Member::loggedIn() );
}
/* Recount */
$this->club->recountMembers();
/* Redirect */
\IPS\Output::i()->redirect( $this->club->url()->setQueryString( 'do', 'members' ) );
}
/**
* Waive membership fee
*
* @return void
*/
protected function bypassPayment()
{
/* CSRF Check */
\IPS\Session::i()->csrfCheck();
/* Permission check */
if ( !$this->club->isLeader() or !\IPS\Application::appIsEnabled('nexus') or !\IPS\Settings::i()->clubs_paid_on )
{
\IPS\Output::i()->error( 'no_module_permission', '2C350/W', 403, '' );
}
/* Get member */
$member = \IPS\nexus\Customer::load( \IPS\Request::i()->member );
/* Do it */
switch ( $this->club->memberStatus( $member ) )
{
/* If they were waiting for payment, just go ahead and promote them to a member */
case \IPS\Member\Club::STATUS_WAITING_PAYMENT:
$this->club->addMember( $member, \IPS\Member\Club::STATUS_MEMBER, TRUE );
break;
/* If they were already in the club, find their purchase and remove the expiry date */
case \IPS\Member\Club::STATUS_MEMBER:
case \IPS\Member\Club::STATUS_EXPIRED:
case \IPS\Member\Club::STATUS_MODERATOR:
case \IPS\Member\Club::STATUS_EXPIRED_MODERATOR:
case \IPS\Member\Club::STATUS_LEADER:
foreach ( \IPS\core\extensions\nexus\Item\ClubMembership::getPurchases( $member, $this->club->id ) as $purchase )
{
$extra = $purchase->extra;
$extra['originalExpire'] = $purchase->expire ? $purchase->expire->getTimestamp() : NULL;
$purchase->extra = $extra;
$purchase->expire = NULL;
$purchase->save();
$member->log( 'purchase', array( 'type' => 'info', 'info' => 'never_expire', 'id' => $purchase->id, 'name' => $purchase->name ) );
}
break;
/* If they have been invited, just change their status to invited bypassing payment */
case \IPS\Member\Club::STATUS_INVITED:
$this->club->addMember( $member, \IPS\Member\Club::STATUS_INVITED_BYPASSING_PAYMENT, TRUE );
break;
/* For anything else, we can't do this... */
default:
\IPS\Output::i()->error( 'node_error', '2C350/X', 403, '' );
}
$this->club->recountMembers();
/* Redirect */
\IPS\Output::i()->redirect( $this->club->url()->setQueryString( 'do', 'members' ) );
}
/**
* Restore Payment
*
* @return void
*/
protected function restorePayment()
{
/* CSRF Check */
\IPS\Session::i()->csrfCheck();
/* Permission check */
if ( !$this->club->isLeader() or !\IPS\Application::appIsEnabled('nexus') or !\IPS\Settings::i()->clubs_paid_on )
{
\IPS\Output::i()->error( 'no_module_permission', '2C350/W', 403, '' );
}
/* Get member */
$member = \IPS\nexus\Customer::load( \IPS\Request::i()->member );
/* Do it */
$status = $this->club->memberStatus( $member );
switch ( $status )
{
/* If they were already in the club, find their purchase and restore the expiry date */
case \IPS\Member\Club::STATUS_MEMBER:
case \IPS\Member\Club::STATUS_EXPIRED:
case \IPS\Member\Club::STATUS_MODERATOR:
case \IPS\Member\Club::STATUS_EXPIRED_MODERATOR:
case \IPS\Member\Club::STATUS_LEADER:
$foundPurchase = FALSE;
foreach ( \IPS\core\extensions\nexus\Item\ClubMembership::getPurchases( $member, $this->club->id ) as $purchase )
{
$foundPurchase = TRUE;
if ( !$purchase->renewals or !$purchase->renewals->cost->amount->isZero() )
{
$purchase->renewals = $this->club->renewalTerm( $purchase->renewal_currency ?: $member->defaultCurrency() );
}
if ( isset( $purchase->extra['originalExpire'] ) )
{
$newExpiry = \IPS\DateTime::ts( $purchase->extra['originalExpire'] );
}
else
{
$newExpiry = \IPS\DateTime::create()->add( $purchase->renewals->interval );
}
$purchase->expire = $newExpiry;
$purchase->save();
$member->log( 'purchase', array( 'type' => 'info', 'info' => 'restored_expire', 'id' => $purchase->id, 'name' => $purchase->name ) );
if ( $newExpiry->getTimestamp() < time() )
{
if ( $status === \IPS\Member\Club::STATUS_MEMBER )
{
$this->club->addMember( $member, \IPS\Member\Club::STATUS_EXPIRED, TRUE );
}
elseif ( $status === \IPS\Member\Club::STATUS_MODERATOR )
{
$this->club->addMember( $member, \IPS\Member\Club::STATUS_EXPIRED_MODERATOR, TRUE );
}
}
else
{
if ( $status === \IPS\Member\Club::STATUS_EXPIRED )
{
$this->club->addMember( $member, \IPS\Member\Club::STATUS_MEMBER, TRUE );
}
elseif ( $status === \IPS\Member\Club::STATUS_EXPIRED_MODERATOR )
{
$this->club->addMember( $member, \IPS\Member\Club::STATUS_MODERATOR, TRUE );
}
}
}
/* If we couldn't find a purchase, we'll have to remove them and re-invite them */
if ( !$foundPurchase )
{
$this->club->addMember( $member, \IPS\Member\Club::STATUS_INVITED, TRUE, NULL, \IPS\Member::loggedIn(), TRUE );
$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 ) );
$notification->recipients->attach( $member );
$notification->send();
}
break;
/* If they have been invited, just change their status to invited NOT bypassing payment */
case \IPS\Member\Club::STATUS_INVITED_BYPASSING_PAYMENT:
$this->club->addMember( $member, \IPS\Member\Club::STATUS_INVITED, TRUE );
break;
/* For anything else, we can't do this... */
default:
\IPS\Output::i()->error( 'node_error', '2C350/X', 403, '' );
}
$this->club->recountMembers();
/* Redirect */
@@ -729,11 +1020,55 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
\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 ( $this->memberStatus === \IPS\Member\Club::STATUS_INVITED 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') )
{
$this->club->addMember( \IPS\Member::loggedIn(), \IPS\Member\Club::STATUS_MEMBER, TRUE, NULL, NULL, TRUE );
$this->club->recountMembers();
$notificationKey = 'club_join';
/* Unless they have to pay */
if ( $this->club->isPaid() and $this->memberStatus !== \IPS\Member\Club::STATUS_INVITED_BYPASSING_PAYMENT )
{
if ( $fee = $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();
/* Take them to it */
\IPS\Output::i()->redirect( $invoice->checkoutUrl() );
}
else
{
\IPS\Output::i()->error( 'club_paid_unavailable', '1C350/N', 403, '' );
}
}
else
{
$this->club->addMember( \IPS\Member::loggedIn(), \IPS\Member\Club::STATUS_MEMBER, TRUE, NULL, NULL, TRUE );
$this->club->recountMembers();
$notificationKey = 'club_join';
}
}
/* Otherwise, add the request */
else
@@ -762,7 +1097,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 ) ) 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 ) ) 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, '' );
}
@@ -770,15 +1105,57 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
/* CSRF Check */
\IPS\Session::i()->csrfCheck();
/* Cancel purchase */
if ( \IPS\Application::appIsEnabled('nexus') and \IPS\Settings::i()->clubs_paid_on )
{
foreach ( \IPS\core\extensions\nexus\Item\ClubMembership::getPurchases( \IPS\nexus\Customer::loggedIn(), $this->club->id ) as $purchase )
{
$purchase->cancelled = TRUE;
$purchase->member->log( 'purchase', array( 'type' => 'cancel', 'id' => $purchase->id, 'name' => $purchase->name ) );
$purchase->can_reactivate = FALSE;
$purchase->save();
}
}
/* Leave */
$this->club->removeMember( \IPS\Member::loggedIn() );
$this->club->recountMembers();
$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\Member::loggedIn()->recountNotifications();
/* Redirect */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=clubs&controller=directory', 'front', 'clubs_list' ) );
}
/**
* Renew
*
* @return void
*/
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 ) ) )
{
\IPS\Output::i()->error( 'no_module_permission', '2C350/Y', 403, '' );
}
/* CSRF Check */
\IPS\Session::i()->csrfCheck();
/* Find the purchase */
foreach ( \IPS\core\extensions\nexus\Item\ClubMembership::getPurchases( \IPS\nexus\Customer::loggedIn(), $this->club->id ) as $purchase )
{
\IPS\Output::i()->redirect( $purchase->url()->setQueryString( array( 'do' => 'renew', 'cycles' => 1 ) )->csrf() );
}
/* Couldn't find it? */
\IPS\Output::i()->error( 'no_module_permission', '2C350/Z', 500, '' );
}
/**
* Invite Members
*
@@ -794,9 +1171,23 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
$form = new \IPS\Helpers\Form( 'form', 'club_send_invitations' );
$form->class = 'ipsForm_vertical';
$form->add( new \IPS\Helpers\Form\Member( 'members', NULL, TRUE, array( 'multiple' => NULL ) ) );
if ( $this->club->isPaid() and $this->club->isLeader() )
{
$form->add( new \IPS\Helpers\Form\YesNo( 'club_invite_waive_fee', FALSE ) );
if ( $this->club->renewal_price )
{
\IPS\Member::loggedIn()->language()->words['club_invite_waive_fee_desc'] = \IPS\Member::loggedIn()->language()->addToStack('club_invite_waive_fee_renewal');
}
}
if ( $values = $form->values() )
{
$status = \IPS\Member\Club::STATUS_INVITED;
if ( $this->club->isPaid() and $this->club->isLeader() and $values['club_invite_waive_fee'] )
{
$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 )
{
@@ -805,7 +1196,7 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
$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 ) ) )
{
$this->club->addMember( $member, \IPS\Member\Club::STATUS_INVITED, TRUE, NULL, \IPS\Member::loggedIn(), TRUE );
$this->club->addMember( $member, $status, TRUE, NULL, \IPS\Member::loggedIn(), TRUE );
$notification->recipients->attach( $member );
}
}
@@ -999,6 +1390,52 @@ class _view extends \IPS\Helpers\CoverPhoto\Controller
\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;
}
/**
* Delete a node
*
* @return void
*/
protected function nodeDelete()
{
\IPS\Session::i()->csrfCheck();
/* Permission check */
if ( !$this->club->isLeader() )
{
\IPS\Output::i()->error( 'no_module_permission', '2C350/AA', 403, '' );
}
/* Load */
$class = \IPS\Request::i()->type;
try
{
$node = $class::load( \IPS\Request::i()->node );
$club = $node->club();
if ( !$club or $club->id !== $this->club->id )
{
throw new \Exception;
}
}
catch ( \Exception $e )
{
\IPS\Output::i()->error( 'node_error', '2C350/AB', 404, '' );
}
/* Permission check */
$itemClass = $node::$contentItemClass;
if ( !$node->modPermission( 'delete', \IPS\Member::loggedIn() ) and $itemClass::contentCount( $node, TRUE, TRUE, TRUE, 1 ) )
{
\IPS\Output::i()->error( 'no_module_permission', '2C350/AC', 403, '' );
}
/* Delete */
\IPS\Db::i()->delete( 'core_clubs_node_map', array( 'club_id=? AND node_class=? AND node_id=?', $club->id, $class, $node->_id ) );
$node->deleteOrMoveFormSubmit( array() );
/* Redirect */
\IPS\Output::i()->redirect( $club->url() );
}
/* !Cover Photo */
/**