Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -11,7 +11,7 @@
|
||||
namespace IPS\core\BulkMail;
|
||||
|
||||
/* 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;
|
||||
@@ -68,98 +68,6 @@ class _Bulkmailer extends \IPS\Patterns\ActiveRecord
|
||||
$this->opts = json_encode( $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the bulk mail. Determines if bulk mail should be sent via a task or immediately and dispatches appropriately.
|
||||
*
|
||||
* @return NULL|int
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
/* Work out how many to do */
|
||||
$classToUse = \IPS\Email::classToUse( \IPS\Email::TYPE_BULK );
|
||||
$limit = array( $this->offset, $classToUse::MAX_EMAILS_PER_GO );
|
||||
|
||||
/* Get recipients */
|
||||
$results = $this->getQuery( $limit );
|
||||
|
||||
/* If there are no recipients we must be done */
|
||||
if( !count( $results ) )
|
||||
{
|
||||
$this->active = 0;
|
||||
$this->offset = 0;
|
||||
$this->save();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Convert $results into an array with replacement tags */
|
||||
$recipients = array();
|
||||
foreach ( $results as $memberData )
|
||||
{
|
||||
$member = \IPS\Member::constructFromData( $memberData );
|
||||
|
||||
$vars = array();
|
||||
foreach ( $this->returnTagValues( 2, $member ) as $k => $v )
|
||||
{
|
||||
$vars[ mb_substr( $k, 1, -1 ) ] = $v;
|
||||
}
|
||||
|
||||
$recipients[ $member->language()->_id ][ $memberData['email'] ] = $vars;
|
||||
}
|
||||
|
||||
/* Convert member-specific {{tag}} into *|tag|* and global {{tag}} into the value */
|
||||
$content = $this->_data['content'];
|
||||
foreach ( $this->returnTagValues( 1 ) as $k => $v )
|
||||
{
|
||||
$content = str_replace( $k, $v, $content );
|
||||
}
|
||||
foreach( array_keys( static::getTags() ) as $k )
|
||||
{
|
||||
if ( mb_strpos( $content, $k ) !== FALSE )
|
||||
{
|
||||
$content = str_replace( $k, '*|' . str_replace( array( '{', '}' ), '', $k ) . '|*', $content );
|
||||
}
|
||||
}
|
||||
|
||||
/* Format content */
|
||||
$content = \IPS\Email::staticParseTextForEmail( $content, \IPS\Lang::load( \IPS\Lang::defaultLanguage() ) );
|
||||
|
||||
foreach( array_keys( static::getTags() ) as $k )
|
||||
{
|
||||
$content = str_replace( '%7B' . mb_substr( $k, 1, -1 ) . '%7D', '*|' . mb_substr( $k, 1, -1 ) . '|*', $content );
|
||||
$content = str_replace( '*%7' . mb_substr( $k, 1, -1 ) . '%7C*', '*|' . mb_substr( $k, 1, -1 ) . '|*', $content );
|
||||
}
|
||||
|
||||
/* Send it */
|
||||
$email = \IPS\Email::buildFromContent( $this->_data['subject'], $content, NULL, \IPS\Email::TYPE_BULK )
|
||||
->setUnsubscribe( 'core', 'unsubscribeBulk' );
|
||||
$sent = 0;
|
||||
foreach ( $recipients as $languageId => $_recipients )
|
||||
{
|
||||
$sent += $email->mergeAndSend( $_recipients, NULL, NULL, array( 'List-Unsubscribe' => '<*|unsubscribe_url|*>' ), \IPS\Lang::load( $languageId ) );
|
||||
}
|
||||
|
||||
/* Update bulk mail record */
|
||||
if( $sent === 0 )
|
||||
{
|
||||
$this->active = 0;
|
||||
$this->updated = time();
|
||||
$this->offset = 0;
|
||||
$this->save();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->updated = time();
|
||||
$this->offset = ( $this->offset + $classToUse::MAX_EMAILS_PER_GO );
|
||||
$this->sentto = ( $this->sentto + $sent );
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/* Return the number to increase the offset by (not necessarily the number of users the email was sent to, but still the amount we need to increase the offset by) */
|
||||
return $classToUse::MAX_EMAILS_PER_GO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the query to fetch members based on our filters
|
||||
*
|
||||
@@ -184,7 +92,12 @@ class _Bulkmailer extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
if( $_where = $extension->getQueryWhereClause( $this->_options[ $key ] ) )
|
||||
{
|
||||
$where[] = $_where;
|
||||
if ( \is_string( $_where ) )
|
||||
{
|
||||
$_where = array( $_where );
|
||||
}
|
||||
|
||||
$where = array_merge( $where, $_where );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,7 +105,7 @@ class _Bulkmailer extends \IPS\Patterns\ActiveRecord
|
||||
|
||||
/* Compile query */
|
||||
$select = ( $option !== static::GET_COUNT_ONLY ) ? 'core_members.member_id AS my_member_id, core_members.*' : 'COUNT(DISTINCT core_members.member_id)';
|
||||
$limit = is_array( $option ) ? $option : NULL;
|
||||
$limit = \is_array( $option ) ? $option : NULL;
|
||||
$query = \IPS\Db::i()->select( $select, 'core_members', $where, ( $option !== static::GET_COUNT_ONLY ) ? 'core_members.member_id' : NULL, $limit, NULL, NULL, \IPS\Db::SELECT_DISTINCT );
|
||||
|
||||
/* Run callbacks */
|
||||
|
||||
Reference in new issue
Block a user