Version 4.7.0
This commit is contained in:
1 parent
517a5e1f70
commit
8ba7d43898
1933 files changed
+65613
-11332
No files matched your search
@@ -78,11 +78,6 @@ class _Records extends \IPS\Content\Item implements
|
||||
*/
|
||||
public static $module = 'records';
|
||||
|
||||
/**
|
||||
* @brief Database Column Map
|
||||
*/
|
||||
public static $databaseColumnMap = NULL;
|
||||
|
||||
/**
|
||||
* @brief Node Class
|
||||
*/
|
||||
@@ -123,6 +118,43 @@ class _Records extends \IPS\Content\Item implements
|
||||
*/
|
||||
protected static $standardFields = array( 'record_publish_date', 'record_expiry_date', 'record_allow_comments', 'record_comment_cutoff' );
|
||||
|
||||
/**
|
||||
* The real definition of this happens in the magic autoloader inside the cms\Application class, but we need this one which contains all the "none database id related" fields for the Content Widget
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public static $databaseColumnMap = array(
|
||||
'author' => 'member_id',
|
||||
'container' => 'category_id',
|
||||
'date' => 'record_publish_date',
|
||||
'is_future_entry' => 'record_future_date',
|
||||
'future_date' => 'record_publish_date',
|
||||
'num_comments' => 'record_comments',
|
||||
'unapproved_comments' => 'record_comments_queued',
|
||||
'hidden_comments' => 'record_comments_hidden',
|
||||
'last_comment' => 'record_last_comment',
|
||||
'last_comment_by' => 'record_last_comment_by',
|
||||
'last_comment_name' => 'record_last_comment_name',
|
||||
'views' => 'record_views',
|
||||
'approved' => 'record_approved',
|
||||
'pinned' => 'record_pinned',
|
||||
'locked' => 'record_locked',
|
||||
'featured' => 'record_featured',
|
||||
'rating' => 'record_rating',
|
||||
'rating_hits' => 'rating_hits',
|
||||
'rating_average' => 'record_rating',
|
||||
'rating_total' => 'rating_value',
|
||||
'num_reviews' => 'record_reviews',
|
||||
'last_review' => 'record_last_review',
|
||||
'last_review_by' => 'record_last_review_by',
|
||||
'last_review_name' => 'record_last_review_name',
|
||||
'updated' => 'record_last_comment',
|
||||
'meta_data' => 'record_meta_data',
|
||||
'author_name' => 'record_author_name',
|
||||
'is_anon' => 'record_is_anon',
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Icon
|
||||
*/
|
||||
@@ -148,6 +180,33 @@ class _Records extends \IPS\Content\Item implements
|
||||
return (bool) \IPS\cms\Databases::load( static::$customDatabaseId )->search;
|
||||
}
|
||||
|
||||
/**
|
||||
* Most, if not all of these are the same for different events, so we can just have one method
|
||||
*
|
||||
* @param IPS\Content\Comment $comment A comment item, leave null for these keys to be omitted
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDataLayerProperties( ?\IPS\Content\Comment $comment = null )
|
||||
{
|
||||
$commentIdColumn = $comment ? $comment::$databaseColumnId : null;
|
||||
$index = $commentIdColumn ? ( $comment->$commentIdColumn ?: 0 ) : 0;
|
||||
if ( isset( $this->_dataLayerProperties[$index] ) )
|
||||
{
|
||||
return $this->_dataLayerProperties[$index];
|
||||
}
|
||||
|
||||
/* Set the content_type and comment_type to lower case for consistency */
|
||||
$properties = parent::getDataLayerProperties( $comment );
|
||||
if ( isset( $properties['content_type'] ) )
|
||||
{
|
||||
$properties['content_type'] = \strtolower( \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->addToStack( static::$title ) );
|
||||
}
|
||||
|
||||
$this->_dataLayerProperties[$index] = $properties;
|
||||
return $properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct ActiveRecord from database row
|
||||
*
|
||||
@@ -591,7 +650,7 @@ class _Records extends \IPS\Content\Item implements
|
||||
$dims = array( 'maxWidth' => $fixedFieldSettings['record_image']['image_dims'][0], 'maxHeight' => $fixedFieldSettings['record_image']['image_dims'][1] );
|
||||
}
|
||||
|
||||
$formElements['record_image'] = new \IPS\Helpers\Form\Upload( 'record_image', ( ( $item and $item->record_image ) ? \IPS\File::get( 'cms_Records', $item->record_image ) : NULL ), FALSE, array( 'image' => $dims, 'storageExtension' => 'cms_Records', 'multiple' => false, 'allowStockPhotos' => true ), NULL, NULL, NULL, 'record_image' );
|
||||
$formElements['record_image'] = new \IPS\Helpers\Form\Upload( 'record_image', ( ( $item and $item->record_image ) ? \IPS\File::get( 'cms_Records', $item->record_image ) : NULL ), FALSE, array( 'image' => $dims, 'storageExtension' => 'cms_Records', 'multiple' => false, 'allowStockPhotos' => true, 'canBeModerated' => TRUE ), NULL, NULL, NULL, 'record_image' );
|
||||
}
|
||||
|
||||
if ( $fieldsClass::fixedFieldFormShow( 'record_expiry_date' ) )
|
||||
@@ -776,13 +835,16 @@ class _Records extends \IPS\Content\Item implements
|
||||
*/
|
||||
public function processForm( $values )
|
||||
{
|
||||
$isNew = $this->_new;
|
||||
$fieldsClass = 'IPS\cms\Fields' . static::$customDatabaseId;
|
||||
$database = \IPS\cms\Databases::load( static::$customDatabaseId );
|
||||
$categoryClass = 'IPS\cms\Categories' . static::$customDatabaseId;
|
||||
$container = ( ! isset( $values['content_record_form_container'] ) ? $categoryClass::load( $this->category_id ) : $values['content_record_form_container'] );
|
||||
|
||||
$autoSaveKeys = [];
|
||||
$imageUploads = [];
|
||||
|
||||
/* Store a revision */
|
||||
if ( $database->revisions AND ! $this->_new )
|
||||
if ( $database->revisions AND !$isNew )
|
||||
{
|
||||
$revision = new \IPS\cms\Records\Revisions;
|
||||
$revision->database_id = static::$customDatabaseId;
|
||||
@@ -797,7 +859,7 @@ class _Records extends \IPS\Content\Item implements
|
||||
$this->post_key = \IPS\Request::i()->postKey;
|
||||
}
|
||||
|
||||
if ( $this->_new )
|
||||
if ( $isNew )
|
||||
{
|
||||
/* Peanut Butter Registering */
|
||||
if ( !\IPS\Member::loggedIn()->member_id and $container and !$container->can( 'add', \IPS\Member::loggedIn(), FALSE ) )
|
||||
@@ -875,7 +937,7 @@ class _Records extends \IPS\Content\Item implements
|
||||
}
|
||||
|
||||
/* Edit stuff */
|
||||
if ( ! $this->_new )
|
||||
if ( !$isNew )
|
||||
{
|
||||
if ( isset( $values['record_edit_reason'] ) )
|
||||
{
|
||||
@@ -919,6 +981,7 @@ class _Records extends \IPS\Content\Item implements
|
||||
}
|
||||
else
|
||||
{
|
||||
$imageUploads[] = $values['record_image'];
|
||||
$fixedFieldSettings = static::database()->fixed_field_settings;
|
||||
|
||||
if ( isset( $fixedFieldSettings['record_image']['thumb_dims'] ) )
|
||||
@@ -963,7 +1026,7 @@ class _Records extends \IPS\Content\Item implements
|
||||
|
||||
/* Custom fields */
|
||||
$customValues = array();
|
||||
$afterEditNotificationsExclude = array();
|
||||
$afterEditNotificationsExclude = [ 'quotes' => [], 'mentions' => [] ];
|
||||
|
||||
foreach( $values as $k => $v )
|
||||
{
|
||||
@@ -977,17 +1040,18 @@ class _Records extends \IPS\Content\Item implements
|
||||
|
||||
if ( static::$customFields === NULL )
|
||||
{
|
||||
static::$customFields = $fieldsClass::fields( $customValues, ( $this->_new ? 'add' : 'edit' ), $container, 0, ( $this->_new ? NULL : $this ) );
|
||||
static::$customFields = $fieldsClass::fields( $customValues, ( $isNew ? 'add' : 'edit' ), $container, 0, ( $isNew ? NULL : $this ) );
|
||||
}
|
||||
|
||||
$seen = [];
|
||||
|
||||
foreach( static::$customFields as $key => $field )
|
||||
{
|
||||
$seen[] = $key;
|
||||
$key = 'field_' . $key;
|
||||
$fieldId = $key;
|
||||
$seen[] = $fieldId;
|
||||
$key = 'field_' . $fieldId;
|
||||
|
||||
if ( !$this->_new )
|
||||
if ( !$isNew )
|
||||
{
|
||||
$afterEditNotificationsExclude = array_merge_recursive( static::_getQuoteAndMentionIdsFromContent( $this->$key ) );
|
||||
}
|
||||
@@ -999,12 +1063,14 @@ class _Records extends \IPS\Content\Item implements
|
||||
$items = array();
|
||||
foreach( $customValues[ $field->name ] as $obj )
|
||||
{
|
||||
$imageUploads[] = $obj;
|
||||
$items[] = (string) $obj;
|
||||
}
|
||||
$this->$key = implode( ',', $items );
|
||||
}
|
||||
else
|
||||
{
|
||||
$imageUploads[] = $customValues[ $field->name ];
|
||||
$this->$key = (string) $customValues[ $field->name ];
|
||||
}
|
||||
}
|
||||
@@ -1015,12 +1081,17 @@ class _Records extends \IPS\Content\Item implements
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( \get_class( $field ) == 'IPS\Helpers\Form\Editor' )
|
||||
{
|
||||
$autoSaveKeys[] = $isNew ? "RecordField_new_{$fieldId}" : [ $this->_id, $fieldId, static::$customDatabaseId ];
|
||||
}
|
||||
|
||||
$this->$key = $field::stringValue( isset( $customValues[ $field->name ] ) ? $customValues[ $field->name ] : NULL );
|
||||
}
|
||||
}
|
||||
|
||||
/* Now set up defaults */
|
||||
if ( $this->_new )
|
||||
if ( $isNew )
|
||||
{
|
||||
foreach ( $fieldObjects as $obj )
|
||||
{
|
||||
@@ -1034,7 +1105,7 @@ class _Records extends \IPS\Content\Item implements
|
||||
}
|
||||
|
||||
/* Other data */
|
||||
if ( $this->_new OR $database->_comment_bump & \IPS\cms\Databases::BUMP_ON_EDIT )
|
||||
if ( $isNew OR $database->_comment_bump & \IPS\cms\Databases::BUMP_ON_EDIT )
|
||||
{
|
||||
$this->record_saved = time();
|
||||
$this->record_updated = time();
|
||||
@@ -1060,7 +1131,7 @@ class _Records extends \IPS\Content\Item implements
|
||||
}
|
||||
else
|
||||
{
|
||||
if( $this->_new )
|
||||
if( $isNew )
|
||||
{
|
||||
$this->record_static_furl = NULL;
|
||||
}
|
||||
@@ -1072,12 +1143,12 @@ class _Records extends \IPS\Content\Item implements
|
||||
}
|
||||
}
|
||||
|
||||
$sendFilterNotifications = $this->checkProfanityFilters( FALSE, $this->_new );
|
||||
$sendFilterNotifications = $this->checkProfanityFilters( FALSE, !$isNew, NULL, NULL, 'cms_Records' . static::$customDatabaseId, $autoSaveKeys, $imageUploads );
|
||||
|
||||
if ( $this->_new )
|
||||
if ( $isNew )
|
||||
{
|
||||
/* Set the author ID on 'new' only */
|
||||
$this->member_id = (int) \IPS\Member::loggedIn()->member_id;
|
||||
$this->member_id = (int) ( static::$createWithMember ? static::$createWithMember->member_id : \IPS\Member::loggedIn()->member_id );
|
||||
}
|
||||
elseif ( !$sendFilterNotifications )
|
||||
{
|
||||
@@ -1089,7 +1160,6 @@ class _Records extends \IPS\Content\Item implements
|
||||
$this->category_id = ( $values['content_record_form_container'] === 0 ) ? 0 : $values['content_record_form_container']->id;
|
||||
}
|
||||
|
||||
$isNew = $this->_new;
|
||||
$idColumn = static::$databaseColumnId;
|
||||
if ( ! $this->$idColumn )
|
||||
{
|
||||
@@ -1567,7 +1637,7 @@ class _Records extends \IPS\Content\Item implements
|
||||
}
|
||||
}
|
||||
|
||||
return \count( $attachments ) ? $attachments : NULL;
|
||||
return \count( $attachments ) ? \array_slice( $attachments, 0, $limit ) : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1839,7 +1909,7 @@ class _Records extends \IPS\Content\Item implements
|
||||
*/
|
||||
public function get__record_image_thumb()
|
||||
{
|
||||
return $this->record_image_thumb ? $this->record_image_thumb : $this->record_image;
|
||||
return $this->record_image_thumb ?: $this->record_image;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2099,7 +2169,15 @@ class _Records extends \IPS\Content\Item implements
|
||||
*/
|
||||
public function useForumComments()
|
||||
{
|
||||
return $this->_forum_record and $this->_forum_comments and $this->record_topicid and \IPS\Application::appIsEnabled('forums');
|
||||
try
|
||||
{
|
||||
return $this->_forum_record and $this->_forum_comments and $this->record_topicid and \IPS\Application::appIsEnabled('forums');
|
||||
}
|
||||
catch( \Exception $e)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2358,6 +2436,11 @@ class _Records extends \IPS\Content\Item implements
|
||||
*/
|
||||
protected static $creatingRecord = FALSE;
|
||||
|
||||
/**
|
||||
* @brief Store the member we are creating with if not the logged in member
|
||||
*/
|
||||
protected static $createWithMember = NULL;
|
||||
|
||||
/**
|
||||
* Create from form
|
||||
*
|
||||
@@ -2368,6 +2451,11 @@ class _Records extends \IPS\Content\Item implements
|
||||
*/
|
||||
public static function createFromForm( $values, \IPS\Node\Model $container = NULL, $sendNotification = TRUE )
|
||||
{
|
||||
if ( isset( $values['record_author_choice'] ) and $values['record_author_choice'] == 'notme' )
|
||||
{
|
||||
static::$createWithMember = $values['record_member_id'];
|
||||
}
|
||||
|
||||
static::$creatingRecord = TRUE;
|
||||
$record = parent::createFromForm( $values, $container, $sendNotification );
|
||||
static::$creatingRecord = FALSE;
|
||||
@@ -2384,6 +2472,22 @@ class _Records extends \IPS\Content\Item implements
|
||||
return $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create generic object
|
||||
*
|
||||
* @param \IPS\Member $author The author
|
||||
* @param string|NULL $ipAddress The IP address
|
||||
* @param \IPS\DateTime $time The time
|
||||
* @param \IPS\Node\Model|NULL $container Container (e.g. forum), if appropriate
|
||||
* @param bool|NULL $hidden Hidden? (NULL to work our automatically)
|
||||
* @return static
|
||||
*/
|
||||
public static function createItem( \IPS\Member $author, $ipAddress, \IPS\DateTime $time, \IPS\Node\Model $container = NULL, $hidden=NULL )
|
||||
{
|
||||
/* This is fired inside createFromForm, and we need to switch the author? */
|
||||
return parent::createItem( static::$createWithMember !== NULL ? static::$createWithMember : $author, $ipAddress, $time, $container, $hidden );
|
||||
}
|
||||
|
||||
/**
|
||||
* Process after the object has been edited on the front-end
|
||||
*
|
||||
@@ -3155,11 +3259,17 @@ class _Records extends \IPS\Content\Item implements
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Am I a Moderator with edit permissions ?*/
|
||||
if( $this->container()->modPermission( 'edit', $member, \get_called_class() ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if ( parent::canEdit( $member ) )
|
||||
{
|
||||
/* Test against specific perms for this category */
|
||||
return $this->container()->can( 'edit', $member ) or $this->container()->modPermission( 'edit', $member, \get_called_class() );
|
||||
return $this->container()->can( 'edit', $member );
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
@@ -3713,7 +3823,7 @@ class _Records extends \IPS\Content\Item implements
|
||||
$url = NULL;
|
||||
}
|
||||
|
||||
return array(
|
||||
$return = array(
|
||||
'id' => $this->primary_id_field,
|
||||
'title' => $this->_title,
|
||||
'category' => $this->container() ? $this->container()->apiOutput() : null,
|
||||
@@ -3735,6 +3845,35 @@ class _Records extends \IPS\Content\Item implements
|
||||
'image' => $this->record_image ? (string) \IPS\File::get( 'cms_Records', $this->record_image )->url : null,
|
||||
'topic' => $this->topicid ? $this->topic()->apiOutput( $authorizedMember ) : NULL,
|
||||
);
|
||||
|
||||
if ( \IPS\IPS::classUsesTrait( $this, 'IPS\Content\Reactable' ) )
|
||||
{
|
||||
if ( $reactions = $this->reactions() )
|
||||
{
|
||||
$enabledReactions = \IPS\Content\Reaction::enabledReactions();
|
||||
$finalReactions = [];
|
||||
foreach( $reactions as $memberId => $array )
|
||||
{
|
||||
foreach( $array as $reaction )
|
||||
{
|
||||
$finalReactions[ $memberId ][] = [
|
||||
'title' => $enabledReactions[ $reaction ]->_title,
|
||||
'id' => $reaction,
|
||||
'value' => $enabledReactions[ $reaction ]->value,
|
||||
'icon' => (string) $enabledReactions[ $reaction ]->_icon->url
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$return['reactions'] = $finalReactions;
|
||||
}
|
||||
else
|
||||
{
|
||||
$return['reactions'] = [];
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user