Advertisement
towfiqi

facebook testimonials.php

Feb 24th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.14 KB | None | 0 0
  1. <?php
  2. /*
  3. *FRONTPAGE - Testimonials WIDGET
  4. */
  5. add_action( 'widgets_init', 'optimizer_register_front_testimonialss' );
  6.  
  7. /*
  8. * Register widget.
  9. */
  10. function remove_testi_widget() {
  11. unregister_widget('optimizer_front_testimonials');
  12. }
  13.  
  14. add_action( 'widgets_init', 'remove_testi_widget' );
  15.  
  16.  
  17. function optimizer_register_front_testimonialss() {
  18. register_widget( 'optimizer_front_testimonialss' );
  19. }
  20.  
  21.  
  22. /*
  23. * Widget class.
  24. */
  25. class optimizer_front_Testimonialss extends WP_Widget {
  26.  
  27. /* ---------------------------- */
  28. /* -------- Widget setup -------- */
  29. /* ---------------------------- */
  30.  
  31.  
  32. function __construct() {
  33. if(is_customize_preview()){$widgetname = __( 'Testimonial', 'optimizer' ); }else{ $widgetname = __( '&diams; Testimonial Widget', 'optimizer' ); }
  34.  
  35. parent::__construct( 'optimizer_front_testimonials', $widgetname, array(
  36. 'classname' => 'optimizer_front_testimonials home_testi',
  37. 'description' => __( 'Optimizer Testimonial Section widget', 'optimizer' ),
  38. 'customize_selective_refresh' => true,
  39. ) );
  40. $this->alt_option_name = 'optimizer_front_testimonials';
  41. add_action('wp_enqueue_scripts', array(&$this, 'front_testi_enqueue_css'));
  42. }
  43.  
  44. /* ---------------------------- */
  45. /* ------- Display Widget -------- */
  46. /* ---------------------------- */
  47.  
  48. function widget( $args, $instance ) {
  49.  
  50.  
  51. extract( $args );
  52. /* Our variables from the widget settings. */
  53. $title = isset( $instance['title'] ) ? $instance['title'] : __('What are people saying?', 'optimizer');
  54. $subtitle = isset( $instance['subtitle'] ) ? $instance['subtitle'] : __('Testimonial Subtitle', 'optimizer');
  55. $custom_testi = isset( $instance['custom_testi'] ) ? $instance['custom_testi'] : array();
  56. $twitter_testi_on = isset( $instance['twitter_testi_on'] ) ? $instance['twitter_testi_on'] : '';
  57. $twitter_testi = isset( $instance['twitter_testi'] ) ? $instance['twitter_testi'] : array();
  58. $testi_layout = isset( $instance['testi_layout'] ) ? $instance['testi_layout'] : 'col1';
  59. $divider = isset( $instance['divider'] ) ? apply_filters('widget_title', $instance['divider']) : 'fa-stop';
  60. $content_color = isset( $instance['content_color'] ) ? $instance['content_color'] : '';
  61. $title_color = isset( $instance['title_color'] ) ? $instance['title_color'] : '';
  62. $content_bg = isset( $instance['content_bg'] ) ? $instance['content_bg'] : '';
  63. $content_bgimg = isset( $instance['content_bgimg'] ) ? $instance['content_bgimg'] : '';
  64. $testi_pausetime = isset( $instance['testi_pausetime'] ) ? $instance['testi_pausetime'] : '8000';
  65.  
  66. /* Before widget (defined by themes). */
  67. echo $before_widget;
  68.  
  69. //Sitegorigin Builder FIX
  70. echo '<span class="so_widget_id" data-panel-id="'.$this->id.'"></span>';
  71. if(is_customize_preview()) echo '<span class="widgetname">'.$this->name.'</span>';
  72.  
  73. ?>
  74. <?php
  75.  
  76. //WIDGET EDIT BUTTON(Customizer)
  77. if(is_customize_preview()){ echo '<a class="edit_widget" title="'.__('Edit ','optimizer').$this->id.'"><i class="fa fa-pencil"></i></a>'; }
  78.  
  79. echo '<div class="home_testi_inner testi_'.$testi_layout.'"><div class="center">';
  80. echo '<div class="homeposts_title testimonial_title title_'.str_replace('fa-','dvd_',$divider).'">';
  81. if ( $title || is_customize_preview() ){
  82. echo '<h2 class="home_title"><span>'.do_shortcode($title).'</span></h2>';
  83. }
  84. if ( $subtitle || is_customize_preview() ){
  85. echo '<div class="home_subtitle"><span>'.do_shortcode($subtitle).'</span></div>';
  86. }
  87. if ( $divider ){
  88. if( $divider !== 'no_divider'){
  89. if($divider == 'underline'){ $underline= 'title_underline';}else{$underline='';}
  90. echo '<div class="optimizer_divider '.$underline.' divider_style_'.str_replace('fa-','dvd_',$divider).'"><span class="div_left"></span><span class="div_middle"><i class="fa '.$divider.'"></i></span><span class="div_right"></span></div>';
  91. }
  92. }
  93. echo '</div>';
  94.  
  95. if(!isset($instance['custom_testi'])){ echo '<p class="widget_warning" style="color: #fff;">'.__('Please Click the "+ Add New" button to create new testimonials','optimizer').'</p>';}
  96. /*START TWITTER TESTIMONIALS*/
  97. if(!empty($twitter_testi_on)){
  98. echo '<div class="home_tweets_wrap">';
  99.  
  100. if(!empty($twitter_testi_on)){
  101. $i = 0;
  102. foreach($twitter_testi as $tweet){
  103. echo '<div class="home_tweet xxx">'.wp_oembed_get($tweet['url']).'</div>';
  104. }
  105. }
  106.  
  107. echo '</div>';
  108. }elseif (!empty ($custom_testi)){
  109. /*START CUSTOM TESTIMONIALS*/
  110. if( $testi_layout == 'col1') { $looper = 'data-looper="go" class="looper slide" data-interval="'.$testi_pausetime.'"'; }else{ $looper = ''; }
  111. echo '<div id="testi-looper_'.$this->id.'" '.$looper.' ><ul class="looper-inner">';
  112.  
  113. foreach ((array)$custom_testi as $testimony){
  114.  
  115. echo '<li class="item">
  116. <div class="testi_content">'.do_shortcode( $testimony['testimonial']).'</div>
  117. <div class="testi_author">';
  118. if (!empty ($testimony['image'])) {
  119. echo '<img alt="'.$testimony['title'].'" class="testi_avatar" src="'.$testimony['image'].'" />' ;
  120. }
  121. if(!empty($testimony['url'])){ $href = 'href="'.esc_url($testimony['url']).'"'; }else{ $href = ''; }
  122. echo '<a '.$href.'>'.$testimony['title'].'</a>';
  123. if(!empty($testimony['occupation'])){ echo '<span class="testi_occu">'.$testimony['occupation'].'</span>'; }
  124. echo '</div>
  125. </li>';
  126.  
  127. }
  128.  
  129. echo '</ul>';
  130.  
  131.  
  132. //LOOPER NAVIGATION
  133. if( $testi_layout == 'col1') {
  134. if(!empty($content_bgimg)){$hasbg = 'has_bg';}else{ $hasbg = 'has_bg'; }
  135.  
  136. echo '<nav><ul class="looper-nav '.$hasbg.'">';
  137. $i = 0;
  138. foreach ((array)$custom_testi as $testimony){
  139. echo '<li><a href="#testi-looper_'.$this->id.'" data-looper="to" data-args="'.($i +1).'"><span></span></a></li>';
  140. $i++;
  141. }
  142. echo '</ul></nav>';
  143. }
  144.  
  145.  
  146. echo '</div>'; //END of testi-looper div
  147.  
  148. }
  149.  
  150. echo '</div></div>';
  151.  
  152.  
  153. //Stylesheet-loaded in Customizer Only.
  154. if(is_customize_preview()){
  155. $id= $this->id;
  156.  
  157. echo "<script>jQuery(window).ready(function() { jQuery('#".$id." .testi_col1 .looper-inner li:eq(0)').addClass('active'); });</script>";
  158.  
  159. $content_bg = 'background-color:#64c2ff;';
  160. $title_color = '#ffffff;';
  161. $content_color = '#ffffff;';
  162. $content_bgimg = '';
  163. $marginTop =''; $marginBottom =''; $marginLeft =''; $marginRight ='';$calcWidth ='';
  164. $paddingTop =''; $paddingBottom =''; $paddingLeft =''; $paddingRight =''; $boxSizing='';
  165.  
  166. //Margin
  167. if ( ! empty( $instance['margin'] ) ) {
  168. if(!empty($instance['margin'][0])){ $marginTop ='margin-top:'.$instance['margin'][0].';';}
  169. if(!empty($instance['margin'][1])){ $marginBottom ='margin-bottom:'.$instance['margin'][1].';';}
  170. if(!empty($instance['margin'][2])){ $marginLeft ='margin-left:'.$instance['margin'][2].';';}
  171. if(!empty($instance['margin'][3])){ $marginRight ='margin-right:'.$instance['margin'][3].';';}
  172.  
  173. //Width
  174. $thewidth ='100';
  175. $leftrightmargin ='0px';
  176.  
  177. if ( ! empty( $instance['width']) ) { if($instance['width'] == 2){ $thewidth = '50';} if($instance['width'] == 3){ $thewidth = '33.33';} if($instance['width'] == 4){ $thewidth = '66.67';} }
  178. if ( ! empty( $instance['width']) && !empty($instance['margin'][2] ) ) { $leftrightmargin = $instance['margin'][2]; }
  179. if ( ! empty( $instance['width']) && !empty($instance['margin'][3] ) ) { $leftrightmargin = $instance['margin'][3]; }
  180. if ( ! empty( $instance['width']) ) {
  181. if(!empty($instance['margin'][2]) && !empty($instance['margin'][3]) ){
  182. $leftrightmargin = '('.$instance['margin'][2].' + '.$instance['margin'][3].')';
  183. }
  184. }
  185. $calcWidth ='width: calc('.$thewidth.'% - '.$leftrightmargin.')!important;';
  186.  
  187. }
  188.  
  189. //Padding
  190. if ( ! empty( $instance['padding'] ) ) {
  191. if(!empty($instance['padding'][0])){ $paddingTop ='padding-top:'.$instance['padding'][0].';';}
  192. if(!empty($instance['padding'][1])){ $paddingBottom ='padding-bottom:'.$instance['padding'][1].';';}
  193. if(!empty($instance['padding'][2])){ $paddingLeft ='padding-left:'.$instance['padding'][2].';';}
  194. if(!empty($instance['padding'][3])){ $paddingRight ='padding-right:'.$instance['padding'][3].';';}
  195.  
  196. $boxSizing='box-sizing:border-box;';
  197.  
  198. }
  199.  
  200.  
  201. if ( ! empty( $instance['content_bg'] ) ) { $content_bg = 'background-color: ' . $instance['content_bg'] . '; ';}
  202. if ( ! empty( $instance['title_color'] ) ) {$title_color = '' . $instance['title_color'] . '; ';}
  203. if ( ! empty( $instance['content_color'] ) ) {$content_color = '' . $instance['content_color'] . '; ';}
  204. if ( ! empty( $instance['content_bgimg'] ) ) {$content_bgimg = 'background-image: url(' . $instance['content_bgimg'] . '); ';}
  205.  
  206. echo '<style>#'.$id.'{ ' . $content_bg . $content_bgimg. '}#'.$id.' .home_title, #'.$id.' .home_subtitle, #'.$id.' span.div_middle{ color:' . $content_color . '} #'.$id.' .testi_content, #'.$id.' .testi_author a, #'.$id.' .testi_occu{color:'.$title_color.'opacity:0.7;}#'.$id.' span.div_left, #'.$id.' span.div_right{background-color:' . $content_color . '} @media screen and (min-width: 480px){#'.$id.' {'.$marginTop.$marginBottom.$marginLeft.$marginRight.$calcWidth. $paddingTop.$paddingBottom.$paddingLeft.$paddingRight. $boxSizing.'} }</style>';
  207.  
  208. }
  209.  
  210.  
  211. /* After widget (defined by themes). */
  212. echo $after_widget;
  213.  
  214. }
  215.  
  216.  
  217.  
  218.  
  219. /* ---------------------------- */
  220. /* ------- Update Widget -------- */
  221. /* ---------------------------- */
  222.  
  223. function update( $new_instance, $old_instance ) {
  224. $instance = $old_instance;
  225.  
  226. /* Strip tags for title and name to remove HTML (important for text inputs). */
  227. $instance['title'] = strip_tags( $new_instance['title'] );
  228.  
  229. /* No need to strip tags */
  230. $instance['subtitle'] = strip_tags($new_instance['subtitle']);
  231. $instance['twitter_testi_on'] = strip_tags($new_instance['twitter_testi_on']);
  232. $instance['divider'] = strip_tags($new_instance['divider']);
  233. $instance['testi_layout'] = strip_tags($new_instance['testi_layout']);
  234. $instance['content_color'] = optimizer_sanitize_hex($new_instance['content_color']);
  235. $instance['title_color'] = optimizer_sanitize_hex($new_instance['title_color']);
  236. $instance['content_bg'] = optimizer_sanitize_hex($new_instance['content_bg']);
  237. $instance['content_bgimg'] = esc_url_raw($new_instance['content_bgimg']);
  238. $instance['testi_pausetime'] = strip_tags($new_instance['testi_pausetime']);
  239.  
  240.  
  241. $instance['custom_testi'] = array();
  242. $instance['twitter_testi'] = array();
  243.  
  244.  
  245. if ( isset( $new_instance['custom_testi'] ) )
  246. {
  247. foreach ( $new_instance['custom_testi'] as $testi )
  248. {
  249. if ( '' !== trim( $testi['title'] ) )
  250. $instance['custom_testi'][] = $testi;
  251. }
  252. }
  253.  
  254. if ( isset( $new_instance['twitter_testi'] ) )
  255. {
  256. foreach ( $new_instance['twitter_testi'] as $twitter )
  257. {
  258. if ( '' !== esc_url_raw( $twitter['url'] ) )
  259. $instance['twitter_testi'][] = $twitter;
  260. }
  261. }
  262.  
  263. return $instance;
  264. }
  265.  
  266. /* ---------------------------- */
  267. /* ------- Widget Settings ------- */
  268. /* ---------------------------- */
  269.  
  270. /**
  271. * Displays the widget settings controls on the widget panel.
  272. * Make use of the get_field_id() and get_field_name() function
  273. * when creating your form elements. This handles the confusing stuff.
  274. */
  275.  
  276. function form( $instance ) {
  277.  
  278. /* Set up some default widget settings. */
  279. $defaults = array(
  280. 'title' => __('What are people saying?','optimizer'),
  281. 'subtitle' => __('Real words from real customers!','optimizer'),
  282. 'custom_testi' => '',
  283. 'twitter_testi_on' => '',
  284. 'twitter_testi' => '',
  285. 'testi_layout' => 'col1',
  286. 'divider' => 'fa-stop',
  287. 'content_color' => '#ffffff',
  288. 'title_color' => '#ffffff',
  289. 'content_bg' => '#64c2ff',
  290. 'content_bgimg' => '',
  291. 'testi_pausetime' => '8000',
  292. );
  293. $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  294.  
  295.  
  296. <!-- Testimonial Section TITLE Field -->
  297. <p>
  298. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'optimizer') ?></label>
  299. <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo htmlspecialchars($instance['title'], ENT_QUOTES, "UTF-8"); ?>" type="text" />
  300. </p>
  301.  
  302. <!-- Testimonial Section Subtitle Field -->
  303. <p>
  304. <label for="<?php echo $this->get_field_id( 'subtitle' ); ?>"><?php _e('Subtitle:', 'optimizer') ?></label>
  305. <input class="widefat" id="<?php echo $this->get_field_id( 'subtitle' ); ?>" name="<?php echo $this->get_field_name( 'subtitle' ); ?>" value="<?php echo htmlspecialchars($instance['subtitle'], ENT_QUOTES, "UTF-8"); ?>" type="text" />
  306. </p>
  307.  
  308.  
  309.  
  310. <!-- TESTIMONIAL TITLE DIVIDER Field -->
  311. <p>
  312. <label for="<?php echo $this->get_field_id( 'divider' ); ?>"><?php _e('Title Divider:', 'optimizer') ?></label>
  313. <select id="<?php echo $this->get_field_id( 'divider' ); ?>" name="<?php echo $this->get_field_name( 'divider' ); ?>" class="widefat">
  314. <option value="underline" <?php if ( 'underline' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Underline', 'optimizer') ?></option>
  315. <option value="border-center" <?php if ( 'border-center' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Bordered (Center)', 'optimizer') ?></option>
  316. <option value="border-left" <?php if ( 'border-left' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Bordered (Left)', 'optimizer') ?></option>
  317. <option value="border-right" <?php if ( 'border-right' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Bordered (Right)', 'optimizer') ?></option>
  318. <option value="fa-stop" <?php if ( 'fa-stop' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Rhombus', 'optimizer') ?></option>
  319. <option value="fa-star" <?php if ( 'fa-star' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Star', 'optimizer') ?></option>
  320. <option value="fa-times" <?php if ( 'fa-times' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Cross', 'optimizer') ?></option>
  321. <option value="fa-bolt" <?php if ( 'fa-bolt' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Bolt', 'optimizer') ?></option>
  322. <option value="fa-asterisk" <?php if ( 'fa-asterisk' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Asterisk', 'optimizer') ?></option>
  323. <option value="fa-chevron-down" <?php if ( 'fa-chevron-down' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Chevron', 'optimizer') ?></option>
  324. <option value="fa-heart" <?php if ( 'fa-heart' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Heart', 'optimizer') ?></option>
  325. <option value="fa-plus" <?php if ( 'fa-plus' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Plus', 'optimizer') ?></option>
  326. <option value="fa-bookmark" <?php if ( 'fa-bookmark' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Bookmark', 'optimizer') ?></option>
  327. <option value="fa-circle-o" <?php if ( 'fa-circle-o' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Circle', 'optimizer') ?></option>
  328. <option value="fa-th-large" <?php if ( 'fa-th-large' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Blocks', 'optimizer') ?></option>
  329. <option value="fa-minus" <?php if ( 'fa-minus' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Sides', 'optimizer') ?></option>
  330. <option value="fa-cog" <?php if ( 'fa-cog' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Cog', 'optimizer') ?></option>
  331. <option value="fa-reorder" <?php if ( 'fa-reorder' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Blinds', 'optimizer') ?></option>
  332. <option value="fa-diamond" <?php if ( 'fa-diamond' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Diamond', 'optimizer') ?></option>
  333. <option value="fa-gg" <?php if ( 'fa-gg' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Tetris', 'optimizer') ?></option>
  334. <option value="fa-houzz" <?php if ( 'fa-houzz' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Digital', 'optimizer') ?></option>
  335. <option value="fa-rocket" <?php if ( 'fa-rocket' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Rocket', 'optimizer') ?></option>
  336. <option value="no_divider" <?php if ( 'no_divider' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Hide Divider', 'optimizer') ?></option>
  337. </select>
  338. </p>
  339.  
  340.  
  341.  
  342. <!-- TESTIMONIAL Column Field -->
  343. <p>
  344. <label for="<?php echo $this->get_field_id( 'testi_layout' ); ?>"><?php _e('Testimonials Layout:', 'optimizer') ?></label>
  345. <select id="<?php echo $this->get_field_id( 'testi_layout' ); ?>" name="<?php echo $this->get_field_name( 'testi_layout' ); ?>" class="widefat">
  346. <option value="col1" <?php if ( 'col1' == $instance['testi_layout'] ) echo 'selected="selected"'; ?>><?php _e('1 Column', 'optimizer') ?></option>
  347. <option value="col2" <?php if ( 'col2' == $instance['testi_layout'] ) echo 'selected="selected"'; ?>><?php _e('2 Column', 'optimizer') ?></option>
  348. <option value="col3" <?php if ( 'col3' == $instance['testi_layout'] ) echo 'selected="selected"'; ?>><?php _e('3 Column', 'optimizer') ?></option>
  349. </select>
  350. </p>
  351.  
  352.  
  353. <!-- ----------------Testimonial Field------------------------ -->
  354. <div class="widget_repeater" data-widget-id="<?php echo $this->get_field_id( 'custom_testi' ); ?>" data-widget-name="<?php echo $this->get_field_name( 'custom_testi' ); ?>">
  355. <?php
  356. $customtesti = isset( $instance['custom_testi'] ) ? $instance['custom_testi'] : array();
  357. $customtesti_num = count($customtesti);
  358. $customtesti[$customtesti_num+1] = '';
  359. $customtesti_html = array();
  360. $customtesti_counter = 0;
  361.  
  362. foreach ( $customtesti as $testi )
  363. {
  364. if ( isset($testi['title']) )
  365. {
  366. $customtesti_html[] = sprintf(
  367. '<div class="widget_input_wrap">
  368. <span id="%9$s%2$s" class="repeat_handle" onclick="repeatOpen(this.id)">%3$s</span>
  369. <input type="text" name="%1$s[%2$s][title]" value="%3$s" class="widefat" placeholder="%6$s">
  370. <input type="text" name="%1$s[%2$s][url]" value="%4$s" class="widefat" placeholder="%7$s">
  371. <input type="text" name="%1$s[%2$s][occupation]" value="%14$s" class="widefat" placeholder="%15$s">
  372. <textarea name="%1$s[%2$s][testimonial]" class="widefat">%13$s</textarea>
  373. <div class="media-picker-wrap">
  374. %12$s
  375. <input id="%10$s-%2$s" type="hidden" name="%1$s[%2$s][image]" value="%5$s" class="widefat media-picker">
  376. <a id="%11$s-%2$s" onclick="mediaPicker(this.id)" class="media-picker-button button">%8$s</a>
  377. </div>
  378. <span class="remove-field button button-primary">Remove</span>
  379. </div>',
  380. $this->get_field_name( 'custom_testi' ),
  381. $customtesti_counter,
  382. esc_attr( $testi['title'] ),
  383. esc_url( $testi['url'] ),
  384. esc_url( $testi['image'] ),
  385. __('Client\'s Name (Required)','optimizer'),
  386. __('Client\'s Website','optimizer'),
  387. __('Select Image', 'optimizer'),
  388. $this->get_field_id('custom_add_field').'-repeat',
  389. $this->get_field_id('custom_testi').'',
  390. $this->get_field_id('custom_testi').'-mpick',
  391. !empty($testi['image']) ? '<img class="media-picker-preview" src="'.esc_url($testi['image']).'" /><i class="fa fa-times media-picker-remove"></i>': '',
  392. wp_kses_post( $testi['testimonial']),
  393. esc_attr( $testi['occupation'] ),
  394. __('Client\'s Occupation','optimizer')
  395. );
  396. }
  397.  
  398. $customtesti_counter += 1;
  399. }
  400.  
  401. echo '<h4>'.__('Custom Testimonials','optimizer').'</h4>' . join( $customtesti_html );
  402.  
  403. ?>
  404.  
  405. <script type="text/javascript">
  406. var fieldnum = <?php echo json_encode( $customtesti_counter-1 ) ?>;
  407. var count = fieldnum;
  408. function customTesticlickFunction(buttonid){
  409. var fieldname = jQuery('#'+buttonid).data('widget-fieldname');
  410. var fieldid = jQuery('#'+buttonid).data('widget-fieldid');
  411.  
  412. jQuery('#'+buttonid).prev().append("<div class='widget_input_wrap'><span id='"+buttonid+"-repeat"+(count+1)+"' class='repeat_handle' onclick='repeatOpen(this.id)'></span><input type='text' name='"+fieldname+"["+(count+1)+"][title]' value='<?php _e( 'Clients Name (Required)', 'optimizer' ); ?>' class='widefat' placeholder='<?php _e( 'Clients Name (Required)', 'optimizer' ); ?>'><input type='text' name='"+fieldname+"["+(count+1)+"][url]' value='http://google.com' class='widefat' placeholder='<?php _e( 'Clients Website', 'optimizer' ); ?>'><input type='text' name='"+fieldname+"["+(count+1)+"][occupation]' value='' class='widefat' placeholder='<?php _e( 'Clients Occupation', 'optimizer' ); ?>'><textarea name='"+fieldname+"["+(count+1)+"][testimonial] class='widefat sourc"+(count+1)+"' placeholder='<?php _e( 'Clients Testimony', 'optimizer' ); ?>'></textarea><div class='media-picker-wrap'><input type='hidden' name='"+fieldname+"["+(count+1)+"][image]' value='' class='widefat media-picker' id='"+fieldid+"-"+(count+1)+"'><a id='"+fieldid+"-mpick"+(count+1)+"' class='media-picker-button button' onclick='mediaPicker(this.id)'><?php _e('Select Image', 'optimizer') ?></a></div><span class='remove-field button button-primary'>Remove</span></div>");
  413. count++;
  414.  
  415. }
  416.  
  417. </script>
  418.  
  419. <span id="<?php echo $this->get_field_id( 'custom-field_clone' );?>" class="repeat_clone_field" data-empty-content="<?php _e('No Custom Testimonials Added', 'optimizer') ?>"></span>
  420.  
  421. <?php echo '<input onclick="customTesticlickFunction(this.id)" class="button button-primary" type="button" value="' . __( '+ Add New', 'optimizer' ) . '" id="'.$this->get_field_id('custom_add_field').'" data-widget-fieldname="'.$this->get_field_name('custom_testi').'" data-widget-fieldid="'.$this->get_field_id('custom_testi').'" />';?>
  422. </div>
  423.  
  424.  
  425.  
  426. <!-- POSTS Preview Button Field -->
  427. <p>
  428. <label for="<?php echo $this->get_field_id( 'twitter_testi_on' ); ?>"><?php _e('Display Twitter Testimonial', 'optimizer') ?></label>
  429. <input class="widefat" id="<?php echo $this->get_field_id( 'twitter_testi_on' ); ?>" name="<?php echo $this->get_field_name( 'twitter_testi_on' ); ?>" value="1" type="checkbox" <?php if ( '1' == $instance['twitter_testi_on'] ) echo 'checked'; ?> />
  430. </p>
  431.  
  432. <!-- ----------------Twitter Testimonial Field------------------------ -->
  433.  
  434. <div class="widget_repeater" data-widget-id="<?php echo $this->get_field_id( 'twitter_testi' ); ?>" data-widget-name="<?php echo $this->get_field_name( 'twitter_testi' ); ?>">
  435. <?php
  436. $twittertesti = isset( $instance['twitter_testi'] ) ? $instance['twitter_testi'] : array();
  437. $twittertesti_num = count($twittertesti);
  438. $twittertesti[$twittertesti_num+1] = '';
  439. $twittertesti_html = array();
  440. $twittertesti_counter = 0;
  441.  
  442. foreach ( $twittertesti as $tweet )
  443. {
  444. if ( isset($tweet['url']) )
  445. {
  446. $twittertesti_html[] = sprintf(
  447. '<div class="widget_multi-text">
  448. <input type="text" name="%1$s[%2$s][url]" value="%3$s" class="widefat" placeholder="%4$s">
  449. <span class="remove-field"><i class="fa fa-times"></i></span>
  450. </div>',
  451. $this->get_field_name( 'twitter_testi' ),
  452. $twittertesti_counter,
  453. esc_attr( $tweet['url'] ),
  454. __('Twitter Status link','optimizer'),
  455. $this->get_field_id('twitter_add_field').'-repeat'
  456. );
  457. }
  458.  
  459. $twittertesti_counter += 1;
  460. }
  461.  
  462. echo '<h4>'.__('Twitter Testimonials','optimizer').'</h4>' . join( $twittertesti_html );
  463.  
  464. ?>
  465.  
  466. <script type="text/javascript">
  467. var twtcount = <?php echo json_encode( $twittertesti_counter-1 ) ?>;
  468. function twitterTesticlickFunction(buttonid){
  469. var fieldname = jQuery('#'+buttonid).data('widget-fieldname');
  470. var fieldid = jQuery('#'+buttonid).data('widget-fieldid');
  471.  
  472. jQuery('#'+buttonid).prev().append("<div class='widget_multi-text'><input type='text' name='"+fieldname+"["+(twtcount+1)+"][url]' value='<?php _e( 'Twitter Status link', 'optimizer' ); ?>' class='widefat' placeholder='<?php _e( 'Twitter Status link', 'optimizer' ); ?>'><span class='remove-field'><i class='fa fa-times'></i></span></div>");
  473. twtcount++;
  474.  
  475. }
  476.  
  477.  
  478.  
  479. </script>
  480.  
  481. <span id="<?php echo $this->get_field_id( 'twitter-field_clone' );?>" class="repeat_clone_field" data-empty-content="<?php _e('No Twitter Testimonials Added','optimizer') ?>"></span>
  482.  
  483. <?php echo '<input onclick="twitterTesticlickFunction(this.id)" class="button button-primary" type="button" value="' . __( '+ Add New', 'optimizer' ) . '" id="'.$this->get_field_id('twitter_add_field').'" data-widget-fieldname="'.$this->get_field_name('twitter_testi').'" data-widget-fieldid="'.$this->get_field_id('twitter_testi').'" />';?>
  484. </div>
  485.  
  486.  
  487. <!-- Testimonial Section Subtitle Field -->
  488. <p>
  489. <label for="<?php echo $this->get_field_id( 'testi_pausetime' ); ?>"><?php _e('Testimonial Pausetime:', 'optimizer') ?></label>
  490. <input class="widefat" id="<?php echo $this->get_field_id( 'testi_pausetime' ); ?>" name="<?php echo $this->get_field_name( 'testi_pausetime' ); ?>" value="<?php echo htmlspecialchars($instance['testi_pausetime'], ENT_QUOTES, "UTF-8"); ?>" type="text" />
  491. </p>
  492.  
  493. <!-- Testimonial Title Color Field -->
  494. <p>
  495. <label for="<?php echo $this->get_field_id( 'content_color' ); ?>"><?php _e('Title Color', 'optimizer') ?></label>
  496. <input class="widefat color-picker" id="<?php echo $this->get_field_id( 'content_color' ); ?>" name="<?php echo $this->get_field_name( 'content_color' ); ?>" value="<?php echo $instance['content_color']; ?>" type="text" />
  497. </p>
  498.  
  499.  
  500.  
  501. <!-- Testimonial Content Color Field -->
  502. <p>
  503. <label for="<?php echo $this->get_field_id( 'title_color' ); ?>"><?php _e('Text Color', 'optimizer') ?></label>
  504. <input class="widefat color-picker" id="<?php echo $this->get_field_id( 'title_color' ); ?>" name="<?php echo $this->get_field_name( 'title_color' ); ?>" value="<?php echo $instance['title_color']; ?>" type="text" />
  505. </p>
  506.  
  507.  
  508.  
  509. <!-- Testimonial Background Color Field -->
  510. <p>
  511. <label for="<?php echo $this->get_field_id( 'content_bg' ); ?>"><?php _e('Background Color', 'optimizer') ?></label>
  512. <input class="widefat color-picker" id="<?php echo $this->get_field_id( 'content_bg' ); ?>" name="<?php echo $this->get_field_name( 'content_bg' ); ?>" value="<?php echo $instance['content_bg']; ?>" type="text" />
  513. </p>
  514.  
  515.  
  516.  
  517. <!-- Testimonial Background IMAGE FIELD -->
  518. <div class="widget_input_wrap">
  519. <label for="<?php echo $this->get_field_id( 'content_bgimg' ); ?>"><?php _e('Background Image', 'optimizer') ?></label>
  520. <div class="media-picker-wrap">
  521. <?php if(!empty($instance['content_bgimg'])) { ?>
  522. <img style="max-width:100%; height:auto;" class="media-picker-preview" src="<?php echo esc_url($instance['content_bgimg']); ?>" />
  523. <i class="fa fa-times media-picker-remove"></i>
  524. <?php } ?>
  525. <input class="widefat media-picker" id="<?php echo $this->get_field_id( 'content_bgimg' ); ?>" name="<?php echo $this->get_field_name( 'content_bgimg' ); ?>" value="<?php echo esc_url($instance['content_bgimg']); ?>" type="hidden" />
  526. <a class="media-picker-button button" onclick="mediaPicker(this.id)" id="<?php echo $this->get_field_id( 'content_bgimg' ).'mpick'; ?>"><?php _e('Select Image', 'optimizer') ?></a>
  527. </div>
  528. </div>
  529.  
  530. <?php
  531. }
  532. //ENQUEUE CSS
  533. function front_testi_enqueue_css() {
  534. $settings = $this->get_settings();
  535.  
  536. if ( empty( $settings ) ) {
  537. return;
  538. }
  539.  
  540. foreach ( $settings as $instance_id => $instance ) {
  541. $id = $this->id_base . '-' . $instance_id;
  542. if(!is_customize_preview()){
  543. if ( ! is_active_widget( false, $id, $this->id_base ) ) {
  544. continue;
  545. }
  546.  
  547. $content_bg = 'background-color:#64c2ff;';
  548. $title_color = '#ffffff;';
  549. $content_color = '#ffffff;';
  550. $content_bgimg = '';
  551. $marginTop =''; $marginBottom =''; $marginLeft =''; $marginRight ='';$calcWidth ='';
  552. $paddingTop =''; $paddingBottom =''; $paddingLeft =''; $paddingRight =''; $boxSizing='';
  553.  
  554. //Margin
  555. if ( ! empty( $instance['margin'] ) ) {
  556. if(!empty($instance['margin'][0])){ $marginTop ='margin-top:'.$instance['margin'][0].';';}
  557. if(!empty($instance['margin'][1])){ $marginBottom ='margin-bottom:'.$instance['margin'][1].';';}
  558. if(!empty($instance['margin'][2])){ $marginLeft ='margin-left:'.$instance['margin'][2].';';}
  559. if(!empty($instance['margin'][3])){ $marginRight ='margin-right:'.$instance['margin'][3].';';}
  560.  
  561. //Width
  562. $thewidth ='100';
  563. $leftrightmargin ='0px';
  564.  
  565. if ( ! empty( $instance['width']) ) { if($instance['width'] == 2){ $thewidth = '50';} if($instance['width'] == 3){ $thewidth = '33.33';} if($instance['width'] == 4){ $thewidth = '66.67';} }
  566. if ( ! empty( $instance['width']) && !empty($instance['margin'][2] ) ) { $leftrightmargin = $instance['margin'][2]; }
  567. if ( ! empty( $instance['width']) && !empty($instance['margin'][3] ) ) { $leftrightmargin = $instance['margin'][3]; }
  568. if ( ! empty( $instance['width']) ) {
  569. if(!empty($instance['margin'][2]) && !empty($instance['margin'][3]) ){
  570. $leftrightmargin = '('.$instance['margin'][2].' + '.$instance['margin'][3].')';
  571. }
  572. }
  573. $calcWidth ='width: calc('.$thewidth.'% - '.$leftrightmargin.')!important;';
  574.  
  575. }
  576.  
  577. //Padding
  578. if ( ! empty( $instance['padding'] ) ) {
  579. if(!empty($instance['padding'][0])){ $paddingTop ='padding-top:'.$instance['padding'][0].';';}
  580. if(!empty($instance['padding'][1])){ $paddingBottom ='padding-bottom:'.$instance['padding'][1].';';}
  581. if(!empty($instance['padding'][2])){ $paddingLeft ='padding-left:'.$instance['padding'][2].';';}
  582. if(!empty($instance['padding'][3])){ $paddingRight ='padding-right:'.$instance['padding'][3].';';}
  583.  
  584. $boxSizing='box-sizing:border-box;';
  585.  
  586. }
  587.  
  588. if ( ! empty( $instance['content_bg'] ) ) {
  589. $content_bg = 'background-color: ' . $instance['content_bg'] . '; ';
  590. }
  591. if ( ! empty( $instance['title_color'] ) ) {
  592. $title_color = '' . $instance['title_color'] . '; ';
  593. }
  594.  
  595. if ( ! empty( $instance['content_color'] ) ) {
  596. $content_color = '' . $instance['content_color'] . '; ';
  597. }
  598.  
  599. if ( ! empty( $instance['content_bgimg'] ) ) {
  600. $content_bgimg = 'background-image: url(' . $instance['content_bgimg'] . '); ';
  601. }
  602.  
  603. $widget_style = '#'.$id.'{ ' . $content_bg . $content_bgimg. '}#'.$id.' .home_title, #'.$id.' .home_subtitle, #'.$id.' span.div_middle{ color:' . $content_color . '} #'.$id.' .testi_content, #'.$id.' .testi_author a, #'.$id.' .testi_occu{color:'.$title_color.'opacity:0.7;}#'.$id.' span.div_left, #'.$id.' span.div_right{background-color:' . $content_color . '} @media screen and (min-width: 480px){#'.$id.' {'.$marginTop.$marginBottom.$marginLeft.$marginRight.$calcWidth. $paddingTop.$paddingBottom.$paddingLeft.$paddingRight. $boxSizing.'} }';
  604. wp_add_inline_style( 'optimizer-style', $widget_style );
  605.  
  606. }
  607. }
  608. }
  609. }
  610. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement