Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

-44
View File
@@ -1,44 +0,0 @@
<?php
/**
* @brief bulkmail Task
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 21 Jun 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* bulkmail Task
*/
class _bulkmail extends \IPS\Task
{
/**
* Execute
*
* @return mixed Message to log or NULL
*/
public function execute()
{
try
{
\IPS\core\BulkMail\Bulkmailer::constructFromData( \IPS\DB::i()->select( '*', 'core_bulk_mail', 'mail_active=1', 'mail_start ASC', 1 )->first() )->send();
}
catch ( \UnderflowException $e )
{
\IPS\core\BulkMail\Bulkmailer::updateTask( 0 );
\IPS\Log::i( \LOG_CRIT )->write( get_class( $e ) . "\n" . $e->getCode() . ": " . $e->getMessage() . "\n" . $e->getTraceAsString() );
}
}
}
+38 -9
View File
@@ -2,9 +2,9 @@
/**
* @brief Daily Cleanup Task
* @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 27 Aug 2013
* @version SVN_VERSION_NUMBER
*/
@@ -31,13 +31,13 @@ class _cleanup extends \IPS\Task
*/
public function execute()
{
/* Delete old password reset requests */
\IPS\Db::i()->delete( 'core_validating', array( 'lost_pass=1 AND entry_date < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P1D' ) )->getTimestamp() ) );
/* Delete old password / security answer reset requests */
\IPS\Db::i()->delete( 'core_validating', array( '( lost_pass=1 OR forgot_security=1 ) AND email_sent < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P1D' ) )->getTimestamp() ) );
/* Delete old validating members */
if ( \IPS\Settings::i()->validate_day_prune )
{
$select = \IPS\Db::i()->select( 'core_validating.member_id, core_members.member_posts', 'core_validating', array( 'core_validating.new_reg=1 AND core_validating.coppa_user<>1 AND core_validating.entry_date<? AND core_validating.lost_pass<>1 AND core_validating.user_verified=0 AND core_members.member_posts < 1', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->validate_day_prune . 'D' ) )->getTimestamp() ) )->join( 'core_members', 'core_members.member_id=core_validating.member_id' );
$select = \IPS\Db::i()->select( 'core_validating.member_id, core_members.member_posts', 'core_validating', array( 'core_validating.new_reg=1 AND core_validating.coppa_user<>1 AND core_validating.entry_date<? AND core_validating.lost_pass<>1 AND core_validating.user_verified=0 AND core_members.member_posts < 1 AND core_validating.do_not_delete=0', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->validate_day_prune . 'D' ) )->getTimestamp() ) )->join( 'core_members', 'core_members.member_id=core_validating.member_id' );
foreach ( $select as $row )
{
@@ -52,6 +52,12 @@ class _cleanup extends \IPS\Task
}
}
/* Delete file system logs */
if( \IPS\Settings::i()->file_log_pruning )
{
\IPS\Db::i()->delete( 'core_file_logs', array( 'log_date < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->file_log_pruning . 'D' ) )->getTimestamp() ) );
}
/* Delete edit history past prune date */
if( \IPS\Settings::i()->edit_log_prune > 0 )
{
@@ -106,12 +112,21 @@ class _cleanup extends \IPS\Task
\IPS\Db::i()->delete( 'core_admin_login_logs', array( 'admin_time < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_log_adminlogin . 'D' ) )->getTimestamp() ) );
}
/* ...and geoip cache */
\IPS\Db::i()->delete( 'core_geoip_cache', array( 'date < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'PT12H' ) )->getTimestamp() ) );
/* ...and API logs */
if( \IPS\Settings::i()->api_log_prune )
{
\IPS\Db::i()->delete( 'core_api_logs', array( 'date < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->api_log_prune . 'D' ) )->getTimestamp() ) );
}
/* Delete old notifications */
if ( \IPS\Settings::i()->prune_notifications )
{
$memberIds = array();
foreach( \IPS\DB::i()->select( 'member', 'core_notifications', array( 'sent_time < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_notifications . 'M' ) )->getTimestamp() ) ) as $member )
foreach( \IPS\Db::i()->select( 'member', 'core_notifications', array( 'sent_time < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_notifications . 'M' ) )->getTimestamp() ) ) as $member )
{
$memberIds[ $member ] = $member;
}
@@ -151,7 +166,7 @@ class _cleanup extends \IPS\Task
}
/* Delete any incompleted accounts (for example, someone has clicked "Sign in with Twitter" and never provided a username or email */
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_members', array( array( 'name=? OR email=?', '', '' ), array( 'joined<? AND last_visit=0', \IPS\DateTime::create()->sub( new \DateInterval( 'PT1H' ) )->getTimestamp() ) ) ), 'IPS\Member' ) as $incompleteMember )
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_members', array( array( '(name=? OR email=?)', '', '' ), array( 'joined<? AND last_visit=0 AND ipsconnect_id=0', \IPS\DateTime::create()->sub( new \DateInterval( 'PT1H' ) )->getTimestamp() ) ) ), 'IPS\Member' ) as $incompleteMember )
{
$incompleteMember->delete();
}
@@ -167,11 +182,25 @@ class _cleanup extends \IPS\Task
}
/* Remove widgets */
\IPS\Widget::emptyTrash();
if ( \IPS\Application::appIsEnabled('cms') )
{
\IPS\cms\Widget::emptyTrash();
}
else
{
\IPS\Widget::emptyTrash();
}
/* Reset expired "moderate content till.." timestamps */
\IPS\Db::i()->update( 'core_members', array( 'mod_posts' => 0 ), array( 'mod_posts != -1 and mod_posts <?', time() ) );
/* Set expired announcements inactive */
\IPS\Db::i()->update( 'core_announcements', array( 'announce_active' => 0 ), array( 'announce_active = 1 and announce_end > 0 and announce_end <?', time() ) );
/* Delete old Google Authenticator code uses */
\IPS\Db::i()->delete( 'core_googleauth_used_codes', array( 'time < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'PT1M' ) )->getTimestamp() ) );
return NULL;
}
}
@@ -0,0 +1,70 @@
<?php
/**
* @brief cleanupattachments Task
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @since 08 Dec 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Task that removes attachments that were never claimed
*/
class _cleanupattachments extends \IPS\Task
{
/**
* Execute
*
* If ran successfully, should return anything worth logging. Only log something
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
* Tasks should execute within the time of a normal HTTP request.
*
* @return mixed Message to log or NULL
* @throws \IPS\Task\Exception
*/
public function execute()
{
/* Cleanup - this is deliberately slightly different to the one in \IPS\Text\Parser as it will only delete attachments which have been "saved" (i.e. are not in the middle of being posted) */
foreach ( \IPS\Db::i()->select( '*', 'core_attachments', array( array( 'attach_id NOT IN(?) AND attach_post_key=?', \IPS\Db::i()->select( 'DISTINCT attachment_id', 'core_attachments_map' ), '' ) ) ) as $attachment )
{
try
{
\IPS\Db::i()->delete( 'core_attachments', array( 'attach_id=?', $attachment['attach_id'] ) );
\IPS\File::get( 'core_Attachment', $attachment['attach_location'] )->delete();
if ( $attachment['attach_thumb_location'] )
{
\IPS\File::get( 'core_Attachment', $attachment['attach_thumb_location'] )->delete();
}
}
catch ( \Exception $e ) { }
}
return NULL;
}
/**
* Cleanup
*
* If your task takes longer than 15 minutes to run, this method
* will be called before execute(). Use it to clean up anything which
* may not have been done
*
* @return void
*/
public function cleanup()
{
}
}
+71
View File
@@ -0,0 +1,71 @@
<?php
/**
* @brief cleanupfiles Task
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @since 6 July 2016
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Task that removes files from core_files_temp that were never claimed
*/
class _cleanupfiles extends \IPS\Task
{
/**
* Execute
*
* If ran successfully, should return anything worth logging. Only log something
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
* Tasks should execute within the time of a normal HTTP request.
*
* @return mixed Message to log or NULL
* @throws \IPS\Task\Exception
*/
public function execute()
{
foreach ( \IPS\Db::i()->select( '*', 'core_files_temp', array( 'time < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P1D' ) )->getTimestamp() ) ) as $file )
{
try
{
\IPS\Db::i()->delete( 'core_files_temp', array( '`id`=?', $file['id'] ) );
/* storage_extension was added in 4.1.14. If available, remove the file on disk too */
if ( ! empty( $file['storage_extension'] ) )
{
\IPS\File::get( $file['storage_extension'], $file['contents'] )->delete();
}
}
catch ( \Exception $e ) { }
}
return NULL;
}
/**
* Cleanup
*
* If your task takes longer than 15 minutes to run, this method
* will be called before execute(). Use it to clean up anything which
* may not have been done
*
* @return void
*/
public function cleanup()
{
}
}
+2 -2
View File
@@ -2,9 +2,9 @@
/**
* @brief clearcache Task
* @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 29 May 2015
* @version SVN_VERSION_NUMBER
*/
+2 -2
View File
@@ -2,9 +2,9 @@
/**
* @brief clearsessions Task
* @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 29 May 2015
* @version SVN_VERSION_NUMBER
*/
+6 -6
View File
@@ -2,9 +2,9 @@
/**
* @brief Reattempt queued IPS Connect requests
* @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 3 Dec 2013
* @version SVN_VERSION_NUMBER
*/
@@ -34,7 +34,7 @@ class _connect extends \IPS\Task
/* Get the next request */
try
{
$request = \IPS\Db::i()->select( 'q.*, s.*', array( 'core_ipsconnect_queue', 'q' ), array(), 'q.id asc', array( 0, 1 ) )
$request = \IPS\Db::i()->select( 'q.*, s.*', array( 'core_ipsconnect_queue', 'q' ), array( 's.slave_enabled=?', 1 ), 'q.id asc', array( 0, 1 ) )
->join( array( 'core_ipsconnect_slaves', 's' ), "s.slave_id=q.slave_id" )
->first();
@@ -61,8 +61,8 @@ class _connect extends \IPS\Task
/* If this is a registered slave but the slave is telling us Connect is disabled, remove it */
if( isset( $response['status'] ) AND $response['status'] == 'DISABLED' )
{
\IPS\Db::i()->delete( 'core_ipsconnect_slaves', array( 'slave_id=?', $request['slave_id'] ) );
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => \IPS\Db::i()->select( 'COUNT(*)', 'core_ipsconnect_slaves' )->first() ), array( 'conf_key=?', 'connect_slaves' ) );
\IPS\Db::i()->update( 'core_ipsconnect_slaves', array( 'slave_enabled' => 0 ), array( 'slave_id=?', $request['slave_id'] ) );
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => \IPS\Db::i()->select( 'COUNT(*)', 'core_ipsconnect_slaves', array( 'slave_enabled=?', 1 ) )->first() ), array( 'conf_key=?', 'connect_slaves' ) );
unset( \IPS\Data\Store::i()->settings );
}
@@ -81,7 +81,7 @@ class _connect extends \IPS\Task
catch( \UnderflowException $e )
{
/* There are none left - disable task */
\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => 0 ), "`key`='ipsconnect'" );
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 0 ), "`key`='connect'" );
return NULL;
}
+16 -9
View File
@@ -2,9 +2,9 @@
/**
* @brief digest Task
* @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 08 May 2014
* @version SVN_VERSION_NUMBER
*/
@@ -39,18 +39,25 @@ class _digest extends \IPS\Task
/* Doing daily or weekly this run? */
$frequencies = array( 'daily', 'weekly' );
$frequency = $frequencies[ array_rand( $frequencies ) ];
/* Grab some members to send digests to. */
$members = \IPS\DB::i()->select( 'follow_member_id', 'core_follow', array( 'follow_notify_do=1 AND follow_visible=1 AND follow_notify_freq = ? AND follow_notify_sent < ?', $frequency, ( $frequency == 'daily' ) ? time() - 86400 : time() - 604800 ), 'follow_member_id ASC', array( 0, 50 ), 'follow_member_id' );
/* Grab some members to send digests to. */
$members = \IPS\Db::i()->select( 'follow_member_id, follow_notify_sent', 'core_follow', array( 'follow_notify_do=1 AND follow_visible=1 AND follow_notify_freq = ? AND follow_notify_sent < ?', $frequency, ( $frequency == 'daily' ) ? time() - 86400 : time() - 604800 ), 'follow_notify_sent ASC', array( 0, 50 ), NULL, NULL, \IPS\Db::SELECT_DISTINCT );
if( !count( $members ) )
{
/* Nothing to send */
return NULL;
return NULL;
}
$memberIDs = array();
foreach( $members as $member )
{
$memberIDs[] = $member['follow_member_id'];
}
/* Fetch the member's follows so we can build their digest */
$follows = \IPS\DB::i()->select( '*', 'core_follow', array( 'follow_notify_do=1 AND follow_notify_freq=? AND follow_visible=1 AND follow_notify_sent < ? AND ' . \IPS\Db::i()->in( 'follow_member_id', iterator_to_array( $members ) ), $frequency, time() - 86400 ), 'follow_member_id ASC, follow_app ASC, follow_area ASC' );
$follows = \IPS\Db::i()->select( '*', 'core_follow', array( 'follow_notify_do=1 AND follow_notify_freq=? AND follow_visible=1 AND follow_notify_sent < ? AND ' . \IPS\Db::i()->in( 'follow_member_id', $memberIDs ), $frequency, time() - 86400 ), 'follow_notify_sent ASC, follow_app ASC, follow_area ASC' );
$groupedFollows = array();
foreach( $follows as $follow )
{
+84
View File
@@ -0,0 +1,84 @@
<?php
/**
* @brief Group Promotion Task
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @since 16 Sep 2016
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Task to promote users based on group promotion settings
*/
class _grouppromote extends \IPS\Task
{
/**
* Execute
*
* If ran successfully, should return anything worth logging. Only log something
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
* Tasks should execute within the time of a normal HTTP request.
*
* @return mixed Message to log or NULL
* @throws \IPS\Task\Exception
*/
public function execute()
{
/* Retrieve all groups but exclude guest group as these cannot auto promote */
foreach ( \IPS\Member\Group::groups( TRUE, FALSE ) as $group)
{
if ( $group->g_promotion != '-1&-1' )
{
list( $gid, $gUnit ) = explode( '&', $group->g_promotion );
if ( $gid > 0 and $gUnit > 0 )
{
/* Is this post, date or reputation based promotion? */
if ( $group->g_promotion_type == 1 )
{
/* Update query for members by date */
$upgradeThresholdTimestamp = time() - ( $gUnit * 86400 );
\IPS\Db::i()->update( "core_members", array( 'member_group_id' => $gid ), array( "joined <= ? AND member_group_id = ?", $upgradeThresholdTimestamp, $group->g_id ) );
}
elseif ( $group->g_promotion_type == 2 )
{
/* Update query for members by reputation */
\IPS\Db::i()->update( "core_members", array( 'member_group_id' => $gid ), array( "pp_reputation_points >= ? AND member_group_id = ?", $gUnit, $group->g_id ) );
}
else
{
/* Update query for members by content count */
\IPS\Db::i()->update( "core_members", array( 'member_group_id' => $gid ), array( "member_posts >= ? AND member_group_id = ?", $gUnit, $group->g_id ) );
}
}
}
}
return NULL;
}
/**
* Cleanup
*
* If your task takes longer than 15 minutes to run, this method
* will be called before execute(). Use it to clean up anything which
* may not have been done
*
* @return void
*/
public function cleanup()
{
}
}
+81
View File
@@ -0,0 +1,81 @@
<?php
/**
* @brief imageproxy Task
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @since 20 Nov 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* imageproxy Task
*/
class _imageproxy extends \IPS\Task
{
/**
* Execute
*
* If ran successfully, should return anything worth logging. Only log something
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
* Tasks should execute within the time of a normal HTTP request.
*
* @return mixed Message to log or NULL
* @throws \IPS\Task\Exception
*/
public function execute()
{
if ( !\IPS\Settings::i()->remote_image_proxy or !\IPS\Settings::i()->image_proxy_cache_period )
{
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 0 ), array( '`key`=?', 'imageproxy' ) );
return NULL;
}
$this->runUntilTimeout(function()
{
$select = \IPS\Db::i()->select( 'location', 'core_image_proxy', array( 'cache_time<?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->image_proxy_cache_period . 'D' ) )->getTimestamp() ), 'cache_time ASC', 10 );
if ( !$select->count() )
{
return FALSE;
}
foreach ( $select as $location )
{
try
{
\IPS\File::get( 'core_Imageproxycache', $location )->delete();
}
catch ( \Exception $e ) { }
\IPS\Db::i()->delete( 'core_image_proxy', array( 'location=?', $location ) );
}
return TRUE;
});
}
/**
* Cleanup
*
* If your task takes longer than 15 minutes to run, this method
* will be called before execute(). Use it to clean up anything which
* may not have been done
*
* @return void
*/
public function cleanup()
{
}
}
+113
View File
@@ -0,0 +1,113 @@
<?php
/**
* @brief leaderboard Task
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @since 02 Nov 2016
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* leaderboard Task
*/
class _leaderboard extends \IPS\Task
{
/**
* Execute
*
* If ran successfully, should return anything worth logging. Only log something
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
* Tasks should execute within the time of a normal HTTP request.
*
* @return mixed Message to log or NULL
* @throws \IPS\Task\Exception
*/
public function execute()
{
/* Get the most recent update */
$date = \IPS\Db::i()->select( 'MAX(leader_date)', 'core_reputation_leaderboard_history' )->first();
$timezone = new \DateTimeZone( \IPS\Settings::i()->reputation_timezone );
if ( $date )
{
/* Only go back 10 days max */
if ( $date < ( time() - 864000 ) )
{
$startDate = \IPS\DateTime::ts( time(), true )->setTimezone( $timezone )->sub( new \DateInterval('P10D') )->setTime( 0, 0, 1 );
}
else
{
$startDate = \IPS\DateTime::ts( $date, true )->setTimezone( $timezone )->setTime( 0, 0, 1 );
}
}
else
{
$startDate = new \IPS\DateTime( 'yesterday midnight', $timezone );
}
$yesterdayEnd = new \IPS\DateTime( 'today midnight', $timezone );
$diff = $startDate->diff( $yesterdayEnd );
$difference = $diff->days > 0 ? $diff->days + 1 : 1;
/* Get top rated contributors */
for( $i = 0; $i < $difference; $i++ )
{
$position = 0;
foreach( \IPS\Db::i()->select( 'core_reputation_index.member_received as member, SUM(rep_rating) as rep', 'core_reputation_index', array( 'member_received > 0 AND rep_date BETWEEN ? and ?', $startDate->getTimeStamp(), $yesterdayEnd->getTimeStamp() ), 'rep DESC', 4, 'member' )->setKeyField('member')->setValueField('rep') as $member => $rep )
{
if ( $member and $rep )
{
\IPS\Db::i()->replace( 'core_reputation_leaderboard_history', array(
'leader_date' => $startDate->setTime( 12, 0 )->getTimeStamp(),
'leader_member_id' => $member,
'leader_position' => ++$position,
'leader_rep_total' => $rep
) );
}
}
/* Fill in the blanks */
if ( $position and $position < 5 )
{
while( $position < 4 )
{
\IPS\Db::i()->replace( 'core_reputation_leaderboard_history', array(
'leader_date' => $startDate->setTime( 12, 0 )->getTimeStamp() - $position,
'leader_member_id' => 0,
'leader_position' => ++$position,
'leader_rep_total' => 0
) );
}
}
$startDate = $startDate->add( new \DateInterval('P1D') )->setTime( 0, 0, 1 );
}
}
/**
* Cleanup
*
* If your task takes longer than 15 minutes to run, this method
* will be called before execute(). Use it to clean up anything which
* may not have been done
*
* @return void
*/
public function cleanup()
{
}
}
+23 -46
View File
@@ -2,9 +2,9 @@
/**
* @brief POP3 Task
* @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 16 Apr 2014
* @version SVN_VERSION_NUMBER
*/
@@ -22,7 +22,7 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
* POP3 Task
*/
class _pop extends \IPS\Task
{
{
/**
* Execute
*
@@ -44,61 +44,38 @@ class _pop extends \IPS\Task
return;
}
/* Or do it */
require_once \IPS\ROOT_PATH . '/system/3rd_party/pop3/pop3.class.inc';
$pop3 = new \POP3;
/* Do it */
try
{
/* Connect */
if ( !$pop3->connect( ( \IPS\Settings::i()->pop3_tls ? 'ssl://' : '' ) . \IPS\Settings::i()->pop3_server, \IPS\Settings::i()->pop3_port ) )
{
throw new \IPS\Task\Exception( $this, 'pop3_cant_connect' );
}
$pop3 = new \IPS\Email\Incoming\PopImap( \IPS\Settings::i()->pop3_server, \IPS\Settings::i()->pop3_tls, \IPS\Settings::i()->pop3_port, \IPS\Settings::i()->pop3_user, \IPS\Settings::i()->pop3_password );
/* Login */
if ( !$pop3->login( \IPS\Settings::i()->pop3_user, \IPS\Settings::i()->pop3_password ) )
{
throw new \IPS\Task\Exception( $this, 'pop3_cant_login' );
}
/* Got any? */
$status = @$pop3->get_office_status();
if ( $status['count_mails'] )
{
foreach ( range( 1, $status['count_mails'] ) as $i )
{
if( $pop3->_putline( "RETR $i" ) )
/* Fetch emails */
if ( $emailsInInbox = $pop3->emailsInInbox() )
{
foreach ( range( 1, min( $emailsInInbox, 50 ) ) as $i )
{
try
{
if ( mb_substr( @$pop3->_getnextstring(), 0, 3 ) == "+OK" )
{
$message = '';
while ( TRUE )
{
$line = @$pop3->_getnextstring();
if ( preg_match( "/^\.\r\n/", $line ) )
{
break;
}
$message .= $line;
}
\IPS\Email\Incoming::i( $message )->route();
$pop3->delete_mail( $i );
}
$incomingEmail = new \IPS\Email\Incoming\Email( $pop3->getEmail( $i ) );
$incomingEmail->route();
$pop3->deleteEmail( $i );
}
catch ( \IPS\Email\Incoming\PopImapException $e )
{
\IPS\Log::log( $e, 'pop3' );
}
}
}
/* Close Connection */
$pop3->close();
/* Disconnect */
unset( $pop3 );
}
catch ( \Exception $exception )
{
\IPS\Log::i( \LOG_CRIT )->write( get_class( $exception ) . "\n" . $exception->getCode() . ": " . $exception->getMessage() . "\n" . $exception->getTraceAsString() );
\IPS\Log::log( $exception, 'pop3' );
throw new \IPS\Task\Exception( $this, $exception->getMessage() );
}
}
}
/**
+8 -3
View File
@@ -2,9 +2,9 @@
/**
* @brief Profile-sync Task
* @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 21 Jun 2013
* @version SVN_VERSION_NUMBER
*/
@@ -33,7 +33,12 @@ class _profilesync extends \IPS\Task
$services = \IPS\core\ProfileSync\ProfileSyncAbstract::services();
if ( !empty( $services ) )
{
foreach ( \IPS\Db::i()->select( '*', 'core_members', 'profilesync IS NOT NULL', 'profilesync_lastsync ASC', 25 ) as $row )
$where = array( 'profilesync IS NOT NULL' );
/* Exclude banned users */
$where[] = array( 'temp_ban=?', 0 );
foreach ( \IPS\Db::i()->select( '*', 'core_members', $where, 'profilesync_lastsync ASC', 25 ) as $row )
{
foreach ( $services as $class )
{
+2 -2
View File
@@ -2,9 +2,9 @@
/**
* @brief publish Task
* @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 07 Oct 2014
* @version SVN_VERSION_NUMBER
*/
+10 -109
View File
@@ -2,9 +2,9 @@
/**
* @brief Queue Task
* @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 04 Dec 2013
* @version SVN_VERSION_NUMBER
*/
@@ -36,123 +36,24 @@ class _queue extends \IPS\Task
*/
public function execute()
{
/* Work out the maximum execution time */
$timeLeft = 45;
if ( $phpMaxExecutionTime = ini_get('max_execution_time') and $phpMaxExecutionTime <= $timeLeft )
{
$timeLeft = $phpMaxExecutionTime - 2;
}
/* Factor in wait_timeout if possible */
try
{
$mysqlTimeout = \IPS\Db::i()->query( "SHOW SESSION VARIABLES LIKE 'wait_timeout'" )->fetch_assoc();
$mysqlTimeout = $mysqlTimeout['Value'];
if( $mysqlTimeout <= $timeLeft )
{
$timeLeft = $mysqlTimeout - 2;
}
}
catch( \IPS\Db\Exception $e ){}
$timeTheLastRunTook = 0;
/* Work out the memory limit */
$memoryLeft = 0;
$memoryUnlimited = FALSE;
if ( function_exists( 'memory_get_usage' ) )
{
$memory_limit = ini_get('memory_limit');
if ( $memory_limit == -1 )
{
$memoryUnlimited = TRUE;
}
else
{
if ( preg_match('/^(\d+)(.)$/', $memory_limit, $matches ) )
{
if ( $matches[2] == 'M' )
{
$memory_limit = $matches[1] * 1024 * 1024;
}
elseif ( $matches[2] == 'K' )
{
$memory_limit = $matches[1] * 1024;
}
}
$memoryLeft = $memory_limit - memory_get_usage( TRUE );
}
}
$memoryTheLastRunTook = 0;
/* Run until we run out of time */
do
{
$this->runUntilTimeout( function(){
/* Try and get a queue item */
try
{
/* Get it */
$queueData = \IPS\Db::i()->select( '*', 'core_queue', NULL, 'priority ASC, RAND()', 1 )->first();
/* Start a timer */
$timer = microtime( TRUE );
$memoryTimer = function_exists( 'memory_get_usage' ) ? memory_get_usage( TRUE ) : 0;
/* Got one, try to run it */
try
{
$extensions = \IPS\Application::load( $queueData['app'] )->extensions( 'core', 'Queue', FALSE );
if ( !isset( $extensions[ $queueData['key'] ] ) )
{
throw new \OutOfRangeException;
}
$class = new $extensions[ $queueData['key'] ];
$data = json_decode( $queueData['data'], TRUE );
$newOffset = $class->run( $data, $queueData['offset'] );
if ( is_null( $newOffset ) )
{
\IPS\Db::i()->delete( 'core_queue', array( 'id=?', $queueData['id'] ) );
}
else
{
\IPS\Db::i()->update( 'core_queue', array( 'offset' => $newOffset ), array( 'id=?', $queueData['id'] ) );
$newData = json_encode( $data );
/* Did it change?? */
if ( $newData !== $data )
{
\IPS\Db::i()->update( 'core_queue', array( 'data' => $newData ), array( 'id=?', $queueData['id'] ) );
}
}
}
/* An error in running - delete it */
catch ( \OutOfRangeException $e )
{
\IPS\Db::i()->delete( 'core_queue', array( 'id=?', $queueData['id'] ) );
}
/* Decrease the time left */
$timeTheLastRunTook = round( ( microtime( TRUE ) - $timer ), 2 );
$timeLeft -= $timeTheLastRunTook;
$memoryTheLastRunTook = function_exists( 'memory_get_usage' ) ? ( memory_get_usage( TRUE ) - $memoryTimer ) : 0;
if ( !$memoryUnlimited )
{
$memoryLeft = $memory_limit - memory_get_usage( TRUE );;
}
/* Run the next queue task, if any */
\IPS\Task::runQueue();
/* Continue */
return TRUE;
}
/* If there's no queue items left, disable this task and return */
catch ( \UnderflowException $e )
{
$this->enabled = FALSE;
$this->save();
return;
return FALSE;
}
}
while ( $timeLeft > $timeTheLastRunTook and ( $memoryUnlimited or $memoryLeft > $memoryTheLastRunTook ) );
});
}
/**
+2 -2
View File
@@ -2,9 +2,9 @@
/**
* @brief Task to generate sitemaps
* @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 30 Aug 2013
* @version SVN_VERSION_NUMBER
*/
+85
View File
@@ -0,0 +1,85 @@
<?php
/**
* @brief Unlock Members Task
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @since 29 Sep 2016
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Unlock Members Task
*/
class _unlockmembers extends \IPS\Task
{
/**
* Execute
*
* If ran successfully, should return anything worth logging. Only log something
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
* Tasks should execute within the time of a normal HTTP request.
*
* @return mixed Message to log or NULL
* @throws \IPS\Task\Exception
*/
public function execute()
{
if( !\IPS\Settings::i()->ipb_bruteforce_unlock or !\IPS\Settings::i()->ipb_bruteforce_period or !\IPS\Settings::i()->ipb_bruteforce_attempts )
{
return NULL;
}
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_members', array( 'failed_login_count >= ?', \IPS\Settings::i()->ipb_bruteforce_attempts ) ), 'IPS\Member') AS $member )
{
$failedLogins = $member->failed_logins;
if ( is_array( $failedLogins ) )
{
foreach ( $failedLogins as $ipAddress => $times )
{
foreach ( $times as $k => $v )
{
if ( $v < \IPS\DateTime::create()->sub( new \DateInterval( 'PT' . \IPS\Settings::i()->ipb_bruteforce_period . 'M' ) )->getTimestamp() )
{
unset( $failedLogins[ $ipAddress ][ $k ] );
}
}
}
$member->failed_logins = $failedLogins;
}
else
{
$member->failed_logins = array();
}
$member->save();
}
return NULL;
}
/**
* Cleanup
*
* If your task takes longer than 15 minutes to run, this method
* will be called before execute(). Use it to clean up anything which
* may not have been done
*
* @return void
*/
public function cleanup()
{
}
}
+13 -5
View File
@@ -2,9 +2,9 @@
/**
* @brief updatecheck Task
* @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 14 Aug 2013
* @version SVN_VERSION_NUMBER
*/
@@ -54,7 +54,7 @@ class _updatecheck extends \IPS\Task
$currentDetails = json_decode( $coreApp->update_version, TRUE );
if ( $currentDetails['version'] != $response['version'] and \IPS\Settings::i()->upgrade_email )
{
\IPS\Email::buildFromTemplate( 'core', 'upgrade', array( $response['version'], $response['releasenotes'], $response['security'] ) )->send( explode( ',', \IPS\Settings::i()->upgrade_email ) );
\IPS\Email::buildFromTemplate( 'core', 'upgrade', array( $response['version'], $response['releasenotes'], $response['security'] ), \IPS\Email::TYPE_LIST )->send( explode( ',', \IPS\Settings::i()->upgrade_email ) );
}
$coreApp->update_version = json_encode( $response );
$coreApp->update_last_check = time();
@@ -114,9 +114,17 @@ class _updatecheck extends \IPS\Task
try
{
$url = \IPS\Http\Url::external( $row['url'] )->setQueryString( 'version', $row['current'] );
/* Query the applications update URL */
$url = \IPS\Http\Url::external( $row['url'] )->setQueryString( array( 'version' => $row['current'], 'ips_version' => $version ) );
$response = $url->request()->get()->decodeJson();
/* Did we get all the information we need? */
if ( !isset( $response['version'], $response['longversion'], $response['released'], $response['updateurl'] ) )
{
throw new \RuntimeException( \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->get( 'update_check_missing' ) );
}
/* Save the latest version data and move on to the next app */
\IPS\Db::i()->update( $row['table'], array(
$dataColumn => json_encode( array(
'version' => $response['version'],
@@ -128,7 +136,7 @@ class _updatecheck extends \IPS\Task
$timeColumn => time()
), array( "{$idColumn}=?", $row['id'] ) );
}
/* \RuntimeException catches BAD_JSON and \IPS\Http\Request\Exception both */
/* \RuntimeException catches BAD_JSON and \IPS\Http\Request\Exception both */
catch ( \RuntimeException $e )
{
$fails[] = $source . ": " . $e->getMessage();
+99
View File
@@ -0,0 +1,99 @@
<?php
/**
* @brief view_updates Task
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @since 12 Nov 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* view_updates Task
*/
class _viewupdates extends \IPS\Task
{
/**
* Execute
*
* If ran successfully, should return anything worth logging. Only log something
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
* Tasks should execute within the time of a normal HTTP request.
*
* @return mixed Message to log or NULL
* @throws \IPS\Task\Exception
*/
public function execute()
{
$this->runUntilTimeout(function(){
try
{
$result = \IPS\Db::i()->select( 'classname, id, COUNT(*) AS count', 'core_view_updates', NULL, NULL, 20, array( 'classname', 'id' ) );
/* If there's no more, break the loop and stop */
if( !count( $result ) )
{
return FALSE;
}
foreach( $result as $row )
{
$class = $row['classname'];
if ( class_exists( $class ) and in_array( 'IPS\Content\Views', class_implements( $class ) ) AND isset( $class::$databaseColumnMap['views'] ) )
{
try
{
\IPS\Db::i()->update(
$class::$databaseTable,
"`{$class::$databasePrefix}{$class::$databaseColumnMap['views']}`=`{$class::$databasePrefix}{$class::$databaseColumnMap['views']}`+{$row['count']}",
array( "{$class::$databasePrefix}{$class::$databaseColumnId}=?", $row['id'] )
);
}
catch( \IPS\Db\Exception $e )
{
/* Table to update no longer exists */
if( $e->getCode() == 1146 )
{
\IPS\Db::i()->delete( 'core_view_updates', array( 'classname=?', $row['classname'] ) );
}
}
}
\IPS\Db::i()->delete( 'core_view_updates', array( 'classname=? AND id=?', $row['classname'], $row['id'] ) );
}
/* If we're here we just ran some, so we can return true to see if there are any more to run */
return TRUE;
}
catch ( \UnderflowException $e )
{
return FALSE;
}
});
}
/**
* Cleanup
*
* If your task takes longer than 15 minutes to run, this method
* will be called before execute(). Use it to clean up anything which
* may not have been done
*
* @return void
*/
public function cleanup()
{
}
}