Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

+233 -32
View File
@@ -183,6 +183,27 @@ class _Promote extends \IPS\Patterns\ActiveRecord
return $this->_data['returned'] ? json_decode( $this->_data['returned'], TRUE ) : array();
}
/**
* Set the "form_data" field
*
* @param string|array $value
* @return void
*/
public function set_form_data( $value )
{
$this->_data['form_data'] = ( is_array( $value ) ? json_encode( $value ) : $value );
}
/**
* Get the "form_data" field
*
* @return array
*/
public function get_form_data()
{
return $this->_data['form_data'] ? json_decode( $this->_data['form_data'], TRUE ) : array();
}
/**
* The author object
*
@@ -221,6 +242,23 @@ class _Promote extends \IPS\Patterns\ActiveRecord
return $this->object;
}
/**
* Get Our Picks title
*
* @return string
*/
public function get_ourPicksTitle()
{
$settings = $this->form_data;
if ( ! empty( $settings['internal']['title'] ) )
{
return $settings['internal']['title'];
}
return $this->objectTitle;
}
/**
* Get the object title
*
@@ -330,17 +368,30 @@ class _Promote extends \IPS\Patterns\ActiveRecord
if ( $object instanceof \IPS\Content\Item )
{
if ( isset( $object::$databaseColumnMap['num_comments'] ) and isset( $object::$commentClass ) )
try
{
$container = $object->container();
}
catch( \Exception $e ){}
if ( $object::supportsComments( NULL, $container ) )
{
$count = $object->mapped('num_comments');
if ( $count AND isset( $object::$firstCommentRequired ) )
if ( $count AND isset( $object::$firstCommentRequired ) AND $object::$firstCommentRequired === TRUE )
{
$count--;
}
$commentClass = $object::$commentClass;
return array( 'count' => $count, 'words' => \IPS\Member::loggedIn()->language()->addToStack( 'num_replies', NULL, array( 'pluralize' => array( $count ) ) ) );
}
if ( $object::supportsReviews( NULL, $container ) )
{
$count = $object->mapped('num_reviews');
return array( 'count' => $count, 'words' => \IPS\Member::loggedIn()->language()->addToStack( 'num_reviews', NULL, array( 'pluralize' => array( $count ) ) ) );
}
/* Valid object, but there isn't any date data available */
return NULL;
@@ -351,7 +402,13 @@ class _Promote extends \IPS\Patterns\ActiveRecord
}
else if ( $object instanceof \IPS\Node\Model )
{
/* Valid object, but there isn't any date data available */
if( $object->_items !== NULL )
{
$count = $object->_items;
return array( 'count' => $count, 'words' => \IPS\Member::loggedIn()->language()->addToStack( $object->_countLanguageString, NULL, array( 'pluralize' => array( $count ) ) ) );
}
return NULL;
}
@@ -361,38 +418,143 @@ class _Promote extends \IPS\Patterns\ActiveRecord
/**
* Returns "Foo posted {{indefart}} in {{container}}, {{date}}
*
* @return array|null
* @return string
*/
public function get_objectMetaDescription()
{
return $this->objectMetaDescription( NULL );
}
/**
* Returns "Foo posted {{indefart}} in {{container}}, {{date}}
*
* @param \IPS\Lang|NULL $plaintextLanguage If specified, will return plaintext (not linking the user or the container in the language specified). If NULL, returns with links based on logged in user's theme and language
* @return string
*/
public function objectMetaDescription( $plaintextLanguage=NULL )
{
$object = $this->object();
$author = $this->objectAuthor;
if ( $object instanceof \IPS\Content\Item )
{
$container = $object->containerWrapper();
if ( $container )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'promote_metadescription_container', NULL, array( 'htmlsprintf' => array( $author->link(), $object->indefiniteArticle(), $container->url(), $container->_title, $this->objectDatePosted->html( FALSE ) ) ) );
if ( !$plaintextLanguage )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'promote_metadescription_container', NULL, array(
'htmlsprintf' => array( $author->link(), $this->objectDatePosted->html( FALSE ) ),
'sprintf' => array( $object->indefiniteArticle(), $container->url(), $container->_title ),
) );
}
else
{
return $plaintextLanguage->addToStack( 'promote_metadescription_container_nolink', NULL, array(
'sprintf' => array( $object->indefiniteArticle( $plaintextLanguage ), $container->_title, $author->name, $this->objectDatePosted->relative( \IPS\DateTime::RELATIVE_FORMAT_NORMAL, $plaintextLanguage ) ),
) );
}
}
else
{
return \IPS\Member::loggedIn()->language()->addToStack( 'promote_metadescription_nocontainer', NULL, array( 'htmlsprintf' => array( $author->link(), $object->indefiniteArticle(), $this->objectDatePosted->html( FALSE ) ) ) );
if ( !$plaintextLanguage )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'promote_metadescription_nocontainer', NULL, array(
'htmlsprintf' => array( $author->link(), $this->objectDatePosted->html( FALSE ) ),
'sprintf' => array( $object->indefiniteArticle() )
) );
}
else
{
return $plaintextLanguage->addToStack( 'promote_metadescription_nocontainer', NULL, array(
'sprintf' => array( $object->indefiniteArticle( $plaintextLanguage ), $author->name, $this->objectDatePosted->relative( \IPS\DateTime::RELATIVE_FORMAT_NORMAL, $plaintextLanguage ) )
) );
}
}
}
else if ( $object instanceof \IPS\Content\Comment )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'promote_metadescription_nocontainer', NULL, array( 'htmlsprintf' => array( $author->link(), $object->indefiniteArticle(), $this->objectDatePosted->html( FALSE ) ) ) );
if ( !$plaintextLanguage )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'promote_metadescription_nocontainer', NULL, array(
'htmlsprintf' => array( $author->link(), $this->objectDatePosted->html( FALSE ) ),
'sprintf' => array( $object->indefiniteArticle() )
) );
}
else
{
return $plaintextLanguage->addToStack( 'promote_metadescription_nocontainer', NULL, array(
'sprintf' => array( $object->indefiniteArticle( $plaintextLanguage ), $author->name, $this->objectDatePosted->relative( \IPS\DateTime::RELATIVE_FORMAT_NORMAL, $plaintextLanguage ) )
) );
}
}
else if ( $object instanceof \IPS\Node\Model )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'promote_metadescription_node', NULL, array( 'htmlsprintf' => array( $author->link(), $object->url(), $object->_title ) ) );
if ( !$plaintextLanguage )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'promote_metadescription_node', NULL, array(
'htmlsprintf' => array( $author->link() ),
'sprintf' => array( $object->url(), $object->_title )
) );
}
else
{
return $plaintextLanguage->addToStack( 'promote_metadescription_node_nolink', NULL, array(
'sprintf' => array( $object->_title, $author->name )
) );
}
}
throw new \OutofRangeException('object_not_valid');
}
/**
* Get reactions class for this object
*
* @return array|null
*/
public function get_objectReactionClass()
{
$object = $this->object();
$class = NULL;
if ( ! \IPS\Settings::i()->reputation_enabled )
{
return NULL;
}
if ( $object instanceof \IPS\Content\Item )
{
/* The first post has the reactions for this item */
if ( $object::$firstCommentRequired )
{
try
{
$class = $object->comments( 1, NULL, 'date', 'asc' );
}
catch( \Exception $e )
{
$class = NULL;
}
}
else
{
$class = $object;
}
}
else if ( $object instanceof \IPS\Content\Comment )
{
$class = $object;
}
else if ( $object instanceof \IPS\Node\Model )
{
return NULL;
}
return ( $class and \IPS\IPS::classUsesTrait( $class, 'IPS\Content\Reactable' ) ) ? $class : NULL;
}
/**
* Send to networks now
*
@@ -405,6 +567,13 @@ class _Promote extends \IPS\Patterns\ActiveRecord
$this->save();
$returned = $this->returned;
$time = time();
$hasFailed = false;
/* Item hidden? Unhide it now */
if ( $this->object()->hidden() !== 0 )
{
$this->object()->unhide( FALSE );
}
foreach( $this->share_to as $service )
{
@@ -431,12 +600,10 @@ class _Promote extends \IPS\Patterns\ActiveRecord
/* Successful post ID returned */
$returned[ $service ] = $serviceObject->post( $this );
$this->failed = 0;
}
catch( \Exception $ex )
{
/* It failed, increment counter and set the next attempt for 10 minutes time */
$this->failed++;
$hasFailed = true;
$this->scheduled = time() + 600;
$this->sent = 0;
@@ -444,11 +611,25 @@ class _Promote extends \IPS\Patterns\ActiveRecord
}
/* Full response stored */
$response['response_json'] = json_encode( $serviceObject->response, TRUE );
if ( isset( $returned[ $service ] ) AND is_array( $returned[ $service ] ) )
{
foreach( $returned[ $service ] as $id => $data )
{
$response['response_json'] = json_encode( $data, TRUE );
$response['response_service_id'] = $id;
\IPS\Db::i()->insert( 'core_social_promote_content', $response );
}
}
else
{
$response['response_json'] = json_encode( $serviceObject->response, TRUE );
\IPS\Db::i()->insert( 'core_social_promote_content', $response );
\IPS\Db::i()->insert( 'core_social_promote_content', $response );
}
}
$this->failed = ( $hasFailed ) ? $this->failed + 1 : 0;
$this->returned = $returned;
$this->save();
}
@@ -572,7 +753,7 @@ class _Promote extends \IPS\Patterns\ActiveRecord
{
$text = $this->text;
return isset( $text[ $service ] ) ? ( $forDisplay ? nl2br( $text[ $service ] ) : $text[ $service ] ) : NULL;
return isset( $text[ $service ] ) ? ( $forDisplay ? nl2br( htmlspecialchars( $text[ $service ], ENT_QUOTES | ENT_DISALLOWED, 'UTF-8', FALSE ) ) : $text[ $service ] ) : NULL;
}
return NULL;
@@ -657,7 +838,7 @@ class _Promote extends \IPS\Patterns\ActiveRecord
foreach( \IPS\Db::i()->select( '*', 'core_social_promote_content', array( 'response_promote_id=? and response_failed=0', $this->id ) ) as $row )
{
$this->history[ $this->id ][ $row['response_sent_date'] ][ $row['response_promote_key'] ] = $row['response_date'];
$this->history[ $this->id ][ $row['response_sent_date'] ][ $row['response_promote_key'] ][] = $row;
}
}
@@ -683,7 +864,6 @@ class _Promote extends \IPS\Patterns\ActiveRecord
/**
* Promote stream of internally promoted items
*
* @param array $services Array of services by key (internal, facebook, etc)
* @param int|array $limit Number of items to fetch
* @param string $sortField Sort by field
* @param string $sortDirection Sort by direction (asc, desc)
@@ -756,7 +936,7 @@ class _Promote extends \IPS\Patterns\ActiveRecord
throw new \OutofRangeException('object_not_valid');
}
/**
* Return a list of groups that cannot see this item
*
@@ -826,31 +1006,52 @@ class _Promote extends \IPS\Patterns\ActiveRecord
*/
public static function objectContent( $object )
{
$result = NULL;
if ( $object instanceof \IPS\Content\Item )
{
if ( isset( $object::$databaseColumnMap['content'] ) )
{
return trim( str_replace( "<br>", "\n", $object->truncated() ) );
$result = $object->truncated();
}
else if ( $object::$firstCommentRequired )
{
$firstComment = $object->comments( 1, NULL, 'date', 'asc' );
return trim( preg_replace( "#(<br>){1,}#", "\n", preg_replace( '#(<br>)\s+#', "\n", $firstComment->truncated() ) ) );
$result = $firstComment->truncated();
}
return '';
}
else if ( $object instanceof \IPS\Content\Comment )
{
return trim( preg_replace( "#(<br>){1,}#", "\n", preg_replace( '#(<br>)\s+#', "\n", $object->truncated() ) ) );
$result = $object->truncated();
}
else if ( $object instanceof \IPS\Node\Model )
{
return trim( strip_tags( preg_replace( "#(<br>){1,}#", "\n", preg_replace( '#(<br>)\s+#', "\n", $object->description ) ) ) );
$result = $object->description;
}
throw new \OutofRangeException('object_not_valid');
/* If result was not set, throw exception now */
if( $result === NULL )
{
throw new \OutofRangeException('object_not_valid');
}
/* If we treat enter key as newline instead of paragraph, we need to clean up a bit further */
if( !\IPS\Settings::i()->editor_paragraph_padding )
{
$result = str_replace( "\n", '', $result );
}
/* Clean up excess newlines */
$result = trim( preg_replace( "#(<br>){1,}#", "\n", preg_replace( '#(<br>)\s+#', "\n", $result ) ) );
/* If this is a node, strip HTML tags for security reasons */
if ( $object instanceof \IPS\Node\Model )
{
$result = strip_tags( $result );
}
return $result;
}
/**
@@ -926,8 +1127,8 @@ class _Promote extends \IPS\Patterns\ActiveRecord
*
* @param string $longUrl The original URL
* @returns string NULL if no shortnener available or it fails
* @throws RuntimeException if shortener fails
* @throws UnderflowException if no shortener available
* @throws \RuntimeException if shortener fails
* @throws \UnderflowException if no shortener available
*/
public static function shortenUrl( $longUrl )
{
@@ -957,7 +1158,7 @@ class _Promote extends \IPS\Patterns\ActiveRecord
/**
* Get the next auto schedule timestamp
*
* @return null|DateTime object
* @return null|\IPS\DateTime object
*/
public static function getNextAutoSchedule()
{
@@ -1002,11 +1203,11 @@ class _Promote extends \IPS\Patterns\ActiveRecord
return $time;
}
/**
* Return a single promote object
*
* @throws UnderflowException
* @param $key string Promote Service
* @return \IPS\Login
*/