Version 4.6.0
This commit is contained in:
1 parent
f79dcf067a
commit
517a5e1f70
2036 files changed
+110041
-26162
No files matched your search
@@ -33,7 +33,8 @@ class _Records extends \IPS\Content\Item implements
|
||||
\IPS\Content\Searchable,
|
||||
\IPS\Content\FuturePublishing,
|
||||
\IPS\Content\Embeddable,
|
||||
\IPS\Content\MetaData
|
||||
\IPS\Content\MetaData,
|
||||
\IPS\Content\Anonymous
|
||||
{
|
||||
use \IPS\Content\Reactable, \IPS\Content\Reportable;
|
||||
|
||||
@@ -403,12 +404,20 @@ class _Records extends \IPS\Content\Item implements
|
||||
* Definite Article
|
||||
*
|
||||
* @param \IPS\Lang|NULL $lang The language to use, or NULL for the language of the currently logged in member
|
||||
* @param integer|boolean $count Number of items. If not false, pluralized version of phrase will be used.
|
||||
* @return string
|
||||
*/
|
||||
public function definiteArticle( \IPS\Lang $lang = NULL )
|
||||
public function definiteArticle( \IPS\Lang $lang = NULL, $count = FALSE )
|
||||
{
|
||||
$lang = $lang ?: \IPS\Member::loggedIn()->language();
|
||||
return $lang->addToStack( 'content_db_lang_sl_' . static::$customDatabaseId, FALSE );
|
||||
if( $count === TRUE || ( \is_int( $count ) && $count > 1 ) )
|
||||
{
|
||||
return $lang->addToStack( 'content_db_lang_pl_' . static::$customDatabaseId, FALSE );
|
||||
}
|
||||
else
|
||||
{
|
||||
return $lang->addToStack( 'content_db_lang_sl_' . static::$customDatabaseId, FALSE );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -417,12 +426,20 @@ class _Records extends \IPS\Content\Item implements
|
||||
* @param array $containerData Basic data about the container. Only includes columns returned by container::basicDataColumns()
|
||||
* @param \IPS\Lang|NULL $lang The language to use, or NULL for the language of the currently logged in member
|
||||
* @param array $options Options to pass to \IPS\Lang::addToStack
|
||||
* @param integer|boolean $count Number of items. If not false, pluralized version of phrase will be used.
|
||||
* @return string
|
||||
*/
|
||||
public static function _definiteArticle( array $containerData = NULL, \IPS\Lang $lang = NULL, $options = array() )
|
||||
public static function _definiteArticle( array $containerData = NULL, \IPS\Lang $lang = NULL, $options = array(), $count = FALSE )
|
||||
{
|
||||
$lang = $lang ?: \IPS\Member::loggedIn()->language();
|
||||
return $lang->addToStack( 'content_db_lang_sl_' . static::$customDatabaseId, FALSE, $options );
|
||||
if( $count === TRUE || ( \is_int( $count ) && $count > 1 ) )
|
||||
{
|
||||
return $lang->addToStack( 'content_db_lang_pl_' . static::$customDatabaseId, FALSE, $options );
|
||||
}
|
||||
else
|
||||
{
|
||||
return $lang->addToStack( 'content_db_lang_sl_' . static::$customDatabaseId, FALSE, $options );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -558,7 +575,7 @@ class _Records extends \IPS\Content\Item implements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( $fieldsClass::fixedFieldFormShow( 'record_publish_date' ) AND ( \IPS\Member::loggedIn()->modPermission( "can_future_publish_content" ) or \IPS\Member::loggedIn()->modPermission( "can_future_publish_" . static::$title ) ) )
|
||||
{
|
||||
$formElements['record_publish_date'] = $elements['date'];
|
||||
@@ -569,7 +586,7 @@ class _Records extends \IPS\Content\Item implements
|
||||
$fixedFieldSettings = static::database()->fixed_field_settings;
|
||||
$dims = TRUE;
|
||||
|
||||
if ( isset( $fixedFieldSettings['record_image']['image_dims'] ) )
|
||||
if ( isset( $fixedFieldSettings['record_image']['image_dims'] ) AND $fixedFieldSettings['record_image']['image_dims'][0] AND $fixedFieldSettings['record_image']['image_dims'][1] )
|
||||
{
|
||||
$dims = array( 'maxWidth' => $fixedFieldSettings['record_image']['image_dims'][0], 'maxHeight' => $fixedFieldSettings['record_image']['image_dims'][1] );
|
||||
}
|
||||
@@ -601,6 +618,12 @@ class _Records extends \IPS\Content\Item implements
|
||||
'unlimitedLang' => 'record_datetime_noval'
|
||||
), NULL, NULL, NULL, 'record_comment_cutoff' );
|
||||
}
|
||||
|
||||
/* Post Anonymously */
|
||||
if ( $container and $container->canPostAnonymously( $container::ANON_ITEMS ) )
|
||||
{
|
||||
$formElements['post_anonymously'] = new \IPS\Helpers\Form\YesNo( 'post_anonymously', ( $item ) ? $item->isAnonymous() : FALSE , FALSE, array( 'label' => \IPS\Member::loggedIn()->language()->addToStack( 'post_anonymously_suffix' ) ), NULL, NULL, NULL, 'post_anonymously' );
|
||||
}
|
||||
|
||||
if ( static::modPermission( 'lock', NULL, $container ) )
|
||||
{
|
||||
@@ -957,6 +980,8 @@ class _Records extends \IPS\Content\Item implements
|
||||
static::$customFields = $fieldsClass::fields( $customValues, ( $this->_new ? 'add' : 'edit' ), $container, 0, ( $this->_new ? NULL : $this ) );
|
||||
}
|
||||
|
||||
$seen = [];
|
||||
|
||||
foreach( static::$customFields as $key => $field )
|
||||
{
|
||||
$seen[] = $key;
|
||||
@@ -986,7 +1011,7 @@ class _Records extends \IPS\Content\Item implements
|
||||
/* If we're using decimals, then the database field is set to DECIMALS, so we cannot using stringValue() */
|
||||
else if ( isset( $customValues[ $field->name ] ) and \get_class( $field ) == 'IPS\Helpers\Form\Number' and ( isset( $field->options['decimals'] ) and $field->options['decimals'] > 0 ) )
|
||||
{
|
||||
$this->$key = $field->value;
|
||||
$this->$key = ( $field->value === '' ) ? NULL : $field->value;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1144,29 +1169,10 @@ class _Records extends \IPS\Content\Item implements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( $row->can( ( $isNew ? 'add' : 'edit' ) ) and $row->type == 'Item' )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'cms_database_fields_reciprocal_map', array( 'map_origin_database_id=? and map_field_id=? and map_origin_item_id=?', static::$customDatabaseId, $row->id, $this->_id ) );
|
||||
|
||||
$field = 'field_' . $row->id;
|
||||
$extra = $row->extra;
|
||||
if ( $this->$field and ! empty( $extra['database'] ) )
|
||||
{
|
||||
foreach( explode( ',', $this->$field ) as $foreignId )
|
||||
{
|
||||
if ( $foreignId )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'cms_database_fields_reciprocal_map', array(
|
||||
'map_origin_database_id' => static::$customDatabaseId,
|
||||
'map_foreign_database_id' => $extra['database'],
|
||||
'map_origin_item_id' => $this->$idColumn,
|
||||
'map_foreign_item_id' => $foreignId,
|
||||
'map_field_id' => $row->id
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
$field = $this->processItemFieldData( $row );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1229,7 +1235,7 @@ class _Records extends \IPS\Content\Item implements
|
||||
switch( $pref )
|
||||
{
|
||||
case 'unread':
|
||||
$action = 'getNewComment';
|
||||
$action = \IPS\Member::loggedIn()->member_id ? 'getNewComment' : NULL;
|
||||
break;
|
||||
|
||||
case 'last':
|
||||
@@ -1241,6 +1247,10 @@ class _Records extends \IPS\Content\Item implements
|
||||
break;
|
||||
}
|
||||
}
|
||||
elseif( !\IPS\Member::loggedIn()->member_id AND $action == 'getNewComment' )
|
||||
{
|
||||
$action = NULL;
|
||||
}
|
||||
|
||||
if ( ! $this->recordPage )
|
||||
{
|
||||
@@ -1352,7 +1362,7 @@ class _Records extends \IPS\Content\Item implements
|
||||
* @param string $view 'expanded' or 'condensed'
|
||||
* @return callable
|
||||
*/
|
||||
public static function searchResultSnippet( array $indexData, array $authorData, array $itemData, array $containerData = NULL, array $reputationData, $reviewRating, $view )
|
||||
public static function searchResultSnippet( array $indexData, array $authorData, array $itemData, ?array $containerData, array $reputationData, $reviewRating, $view )
|
||||
{
|
||||
/* We want the custom template only for expanded view or if we have a record image */
|
||||
|
||||
@@ -1384,7 +1394,7 @@ class _Records extends \IPS\Content\Item implements
|
||||
switch( $pref )
|
||||
{
|
||||
case 'unread':
|
||||
$action = 'getNewComment';
|
||||
$action = \IPS\Member::loggedIn()->member_id ? 'getNewComment' : NULL;
|
||||
break;
|
||||
|
||||
case 'last':
|
||||
@@ -1396,6 +1406,10 @@ class _Records extends \IPS\Content\Item implements
|
||||
break;
|
||||
}
|
||||
}
|
||||
elseif( !\IPS\Member::loggedIn()->member_id AND $action == 'getNewComment' )
|
||||
{
|
||||
$action = NULL;
|
||||
}
|
||||
|
||||
if ( static::$pagePath === NULL )
|
||||
{
|
||||
@@ -2339,6 +2353,11 @@ class _Records extends \IPS\Content\Item implements
|
||||
*/
|
||||
public static $skipTopicCreation = FALSE;
|
||||
|
||||
/**
|
||||
* @brief Are we creating a record? Ignore topic syncs until we are done if so.
|
||||
*/
|
||||
protected static $creatingRecord = FALSE;
|
||||
|
||||
/**
|
||||
* Create from form
|
||||
*
|
||||
@@ -2349,7 +2368,9 @@ class _Records extends \IPS\Content\Item implements
|
||||
*/
|
||||
public static function createFromForm( $values, \IPS\Node\Model $container = NULL, $sendNotification = TRUE )
|
||||
{
|
||||
static::$creatingRecord = TRUE;
|
||||
$record = parent::createFromForm( $values, $container, $sendNotification );
|
||||
static::$creatingRecord = FALSE;
|
||||
|
||||
if ( !static::$skipTopicCreation and \IPS\Application::appIsEnabled('forums') and $record->_forum_record and $record->_forum_forum and ! $record->hidden() and ! $record->record_future_date )
|
||||
{
|
||||
@@ -2383,6 +2404,38 @@ class _Records extends \IPS\Content\Item implements
|
||||
parent::processAfterEdit( $values );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the reciprocal field data
|
||||
*
|
||||
* @param mixed $row
|
||||
* @return string
|
||||
*/
|
||||
public function processItemFieldData( \IPS\cms\Fields $row ): string
|
||||
{
|
||||
$idColumn = static::$databaseColumnId;
|
||||
\IPS\Db::i()->delete( 'cms_database_fields_reciprocal_map', array('map_origin_database_id=? and map_field_id=? and map_origin_item_id=?', static::$customDatabaseId, $row->id, $this->_id) );
|
||||
|
||||
$field = 'field_' . $row->id;
|
||||
$extra = $row->extra;
|
||||
if ( $this->$field and !empty( $extra['database'] ) )
|
||||
{
|
||||
foreach ( explode( ',', $this->$field ) as $foreignId )
|
||||
{
|
||||
if ( $foreignId )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'cms_database_fields_reciprocal_map', array(
|
||||
'map_origin_database_id' => static::$customDatabaseId,
|
||||
'map_foreign_database_id' => $extra['database'],
|
||||
'map_origin_item_id' => $this->$idColumn,
|
||||
'map_foreign_item_id' => $foreignId,
|
||||
'map_field_id' => $row->id
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
return $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to execute when tags are edited
|
||||
*
|
||||
@@ -2434,9 +2487,26 @@ class _Records extends \IPS\Content\Item implements
|
||||
$post = \IPS\forums\Topic\Post::create( $topic, $comment, FALSE, ( isset( $values['guest_name'] ) ? $values['guest_name'] : NULL ) );
|
||||
|
||||
$commentClass = 'IPS\cms\Records\CommentTopicSync' . static::$customDatabaseId;
|
||||
|
||||
$idColumn = static::$databaseColumnId;
|
||||
$autoSaveKey = 'reply-' . static::$application . '/' . static::$module . '-' . $this->$idColumn;
|
||||
|
||||
/* First we have to update the attachment location key */
|
||||
\IPS\Db::i()->update( 'core_attachments_map', array( 'location_key' => 'forums_Forums' ), array( 'temp=?', md5( $autoSaveKey ) ) );
|
||||
|
||||
/* Then "claim" the attachments */
|
||||
$parameters = array_merge( array( $autoSaveKey ), $post->attachmentIds() );
|
||||
\IPS\File::claimAttachments( ...$parameters );
|
||||
|
||||
$topic->markRead();
|
||||
|
||||
/* Post anonymously */
|
||||
if( isset( $values[ 'post_anonymously' ] ) )
|
||||
{
|
||||
$post->setAnonymous( $values[ 'post_anonymously' ] );
|
||||
$this->syncRecordFromTopic( $topic );
|
||||
}
|
||||
|
||||
return $commentClass::load( $post->pid );
|
||||
|
||||
}
|
||||
@@ -2587,11 +2657,6 @@ class _Records extends \IPS\Content\Item implements
|
||||
return parent::lastCommenter();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Map of topic links we've already checked
|
||||
*/
|
||||
protected static $topicLinkMap = array();
|
||||
|
||||
/**
|
||||
* Is this topic linked to a record?
|
||||
*
|
||||
@@ -2600,33 +2665,13 @@ class _Records extends \IPS\Content\Item implements
|
||||
*/
|
||||
public static function topicIsLinked( $topic )
|
||||
{
|
||||
if( isset( static::$topicLinkMap[ $topic->tid ] ) )
|
||||
{
|
||||
return static::$topicLinkMap[ $topic->tid ];
|
||||
}
|
||||
|
||||
foreach( \IPS\cms\Databases::databases() as $database )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( $database->forum_record and $database->forum_forum == $topic->container()->_id )
|
||||
{
|
||||
$class = '\IPS\cms\Records' . $database->id;
|
||||
$record = $class::load( $topic->tid, 'record_topicid' );
|
||||
|
||||
if ( $record->_forum_record )
|
||||
{
|
||||
static::$topicLinkMap[ $topic->tid ] = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
}
|
||||
|
||||
static::$topicLinkMap[ $topic->tid ] = FALSE;
|
||||
|
||||
return static::$topicLinkMap[ $topic->tid ];
|
||||
return ( static::getLinkedRecord( $topic ) === NULL ) ? FALSE : TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Cached linked record checks to prevent duplicate queries
|
||||
*/
|
||||
protected static $linkedRecordLookup = array();
|
||||
|
||||
/**
|
||||
* Is this topic linked to a record?
|
||||
@@ -2636,6 +2681,13 @@ class _Records extends \IPS\Content\Item implements
|
||||
*/
|
||||
public static function getLinkedRecord( $topic )
|
||||
{
|
||||
if( array_key_exists( $topic->tid, static::$linkedRecordLookup ) )
|
||||
{
|
||||
return static::$linkedRecordLookup[ $topic->tid ];
|
||||
}
|
||||
|
||||
static::$linkedRecordLookup[ $topic->tid ] = NULL;
|
||||
|
||||
foreach( \IPS\cms\Databases::databases() as $database )
|
||||
{
|
||||
try
|
||||
@@ -2647,14 +2699,14 @@ class _Records extends \IPS\Content\Item implements
|
||||
|
||||
if ( $record->_forum_record )
|
||||
{
|
||||
return $record;
|
||||
static::$linkedRecordLookup[ $topic->tid ] = $record;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return static::$linkedRecordLookup[ $topic->tid ];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2693,6 +2745,12 @@ class _Records extends \IPS\Content\Item implements
|
||||
throw new \UnexpectedValueException('content_record_no_forum_app_for_topic');
|
||||
}
|
||||
|
||||
/* If we're in the middle of creating a record, don't sync the topic yet */
|
||||
if( static::$creatingRecord === TRUE )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Fetch the forum */
|
||||
try
|
||||
{
|
||||
@@ -2784,8 +2842,20 @@ class _Records extends \IPS\Content\Item implements
|
||||
|
||||
$topic->topic_firstpost = $post->pid;
|
||||
$topic->save();
|
||||
|
||||
if( $this->isAnonymous() )
|
||||
{
|
||||
$topic->setAnonymous( TRUE, $this->author );
|
||||
$post->setAnonymous( TRUE, $this->author );
|
||||
}
|
||||
|
||||
$topic->markRead();
|
||||
|
||||
/* Send notifications */
|
||||
if ( !$topic->isFutureDate() AND !$topic->hidden() )
|
||||
{
|
||||
$topic->sendNotifications();
|
||||
}
|
||||
|
||||
/* Update file */
|
||||
$this->record_topicid = $topic->tid;
|
||||
@@ -2945,7 +3015,6 @@ class _Records extends \IPS\Content\Item implements
|
||||
}
|
||||
|
||||
/* Remove Record Image And Record Thumb Image */
|
||||
|
||||
if ( $this->record_image )
|
||||
{
|
||||
try
|
||||
@@ -2964,6 +3033,34 @@ class _Records extends \IPS\Content\Item implements
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
|
||||
/* Clean up any other uploaded files */
|
||||
$fieldsClass = '\IPS\cms\Fields' . static::$customDatabaseId;
|
||||
foreach( $fieldsClass::roots( NULL ) as $id => $field )
|
||||
{
|
||||
if( $field->type == 'Upload' )
|
||||
{
|
||||
$fieldName = 'field_' . $field->id;
|
||||
|
||||
if ( $this->$fieldName )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\File::get( 'cms_Records', $this->$fieldName )->delete();
|
||||
}
|
||||
catch( \Exception $e ){}
|
||||
}
|
||||
|
||||
/* Delete thumbnails */
|
||||
foreach( \IPS\Db::i()->select( '*', 'cms_database_fields_thumbnails', array( array( 'thumb_field_id=? AND thumb_record_id=?', $field->id, $this->primary_id_field ) ) ) as $thumb )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\File::get( 'cms_Records', $thumb['thumb_location'] )->delete();
|
||||
}
|
||||
catch( \Exception $e ){}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove any reciprocal linking */
|
||||
\IPS\Db::i()->delete( 'cms_database_fields_reciprocal_map', array( 'map_origin_database_id=? and map_origin_item_id=?', static::database()->id, $this->_id ) );
|
||||
@@ -3378,7 +3475,7 @@ class _Records extends \IPS\Content\Item implements
|
||||
* @param string $exclude Predetermined array of member IDs to exclude
|
||||
* @return void
|
||||
*/
|
||||
public function setFieldQuoteAndMentionExcludes( array $exclude = array() ): void
|
||||
public function setFieldQuoteAndMentionExcludes( array $exclude = array() )
|
||||
{
|
||||
$className = 'IPS\cms\Fields' . static::$customDatabaseId;
|
||||
foreach( $className::data() AS $field )
|
||||
@@ -3558,6 +3655,26 @@ class _Records extends \IPS\Content\Item implements
|
||||
return $this->deleteLogPermissions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Online List Permissions
|
||||
*
|
||||
* @return string Comma-delimited values or '*'
|
||||
* @li Number indicates a group
|
||||
* @li Number prepended by "m" indicates a member
|
||||
* @li Number prepended by "s" indicates a social group
|
||||
*/
|
||||
public function onlineListPermissions()
|
||||
{
|
||||
/* If search is disabled for this database, we want to use the page/category permissions
|
||||
instead of falling back to searchIndexPermissions */
|
||||
if( ! static::database()->search )
|
||||
{
|
||||
return $this->container()->readPermissionMergeWithPage();
|
||||
}
|
||||
|
||||
return parent::onlineListPermissions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
@@ -3579,13 +3696,23 @@ class _Records extends \IPS\Content\Item implements
|
||||
* @apiresponse bool hidden Event is hidden
|
||||
* @apiresponse bool pinned Event is pinned
|
||||
* @apiresponse bool featured Event is featured
|
||||
* @apiresponse string url URL
|
||||
* @apiresponse string|NULL url URL, or NULL if the database has not been embedded onto a page
|
||||
* @apiresponse float rating Average Rating
|
||||
* @apiresponse string image Record Image
|
||||
* @apiresponse \IPS\forums\Topic topic The topic
|
||||
*/
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL )
|
||||
{
|
||||
/* You can have a database that is not embedded onto a page */
|
||||
try
|
||||
{
|
||||
$url = (string) $this->url();
|
||||
}
|
||||
catch( \LogicException $e )
|
||||
{
|
||||
$url = NULL;
|
||||
}
|
||||
|
||||
return array(
|
||||
'id' => $this->primary_id_field,
|
||||
'title' => $this->_title,
|
||||
@@ -3603,7 +3730,7 @@ class _Records extends \IPS\Content\Item implements
|
||||
'hidden' => (bool) $this->hidden(),
|
||||
'pinned' => (bool) $this->mapped('pinned'),
|
||||
'featured' => (bool) $this->mapped('featured'),
|
||||
'url' => (string) $this->url(),
|
||||
'url' => $url,
|
||||
'rating' => $this->averageRating(),
|
||||
'image' => $this->record_image ? (string) \IPS\File::get( 'cms_Records', $this->record_image )->url : null,
|
||||
'topic' => $this->topicid ? $this->topic()->apiOutput( $authorizedMember ) : NULL,
|
||||
@@ -3730,10 +3857,10 @@ class _Records extends \IPS\Content\Item implements
|
||||
/**
|
||||
* Get a count of the database table
|
||||
*
|
||||
*
|
||||
* @return int
|
||||
* @param bool $approximate Accept an approximate result if the table is large (approximate results are faster on large tables)
|
||||
* @return int
|
||||
*/
|
||||
public static function databaseTableCount()
|
||||
public static function databaseTableCount( bool $approximate=FALSE ): int
|
||||
{
|
||||
if ( static::$databaseTable == NULL )
|
||||
{
|
||||
@@ -3741,7 +3868,7 @@ class _Records extends \IPS\Content\Item implements
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::databaseTableCount();
|
||||
return parent::databaseTableCount( $approximate );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user