Page Menu
Home
GitPull.it
Search
Configure Global Search
Log In
Files
F15187219
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Unknown
Size
9 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/include/class-Domain.php b/include/class-Domain.php
index 18c5062..b3859ab 100644
--- a/include/class-Domain.php
+++ b/include/class-Domain.php
@@ -1,131 +1,185 @@
<?php
# Copyright (C) 2018, 2019 Valerio Bozzolan
# Boz Libre Hosting Panel
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
// load Plan trait
class_exists( 'Plan' );
/**
* Methods for a Domain class
*/
trait DomainTrait {
use PlanTrait;
+ /**
+ * Count of the Domain's Mailboxes
+ *
+ * This is a kind of cache
+ *
+ * @var int
+ */
+ private $domainMailboxCount = null;
+
/**
* Get domain ID
*
* @return int
*/
public function getDomainID() {
return $this->get( 'domain_ID' );
}
/*
* Get domain name
*
* @return string
*/
public function getDomainName() {
return $this->get( 'domain_name' );
}
/**
* Get the domain edit URl
*
* @param boolean $absolute True for an absolute URL
* @return string
*/
public function getDomainPermalink( $absolute = false ) {
return Domain::permalink( $this->get( 'domain_name' ), $absolute );
}
/**
* Factory mailbox from this domain
*
* @return MailboxFullAPI
*/
public function factoryMailbox() {
return ( new MailboxFullAPI() )->whereDomain( $this );
}
/**
* Factory e-mail forward from this domain
*
* @return MailforwardFullAPI
*/
public function factoryMailforwardfrom() {
return ( new MailforwardfromAPI() )->whereDomain( $this );
}
+ /**
+ * Set a count of Domain's Mailboxes
+ *
+ * @param $count int
+ * @return self
+ */
+ public function setDomainMailboxCount( $count ) {
+ $this->domainMailboxCount = $count;
+ }
+
+ /**
+ * Get the number of Mailboxes of this Domain
+ *
+ * This method has a layer of cache.
+ *
+ * @return int
+ */
+ public function getDomainMailboxCount() {
+
+ // check if we already know the count
+ if( !isset( $this->domainMailboxCount ) ) {
+
+ // count the number of mailboxes associated to this Domain
+ $count = $this->factoryMailbox()
+ ->select( 'COUNT(*) count' )
+ ->queryValue( 'count' );
+
+ // save in cache
+ $this->domainMailboxCount = (int) $count;
+ }
+
+ return $this->domainMailboxCount;
+ }
+
+ /**
+ * Check if you can create a new mailbox for this Domain
+ *
+ * The Domain must have plan informations.
+ *
+ * @return boolean
+ */
+ public function canCreateMailboxInDomain() {
+ return $this->getPlanMailboxes() > $this->getDomainMailboxCount() || has_permission( 'edit-email-all' );
+ }
+
/**
* Factory FTP users from this domain
*
* @return FTPAPI
*/
public function factoryFTP() {
return ( new FTPAPI() )->whereDomain( $this );
}
/**
* Normalize a Domain object after being retrieved from database
*/
protected function normalizeDomain() {
$this->integers( 'domain_ID' );
$this->booleans( 'domain_active' );
$this->dates( 'domain_born', 'domain_expiration' );
$this->normalizePlan();
}
}
/**
* Describe the 'domain' table
*/
class Domain extends Queried {
use DomainTrait;
/**
* Table name
*/
const T = 'domain';
const UID = 'domain_name';
/**
* Constructor
*/
public function __construct() {
$this->normalizeDomain();
}
/**
* Get the domain permalink
*
* @param string $domain_name Domain name
* @param boolean $absolute True for an absolute URL
*/
public static function permalink( $domain_name = null, $absolute = false ) {
$url = 'domain.php';
if( $domain_name ) {
$url .= _ . $domain_name;
}
return site_page( $url, $absolute );
}
}
diff --git a/include/class-MailboxAPI.php b/include/class-MailboxAPI.php
index 10a4035..bad385a 100644
--- a/include/class-MailboxAPI.php
+++ b/include/class-MailboxAPI.php
@@ -1,118 +1,118 @@
<?php
# Copyright (C) 2018, 2019 Valerio Bozzolan
# Boz Libre Hosting Panel
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
// load dependend traits
class_exists( 'DomainAPI' );
/**
* Methods for a MailboxAPI class
*/
trait MailboxAPITrait {
use DomainAPITrait;
/**
* Limit to a specific mailbox
*
* @param object $mailbox Mailbox
* @return self
*/
public function whereMailbox( $mailbox ) {
return $this->whereDomain( $mailbox )
- ->whereMaiboxUsername( $mailbox->getMailboxUsername() );
+ ->whereMailboxUsername( $mailbox->getMailboxUsername() );
}
/**
* Filter a specific Mailbox username
*
* @param string $username Mailbox username (without domain name)
* @return self
*/
public function whereMailboxUsername( $username ) {
return $this->whereStr( 'mailbox_username', $username );
}
/**
* Where the Mailbox is Active (or not)
*
* @param boolean $active If you want the active, or the inactive
* @return self
*/
public function whereMailboxIsActive( $active = true ) {
return $this->whereInt( 'mailbox_active', $active );
}
/**
* Join mailboxes and domain (once)
*
* @return self
*/
public function joinMailboxDomain() {
if( empty( $this->joinedMailboxDomain ) ) {
$this->from( 'domain' );
$this->equals( 'domain.domain_ID', 'mailbox.domain_ID' );
$this->joinedMailboxDomain = true;
}
return $this;
}
/**
* Check if I can edit this mailbox
*
* Actually it just checks if you can edit the whole domain.
*
* @return boolean
*/
public function whereMailboxIsEditable() {
return $this->whereDomainIsEditable();
}
}
/**
* Mailbox API
*/
class MailboxAPI extends Query {
use MailboxAPITrait;
/**
* Univoque Domain ID column name
*
* Used by DomainAPITrait
*/
const DOMAIN_ID = 'mailbox.domain_ID';
/**
* Univoque Plan ID column name
*/
const PLAN_ID = 'domain.plan_ID';
/**
* Constructor
*/
public function __construct( $db = null ) {
// set database and class name
parent::__construct( $db, Mailbox::class );
// set database table
$this->from( Mailbox::T );
}
}
diff --git a/template/mailboxes.php b/template/mailboxes.php
index 15d8684..1e53bc5 100644
--- a/template/mailboxes.php
+++ b/template/mailboxes.php
@@ -1,76 +1,79 @@
<?php
-# Copyright (C) 2018 Valerio Bozzolan
+# Copyright (C) 2018, 2019 Valerio Bozzolan
# Boz Libre Hosting Panel
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
* This is the template for the mailboxes list
*
* Called from:
* template/domain.php
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
// domain mailboxes
$mailboxes = $domain->factoryMailbox()
->select( [
'domain_name',
'mailbox_username',
'mailbox_receive',
] )
->queryGenerator();
// total number of mailboxes
$count = DB::instance()->affectedRows();
+
+// cache the value that can be useful
+$domain->setDomainMailboxCount( $count );
?>
<!-- mail boxes -->
<h3><?php printf(
__( "Your %s" ),
__( "mailboxes" )
) ?></h3>
<?php template( 'mailbox-description', [
'mailbox' => null,
] ) ?>
<?php if( $mailboxes->valid() ): ?>
<ul>
<?php foreach( $mailboxes as $mailbox ): ?>
<li>
<code><?= HTML::a(
$mailbox->getMailboxPermalink(),
esc_html( $mailbox->getMailboxAddress() )
) ?></code>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
<p><?= esc_html( sprintf(
__( "Your Plan \"%s\" allows %s %s." ),
$plan->getPlanName(),
$plan->getPlanMailboxes(),
__( "Mailboxes" )
) ) ?></p>
-<?php if( $plan->getPlanMailboxes() > $count || has_permission( 'edit-email-all' ) ): ?>
+<?php if( $domain->canCreateMailboxInDomain() ): ?>
<p><?php the_link( Mailbox::permalink( $domain->getDomainName() ), __( "Create" ) ) ?></p>
<?php endif ?>
<!-- end mail boxes -->
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Nov 19, 09:45 (20 m, 27 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2265659
Default Alt Text
(9 KB)
Attached To
Mode
R3 KISS Libre Hosting Panel
Attached
Detach File
Event Timeline