PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/skilled-plugin/extensions/testimonial-rotator/admin/metaboxes-rotator.php

https://gitlab.com/ezgonzalez/integral
PHP | 265 lines | 208 code | 49 blank | 8 comment | 31 complexity | 8b82193ad74310f38a7c8cbce6cb67f4 MD5 | raw file
  1. <?php
  2. /* SHORTCODE DISPLAY HELPER */
  3. function testimonial_rotator_shortcode_metabox()
  4. {
  5. global $post;
  6. echo '
  7. <b>' . __('Base Rotator', 'testimonial-rotator') . '</b><br />
  8. [testimonial_rotator id="' . $post->ID . '"]<br /><br />
  9. <b>' . __('List All Testimonials', 'testimonial-rotator') . '</b><br />
  10. [testimonial_rotator id="' . $post->ID . '" format="list"]<br /><br />
  11. <b>' . __('Limit Results to 10 and list', 'testimonial-rotator') . '</b><br />
  12. [testimonial_rotator id="' . $post->ID . '" format="list" limit="10"]<br /><br />
  13. <b>' . __('Hide Titles', 'testimonial-rotator') . '</b><br />
  14. [testimonial_rotator id="' . $post->ID . '" hide_title="true"]<br /><br />
  15. <b>' . __('Randomize Testimonials', 'testimonial-rotator') . '</b><br />
  16. [testimonial_rotator id="' . $post->ID . '" shuffle="true"]<br /><br />
  17. ';
  18. }
  19. /* TESTIMONIAL ROTATOR EFFECTS AND TIMING */
  20. function testimonial_rotator_metabox_effects()
  21. {
  22. global $post;
  23. $timeout = (int) get_post_meta( $post->ID, '_timeout', true );
  24. $speed = (int) get_post_meta( $post->ID, '_speed', true );
  25. $fx = get_post_meta( $post->ID, '_fx', true );
  26. $shuffle = get_post_meta( $post->ID, '_shuffle', true );
  27. $verticalalign = get_post_meta( $post->ID, '_verticalalign', true );
  28. $prevnext = get_post_meta( $post->ID, '_prevnext', true );
  29. $hidefeaturedimage = get_post_meta( $post->ID, '_hidefeaturedimage', true );
  30. $hide_microdata = get_post_meta( $post->ID, '_hide_microdata', true );
  31. $limit = (int) get_post_meta( $post->ID, '_limit', true );
  32. $itemreviewed = get_post_meta( $post->ID, '_itemreviewed', true );
  33. $template = get_post_meta( $post->ID, '_template', true );
  34. $img_size = get_post_meta( $post->ID, '_img_size', true );
  35. $title_heading = get_post_meta( $post->ID, '_title_heading', true );
  36. $available_effects = testimonial_rotator_base_transitions();
  37. $image_sizes = get_intermediate_image_sizes();
  38. if(!$timeout) { $timeout = 5; }
  39. if(!$speed) { $speed = 1; }
  40. if(!$template) { $template = 'default'; }
  41. if(!$img_size) { $img_size = 'thumbnail'; }
  42. if(!$title_heading) { $title_heading = apply_filters('testimonial_rotator_title_heading', 'h2'); }
  43. $available_themes = testimonial_rotator_available_themes();
  44. ?>
  45. <style>
  46. .hg_slider_column { width: 46%; margin: 0 2%; float: left; }
  47. /* 680 */
  48. @media only screen and (max-width: 680px) {
  49. .hg_slider_column { width: 100%; margin: 0 0 20px 0; float: none; }
  50. }
  51. </style>
  52. <div class="hg_slider_column">
  53. <p>
  54. <select name="fx">
  55. <?php foreach($available_effects as $available_effect) { ?>
  56. <option value="<?php echo $available_effect ?>" <?php if($available_effect == $fx) echo " SELECTED"; ?>><?php echo $available_effect ?></option>
  57. <?php } ?>
  58. </select>
  59. <?php _e('Transition Effect', 'testimonial-rotator'); ?>
  60. </p>
  61. <p>
  62. <select name="img_size">
  63. <?php foreach($image_sizes as $image_size) { ?>
  64. <option value="<?php echo $image_size ?>" <?php if($image_size == $img_size) echo " SELECTED"; ?>><?php echo $image_size ?></option>
  65. <?php } ?>
  66. </select>
  67. <?php _e('Image Size', 'testimonial-rotator'); ?>
  68. </p>
  69. <p>
  70. <input type="text" style="width: 45px; text-align: center;" name="timeout" value="<?php echo esc_attr( $timeout ); ?>" maxlength="4" />
  71. <?php _e('Seconds per Testimonial', 'testimonial-rotator'); ?>
  72. </p>
  73. <p>
  74. <input type="text" style="width: 45px; text-align: center;" name="speed" value="<?php echo esc_attr( $speed ); ?>" maxlength="4" />
  75. <?php _e('Transition Speed (in seconds)', 'testimonial-rotator'); ?>
  76. </p>
  77. <p>
  78. <input type="text" style="width: 45px; text-align: center;" name="limit" value="<?php echo esc_attr( $limit ); ?>" maxlength="4" />
  79. <?php _e('Limit Number of Testimonials', 'testimonial-rotator'); ?>
  80. </p>
  81. <p>
  82. <input type="text" style="width: 45px; text-align: center;" name="title_heading" value="<?php echo esc_attr( $title_heading ); ?>" maxlength="12" />
  83. <?php _e('Element for Title Field', 'testimonial-rotator'); ?>
  84. </p>
  85. </div>
  86. <div class="hg_slider_column">
  87. <p>
  88. <input type="checkbox" name="shuffle" value="1" <?php if($shuffle) echo " CHECKED"; ?> />
  89. <?php _e('Randomize Testimonials', 'testimonial-rotator'); ?>
  90. </p>
  91. <p>
  92. <input type="checkbox" name="verticalalign" value="1" <?php if($verticalalign) echo " CHECKED"; ?> />
  93. <?php _e('Vertical Align (Center Testimonials Height)', 'testimonial-rotator'); ?>
  94. </p>
  95. <p>
  96. <input type="checkbox" name="prevnext" value="1" <?php if($prevnext) echo " CHECKED"; ?> />
  97. <?php _e('Show Previous/Next Buttons', 'testimonial-rotator'); ?>
  98. </p>
  99. <p>
  100. <input type="checkbox" name="hidefeaturedimage" value="1" <?php if($hidefeaturedimage) echo " CHECKED"; ?> />
  101. <?php _e('Hide Featured Image', 'testimonial-rotator'); ?>
  102. </p>
  103. <p>
  104. <input type="checkbox" name="hide_microdata" value="1" onchange="if(this.checked) { jQuery('#item-reviewed-p').slideUp(); } else { jQuery('#item-reviewed-p').slideDown(); }" <?php if($hide_microdata) echo " CHECKED"; ?> />
  105. <?php _e('Hide Microdata (hReview)', 'testimonial-rotator'); ?>
  106. </p>
  107. </div>
  108. <div class="clear"></div>
  109. <p id="item-reviewed-p" style="border-top: solid 1px #ccc; margin-top: 15px; padding-top: 15px;<?php if($hide_microdata) echo " display:none;"; ?>">
  110. <label for="itemreviewed"><?php _e('Name of Item Being Reviewed (optional):', 'testimonial-rotator'); ?></label><br />
  111. <small><?php _e("Company Name, Product Name, etc.", 'testimonial-rotator'); ?> (<?php _e("not visible on your website, used for search engines", 'testimonial-rotator'); ?>)</small><br />
  112. <input type="text" style="width: 80%;" id="itemreviewed" name="itemreviewed" value="<?php echo esc_attr( $itemreviewed ); ?>" />
  113. </p>
  114. <div style="padding: 15px 0; margin: 15px 0; border-top: solid 1px #ccc; border-bottom: solid 1px #ccc;">
  115. <style>
  116. .testimonial-rotator-template-selector-wrap { border: solid 5px #ccc; }
  117. .tr_template_selected { border: solid 5px #bee483; }
  118. #testimonial-rotator-templates a:focus { box-shadow: none; }
  119. </style>
  120. <script>
  121. jQuery(document).ready(function()
  122. {
  123. jQuery('.testimonial-rotator-template-selector-wrap a').on('click', function()
  124. {
  125. jQuery('.testimonial-rotator-template-selector-wrap').removeClass('tr_template_selected');
  126. jQuery('#testimonial_rotator_template').val( jQuery(this).data('slug') );
  127. jQuery(this).parent('.testimonial-rotator-template-selector-wrap').addClass('tr_template_selected');
  128. });
  129. });
  130. </script>
  131. <p>
  132. <strong><?php _e('Select a Theme:', 'testimonial-rotator'); ?></strong><br>
  133. </p>
  134. <div id="testimonial-rotator-templates">
  135. <?php foreach( $available_themes as $theme_slug => $available_theme ) { ?>
  136. <div class="testimonial-rotator-template-selector-wrap <?php if($template == $theme_slug) echo "tr_template_selected"; ?>" style="float: left; text-align: center; padding: 10px; margin: 10px; min-height: 100px;">
  137. <a href="javascript:;" class="testimonial-rotator-template-selector" data-slug="<?php echo esc_attr($theme_slug); ?>"><img src="<?php echo $available_theme['icon']; ?>" style="width: 155px;"></a><br>
  138. <b><?php echo $available_theme['title']; ?></b> - <a href="javascript:;" class="testimonial-rotator-template-selector" data-slug="<?php echo esc_attr($theme_slug); ?>"><?php echo __('Use', 'testimonial-rotator'); ?></a>
  139. </div>
  140. <?php } ?>
  141. <div style="float: left; text-align: center; padding: 10px; margin: 10px; min-height: 100px;">
  142. <a href="<?php echo TESTIMONIAL_ROTATOR_THEMES_URL; ?>" class="testimonial-rotator-template-selector" target="_blank"><img src="<?php echo TESTIMONIAL_ROTATOR_URI . "/images/get-themes.png"; ?>" style="width: 155px;"></a><br>
  143. <b>Add More Themes</b> - <a href="<?php echo TESTIMONIAL_ROTATOR_THEMES_URL; ?>" target="_blank"><?php echo __('Go', 'testimonial-rotator'); ?></a>
  144. </div>
  145. <div style="clear:both;"></div>
  146. <input type="hidden" name="template" id="testimonial_rotator_template" value="<?php echo $template; ?>" />
  147. </div>
  148. </div>
  149. <?php if($post->post_name) { ?>
  150. <p>
  151. <strong><?php _e('Make a Custom Template:', 'testimonial-rotator'); ?></strong><br>
  152. <?php _e('To create custom layouts for this rotator create a file called', 'testimonial-rotator'); ?>
  153. <b>loop-testimonial-<?php echo $post->post_name; ?>.php</b> <?php _e('and place it in your theme.', 'testimonial-rotator'); ?>
  154. </p>
  155. <?php } ?>
  156. <?php
  157. }
  158. /* SAVE TESTIMONIAL ROTATOR META DATA */
  159. function testimonial_rotator_save_rotator_meta( $post_id, $post )
  160. {
  161. global $post;
  162. if( isset( $_POST ) && isset( $post->ID ) )
  163. {
  164. // INPUTS
  165. if ( isset( $_POST['fx'] ) ) { update_post_meta( $post->ID, '_fx', strip_tags( $_POST['fx'] ) ); }
  166. if ( isset( $_POST['timeout'] ) ) { update_post_meta( $post->ID, '_timeout', strip_tags( $_POST['timeout'] ) ); }
  167. if ( isset( $_POST['speed'] ) ) { update_post_meta( $post->ID, '_speed', strip_tags( $_POST['speed'] ) ); }
  168. if ( isset( $_POST['limit'] ) ) { update_post_meta( $post->ID, '_limit', strip_tags( $_POST['limit'] ) ); }
  169. if ( isset( $_POST['itemreviewed'] ) ) { update_post_meta( $post->ID, '_itemreviewed', strip_tags( $_POST['itemreviewed'] ) ); }
  170. if ( isset( $_POST['template'] ) ) { update_post_meta( $post->ID, '_template', strip_tags( $_POST['template'] ) ); }
  171. if ( isset( $_POST['img_size'] ) ) { update_post_meta( $post->ID, '_img_size', strip_tags( $_POST['img_size'] ) ); }
  172. if ( isset( $_POST['title_heading'] ) ) { update_post_meta( $post->ID, '_title_heading', strip_tags( $_POST['title_heading'] ) ); }
  173. // CHECKBOXES
  174. update_post_meta( $post->ID, '_shuffle', isset( $_POST['shuffle']) ? 1 : 0 );
  175. update_post_meta( $post->ID, '_verticalalign', isset( $_POST['verticalalign']) ? 1 : 0 );
  176. update_post_meta( $post->ID, '_prevnext', isset( $_POST['prevnext']) ? 1 : 0 );
  177. update_post_meta( $post->ID, '_hidefeaturedimage', isset( $_POST['hidefeaturedimage']) ? 1 : 0 );
  178. update_post_meta( $post->ID, '_hide_microdata', isset( $_POST['hide_microdata']) ? 1 : 0 );
  179. }
  180. }
  181. function testimonial_rotator_testimonial_count_meta()
  182. {
  183. global $post;
  184. $originalpost = $post;
  185. $id = $post->ID;
  186. $testimonials_args = array(
  187. 'post_type' => 'testimonial',
  188. 'order' => 'ASC',
  189. 'orderby' => "menu_order",
  190. 'posts_per_page' => -1,
  191. 'meta_query' => testimonial_rotator_meta_query( $id )
  192. );
  193. // GET ROTATOR SLIDES
  194. $slide_query = new WP_Query( $testimonials_args );
  195. if ( $slide_query->have_posts() )
  196. {
  197. echo "<ol>";
  198. while ( $slide_query->have_posts() )
  199. {
  200. $slide_query->the_post();
  201. echo "<li><a href='post.php?post=" . get_the_id() . "&action=edit'>" . get_the_title() . "</a></li>";
  202. }
  203. echo "</ol>";
  204. echo "<a href='edit.php?post_type=testimonial&rotator_id=" . $id . "' class='button'>" . __('View in Edit List', 'testimonial-rotator') . "</a>";
  205. }
  206. else
  207. {
  208. echo "<p>" . __('No testimonials have been associated to this rotator yet.', 'testimonial-rotator') . "</p>";
  209. }
  210. wp_reset_postdata();
  211. $post = $originalpost;
  212. }