fisheye
[ class tree: fisheye ] [ index: fisheye ] [ all elements ]

Source for file image_order.php

Documentation is available at image_order.php

  1. <?php
  2. /**
  3.  * @version $Header$
  4.  * @package fisheye
  5.  * @subpackage functions
  6.  */
  7.  
  8. /**
  9.  * required setup
  10.  */
  11. require_once( '../kernel/setup_inc.php' );
  12.  
  13. require_once( FISHEYE_PKG_PATH.'FisheyeGallery.php');
  14. require_once( FISHEYE_PKG_PATH.'FisheyeImage.php');
  15.  
  16. global $gBitSystem;
  17.  
  18. include_once( FISHEYE_PKG_PATH.'gallery_lookup_inc.php' );
  19.  
  20. if( $gBitSystem->isPackageActive( 'gatekeeper' ) ) {
  21.     global $gGatekeeper;
  22.     $gBitSmarty->assign( 'securities', $gGatekeeper->getSecurityList( $gBitUser->mUserId ) );
  23. }
  24.  
  25. // Ensure the user has the permission to create new image galleries
  26. $gContent->verifyUpdatePermission();
  27.  
  28. if (!empty($_REQUEST['cancel'])) {
  29.     header( 'Location: '.$gContent->getDisplayUrl() );
  30.     die;
  31. } elseif (!empty($_REQUEST['updateImageOrder'])) {
  32.     if( !empty( $_REQUEST['batch'] ) ) {
  33.         // flip so we can do instant hash lookup
  34.         $batchCon = array_flip( $_REQUEST['batch'] );
  35.         // increment the first element from 0 to 1 (element 0 index before flip) so any conditional tests will pass, particularly in the .tpl
  36.         $batchCon[key($batchCon)]++;
  37.         $gBitSmarty->assign_by_ref( 'batchEdit', $batchCon );
  38.     }
  39.  
  40.     if( !empty( $_REQUEST['is_favorite'] ) ) {
  41.         // flip so we can do instant hash lookup
  42.         $favoriteCon = array_flip( $_REQUEST['is_favorite'] );
  43.         // increment the first element from 0 to 1 (element 0 index before flip) so any conditional tests will pass, particularly in the .tpl
  44.         $favoriteCon[key($favoriteCon)]++;
  45.     }
  46.  
  47.     $gContent->loadImages();
  48.  
  49.     $feedback = NULL;
  50.  
  51.     if( !empty( $_REQUEST['reorder_gallery'] ) ) {
  52.         switch( $_REQUEST['reorder_gallery'] ){
  53.             case 'photo_date':
  54.                 foreach( array_keys( $gContent->mItems ) as $imageId ) {
  55.                     $reorder[$gContent->mItems[$imageId]->mContentId] = $gContent->mItems[$imageId]->mInfo['event_time'];
  56.                 }
  57.                 break;
  58.             case 'upload_date':
  59.                 foreach( array_keys( $gContent->mItems ) as $imageId ) {
  60.                     $reorder[$gContent->mItems[$imageId]->mContentId] = $gContent->mItems[$imageId]->mInfo['created'];
  61.                 }
  62.                 break;
  63.             case 'caption':
  64.                 foreach( array_keys( $gContent->mItems ) as $imageId ) {
  65.                     $reorder[$gContent->mItems[$imageId]->mContentId] = $gContent->mItems[$imageId]->mInfo['title'];
  66.                 }
  67.                 break;
  68.             case 'file_name':
  69.                 foreach( array_keys( $gContent->mItems ) as $imageId ) {
  70.                     $reorder[$gContent->mItems[$imageId]->mContentId] = $gContent->mItems[$imageId]->mInfo['file_name'];
  71.                 }
  72.                 break;
  73.             case 'random':
  74.                 foreach( array_keys( $gContent->mItems ) as $imageId ) {
  75.                     $reorder[$gContent->mItems[$imageId]->mContentId] = rand( 0, 9999999 );
  76.                 }
  77.                 break;
  78.         }
  79.         natcasesort( $reorder );
  80.         $sortPos = 10;
  81.         foreach( $reorder as $conId => $sortVal ) {
  82.             $newOrder[$conId] = $sortPos;
  83.             $sortPos += 10;
  84.         }
  85.     }
  86.  
  87.     if( !empty( $gContent->mItems ) ) {
  88.         foreach( array_keys( $gContent->mItems ) as $itemConId ) {
  89.             if( $gContent->mItems[$itemConId]->getField( 'is_favorite' ) && empty( $favoriteCon[$itemConId] ) ) {
  90.                 $gBitUser->expungeFavorite( $itemConId );
  91.             } elseif( !$gContent->mItems[$itemConId]->getField('is_favorite') && !empty( $favoriteCon[$itemConId] ) ) {
  92.                 $gBitUser->storeFavorite( $itemConId );
  93.             }
  94.         }
  95.     }
  96.  
  97.     foreach ($_REQUEST['imagePosition'] as $contentId=>$newPos) {
  98.         if( $galleryItem = LibertyBase::getLibertyObject( $contentId ) ) {
  99.             $galleryItem->load();
  100.             if( isset( $batchCon[$contentId] ) ) {
  101.                 if( !empty( $_REQUEST['batch_command'] ) ) {
  102.                     @list( $batchCommand, $batchParam ) = @explode( ':', $_REQUEST['batch_command'] );
  103.                     switch( $batchCommand ) {
  104.                         case 'delete':
  105.                             $galleryItem->expunge();
  106.                             $galleryItem = NULL;
  107.                             break;
  108.                         case 'remove':
  109.                             $parents = $galleryItem->getParentGalleries();
  110.                             if( $galleryItem->isContentType( FISHEYEGALLERY_CONTENT_TYPE_GUID ) || count( $parents ) > 1 ) {
  111.                                 $gContent->removeItem( $contentId );
  112.                             } else {
  113.                                 $galleryItem->expunge();
  114.                             }
  115.                             $galleryItem = NULL;
  116.                             break;
  117.                         case 'rotate':
  118.                             if( is_a( $galleryItem, 'FisheyeImage' ) ) {
  119.                                 $galleryItem->rotateImage( $batchParam );
  120.                                 $feedback['success'] = tra( "Images rotated" );
  121.                             }
  122.                             break;
  123.                         case 'thumbnail':
  124.                             $galleryItem->generateThumbnails();
  125.                             $feedback['success'] = tra( "Thumbnail regeneration queued" );
  126.                             break;
  127.                         case 'grayscale':
  128.                             $galleryItem->convertColorspace( 'grayscale' );
  129.                             break;
  130.                         case 'security':
  131.                             $storageHash['security_id'] = $batchParam;
  132.                             $feedback['success'] = tra( "Items security assigned" );
  133.                             break;
  134.                         case 'gallerymove':
  135.                             if( empty( $destGallery ) ) {
  136.                                 $destGallery = new FisheyeGallery( NULL, $batchParam );
  137.                                 $destGallery->load();
  138.                             }
  139.                             if( $batchParam != $contentId ) {
  140.                                 $gContent->removeItem( $contentId );
  141.                             }
  142.                         case 'gallerycopy':
  143.                             if( empty( $destGallery ) ) {
  144.                                 $destGallery = new FisheyeGallery( NULL, $batchParam );
  145.                                 $destGallery->load();
  146.                             }
  147.                             if( $destGallery->addItem( $contentId ) ) {
  148.                                 $feedback['success'][] = $galleryItem->getTitle().' '.tra( "added to" ).' '.$destGallery->getTitle();
  149.                             } else {
  150.                                 $feedback['error'][] = $galleryItem->getTitle().' '.tra( "could not be added to" ).' '.$destGallery->getTitle();
  151.                             }
  152.                             break;
  153.                         case 'filenametoimagename':
  154.                             $renameHash = array();
  155.                             if( !empty( $galleryItem->mInfo['filename'] ) ) {
  156.                                 $renameHash['title'] = file_name_to_title( $galleryItem->mInfo['filename'] );
  157.                                 $galleryItem->store( $renameHash );
  158.                                 // update to prevent renaming value in text input
  159.                                 $_REQUEST['image_title'][$contentId] = $renameHash['title'];
  160.                             }
  161.                             break;
  162.                     }
  163.                 }
  164.             }
  165.             if( is_object( $galleryItem ) ) {
  166.                 if( !empty( $_REQUEST['batch_security_id'] ) ) {
  167.                 }
  168.                 // if we are reordered, that takes precident
  169.                 $newPos = preg_replace( '/[^\d\.]/', '', (!empty( $newOrder[$contentId] ) ? $newOrder[$contentId] : $newPos) );
  170.                 if ($galleryItem->mInfo['title'] != $_REQUEST['image_title'][$contentId]) {
  171.                     $storageHash = array('title' => $_REQUEST['image_title'][$contentId]);
  172.                     // make sure we don't delete the 'data' field on en masse title updating
  173.                     $storageHash['edit'] = $galleryItem->getField( 'data' );
  174.                 }
  175.                 if( !empty( $storageHash ) ) {
  176.                     $galleryItem->store($storageHash);
  177.                 }
  178.                 $galleryItem->updatePosition($gContent->mContentId, $newPos);
  179.             }
  180.         }
  181.         unset( $storageHash );
  182.     }
  183.  
  184.     if ($gContent->storeGalleryThumbnail($_REQUEST['gallery_preview_content_id'])) {
  185.         $gContent->mInfo['preview_content_id'] = $_REQUEST['gallery_preview_content_id'];
  186.     }
  187.  
  188.     $_SESSION['image_order_feedback'] = $feedback;
  189.  
  190.     // Redirect so reload does not cause double-batch processing
  191.     bit_redirect( FISHEYE_PKG_URL.'image_order.php?gallery_id='.$gContent->getField( 'gallery_id' ) );
  192. }
  193.  
  194. if( !empty( $_SESSION['image_order_feedback'] ) ) {
  195.     $feedback = $_SESSION['image_order_feedback'];
  196.     unset( $_SESSION['image_order_feedback'] );
  197. }
  198.  
  199. // Get a list of usable galleries
  200. $listHash = array(
  201.     'user_id'       => $gBitUser->mUserId,
  202.     'max_records'   => -1,
  203.     'no_thumbnails' => TRUE,
  204.     'sort_mode'     => 'title_asc',
  205.     'show_empty'    => TRUE
  206. );
  207. // modify listHash according to global preferences
  208. if( $gBitSystem->isFeatureActive( 'fisheye_show_all_to_admins' ) && $gBitUser->hasPermission( 'p_fisheye_admin' ) ) {
  209.     unset( $listHash['user_id'] );
  210. } elseif( $gBitSystem->isFeatureActive( 'fisheye_show_public_on_upload' ) ) {
  211. //    $listHash['show_public'] = TRUE;
  212. }
  213. $galleryList = $gContent->getList( $listHash );
  214. $gBitSmarty->assign_by_ref( 'galleryList', $galleryList );
  215. $gContent->loadImages();
  216.  
  217. $gBitSmarty->assign_by_ref('formfeedback', $feedback);
  218.  
  219. $gBitThemes->loadAjax( 'mochikit' );
  220. $gBitSystem->display( 'bitpackage:fisheye/image_order.tpl', tra( 'Edit Gallery Images' ).': '.$gContent->getTitle() , array( 'display_mode' => 'display' ));
  221. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:42 +0000 by phpDocumentor 1.5.0-lsces