PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/themes/enfold/config-templatebuilder/avia-shortcodes/buttons_fullwidth.php

https://bitbucket.org/SanchitSahu03/hyslifecare
PHP | 368 lines | 270 code | 65 blank | 33 comment | 29 complexity | dfad00418213627bfc35d668c2caeb91 MD5 | raw file
  1. <?php
  2. /**
  3. * Button
  4. * Displays a button that links to any url of your choice
  5. */
  6. if ( !class_exists( 'avia_sc_button_full' ) )
  7. {
  8. class avia_sc_button_full extends aviaShortcodeTemplate
  9. {
  10. static $count = 0;
  11. /**
  12. * Create the config array for the shortcode button
  13. */
  14. function shortcode_insert_button()
  15. {
  16. $this->config['name'] = __('Fullwidth Button', 'avia_framework' );
  17. $this->config['tab'] = __('Content Elements', 'avia_framework' );
  18. $this->config['icon'] = AviaBuilder::$path['imagesURL']."sc-button.png";
  19. $this->config['order'] = 84;
  20. $this->config['target'] = 'avia-target-insert';
  21. $this->config['shortcode'] = 'av_button_big';
  22. $this->config['tooltip'] = __('Creates a colored button that stretches across the full width', 'avia_framework' );
  23. $this->config['tinyMCE'] = array('tiny_always'=>true);
  24. }
  25. /**
  26. * Popup Elements
  27. *
  28. * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  29. * opens a modal window that allows to edit the element properties
  30. *
  31. * @return void
  32. */
  33. function popup_elements()
  34. {
  35. $this->elements = array(
  36. array(
  37. "type" => "tab_container", 'nodescription' => true
  38. ),
  39. array(
  40. "type" => "tab",
  41. "name" => __("Content" , 'avia_framework'),
  42. 'nodescription' => true
  43. ),
  44. array( "name" => __("Button Title", 'avia_framework' ),
  45. "desc" => __("This is the text that appears on your button.", 'avia_framework' ),
  46. "id" => "label",
  47. "type" => "input",
  48. "std" => __("Click me", 'avia_framework' )),
  49. array(
  50. "name" => __("Additional Description",'avia_framework' ),
  51. "desc" => __("Enter an additional description",'avia_framework' ),
  52. "id" => "content",
  53. "type" => "textarea",
  54. "std" => ""
  55. ),
  56. array(
  57. "name" => __("Description position", 'avia_framework' ),
  58. "desc" => __("Show the description above or below the title?", 'avia_framework' ),
  59. "id" => "description_pos",
  60. "type" => "select",
  61. "subtype" => array(
  62. __('Description above title', 'avia_framework' ) =>'above',
  63. __('Description below title', 'avia_framework' ) =>'below',
  64. ),
  65. "std" => "below"),
  66. array(
  67. "name" => __("Button Link?", 'avia_framework' ),
  68. "desc" => __("Where should your button link to?", 'avia_framework' ),
  69. "id" => "link",
  70. "type" => "linkpicker",
  71. "fetchTMPL" => true,
  72. "subtype" => array(
  73. __('Set Manually', 'avia_framework' ) =>'manually',
  74. __('Single Entry', 'avia_framework' ) =>'single',
  75. __('Taxonomy Overview Page', 'avia_framework' )=>'taxonomy',
  76. ),
  77. "std" => ""),
  78. array(
  79. "name" => __("Open Link in new Window?", 'avia_framework' ),
  80. "desc" => __("Select here if you want to open the linked page in a new window", 'avia_framework' ),
  81. "id" => "link_target",
  82. "type" => "select",
  83. "std" => "",
  84. "subtype" => AviaHtmlHelper::linking_options()),
  85. array(
  86. "name" => __("Button Icon", 'avia_framework' ),
  87. "desc" => __("Should an icon be displayed at the left side of the button", 'avia_framework' ),
  88. "id" => "icon_select",
  89. "type" => "select",
  90. "std" => "no",
  91. "subtype" => array(
  92. __('No Icon', 'avia_framework' ) =>'no',
  93. __('Yes, display Icon to the left of the title', 'avia_framework' ) => 'yes-left-icon' ,
  94. __('Yes, display Icon to the right of the title', 'avia_framework' ) =>'yes-right-icon',
  95. )),
  96. array(
  97. "name" => __("Icon Visibility",'avia_framework' ),
  98. "desc" => __("Check to only display icon on hover",'avia_framework' ),
  99. "id" => "icon_hover",
  100. "type" => "checkbox",
  101. "std" => "",
  102. "required" => array('icon_select','not_empty_and','no')
  103. ),
  104. array(
  105. "name" => __("Button Icon",'avia_framework' ),
  106. "desc" => __("Select an icon for your Button below",'avia_framework' ),
  107. "id" => "icon",
  108. "type" => "iconfont",
  109. "std" => "",
  110. "required" => array('icon_select','not_empty_and','no')
  111. ),
  112. array(
  113. "type" => "close_div",
  114. 'nodescription' => true
  115. ),
  116. array(
  117. "type" => "tab",
  118. "name" => __("Colors",'avia_framework' ),
  119. 'nodescription' => true
  120. ),
  121. array(
  122. "name" => __("Font Color", 'avia_framework' ),
  123. "desc" => __("Select a custom font color for your Button here", 'avia_framework' ),
  124. "id" => "custom_font",
  125. "type" => "colorpicker",
  126. "std" => "#ffffff",
  127. ),
  128. array(
  129. "name" => __("Background Color", 'avia_framework' ),
  130. "desc" => __("Choose a background color for your button here", 'avia_framework' ),
  131. "id" => "color",
  132. "type" => "select",
  133. "std" => "theme-color",
  134. "subtype" => array(
  135. __('Theme Color', 'avia_framework' )=>'theme-color',
  136. __('Theme Color Subtle', 'avia_framework' )=>'theme-color-subtle',
  137. __('Blue', 'avia_framework' )=>'blue',
  138. __('Red', 'avia_framework' )=>'red',
  139. __('Green', 'avia_framework' )=>'green',
  140. __('Orange', 'avia_framework' )=>'orange',
  141. __('Aqua', 'avia_framework' )=>'aqua',
  142. __('Teal', 'avia_framework' )=>'teal',
  143. __('Purple', 'avia_framework' )=>'purple',
  144. __('Pink', 'avia_framework' )=>'pink',
  145. __('Silver', 'avia_framework' )=>'silver',
  146. __('Grey', 'avia_framework' )=>'grey',
  147. __('Black', 'avia_framework' )=>'black',
  148. __('Custom Color', 'avia_framework' )=>'custom',
  149. )),
  150. array(
  151. "name" => __("Custom Background Color", 'avia_framework' ),
  152. "desc" => __("Select a custom background color for your Button here", 'avia_framework' ),
  153. "id" => "custom_bg",
  154. "type" => "colorpicker",
  155. "std" => "#444444",
  156. "required" => array('color','equals','custom')
  157. ),
  158. array(
  159. "name" => __("Background Hover Color", 'avia_framework' ),
  160. "desc" => __("Choose a background hover color for your button here", 'avia_framework' ),
  161. "id" => "color_hover",
  162. "type" => "select",
  163. "std" => "theme-color-subtle",
  164. "subtype" => array(
  165. __('Theme Color', 'avia_framework' )=>'theme-color',
  166. __('Theme Color Subtle', 'avia_framework' )=>'theme-color-subtle',
  167. __('Blue', 'avia_framework' )=>'blue',
  168. __('Red', 'avia_framework' )=>'red',
  169. __('Green', 'avia_framework' )=>'green',
  170. __('Orange', 'avia_framework' )=>'orange',
  171. __('Aqua', 'avia_framework' )=>'aqua',
  172. __('Teal', 'avia_framework' )=>'teal',
  173. __('Purple', 'avia_framework' )=>'purple',
  174. __('Pink', 'avia_framework' )=>'pink',
  175. __('Silver', 'avia_framework' )=>'silver',
  176. __('Grey', 'avia_framework' )=>'grey',
  177. __('Black', 'avia_framework' )=>'black',
  178. __('Custom Color', 'avia_framework' )=>'custom',
  179. )),
  180. array(
  181. "name" => __("Custom Hover Color", 'avia_framework' ),
  182. "desc" => __("Select a custom background color for your Button here", 'avia_framework' ),
  183. "id" => "custom_bg_hover",
  184. "type" => "colorpicker",
  185. "std" => "#444444",
  186. "required" => array('color_hover','equals','custom')
  187. ),
  188. array(
  189. "type" => "close_div",
  190. 'nodescription' => true
  191. ),
  192. array(
  193. "type" => "close_div",
  194. 'nodescription' => true
  195. ),
  196. );
  197. }
  198. /**
  199. * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  200. * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  201. * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  202. *
  203. *
  204. * @param array $params this array holds the default values for $content and $args.
  205. * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  206. */
  207. function editor_element($params)
  208. {
  209. extract(av_backend_icon($params)); // creates $font and $display_char if the icon was passed as param "icon" and the font as "font"
  210. $inner = "<div class='avia_button_box avia_hidden_bg_box avia_textblock avia_textblock_style'>";
  211. $inner .= " <div ".$this->class_by_arguments('icon_select, color' ,$params['args']).">";
  212. $inner .= " <span ".$this->class_by_arguments('font' ,$font).">";
  213. $inner .= " <span data-update_with='icon_fakeArg' class='avia_button_icon avia_button_icon_left'>".$display_char."</span>";
  214. $inner .= " </span>";
  215. $inner .= " <span data-update_with='label' class='avia_iconbox_title' >".$params['args']['label']."</span>";
  216. $inner .= " <span ".$this->class_by_arguments('font' ,$font).">";
  217. $inner .= " <span data-update_with='icon_fakeArg' class='avia_button_icon avia_button_icon_right'>".$display_char."</span>";
  218. $inner .= " </span>";
  219. $inner .= " </div>";
  220. $inner .= "</div>";
  221. $params['innerHtml'] = $inner;
  222. $params['class'] = "";
  223. return $params;
  224. }
  225. /**
  226. * Frontend Shortcode Handler
  227. *
  228. * @param array $atts array of attributes
  229. * @param string $content text within enclosing form of shortcode element
  230. * @param string $shortcodename the shortcode found, when == callback name
  231. * @return string $output returns the modified html string
  232. */
  233. function shortcode_handler($atts, $content = "", $shortcodename = "", $meta = "")
  234. {
  235. avia_sc_button_full::$count++;
  236. $atts = shortcode_atts(array('label' => 'Click me',
  237. 'link' => '',
  238. 'link_target' => '',
  239. 'color' => 'theme-color',
  240. 'color_hover' => 'theme-color-subtle',
  241. 'custom_bg' => '#444444',
  242. 'custom_bg_hover' => '#444444',
  243. 'custom_font' => '#ffffff',
  244. 'position' => 'center',
  245. 'icon_select' => 'no',
  246. 'icon' => '',
  247. 'font' =>'',
  248. 'icon_hover' => '',
  249. 'description_pos' => ''
  250. ), $atts, $this->config['shortcode']);
  251. $display_char = av_icon($atts['icon'], $atts['font']);
  252. $style = "color:".$atts['custom_font']."; ";
  253. $style_hover = "";
  254. if($atts['color'] == "custom")
  255. {
  256. $style .= "background-color:".$atts['custom_bg']."; ";
  257. }
  258. if($atts['color_hover'] == "custom")
  259. {
  260. $style_hover = "style='background-color:".$atts['custom_bg_hover']."; '";
  261. }
  262. $extraClass = $atts['icon_hover'] ? "av-icon-on-hover" : "";
  263. $blank = strpos($atts['link_target'], '_blank') !== false ? ' target="_blank" ' : "";
  264. $blank .= strpos($atts['link_target'], 'nofollow') !== false ? ' rel="nofollow" ' : "";
  265. $link = AviaHelper::get_url($atts['link']);
  266. $link = $link == "http://" ? "" : $link;
  267. if($style) $style = "style='{$style}'";
  268. $content_html = "";
  269. if($content && $atts['description_pos'] == 'above')
  270. {
  271. $content_html .= "<div class='av-button-description av-button-description-above'>".ShortcodeHelper::avia_apply_autop(ShortcodeHelper::avia_remove_autop($content) )."</div>";
  272. }
  273. if('yes-left-icon' == $atts['icon_select']) $content_html .= "<span class='avia_button_icon avia_button_icon_left ' {$display_char}></span>";
  274. $content_html .= "<span class='avia_iconbox_title' >".$atts['label']."</span>";
  275. if('yes-right-icon' == $atts['icon_select']) $content_html .= "<span class='avia_button_icon avia_button_icon_right' {$display_char}></span>";
  276. if($content && $atts['description_pos'] == 'below')
  277. {
  278. $content_html .= "<div class='av-button-description av-button-description-below'>".ShortcodeHelper::avia_apply_autop(ShortcodeHelper::avia_remove_autop($content) )."</div>";
  279. }
  280. $output = "";
  281. $output .= "<a href='{$link}' class='avia-button avia-button-fullwidth {$extraClass} ".$this->class_by_arguments('icon_select, color' , $atts, true)."' {$blank} {$style} >";
  282. $output .= $content_html;
  283. $output .= "<span class='avia_button_background avia-button avia-button-fullwidth avia-color-".$atts['color_hover']."' {$style_hover}></span>";
  284. $output .= "</a>";
  285. $output = "<div class='avia-button-wrap avia-button-".$atts['position']." ".$meta['el_class']."'>".$output."</div>";
  286. $params['class'] = "main_color av-fullscreen-button avia-no-border-styling ".$meta['el_class'];
  287. $params['open_structure'] = false;
  288. $id = AviaHelper::save_string($atts['label'],'-');
  289. $params['id'] = !empty($id) ? $id : "av-fullwidth-button-".avia_sc_button_full::$count;
  290. $params['custom_markup'] = $meta['custom_markup'];
  291. //we dont need a closing structure if the element is the first one or if a previous fullwidth element was displayed before
  292. if($meta['index'] == 0) $params['close'] = false;
  293. if(!empty($meta['siblings']['prev']['tag']) && in_array($meta['siblings']['prev']['tag'], AviaBuilder::$full_el_no_section )) $params['close'] = false;
  294. if(!ShortcodeHelper::is_top_level()) return $output;
  295. $button_html = $output;
  296. $output = avia_new_section($params);
  297. $output .= $button_html;
  298. $output .= avia_section_after_element_content( $meta , 'after_fullwidth_button' );
  299. return $output;
  300. return $output;
  301. }
  302. }
  303. }