Advertisement
towfiqi

Untitled

Mar 15th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.16 KB | None | 0 0
  1. <?php
  2. /*
  3. *FRONTPAGE - MAP WIDGET
  4. */
  5. add_action( 'widgets_init', 'optimizer_register_front_carousel' );
  6.  
  7. /*
  8. * Register widget.
  9. */
  10. function optimizer_register_front_carousel() {
  11. register_widget( 'optimizer_front_carousel' );
  12. }
  13.  
  14.  
  15. /*
  16. * Widget class.
  17. */
  18. class optimizer_front_Carousel extends WP_Widget {
  19.  
  20. /* ---------------------------- */
  21. /* -------- Widget setup -------- */
  22. /* ---------------------------- */
  23.  
  24.  
  25. function __construct() {
  26. if(is_customize_preview()){$widgetname = __( 'Dynamic Content', 'optimizer' ); }else{ $widgetname = __( '&diams; Dynamic Content Widget', 'optimizer' ); }
  27.  
  28. parent::__construct( 'optimizer_front_carousel', $widgetname, array(
  29. 'classname' => 'optimizer_front_carousel home_testi',
  30. 'description' => __( 'Optimizer Dynamic Content widget', 'optimizer' ),
  31. 'customize_selective_refresh' => true,
  32. ) );
  33. $this->alt_option_name = 'optimizer_front_carousel';
  34. add_action('wp_enqueue_scripts', array(&$this, 'front_carousel_enqueue_css'));
  35. }
  36.  
  37. /* ---------------------------- */
  38. /* ------- Display Widget -------- */
  39. /* ---------------------------- */
  40.  
  41. function widget( $args, $instance ) {
  42.  
  43.  
  44. extract( $args );
  45. /* Our variables from the widget settings. */
  46. $title = isset( $instance['title'] ) ? $instance['title'] : __('What are people saying?', 'optimizer');
  47. $subtitle = isset( $instance['subtitle'] ) ? $instance['subtitle'] : __('Testimonial Subtitle', 'optimizer');
  48. $type = isset( $instance['type'] ) ? $instance['type'] : 'carousel';
  49. $style = isset( $instance['style'] ) ? $instance['style'] : 'style1';
  50. $carousel = isset( $instance['carousel'] ) ? $instance['carousel'] : array();
  51. $img_pos = isset( $instance['img_pos'] ) ? $instance['img_pos'] : 'top';
  52. $divider = isset( $instance['divider'] ) ? apply_filters('widget_title', $instance['divider']) : 'fa-stop';
  53. $title_color = isset( $instance['title_color'] ) ? $instance['title_color'] : '';
  54. $content_bg = isset( $instance['content_bg'] ) ? $instance['content_bg'] : '';
  55. $content_bgimg = isset( $instance['content_bgimg'] ) ? $instance['content_bgimg'] : '';
  56. $pausetime = isset( $instance['pausetime'] ) ? $instance['pausetime'] : '8000';
  57.  
  58. /* Before widget (defined by themes). */
  59. echo $before_widget;
  60.  
  61. //Sitegorigin Builder FIX
  62. echo '<span class="so_widget_id" data-panel-id="'.$this->id.'"></span>';
  63. if(is_customize_preview()) echo '<span class="widgetname">'.$this->name.'</span>';
  64.  
  65. ?>
  66. <?php
  67.  
  68. //WIDGET EDIT BUTTON(Customizer)
  69. if(is_customize_preview()){ echo '<a class="edit_widget" title="'.__('Edit ','optimizer').$this->id.'"><i class="fa fa-pencil"></i></a>'; }
  70.  
  71. if ( !empty($content_bgimg) ){ $hasbgimg ='hasbgimg'; }else{ $hasbgimg =''; }
  72.  
  73. echo '<div class="home_carousel_inner carousel_'.$img_pos.' carousel_'.$style.' '.$hasbgimg.' " ><div class="center">';
  74. echo '<div class="homeposts_title carousel_title title_'.str_replace('fa-','dvd_',$divider).'">';
  75. if ( $title || is_customize_preview() ){
  76. echo '<h2 class="home_title"><span>'.do_shortcode($title).'</span></h2>';
  77. }
  78. if ( $subtitle || is_customize_preview() ){
  79. echo '<div class="home_subtitle"><span>'.do_shortcode($subtitle).'</span></div>';
  80. }
  81. if ( $divider ){
  82. if( $divider !== 'no_divider'){
  83. if($divider == 'underline'){ $underline= 'title_underline';}else{$underline='';}
  84. 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>';
  85. }
  86. }
  87. echo '</div>';
  88.  
  89. if(!isset($instance['carousel'])){ echo '<p class="widget_warning" style="color: #fff;">'.__('Please Click the "+ Add New" button to create new Carousel','optimizer').'</p>';}
  90.  
  91. if(!empty($carousel) && $type == 'carousel' ){
  92. /*START CUSTOM Carosel*/
  93. if( $type == 'carousel') { $looper = 'data-looper="go" class="looper slide" data-interval="'.$pausetime.'"'; }else{ $looper = ''; }
  94. echo '<div id="carousel-looper_'.$this->id.'" '.$looper.' ><ul class="looper-inner">';
  95.  
  96. foreach ((array)$carousel as $cars){
  97.  
  98. echo '<li class="item">
  99. <div class="carousel_image">';
  100. if (!empty ($cars['image'])) {
  101. echo '<img alt="'.$cars['title'].'" class="carousel_img" src="'.$cars['image'].'" />' ;
  102. }
  103. echo '</div>
  104. <div class="carousel_content">'.apply_filters( 'wp_editor_widget_content', do_shortcode($cars['content']) ).'</div>
  105.  
  106. </li>';
  107.  
  108. }
  109.  
  110. echo '</ul>';
  111.  
  112.  
  113. //LOOPER NAVIGATION - TYPE 1
  114. if( $style == 'style1') {
  115. echo '<nav>
  116. <a class="looper-control" data-looper="prev" href="#carousel-looper_'.$this->id.'">
  117. <i class="fa fa-angle-left"></i>
  118. </a>
  119. <a class="looper-control right" data-looper="next" href="#carousel-looper_'.$this->id.'">
  120. <i class="fa fa-angle-right"></i>
  121. </a>
  122. </nav>';
  123. }
  124.  
  125. //LOOPER NAVIGATION - TYPE 2
  126. if( $style == 'style2' || $style == 'style3') {
  127.  
  128. echo '<nav><ul class="looper-nav">';
  129. $i = 0;
  130. foreach ((array)$carousel as $cars){
  131. echo '<li><a href="#carousel-looper_'.$this->id.'" data-looper="to" data-args="'.($i +1).'"><span></span></a></li>';
  132. $i++;
  133. }
  134. echo '</ul></nav>';
  135. }
  136.  
  137. echo '</div>'; //END of testi-looper div
  138.  
  139. } //CAROUSEL END
  140.  
  141.  
  142. //TABS START
  143. if(!empty($carousel) && $type == 'tabs' ){
  144. if($style == 'style1'){ $style ='minimal'; } if($style == 'style2'){ $style ='circular'; } if($style == 'style3'){ $style ='capsule'; }
  145. echo '<div class="tabs-container lts_tabs tabs_'.$style.'"">
  146.  
  147. <ul class="tabs ">';
  148. foreach ((array)$carousel as $cars){
  149. echo '<li class="tabli lts_tabtitle"><a href="#" class="tabtrigger">'.do_shortcode($cars['title']).'</a></li>';
  150. }
  151. echo '</ul>';
  152.  
  153. echo '<div class="lts_tab">';
  154. foreach ((array)$carousel as $cars){
  155. echo '<div class="lts_tab_child">
  156. <div class="tab_wimg">';
  157. if (!empty ($cars['image'])) {
  158. echo '<img alt="'.$cars['title'].'" class="tabs_img" src="'.$cars['image'].'" />' ;
  159. }
  160. echo '</div>
  161. <div class="tab_wcontent">'.apply_filters( 'wp_editor_widget_content', do_shortcode($cars['content']) ).'</div>
  162. </div>';
  163. }
  164. echo '</div>';
  165.  
  166. echo '</div>'; //tabs-container END
  167.  
  168. } //TABS END
  169.  
  170. if(!empty($carousel) && $type == 'toggle' ){
  171.  
  172. echo '<div class="toggle_widget_wrap toggle_'.$style.'">';
  173.  
  174. foreach($carousel as $cars){
  175. echo '<div class="lts_toggle">';
  176.  
  177. //THE BUTTONS
  178. echo '<div class="trigger_wrap"><a class="trigger"><i class="fa fa-plus"></i> '.do_shortcode($cars['title']).'</a></div>';
  179.  
  180. //THE CONTENT
  181. echo '<div class="lts_toggle_content" style="display:none;">';
  182.  
  183. echo '<div class="toggle_wimg">';
  184. if (!empty ($cars['image'])) { echo '<img alt="'.$cars['title'].'" class="tabs_img" src="'.$cars['image'].'" />' ; }
  185. echo '</div>';
  186.  
  187. echo '<div class="toggle_wcontent">'.apply_filters( 'wp_editor_widget_content', do_shortcode($cars['content']) ).'</div><div style="clear:both"></div>';
  188.  
  189. echo '</div>';//lts_toggle_content END
  190.  
  191. echo '</div>';//lts_toggle END
  192.  
  193. } //FOREACH END
  194.  
  195. echo '</div>';//toggle_widget_wrap END
  196.  
  197. } //TABS END
  198.  
  199.  
  200. echo '</div></div>';
  201.  
  202.  
  203. //Stylesheet-loaded in Customizer Only.
  204. if(is_customize_preview()){
  205. $id= $this->id;
  206.  
  207. echo "<script>jQuery(window).ready(function() { jQuery('#".$id." .looper-inner li:eq(0)').addClass('active'); });</script>";
  208. echo '<script>
  209. jQuery( document ).ajaxStop( function() {
  210. jQuery(".lts_tab p:empty").remove(),jQuery(".lts_tabs .lts_tabtitle.emptyp_clear").remove();var i=1;jQuery(".tabs-container").each(function(){jQuery(this).find("a.tabtrigger").each(function(){jQuery(this).attr("href","#tab-"+i),i++})});var i=1;jQuery(".tabs-container").each(function(){jQuery(this).find(".lts_tab_child").not(":empty").each(function(){jQuery(this).attr("id","tab-"+i),i++})});var i=1;jQuery(".tabs-container").each(function(){jQuery(this).attr("id","tabs-container_"+i),i++}),jQuery(".tabs-container.tabs_default").each(function(){var a=jQuery(this).attr("id"),b=jQuery(this).data("active-color");jQuery("<style>body #"+a+" ul.tabs li.active a{color:"+b+"!important;border-color:"+b+"}</style>").appendTo("head")}),jQuery(".tabs-container.tabs_circular").each(function(){var a=jQuery(this).attr("id"),b=jQuery(this).data("active-color");jQuery("<style>body #"+a+" ul.tabs li.active a{color:"+jQuery("body").css("background-color")+"!important;background:"+b+"}</style>").appendTo("head")}),jQuery(".tabs-container.tabs_minimal").each(function(){var a=jQuery(this).attr("id"),b=jQuery(this).data("active-color");jQuery("<style>body #"+a+" ul.tabs li.active a{color:"+b+"!important;border-color:"+b+"}</style>").appendTo("head")}),jQuery(".tabs-container.tabs_capsule").each(function(){var a=jQuery(this).attr("id"),b=jQuery(this).data("active-color");jQuery("<style>body #"+a+" ul.tabs li.active a{color:"+jQuery("body").css("background-color")+"!important;background:"+b+";border-color:"+b+"}</style>").appendTo("head")}),jQuery(".tabs-container").easytabs({updateHash:!1}),jQuery(".lts_toggle_content").hide(),jQuery(".lts_toggle .trigger").click(function(){return jQuery(this).closest(".lts_toggle").find(".lts_toggle_content").slideToggle("fast"),!1}),jQuery(".lts_toggle a.trigger").toggle(function(){jQuery(this).find("i").animateRotate(135),jQuery(this).addClass("down")},function(){jQuery(this).find("i").animateRotate(-90),jQuery(this).removeClass("down")}),jQuery(".lts_toggle").each(function(){jQuery(this).next("br")&&jQuery(this).next("br").addClass("tabsbr")});
  211. jQuery(".toggle_style3").each(function(a,b){var c=jQuery("<div/>").addClass("first_toggles"),d=jQuery("<div/>").addClass("mid_toggles"),e=jQuery("<div/>").addClass("last_toggles"),f=jQuery(this).find("div.lts_toggle:nth-child(3n+1)"),g=jQuery(this).find("div.lts_toggle:nth-child(3n+2)"),h=jQuery(this).find("div.lts_toggle:nth-child(3n+3)");f.appendTo(c),g.appendTo(d),h.appendTo(e),jQuery(this).append(c,d,e)}),jQuery(".toggle_style2").each(function(a,b){var c=jQuery("<div/>").addClass("first_toggles"),d=jQuery("<div/>").addClass("mid_toggles"),e=jQuery(this).find("div.lts_toggle:nth-child(2n+1)"),f=jQuery(this).find("div.lts_toggle:nth-child(2n+2)");e.appendTo(c),f.appendTo(d),jQuery(this).append(c,d)});
  212. });
  213. </script>';
  214.  
  215. $content_bg = 'background-color:#ffffff;';
  216. $title_color = '#777777;';
  217. $content_bgimg = '';
  218.  
  219. $marginTop =''; $marginBottom =''; $marginLeft =''; $marginRight ='';$calcWidth ='';
  220. $paddingTop =''; $paddingBottom =''; $paddingLeft =''; $paddingRight =''; $boxSizing='';
  221.  
  222. //Margin
  223. if ( ! empty( $instance['margin'] ) ) {
  224. if(!empty($instance['margin'][0])){ $marginTop ='margin-top:'.$instance['margin'][0].';';}
  225. if(!empty($instance['margin'][1])){ $marginBottom ='margin-bottom:'.$instance['margin'][1].';';}
  226. if(!empty($instance['margin'][2])){ $marginLeft ='margin-left:'.$instance['margin'][2].';';}
  227. if(!empty($instance['margin'][3])){ $marginRight ='margin-right:'.$instance['margin'][3].';';}
  228.  
  229. //Width
  230. $thewidth ='100';
  231. $leftrightmargin ='0px';
  232.  
  233. if ( ! empty( $instance['width']) ) { if($instance['width'] == 2){ $thewidth = '50';} if($instance['width'] == 3){ $thewidth = '33.33';} if($instance['width'] == 4){ $thewidth = '66.67';} }
  234. if ( ! empty( $instance['width']) && !empty($instance['margin'][2] ) ) { $leftrightmargin = $instance['margin'][2]; }
  235. if ( ! empty( $instance['width']) && !empty($instance['margin'][3] ) ) { $leftrightmargin = $instance['margin'][3]; }
  236.  
  237. if ( ! empty( $instance['width']) ) {
  238. if(!empty($instance['margin'][2]) && !empty($instance['margin'][3]) ){
  239. $leftrightmargin = '('.$instance['margin'][2].' + '.$instance['margin'][3].')';
  240. }
  241. }
  242. $calcWidth ='width: calc('.$thewidth.'% - '.$leftrightmargin.')!important;';
  243.  
  244. }
  245.  
  246. //Padding
  247. if ( ! empty( $instance['padding'] ) ) {
  248. if(!empty($instance['padding'][0])){ $paddingTop ='padding-top:'.$instance['padding'][0].';';}
  249. if(!empty($instance['padding'][1])){ $paddingBottom ='padding-bottom:'.$instance['padding'][1].';';}
  250. if(!empty($instance['padding'][2])){ $paddingLeft ='padding-left:'.$instance['padding'][2].';';}
  251. if(!empty($instance['padding'][3])){ $paddingRight ='padding-right:'.$instance['padding'][3].';';}
  252.  
  253. $boxSizing='box-sizing:border-box;';
  254.  
  255. }
  256.  
  257.  
  258. if ( ! empty( $instance['content_bg'] ) ) { $content_bg = 'background-color: ' . $instance['content_bg'] . '; '; $rawbg = $instance['content_bg'];}
  259. if ( ! empty( $instance['title_color'] ) ) {$title_color = '' . $instance['title_color'] . '; ';}
  260. if ( ! empty( $instance['content_bgimg'] ) ) {$content_bgimg = 'background-image: url(' . $instance['content_bgimg'] . '); ';}
  261.  
  262.  
  263. echo '<style>#'.$id.'{ ' . $content_bg . $content_bgimg. '}#'.$id.' .home_title, #'.$id.' .home_subtitle, #'.$id.' span.div_middle, #'.$id.' .widget_wrap{ color:' . $title_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:' . $title_color . '} #'.$id.' .home_carousel_inner .tabs li a{ color:' . $title_color . '; border-color:' . $title_color . ';} #'.$id.' .home_carousel_inner .tabs li a.active{ color:' . $rawbg . '!important; background-color:' . $title_color . '} @media screen and (min-width: 480px){#'.$id.' {'.$marginTop.$marginBottom.$marginLeft.$marginRight.$calcWidth. $paddingTop.$paddingBottom.$paddingLeft.$paddingRight. $boxSizing.'} } </style>';
  264.  
  265. }
  266.  
  267.  
  268. /* After widget (defined by themes). */
  269. echo $after_widget;
  270.  
  271. }
  272.  
  273.  
  274.  
  275.  
  276. /* ---------------------------- */
  277. /* ------- Update Widget -------- */
  278. /* ---------------------------- */
  279.  
  280. function update( $new_instance, $old_instance ) {
  281. $instance = $old_instance;
  282.  
  283. /* Strip tags for title and name to remove HTML (important for text inputs). */
  284. $instance['title'] = strip_tags( $new_instance['title'] );
  285.  
  286. /* No need to strip tags */
  287. $instance['subtitle'] = strip_tags($new_instance['subtitle']);
  288. $instance['divider'] = strip_tags($new_instance['divider']);
  289. $instance['type'] = strip_tags($new_instance['type']);
  290. $instance['style'] = strip_tags($new_instance['style']);
  291. $instance['img_pos'] = strip_tags($new_instance['img_pos']);
  292. $instance['title_color'] = optimizer_sanitize_hex($new_instance['title_color']);
  293. $instance['content_bg'] = optimizer_sanitize_hex($new_instance['content_bg']);
  294. $instance['content_bgimg'] = esc_url_raw($new_instance['content_bgimg']);
  295. $instance['pausetime'] = strip_tags($new_instance['pausetime']);
  296.  
  297.  
  298. $instance['carousel'] = array();
  299.  
  300. if ( isset( $new_instance['carousel'] ) )
  301. {
  302. foreach ( $new_instance['carousel'] as $cars )
  303. {
  304. if ( '' !== trim( $cars['title'] ) )
  305. $instance['carousel'][] = $cars;
  306. }
  307. }
  308.  
  309. return $instance;
  310. }
  311.  
  312. /* ---------------------------- */
  313. /* ------- Widget Settings ------- */
  314. /* ---------------------------- */
  315.  
  316. /**
  317. * Displays the widget settings controls on the widget panel.
  318. * Make use of the get_field_id() and get_field_name() function
  319. * when creating your form elements. This handles the confusing stuff.
  320. */
  321.  
  322. function form( $instance ) {
  323.  
  324. /* Set up some default widget settings. */
  325. $defaults = array(
  326. 'title' => __('What are people saying?','optimizer'),
  327. 'subtitle' => __('Real words from real customers!','optimizer'),
  328. 'type' => 'carousel',
  329. 'style' => 'style1',
  330. 'carousel' => '',
  331. 'img_pos' => 'top',
  332. 'divider' => 'fa-stop',
  333. 'title_color' => '#777777',
  334. 'content_bg' => '#ffffff',
  335. 'content_bgimg' => '',
  336. 'pausetime' => '8000'
  337. );
  338. $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  339.  
  340.  
  341. <!-- Carousel Section TITLE Field -->
  342. <p>
  343. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'optimizer') ?></label>
  344. <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" />
  345. </p>
  346.  
  347. <!-- Carousel Section Subtitle Field -->
  348. <p>
  349. <label for="<?php echo $this->get_field_id( 'subtitle' ); ?>"><?php _e('Subtitle:', 'optimizer') ?></label>
  350. <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" />
  351. </p>
  352.  
  353.  
  354. <!-- Carousel Type Field -->
  355. <p>
  356. <label for="<?php echo $this->get_field_id( 'type' ); ?>"><?php _e('Display As:', 'optimizer') ?></label>
  357. <select id="<?php echo $this->get_field_id( 'type' ); ?>" name="<?php echo $this->get_field_name( 'type' ); ?>" class="widefat dynamic_type_field">
  358. <option value="carousel" <?php if ( 'carousel' == $instance['type'] ) echo 'selected="selected"'; ?>><?php _e('Carousel', 'optimizer') ?></option>
  359. <option value="tabs" <?php if ( 'tabs' == $instance['type'] ) echo 'selected="selected"'; ?>><?php _e('Tabs', 'optimizer') ?></option>
  360. <option value="toggle" <?php if ( 'toggle' == $instance['type'] ) echo 'selected="selected"'; ?>><?php _e('Toggle', 'optimizer') ?></option>
  361. </select>
  362. </p>
  363.  
  364.  
  365. <!-- ----------------Carousel Field------------------------ -->
  366. <div class="widget_repeater" data-widget-id="<?php echo $this->get_field_id( 'carousel' ); ?>" data-widget-name="<?php echo $this->get_field_name( 'carousel' ); ?>">
  367. <?php
  368. $customtesti = isset( $instance['carousel'] ) ? $instance['carousel'] : array();
  369. $customtesti_num = count($customtesti);
  370. $customtesti[$customtesti_num+1] = '';
  371. $cars_html = array();
  372. $customtesti_counter = 0;
  373.  
  374. foreach ( $customtesti as $cars )
  375. {
  376. if ( isset($cars['title']) )
  377. {
  378. $cars_html[] = sprintf(
  379. '<div class="widget_input_wrap">
  380. <span id="%4$s%2$s" class="repeat_handle" onclick="repeatOpen(this.id)">%5$s</span>
  381. <input type="text" name="%1$s[%2$s][title]" value="%5$s" class="widefat" placeholder="%6$s">
  382. <div class="media-picker-wrap">
  383. %7$s
  384. <input id="%3$s-%2$s-img" type="hidden" name="%1$s[%2$s][image]" value="%8$s" class="widefat media-picker">
  385. <a id="%10$s-%2$s" onclick="mediaPicker(this.id)" class="media-picker-button button">%9$s</a>
  386. </div>
  387. <input id="%3$s-%2$s-cont" type="hidden" name="%1$s[%2$s][content]" value="%12$s" class="widefat">
  388. <a id="%11$s-%2$s" href="javascript:WPEditorWidget.showEditor(\'%3$s-%2$s-cont\')" class="edit-content-button button">%13$s</a>
  389. <span class="remove-field button button-primary">Remove</span>
  390. </div>',
  391. $this->get_field_name( 'carousel' ), //1
  392. $customtesti_counter, //2
  393. $this->get_field_id('carousel').'', //3
  394. $this->get_field_id('custom_add_field').'-repeat', //4
  395.  
  396. //Title
  397. esc_attr( $cars['title'] ), //5 - Title Value
  398. __('Title (Required)','optimizer'), //6 - Title Placeholder
  399. //Media
  400. !empty($cars['image']) ? '<img class="media-picker-preview" src="'.esc_url($cars['image']).'" /><i class="fa fa-times media-picker-remove"></i>': '', //7
  401. esc_url( $cars['image'] ), //8 - Image Value
  402. __('Select Image', 'optimizer'), //9 - Image Placeholder
  403. $this->get_field_id('carousel').'-mpick', //10
  404.  
  405. //Content
  406. $this->get_field_id('carousel').'-editor', //11
  407. esc_attr( $cars['content']), //12 - Content Value
  408. __('Edit Content', 'optimizer') //13 - Content Placeholder
  409.  
  410. );
  411. }
  412.  
  413. $customtesti_counter += 1;
  414. }
  415.  
  416. echo '<h4>'.__('Content','optimizer').'</h4>' . join( $cars_html );
  417.  
  418. ?>
  419.  
  420. <script type="text/javascript">
  421. var fieldnum = <?php echo json_encode( $customtesti_counter-1 ) ?>;
  422. var count = fieldnum;
  423. function customCarsclickFunction(buttonid){
  424. var fieldname = jQuery('#'+buttonid).data('widget-fieldname');
  425. var fieldid = jQuery('#'+buttonid).data('widget-fieldid');
  426.  
  427. 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( 'Title (Required)', 'optimizer' ); ?>' class='widefat' placeholder='<?php _e( 'Title (Required)', 'optimizer' ); ?>'><div class='media-picker-wrap'><input type='hidden' name='"+fieldname+"["+(count+1)+"][image]' value='' class='widefat media-picker' id='"+fieldid+"-"+(count+1)+"-img'><a id='"+fieldid+"-mpick"+(count+1)+"' class='media-picker-button button' onclick='mediaPicker(this.id)'><?php _e('Select Image', 'optimizer') ?></a></div><input type='hidden' name='"+fieldname+"["+(count+1)+"][content]' value='' class='widefat' id='"+fieldid+"-"+(count+1)+"-cont'><a href='javascript:WPEditorWidget.showEditor(\""+fieldid+"-"+(count+1)+"-cont\")' class='edit-content-button button'><?php _e('Edit Content', 'optimizer') ?></a><span class='remove-field button button-primary'>Remove</span></div>");
  428. count++;
  429.  
  430. }
  431.  
  432. </script>
  433.  
  434. <span id="<?php echo $this->get_field_id( 'custom-field_clone' );?>" class="repeat_clone_field" data-empty-content="<?php _e('No Carousel / Tabs Added!', 'optimizer') ?>"></span>
  435.  
  436. <?php echo '<input onclick="customCarsclickFunction(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('carousel').'" data-widget-fieldid="'.$this->get_field_id('carousel').'" />';?>
  437. </div>
  438.  
  439.  
  440. <!-- Carousel TITLE DIVIDER Field -->
  441. <p>
  442. <label for="<?php echo $this->get_field_id( 'divider' ); ?>"><?php _e('Title Divider:', 'optimizer') ?></label>
  443. <select id="<?php echo $this->get_field_id( 'divider' ); ?>" name="<?php echo $this->get_field_name( 'divider' ); ?>" class="widefat">
  444. <option value="underline" <?php if ( 'underline' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Underline', 'optimizer') ?></option>
  445. <option value="border-center" <?php if ( 'border-center' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Bordered (Center)', 'optimizer') ?></option>
  446. <option value="border-left" <?php if ( 'border-left' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Bordered (Left)', 'optimizer') ?></option>
  447. <option value="border-right" <?php if ( 'border-right' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Bordered (Right)', 'optimizer') ?></option>
  448. <option value="fa-stop" <?php if ( 'fa-stop' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Rhombus', 'optimizer') ?></option>
  449. <option value="fa-star" <?php if ( 'fa-star' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Star', 'optimizer') ?></option>
  450. <option value="fa-times" <?php if ( 'fa-times' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Cross', 'optimizer') ?></option>
  451. <option value="fa-bolt" <?php if ( 'fa-bolt' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Bolt', 'optimizer') ?></option>
  452. <option value="fa-asterisk" <?php if ( 'fa-asterisk' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Asterisk', 'optimizer') ?></option>
  453. <option value="fa-chevron-down" <?php if ( 'fa-chevron-down' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Chevron', 'optimizer') ?></option>
  454. <option value="fa-heart" <?php if ( 'fa-heart' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Heart', 'optimizer') ?></option>
  455. <option value="fa-plus" <?php if ( 'fa-plus' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Plus', 'optimizer') ?></option>
  456. <option value="fa-bookmark" <?php if ( 'fa-bookmark' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Bookmark', 'optimizer') ?></option>
  457. <option value="fa-circle-o" <?php if ( 'fa-circle-o' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Circle', 'optimizer') ?></option>
  458. <option value="fa-th-large" <?php if ( 'fa-th-large' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Blocks', 'optimizer') ?></option>
  459. <option value="fa-minus" <?php if ( 'fa-minus' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Sides', 'optimizer') ?></option>
  460. <option value="fa-cog" <?php if ( 'fa-cog' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Cog', 'optimizer') ?></option>
  461. <option value="fa-reorder" <?php if ( 'fa-reorder' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Blinds', 'optimizer') ?></option>
  462. <option value="fa-diamond" <?php if ( 'fa-diamond' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Diamond', 'optimizer') ?></option>
  463. <option value="fa-gg" <?php if ( 'fa-gg' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Tetris', 'optimizer') ?></option>
  464. <option value="fa-houzz" <?php if ( 'fa-houzz' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Digital', 'optimizer') ?></option>
  465. <option value="fa-rocket" <?php if ( 'fa-rocket' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Rocket', 'optimizer') ?></option>
  466. <option value="no_divider" <?php if ( 'no_divider' == $instance['divider'] ) echo 'selected="selected"'; ?>><?php _e('Hide Divider', 'optimizer') ?></option>
  467. </select>
  468. </p>
  469.  
  470. <!-- Carousel Pause Time Field -->
  471. <p>
  472. <label for="<?php echo $this->get_field_id( 'pausetime' ); ?>"><?php _e('Carousel Pausetime:', 'optimizer') ?></label>
  473. <input class="widefat cars_pausetime" id="<?php echo $this->get_field_id( 'pausetime' ); ?>" name="<?php echo $this->get_field_name( 'pausetime' ); ?>" value="<?php echo htmlspecialchars($instance['pausetime'], ENT_QUOTES, "UTF-8"); ?>" type="text" />
  474. </p>
  475.  
  476. <!-- Carousel Style Field -->
  477. <p>
  478. <label for="<?php echo $this->get_field_id( 'style' ); ?>"><?php _e('Style:', 'optimizer') ?></label>
  479. <select id="<?php echo $this->get_field_id( 'style' ); ?>" name="<?php echo $this->get_field_name( 'style' ); ?>" class="widefat">
  480. <option value="style1" <?php if ( 'style1' == $instance['style'] ) echo 'selected="selected"'; ?>><?php _e('Style 1', 'optimizer') ?></option>
  481. <option value="style2" <?php if ( 'style2' == $instance['style'] ) echo 'selected="selected"'; ?>><?php _e('Style 2', 'optimizer') ?></option>
  482. <option value="style3" <?php if ( 'style3' == $instance['style'] ) echo 'selected="selected"'; ?>><?php _e('Style 3', 'optimizer') ?></option>
  483. </select>
  484. </p>
  485.  
  486. <!-- Carousel Column Field -->
  487. <p>
  488. <label for="<?php echo $this->get_field_id( 'img_pos' ); ?>"><?php _e('Image Alignment', 'optimizer') ?></label>
  489. <select id="<?php echo $this->get_field_id( 'img_pos' ); ?>" name="<?php echo $this->get_field_name( 'img_pos' ); ?>" class="widefat">
  490. <option value="top" <?php if ( 'top' == $instance['img_pos'] ) echo 'selected="selected"'; ?>><?php _e('Top', 'optimizer') ?></option>
  491. <option value="left" <?php if ( 'left' == $instance['img_pos'] ) echo 'selected="selected"'; ?>><?php _e('Left', 'optimizer') ?></option>
  492. <option value="right" <?php if ( 'right' == $instance['img_pos'] ) echo 'selected="selected"'; ?>><?php _e('Right', 'optimizer') ?></option>
  493. </select>
  494. </p>
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501. <!-- Testimonial Title 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. <!-- Testimonial Background Color Field -->
  509. <p>
  510. <label for="<?php echo $this->get_field_id( 'content_bg' ); ?>"><?php _e('Background Color', 'optimizer') ?></label>
  511. <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" />
  512. </p>
  513.  
  514.  
  515.  
  516. <!-- Testimonial Background IMAGE FIELD -->
  517. <div class="widget_input_wrap">
  518. <label for="<?php echo $this->get_field_id( 'content_bgimg' ); ?>"><?php _e('Background Image', 'optimizer') ?></label>
  519. <div class="media-picker-wrap">
  520. <?php if(!empty($instance['content_bgimg'])) { ?>
  521. <img style="max-width:100%; height:auto;" class="media-picker-preview" src="<?php echo esc_url($instance['content_bgimg']); ?>" />
  522. <i class="fa fa-times media-picker-remove"></i>
  523. <?php } ?>
  524. <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" />
  525. <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>
  526. </div>
  527. </div>
  528.  
  529. <?php
  530. }
  531. //ENQUEUE CSS
  532. function front_carousel_enqueue_css() {
  533. $settings = $this->get_settings();
  534.  
  535. if ( empty( $settings ) ) {
  536. return;
  537. }
  538.  
  539. foreach ( $settings as $instance_id => $instance ) {
  540. $id = $this->id_base . '-' . $instance_id;
  541. if(!is_customize_preview()){
  542. if ( ! is_active_widget( false, $id, $this->id_base ) ) {
  543. continue;
  544. }
  545.  
  546. $content_bg = 'background-color:#ffffff;';
  547. $title_color = '#777777;';
  548. $content_bgimg = '';
  549.  
  550. $marginTop =''; $marginBottom =''; $marginLeft =''; $marginRight ='';$calcWidth ='';
  551. $paddingTop =''; $paddingBottom =''; $paddingLeft =''; $paddingRight =''; $boxSizing='';
  552.  
  553. //Margin
  554. if ( ! empty( $instance['margin'] ) ) {
  555. if(!empty($instance['margin'][0])){ $marginTop ='margin-top:'.$instance['margin'][0].';';}
  556. if(!empty($instance['margin'][1])){ $marginBottom ='margin-bottom:'.$instance['margin'][1].';';}
  557. if(!empty($instance['margin'][2])){ $marginLeft ='margin-left:'.$instance['margin'][2].';';}
  558. if(!empty($instance['margin'][3])){ $marginRight ='margin-right:'.$instance['margin'][3].';';}
  559.  
  560. //Width
  561. $thewidth ='100';
  562. $leftrightmargin ='0px';
  563.  
  564. if ( ! empty( $instance['width']) ) { if($instance['width'] == 2){ $thewidth = '50';} if($instance['width'] == 3){ $thewidth = '33.33';} if($instance['width'] == 4){ $thewidth = '66.67';} }
  565. if ( ! empty( $instance['width']) && !empty($instance['margin'][2] ) ) { $leftrightmargin = $instance['margin'][2]; }
  566. if ( ! empty( $instance['width']) && !empty($instance['margin'][3] ) ) { $leftrightmargin = $instance['margin'][3]; }
  567.  
  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.  
  589. if ( ! empty( $instance['content_bg'] ) ) {
  590. $content_bg = 'background-color: ' . $instance['content_bg'] . '; ';
  591. $rawbg = $instance['content_bg'];
  592. }
  593. if ( ! empty( $instance['title_color'] ) ) {
  594. $title_color = '' . $instance['title_color'] . '; ';
  595. }
  596. if ( ! empty( $instance['content_bgimg'] ) ) {
  597. $content_bgimg = 'background-image: url(' . $instance['content_bgimg'] . '); ';
  598. }
  599.  
  600. $widget_style = '#'.$id.'{ ' . $content_bg . $content_bgimg. '}#'.$id.' .home_title, #'.$id.' .home_subtitle, #'.$id.' span.div_middle, #'.$id.' .widget_wrap{ color:' . $title_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:' . $title_color . '} #'.$id.' .home_carousel_inner .tabs li a{ color:' . $title_color . '; border-color:' . $title_color . ';} #'.$id.' .home_carousel_inner .tabs li a.active{ color:' . $rawbg . '!important; background-color:' . $title_color . '} @media screen and (min-width: 480px){#'.$id.' {'.$marginTop.$marginBottom.$marginLeft.$marginRight.$calcWidth. $paddingTop.$paddingBottom.$paddingLeft.$paddingRight. $boxSizing.'} }';
  601. wp_add_inline_style( 'optimizer-style', $widget_style );
  602.  
  603. }
  604. }
  605. }
  606. }
  607. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement