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

Source for file edit_image.php

Documentation is available at edit_image.php

  1. <?php
  2. /**
  3.  * @package fisheye
  4.  * @subpackage functions
  5.  */
  6.  
  7. /**
  8.  * required setup
  9.  */
  10. require_once( '../kernel/setup_inc.php' );
  11.  
  12. require_once( FISHEYE_PKG_PATH.'FisheyeGallery.php');
  13. require_once( FISHEYE_PKG_PATH.'FisheyeImage.php');
  14.  
  15. global $gBitSystem;
  16.  
  17. include_once( FISHEYE_PKG_PATH.'image_lookup_inc.php' );
  18.  
  19. if( $gContent->isValid() ) {
  20.     $gContent->verifyUpdatePermission();
  21. } else {
  22.     bit_redirect( FISHEYE_PKG_URL.'?user_id='.$gBitUser->mUserId );
  23. }
  24.  
  25. //Utility function, maybe should be moved for use elsewhere. Seems like it has a multitude of possible hook points
  26. function convertSmartQuotes($string)
  27. {
  28. //UTF-8
  29. $search = array("\xe2\x80\x98", "\xe2\x80\x99", "\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x80\xa6");
  30. $replace= array("'", "'", '"', '"', '-', '--', '...');
  31.  
  32. $string = str_replace($search, $replace, $string);
  33.  
  34. //Windows
  35. $search = array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133));
  36. $replace=  array("'", "'", '"', '"', '-', '--', '...');
  37.  
  38. $string = str_replace($search, $replace, $string);
  39.  
  40. return $string;
  41. }
  42. if( !empty($_REQUEST['edit'])){
  43.     global $gBitContent;
  44.     $_REQUEST['edit'] = convertSmartQuotes($_REQUEST['edit']);
  45. }
  46.  
  47. if( !empty($_REQUEST['saveImage']) || !empty($_REQUEST['regenerateThumbnails'] ) ) {
  48.  
  49.     if (empty($_REQUEST['gallery_id']) && empty($_REQUEST['image_id'])) {
  50.         // We have no way to know what gallery to add an image to or what image to edit!
  51.         $gBitSmarty->assign( 'msg', tra( "No gallery or image was specified" ) );
  52.         $gBitSystem->display( "error.tpl" , NULL, array( 'display_mode' => 'edit' ));
  53.         die;
  54.     }
  55.  
  56.     // Store/Update the image
  57.     if (isset($_FILES['imageFile']) && is_uploaded_file($_FILES['imageFile']['tmp_name'])) {
  58.         $_REQUEST['_files_override'] = array( $_FILES['imageFile'] );
  59.         $_REQUEST['_files_override']['process_storage'] = STORAGE_IMAGE;
  60.         $replaceOriginal=$gContent->getSourceFile();
  61.         if( file_exists( dirname( $replaceOriginal ).'/original.jpg' ) ) {
  62.             unlink( dirname( $replaceOriginal ).'/original.jpg' );
  63.         }
  64.     }
  65.  
  66.     $_REQUEST['purge_from_galleries'] = TRUE;
  67.     if( $gContent->store($_REQUEST) ) {
  68.         // refresh all hashes
  69.         $gContent->load();
  70.  
  71.         // if user uploaded a file with a different name, delete the previous original file
  72.         if( !empty( $replaceOriginal ) && $replaceOriginal != $gContent->getSourceFile() && file_exists( $replaceOriginal ) ) {
  73.             unlink( $replaceOriginal );
  74.         }
  75.  
  76.         // maybe we need to resize the original and generate thumbnails
  77.         if( !empty( $_REQUEST['resize'] ) ) {
  78.             $gContent->resizeOriginal( $_REQUEST['resize'] );
  79.         }
  80.         // This needs to happen after the store, else the image width/hieght are screwed for people using the background thumbnailer
  81.         if( !empty( $_REQUEST['rotate_image'] ) ) {
  82.             $gContent->rotateImage( $_REQUEST['rotate_image'] );
  83.         }
  84.         if( !empty( $_REQUEST['ajax'] ) ) {
  85.             // we need to refresh the images in the page after saving - not working yet - xing
  86.             header( 'Location: '.FISHEYE_PKG_URL."image_order.php?refresh=1&gallery_id=".$_REQUEST['gallery_id'] );
  87.             die;
  88.         }
  89.         $gContent->addToGalleries( $_REQUEST['gallery_additions'] );
  90.         if( !empty( $_REQUEST['generate_thumbnails'] ) ) {
  91.             $gContent->generateThumbnails();
  92.         }
  93.         if( empty( $gContent->mErrors ) ) {
  94.             // add a refresh parameter to the URL so the thumbnails will properly refresh first go reload
  95.             header( 'Location: '.$gContent->getDisplayUrl().($gBitSystem->isFeatureActive( 'pretty_urls' ) ? '?' : '&' ).'refresh=1' );
  96.             die;
  97.         }
  98.     }
  99. } elseif( !empty($_REQUEST['ajax_edit']) ) {
  100.     if( !empty( $_REQUEST['rotate_image'] ) ) {
  101.         $gContent->rotateImage( $_REQUEST['rotate_image'], TRUE );
  102.     }
  103. } elseif( !empty($_REQUEST['delete']) ) {
  104.     $gContent->verifyUserPermission( tra( "You do not have permission to delete this image." ) );
  105.  
  106.     if( !empty( $_REQUEST['cancel'] ) ) {
  107.         // user cancelled - just continue on, doing nothing
  108.     } elseif( empty( $_REQUEST['confirm'] ) ) {
  109.         $formHash['delete'] = TRUE;
  110.         $formHash['image_id'] = $gContent->mImageId;
  111.         $gBitSystem->confirmDialog( $formHash,
  112.             array(
  113.                 'warning' => tra('Are you sure you want to delete this image?') . ' (' . $gContent->getTitle() . ') ' . tra('It will be removed from all galleries to which it belongs.'),
  114.                 'error' => tra('This cannot be undone!'),
  115.             )
  116.         );
  117.     } else {
  118.         if( $gContent->expunge() ) {
  119.             $url = ( is_object( $gGallery ) ? $gGallery->getDisplayUrl() : FISHEYE_PKG_URL );
  120.             header( "Location: $url" );
  121.         }
  122.     }
  123. }
  124.  
  125. $errors = $gContent->mErrors;
  126. $gBitSmarty->assign_by_ref('errors', $errors);
  127.  
  128. $gContent->loadParentGalleries();
  129.  
  130. // Get a list of all existing galleries
  131. $gFisheyeGallery = new FisheyeGallery();
  132. $getHash = array(
  133.     'user_id'       => $gBitUser->mUserId,
  134. );
  135. if( $gContent->mContentId ) {
  136.     $getHash['contain_item'] = $gContent->mContentId;
  137. }
  138. // modify listHash according to global preferences
  139. if( $gBitSystem->isFeatureActive( 'fisheye_show_all_to_admins' ) && $gBitUser->hasPermission( 'p_fisheye_admin' ) ) {
  140.     unset( $getHash['user_id'] );
  141. } elseif( $gBitSystem->isFeatureActive( 'fisheye_show_public_on_upload' ) ) {
  142. //    $getHash['show_public'] = TRUE;
  143. }
  144. $galleryTree = $gFisheyeGallery->generateList( $getHash,  array( 'name' => "gallery_id", 'id' => "gallerylist", 'item_attributes' => array( 'class'=>'listingtitle'), 'radio_checkbox' => TRUE, ), true );
  145. $gBitSmarty->assign_by_ref( 'galleryTree', $galleryTree );
  146.  
  147. $gBitSmarty->assign('requested_gallery', !empty($_REQUEST['gallery_id']) ? $_REQUEST['gallery_id'] : NULL);
  148.  
  149. $gContent->invokeServices( 'content_edit_function' );
  150.  
  151. if( !empty( $_REQUEST['ajax'] ) ) {
  152.     echo $gBitSmarty->fetch( 'bitpackage:fisheye/edit_image_inc.tpl', tra('Edit Image: ').$gContent->getTitle() );
  153. } else {
  154.     $gBitSystem->display( 'bitpackage:fisheye/edit_image.tpl', tra('Edit Image: ').$gContent->getTitle() , array( 'display_mode' => 'edit' ));
  155. }
  156. ?>

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