/wp-content/themes/osmosis/includes/admin/grve-admin-media-functions.php

https://github.com/Canuckaholic/Pop-Digital · PHP · 281 lines · 218 code · 45 blank · 18 comment · 5 complexity · 4bfc2fc8de3206f10a5a065885ed28da MD5 · raw file

  1. <?php
  2. /*
  3. * Collection of functions for the media items
  4. *
  5. * @author Greatives Team
  6. * @URI http://greatives.eu
  7. */
  8. $grve_media_align_selection = array(
  9. 'left' => __( 'Left', GRVE_THEME_TRANSLATE ),
  10. 'right' => __( 'Right', GRVE_THEME_TRANSLATE ),
  11. 'center' => __( 'Center', GRVE_THEME_TRANSLATE ),
  12. );
  13. $grve_media_color_selection = array(
  14. 'dark' => __( 'Dark', GRVE_THEME_TRANSLATE ),
  15. 'light' => __( 'Light', GRVE_THEME_TRANSLATE ),
  16. 'primary-1' => __( 'Primary 1', GRVE_THEME_TRANSLATE ),
  17. 'primary-2' => __( 'Primary 2', GRVE_THEME_TRANSLATE ),
  18. 'primary-3' => __( 'Primary 3', GRVE_THEME_TRANSLATE ),
  19. 'primary-4' => __( 'Primary 4', GRVE_THEME_TRANSLATE ),
  20. 'primary-5' => __( 'Primary 5', GRVE_THEME_TRANSLATE ),
  21. );
  22. $grve_media_header_style_selection = array(
  23. 'default' => __( 'Default', GRVE_THEME_TRANSLATE ),
  24. 'dark' => __( 'Dark', GRVE_THEME_TRANSLATE ),
  25. 'light' => __( 'Light', GRVE_THEME_TRANSLATE ),
  26. );
  27. $grve_media_color_overlay_selection = array(
  28. '' => __( 'None', GRVE_THEME_TRANSLATE ),
  29. 'dark' => __( 'Dark', GRVE_THEME_TRANSLATE ),
  30. 'light' => __( 'Light', GRVE_THEME_TRANSLATE ),
  31. 'primary-1' => __( 'Primary 1', GRVE_THEME_TRANSLATE ),
  32. 'primary-2' => __( 'Primary 2', GRVE_THEME_TRANSLATE ),
  33. 'primary-3' => __( 'Primary 3', GRVE_THEME_TRANSLATE ),
  34. 'primary-4' => __( 'Primary 4', GRVE_THEME_TRANSLATE ),
  35. 'primary-5' => __( 'Primary 5', GRVE_THEME_TRANSLATE ),
  36. );
  37. $grve_media_style_selection = array(
  38. 'default' => __( 'Default', GRVE_THEME_TRANSLATE ),
  39. '1' => __( 'Style 1', GRVE_THEME_TRANSLATE ),
  40. '2' => __( 'Style 2', GRVE_THEME_TRANSLATE ),
  41. '3' => __( 'Style 3', GRVE_THEME_TRANSLATE ),
  42. '4' => __( 'Style 4', GRVE_THEME_TRANSLATE ),
  43. );
  44. $grve_media_pattern_overlay_selection = array(
  45. '' => __( 'No', GRVE_THEME_TRANSLATE ),
  46. 'default' => __( 'Yes', GRVE_THEME_TRANSLATE ),
  47. );
  48. $grve_media_text_animation_selection = array(
  49. 'fade-in' => __( 'Default', GRVE_THEME_TRANSLATE ),
  50. 'fade-in-up' => __( 'Fade In Up', GRVE_THEME_TRANSLATE ),
  51. 'fade-in-down' => __( 'Fade In Down', GRVE_THEME_TRANSLATE ),
  52. 'fade-in-left' => __( 'Fade In Left', GRVE_THEME_TRANSLATE ),
  53. 'fade-in-right' => __( 'Fade In Right', GRVE_THEME_TRANSLATE ),
  54. );
  55. $grve_media_button_color_selection = array(
  56. 'primary-1' => __( 'Primary 1', GRVE_THEME_TRANSLATE ),
  57. 'primary-2' => __( 'Primary 2', GRVE_THEME_TRANSLATE ),
  58. 'primary-3' => __( 'Primary 3', GRVE_THEME_TRANSLATE ),
  59. 'primary-4' => __( 'Primary 4', GRVE_THEME_TRANSLATE ),
  60. 'primary-5' => __( 'Primary 5', GRVE_THEME_TRANSLATE ),
  61. 'green' => __( 'Green', GRVE_THEME_TRANSLATE ),
  62. 'orange' => __( 'Orange', GRVE_THEME_TRANSLATE ),
  63. 'red' => __( 'Red', GRVE_THEME_TRANSLATE ),
  64. 'blue' => __( 'Blue', GRVE_THEME_TRANSLATE ),
  65. 'aqua' => __( 'Aqua', GRVE_THEME_TRANSLATE ),
  66. 'purple' => __( 'Purple', GRVE_THEME_TRANSLATE ),
  67. 'black' => __( 'Black', GRVE_THEME_TRANSLATE ),
  68. 'grey' => __( 'Grey', GRVE_THEME_TRANSLATE ),
  69. 'white' => __( 'White', GRVE_THEME_TRANSLATE ),
  70. );
  71. $grve_media_button_size_selection = array(
  72. 'extrasmall' => __( 'Extra Small', GRVE_THEME_TRANSLATE ),
  73. 'small' => __( 'Small', GRVE_THEME_TRANSLATE ),
  74. 'medium' => __( 'Medium', GRVE_THEME_TRANSLATE ),
  75. 'large' => __( 'Large', GRVE_THEME_TRANSLATE ),
  76. 'extralarge' => __( 'Extra Large', GRVE_THEME_TRANSLATE ),
  77. );
  78. $grve_media_button_shape_selection = array(
  79. 'square' => __( 'Square', GRVE_THEME_TRANSLATE ),
  80. 'round' => __( 'Round', GRVE_THEME_TRANSLATE ),
  81. 'extra-round' => __( 'Extra Round', GRVE_THEME_TRANSLATE ),
  82. );
  83. $grve_media_button_type_selection = array(
  84. '' => __( 'Default', GRVE_THEME_TRANSLATE ),
  85. 'outline' => __( 'Outline', GRVE_THEME_TRANSLATE ),
  86. );
  87. $grve_media_button_target_selection = array(
  88. '_self' => __( 'Same Page', GRVE_THEME_TRANSLATE ),
  89. '_blank' => __( 'New page', GRVE_THEME_TRANSLATE ),
  90. );
  91. $grve_media_bg_position_selection = array(
  92. 'left-top' => __( 'Left Top', GRVE_THEME_TRANSLATE ),
  93. 'left-center' => __( 'Left Center', GRVE_THEME_TRANSLATE ),
  94. 'left-bottom' => __( 'Left Bottom', GRVE_THEME_TRANSLATE ),
  95. 'center-top' => __( 'Center Top', GRVE_THEME_TRANSLATE ),
  96. 'center-center' => __( 'Center Center', GRVE_THEME_TRANSLATE ),
  97. 'center-bottom' => __( 'Center Bottom', GRVE_THEME_TRANSLATE ),
  98. 'right-top' => __( 'Right Top', GRVE_THEME_TRANSLATE ),
  99. 'right-center' => __( 'Right Center', GRVE_THEME_TRANSLATE ),
  100. 'right-bottom' => __( 'Right Bottom', GRVE_THEME_TRANSLATE ),
  101. );
  102. $grve_media_bg_effect_selection = array(
  103. 'none' => __( 'None', GRVE_THEME_TRANSLATE ),
  104. 'zoom' => __( 'Zoom', GRVE_THEME_TRANSLATE ),
  105. );
  106. /**
  107. * Print Media Selector Functions
  108. */
  109. function grve_print_media_options( $selector_array, $current_value = "" ) {
  110. foreach ( $selector_array as $value=>$display_value ) {
  111. ?>
  112. <option value="<?php echo $value; ?>" <?php selected( $current_value, $value ); ?>><?php echo $display_value; ?></option>
  113. <?php
  114. }
  115. }
  116. function grve_print_media_button_color_selection( $current_value = "" ) {
  117. global $grve_media_button_color_selection;
  118. grve_print_media_options( $grve_media_button_color_selection, $current_value );
  119. }
  120. function grve_print_media_button_size_selection( $current_value = "" ) {
  121. global $grve_media_button_size_selection;
  122. grve_print_media_options( $grve_media_button_size_selection, $current_value );
  123. }
  124. function grve_print_media_button_shape_selection( $current_value = "" ) {
  125. global $grve_media_button_shape_selection;
  126. grve_print_media_options( $grve_media_button_shape_selection, $current_value );
  127. }
  128. function grve_print_media_button_type_selection( $current_value = "" ) {
  129. global $grve_media_button_type_selection;
  130. grve_print_media_options( $grve_media_button_type_selection, $current_value );
  131. }
  132. function grve_print_media_button_target_selection( $current_value = "" ) {
  133. global $grve_media_button_target_selection;
  134. grve_print_media_options( $grve_media_button_target_selection, $current_value );
  135. }
  136. function grve_print_media_style_selection( $current_value = "" ) {
  137. global $grve_media_style_selection;
  138. grve_print_media_options( $grve_media_style_selection, $current_value );
  139. }
  140. function grve_print_media_color_selection( $current_value = "" ) {
  141. global $grve_media_color_selection;
  142. grve_print_media_options( $grve_media_color_selection, $current_value );
  143. }
  144. function grve_print_media_align_selection( $current_value = "" ) {
  145. global $grve_media_align_selection;
  146. grve_print_media_options( $grve_media_align_selection, $current_value );
  147. }
  148. function grve_print_media_header_style_selection( $current_value = "" ) {
  149. global $grve_media_header_style_selection;
  150. grve_print_media_options( $grve_media_header_style_selection, $current_value );
  151. }
  152. function grve_print_media_color_overlay_selection( $current_value = "" ) {
  153. global $grve_media_color_overlay_selection;
  154. grve_print_media_options( $grve_media_color_overlay_selection, $current_value );
  155. }
  156. function grve_print_media_pattern_overlay_selection( $current_value = "" ) {
  157. global $grve_media_pattern_overlay_selection;
  158. grve_print_media_options( $grve_media_pattern_overlay_selection, $current_value );
  159. }
  160. function grve_print_media_opacity_overlay_selection( $current_value = "" ) {
  161. for ( $i = 1; $i <= 9; $i++ ) {
  162. $value = $i*10 ;
  163. ?>
  164. <option value="<?php echo $value; ?>" <?php selected( $current_value, $value ); ?>>
  165. <?php echo $value; ?>
  166. </option>
  167. <?php
  168. }
  169. }
  170. function grve_print_media_text_animation_selection( $current_value = "" ) {
  171. global $grve_media_text_animation_selection;
  172. grve_print_media_options( $grve_media_text_animation_selection, $current_value );
  173. }
  174. function grve_print_media_bg_position_selection( $current_value = "center-center" ) {
  175. global $grve_media_bg_position_selection;
  176. grve_print_media_options( $grve_media_bg_position_selection, $current_value );
  177. }
  178. function grve_print_media_bg_effect_selection( $current_value = "" ) {
  179. global $grve_media_bg_effect_selection;
  180. grve_print_media_options( $grve_media_bg_effect_selection, $current_value );
  181. }
  182. /**
  183. * Prints Media Slider items
  184. */
  185. function grve_print_admin_media_slider_items( $slider_items ) {
  186. foreach ( $slider_items as $slider_item ) {
  187. grve_print_admin_media_slider_item( $slider_item, '' );
  188. }
  189. }
  190. /**
  191. * Get Single Slider Media with ajax
  192. */
  193. function grve_get_slider_media() {
  194. if( isset( $_POST['attachment_ids'] ) ) {
  195. $attachment_ids = $_POST['attachment_ids'];
  196. if( !empty( $attachment_ids ) ) {
  197. $media_ids = explode(",", $attachment_ids);
  198. foreach ( $media_ids as $media_id ) {
  199. $slider_item = array (
  200. 'id' => $media_id,
  201. );
  202. grve_print_admin_media_slider_item( $slider_item, "new" );
  203. }
  204. }
  205. }
  206. if( isset( $_POST['attachment_ids'] ) ) { die(); }
  207. }
  208. add_action( 'wp_ajax_grve_get_slider_media', 'grve_get_slider_media' );
  209. /**
  210. * Prints Single Slider Media Item
  211. */
  212. function grve_print_admin_media_slider_item( $slider_item, $new = "" ) {
  213. $media_id = $slider_item['id'];
  214. $title = '';
  215. $thumb_src = wp_get_attachment_image_src( $media_id, 'thumbnail' );
  216. $thumbnail_url = $thumb_src[0];
  217. $alt = get_post_meta( $media_id, '_wp_attachment_image_alt', true );
  218. $alt = ! empty( $alt ) ? esc_attr( $alt ) : '';
  219. $grve_button_class = "grve-slider-item-delete-button";
  220. if( $new = "new" ) {
  221. $grve_button_class = "grve-slider-item-delete-button grve-item-new";
  222. }
  223. ?>
  224. <div class="grve-slider-item-minimal">
  225. <input class="<?php echo $grve_button_class; ?> button" type="button" value="<?php _e( 'Delete', GRVE_THEME_TRANSLATE ); ?>">
  226. <h3 class="hndle grve-title">
  227. <span><?php _e( 'Image', GRVE_THEME_TRANSLATE ); ?></span>
  228. </h3>
  229. <div class="inside">
  230. <input type="hidden" value="<?php echo $media_id; ?>" name="grve_media_slider_item_id[]">
  231. <?php echo '<img class="grve-thumb" src="' . $thumbnail_url . '" title="' . $title . '" attid="' . $media_id . '" alt="' . $alt . '" width="120" height="120"/>'; ?>
  232. </div>
  233. </div>
  234. <?php
  235. }
  236. ?>