Source for file image_order.php
Documentation is available at image_order.php
require_once( '../kernel/setup_inc.php' );
require_once( FISHEYE_PKG_PATH. 'FisheyeGallery.php');
require_once( FISHEYE_PKG_PATH. 'FisheyeImage.php');
include_once( FISHEYE_PKG_PATH. 'gallery_lookup_inc.php' );
if( $gBitSystem->isPackageActive( 'gatekeeper' ) ) {
$gBitSmarty->assign( 'securities', $gGatekeeper->getSecurityList( $gBitUser->mUserId ) );
// Ensure the user has the permission to create new image galleries
$gContent->verifyUpdatePermission();
if (!empty($_REQUEST['cancel'])) {
} elseif (!empty($_REQUEST['updateImageOrder'])) {
if( !empty( $_REQUEST['batch'] ) ) {
// flip so we can do instant hash lookup
// increment the first element from 0 to 1 (element 0 index before flip) so any conditional tests will pass, particularly in the .tpl
$batchCon[key($batchCon)]++ ;
$gBitSmarty->assign_by_ref( 'batchEdit', $batchCon );
if( !empty( $_REQUEST['is_favorite'] ) ) {
// flip so we can do instant hash lookup
$favoriteCon = array_flip( $_REQUEST['is_favorite'] );
// increment the first element from 0 to 1 (element 0 index before flip) so any conditional tests will pass, particularly in the .tpl
$favoriteCon[key($favoriteCon)]++ ;
if( !empty( $_REQUEST['reorder_gallery'] ) ) {
switch( $_REQUEST['reorder_gallery'] ){
foreach( array_keys( $gContent->mItems ) as $imageId ) {
$reorder[$gContent->mItems[$imageId]->mContentId] = $gContent->mItems[$imageId]->mInfo['event_time'];
foreach( array_keys( $gContent->mItems ) as $imageId ) {
$reorder[$gContent->mItems[$imageId]->mContentId] = $gContent->mItems[$imageId]->mInfo['created'];
foreach( array_keys( $gContent->mItems ) as $imageId ) {
$reorder[$gContent->mItems[$imageId]->mContentId] = $gContent->mItems[$imageId]->mInfo['title'];
foreach( array_keys( $gContent->mItems ) as $imageId ) {
$reorder[$gContent->mItems[$imageId]->mContentId] = $gContent->mItems[$imageId]->mInfo['file_name'];
foreach( array_keys( $gContent->mItems ) as $imageId ) {
$reorder[$gContent->mItems[$imageId]->mContentId] = rand( 0, 9999999 );
foreach( $reorder as $conId => $sortVal ) {
$newOrder[$conId] = $sortPos;
if( !empty( $gContent->mItems ) ) {
foreach( array_keys( $gContent->mItems ) as $itemConId ) {
if( $gContent->mItems[$itemConId]->getField( 'is_favorite' ) && empty( $favoriteCon[$itemConId] ) ) {
$gBitUser->expungeFavorite( $itemConId );
} elseif( !$gContent->mItems[$itemConId]->getField('is_favorite') && !empty( $favoriteCon[$itemConId] ) ) {
$gBitUser->storeFavorite( $itemConId );
foreach ($_REQUEST['imagePosition'] as $contentId=> $newPos) {
if( isset ( $batchCon[$contentId] ) ) {
if( !empty( $_REQUEST['batch_command'] ) ) {
@list ( $batchCommand, $batchParam ) = @explode( ':', $_REQUEST['batch_command'] );
switch( $batchCommand ) {
$parents = $galleryItem->getParentGalleries();
$gContent->removeItem( $contentId );
if( is_a( $galleryItem, 'FisheyeImage' ) ) {
$galleryItem->rotateImage( $batchParam );
$feedback['success'] = tra( "Images rotated" );
$galleryItem->generateThumbnails();
$feedback['success'] = tra( "Thumbnail regeneration queued" );
$galleryItem->convertColorspace( 'grayscale' );
$storageHash['security_id'] = $batchParam;
$feedback['success'] = tra( "Items security assigned" );
if( empty( $destGallery ) ) {
if( $batchParam != $contentId ) {
$gContent->removeItem( $contentId );
if( empty( $destGallery ) ) {
if( $destGallery->addItem( $contentId ) ) {
$feedback['success'][] = $galleryItem->getTitle(). ' '. tra( "added to" ). ' '. $destGallery->getTitle();
$feedback['error'][] = $galleryItem->getTitle(). ' '. tra( "could not be added to" ). ' '. $destGallery->getTitle();
case 'filenametoimagename':
if( !empty( $galleryItem->mInfo['filename'] ) ) {
$galleryItem->store( $renameHash );
// update to prevent renaming value in text input
$_REQUEST['image_title'][$contentId] = $renameHash['title'];
if( !empty( $_REQUEST['batch_security_id'] ) ) {
// if we are reordered, that takes precident
$newPos = preg_replace( '/[^\d\.]/', '', (!empty( $newOrder[$contentId] ) ? $newOrder[$contentId] : $newPos) );
if ($galleryItem->mInfo['title'] != $_REQUEST['image_title'][$contentId]) {
$storageHash = array('title' => $_REQUEST['image_title'][$contentId]);
// make sure we don't delete the 'data' field on en masse title updating
$storageHash['edit'] = $galleryItem->getField( 'data' );
if( !empty( $storageHash ) ) {
$galleryItem->store($storageHash);
$galleryItem->updatePosition($gContent->mContentId, $newPos);
if ($gContent->storeGalleryThumbnail($_REQUEST['gallery_preview_content_id'])) {
$gContent->mInfo['preview_content_id'] = $_REQUEST['gallery_preview_content_id'];
$_SESSION['image_order_feedback'] = $feedback;
// Redirect so reload does not cause double-batch processing
if( !empty( $_SESSION['image_order_feedback'] ) ) {
$feedback = $_SESSION['image_order_feedback'];
unset ( $_SESSION['image_order_feedback'] );
// Get a list of usable galleries
'user_id' => $gBitUser->mUserId,
'sort_mode' => 'title_asc',
// modify listHash according to global preferences
unset ( $listHash['user_id'] );
} elseif( $gBitSystem->isFeatureActive( 'fisheye_show_public_on_upload' ) ) {
// $listHash['show_public'] = TRUE;
$galleryList = $gContent->getList( $listHash );
$gBitSmarty->assign_by_ref( 'galleryList', $galleryList );
$gBitSmarty->assign_by_ref('formfeedback', $feedback);
$gBitThemes->loadAjax( 'mochikit' );
$gBitSystem->display( 'bitpackage:fisheye/image_order.tpl', tra( 'Edit Gallery Images' ). ': '. $gContent->getTitle() , array( 'display_mode' => 'display' ));
|