Version 4.1.19
This commit is contained in:
1 parent
28bd025b35
commit
2bd5025018
2674 files changed
+233518
-77766
No files matched your search
@@ -2,9 +2,9 @@
|
||||
/**
|
||||
* @brief Bulk mail handler
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @package IPS Community Suite
|
||||
* @since 18 Jun 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -119,13 +119,14 @@ class _bulkmail extends \IPS\Dispatcher\Controller
|
||||
'title' => 'cancel',
|
||||
'link' => \IPS\Http\Url::internal( 'app=core&module=bulkmail&controller=bulkmail&do=cancel&id=' ) . $row['mail_id'],
|
||||
);
|
||||
|
||||
if ( \IPS\Settings::i()->mandrill_api_key AND \IPS\Settings::i()->mandrill_use_for )
|
||||
|
||||
$classToUse = \IPS\Email::classToUse( \IPS\Email::TYPE_BULK );
|
||||
if( !$classToUse::REQUIRES_TIME_BREAK )
|
||||
{
|
||||
$return['resend'] = array(
|
||||
'icon' => 'share',
|
||||
'title' => 'continue_sending',
|
||||
'link' => \IPS\Http\Url::internal( 'app=core&module=bulkmail&controller=bulkmail&resetTask=1&do=sendMandrill&id=' ) . $row['mail_id'],
|
||||
'link' => \IPS\Http\Url::internal( 'app=core&module=bulkmail&controller=bulkmail&resetTask=1&do=sendImmediately&id=' ) . $row['mail_id'],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -152,17 +153,7 @@ class _bulkmail extends \IPS\Dispatcher\Controller
|
||||
return $return;
|
||||
};
|
||||
|
||||
/* Shortcut to Mandrill configuration */
|
||||
\IPS\Output::i()->sidebar['actions'] = array(
|
||||
'configure' => array(
|
||||
'title' => 'mandrill_cross_link',
|
||||
'icon' => 'cog',
|
||||
'link' => \IPS\Http\Url::internal( "app=core&module=applications&controller=enhancements&do=edit&id=core_Mandrill" ),
|
||||
),
|
||||
);
|
||||
|
||||
/* Display */
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('manage_bulk_mail');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->block( 'title', (string) $table );
|
||||
}
|
||||
@@ -174,6 +165,9 @@ class _bulkmail extends \IPS\Dispatcher\Controller
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
/* Make sure the user confirmed the deletion */
|
||||
\IPS\Request::i()->confirmedDelete();
|
||||
|
||||
/* Retrieve the bulk mail details for the log */
|
||||
try
|
||||
{
|
||||
@@ -187,9 +181,6 @@ class _bulkmail extends \IPS\Dispatcher\Controller
|
||||
/* Delete the bulk mail */
|
||||
$mail->delete();
|
||||
|
||||
/* Reset bulk mail task */
|
||||
\IPS\core\BulkMail\Bulkmailer::updateTask();
|
||||
|
||||
/* Log and redirect */
|
||||
\IPS\Session::i()->log( 'acplog__bulkmail_deleted', array( $mail->subject => FALSE ) );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=bulkmail&controller=bulkmail' ), 'deleted' );
|
||||
@@ -216,9 +207,16 @@ class _bulkmail extends \IPS\Dispatcher\Controller
|
||||
$mail->updated = time();
|
||||
$mail->active = 0;
|
||||
$mail->save();
|
||||
|
||||
/* Reset bulk mail task */
|
||||
\IPS\core\BulkMail\Bulkmailer::updateTask();
|
||||
|
||||
/* Remove any queue tasks */
|
||||
foreach( \IPS\Db::i()->select( '*', 'core_queue', array( "`key`=?", 'Bulkmail' ) ) AS $task )
|
||||
{
|
||||
$data = json_decode( $task['data'], TRUE );
|
||||
if ( isset( $data['mail_id'] ) AND $data['mail_id'] == $mail->id )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_queue', array( "id=?", $task['id'] ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Log and redirect */
|
||||
\IPS\Session::i()->log( 'acplog__bulkmail_cancelled', array( $mail->subject => FALSE ) );
|
||||
@@ -259,7 +257,7 @@ class _bulkmail extends \IPS\Dispatcher\Controller
|
||||
$results = $mail->getQuery( array( 0, 1000 ) );
|
||||
|
||||
/* Get a count of the members */
|
||||
$total = $results->count( TRUE );
|
||||
$total = $mail->getQuery( \IPS\core\BulkMail\Bulkmailer::GET_COUNT_ONLY )->first();
|
||||
|
||||
/* Do we have anyone to send to? */
|
||||
if( !$total )
|
||||
@@ -276,12 +274,7 @@ class _bulkmail extends \IPS\Dispatcher\Controller
|
||||
|
||||
/* Output */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('bm_send_preview');
|
||||
|
||||
if( !\IPS\Settings::i()->mandrill_api_key )
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->message( 'bulkmail_send_info', 'information' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->message( 'bulkmail_send_info', 'information' );
|
||||
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'members' )->bulkMailPreview( $mail, $results, $total );
|
||||
}
|
||||
|
||||
@@ -301,12 +294,46 @@ class _bulkmail extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
\IPS\Output::i()->error( 'couldnt_find_bulkmail', '2C125/2', 404, '' );
|
||||
}
|
||||
|
||||
/* For the preview we need to display the tags replaced with this member's data */
|
||||
$content = $mail->content;
|
||||
foreach ( $mail->returnTagValues( 0, \IPS\Member::loggedIn() ) as $k => $v )
|
||||
{
|
||||
$content = str_replace( $k, $v, $content );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
$email = \IPS\Email::buildFromContent( $mail->subject, $content, NULL, \IPS\Email::TYPE_BULK )->setUnsubscribe( 'core', 'unsubscribeBulk' );
|
||||
|
||||
/* Format the email */
|
||||
$email = \IPS\Email::buildFromContent( $mail->subject, $mail->formatBody( \IPS\Member::loggedIn() ) );
|
||||
$email->buildUnsubscribe( 'bulk', \IPS\Member::loggedIn() );
|
||||
\IPS\Output::i()->sendOutput( $email->compileContent( 'html', \IPS\Member::loggedIn() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a bulk mail by replacing out the tags with the proper values
|
||||
*
|
||||
* @param \IPS\Member $member Member data
|
||||
* @return string
|
||||
*/
|
||||
public function formatBody( $member )
|
||||
{
|
||||
if( empty($this->_data['content']) )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
\IPS\Output::i()->sendOutput( $email->body['html'] );
|
||||
/* Default tags */
|
||||
$tags = $this->returnTagValues( 0, $member );
|
||||
|
||||
/* Work on a copy rather than the original template */
|
||||
$body = $this->_data['content'];
|
||||
|
||||
/* Loop over the tags and swap out as appropriate */
|
||||
foreach( $tags as $key => $value )
|
||||
{
|
||||
$body = str_replace( $key, $value, $body );
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -332,37 +359,32 @@ class _bulkmail extends \IPS\Dispatcher\Controller
|
||||
$mail->sentto = 0;
|
||||
$mail->save();
|
||||
|
||||
/* Reset bulk mail task */
|
||||
\IPS\core\BulkMail\Bulkmailer::updateTask();
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__bulkmail_sent', array( $mail->subject => FALSE ) );
|
||||
|
||||
/* And redirect */
|
||||
if( \IPS\Settings::i()->mandrill_api_key AND \IPS\Settings::i()->mandrill_use_for )
|
||||
$classToUse = \IPS\Email::classToUse( \IPS\Email::TYPE_BULK );
|
||||
if( !$classToUse::REQUIRES_TIME_BREAK )
|
||||
{
|
||||
return $this->sendMandrill();
|
||||
return $this->sendImmediately();
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Task::queue( 'core', 'Bulkmail', array( 'mail_id' => $mail->id ) );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=bulkmail&controller=bulkmail' ), 'bm_initiated' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Mandrill bulk mails immediately
|
||||
* Send bulk mails immediately
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function sendMandrill()
|
||||
public function sendImmediately()
|
||||
{
|
||||
/* If we are "continuing" an existing bulk mail send, update the task first */
|
||||
if( isset( \IPS\Request::i()->resetTask ) AND \IPS\Request::i()->resetTask == 1 )
|
||||
{
|
||||
\IPS\core\BulkMail\Bulkmailer::updateTask();
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('bm_initiated');
|
||||
|
||||
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect(
|
||||
\IPS\Http\Url::internal( "app=core&module=bulkmail&controller=bulkmail&do=sendMandrill&id=" . intval( \IPS\Request::i()->id ) ),
|
||||
\IPS\Http\Url::internal( "app=core&module=bulkmail&controller=bulkmail&do=sendImmediately&id=" . intval( \IPS\Request::i()->id ) ),
|
||||
function( $data )
|
||||
{
|
||||
/* Retrieve the bulk mail details */
|
||||
@@ -378,7 +400,7 @@ class _bulkmail extends \IPS\Dispatcher\Controller
|
||||
/* On first cycle return data */
|
||||
if ( !is_array( $data ) )
|
||||
{
|
||||
return array( array( 'total' => $mail->getQuery()->count( TRUE ), 'done' => 0 ),
|
||||
return array( array( 'total' => $mail->getQuery( \IPS\core\BulkMail\Bulkmailer::GET_COUNT_ONLY )->first() ),
|
||||
\IPS\Member::loggedIn()->language()->addToStack('bulkmail_sent_sofar', FALSE, array( 'sprintf' => array( $mail->subject, \IPS\Member::loggedIn()->language()->addToStack( 'bm_users', FALSE, array( 'pluralize' => array( 0 ) ) ) ) ) ),
|
||||
1
|
||||
);
|
||||
@@ -394,18 +416,16 @@ class _bulkmail extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
else
|
||||
{
|
||||
$data['done'] += (int) $result;
|
||||
|
||||
return array( $data,
|
||||
\IPS\Member::loggedIn()->language()->addToStack('bulkmail_sent_sofar', FALSE, array( 'sprintf' => array( $mail->subject, \IPS\Member::loggedIn()->language()->addToStack( 'bm_users', FALSE, array( 'pluralize' => array( $result ) ) ) ) ) ),
|
||||
( $result / $data['total'] * $data['done'] )
|
||||
\IPS\Member::loggedIn()->language()->addToStack('bulkmail_sent_sofar', FALSE, array( 'sprintf' => array( $mail->subject, \IPS\Member::loggedIn()->language()->addToStack( 'bm_users', FALSE, array( 'pluralize' => array( $mail->sentto ) ) ) ) ) ),
|
||||
min( ( 100 / $data['total'] * $mail->offset ), 100 )
|
||||
);
|
||||
}
|
||||
},
|
||||
function()
|
||||
{
|
||||
/* We don't have to do anything special because BulkMailer will have already updated the task and disabled the bulk mail */
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=bulkmail&controller=bulkmail' ), 'bm_mandrill_sent' );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=bulkmail&controller=bulkmail' ), 'bm_sparkpost_sent' );
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -445,12 +465,7 @@ class _bulkmail extends \IPS\Dispatcher\Controller
|
||||
$form->class = 'ipsForm_vertical';
|
||||
$form->addTab( 'bulkmail__main' );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'mail_subject', $mail->subject, TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Editor( 'mail_body', $mail->content ?: "<p>{member_name},</p><p> </p>", TRUE, array( 'app' => 'core', 'key' => 'Admin', 'autoSaveKey' => 'bulkmail' . ( $mail->id ? '-' . $mail->id : '' ), 'tags' => $tags, 'attachIds' => array( $mail->id, NULL, 'bulkmail' ) ) ) );
|
||||
|
||||
if( \IPS\Settings::i()->mandrill_api_key AND \IPS\Settings::i()->mandrill_use_for )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'mandrill_tags', ( !empty( $mail->_options['mandrill_tags'] ) ) ? $mail->_options['mandrill_tags'] : array(), FALSE ) );
|
||||
}
|
||||
$form->add( new \IPS\Helpers\Form\Editor( 'mail_body', $mail->content ?: '', TRUE, array( 'app' => 'core', 'key' => 'Admin', 'autoSaveKey' => 'bulkmail' . ( $mail->id ? '-' . $mail->id : '' ), 'tags' => $tags, 'attachIds' => array( $mail->id, NULL, 'bulkmail' ) ) ) );
|
||||
|
||||
/* Add the filters tab and the "generic filters" header */
|
||||
$form->addTab( 'bulkmail__filters' );
|
||||
@@ -459,7 +474,7 @@ class _bulkmail extends \IPS\Dispatcher\Controller
|
||||
$lastApp = 'core';
|
||||
|
||||
/* Now grab bulk mail extensions */
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'BulkMail', TRUE, 'core' ) as $key => $extension )
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' ) as $key => $extension )
|
||||
{
|
||||
if( method_exists( $extension, 'getSettingField' ) )
|
||||
{
|
||||
@@ -494,13 +509,8 @@ class _bulkmail extends \IPS\Dispatcher\Controller
|
||||
|
||||
$_options = array();
|
||||
|
||||
if( \IPS\Settings::i()->mandrill_api_key AND \IPS\Settings::i()->mandrill_use_for )
|
||||
{
|
||||
$_options['mandrill_tags'] = $values['mandrill_tags'];
|
||||
}
|
||||
|
||||
/* Loop over bulk mail extensions to format the options */
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'BulkMail', TRUE, 'core' ) as $key => $extension )
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' ) as $key => $extension )
|
||||
{
|
||||
if( method_exists( $extension, 'save' ) )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user