Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

+108 -42
View File
@@ -2,9 +2,9 @@
/**
* @brief Node Controller
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @since 18 Feb 2013
* @version SVN_VERSION_NUMBER
*/
@@ -74,7 +74,14 @@ class _Controller extends \IPS\Dispatcher\Controller
if ( isset( \IPS\Request::i()->searchResult ) )
{
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core' )->message( sprintf( \IPS\Member::loggedIn()->language()->get('search_results_in_nodes'), mb_strtolower( \IPS\Member::loggedIn()->language()->get( $nodeClass::$nodeTitle . '_sg' ) ) ), 'information' );
try
{
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core' )->message( sprintf( \IPS\Member::loggedIn()->language()->get('search_results_in_nodes'), mb_strtolower( \IPS\Member::loggedIn()->language()->get( $nodeClass::$nodeTitle . '_sg' ) ) ), 'information' );
}
catch( \UnderflowException $ex )
{
\IPS\Log::log( $ex->getMessage(), "Language" );
}
}
if ( $nodeClass::$databaseColumnParent === NULL )
@@ -247,15 +254,20 @@ class _Controller extends \IPS\Dispatcher\Controller
*/
protected function form()
{
/* Get node */
/* What class are we working with? */
$nodeClass = $this->nodeClass;
$parentNodeClass = NULL;
if ( \IPS\Request::i()->subnode )
{
$parentNodeClass = $nodeClass;
$nodeClass = $nodeClass::$subnodeClass;
}
$node = NULL;
/* Init Edit */
if ( \IPS\Request::i()->id )
{
/* Load the node being edited */
try
{
$node = call_user_func( "{$nodeClass}::load", \IPS\Request::i()->id );
@@ -265,11 +277,21 @@ class _Controller extends \IPS\Dispatcher\Controller
{
\IPS\Output::i()->error( 'node_error', '2S101/K', 404, '' );
}
/* Check we have permission to edit it */
if( !$node->canEdit() )
{
\IPS\Output::i()->error( 'node_noperm_edit', '2S101/N', 403, '' );
}
}
/* Init Create */
else
{
/* Create a new object */
$node = new $nodeClass;
/* Set an appropriate title */
if ( !$this->title )
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( $nodeClass::$nodeTitle . '_add_child' );
@@ -279,35 +301,59 @@ class _Controller extends \IPS\Dispatcher\Controller
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( $this->title );
}
/* Are we creating a child of an existing node? */
if ( \IPS\Request::i()->parent )
{
$parentColumn = NULL;
/* Sub node? */
if ( \IPS\Request::i()->subnode )
{
if ( isset( $nodeClass::$parentNodeColumnId ) )
{
$parentColumn = $nodeClass::$parentNodeColumnId;
try
{
$parent = $parentNodeClass::load( \IPS\Request::i()->parent );
if ( !$parent->canAdd() )
{
\IPS\Output::i()->error( 'node_noperm_edit', '2S101/W', 403, '' );
}
$parentColumn = $nodeClass::$parentNodeColumnId;
}
catch ( \OutOfRangeException $e ) { }
}
}
/* Nope, normal */
elseif ( isset( $nodeClass::$databaseColumnParent ) )
{
$parentColumn = $nodeClass::$databaseColumnParent;
try
{
$parent = $nodeClass::load( \IPS\Request::i()->parent );
if ( !$parent->canAdd() )
{
\IPS\Output::i()->error( 'node_noperm_edit', '2S101/V', 403, '' );
}
$parentColumn = $nodeClass::$databaseColumnParent;
}
catch ( \OutOfRangeException $e ) { }
}
/* Set the value */
if ( $parentColumn !== NULL )
{
$node->$parentColumn = \IPS\Request::i()->parent;
}
}
/* No - creating a root - check permission */
else
{
if( !$nodeClass::canAddRoot() )
{
\IPS\Output::i()->error( 'node_noperm_edit', '2S101/U', 403, '' );
}
}
}
/* Check permission */
if( !$node->canEdit() )
{
\IPS\Output::i()->error( 'node_noperm_edit', '2S101/N', 403, '' );
}
/* Build form */
$form = $this->_addEditForm( $node );
@@ -338,7 +384,7 @@ class _Controller extends \IPS\Dispatcher\Controller
if ( $new )
{
\IPS\Session::i()->log( 'acplog__node_created', array( $this->title => TRUE, $node->_logKey => TRUE ) );
\IPS\Session::i()->log( 'acplog__node_created', array( $this->title => TRUE, $node->titleForLog() => FALSE ) );
if ( $node->canManagePermissions() )
{
@@ -374,13 +420,13 @@ class _Controller extends \IPS\Dispatcher\Controller
$node->save();
}
\IPS\Session::i()->log( 'acplog__node_edited', array( $this->title => TRUE, $node->_logKey => TRUE ) );
\IPS\Session::i()->log( 'acplog__node_edited', array( $this->title => TRUE, $node->titleForLog() => FALSE ) );
}
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
$this->_afterSave( $old, $node );
$this->_afterSave( $old, $node, $form->getLastUsedTab() );
return;
}
catch ( \LogicException $e )
@@ -418,11 +464,12 @@ class _Controller extends \IPS\Dispatcher\Controller
/**
* Redirect after save
*
* @param \IPS\Node\Model $old A clone of the node as it was before or NULL if this is a creation
* @param \IPS\Node\Model $node The node now
* @param \IPS\Node\Model $old A clone of the node as it was before or NULL if this is a creation
* @param \IPS\Node\Model $new The node now
* @param string $lastUsedTab The tab last used in the form
* @return void
*/
protected function _afterSave( \IPS\Node\Model $old = NULL, \IPS\Node\Model $new )
protected function _afterSave( \IPS\Node\Model $old = NULL, \IPS\Node\Model $new, $lastUsedTab = FALSE )
{
if( \IPS\Request::i()->isAjax() )
{
@@ -430,7 +477,16 @@ class _Controller extends \IPS\Dispatcher\Controller
}
else
{
\IPS\Output::i()->redirect( $this->url->setQueryString( array( 'root' => ( $new->parent() ? $new->parent()->_id : '' ) ) ), 'saved' );
if( isset( \IPS\Request::i()->save_and_reload ) )
{
$buttons = $new->getButtons( $this->url, !( $new instanceof $this->nodeClass ) );
\IPS\Output::i()->redirect( ( $lastUsedTab ? $buttons['edit']['link']->setQueryString('activeTab', $lastUsedTab ) : $buttons['edit']['link'] ), 'saved' );
}
else
{
\IPS\Output::i()->redirect( $this->url->setQueryString( array( 'root' => ( $new->parent() ? $new->parent()->_id : '' ) ) ), 'saved' );
}
}
}
@@ -523,9 +579,9 @@ class _Controller extends \IPS\Dispatcher\Controller
foreach( $values as $k => $v )
{
$k = str_replace( $nodeClass::$databasePrefix, "", $k );
$k = preg_replace( '#^' . preg_quote( $nodeClass::$databasePrefix, '#' ) . '#', "", $k );
$val = $_node->$k;
if( is_array( $v ) )
{
foreach( $v as $_k => $_v )
@@ -634,11 +690,11 @@ class _Controller extends \IPS\Dispatcher\Controller
/* Log */
if ( $node->_enabled )
{
\IPS\Session::i()->log( 'acplog__node_enabled', array( $this->title => TRUE, $node->_logKey => TRUE ) );
\IPS\Session::i()->log( 'acplog__node_enabled', array( $this->title => TRUE, $node->titleForLog() => FALSE ) );
}
else
{
\IPS\Session::i()->log( 'acplog__node_disabled', array( $this->title => TRUE, $node->_logKey => TRUE ) );
\IPS\Session::i()->log( 'acplog__node_disabled', array( $this->title => TRUE, $node->titleForLog() => FALSE ) );
}
/* If this is an AJAX request, just respond */
@@ -762,7 +818,7 @@ class _Controller extends \IPS\Dispatcher\Controller
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Session::i()->log( 'acplog__node_copied_c', array( $node->title => TRUE, $node->_logKey => TRUE ) );
\IPS\Session::i()->log( 'acplog__node_copied_c', array( $node->title => TRUE, $node->titleForLog() => FALSE ) );
\IPS\Output::i()->redirect( $ourObj->url->setQueryString( array( 'root' => ( $node->parent() ? $node->parent()->id : '' ) ) ), 'saved' );
}
);
@@ -780,7 +836,7 @@ class _Controller extends \IPS\Dispatcher\Controller
/* Copy it */
$new = clone $node;
\IPS\Session::i()->log( 'acplog__node_copied', array( $this->title => TRUE, $node->_logKey => TRUE ) );
\IPS\Session::i()->log( 'acplog__node_copied', array( $this->title => TRUE, $node->titleForLog() => FALSE ) );
/* Boink */
$url = $this->url->setQueryString( array( 'do' => 'form', 'id' => $new->_id ) );
@@ -846,6 +902,7 @@ class _Controller extends \IPS\Dispatcher\Controller
\IPS\Output::i()->error( 'node_error', '3S101/B', 404, '' );
}
$orderColumn = $node::$databaseColumnOrder;
$idColumn = $node::$databaseColumnId;
/* Check permission */
if( !$node->canEdit() )
@@ -860,6 +917,12 @@ class _Controller extends \IPS\Dispatcher\Controller
/* Do it */
if ( $parentColumn )
{
if ( is_numeric( $parent ) and $node->$idColumn == $parent AND !isset( $nodeClass::$subnodeClass ) )
{
/* It is attempting to assign a parent ID of itself which will break the tree */
$parent = $nodeClass::$databaseColumnParentRootValue;
}
$node->$parentColumn = ( $parent === 'null' ) ? 0 : is_numeric( $parent ) ? $parent : $nodeClass::$databaseColumnParentRootValue;
}
$node->$orderColumn = $position;
@@ -880,6 +943,9 @@ class _Controller extends \IPS\Dispatcher\Controller
/* Log */
\IPS\Session::i()->log( 'acplog__node_reorder', array( $this->title => TRUE ), TRUE );
/* Allow plugins to act if necessary */
$this->_afterReorder( $order );
/* If this is an AJAX request, just respond */
if( \IPS\Request::i()->isAjax() )
@@ -893,6 +959,17 @@ class _Controller extends \IPS\Dispatcher\Controller
}
\IPS\Output::i()->sendOutput();
}
/**
* Function to execute after nodes are reordered. Do nothing by default but plugins can extend.
*
* @param array $order The new ordering that was saved
* @return void
*/
protected function _afterReorder( $order )
{
}
/**
* Permissions
@@ -1055,7 +1132,7 @@ class _Controller extends \IPS\Dispatcher\Controller
unset(\IPS\Data\Store::i()->modules);
/* Log */
\IPS\Session::i()->log( 'permissions_adjusted_node', array( $node->_logKey => TRUE ) );
\IPS\Session::i()->log( 'permissions_adjusted_node', array( $node->titleForLog() => FALSE ) );
/* Clear out member's cached "Create Menu" contents */
\IPS\Member::clearCreateMenu();
@@ -1102,12 +1179,7 @@ class _Controller extends \IPS\Dispatcher\Controller
}
/* Do we have any children or content? */
$hasContent = FALSE;
if ( isset( $nodeClass::$contentItemClass ) )
{
$hasContent = (bool) $node->getContentItemCount();
}
if ( $node->hasChildren( NULL, NULL, TRUE ) or $hasContent )
if ( $node->hasChildren( NULL, NULL, TRUE ) or $node->showDeleteOrMoveForm() )
{
$form = $node->deleteOrMoveForm();
if ( $values = $form->values() )
@@ -1124,18 +1196,12 @@ class _Controller extends \IPS\Dispatcher\Controller
}
else
{
$form = $node->deleteForm();
if ( ! isset( \IPS\Request::i()->form_submitted ) )
{
/* Show form */
\IPS\Output::i()->output = $form;
return;
}
/* Make sure the user confirmed the deletion */
\IPS\Request::i()->confirmedDelete();
}
/* Delete it */
\IPS\Session::i()->log( 'acplog__node_deleted', array( $this->title => TRUE, $node->_logKey => TRUE ) );
\IPS\Session::i()->log( 'acplog__node_deleted', array( $this->title => TRUE, $node->titleForLog() => FALSE ) );
$node->delete();
/* Clear out member's cached "Create Menu" contents */