Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

@@ -11,31 +11,45 @@
namespace IPS\core\BulkMail;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Application;
use IPS\DateTime;
use IPS\Db;
use IPS\Db\Select;
use IPS\File;
use IPS\Http\Url;
use IPS\Member;
use IPS\Patterns\ActiveRecord;
use IPS\Settings;
use function defined;
use function is_array;
use function is_string;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Bulk mail central library
*/
class _Bulkmailer extends \IPS\Patterns\ActiveRecord
class Bulkmailer extends ActiveRecord
{
/**
* @brief Database Table
*/
public static $databaseTable = 'core_bulk_mail';
public static ?string $databaseTable = 'core_bulk_mail';
/**
* @brief [ActiveRecord] Database Prefix
*/
public static $databasePrefix = 'mail_';
public static string $databasePrefix = 'mail_';
/**
* @brief Multiton Store
*/
protected static $multitons;
protected static array $multitons;
/**
* @brief Flag to denote just getting the count only.
@@ -47,7 +61,7 @@ class _Bulkmailer extends \IPS\Patterns\ActiveRecord
*
* @return array
*/
public function get__options()
public function get__options() : array
{
if ( !isset( $this->_data['opts'] ) )
{
@@ -61,9 +75,9 @@ class _Bulkmailer extends \IPS\Patterns\ActiveRecord
* Set the mail options
*
* @param array $value Mail options
* @return vpid
* @return void
*/
public function set__options( $value )
public function set__options( array $value ) : void
{
$this->opts = json_encode( $value );
}
@@ -71,28 +85,28 @@ class _Bulkmailer extends \IPS\Patterns\ActiveRecord
/**
* Retrieve the query to fetch members based on our filters
*
* @param array|int $option A constant to fetch counts only or an array with the limit to apply to the query
* @return \IPS\Db\Select
* @param array|int|null $option A constant to fetch counts only or an array with the limit to apply to the query
* @return Select
*/
public function getQuery( $option=NULL )
{
public function getQuery( array|int|null $option=NULL ) : Select
{
/* Compile where */
$where = array();
$where[] = array( "core_members.allow_admin_mails=1" );
$where[] = array( "core_members.temp_ban=0" );
$where[] = array( "core_members.email!=''" );
$where[] = array( '( ! ' . \IPS\Db::i()->bitwiseWhere( \IPS\Member::$bitOptions['members_bitoptions'], 'bw_is_spammer' ) . ' )' );
$where[] = array( '( ! ' . Db::i()->bitwiseWhere( Member::$bitOptions['members_bitoptions'], 'bw_is_spammer' ) . ' )' );
foreach ( \IPS\Application::allExtensions( 'core', 'MemberFilter', FALSE, 'core' ) as $key => $extension )
foreach ( Application::allExtensions( 'core', 'MemberFilter', FALSE, 'core' ) as $key => $extension )
{
if( method_exists( $extension, 'getQueryWhereClause' ) AND $extension->availableIn( 'bulkmail' ) )
if( $extension->availableIn( 'bulkmail' ) )
{
/* Grab our fields and add to the form */
if( !empty( $this->_options[ $key ] ) )
{
if( $_where = $extension->getQueryWhereClause( $this->_options[ $key ] ) )
{
if ( \is_string( $_where ) )
if ( is_string( $_where ) )
{
$_where = array( $_where );
}
@@ -105,13 +119,13 @@ 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;
$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 );
$limit = is_array( $option ) ? $option : NULL;
$query = Db::i()->select( $select, 'core_members', $where, ( $option !== static::GET_COUNT_ONLY ) ? 'core_members.member_id' : NULL, $limit, NULL, NULL, Db::SELECT_DISTINCT );
/* Run callbacks */
foreach ( \IPS\Application::allExtensions( 'core', 'MemberFilter', FALSE, 'core' ) as $key => $extension )
foreach ( Application::allExtensions( 'core', 'MemberFilter', FALSE, 'core' ) as $key => $extension )
{
if( method_exists( $extension, 'queryCallback' ) AND $extension->availableIn( 'bulkmail' ) )
if( $extension->availableIn( 'bulkmail' ) )
{
/* Grab our fields and add to the form */
if( !empty( $this->_options[ $key ] ) )
@@ -129,27 +143,27 @@ class _Bulkmailer extends \IPS\Patterns\ActiveRecord
* Return tag values
*
* @param int $type 0=All, 1=Global, 2=Member-specific
* @param NULL|\IPS\Member $member Member object if $type is 0 or 2
* @param NULL|Member $member Member object if $type is 0 or 2
* @return array
*/
public function returnTagValues( $type, $member=NULL )
public function returnTagValues( int $type, ?Member $member=NULL ) : array
{
$tags = array();
/* Do we want global tags? */
if( $type === 0 OR $type === 1 )
{
$mostOnline = json_decode( \IPS\Settings::i()->most_online, TRUE );
$mostOnline = json_decode( Settings::i()->most_online, TRUE );
$tags['{suite_name}'] = \IPS\Settings::i()->board_name;
$tags['{suite_url}'] = \IPS\Settings::i()->base_url;
$tags['{busy_time}'] = \IPS\DateTime::ts( ( $mostOnline['time'] ) ? $mostOnline['time'] : time() )->localeDate();
$tags['{suite_name}'] = Settings::i()->board_name;
$tags['{suite_url}'] = Settings::i()->base_url;
$tags['{busy_time}'] = DateTime::ts( ( $mostOnline['time'] ) ?: time() )->localeDate();
$tags['{busy_count}'] = $mostOnline['count'];
/* Only bother querying if we need the value */
if( mb_strpos( $this->_data['content'], '{reg_total}' ) !== FALSE )
{
$tags['{reg_total}'] = \IPS\Db::i()->select( 'count(*)', 'core_members', 'member_id > 0' )->first();
$tags['{reg_total}'] = Db::i()->select( 'count(*)', 'core_members', 'member_id > 0' )->first();
}
}
@@ -161,9 +175,9 @@ class _Bulkmailer extends \IPS\Patterns\ActiveRecord
$tags['{member_name}'] = $member->name;
$tags['{member_url}'] = $member->url();
$tags['{member_joined}'] = $member->joined->localeDate();
$tags['{member_last_visit}'] = \IPS\DateTime::ts( $member->last_visit )->localeDate();
$tags['{member_last_visit}'] = DateTime::ts( (int) $member->last_visit )->localeDate();
$tags['{member_posts}'] = $member->member_posts;
$tags['{unsubscribe_url}'] = (string) \IPS\Http\Url::internal( 'app=core&module=system&controller=unsubscribe', 'front', 'unsubscribe' )->setQueryString( array(
$tags['{unsubscribe_url}'] = (string) Url::internal( 'app=core&module=system&controller=unsubscribe', 'front', 'unsubscribe' )->setQueryString( array(
'email' => $member->email,
'key' => md5( $member->email . ':' . $member->members_pass_hash )
) );
@@ -173,12 +187,9 @@ class _Bulkmailer extends \IPS\Patterns\ActiveRecord
/* Now retrieve tags via any bulk mail extensions. We only want them to return an array of tags to perform formatting, but
$body is passed in case a particular tag is computationally expensive so that the extension may "sniff" for it and elect
not to perform the computation if it is not used. */
foreach ( \IPS\Application::allExtensions( 'core', 'BulkMail', TRUE, 'core' ) as $key => $extension )
foreach ( Application::allExtensions( 'core', 'BulkMail', TRUE, 'core' ) as $key => $extension )
{
if( method_exists( $extension, 'returnTagValues' ) )
{
$tags = array_merge( $tags, $extension->returnTagValues( $this->_data['content'], $type, $member ) );
}
$tags = array_merge( $tags, $extension->returnTagValues( $this->_data['content'], $type, $member ) );
}
return $tags;
@@ -189,25 +200,25 @@ class _Bulkmailer extends \IPS\Patterns\ActiveRecord
*
* @return array An array of tags in foramt of 'tag' => 'explanation text'
*/
public static function getTags()
public static function getTags() : array
{
/* Default tags */
$tags = array(
'{member_id}' => \IPS\Member::loggedIn()->language()->addToStack('bmtag_member_id'),
'{member_name}' => \IPS\Member::loggedIn()->language()->addToStack('bmtag_member_name'),
'{member_url}' => \IPS\Member::loggedIn()->language()->addToStack('bmtag_member_profileurl'),
'{member_joined}' => \IPS\Member::loggedIn()->language()->addToStack('bmtag_member_joined'),
'{member_last_visit}' => \IPS\Member::loggedIn()->language()->addToStack('bmtag_member_last_visit'),
'{member_posts}' => \IPS\Member::loggedIn()->language()->addToStack('bmtag_member_posts'),
'{reg_total}' => \IPS\Member::loggedIn()->language()->addToStack('bmtag_reg_total'),
'{suite_name}' => \IPS\Member::loggedIn()->language()->addToStack('bmtag_suite_name'),
'{suite_url}' => \IPS\Member::loggedIn()->language()->addToStack('bmtag_suite_url'),
'{busy_count}' => \IPS\Member::loggedIn()->language()->addToStack('bmtag_busy_count'),
'{busy_time}' => \IPS\Member::loggedIn()->language()->addToStack('bmtag_busy_time'),
'{member_id}' => Member::loggedIn()->language()->addToStack('bmtag_member_id'),
'{member_name}' => Member::loggedIn()->language()->addToStack('bmtag_member_name'),
'{member_url}' => Member::loggedIn()->language()->addToStack('bmtag_member_profileurl'),
'{member_joined}' => Member::loggedIn()->language()->addToStack('bmtag_member_joined'),
'{member_last_visit}' => Member::loggedIn()->language()->addToStack('bmtag_member_last_visit'),
'{member_posts}' => Member::loggedIn()->language()->addToStack('bmtag_member_posts'),
'{reg_total}' => Member::loggedIn()->language()->addToStack('bmtag_reg_total'),
'{suite_name}' => Member::loggedIn()->language()->addToStack('bmtag_suite_name'),
'{suite_url}' => Member::loggedIn()->language()->addToStack('bmtag_suite_url'),
'{busy_count}' => Member::loggedIn()->language()->addToStack('bmtag_busy_count'),
'{busy_time}' => Member::loggedIn()->language()->addToStack('bmtag_busy_time'),
);
/* Now grab tags from any bulk mail extensions */
foreach ( \IPS\Application::allExtensions( 'core', 'BulkMail', TRUE, 'core' ) as $key => $extension )
foreach ( Application::allExtensions( 'core', 'BulkMail', TRUE, 'core' ) as $key => $extension )
{
if( method_exists( $extension, 'getTags' ) )
{
@@ -221,21 +232,21 @@ class _Bulkmailer extends \IPS\Patterns\ActiveRecord
/**
* Delete Record
*
* @return void
* @return void
*/
public function delete()
public function delete(): void
{
/* Unclaim Attachments */
\IPS\File::unclaimAttachments( 'core_Admin', $this->id, NULL, 'bulkmail' );
File::unclaimAttachments( 'core_Admin', $this->id, NULL, 'bulkmail' );
/* Make sure any queue rows are removed */
foreach( \IPS\Db::i()->select( '*', 'core_queue', array( "`key`=?", 'Bulkmail' ) ) AS $task )
foreach( 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'] == $this->id )
{
\IPS\Db::i()->delete( 'core_queue', array( "id=?", $task['id'] ) );
Db::i()->delete( 'core_queue', array( "id=?", $task['id'] ) );
}
}