PageRenderTime 39ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/Wordpress-Project/wp-content/plugins/foogallery/extensions/default-templates/thumbnail/class-thumbnail-gallery-template.php

https://bitbucket.org/hinzanhilmy/hinzan-sample-works
PHP | 214 lines | 150 code | 17 blank | 47 comment | 6 complexity | 87611dc36a3305ceadd38a22f56fe140 MD5 | raw file
Possible License(s): GPL-3.0, 0BSD, Apache-2.0, BSD-2-Clause, MPL-2.0-no-copyleft-exception, LGPL-2.1, GPL-2.0, BSD-3-Clause, MIT
  1. <?php
  2. if ( !class_exists( 'FooGallery_Thumbnail_Gallery_Template' ) ) {
  3. define('FOOGALLERY_THUMBNAIL_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ ));
  4. class FooGallery_Thumbnail_Gallery_Template {
  5. /**
  6. * Wire up everything we need to run the extension
  7. */
  8. function __construct() {
  9. add_filter( 'foogallery_gallery_templates', array( $this, 'add_template' ) );
  10. add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) );
  11. add_filter( 'foogallery_located_template-thumbnail', array( $this, 'enqueue_dependencies' ) );
  12. //build up any preview arguments
  13. add_filter( 'foogallery_preview_arguments-thumbnail', array( $this, 'preview_arguments' ), 10, 2 );
  14. //build up the thumb dimensions from some arguments
  15. add_filter( 'foogallery_calculate_thumbnail_dimensions-thumbnail', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 );
  16. //build up the thumb dimensions on save
  17. add_filter( 'foogallery_template_thumbnail_dimensions-thumbnail', array( $this, 'get_thumbnail_dimensions' ), 10, 2 );
  18. //alter the crop value if needed
  19. add_filter( 'foogallery_render_gallery_template_field_value', array( $this, 'alter_field_value'), 10, 4 );
  20. }
  21. function alter_field_value( $value, $field, $gallery, $template ) {
  22. //only do something if we are dealing with the thumbnail_dimensions field in this template
  23. if ( 'thumbnail' === $template['slug'] && 'thumbnail_dimensions' === $field['id'] ) {
  24. if ( !array_key_exists( 'crop', $value ) ) {
  25. $value['crop'] = true;
  26. }
  27. }
  28. return $value;
  29. }
  30. /**
  31. * Register myself so that all associated JS and CSS files can be found and automatically included
  32. * @param $extensions
  33. *
  34. * @return array
  35. */
  36. function register_myself( $extensions ) {
  37. $extensions[] = __FILE__;
  38. return $extensions;
  39. }
  40. /**
  41. * Add our gallery template to the list of templates available for every gallery
  42. * @param $gallery_templates
  43. *
  44. * @return array
  45. */
  46. function add_template( $gallery_templates ) {
  47. $gallery_templates[] = array(
  48. 'slug' => 'thumbnail',
  49. 'name' => __( 'Single Thumbnail Gallery', 'foogallery' ),
  50. 'preview_support' => true,
  51. 'common_fields_support' => true,
  52. 'lazyload_support' => true,
  53. 'mandatory_classes' => 'fg-thumbnail',
  54. 'thumbnail_dimensions' => true,
  55. 'fields' => array(
  56. array(
  57. 'id' => 'help',
  58. 'type' => 'html',
  59. 'section' => __( 'General', 'foogallery' ),
  60. 'help' => true,
  61. 'desc' => __( 'This gallery template only shows a single thumbnail, but the true power shines through when the thumbnail is clicked, because then the lightbox takes over and the user can view all the images in the gallery.', 'foogallery' ),
  62. ),
  63. array(
  64. 'id' => 'thumbnail_dimensions',
  65. 'title' => __( 'Size', 'foogallery' ),
  66. 'desc' => __( 'Choose the size of your thumbnail.', 'foogallery' ),
  67. 'section' => __( 'General', 'foogallery' ),
  68. 'type' => 'thumb_size',
  69. 'default' => array(
  70. 'width' => 250,
  71. 'height' => 200,
  72. 'crop' => true
  73. ),
  74. 'row_data'=> array(
  75. 'data-foogallery-change-selector' => 'input',
  76. 'data-foogallery-preview' => 'shortcode'
  77. )
  78. ),
  79. array(
  80. 'id' => 'position',
  81. 'title' => __( 'Position', 'foogallery' ),
  82. 'desc' => __( 'The position of the thumbnail related to the content around it.', 'foogallery' ),
  83. 'section' => __( 'General', 'foogallery' ),
  84. 'default' => 'position-block',
  85. 'type' => 'select',
  86. 'choices' => array(
  87. 'fg-center' => __( 'Full Width (block)', 'foogallery' ),
  88. 'fg-left' => __( 'Float Left', 'foogallery' ),
  89. 'fg-right' => __( 'Float Right', 'foogallery' ),
  90. ),
  91. 'row_data'=> array(
  92. 'data-foogallery-change-selector' => 'select',
  93. 'data-foogallery-preview' => 'class'
  94. )
  95. ),
  96. array(
  97. 'id' => 'link_custom_url',
  98. 'title' => __( 'Link To Custom URL', 'foogallery' ),
  99. 'section' => __( 'General', 'foogallery' ),
  100. 'default' => '',
  101. 'type' => 'checkbox',
  102. 'desc' => __( 'You can link your thumbnails to Custom URL\'s (if they are set on your attachments). Fallback will be to the full size image.', 'foogallery' )
  103. ),
  104. array(
  105. 'id' => 'lightbox',
  106. 'title' => __( 'Lightbox', 'foogallery' ),
  107. 'section' => __( 'General', 'foogallery' ),
  108. 'desc' => __( 'Choose which lightbox you want to use.', 'foogallery' ),
  109. 'type' => 'lightbox',
  110. 'default' => 'none',
  111. ),
  112. array(
  113. 'id' => 'caption_title',
  114. 'title' => __('Override Title', 'foogallery'),
  115. 'section' => __( 'Captions', 'foogallery' ),
  116. 'desc' => __('Leave blank if you do not want a caption title.', 'foogallery'),
  117. 'type' => 'text',
  118. 'row_data'=> array(
  119. 'data-foogallery-change-selector' => 'input',
  120. 'data-foogallery-preview' => 'shortcode'
  121. )
  122. ),
  123. array(
  124. 'id' => 'caption_description',
  125. 'title' => __('Override Description', 'foogallery'),
  126. 'section' => __( 'Captions', 'foogallery' ),
  127. 'desc' => __('Leave blank if you do not want a caption description.', 'foogallery'),
  128. 'type' => 'textarea',
  129. 'row_data'=> array(
  130. 'data-foogallery-change-selector' => 'textarea',
  131. 'data-foogallery-preview' => 'shortcode'
  132. )
  133. )
  134. )
  135. );
  136. return $gallery_templates;
  137. }
  138. /**
  139. * Enqueue scripts that the masonry gallery template relies on
  140. */
  141. function enqueue_dependencies() {
  142. //enqueue core files
  143. foogallery_enqueue_core_gallery_template_style();
  144. foogallery_enqueue_core_gallery_template_script();
  145. }
  146. /**
  147. * Build up a arguments used in the preview of the gallery
  148. * @param $args
  149. * @param $post_data
  150. *
  151. * @return mixed
  152. */
  153. function preview_arguments( $args, $post_data ) {
  154. $args['thumbnail_dimensions'] = $post_data[FOOGALLERY_META_SETTINGS]['thumbnail_thumbnail_dimensions'];
  155. $args['caption_title'] = $post_data[FOOGALLERY_META_SETTINGS]['thumbnail_caption_title'];
  156. $args['caption_description'] = $post_data[FOOGALLERY_META_SETTINGS]['thumbnail_caption_description'];
  157. return $args;
  158. }
  159. /**
  160. * Builds thumb dimensions from arguments
  161. *
  162. * @param array $dimensions
  163. * @param array $arguments
  164. *
  165. * @return mixed
  166. */
  167. function build_thumbnail_dimensions_from_arguments( $dimensions, $arguments ) {
  168. if ( array_key_exists( 'thumbnail_dimensions', $arguments) ) {
  169. return array(
  170. 'height' => intval($arguments['thumbnail_dimensions']['height']),
  171. 'width' => intval($arguments['thumbnail_dimensions']['width']),
  172. 'crop' => $arguments['thumbnail_dimensions']['crop']
  173. );
  174. }
  175. return null;
  176. }
  177. /**
  178. * Get the thumb dimensions arguments saved for the gallery for this gallery template
  179. *
  180. * @param array $dimensions
  181. * @param FooGallery $foogallery
  182. *
  183. * @return mixed
  184. */
  185. function get_thumbnail_dimensions( $dimensions, $foogallery ) {
  186. $dimensions = $foogallery->get_meta( 'thumbnail_thumbnail_dimensions', array(
  187. 'width' => get_option( 'thumbnail_size_w' ),
  188. 'height' => get_option( 'thumbnail_size_h' ),
  189. 'crop' => true
  190. ) );
  191. if ( !array_key_exists( 'crop', $dimensions ) ) {
  192. $dimensions['crop'] = true;
  193. }
  194. return $dimensions;
  195. }
  196. }
  197. }