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

+78 -66
View File
@@ -11,7 +11,7 @@
namespace IPS\core;
/* 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;
@@ -86,7 +86,7 @@ class _Promote extends \IPS\Patterns\ActiveRecord
*/
public function set_text( $value )
{
$this->_data['text'] = ( is_array( $value ) ? json_encode( $value ) : $value );
$this->_data['text'] = ( \is_array( $value ) ? json_encode( $value ) : $value );
}
/**
@@ -107,7 +107,7 @@ class _Promote extends \IPS\Patterns\ActiveRecord
*/
public function set_images( $value )
{
$this->_data['images'] = ( is_array( $value ) ? json_encode( $value ) : $value );
$this->_data['images'] = ( \is_array( $value ) ? json_encode( $value ) : $value );
}
/**
@@ -128,7 +128,7 @@ class _Promote extends \IPS\Patterns\ActiveRecord
*/
public function set_media( $value )
{
$this->_data['media'] = ( is_array( $value ) ? json_encode( $value ) : $value );
$this->_data['media'] = ( \is_array( $value ) ? json_encode( $value ) : $value );
}
/**
@@ -149,7 +149,7 @@ class _Promote extends \IPS\Patterns\ActiveRecord
*/
public function set_share_to( $value )
{
$this->_data['share_to'] = ( is_array( $value ) ? json_encode( $value ) : $value );
$this->_data['share_to'] = ( \is_array( $value ) ? json_encode( $value ) : $value );
}
/**
@@ -170,7 +170,7 @@ class _Promote extends \IPS\Patterns\ActiveRecord
*/
public function set_returned( $value )
{
$this->_data['returned'] = ( is_array( $value ) ? json_encode( $value ) : $value );
$this->_data['returned'] = ( \is_array( $value ) ? json_encode( $value ) : $value );
}
/**
@@ -191,7 +191,7 @@ class _Promote extends \IPS\Patterns\ActiveRecord
*/
public function set_form_data( $value )
{
$this->_data['form_data'] = ( is_array( $value ) ? json_encode( $value ) : $value );
$this->_data['form_data'] = ( \is_array( $value ) ? json_encode( $value ) : $value );
}
/**
@@ -623,7 +623,7 @@ class _Promote extends \IPS\Patterns\ActiveRecord
}
/* Full response stored */
if ( isset( $returned[ $service ] ) AND is_array( $returned[ $service ] ) )
if ( isset( $returned[ $service ] ) AND \is_array( $returned[ $service ] ) )
{
foreach( $returned[ $service ] as $id => $data )
{
@@ -761,7 +761,7 @@ class _Promote extends \IPS\Patterns\ActiveRecord
*/
public function getText( $service, $forDisplay=false )
{
if ( in_array( $service, $this->share_to ) )
if ( \in_array( $service, $this->share_to ) )
{
$text = $this->text;
@@ -885,7 +885,7 @@ class _Promote extends \IPS\Patterns\ActiveRecord
{
$items = array();
foreach( \IPS\Db::i()->select( '*', 'core_social_promote', array( 'promote_sent > 0 and promote_internal=1' ), $sortField . ' ' . $sortDirection, $limit ) as $row )
foreach( \IPS\Db::i()->select( '*', 'core_social_promote', array( 'promote_sent > 0 and promote_internal=1 and promote_hide=0' ), $sortField . ' ' . $sortDirection, $limit ) as $row )
{
$items[ $row['promote_id'] ] = static::constructFromData( $row );
}
@@ -912,7 +912,7 @@ class _Promote extends \IPS\Patterns\ActiveRecord
if ( \IPS\Settings::i()->promote_members )
{
if ( \IPS\Settings::i()->promote_members and in_array( $member->member_id , explode( "\n", \IPS\Settings::i()->promote_members ) ) )
if ( \IPS\Settings::i()->promote_members and \in_array( $member->member_id , explode( "\n", \IPS\Settings::i()->promote_members ) ) )
{
return TRUE;
}
@@ -949,36 +949,6 @@ class _Promote extends \IPS\Patterns\ActiveRecord
throw new \OutOfRangeException('object_not_valid');
}
/**
* Return a list of groups that cannot see this item
*
* @param object $object Object (node or content item)
* @return NULL|Array
*/
public static function objectCannotViewGroups( $object )
{
$groups = array();
foreach( \IPS\Member\Group::groups() as $group )
{
if ( $object instanceof \IPS\Content\Comment )
{
if ( ! $object->item()->can( 'view', $group ) )
{
$groups[] = $group->name;
}
}
else
{
if ( ! $object->can( 'view', $group ) )
{
$groups[] = $group->name;
}
}
}
return \count( $groups ) ? $groups : NULL;
}
/**
* Get title wrapper for items and nodes
@@ -1058,6 +1028,16 @@ class _Promote extends \IPS\Patterns\ActiveRecord
/* Clean up excess newlines */
$result = trim( preg_replace( "#(<br>){1,}#", "\n", preg_replace( '#(<br>)\s+#', "\n", $result ) ) );
/* Clean up excess spaces at the beginning of text lines */
$lines = array();
foreach( explode( "\n", $result ) as $line )
{
$lines[] = trim( $line );
}
$result = implode( "\n", $lines );
/* If this is a node, strip HTML tags for security reasons */
if ( $object instanceof \IPS\Node\Model )
{
@@ -1153,14 +1133,17 @@ class _Promote extends \IPS\Patterns\ActiveRecord
/* Have a bash at it like */
try
{
$response = \IPS\Http\Url::external( "https://api-ssl.bitly.com/v3/shorten" )->setQueryString( array( 'access_token' => \IPS\Settings::i()->bitly_token, 'longUrl' => $longUrl ) )->request()->get()->decodeJson();
if ( $response['status_code'] !== 200 )
$groups = \IPS\Http\Url::external( "https://api-ssl.bitly.com/v4/groups" )->request()->setHeaders( array( 'Content-Type' => 'application/json', 'Authorization' => "Bearer " . \IPS\Settings::i()->bitly_token ) )->get()->decodeJson();
$response = \IPS\Http\Url::external( "https://api-ssl.bitly.com/v4/shorten" )->request()->setHeaders( array( 'Content-Type' => 'application/json', 'Authorization' => "Bearer " . \IPS\Settings::i()->bitly_token ) )->post( json_encode( array( 'long_url' => (string) $longUrl, 'group_guid' => $groups['groups'][0]['guid'] ) ) );
if ( !\in_array( $response->httpResponseCode, array( 200, 201 ) ) )
{
throw new \RuntimeException;
}
return $response['data']['url'];
$responseData = json_decode( $response->content, TRUE );
return $responseData['link'];
}
catch ( \IPS\Http\Request\Exception $e )
{
@@ -1171,7 +1154,7 @@ class _Promote extends \IPS\Patterns\ActiveRecord
/**
* Get the next auto schedule timestamp
*
* @return null|\IPS\DateTime object
* @return \IPS\DateTime|null object
*/
public static function getNextAutoSchedule()
{
@@ -1180,13 +1163,16 @@ class _Promote extends \IPS\Patterns\ActiveRecord
return NULL;
}
$latest = \IPS\Db::i()->select( 'MAX(promote_scheduled)', 'core_social_promote', array( 'promote_schedule_auto=1 and promote_sent=0' ) )->first();
$latest = \IPS\Db::i()->select( 'MAX(promote_scheduled)', 'core_social_promote', array( 'promote_schedule_auto=1 and promote_sent=0 and promote_failed=0' ) )->first();
$timezone = new \DateTimeZone( \IPS\Settings::i()->promote_tz );
$current = \IPS\DateTime::create()->setTimezone( $timezone );
$times = explode( ',', \IPS\Settings::i()->promote_scheduled );
$time = NULL;
if ( $latest )
/* Sort schedule times just in case they have been added out of order in the ACP */
natsort( $times );
if ( $latest AND $latest > $current->getTimestamp() )
{
$current = \IPS\DateTime::ts( $latest )->setTimezone( $timezone );
}
@@ -1210,9 +1196,6 @@ class _Promote extends \IPS\Patterns\ActiveRecord
{
while( $time === NULL )
{
/* Set to midnight of current day */
$current->setTime( 0, 0 );
/* We need to clone otherwise $test is always the same as $current */
$test = clone $current;
@@ -1220,7 +1203,7 @@ class _Promote extends \IPS\Patterns\ActiveRecord
{
list( $h, $m ) = explode( ':', $entry );
$test->setTime( $h, $m );
if ( ( $test->getTimeStamp() > time() ) and ( $current->getTimeStamp() <= $test->getTimeStamp() ) )
if ( ( $test->getTimeStamp() > time() ) and ( $current->getTimeStamp() < $test->getTimeStamp() ) )
{
$time = $test;
break;
@@ -1228,7 +1211,7 @@ class _Promote extends \IPS\Patterns\ActiveRecord
}
/* Still here? */
$current->add( new \DateInterval( 'P1D' ) );
$current->add( new \DateInterval( 'P1D' ) )->setTime( 0, 0 );
}
}
@@ -1271,19 +1254,8 @@ class _Promote extends \IPS\Patterns\ActiveRecord
{
/* Fetch the appropriate promoters */
if ( static::$promoters === NULL )
{
if ( isset( \IPS\Data\Store::i()->promoters ) )
{
$rows = \IPS\Data\Store::i()->promoters;
}
else
{
$rows = iterator_to_array( \IPS\Db::i()->select( '*', 'core_social_promote_sharers', 'sharer_enabled=1' ) );
\IPS\Data\Store::i()->promoters = $rows;
}
foreach ( $rows as $row )
{
foreach ( static::getStore() as $row )
{
try
{
@@ -1295,6 +1267,21 @@ class _Promote extends \IPS\Patterns\ActiveRecord
return static::$promoters;
}
/**
* Get all promoter obects
*
* @return array
*/
public static function getStore()
{
if ( !isset( \IPS\Data\Store::i()->promoters ) )
{
\IPS\Data\Store::i()->promoters = iterator_to_array( \IPS\Db::i()->select( '*', 'core_social_promote_sharers', 'sharer_enabled=1' ) );
}
return \IPS\Data\Store::i()->promoters;
}
/**
* Return the promotable services this user has access to
@@ -1374,4 +1361,29 @@ class _Promote extends \IPS\Patterns\ActiveRecord
}
}
}
/**
* Change the hidden flag for all rows that match a class
*
* @param $class Object Class (eg IPS\Blog\entry)
* @param $hidden Boolean Set hidden
* @return void
*/
public static function changeHiddenByClass( $class, $hidden=0 )
{
\IPS\Db::i()->update( 'core_social_promote', array( 'promote_hide' => \intval( $hidden ) ), array( 'promote_class=?', \get_class( $class ) ) );
if ( $class instanceof \IPS\Content\Item )
{
if ( isset( $class::$commentClass ) )
{
\IPS\Db::i()->update( 'core_social_promote', array( 'promote_hide' => \intval( $hidden ) ), array( 'promote_class=?', $class::$commentClass ) );
}
if ( isset( $class::$reviewClass ) )
{
\IPS\Db::i()->update( 'core_social_promote', array( 'promote_hide' => \intval( $hidden ) ), array( 'promote_class=?', $class::$reviewClass ) );
}
}
}
}