Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
@@ -31,14 +31,31 @@ class _NodeController extends \IPS\Api\Controller
|
||||
protected function _list( $where = array() )
|
||||
{
|
||||
$class = $this->class;
|
||||
|
||||
if ( $this->member and in_array( 'IPS\Node\Permissions', class_implements( $class ) ) )
|
||||
{
|
||||
$where[] = array( '(' . \IPS\Db::i()->findInSet( 'core_permission_index.perm_' . $class::$permissionMap['view'], $this->member->permissionArray() ) . ' OR ' . 'core_permission_index.perm_' . $class::$permissionMap['view'] . '=? )', '*' );
|
||||
if ( $class::$databaseColumnEnabledDisabled )
|
||||
{
|
||||
$where[] = array( $class::$databasePrefix . $class::$databaseColumnEnabledDisabled . '=1' );
|
||||
}
|
||||
}
|
||||
|
||||
$select = \IPS\Db::i()->select( '*', $class::$databaseTable, $where, $class::$databaseColumnOrder ? $class::$databasePrefix . $class::$databaseColumnOrder . " asc" : NULL, NULL, NULL, NULL, \IPS\Db::SELECT_SQL_CALC_FOUND_ROWS );
|
||||
if ( $this->member and in_array( 'IPS\Node\Permissions', class_implements( $class ) ) )
|
||||
{
|
||||
$select->join( 'core_permission_index', array( "core_permission_index.app=? AND core_permission_index.perm_type=? AND core_permission_index.perm_type_id=" . $class::$databaseTable . "." . $class::$databasePrefix . $class::$databaseColumnId, $class::$permApp, $class::$permType ) );
|
||||
}
|
||||
|
||||
/* Return */
|
||||
return new \IPS\Api\PaginatedResponse(
|
||||
200,
|
||||
\IPS\Db::i()->select( '*', $class::$databaseTable, $where, $class::$databaseColumnOrder ? $class::$databaseColumnOrder . " asc" : NULL ),
|
||||
$select,
|
||||
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
|
||||
$class,
|
||||
\IPS\Db::i()->select( 'COUNT(*)', $class::$databaseTable, $where )->first()
|
||||
$select->count( TRUE ),
|
||||
$this->member,
|
||||
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
|
||||
);
|
||||
}
|
||||
|
||||
@@ -51,7 +68,14 @@ class _NodeController extends \IPS\Api\Controller
|
||||
protected function _view( $id )
|
||||
{
|
||||
$class = $this->class;
|
||||
return new \IPS\Api\Response( 200, $class::load( $id )->apiOutput() );
|
||||
|
||||
$node = $class::load( $id );
|
||||
if ( $this->member and !$node->can( 'view', $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 200, $node->apiOutput( $this->member ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +115,6 @@ class _NodeController extends \IPS\Api\Controller
|
||||
return $node;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create
|
||||
*
|
||||
|
||||
@@ -127,7 +127,7 @@ trait Colorize
|
||||
|
||||
|
||||
/**
|
||||
* Get URL from index data
|
||||
* Get title from index data
|
||||
*
|
||||
* @param array $indexData Data from the search index
|
||||
* @param array $itemData Basic data about the item. Only includes columns returned by item::basicDataColumns()
|
||||
@@ -136,23 +136,23 @@ trait Colorize
|
||||
*/
|
||||
public static function titleFromIndexData( $indexData, $itemData, $containerData )
|
||||
{
|
||||
if ( ! isset( $containerData[ static::$featureColumnName ] ) )
|
||||
if ( ! isset( $containerData[ static::$databasePrefix . static::$featureColumnName ] ) )
|
||||
{
|
||||
return parent::titleFromIndexData( $indexData, $itemData, $containerData );
|
||||
}
|
||||
|
||||
$node = $containerData;
|
||||
$node['title'] = \IPS\Member::loggedIn()->language()->addToStack( static::$titleLangPrefix . $indexData['index_container_id'], 'NULL', array( 'escape' => true ) );
|
||||
$node['text_color'] = static::featureTextColor( $node[ static::$featureColumnName ] );
|
||||
$node['text_color'] = static::featureTextColor( $node[ static::$databasePrefix . static::$featureColumnName ] );
|
||||
|
||||
/* Normalize */
|
||||
$node['feature_color'] = $node[ static::$featureColumnName ];
|
||||
$node['feature_color'] = $node[ static::$databasePrefix . static::$featureColumnName ];
|
||||
|
||||
$title = \IPS\Theme::i()->getTemplate( 'global', 'core', 'front' )->formattedTitle( $node );
|
||||
|
||||
if ( $indexData['index_club_id'] and isset( $containerData['_club'] ) )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'club_container_title', FALSE, array( 'htmlsprintf' => array( $containerData['_club']['name'], $title ) ) );
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'club_container_title', FALSE, array( 'sprintf' => array( $containerData['_club']['name'] ), 'htmlsprintf' => array( $title ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+57
-12
@@ -109,6 +109,11 @@ class _Controller extends \IPS\Dispatcher\Controller
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the "add" button in the page root rather than the table root
|
||||
*/
|
||||
protected $_addButtonInRoot = TRUE;
|
||||
|
||||
/**
|
||||
* Get Root Buttons
|
||||
*
|
||||
@@ -127,7 +132,7 @@ class _Controller extends \IPS\Dispatcher\Controller
|
||||
'data' => ( $nodeClass::$modalForms ? array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('add') ) : array() )
|
||||
);
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
if ( \IPS\Request::i()->isAjax() or !$this->_addButtonInRoot )
|
||||
{
|
||||
return array( 'add' => $add );
|
||||
}
|
||||
@@ -150,6 +155,17 @@ class _Controller extends \IPS\Dispatcher\Controller
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch any additional HTML for this row
|
||||
*
|
||||
* @param object $node Node returned from $nodeClass::load()
|
||||
* @return NULL|string
|
||||
*/
|
||||
public function _getRowHtml( $node )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Single Row
|
||||
*
|
||||
@@ -189,7 +205,7 @@ class _Controller extends \IPS\Dispatcher\Controller
|
||||
return \IPS\Theme::i()->getTemplate( 'trees', 'core' )->row(
|
||||
$this->url,
|
||||
$id,
|
||||
$node->_title,
|
||||
static::nodeTitle( $node ),
|
||||
$node->childrenCount( NULL ),
|
||||
$buttons,
|
||||
$node->_description,
|
||||
@@ -202,7 +218,8 @@ class _Controller extends \IPS\Dispatcher\Controller
|
||||
$this->_titleHtml,
|
||||
$this->_descriptionHtml,
|
||||
$node->canAdd(),
|
||||
( $node instanceof $nodeClass )
|
||||
( $node instanceof $nodeClass ),
|
||||
$this->_getRowHtml( $node )
|
||||
);
|
||||
}
|
||||
|
||||
@@ -513,7 +530,7 @@ class _Controller extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
try
|
||||
{
|
||||
$node = call_user_func( "{$nodeClass}::load", \IPS\Request::i()->from );
|
||||
$node = $nodeClass::load( \IPS\Request::i()->from );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -732,7 +749,7 @@ class _Controller extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
try
|
||||
{
|
||||
$node = call_user_func( "{$nodeClass}::load", \IPS\Request::i()->id );
|
||||
$node = $nodeClass::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -845,6 +862,9 @@ class _Controller extends \IPS\Dispatcher\Controller
|
||||
/* Copy it */
|
||||
$new = clone $node;
|
||||
\IPS\Session::i()->log( 'acplog__node_copied', array( $this->title => TRUE, $node->titleForLog() => FALSE ) );
|
||||
|
||||
/* Clear create menu */
|
||||
\IPS\Member::clearCreateMenu();
|
||||
|
||||
/* Boink */
|
||||
$url = $this->url->setQueryString( array( 'do' => 'form', 'id' => $new->_id ) );
|
||||
@@ -939,7 +959,7 @@ class _Controller extends \IPS\Dispatcher\Controller
|
||||
|
||||
if( $parent !== 'null' )
|
||||
{
|
||||
$node = call_user_func( array( $nodeClass, 'load' ), $parent );
|
||||
$node = $nodeClass::load( $parent );
|
||||
$node->setLastComment();
|
||||
$node->setLastReview();
|
||||
$node->save();
|
||||
@@ -998,7 +1018,7 @@ class _Controller extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
try
|
||||
{
|
||||
$node = call_user_func( "{$nodeClass}::load", \IPS\Request::i()->id );
|
||||
$node = $nodeClass::load( \IPS\Request::i()->id );
|
||||
\IPS\Output::i()->title = $node->_title;
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
@@ -1006,6 +1026,10 @@ class _Controller extends \IPS\Dispatcher\Controller
|
||||
\IPS\Output::i()->error( 'node_error', '2S101/M', 404, '' );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2S101/X', 404, '' );
|
||||
}
|
||||
|
||||
/* Check permission */
|
||||
if( !$node->canManagePermissions() )
|
||||
@@ -1054,7 +1078,19 @@ class _Controller extends \IPS\Dispatcher\Controller
|
||||
},
|
||||
);
|
||||
|
||||
$disabledPermissions = $node->disabledPermissions();
|
||||
try
|
||||
{
|
||||
$disabledPermissions = $node->disabledPermissions();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
if( $e->getCode() != 199 )
|
||||
{
|
||||
throw $e;
|
||||
}
|
||||
|
||||
\IPS\Output::i()->error( 'generic_error', '4F383/1', 500, $e->getMessage() );
|
||||
}
|
||||
|
||||
foreach ( $node->permissionTypes() as $k => $v )
|
||||
{
|
||||
@@ -1173,7 +1209,7 @@ class _Controller extends \IPS\Dispatcher\Controller
|
||||
|
||||
try
|
||||
{
|
||||
$node = call_user_func( "{$nodeClass}::load", \IPS\Request::i()->id );
|
||||
$node = $nodeClass::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -1244,7 +1280,7 @@ class _Controller extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
try
|
||||
{
|
||||
$node = call_user_func( "{$nodeClass}::load", \IPS\Request::i()->id );
|
||||
$node = $nodeClass::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -1415,8 +1451,6 @@ class _Controller extends \IPS\Dispatcher\Controller
|
||||
),
|
||||
$this->url->setQueryString( array( 'do' => 'massManageContent', 'id' => $node->_id ) )
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1452,4 +1486,15 @@ class _Controller extends \IPS\Dispatcher\Controller
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'trees', 'core' )->rows( $rows, '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow overloading to change how the title is displayed in the tree
|
||||
*
|
||||
* @param $node \IPS\Node Node
|
||||
* @return string
|
||||
*/
|
||||
protected static function nodeTitle( $node )
|
||||
{
|
||||
return $node->_title;
|
||||
}
|
||||
}
|
||||
+101
-60
@@ -142,21 +142,7 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
}
|
||||
|
||||
/* Have we got a cached result we can use? */
|
||||
if ( $usingPermssions )
|
||||
{
|
||||
$cacheKey = md5( get_called_class() . $permissionCheck . $member->member_id . json_encode( $where ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$cacheKey = md5( get_called_class() . $permissionCheck . json_encode( $where ) );
|
||||
}
|
||||
if( isset( static::$rootsResult[ $cacheKey ] ) )
|
||||
{
|
||||
return static::$rootsResult[ $cacheKey ];
|
||||
}
|
||||
|
||||
|
||||
/* Specify that we only want the ones without a parent */
|
||||
if( static::$databaseColumnParent !== NULL )
|
||||
{
|
||||
@@ -168,7 +154,22 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
$where[] = array( static::$databasePrefix . static::clubIdColumn() . ' IS NULL' );
|
||||
}
|
||||
|
||||
|
||||
/* Have we got a cached result we can use? */
|
||||
if ( $usingPermssions )
|
||||
{
|
||||
$cacheKey = md5( get_called_class() . $permissionCheck . $member->member_id . json_encode( $where ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$cacheKey = md5( get_called_class() . $permissionCheck . json_encode( $where ) );
|
||||
}
|
||||
|
||||
if( isset( static::$rootsResult[ $cacheKey ] ) )
|
||||
{
|
||||
return static::$rootsResult[ $cacheKey ];
|
||||
}
|
||||
|
||||
/* Fetch */
|
||||
$nodes = static::nodesWithPermission( $usingPermssions ? $permissionCheck : NULL, $member, $where );
|
||||
|
||||
@@ -185,13 +186,15 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
* @param string|NULL $permissionCheck The permission key to check for or NULl to not check permissions
|
||||
* @param \IPS\Member|NULL $member The member to check permissions for or NULL for the currently logged in member
|
||||
* @param mixed $where Additional WHERE clause
|
||||
* @param string $order ORDER BY clause
|
||||
* @return array
|
||||
*/
|
||||
protected static function nodesWithPermission( $permissionCheck, $member, $where=array() )
|
||||
protected static function nodesWithPermission( $permissionCheck, $member, $where=array(), $order=NULL )
|
||||
{
|
||||
/* Permission check? */
|
||||
if ( $permissionCheck )
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
$where[] = array( '(' . \IPS\Db::i()->findInSet( 'core_permission_index.perm_' . static::$permissionMap[ $permissionCheck ], $member->permissionArray() ) . ' OR ' . 'core_permission_index.perm_' . static::$permissionMap[ $permissionCheck ] . '=? )', '*' );
|
||||
if ( static::$databaseColumnEnabledDisabled )
|
||||
{
|
||||
@@ -200,12 +203,11 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
|
||||
/* Specify the order */
|
||||
$order = NULL;
|
||||
if( static::$databaseColumnOrder !== NULL )
|
||||
if( $order == NULL and static::$databaseColumnOrder !== NULL )
|
||||
{
|
||||
$order = static::$databasePrefix . static::$databaseColumnOrder;
|
||||
}
|
||||
|
||||
|
||||
/* Select */
|
||||
$select = \IPS\Db::i()->select( '*', static::$databaseTable, $where, $order );
|
||||
if ( $permissionCheck )
|
||||
@@ -224,7 +226,7 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
|
||||
|
||||
/* Return */
|
||||
return $nodes;
|
||||
}
|
||||
@@ -480,6 +482,7 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
* Get URL
|
||||
*
|
||||
* @return \IPS\Http\Url
|
||||
* @throws BadMethodCallException
|
||||
*/
|
||||
public function url()
|
||||
{
|
||||
@@ -508,7 +511,7 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
/* Using colorize trait? We can't check the object but we can check the added class variable */
|
||||
if ( isset( static::$featureColumnName ) )
|
||||
{
|
||||
$return[] = static::$featureColumnName;
|
||||
$return[] = static::$databasePrefix . static::$featureColumnName;
|
||||
}
|
||||
|
||||
return $return;
|
||||
@@ -528,7 +531,7 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL from index data
|
||||
* Get title from index data
|
||||
*
|
||||
* @param array $indexData Data from the search index
|
||||
* @param array $itemData Basic data about the item. Only includes columns returned by item::basicDataColumns()
|
||||
@@ -635,17 +638,36 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* [Node] Get Title
|
||||
*
|
||||
* @return string|null
|
||||
* @return string
|
||||
*/
|
||||
protected function get__title()
|
||||
{
|
||||
if ( static::$titleLangPrefix )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( static::$titleLangPrefix . $this->_id );
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( static::$titleLangPrefix . $this->_id, NULL, array( 'escape' => TRUE ) );
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title for a node using the specified language object
|
||||
* This is commonly used where we cannot use the logged in member's language, such as sending emails
|
||||
*
|
||||
* @param \IPS\Lang $language Language object to fetch the title with
|
||||
* @param array $options What options to use for language parsing
|
||||
* @return string
|
||||
*/
|
||||
public function getTitleForLanguage( $language, $options=array() )
|
||||
{
|
||||
if ( static::$titleLangPrefix )
|
||||
{
|
||||
return $language->addToStack( static::$titleLangPrefix . $this->_id, NULL, $options );
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get Title language key, not added to a language stack
|
||||
*
|
||||
@@ -662,16 +684,13 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
|
||||
/**
|
||||
* Node titles can contain HTML. Apparently.
|
||||
* @deprecated in 4.3, will be removed in 4.4.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get__stripTagsTitle()
|
||||
{
|
||||
if ( static::$titleLangPrefix )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( static::$titleLangPrefix . $this->_id, NULL, array( 'striptags' => true ) );
|
||||
}
|
||||
return '';
|
||||
return $this->_title;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -729,7 +748,7 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
*/
|
||||
public function metaTitle()
|
||||
{
|
||||
return $this->_stripTagsTitle;
|
||||
return $this->_title;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1807,10 +1826,11 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
*
|
||||
* @param mixed $permission A key which has a value in static::$permissionMap['view'] matching a column ID in core_permission_index
|
||||
* @param \IPS\Member|\IPS\Member\Group|NULL $member The member or group to check (NULL for currently logged in member)
|
||||
* @param array $where Additional WHERE clause
|
||||
* @return bool
|
||||
* @throws \OutOfBoundsException If $permission does not exist in static::$permissionMap
|
||||
*/
|
||||
public static function canOnAny( $permission, $member=NULL )
|
||||
public static function canOnAny( $permission, $member=NULL, $where = array() )
|
||||
{
|
||||
/* If this is not permission-dependant, return TRUE */
|
||||
if ( !in_array( 'IPS\Node\Permissions', class_implements( get_called_class() ) ) )
|
||||
@@ -1821,7 +1841,7 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
/* Check it exists */
|
||||
if ( !isset( static::$permissionMap[ $permission ] ) )
|
||||
{
|
||||
throw \OutOfBoundsException;
|
||||
throw new \OutOfBoundsException;
|
||||
}
|
||||
|
||||
/* Load member */
|
||||
@@ -1836,28 +1856,25 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$_key = md5( get_called_class() );
|
||||
$_key = md5( get_called_class() . json_encode( $where ) );
|
||||
|
||||
/* Have we already cached the check? */
|
||||
if( isset( static::$_canOnAny[ $_key ] ) )
|
||||
if( isset( static::$_canOnAny[ $_key ][ $permission ] ) )
|
||||
{
|
||||
return static::$_canOnAny[ $_key ];
|
||||
return static::$_canOnAny[ $_key ][ $permission ];
|
||||
}
|
||||
|
||||
/* Return */
|
||||
$where = array( );
|
||||
$where[] = array( \IPS\Db::i()->findInSet( 'core_permission_index.perm_' . static::$permissionMap[ $permission ], $member->groups ) . ' OR core_permission_index.perm_' . static::$permissionMap[ $permission ] . "='*'" );
|
||||
if ( static::$databaseColumnEnabledDisabled )
|
||||
{
|
||||
static::$_canOnAny[ $_key ] = (bool) \IPS\Db::i()->select( 'COUNT(*)', static::$databaseTable, array( static::$databasePrefix . static::$databaseColumnEnabledDisabled . '=1 AND (' . \IPS\Db::i()->findInSet( 'core_permission_index.perm_' . static::$permissionMap[ $permission ], $member->groups ) . ' OR core_permission_index.perm_' . static::$permissionMap[ $permission ] . "='*' )" ) )
|
||||
->join( 'core_permission_index', array( "core_permission_index.app=? AND core_permission_index.perm_type=? AND core_permission_index.perm_type_id=" . static::$databaseTable . "." . static::$databasePrefix . static::$databaseColumnId, static::$permApp, static::$permType ) )
|
||||
->first();
|
||||
}
|
||||
else
|
||||
{
|
||||
static::$_canOnAny[ $_key ] = (bool) \IPS\Db::i()->select( 'COUNT(*)', 'core_permission_index', array( 'core_permission_index.app=? AND core_permission_index.perm_type=? AND (' . \IPS\Db::i()->findInSet( 'core_permission_index.perm_' . static::$permissionMap[ $permission ], $member->groups ) . ' OR core_permission_index.perm_' . static::$permissionMap[ $permission ] . "='*' )", static::$permApp, static::$permType ) )->first();
|
||||
$where[] = array( static::$databasePrefix . static::$databaseColumnEnabledDisabled . '=1' );
|
||||
}
|
||||
static::$_canOnAny[ $_key ][ $permission ] = (bool) \IPS\Db::i()->select( 'COUNT(*)', static::$databaseTable, $where )
|
||||
->join( 'core_permission_index', array( "core_permission_index.app=? AND core_permission_index.perm_type=? AND core_permission_index.perm_type_id=" . static::$databaseTable . "." . static::$databasePrefix . static::$databaseColumnId, static::$permApp, static::$permType ) )
|
||||
->first();
|
||||
|
||||
return static::$_canOnAny[ $_key ];
|
||||
return static::$_canOnAny[ $_key ][ $permission ];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1865,6 +1882,7 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
* Allow node classes to define permissions that are unselectable in the permission matrix
|
||||
*
|
||||
* @return array array( {group_id} => array( 'read', 'view', 'perm_7' );
|
||||
* @throws UnderflowException (if guest group ID is invalid)
|
||||
*/
|
||||
public function disabledPermissions()
|
||||
{
|
||||
@@ -1987,6 +2005,7 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
* @return array
|
||||
* @throws
|
||||
* @li BadMethodCallException
|
||||
* @li UnderflowException (if guest group ID is invalid)
|
||||
*/
|
||||
public static function populatePermissionMatrix( &$rows, $node, $group, $current, $level=0 )
|
||||
{
|
||||
@@ -2100,6 +2119,17 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
/* If we are checking view permissions, make sure we can view parent too */
|
||||
if( $permission == 'view' )
|
||||
{
|
||||
/* If this is a club node, make sure we can access the clubs module */
|
||||
if ( \IPS\IPS::classUsesTrait( get_called_class(), 'IPS\Content\ClubContainer' ) AND $this->club() )
|
||||
{
|
||||
if ( !$member->canAccessModule( \IPS\Application\Module::get( 'core', 'clubs', 'front' ) ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Let the rest of the method bubble up as necessary */
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
foreach( $this->parents() as $parent )
|
||||
@@ -2131,11 +2161,11 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
|
||||
if( $member instanceof \IPS\Member\Group )
|
||||
{
|
||||
return ( $permissions[ 'perm_' . static::$permissionMap[ $permission ] ] === '*' or ( $permissions[ 'perm_' . static::$permissionMap[ $permission ] ] and in_array( $member->g_id, explode( ',', $permissions[ 'perm_' . static::$permissionMap[ $permission ] ] ) ) ) );
|
||||
return ( $permissions[ 'perm_' . static::$permissionMap[ $permission ] ] === '*' or ( $permissions[ 'perm_' . static::$permissionMap[ $permission ] ] and in_array( $member->g_id, array_filter( explode( ',', $permissions[ 'perm_' . static::$permissionMap[ $permission ] ] ) ) ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return ( $permissions[ 'perm_' . static::$permissionMap[ $permission ] ] === '*' or ( $permissions[ 'perm_' . static::$permissionMap[ $permission ] ] and array_intersect( explode( ',', $permissions[ 'perm_' . static::$permissionMap[ $permission ] ] ), $member->permissionArray() ) ) );
|
||||
return ( $permissions[ 'perm_' . static::$permissionMap[ $permission ] ] === '*' or ( $permissions[ 'perm_' . static::$permissionMap[ $permission ] ] and array_intersect( array_filter( explode( ',', $permissions[ 'perm_' . static::$permissionMap[ $permission ] ] ) ), $member->permissionArray() ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2144,13 +2174,14 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
*
|
||||
* @param string $type 'edit', 'hide', 'unhide', 'delete', etc.
|
||||
* @param \IPS\Member|NULL $member The member to check for or NULL for the currently logged in member
|
||||
* @param string|NULL $itemClass The item class to check against, or NULL to check against static::$contentItemClass
|
||||
* @return bool
|
||||
*/
|
||||
public function modPermission( $type, \IPS\Member $member )
|
||||
public function modPermission( $type, \IPS\Member $member, $itemClass=NULL )
|
||||
{
|
||||
if ( isset( static::$modPerm ) )
|
||||
{
|
||||
$itemClass = static::$contentItemClass;
|
||||
$itemClass = $itemClass ?: static::$contentItemClass;
|
||||
$title = $itemClass::$title;
|
||||
if ( $member->modPermission( "can_{$type}_{$title}" ) )
|
||||
{
|
||||
@@ -2378,7 +2409,7 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
if ( $this->_items !== NULL )
|
||||
{
|
||||
$this->_items = \IPS\Db::i()->select( 'COUNT(*)', $itemClass::$databaseTable, $containerWhere )->first();
|
||||
$this->_items = \IPS\Db::i()->select( 'COUNT(*)', $itemClass::$databaseTable, $containerWhere, NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
}
|
||||
if ( $this->_comments !== NULL AND $commentClass !== NULL )
|
||||
{
|
||||
@@ -2410,8 +2441,8 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
|
||||
$this->_comments = \IPS\Db::i()->select( 'COUNT(*)', array(
|
||||
array( $commentClass::$databaseTable, $commentClass::$databaseTable ),
|
||||
array( $itemClass::$databaseTable, $itemClass::$databaseTable )
|
||||
), $commentWhere )->first();
|
||||
array( $itemClass::$databaseTable, $itemClass::$databaseTable ),
|
||||
), $commentWhere, NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
}
|
||||
|
||||
if ( $this->_reviews !== NULL AND $reviewClass !== NULL )
|
||||
@@ -2433,7 +2464,7 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
$this->_reviews = \IPS\Db::i()->select( 'COUNT(*)', array(
|
||||
array( $reviewClass::$databaseTable, $reviewClass::$databaseTable ),
|
||||
array( $itemClass::$databaseTable, $itemClass::$databaseTable )
|
||||
), $reviewWhere )->first();
|
||||
), $reviewWhere, NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
}
|
||||
|
||||
if ( in_array( 'IPS\Content\Hideable', class_implements( $itemClass ) ) )
|
||||
@@ -2451,7 +2482,7 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
$hiddenContainerWhere[] = array( $itemClass::$databasePrefix . $itemClass::$databaseColumnMap['hidden'] . '=?', 1 );
|
||||
}
|
||||
|
||||
$this->_unapprovedItems = \IPS\Db::i()->select( 'COUNT(*)', $itemClass::$databaseTable, $hiddenContainerWhere )->first();
|
||||
$this->_unapprovedItems = \IPS\Db::i()->select( 'COUNT(*)', $itemClass::$databaseTable, $hiddenContainerWhere, NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
}
|
||||
|
||||
if( $commentClass !== NULL AND in_array( 'IPS\Content\Hideable', class_implements( $commentClass ) ) )
|
||||
@@ -2481,7 +2512,7 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
$this->_unapprovedComments = \IPS\Db::i()->select( 'COUNT(*)', array(
|
||||
array( $commentClass::$databaseTable, $commentClass::$databaseTable ),
|
||||
array( $itemClass::$databaseTable, $itemClass::$databaseTable )
|
||||
), $commentWhere )->first();
|
||||
), $commentWhere, NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2490,7 +2521,6 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
$reviewWhere = array( array( $reviewClass::$databaseTable . '.' . $reviewClass::$databasePrefix . $reviewClass::$databaseColumnMap['item'] . ' = ' . $itemClass::$databaseTable . '.' . $itemClass::$databasePrefix . $itemIdColumn ) );
|
||||
if ( $this->_unapprovedReviews !== NULL )
|
||||
{
|
||||
|
||||
$reviewWhere = array_merge( $reviewWhere, $anyContainerWhere );
|
||||
|
||||
if ( isset( $reviewClass::$databaseColumnMap['approved'] ) )
|
||||
@@ -2505,7 +2535,7 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
$this->_unapprovedReviews = \IPS\Db::i()->select( 'COUNT(*)', array(
|
||||
array( $reviewClass::$databaseTable, $reviewClass::$databaseTable ),
|
||||
array( $itemClass::$databaseTable, $itemClass::$databaseTable )
|
||||
), $reviewWhere )->first();
|
||||
), $reviewWhere, NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3056,7 +3086,17 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
if ( $showMoveToChildren or $this->hasChildren( NULL, NULL, TRUE ) )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['node_move_children'] = sprintf( \IPS\Member::loggedIn()->language()->get( 'node_move_children', FALSE ), \IPS\Member::loggedIn()->language()->addToStack( static::$nodeTitle, FALSE, array( 'strtolower' => TRUE) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'node_move_children', 0, TRUE, array( 'class' => get_class( $this ), 'disabled' => array( $this->_id ), 'disabledLang' => 'node_move_delete', 'zeroVal' => 'node_delete_children', 'subnodes' => FALSE ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'node_move_children', 0, TRUE, array(
|
||||
'class' => get_class( $this ),
|
||||
'disabled' => array( $this->_id ),
|
||||
'disabledLang' => 'node_move_delete',
|
||||
'zeroVal' => 'node_delete_children',
|
||||
'subnodes' => FALSE,
|
||||
'permissionCheck' => function( $node )
|
||||
{
|
||||
return $node->canAdd();
|
||||
}
|
||||
) ) );
|
||||
}
|
||||
if ( $hasContent )
|
||||
{
|
||||
@@ -3089,7 +3129,7 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
if ( $values['node_move_children'] )
|
||||
{
|
||||
$parentColumn = static::$databaseColumnParent;
|
||||
$parentColumn = ( isset( static::$subnodeClass ) AND $child instanceof static::$subnodeClass ) ? $child::$parentNodeColumnId : $child::$databaseColumnParent;
|
||||
$child->$parentColumn = \IPS\Request::i()->node_move_children;
|
||||
$child->setLastComment();
|
||||
$child->setLastReview();
|
||||
@@ -3330,12 +3370,13 @@ abstract class _Model extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @return array
|
||||
* @apiresponse int id ID number
|
||||
* @apiresponse string name Name
|
||||
* @apiresponse string url URL
|
||||
*/
|
||||
public function apiOutput()
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL )
|
||||
{
|
||||
return array(
|
||||
'id' => $this->id,
|
||||
|
||||
Reference in new issue
Block a user