PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/yoimages/vendor/sirulli/yoimages-crop/inc/html/edit-image-size.php

https://bitbucket.org/studioparkers/spinozacentre.2018.nl
PHP | 218 lines | 210 code | 8 blank | 0 comment | 36 complexity | 2d6f31c2479653b5392e9a2c9f872604 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, MIT, Apache-2.0
  1. <?php
  2. if ( ! defined ( 'ABSPATH' ) ) {
  3. die ( 'No script kiddies please!' );
  4. }
  5. $yoimg_retina_crop_enabled = yoimg_is_retina_crop_enabled_for_size( $yoimg_image_size );
  6. $is_immediate_cropping = isset( $_GET['immediatecrop'] ) && $_GET['immediatecrop'] == '1';
  7. $is_partial_rendering = isset( $_GET['partial'] ) && $_GET['partial'] == '1';
  8. if ( ! $is_partial_rendering ) {
  9. ?>
  10. <script>
  11. var yoimg_image_id, yoimg_image_size, yoimg_cropper_min_width, yoimg_cropper_min_height, yoimg_cropper_aspect_ratio,yoimg_prev_crop_x, yoimg_prev_crop_y, yoimg_prev_crop_width, yoimg_prev_crop_height, yoimg_retina_crop_enabled;
  12. </script>
  13. <?php
  14. }
  15. $attachment_metadata = wp_get_attachment_metadata( $yoimg_image_id );
  16. $cropped_image_sizes = yoimg_get_image_sizes( $yoimg_image_size );
  17. if ( isset( $attachment_metadata['yoimg_attachment_metadata']['crop'][$yoimg_image_size]['replacement'] ) ) {
  18. $replacement = $attachment_metadata['yoimg_attachment_metadata']['crop'][$yoimg_image_size]['replacement'];
  19. } else {
  20. $replacement = null;
  21. }
  22. $has_replacement = ! empty ( $replacement ) && get_post( $replacement );
  23. if ( $has_replacement ) {
  24. $full_image_attributes = wp_get_attachment_image_src( $replacement, 'full' );
  25. } else {
  26. $full_image_attributes = wp_get_attachment_image_src( $yoimg_image_id, 'full' );
  27. }
  28. ?>
  29. <script>
  30. yoimg_image_id = <?php echo $yoimg_image_id; ?>;
  31. yoimg_image_size = '<?php echo $yoimg_image_size; ?>';
  32. <?php
  33. if ( $yoimg_retina_crop_enabled ) {
  34. ?>
  35. yoimg_cropper_min_width = <?php echo $cropped_image_sizes['width'] * 2; ?>;
  36. yoimg_cropper_min_height = <?php echo $cropped_image_sizes['height'] * 2; ?>;
  37. yoimg_retina_crop_enabled = true;
  38. <?php
  39. } else {
  40. ?>
  41. yoimg_cropper_min_width = <?php echo $cropped_image_sizes['width']; ?>;
  42. yoimg_cropper_min_height = <?php echo $cropped_image_sizes['height']; ?>;
  43. yoimg_retina_crop_enabled = false;
  44. <?php
  45. }
  46. ?>
  47. yoimg_cropper_aspect_ratio = <?php echo $cropped_image_sizes['width']; ?> / <?php echo $cropped_image_sizes['height']; ?>;
  48. <?php
  49. if ( isset( $attachment_metadata['yoimg_attachment_metadata']['crop'][$yoimg_image_size]['x'] ) ) {
  50. $crop_x = $attachment_metadata['yoimg_attachment_metadata']['crop'][$yoimg_image_size]['x'];
  51. } else {
  52. $crop_x = null;
  53. }
  54. if ( is_numeric( $crop_x ) && $crop_x >= 0 && ( ! $is_immediate_cropping ) ) {
  55. ?>
  56. yoimg_prev_crop_x = <?php echo $crop_x; ?>;
  57. yoimg_prev_crop_y = <?php echo $attachment_metadata['yoimg_attachment_metadata']['crop'][$yoimg_image_size]['y']; ?>;
  58. yoimg_prev_crop_width = <?php echo $attachment_metadata['yoimg_attachment_metadata']['crop'][$yoimg_image_size]['width']; ?>;
  59. yoimg_prev_crop_height = <?php echo $attachment_metadata['yoimg_attachment_metadata']['crop'][$yoimg_image_size]['height']; ?>;
  60. <?php
  61. } else {
  62. ?>
  63. yoimg_prev_crop_x = undefined;
  64. yoimg_prev_crop_y = undefined;
  65. yoimg_prev_crop_width = undefined;
  66. yoimg_prev_crop_height = undefined;
  67. <?php
  68. }
  69. ?>
  70. </script>
  71. <?php if ( ! $is_partial_rendering ) { ?>
  72. <div id="yoimg-cropper-wrapper">
  73. <div class="media-modal wp-core-ui">
  74. <button type="button" class="media-modal-close" onclick="javascript:yoimgCancelCropImage();">
  75. <span class="media-modal-icon">
  76. <span class="screen-reader-text"><?php _e( 'Close crop panel', YOIMG_DOMAIN ); ?></span>
  77. </span>
  78. </button>
  79. <div class="media-modal-content">
  80. <?php } ?>
  81. <div class="media-frame wp-core-ui">
  82. <div class="media-frame-title"><h1><?php _e( 'Edit crop formats from full image', YOIMG_DOMAIN ); ?> (<?php echo $full_image_attributes[1]; ?>x<?php echo $full_image_attributes[2]; ?>)</h1></div>
  83. <div class="media-frame-router">
  84. <button type="button" class="button-link arrows arrow-l">
  85. <span class="dashicons dashicons-arrow-left-alt2"></span>
  86. </button>
  87. <div class="media-router">
  88. <?php
  89. $sizes = yoimg_get_image_sizes ();
  90. foreach ( $sizes as $size_key => $size_value ) {
  91. if ( $size_value['crop'] == 1 && $size_value['active'] ) {
  92. $is_current_size = $size_key === $yoimg_image_size;
  93. if ( $is_current_size ) {
  94. $curr_size_width = $size_value['width'];
  95. $curr_size_height = $size_value['height'];
  96. }
  97. $anchor_class = $is_current_size ? 'active' : '';
  98. $anchor_href = yoimg_get_edit_image_url( $yoimg_image_id, $size_key ) . '&partial=1';
  99. ?>
  100. <a href="<?php echo $anchor_href; ?>" class="media-menu-item yoimg-thickbox yoimg-thickbox-partial <?php echo $anchor_class; ?>"><?php echo $size_value['name']; ?></a>
  101. <?php
  102. }
  103. }
  104. ?>
  105. </div>
  106. <button type="button" class="button-link arrows arrow-r">
  107. <span class="dashicons dashicons-arrow-right-alt2"></span>
  108. </button>
  109. </div>
  110. <div class="media-frame-content">
  111. <div class="attachments-browser">
  112. <div class="attachments">
  113. <div id="yoimg-cropper-container" style="max-width: <?php echo $full_image_attributes[1]; ?>px;max-height: <?php echo $full_image_attributes[2]; ?>px;">
  114. <img id="yoimg-cropper" src="<?php echo $full_image_attributes[0] . '?' . mt_rand( 1000, 9999 ); ?>" style="max-width: 100%;" />
  115. <div id="yoimg-replace-restore-wrapper">
  116. <div id="yoimg-replace-img-btn" style="display:none;" title="<?php _e( 'Replace image source for', YOIMG_DOMAIN ); ?> <?php echo $yoimg_image_size; ?>" class="button button-primary button-large"><?php _e( 'Replace', YOIMG_DOMAIN ); ?></div>
  117. <?php if ( $has_replacement ) {?>
  118. <div id="yoimg-restore-img-btn" title="<?php _e( 'Restore original image source for', YOIMG_DOMAIN ); ?> <?php echo $yoimg_image_size; ?>" class="button button-large"><?php _e( 'Restore', YOIMG_DOMAIN ); ?></div>
  119. <?php } ?>
  120. </div>
  121. </div>
  122. </div>
  123. <div class="media-sidebar">
  124. <div class="attachment-details">
  125. <?php
  126. $is_crop_smaller = false;
  127. $is_crop_retina_smaller = false;
  128. $this_crop_exists = ! empty( $attachment_metadata['sizes'][$yoimg_image_size]['file'] );
  129. if ( $this_crop_exists ) {
  130. ?>
  131. <h3><?php _e( 'Current', YOIMG_DOMAIN ); ?> <?php echo $cropped_image_sizes['name']; ?> (<?php echo $attachment_metadata['sizes'][$yoimg_image_size]['width']; ?>x<?php echo $attachment_metadata['sizes'][$yoimg_image_size]['height']; ?>)</h3>
  132. <?php
  133. } else {
  134. ?>
  135. <h3><?php _e( 'Current', YOIMG_DOMAIN ); ?> <?php echo $cropped_image_sizes['name']; ?> (<?php echo $curr_size_width; ?>x<?php echo $curr_size_height; ?>)</h3>
  136. <?php
  137. }
  138. $image_attributes = wp_get_attachment_image_src( $yoimg_image_id, $yoimg_image_size );
  139. if ( $this_crop_exists ) {
  140. ?>
  141. <img src="<?php echo $image_attributes[0] . '?' . mt_rand( 1000, 9999 ); ?>" style="max-width: 100%;" />
  142. <?php
  143. $is_crop_smaller = $full_image_attributes[1] < $curr_size_width || $full_image_attributes[2] < $curr_size_height;
  144. $is_crop_retina_smaller = $yoimg_retina_crop_enabled && ( $full_image_attributes[1] < ( $curr_size_width * 2 ) || $full_image_attributes[2] < ( $curr_size_height * 2 ) );
  145. } else {
  146. $img_url_parts = parse_url( $image_attributes[0] );
  147. $img_path_parts = pathinfo( $img_url_parts['path'] );
  148. $expected_crop_width = $cropped_image_sizes['width'];
  149. $expected_crop_height = $cropped_image_sizes['height'];
  150. $expected_url = $img_path_parts['dirname'] . '/' . yoimg_get_cropped_image_filename( $img_path_parts['filename'], $expected_crop_width, $expected_crop_height, $img_path_parts['extension'] );
  151. ?>
  152. <div class="yoimg-not-existing-crop">
  153. <img src="<?php echo $expected_url; ?>" style="max-width: 100%;" />
  154. <div class="message error">
  155. <p><?php _e( 'Crop not generated yet, use the crop button here below to generate it', YOIMG_DOMAIN ); ?></p>
  156. </div>
  157. </div>
  158. <?php } ?>
  159. <div class="message error yoimg-crop-smaller" style="display:<?php echo $is_crop_smaller ? 'block' : 'none'; ?>;">
  160. <?php //TODO ?>
  161. <p><?php _e( 'This crop is smaller than expected, you may replace the original image for this crop format using the replace button on the left and then cropping it', YOIMG_DOMAIN ); ?></p>
  162. </div>
  163. <div class="message error yoimg-crop-retina-smaller" style="display:<?php echo $is_crop_retina_smaller ? 'block' : 'none'; ?>;">
  164. <p><?php _e( 'This crop is too small to create the retina version of the image, you may replace the original image for this crop format using the replace button on the left and then crop it again.', YOIMG_DOMAIN ); ?></p>
  165. </div>
  166. <h3 id="yoimg-cropper-preview-title"><?php _e( 'Crop preview', YOIMG_DOMAIN ); ?></h3>
  167. <div id="yoimg-cropper-preview"></div>
  168. <div class="yoimg-cropper-quality-wrapper">
  169. <label for="yoimg-cropper-quality"><?php _e( 'Crop quality', YOIMG_DOMAIN ); ?>:</label>
  170. <select name="quality" id="yoimg-cropper-quality">
  171. <?php
  172. $yoimg_crop_settings = get_option( 'yoimg_crop_settings' );
  173. $crop_qualities = $yoimg_crop_settings && isset( $yoimg_crop_settings['crop_qualities'] ) ? $yoimg_crop_settings['crop_qualities'] : unserialize( YOIMG_DEFAULT_CROP_QUALITIES );
  174. foreach ($crop_qualities AS $index => $value) {
  175. ?>
  176. <option value="<?php echo $value; ?>"><?php echo $value; ?>%</option>
  177. <?php
  178. }
  179. ?>
  180. </select>
  181. </div>
  182. <div class="yoimg-crop-now-wrapper">
  183. <a href="javascript:yoimgCropImage();"
  184. class="button media-button button-primary button-large media-button-select">
  185. <?php _e( 'Crop', YOIMG_DOMAIN ); ?> <?php echo $cropped_image_sizes['name']; ?>
  186. </a>
  187. <span class="spinner"></span>
  188. </div>
  189. </div>
  190. </div>
  191. </div>
  192. </div>
  193. </div>
  194. <?php if ( ! $is_partial_rendering ) { ?>
  195. </div>
  196. </div>
  197. <div id="yoimg-cropper-bckgr" class="media-modal-backdrop"></div>
  198. </div>
  199. <?php
  200. }
  201. if ( $is_immediate_cropping ) {
  202. ?>
  203. <script>yoimgInitCropImage(true);</script>
  204. <?php
  205. } else {
  206. ?>
  207. <script>yoimgInitCropImage();</script>
  208. <?php
  209. }
  210. exit();