vamtam-callout.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <?php
  2. /**
  3. * @class VamtamCalloutModule
  4. */
  5. class VamtamCalloutModule extends FLBuilderModule {
  6. /**
  7. * @method __construct
  8. */
  9. public function __construct() {
  10. $path = trailingslashit( 'modules/' . basename( dirname( __FILE__ ) ) );
  11. parent::__construct(array(
  12. 'name' => __( 'Callout', 'vamtam-elements-b' ),
  13. 'description' => __( 'A heading and snippet of text with an optional link, icon and image.', 'vamtam-elements-b' ),
  14. 'category' => __( 'VamTam Modules', 'vamtam-elements-b' ),
  15. 'partial_refresh' => true,
  16. 'dir' => VAMTAMEL_B_DIR . $path,
  17. 'url' => VAMTAMEL_B_URL . $path,
  18. ));
  19. }
  20. /**
  21. * @method update
  22. * @param $settings {object}
  23. */
  24. public function update( $settings ) {
  25. // Cache the photo data.
  26. if ( ! empty( $settings->photo ) ) {
  27. $data = FLBuilderPhoto::get_attachment_data( $settings->photo );
  28. if ( $data ) {
  29. $settings->photo_data = $data;
  30. }
  31. }
  32. return $settings;
  33. }
  34. /**
  35. * @method delete
  36. */
  37. public function delete() {
  38. // Delete photo module cache.
  39. if ( $this->settings->image_type == 'photo' && ! empty( $this->settings->photo_src ) ) {
  40. $module_class = get_class( FLBuilderModel::$modules['photo'] );
  41. $photo_module = new $module_class();
  42. $photo_module->settings = new stdClass();
  43. $photo_module->settings->photo_source = 'library';
  44. $photo_module->settings->photo_src = $this->settings->photo_src;
  45. $photo_module->settings->crop = $this->settings->photo_crop;
  46. $photo_module->delete();
  47. }
  48. }
  49. /**
  50. * @method get_classname
  51. */
  52. public function get_classname() {
  53. $classname = 'fl-callout fl-callout-' . $this->settings->align;
  54. if ( $this->settings->image_type == 'photo' ) {
  55. $classname .= ' fl-callout-has-photo fl-callout-photo-' . $this->settings->photo_position;
  56. } elseif ( $this->settings->image_type == 'icon' ) {
  57. $classname .= ' fl-callout-has-icon fl-callout-icon-' . $this->settings->icon_position;
  58. }
  59. return $classname;
  60. }
  61. /**
  62. * @method render_title
  63. */
  64. public function render_title() {
  65. echo '<' . esc_html( $this->settings->title_tag ) . ' class="fl-callout-title">';
  66. $this->render_image( 'left-title' );
  67. echo '<span>';
  68. if ( ! empty( $this->settings->link ) ) {
  69. echo '<a href="' . esc_url( $this->settings->link ) . '" target="' . esc_attr( $this->settings->link_target ) . '" class="fl-callout-title-link">';
  70. }
  71. echo $this->settings->title; // xss ok
  72. if ( ! empty( $this->settings->link ) ) {
  73. echo '</a>';
  74. }
  75. echo '</span>';
  76. $this->render_image( 'right-title' );
  77. echo '</' . esc_html( $this->settings->title_tag ) . '>';
  78. }
  79. /**
  80. * @method render_text
  81. */
  82. public function render_text() {
  83. echo '<div class="fl-callout-text">' . $this->settings->text . '</div>'; // xss ok
  84. }
  85. /**
  86. * @method render_link
  87. */
  88. public function render_link() {
  89. if ( $this->settings->cta_type == 'link' ) {
  90. echo '<a href="' . esc_url( $this->settings->link ) . '" target="' . esc_attr( $this->settings->link_target ) . '" class="fl-callout-cta-link">' . $this->settings->cta_text . '</a>'; // xss ok
  91. }
  92. }
  93. public static function get_button_settings( $settings ) {
  94. return array(
  95. 'align' => '',
  96. 'color' => $settings->btn_color,
  97. 'hover_color' => $settings->btn_hover_color,
  98. 'font_size' => $settings->btn_font_size,
  99. 'icon' => $settings->btn_icon,
  100. 'icon_position' => $settings->btn_icon_position,
  101. 'link' => $settings->link,
  102. 'link_target' => $settings->link_target,
  103. 'padding' => $settings->btn_padding,
  104. 'layout_type' => $settings->btn_layout_type,
  105. 'text' => $settings->cta_text,
  106. 'width' => $settings->btn_width,
  107. );
  108. }
  109. /**
  110. * @method render_button
  111. */
  112. public function render_button() {
  113. if ( $this->settings->cta_type == 'button' ) {
  114. echo '<div class="fl-callout-button">';
  115. FLBuilder::render_module_html( 'vamtam-button', self::get_button_settings( $this->settings ) );
  116. echo '</div>';
  117. }
  118. }
  119. /**
  120. * @method render_image
  121. */
  122. public function render_image( $position ) {
  123. if ( $this->settings->image_type == 'photo' && $this->settings->photo_position == $position ) {
  124. if ( empty( $this->settings->photo ) ) {
  125. return;
  126. }
  127. $photo_data = FLBuilderPhoto::get_attachment_data( $this->settings->photo );
  128. if ( ! $photo_data ) {
  129. $photo_data = $this->settings->photo_data;
  130. }
  131. $photo_settings = array(
  132. 'align' => 'center',
  133. 'crop' => $this->settings->photo_crop,
  134. 'link_target' => $this->settings->link_target,
  135. 'link_type' => 'url',
  136. 'link_url' => $this->settings->link,
  137. 'photo' => $photo_data,
  138. 'photo_src' => $this->settings->photo_src,
  139. 'photo_source' => 'library',
  140. );
  141. echo '<div class="fl-callout-photo">';
  142. FLBuilder::render_module_html( 'photo', $photo_settings );
  143. echo '</div>';
  144. } elseif ( $this->settings->image_type == 'icon' && $this->settings->icon_position == $position ) {
  145. $icon_settings = array(
  146. 'bg_color' => $this->settings->icon_bg_color,
  147. 'bg_hover_color' => $this->settings->icon_bg_hover_color,
  148. 'color' => $this->settings->icon_color,
  149. 'exclude_wrapper' => true,
  150. 'hover_color' => $this->settings->icon_hover_color,
  151. 'icon' => $this->settings->icon,
  152. 'link' => $this->settings->link,
  153. 'link_target' => $this->settings->link_target,
  154. 'size' => $this->settings->icon_size,
  155. 'text' => '',
  156. );
  157. FLBuilder::render_module_html( 'vamtam-icon', $icon_settings );
  158. }
  159. }
  160. }
  161. /**
  162. * Register the module and its form settings.
  163. */
  164. FLBuilder::register_module('VamtamCalloutModule', array(
  165. 'general' => array(
  166. 'title' => __( 'General', 'vamtam-elements-b' ),
  167. 'sections' => array(
  168. 'title' => array(
  169. 'title' => '',
  170. 'fields' => array(
  171. 'title' => array(
  172. 'type' => 'text',
  173. 'label' => __( 'Heading', 'vamtam-elements-b' ),
  174. 'preview' => array(
  175. 'type' => 'text',
  176. 'selector' => '.fl-callout-title',
  177. ),
  178. ),
  179. ),
  180. ),
  181. 'text' => array(
  182. 'title' => __( 'Text', 'vamtam-elements-b' ),
  183. 'fields' => array(
  184. 'text' => array(
  185. 'type' => 'editor',
  186. 'label' => '',
  187. 'media_buttons' => false,
  188. 'preview' => array(
  189. 'type' => 'text',
  190. 'selector' => '.fl-callout-text',
  191. ),
  192. ),
  193. ),
  194. ),
  195. ),
  196. ),
  197. 'style' => array(
  198. 'title' => __( 'Style', 'vamtam-elements-b' ),
  199. 'sections' => array(
  200. 'overall_structure' => array(
  201. 'title' => __( 'Structure', 'vamtam-elements-b' ),
  202. 'fields' => array(
  203. 'align' => array(
  204. 'type' => 'select',
  205. 'label' => __( 'Overall Alignment', 'vamtam-elements-b' ),
  206. 'default' => 'left',
  207. 'options' => array(
  208. 'center' => __( 'Center', 'vamtam-elements-b' ),
  209. 'left' => __( 'Left', 'vamtam-elements-b' ),
  210. 'right' => __( 'Right', 'vamtam-elements-b' ),
  211. ),
  212. 'help' => __( 'The alignment that will apply to all elements within the callout.', 'vamtam-elements-b' ),
  213. 'preview' => array(
  214. 'type' => 'none',
  215. ),
  216. ),
  217. ),
  218. ),
  219. 'title_structure' => array(
  220. 'title' => __( 'Heading Structure', 'vamtam-elements-b' ),
  221. 'fields' => array(
  222. 'title_tag' => array(
  223. 'type' => 'select',
  224. 'label' => __( 'Heading Tag', 'vamtam-elements-b' ),
  225. 'default' => 'h3',
  226. 'options' => array(
  227. 'h1' => 'h1',
  228. 'h2' => 'h2',
  229. 'h3' => 'h3',
  230. 'h4' => 'h4',
  231. 'h5' => 'h5',
  232. 'h6' => 'h6',
  233. ),
  234. ),
  235. 'title_size' => array(
  236. 'type' => 'select',
  237. 'label' => __( 'Heading Size', 'vamtam-elements-b' ),
  238. 'default' => 'default',
  239. 'options' => array(
  240. 'default' => __( 'Default', 'vamtam-elements-b' ),
  241. 'custom' => __( 'Custom', 'vamtam-elements-b' ),
  242. ),
  243. 'toggle' => array(
  244. 'custom' => array(
  245. 'fields' => array( 'title_custom_size' ),
  246. ),
  247. ),
  248. ),
  249. 'title_custom_size' => array(
  250. 'type' => 'text',
  251. 'label' => __( 'Heading Custom Size', 'vamtam-elements-b' ),
  252. 'default' => '24',
  253. 'maxlength' => '3',
  254. 'size' => '4',
  255. 'description' => 'px',
  256. ),
  257. ),
  258. ),
  259. ),
  260. ),
  261. 'image' => array(
  262. 'title' => __( 'Image', 'vamtam-elements-b' ),
  263. 'sections' => array(
  264. 'general' => array(
  265. 'title' => '',
  266. 'fields' => array(
  267. 'image_type' => array(
  268. 'type' => 'select',
  269. 'label' => __( 'Image Type', 'vamtam-elements-b' ),
  270. 'default' => 'photo',
  271. 'options' => array(
  272. 'none' => _x( 'None', 'Image type.', 'vamtam-elements-b' ),
  273. 'photo' => __( 'Photo', 'vamtam-elements-b' ),
  274. 'icon' => __( 'Icon', 'vamtam-elements-b' ),
  275. ),
  276. 'toggle' => array(
  277. 'none' => array(),
  278. 'photo' => array(
  279. 'sections' => array( 'photo' ),
  280. ),
  281. 'icon' => array(
  282. 'sections' => array( 'icon', 'icon_colors', 'icon_structure' ),
  283. ),
  284. ),
  285. ),
  286. ),
  287. ),
  288. 'photo' => array(
  289. 'title' => __( 'Photo', 'vamtam-elements-b' ),
  290. 'fields' => array(
  291. 'photo' => array(
  292. 'type' => 'photo',
  293. 'label' => __( 'Photo', 'vamtam-elements-b' ),
  294. ),
  295. 'photo_crop' => array(
  296. 'type' => 'select',
  297. 'label' => __( 'Crop', 'vamtam-elements-b' ),
  298. 'default' => '',
  299. 'options' => array(
  300. '' => _x( 'None', 'Photo Crop.', 'vamtam-elements-b' ),
  301. 'landscape' => __( 'Landscape', 'vamtam-elements-b' ),
  302. 'panorama' => __( 'Panorama', 'vamtam-elements-b' ),
  303. 'portrait' => __( 'Portrait', 'vamtam-elements-b' ),
  304. 'square' => __( 'Square', 'vamtam-elements-b' ),
  305. 'circle' => __( 'Circle', 'vamtam-elements-b' ),
  306. ),
  307. ),
  308. 'photo_position' => array(
  309. 'type' => 'select',
  310. 'label' => __( 'Position', 'vamtam-elements-b' ),
  311. 'default' => 'above-title',
  312. 'options' => array(
  313. 'above-title' => __( 'Above Heading', 'vamtam-elements-b' ),
  314. 'below-title' => __( 'Below Heading', 'vamtam-elements-b' ),
  315. 'left' => __( 'Left of Text and Heading', 'vamtam-elements-b' ),
  316. 'right' => __( 'Right of Text and Heading', 'vamtam-elements-b' ),
  317. ),
  318. ),
  319. ),
  320. ),
  321. 'icon' => array(
  322. 'title' => __( 'Icon', 'vamtam-elements-b' ),
  323. 'fields' => array(
  324. 'icon' => array(
  325. 'type' => 'icon',
  326. 'label' => __( 'Icon', 'vamtam-elements-b' ),
  327. ),
  328. 'icon_position' => array(
  329. 'type' => 'select',
  330. 'label' => __( 'Position', 'vamtam-elements-b' ),
  331. 'default' => 'left-title',
  332. 'options' => array(
  333. 'above-title' => __( 'Above Heading', 'vamtam-elements-b' ),
  334. 'below-title' => __( 'Below Heading', 'vamtam-elements-b' ),
  335. 'left-title' => __( 'Left of Heading', 'vamtam-elements-b' ),
  336. 'right-title' => __( 'Right of Heading', 'vamtam-elements-b' ),
  337. 'left' => __( 'Left of Text and Heading', 'vamtam-elements-b' ),
  338. 'right' => __( 'Right of Text and Heading', 'vamtam-elements-b' ),
  339. ),
  340. ),
  341. ),
  342. ),
  343. 'icon_colors' => array(
  344. 'title' => __( 'Icon Colors', 'vamtam-elements-b' ),
  345. 'fields' => array(
  346. 'icon_color' => array(
  347. 'type' => 'vamtam-color',
  348. 'label' => __( 'Color', 'vamtam-elements-b' ),
  349. ),
  350. 'icon_hover_color' => array(
  351. 'type' => 'vamtam-color',
  352. 'label' => __( 'Hover Color', 'vamtam-elements-b' ),
  353. 'preview' => array(
  354. 'type' => 'none',
  355. ),
  356. ),
  357. 'icon_bg_color' => array(
  358. 'type' => 'vamtam-color',
  359. 'label' => __( 'Background Color', 'vamtam-elements-b' ),
  360. ),
  361. 'icon_bg_hover_color' => array(
  362. 'type' => 'vamtam-color',
  363. 'label' => __( 'Background Hover Color', 'vamtam-elements-b' ),
  364. 'preview' => array(
  365. 'type' => 'none',
  366. ),
  367. ),
  368. ),
  369. ),
  370. 'icon_structure' => array(
  371. 'title' => __( 'Icon Structure', 'vamtam-elements-b' ),
  372. 'fields' => array(
  373. 'icon_size' => array(
  374. 'type' => 'text',
  375. 'label' => __( 'Size', 'vamtam-elements-b' ),
  376. 'default' => '30',
  377. 'maxlength' => '3',
  378. 'size' => '4',
  379. 'description' => 'px',
  380. ),
  381. ),
  382. ),
  383. ),
  384. ),
  385. 'cta' => array(
  386. 'title' => __( 'Call To Action', 'vamtam-elements-b' ),
  387. 'sections' => array(
  388. 'link' => array(
  389. 'title' => __( 'Link', 'vamtam-elements-b' ),
  390. 'fields' => array(
  391. 'link' => array(
  392. 'type' => 'link',
  393. 'label' => __( 'Link', 'vamtam-elements-b' ),
  394. 'help' => __( 'The link applies to the entire module. If choosing a call to action type below, this link will also be used for the text or button.', 'vamtam-elements-b' ),
  395. 'preview' => array(
  396. 'type' => 'none',
  397. ),
  398. ),
  399. 'link_target' => array(
  400. 'type' => 'select',
  401. 'label' => __( 'Link Target', 'vamtam-elements-b' ),
  402. 'default' => '_self',
  403. 'options' => array(
  404. '_self' => __( 'Same Window', 'vamtam-elements-b' ),
  405. '_blank' => __( 'New Window', 'vamtam-elements-b' ),
  406. ),
  407. 'preview' => array(
  408. 'type' => 'none',
  409. ),
  410. ),
  411. ),
  412. ),
  413. 'cta' => array(
  414. 'title' => __( 'Call to Action', 'vamtam-elements-b' ),
  415. 'fields' => array(
  416. 'cta_type' => array(
  417. 'type' => 'select',
  418. 'label' => __( 'Type', 'vamtam-elements-b' ),
  419. 'default' => 'none',
  420. 'options' => array(
  421. 'none' => _x( 'None', 'Call to action.', 'vamtam-elements-b' ),
  422. 'link' => __( 'Text', 'vamtam-elements-b' ),
  423. 'button' => __( 'Button', 'vamtam-elements-b' ),
  424. ),
  425. 'toggle' => array(
  426. 'none' => array(),
  427. 'link' => array(
  428. 'fields' => array( 'cta_text' ),
  429. ),
  430. 'button' => array(
  431. 'fields' => array( 'cta_text', 'btn_icon', 'btn_icon_position' ),
  432. 'sections' => array( 'btn_style', 'btn_colors', 'btn_structure' ),
  433. ),
  434. ),
  435. ),
  436. 'cta_text' => array(
  437. 'type' => 'text',
  438. 'label' => __( 'Text', 'vamtam-elements-b' ),
  439. 'default' => __( 'Read More', 'vamtam-elements-b' ),
  440. ),
  441. 'btn_icon' => array(
  442. 'type' => 'icon',
  443. 'label' => __( 'Button Icon', 'vamtam-elements-b' ),
  444. 'show_remove' => true,
  445. ),
  446. 'btn_icon_position' => array(
  447. 'type' => 'select',
  448. 'label' => __( 'Button Icon Position', 'vamtam-elements-b' ),
  449. 'default' => 'before',
  450. 'options' => array(
  451. 'before' => __( 'Before Text', 'vamtam-elements-b' ),
  452. 'after' => __( 'After Text', 'vamtam-elements-b' ),
  453. ),
  454. ),
  455. ),
  456. ),
  457. 'btn_colors' => array(
  458. 'title' => __( 'Button Colors', 'vamtam-elements-b' ),
  459. 'fields' => array(
  460. 'btn_color' => array(
  461. 'type' => 'select',
  462. 'label' => __( 'Normal Color', 'vamtam-elements-b' ),
  463. 'default' => 'accent1',
  464. 'options' => array(
  465. 'accent1' => esc_html__( 'Accent 1', 'vamtam-elements-b' ),
  466. 'accent2' => esc_html__( 'Accent 2', 'vamtam-elements-b' ),
  467. 'accent3' => esc_html__( 'Accent 3', 'vamtam-elements-b' ),
  468. 'accent4' => esc_html__( 'Accent 4', 'vamtam-elements-b' ),
  469. 'accent5' => esc_html__( 'Accent 5', 'vamtam-elements-b' ),
  470. 'accent6' => esc_html__( 'Accent 6', 'vamtam-elements-b' ),
  471. 'accent7' => esc_html__( 'Accent 7', 'vamtam-elements-b' ),
  472. 'accent8' => esc_html__( 'Accent 8', 'vamtam-elements-b' ),
  473. ),
  474. ),
  475. 'btn_hover_color' => array(
  476. 'type' => 'select',
  477. 'label' => __( 'Hover Color', 'vamtam-elements-b' ),
  478. 'default' => 'accent2',
  479. 'options' => array(
  480. 'accent1' => esc_html__( 'Accent 1', 'vamtam-elements-b' ),
  481. 'accent2' => esc_html__( 'Accent 2', 'vamtam-elements-b' ),
  482. 'accent3' => esc_html__( 'Accent 3', 'vamtam-elements-b' ),
  483. 'accent4' => esc_html__( 'Accent 4', 'vamtam-elements-b' ),
  484. 'accent5' => esc_html__( 'Accent 5', 'vamtam-elements-b' ),
  485. 'accent6' => esc_html__( 'Accent 6', 'vamtam-elements-b' ),
  486. 'accent7' => esc_html__( 'Accent 7', 'vamtam-elements-b' ),
  487. 'accent8' => esc_html__( 'Accent 8', 'vamtam-elements-b' ),
  488. ),
  489. ),
  490. ),
  491. ),
  492. 'btn_style' => array(
  493. 'title' => __( 'Button Style', 'vamtam-elements-b' ),
  494. 'fields' => array(
  495. 'btn_layout_type' => array(
  496. 'type' => 'select',
  497. 'label' => __( 'Button Type', 'vamtam-elements-b' ),
  498. 'default' => 'solid',
  499. 'options' => array(
  500. 'solid' => esc_html__( 'Solid', 'vamtam-elements-b' ),
  501. 'border' => esc_html__( 'Border', 'vamtam-elements-b' ),
  502. 'underline' => esc_html__( 'Underline', 'vamtam-elements-b' ),
  503. ),
  504. ),
  505. ),
  506. ),
  507. 'btn_structure' => array(
  508. 'title' => __( 'Button Structure', 'vamtam-elements-b' ),
  509. 'fields' => array(
  510. 'btn_width' => array(
  511. 'type' => 'select',
  512. 'label' => __( 'Button Width', 'vamtam-elements-b' ),
  513. 'default' => 'auto',
  514. 'options' => array(
  515. 'auto' => _x( 'Auto', 'Width.', 'vamtam-elements-b' ),
  516. 'full' => __( 'Full Width', 'vamtam-elements-b' ),
  517. ),
  518. ),
  519. 'btn_font_size' => array(
  520. 'type' => 'text',
  521. 'label' => __( 'Font Size', 'vamtam-elements-b' ),
  522. 'default' => '14',
  523. 'maxlength' => '3',
  524. 'size' => '4',
  525. 'description' => 'px',
  526. ),
  527. 'btn_padding' => array(
  528. 'type' => 'text',
  529. 'label' => __( 'Padding', 'vamtam-elements-b' ),
  530. 'default' => '10',
  531. 'maxlength' => '3',
  532. 'size' => '4',
  533. 'description' => 'px',
  534. ),
  535. ),
  536. ),
  537. ),
  538. ),
  539. ));