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

+168 -56
View File
@@ -51,83 +51,195 @@ class _Table extends \IPS\Helpers\Table\Content
}
/**
* Multimod
* Build the form to move images
*
* @return void
* @param \IPS\Node\Model $currentContainer Current image container
* @param string $class Class to use
* @param array $extraAlbumOptions Additional options to use for the album helper (e.g. to force owner)
* @return \IPS\Helpers\Form
*/
protected function multimod()
static public function buildMoveForm( $currentContainer, $class, $extraAlbumOptions=array() )
{
\IPS\Session::i()->csrfCheck();
$form = new \IPS\Helpers\Form( 'form', 'move' );
$form->class = 'ipsForm_vertical';
if ( \IPS\gallery\Category::canOnAny('add') and \IPS\gallery\Album::canOnAny('add') )
{
$options = array( 'category' => 'image_category', 'album' => 'image_album' );
$toggles = array( 'category' => array( 'move_to_category' ), 'album' => array( 'move_to_album' ) );
$extraFields = array();
if ( \IPS\gallery\Image::modPermission( 'edit', NULL, NULL ) and \IPS\Db::i()->select( 'COUNT(*)', 'gallery_categories', array( array( 'category_allow_albums>0' ), array( '(' . \IPS\Db::i()->findInSet( 'core_permission_index.perm_' . \IPS\gallery\Category::$permissionMap['add'], \IPS\Member::loggedIn()->groups ) . ' OR ' . 'core_permission_index.perm_' . \IPS\gallery\Category::$permissionMap['add'] . '=? )', '*' ) ) )->join( 'core_permission_index', array( "core_permission_index.app=? AND core_permission_index.perm_type=? AND core_permission_index.perm_type_id=" . \IPS\gallery\Category::$databaseTable . "." . \IPS\gallery\Category::$databasePrefix . \IPS\gallery\Category::$databaseColumnId, \IPS\gallery\Category::$permApp, \IPS\gallery\Category::$permType ) )->first() )
{
$options['new_album'] = 'move_to_new_album';
/* Basic check that we selected something */
if( !isset( \IPS\Request::i()->moderate ) OR empty( \IPS\Request::i()->moderate ) )
{
\IPS\Output::i()->error( 'nothing_mm_selected', '1G329/1', 403, '' );
}
$class = $this->class;
$params = array();
if ( \IPS\Request::i()->modaction == 'move' )
{
$form = new \IPS\Helpers\Form( 'form', 'move' );
$form->add( new \IPS\Helpers\Form\Node( 'move_to_category', NULL, FALSE, array( 'clubs' => true, 'class' => 'IPS\\gallery\\Category', 'url' => \IPS\Request::i()->url()->setQueryString( 'modaction', 'move' ) ) ) );
$form->add( new \IPS\Helpers\Form\Node( 'move_to_album', NULL, FALSE, array(
'class' => 'IPS\\gallery\\Album',
'forceOwner' => FALSE,
'url' => \IPS\Request::i()->url()->setQueryString( 'modaction', 'move' ),
'permissionCheck' => function( $node )
foreach ( \IPS\gallery\Album::formFields( NULL, TRUE, \IPS\Request::i()->move_to === 'new_album' ) as $field )
{
/* Have we hit an images per album limit? */
if( $node->owner()->group['g_img_album_limit'] AND ( $node->count_imgs + $node->count_imgs_hidden ) >= $node->owner()->group['g_img_album_limit'] )
if ( !$field->htmlId )
{
return false;
$field->htmlId = $field->name . '_id';
}
$toggles['new_album'][] = $field->htmlId;
$extraFields[] = $field;
}
}
$form->add( new \IPS\Helpers\Form\Radio( 'move_to', NULL, TRUE, array( 'options' => $options, 'toggles' => $toggles ) ) );
foreach ( $extraFields as $field )
{
$form->add( $field );
}
}
$form->add( new \IPS\Helpers\Form\Node( 'move_to_category', NULL, NULL, array(
'clubs' => true,
'class' => 'IPS\\gallery\\Category',
'permissionCheck' => function( $node ) use ( $currentContainer, $class )
{
/* If the image is in the same category already, we can't move it there */
if( $currentContainer instanceof \IPS\gallery\Category and $currentContainer->id == $node->id )
{
return false;
}
/* If the category requires albums, we cannot move images directly to it */
if( $node->allow_albums == 2 )
{
return false;
}
/* If the category is a club, check mod permissions appropriately */
try
{
/* If the item is in a club, only allow moving to other clubs that you moderate */
if ( $currentContainer and \IPS\IPS::classUsesTrait( $currentContainer, 'IPS\Content\ClubContainer' ) and $currentContainer->club() )
{
return $class::modPermission( 'move', \IPS\Member::loggedIn(), $node ) and $node->can( 'add' ) ;
}
}
catch( \OutOfBoundsException $e ) { }
/* Can we add in this category? */
if ( $node->can( 'add' ) )
{
return true;
}
) ) );
if ( $values = $form->values() )
return false;
}
), function( $val ) {
if ( !$val and isset( \IPS\Request::i()->move_to ) and \IPS\Request::i()->move_to == 'category' )
{
if( ( !isset( $values['move_to_category'] ) OR !( $values['move_to_category'] instanceof \IPS\Node\Model ) ) AND
( !isset( $values['move_to_album'] ) OR !( $values['move_to_album'] instanceof \IPS\Node\Model ) ) )
{
$form->error = \IPS\Member::loggedIn()->language()->addToStack('gallery_cat_or_album');
throw new \DomainException('form_required');
}
}, NULL, NULL, 'move_to_category' ) );
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
return;
$form->add( new \IPS\Helpers\Form\Node( 'move_to_album', NULL, NULL, array_merge( array(
'class' => 'IPS\\gallery\\Album',
'permissionCheck' => function( $node ) use ( $currentContainer )
{
/* If the image is in the same album already, we can't move it there */
if( $currentContainer instanceof \IPS\gallery\Album and $currentContainer->id == $node->id )
{
return false;
}
$params[] = ( isset( $values['move_to_category'] ) AND $values['move_to_category'] ) ? $values['move_to_category'] : $values['move_to_album'];
$params[] = FALSE;
/* Do we have permission to add? */
if( !$node->can( 'add' ) )
{
return false;
}
/* Have we hit an images per album limit? */
if( $node->owner()->group['g_img_album_limit'] AND ( $node->count_imgs + $node->count_imgs_hidden ) >= $node->owner()->group['g_img_album_limit'] )
{
return false;
}
return true;
}
), $extraAlbumOptions ), function( $val ) {
if ( !$val and isset( \IPS\Request::i()->move_to ) and \IPS\Request::i()->move_to == 'album' )
{
throw new \DomainException('form_required');
}
}, NULL, NULL, 'move_to_album' ) );
return $form;
}
/**
* Get the form to move items
*
* @return string|array
*/
protected function getMoveForm()
{
$class = $this->class;
$params = array();
$currentContainer = $this->container;
$form = static::buildMoveForm( $currentContainer, $class );
if ( $values = $form->values() )
{
if ( isset( $values['move_to'] ) )
{
if ( $values['move_to'] == 'new_album' )
{
$albumValues = $values;
unset( $albumValues['move_to'] );
unset( $albumValues['move_to_category'] );
unset( $albumValues['move_to_album'] );
$target = new \IPS\gallery\Album;
$target->saveForm( $target->formatFormValues( $albumValues ) );
$target->save();
}
else
{
$target = ( \IPS\Request::i()->move_to == 'category' ) ? $values['move_to_category'] : $values['move_to_album'];
}
}
else
{
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
if ( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->sendOutput( \IPS\Output::i()->output );
}
else
{
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Output::i()->title, \IPS\Output::i()->output, array( 'app' => \IPS\Dispatcher::i()->application->directory, 'module' => \IPS\Dispatcher::i()->module->key, 'controller' => \IPS\Dispatcher::i()->controller ) ), 200, 'text/html', \IPS\Output::i()->httpHeaders );
}
return;
$target = isset( $values['move_to_category'] ) ? $values['move_to_category'] : $values['move_to_album'];
}
$params[] = $target;
$params[] = FALSE;
return $params;
}
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
foreach ( array_keys( \IPS\Request::i()->moderate ) as $id )
if ( \IPS\Request::i()->isAjax() )
{
try
{
$object = $class::loadAndCheckPerms( $id );
$object->modAction( \IPS\Request::i()->modaction, \IPS\Member::loggedIn(), $params );
}
catch ( \Exception $e ) {}
\IPS\Output::i()->sendOutput( \IPS\Output::i()->output );
}
\IPS\Output::i()->redirect( $this->baseUrl );
else
{
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Output::i()->title, \IPS\Output::i()->output, array( 'app' => \IPS\Dispatcher::i()->application->directory, 'module' => \IPS\Dispatcher::i()->module->key, 'controller' => \IPS\Dispatcher::i()->controller ) ), 200, 'text/html', \IPS\Output::i()->httpHeaders );
}
return;
}
/**
* Return the sort direction to use for links
*
* @note Abstracted so other table helper instances can adjust as needed
* @param string $column Sort by string
* @return string [asc|desc]
*/
public function getSortDirection( $column )
{
if( $column == 'image_caption' )
{
return 'asc';
}
return 'desc';
}
}