Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+308 -19
View File
@@ -11,7 +11,7 @@
namespace IPS\core\modules\front\system;
/* 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;
@@ -31,19 +31,19 @@ class _ajax extends \IPS\Dispatcher\Controller
{
$results = array();
$input = mb_strtolower( \IPS\Request::i()->input );
$input = str_replace( array( '%', '_' ), array( '\%', '\_' ), mb_strtolower( \IPS\Request::i()->input ) );
$where = array( "name LIKE CONCAT('%', ?, '%')" );
$where = array( "name LIKE CONCAT(?, '%')" );
$binds = array( $input );
if ( \IPS\Dispatcher::i()->controllerLocation === 'admin' )
{
$where[] = "email LIKE CONCAT('%', ?, '%')";
$where[] = "email LIKE CONCAT(?, '%')";
$binds[] = $input;
if ( is_numeric( \IPS\Request::i()->input ) )
if ( \is_numeric( \IPS\Request::i()->input ) )
{
$where[] = "member_id=?";
$binds[] = intval( \IPS\Request::i()->input );
$binds[] = \intval( \IPS\Request::i()->input );
}
}
@@ -64,6 +64,138 @@ class _ajax extends \IPS\Dispatcher\Controller
\IPS\Output::i()->json( $results );
}
/**
* Returns size and download count of an array of attachments
*
* @return void
*/
public function attachmentInfo()
{
$toReturn = array();
$member = \IPS\Member::loggedIn();
$loadedExtensions = array();
/* As you can insert "other media" from other apps (such as Downloads), we need to route the attachIDs appropriately. */
$attachmentIds = array();
foreach( array_keys( \IPS\Request::i()->attachIDs ) as $attachId )
{
if( (int) $attachId == $attachId AND mb_strlen( (int) $attachId ) == mb_strlen( $attachId ) )
{
$attachmentIds[] = $attachId;
}
else
{
try
{
$url = \IPS\Http\Url::createFromString( $attachId );
/* Get the "real" query string (whatever the query string is, plus what we can get from decoding the FURL) */
$qs = array_merge( $url->queryString, $url->hiddenQueryString );
/* We need an app, and it needs to not be an RSS link */
if ( !isset( $qs['app'] ) )
{
throw new \UnexpectedValueException;
}
/* Load the application */
$application = \IPS\Application::load( $qs['app'] );
/* Loop through our content classes and see if we can find one that matches */
foreach ( $application->extensions( 'core', 'ContentRouter' ) as $key => $extension )
{
$classes = $extension->classes;
/* So for each of those... */
foreach ( $classes as $class )
{
/* Try to load it */
try
{
$item = $class::loadFromURL( $url );
if( !$item->canView() )
{
throw new \OutOfRangeException;
}
/* If we're still here, we should be good. Any exceptions will have been caught by our general try/catch. */
$toReturn[ $attachId ] = $item->getAttachmentInfo();
break;
}
catch( \OutOfRangeException $e ){}
}
}
}
catch( \Exception $e ){}
}
}
/* Get attachments */
if( \count( $attachmentIds ) )
{
$attachments = \IPS\Db::i()->select( '*', 'core_attachments', array( \IPS\Db::i()->in( 'attach_id', $attachmentIds ) ) );
foreach( $attachments as $attachment )
{
$permission = FALSE;
if( $member->member_id )
{
if ( $member->member_id == $attachment['attach_member_id'] )
{
$permission = TRUE;
}
}
if( $permission !== TRUE )
{
foreach ( \IPS\Db::i()->select( '*', 'core_attachments_map', array( 'attachment_id=?', $attachment['attach_id'] ) ) as $map )
{
if ( !isset( $loadedExtensions[ $map['location_key'] ] ) )
{
$exploded = explode( '_', $map['location_key'] );
try
{
$extensions = \IPS\Application::load( $exploded[0] )->extensions( 'core', 'EditorLocations' );
if ( isset( $extensions[ $exploded[1] ] ) )
{
$loadedExtensions[ $map['location_key'] ] = $extensions[ $exploded[1] ];
}
}
catch ( \OutOfRangeException $e ) { }
}
if ( isset( $loadedExtensions[ $map['location_key'] ] ) )
{
try
{
if ( $loadedExtensions[ $map['location_key'] ]->attachmentPermissionCheck( $member, $map['id1'], $map['id2'], $map['id3'], $attachment ) )
{
$permission = TRUE;
break;
}
}
catch ( \OutOfRangeException $e ) { }
}
}
}
/* Permission check */
if ( $permission )
{
$toReturn[ $attachment['attach_id'] ] = array(
'size' => \IPS\Output\Plugin\Filesize::humanReadableFilesize( $attachment['attach_filesize'], FALSE, TRUE ),
'downloads' => \IPS\Member::loggedIn()->language()->formatNumber( $attachment['attach_hits'] )
);
}
}
}
\IPS\Output::i()->json( $toReturn );
}
/**
* Returns boolean in json indicating whether the supplied username already exists
@@ -90,7 +222,7 @@ class _ajax extends \IPS\Dispatcher\Controller
{
$result = array( 'result' => 'fail', 'message' => \IPS\Member::loggedIn()->language()->addToStack( 'form_maxlength', FALSE, array( 'pluralize' => array( \IPS\Settings::i()->max_user_name_length ) ) ) );
}
elseif ( \IPS\Settings::i()->username_characters and !preg_match( '/^[' . str_replace( '\-', '-', preg_quote( \IPS\Settings::i()->username_characters, '/' ) ) . ']*$/iu', $name ) )
elseif ( !\IPS\Login::usernameIsAllowed( $name ) )
{
$result = array( 'result' => 'fail', 'message' => \IPS\Member::loggedIn()->language()->addToStack('form_bad_value') );
}
@@ -185,7 +317,7 @@ class _ajax extends \IPS\Dispatcher\Controller
}
}
if ( count( $allowedEmailDomains ) AND !$matched )
if ( \count( $allowedEmailDomains ) AND !$matched )
{
$result = array( 'result' => 'fail', 'message' => $email );
}
@@ -214,12 +346,12 @@ class _ajax extends \IPS\Dispatcher\Controller
/**
* Top Contributors
*
* @retun void
* @return void
*/
public function topContributors()
{
/* How many? */
$limit = intval( ( isset( \IPS\Request::i()->limit ) and \IPS\Request::i()->limit <= 25 ) ? \IPS\Request::i()->limit : 5 );
$limit = \intval( ( isset( \IPS\Request::i()->limit ) and \IPS\Request::i()->limit <= 25 ) ? \IPS\Request::i()->limit : 5 );
/* What timeframe? */
$where = array( array( 'member_received > 0' ) );
@@ -242,12 +374,12 @@ class _ajax extends \IPS\Dispatcher\Controller
break;
}
$innerQuery = \IPS\Db::i()->select( 'core_reputation_index.member_received as member, SUM(rep_rating) as rep', 'core_reputation_index', $where, NULL, NULL, 'member' );
$topContributors = iterator_to_array( \IPS\Db::i()->select( 'member, rep', array( $innerQuery, 'in' ), NULL, 'rep DESC', $limit )->setKeyField('member')->setValueField('rep') );
$innerQuery = \IPS\Db::i()->select( 'core_reputation_index.member_received as themember, SUM(rep_rating) as rep', 'core_reputation_index', $where, NULL, NULL, 'themember' );
$topContributors = iterator_to_array( \IPS\Db::i()->select( 'themember, rep', array( $innerQuery, 'in' ), NULL, 'rep DESC', $limit )->setKeyField('themember')->setValueField('rep') );
}
else
{
$topContributors = iterator_to_array( \IPS\Db::i()->select( 'member_id as member, pp_reputation_points as rep', 'core_members', array( 'pp_reputation_points > 0' ), 'rep DESC', $limit )->setKeyField('member')->setValueField('rep') );
$topContributors = iterator_to_array( \IPS\Db::i()->select( 'member_id as themember, pp_reputation_points as rep', 'core_members', array( 'pp_reputation_points > 0' ), 'rep DESC', $limit )->setKeyField('themember')->setValueField('rep') );
}
/* Load their data */
@@ -269,10 +401,68 @@ class _ajax extends \IPS\Dispatcher\Controller
}
}
/**
* Most Solved
*
* @return void
*/
public function mostSolved()
{
/* How many? */
$limit = \intval( ( isset( \IPS\Request::i()->limit ) and \IPS\Request::i()->limit <= 25 ) ? \IPS\Request::i()->limit : 5 );
/* What timeframe? */
$where = array( array( 'member_id > 0' ) );
$timeframe = 'all';
if ( isset( \IPS\Request::i()->time ) and \IPS\Request::i()->time != 'all' )
{
switch ( \IPS\Request::i()->time )
{
case 'week':
$where[] = array( 'solved_date>' . \IPS\DateTime::create()->sub( new \DateInterval( 'P1W' ) )->getTimestamp() );
$timeframe = 'week';
break;
case 'month':
$where[] = array( 'solved_date>' . \IPS\DateTime::create()->sub( new \DateInterval( 'P1M' ) )->getTimestamp() );
$timeframe = 'month';
break;
case 'year':
$where[] = array( 'solved_date>' . \IPS\DateTime::create()->sub( new \DateInterval( 'P1Y' ) )->getTimestamp() );
$timeframe = 'year';
break;
}
$innerQuery = \IPS\Db::i()->select( 'core_solved_index.member_id as themember, COUNT(*) as count', 'core_solved_index', $where, NULL, NULL, 'themember' );
$topSolved = iterator_to_array( \IPS\Db::i()->select( 'themember, count', array( $innerQuery, 'in' ), NULL, 'count DESC', $limit )->setKeyField('themember')->setValueField('count') );
}
else
{
$topSolved = iterator_to_array( \IPS\Db::i()->select( 'MAX(member_id) as member_id, COUNT(*) as count', 'core_solved_index', NULL, 'count DESC', $limit, 'member_id' )->setKeyField('member_id')->setValueField('count') );
}
/* Load their data */
foreach ( \IPS\Db::i()->select( '*', 'core_members', \IPS\Db::i()->in( 'member_id', array_keys( $topSolved ) ) ) as $member )
{
\IPS\Member::constructFromData( $member );
}
/* Render */
$output = \IPS\Theme::i()->getTemplate( 'widgets' )->mostSolvedRows( $topSolved, $timeframe, \IPS\Request::i()->orientation );
if ( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->sendOutput( $output );
}
else
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'block_mostSolved' );
\IPS\Output::i()->output = $output;
}
}
/**
* Menu Preview
*
* @retun void
* @return void
*/
public function menuPreview()
{
@@ -306,7 +496,7 @@ class _ajax extends \IPS\Dispatcher\Controller
/* If there's new notifications, get the actual data */
if ( \IPS\Request::i()->notifications < $return['notifications']['count'] )
{
$notificationsDifference = $return['notifications']['count'] - \IPS\Request::i()->notifications;
$notificationsDifference = $return['notifications']['count'] - (int) \IPS\Request::i()->notifications;
/* Cap at 200 to prevent DOSing the server when there are like 1000+ notifications to send */
if( $notificationsDifference > 200 )
@@ -314,7 +504,7 @@ class _ajax extends \IPS\Dispatcher\Controller
$notificationsDifference = 200;
}
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_notifications', array( 'member=? AND ( read_time IS NULL OR read_time<? )', \IPS\Member::loggedIn()->member_id, time() ), 'updated_time DESC', $notificationsDifference ), 'IPS\Notification\Inline' ) as $notification )
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_notifications', array( '`member`=? AND ( read_time IS NULL OR read_time<? )', \IPS\Member::loggedIn()->member_id, time() ), 'updated_time DESC', $notificationsDifference ), 'IPS\Notification\Inline' ) as $notification )
{
/* It is possible that the content has been removed after the iterator has started but before we fetch the data */
try
@@ -342,7 +532,7 @@ class _ajax extends \IPS\Dispatcher\Controller
{
if ( \IPS\Request::i()->messages < $return['messages']['count'] )
{
$messagesDifference = $return['messages']['count'] - \IPS\Request::i()->messages;
$messagesDifference = $return['messages']['count'] - (int) \IPS\Request::i()->messages;
foreach ( \IPS\Db::i()->select( 'map_topic_id', 'core_message_topic_user_map', array( 'map_user_id=? AND map_user_active=1 AND map_has_unread=1 AND map_ignore_notification=0', \IPS\Member::loggedIn()->member_id ), 'map_last_topic_reply DESC', $messagesDifference ) as $conversationId )
{
@@ -386,7 +576,22 @@ class _ajax extends \IPS\Dispatcher\Controller
$phpass = new \PasswordStrength();
$response = array( 'result' => 'ok', 'score' => $phpass->classify( $password ), 'granular' => $phpass->calculate( $password ) );
$score = NULL;
$granular = NULL;
if( isset( \IPS\Request::i()->checkAgainstRequest ) AND \is_array( \IPS\Request::i()->checkAgainstRequest ) )
{
foreach( \IPS\Request::i()->checkAgainstRequest as $notIdenticalValue )
{
if( $notIdenticalValue AND $password == urldecode( $notIdenticalValue ) )
{
$score = $phpass::STRENGTH_VERY_WEAK;
$granular = 1;
}
}
}
$response = array( 'result' => 'ok', 'score' => $score ?? $phpass->classify( $password ), 'granular' => $granular ?? $phpass->calculate( $password ) );
\IPS\Output::i()->json( $response );
}
@@ -401,9 +606,93 @@ class _ajax extends \IPS\Dispatcher\Controller
$mysqlTimezone = \IPS\Db::i()->query( "SELECT TIMEDIFF( NOW(), CONVERT_TZ( NOW(), @@session.time_zone, '+00:00' ) );" )->fetch_row()[0];
if ( preg_match( '/^(-?)(\d{2}):00:00/', $mysqlTimezone, $matches ) )
{
$mysqlTimezone = "GMT" . ( ( $matches[2] == 0 ) ? '' : ( ( $matches[1] ?: '+' ) . intval( $matches[2] ) ) );
$mysqlTimezone = "GMT" . ( ( $matches[2] == 0 ) ? '' : ( ( $matches[1] ?: '+' ) . \intval( $matches[2] ) ) );
}
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->chartTimezoneInfo( $mysqlTimezone );
}
/**
* Dismiss ACP Notification
*
* @return void
*/
public function dismissAcpNotification()
{
\IPS\Session::i()->csrfCheck();
if ( \IPS\Member::loggedIn()->isAdmin() )
{
\IPS\core\AdminNotification::dismissNotification( \IPS\Request::i()->id );
}
\IPS\Output::i()->json( array( 'status' => 'OK' ) );
}
/**
* Find suggested tags
*
* @return void
*/
public function findTags()
{
$results = array();
$input = mb_strtolower( \IPS\Request::i()->input );
/* First, get the admin-defined tags */
$definedTags = array();
if( isset( \IPS\Request::i()->class ) )
{
$class = \IPS\Request::i()->class;
$containerClass = $class::$containerNodeClass;
try
{
$container = $containerClass::load( \IPS\Request::i()->container );
}
catch( \OutOfRangeException $e )
{
$container = NULL;
}
if( $definedTags = $class::definedTags( $container ) )
{
foreach( $definedTags as $tag )
{
/* Only include tags that match the input term */
if( mb_stripos( $tag, $input ) !== FALSE )
{
$results[] = array(
'value' => $tag,
'html' => $tag,
'recommended' => true
);
}
}
}
}
/* Then look for used tags */
$where = array(
array( "tag_text LIKE CONCAT(?, '%')", $input ),
array( 'tag_perm_visible=?', 1 ),
array( '(' . \IPS\Db::i()->findInSet( 'tag_perm_text', \IPS\Member::loggedIn()->groups ) . ' OR ' . 'tag_perm_text=? )', '*' ),
);
foreach ( \IPS\Db::i()->select( 'tag_text', 'core_tags', $where, 'LENGTH(tag_text) ASC', array( 0, 20 ), 'tag_text' )->join( 'core_tags_perms', array( 'tag_perm_aai_lookup=tag_aai_lookup' ) ) as $tag )
{
if( !\in_array( $tag, $definedTags ) )
{
$results[] = array(
'value' => $tag,
'html' => $tag,
'recommended' => false
);
}
}
\IPS\Output::i()->json( $results );
}
}