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

@@ -12,16 +12,25 @@
namespace IPS\downloads\extensions\core\Queue;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\downloads\Category;
use IPS\downloads\File;
use IPS\Extensions\QueueAbstract;
use IPS\Member;
use IPS\Theme;
use OutOfRangeException;
use function defined;
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;
}
/**
* Background Task
*/
class _Follow
class Follow extends QueueAbstract
{
/**
* Run Background Task
@@ -31,11 +40,11 @@ class _Follow
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( $data, $offset )
public function run( array &$data, int $offset ): int
{
$category = \IPS\downloads\Category::load( $data['category_id'] );
$member = \IPS\Member::load( $data['member_id'] );
$newOffset = \IPS\downloads\File::_sendNotificationsBatch( $category, $member, $offset );
$category = Category::load( $data['category_id'] );
$member = Member::load( $data['member_id'] );
$newOffset = File::_sendNotificationsBatch( $category, $member, $offset );
if( $newOffset === NULL )
{
@@ -51,13 +60,24 @@ class _Follow
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaining task and percentage complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
* @throws OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function getProgress( $data, $offset )
public function getProgress( mixed $data, int $offset ): array
{
$category = \IPS\downloads\Category::load( $data['category_id'] );
$category = Category::load( $data['category_id'] );
$complete = $data['followerCount'] ? round( 100 / $data['followerCount'] * $offset, 2 ) : 100;
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('backgroundQueue_follow', FALSE, array( 'htmlsprintf' => array( \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->basicUrl( $category->url(), TRUE, $category->_title, FALSE ) ) ) ), 'complete' => $complete );
}
return array( 'text' => Member::loggedIn()->language()->addToStack('backgroundQueue_follow', FALSE, array( 'htmlsprintf' => array( Theme::i()->getTemplate( 'global', 'core', 'global' )->basicUrl( $category->url(), TRUE, $category->_title, FALSE ) ) ) ), 'complete' => $complete );
}
/**
* Parse data before queuing
*
* @param array $data
* @return array|null
*/
public function preQueueData( array $data ): ?array
{
return $data;
}
}
@@ -12,24 +12,37 @@
namespace IPS\downloads\extensions\core\Queue;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Application;
use IPS\Content;
use IPS\Db;
use IPS\downloads\File;
use IPS\Extensions\QueueAbstract;
use IPS\Member;
use IPS\Notification;
use IPS\Task\Queue\OutOfRangeException;
use IPS\Theme;
use function count;
use function defined;
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;
}
/**
* Background Task
*/
class _Notify
class Notify extends QueueAbstract
{
/**
* Parse data before queuing
*
* @param array $data
* @return array
* @return array|null
*/
public function preQueueData( $data )
public function preQueueData( array $data ): ?array
{
return $data;
}
@@ -40,33 +53,33 @@ class _Notify
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
* @throws OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( $data, $offset )
public function run( array &$data, int $offset ): int
{
try
{
$file = \IPS\downloads\File::load( $data['file'] );
$file = File::load( $data['file'] );
}
catch( \OutOfRangeException $e )
{
throw new \IPS\Task\Queue\OutOfRangeException;
throw new OutOfRangeException;
}
$notifyIds = array();
$recipients = iterator_to_array( \IPS\Db::i()->select( 'downloads_files_notify.*', 'downloads_files_notify', array( 'notify_file_id=?', $data['file'] ), 'notify_id ASC', array( $offset, \IPS\Downloads\File::NOTIFICATIONS_PER_BATCH ) ) );
$recipients = iterator_to_array( Db::i()->select( 'downloads_files_notify.*', 'downloads_files_notify', array( 'notify_file_id=?', $data['file'] ), 'notify_id ASC', array( $offset, Content::NOTIFICATIONS_PER_BATCH ) ) );
if( !\count( $recipients ) )
if( !count( $recipients ) )
{
throw new \IPS\Task\Queue\OutOfRangeException;
throw new OutOfRangeException;
}
$notification = new \IPS\Notification( \IPS\Application::load( 'downloads' ), 'new_file_version', $file, array( $file ) );
$notification = new Notification( Application::load( 'downloads' ), 'new_file_version', $file, array( $file ) );
foreach( $recipients AS $recipient )
{
$recipientMember = \IPS\Member::load( $recipient['notify_member_id'] );
$recipientMember = Member::load( $recipient['notify_member_id'] );
if ( $file->container()->can( 'view', $recipientMember ) )
{
$notifyIds[] = $recipient['notify_id'];
@@ -74,10 +87,10 @@ class _Notify
}
}
\IPS\Db::i()->update( 'downloads_files_notify', array( 'notify_sent' => time() ), \IPS\Db::i()->in( 'notify_id', $notifyIds ) );
Db::i()->update( 'downloads_files_notify', array( 'notify_sent' => time() ), Db::i()->in( 'notify_id', $notifyIds ) );
$notification->send();
return $offset + \IPS\downloads\File::NOTIFICATIONS_PER_BATCH;
return $offset + Content::NOTIFICATIONS_PER_BATCH;
}
/**
@@ -88,19 +101,19 @@ class _Notify
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaining task and percentage complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function getProgress( $data, $offset )
public function getProgress( mixed $data, int $offset ): array
{
try
{
$file = \IPS\downloads\File::load( $data['file'] );
$file = File::load( $data['file'] );
}
catch( \OutOfRangeException $e )
{
throw new \IPS\Task\Queue\OutOfRangeException;
throw new OutOfRangeException;
}
$complete = $data['notifyCount'] ? round( 100 / $data['notifyCount'] * $offset, 2 ) : 100;
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('backgroundQueue_new_version', FALSE, array( 'htmlsprintf' => array( \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->basicUrl( $file->url(), TRUE, $file->name, FALSE ) ) ) ), 'complete' => $complete );
return array( 'text' => Member::loggedIn()->language()->addToStack('backgroundQueue_new_version', FALSE, array( 'htmlsprintf' => array( Theme::i()->getTemplate( 'global', 'core', 'global' )->basicUrl( $file->url(), TRUE, $file->name, FALSE ) ) ) ), 'complete' => $complete );
}
}
@@ -12,43 +12,55 @@
namespace IPS\downloads\extensions\core\Queue;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use Exception;
use IPS\Db;
use IPS\Extensions\QueueAbstract;
use IPS\File;
use IPS\Image;
use IPS\Member;
use IPS\Settings;
use OutOfRangeException;
use function defined;
use const IPS\REBUILD_INTENSE;
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;
}
/**
* Background Task
*/
class _RebuildScreenshotWatermarks
class RebuildScreenshotWatermarks extends QueueAbstract
{
/**
* @brief Number of items to rebuild per cycle
*/
public $rebuild = \IPS\REBUILD_INTENSE;
public int $rebuild = REBUILD_INTENSE;
/**
* Parse data before queuing
*
* @param array $data
* @return array
* @return array|null
*/
public function preQueueData( $data )
public function preQueueData( array $data ): ?array
{
try
{
$watermark = \IPS\Settings::i()->idm_watermarkpath ? \IPS\File::get( 'core_Theme', \IPS\Settings::i()->idm_watermarkpath )->contents() : NULL;
$watermark = Settings::i()->idm_watermarkpath ? File::get( 'core_Theme', Settings::i()->idm_watermarkpath )->contents() : NULL;
$where = array( array( 'record_type=?', 'ssupload' ) );
if ( !$watermark )
{
$where[] = array( 'record_no_watermark<>?', '' );
}
$data['count'] = \IPS\Db::i()->select( 'MAX(record_id)', 'downloads_files_records', $where )->first();
$data['realCount'] = \IPS\Db::i()->select( 'COUNT(*)', 'downloads_files_records', $where )->first();
$data['count'] = Db::i()->select( 'MAX(record_id)', 'downloads_files_records', $where )->first();
$data['realCount'] = Db::i()->select( 'COUNT(*)', 'downloads_files_records', $where )->first();
}
catch( \Exception $ex )
catch( Exception $ex )
{
return NULL;
}
@@ -71,10 +83,10 @@ class _RebuildScreenshotWatermarks
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( &$data, $offset )
public function run( mixed &$data, int $offset ): int
{
$last = NULL;
$watermark = \IPS\Settings::i()->idm_watermarkpath ? \IPS\Image::create( \IPS\File::get( 'core_Theme', \IPS\Settings::i()->idm_watermarkpath )->contents() ) : NULL;
$watermark = Settings::i()->idm_watermarkpath ? Image::create( File::get( 'core_Theme', Settings::i()->idm_watermarkpath )->contents() ) : NULL;
$where = array( array( 'record_id>? AND record_type=?', $offset, 'ssupload' ) );
if ( !$watermark )
@@ -82,7 +94,7 @@ class _RebuildScreenshotWatermarks
$where[] = array( 'record_no_watermark<>?', '' );
}
$select = \IPS\Db::i()->select( '*', 'downloads_files_records', $where, 'record_id', array( 0, $this->rebuild ) );
$select = Db::i()->select( '*', 'downloads_files_records', $where, 'record_id', array( 0, $this->rebuild ) );
foreach ( $select as $row )
{
@@ -90,18 +102,18 @@ class _RebuildScreenshotWatermarks
{
if ( $row['record_no_watermark'] )
{
$original = \IPS\File::get( 'downloads_Screenshots', $row['record_no_watermark'] );
$original = File::get( 'downloads_Screenshots', $row['record_no_watermark'] );
try
{
\IPS\File::get( 'downloads_Screenshots', $row['record_location'] )->delete();
\IPS\File::get( 'downloads_Screenshots', $row['record_thumb'] )->delete();
File::get( 'downloads_Screenshots', $row['record_location'] )->delete();
File::get( 'downloads_Screenshots', $row['record_thumb'] )->delete();
}
catch ( \Exception $e ) { }
catch ( Exception $e ) { }
if ( !$watermark )
{
\IPS\Db::i()->update( 'downloads_files_records', array(
Db::i()->update( 'downloads_files_records', array(
'record_location' => (string) $original,
'record_thumb' => (string) $original->thumbnail( 'downloads_Screenshots' ),
'record_no_watermark' => NULL
@@ -115,21 +127,21 @@ class _RebuildScreenshotWatermarks
}
else
{
$original = \IPS\File::get( 'downloads_Screenshots', $row['record_location'] );
$original = File::get( 'downloads_Screenshots', $row['record_location'] );
}
$image = \IPS\Image::create( $original->contents() );
$image = Image::create( $original->contents() );
$image->watermark( $watermark );
$newFile = \IPS\File::create( 'downloads_Screenshots', $original->originalFilename, $image );
$newFile = File::create( 'downloads_Screenshots', $original->originalFilename, $image );
\IPS\Db::i()->update( 'downloads_files_records', array(
Db::i()->update( 'downloads_files_records', array(
'record_location' => (string) $newFile,
'record_thumb' => (string) $newFile->thumbnail( 'downloads_Screenshots' ),
'record_no_watermark' => (string) $original
), array( 'record_id=?', $row['record_id'] ) );
}
catch ( \Exception $e ) { }
catch ( Exception $e ) { }
$data['indexed']++;
$last = $row['record_id'];
@@ -149,10 +161,10 @@ class _RebuildScreenshotWatermarks
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaining task and percentage complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
* @throws OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function getProgress( $data, $offset )
public function getProgress( mixed $data, int $offset ): array
{
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('downloads_rebuilding_screenshots'), 'complete' => ( $data['realCount'] * $data['indexed'] ) > 0 ? round( ( $data['realCount'] * $data['indexed'] ) * 100, 2 ) : 0 );
return array( 'text' => Member::loggedIn()->language()->addToStack('downloads_rebuilding_screenshots'), 'complete' => ( $data['realCount'] * $data['indexed'] ) > 0 ? round( ( $data['realCount'] * $data['indexed'] ) * 100, 2 ) : 0 );
}
}
@@ -0,0 +1,107 @@
<?php
/**
* @brief Background Task
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Downloads
* @since 08 Jul 2024
*/
namespace IPS\downloads\extensions\core\Queue;
use IPS\Db;
use IPS\Extensions\QueueAbstract;
use IPS\Member;
use IPS\Task\Queue\OutOfRangeException as QueueOutOfRangeException;
use OutOfRangeException;
use function defined;
use const IPS\REBUILD_NORMAL;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Background Task
*/
class StoreMemberViews extends QueueAbstract
{
/**
* Parse data before queuing
*
* @param array $data
* @return array|null
*/
public function preQueueData( array $data ): ?array
{
$data['count'] = (int) Db::i()->select( 'count(*)', 'downloads_view_method' )->first();
return $data;
}
/**
* Run Background Task
*
* @param array $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int New offset
* @throws QueueOutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( array &$data, int $offset ): int
{
$rows = iterator_to_array(
Db::i()->select( '*', 'downloads_view_method', null, 'member_id', [ $offset, REBUILD_NORMAL] )
);
if( !count( $rows ) )
{
throw new QueueOutOfRangeException;
}
foreach( $rows as $row )
{
Member::load( $row['member_id'] )->setLayoutValue( 'downloads_categories', $row['method'] );
}
$offset += REBUILD_NORMAL;
if( $offset >= $data['count'] )
{
throw new QueueOutOfRangeException;
}
return $offset;
}
/**
* Get Progress
*
* @param array $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaining task and percentage complete
* @throws OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function getProgress( array $data, int $offset ): array
{
return array(
'text' => Member::loggedIn()->language()->addToStack( 'downloads_updating_views' ),
'complete' => ( $offset ? round( 100 / $data['count'] * $offset, 2 ) : 0 )
);
}
/**
* Perform post-completion processing
*
* @param array $data Data returned from preQueueData
* @param bool $processed Was anything processed or not? If preQueueData returns NULL, this will be FALSE.
* @return void
*/
public function postComplete( array $data, bool $processed = TRUE ) : void
{
Db::i()->dropTable( 'downloads_view_method' );
}
}