/shared/shortcodes/shortcodes/teaser.php

https://github.com/deltafactory/leads · PHP · 255 lines · 225 code · 21 blank · 9 comment · 20 complexity · 74f93aae07c8d93d0d47bbf5fb97bd06 MD5 · raw file

  1. <?php
  2. /**
  3. * Teaser Shortcode
  4. */
  5. /* Shortcode generator config
  6. * ----------------------------------------------------- */
  7. $shortcodes_config['teaser'] = array(
  8. 'no_preview' => true,
  9. 'options' => array(
  10. 'heading' => array(
  11. 'name' => __('Heading', 'leads'),
  12. 'desc' => __('Enter the heading text', 'leads'),
  13. 'type' => 'text',
  14. 'std' => ''
  15. ),
  16. 'style' => array(
  17. 'name' => __('Style', 'leads'),
  18. 'desc' => __('Select the style.', 'leads'),
  19. 'type' => 'select',
  20. 'options' => array(
  21. '' => __('Default', 'leads'),
  22. 'nested' => __('Nested', 'leads'),
  23. 'centered' => __('Centered', 'leads')
  24. ),
  25. 'std' => ''
  26. ),
  27. 'column' => array(
  28. 'name' => __('Column', 'leads'),
  29. 'desc' => __('Select the number of column(s).', 'leads'),
  30. 'type' => 'select',
  31. 'options' => array(
  32. '1' => __('1 Column', 'leads'),
  33. '2' => __('2 Columns', 'leads'),
  34. '3' => __('3 Columns', 'leads'),
  35. '4' => __('4 Columns', 'leads'),
  36. '5' => __('5 Columns', 'leads')
  37. ),
  38. 'std' => '3'
  39. )
  40. ),
  41. 'child' => array(
  42. 'options' => array(
  43. 'title' => array(
  44. 'name' => __('Title', 'leads'),
  45. 'desc' => __('Enter the title.', 'leads'),
  46. 'type' => 'text',
  47. 'std' => ''
  48. ),
  49. 'subtitle' => array(
  50. 'name' => __('Sub Title', 'leads'),
  51. 'desc' => __('Enter the sub title.', 'leads'),
  52. 'type' => 'text',
  53. 'std' => ''
  54. ),
  55. 'icon' => array(
  56. 'name' => __('Icon', 'leads'),
  57. 'desc' => __('Select an icon.', 'leads'),
  58. 'type' => 'select',
  59. 'options' => $fontawesome,
  60. 'std' => ''
  61. ),
  62. 'image' => array(
  63. 'name' => __('Image URL', 'leads'),
  64. 'desc' => __('Enter your image url, it will override the icon above', 'leads'),
  65. 'type' => 'text',
  66. 'std' => '',
  67. 'class' => ''
  68. ),
  69. 'link' => array(
  70. 'name' => __('Link', 'leads'),
  71. 'desc' => __('The title link destination URL.', 'leads'),
  72. 'type' => 'text',
  73. 'std' => ''
  74. ),
  75. 'content' => array(
  76. 'name' => __('Teaser Content', 'leads'),
  77. 'desc' => __('Enter the content.', 'leads'),
  78. 'type' => 'textarea',
  79. 'std' => ''
  80. )
  81. ),
  82. 'shortcode' => '[block title="{{title}}" subtitle="{{subtitle}}" icon="{{icon}}" link="{{link}}" ]{{content}}[/block]',
  83. 'clone' => __('Add More Block', 'leads' )
  84. ),
  85. 'shortcode' => '[teaser heading="{{heading}}" style="{{style}}" column="{{column}}"]{{child}}[/teaser]',
  86. 'popup_title' => 'Insert Teaser Shortcode'
  87. );
  88. /* Page builder module config
  89. * ----------------------------------------------------- */
  90. $freshbuilder_modules['teaser'] = array(
  91. 'name' => __('Teaser', 'leads'),
  92. 'size' => 'one_full',
  93. 'options' => array(
  94. 'heading' => array(
  95. 'name' => __('Heading', 'leads'),
  96. 'desc' => __('Enter the heading text.', 'leads'),
  97. 'type' => 'text',
  98. 'std' => '',
  99. 'class' => '',
  100. 'is_content' => 0
  101. ),
  102. 'style' => array(
  103. 'name' => __('Style', 'leads'),
  104. 'desc' => __('Select the style.', 'leads'),
  105. 'type' => 'select',
  106. 'options' => array(
  107. '' => __('Default', 'leads'),
  108. 'nested' => __('Nested', 'leads'),
  109. 'centered' => __('Centered', 'leads')
  110. ),
  111. 'std' => '',
  112. 'class' => '',
  113. 'is_content' => 0
  114. ),
  115. 'column' => array(
  116. 'name' => __('Column', 'leads'),
  117. 'desc' => __('Select the column.', 'leads'),
  118. 'type' => 'select',
  119. 'options' => array(
  120. '1' => __('1 Column', 'leads'),
  121. '2' => __('2 Columns', 'leads'),
  122. '3' => __('3 Columns', 'leads'),
  123. '4' => __('4 Columns', 'leads'),
  124. '5' => __('5 Columns', 'leads')
  125. ),
  126. 'std' => '3',
  127. 'class' => '',
  128. 'is_content' => 0
  129. )
  130. ),
  131. 'child' => array(
  132. 'icon' => array(
  133. 'name' => __('Icon', 'leads'),
  134. 'desc' => __('Select an icon.', 'leads'),
  135. 'type' => 'select',
  136. 'options' => $fontawesome,
  137. 'std' => 'none',
  138. 'class' => '',
  139. 'is_content' => 0
  140. ),
  141. 'image' => array(
  142. 'name' => __('Image URL', 'leads'),
  143. 'desc' => __('Enter your image url, it will override the icon above', 'leads'),
  144. 'type' => 'text',
  145. 'std' => '',
  146. 'class' => '',
  147. 'is_content' => 0
  148. ),
  149. 'title' => array(
  150. 'name' => __('Title', 'leads'),
  151. 'desc' => __('Enter the heading text.', 'leads'),
  152. 'type' => 'text',
  153. 'class' => '',
  154. 'is_content' => 0
  155. ),
  156. 'subtitle' => array(
  157. 'name' => __('Sub Title', 'leads'),
  158. 'desc' => __('Enter the sub title.', 'leads'),
  159. 'type' => 'text',
  160. 'class' => '',
  161. 'is_content' => 0
  162. ),
  163. 'link' => array(
  164. 'name' => __('Link', 'leads'),
  165. 'desc' => __('The title link destination URL.', 'leads'),
  166. 'type' => 'text',
  167. 'class' => '',
  168. 'is_content' => 0
  169. ),
  170. 'content' => array(
  171. 'name' => __('Content', 'leads'),
  172. 'desc' => __('Enter the content.', 'leads'),
  173. 'type' => 'textarea',
  174. 'std' => '',
  175. 'class' => '',
  176. 'is_content' => 1
  177. )
  178. ),
  179. 'child_code' => 'block'
  180. );
  181. /* Add shortcode
  182. * ----------------------------------------------------- */
  183. add_shortcode('teaser', 'inbound_shortcode_teaser');
  184. function inbound_shortcode_teaser( $atts, $content = null ) {
  185. extract(shortcode_atts(array(
  186. 'heading' => '',
  187. 'style' => '',
  188. 'column' => '4'
  189. ), $atts));
  190. $out = '';
  191. $grid = ' grid full';
  192. if ($column == '2') $grid = ' grid one-half';
  193. if ($column == '3') $grid = ' grid one-third';
  194. if ($column == '4') $grid = ' grid one-fourth';
  195. if ($column == '5') $grid = ' grid one-fifth';
  196. $style = ($style != '') ? ' '. $style : '';
  197. if (!preg_match_all("/(.?)\[(block)\b(.*?)(?:(\/))?\](?:(.+?)\[\/block\])?(.?)/s", $content, $matches)) {
  198. return do_shortcode($content);
  199. }
  200. else {
  201. for($i = 0; $i < count($matches[0]); $i++) {
  202. $matches[3][$i] = shortcode_parse_atts($matches[3][$i]);
  203. }
  204. $out .= '<div class="row">';
  205. if ($heading != '') {
  206. $out .= '<div class="grid full"><div class="heading"><h3>'.$heading.'</h3><div class="sep"></div></div></div>';
  207. }
  208. for($i = 0; $i < count($matches[0]); $i++) {
  209. $title = ( $matches[3][$i]['link'] ) ? '<a class="reserve" href="'. $matches[3][$i]['link'] .'">'. $matches[3][$i]['title'] .'</a>' : $matches[3][$i]['title'];
  210. $out .= '<aside class="teaser'. $grid . $style .'">';
  211. if( $matches[3][$i]['image'] ) {
  212. $out .= '<div class="teaser-image"><img src="'. $matches[3][$i]['image'] .'" alt="" /></div>';
  213. }
  214. elseif ( $matches[3][$i]['icon'] ) {
  215. $out .= '<div class="teaser-icon"><i class="icon-'. $matches[3][$i]['icon'] .'"></i></div>';
  216. }
  217. $out .= '<header class="teaser-header">';
  218. $out .= '<h3 class="teaser-title">'.$title.'</h3>';
  219. if( $matches[3][$i]['subtitle'] ) {
  220. $out .= '<div class="teaser-subtitle">'. $matches[3][$i]['subtitle'] .'</div>';
  221. }
  222. $out .= '</header>';
  223. if( $matches[5][$i] ) {
  224. $out .= '<div class="teaser-content">'.do_shortcode( trim($matches[5][$i]) ).'</div>';
  225. }
  226. $out .= '</aside>';
  227. }
  228. if( $i == $column - 1 ) {
  229. $out .= '<div class="clear"></div>';
  230. }
  231. $out .= '</div>';
  232. }
  233. return $out;
  234. }