vamtam-elements.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. <?php
  2. /**
  3. * Plugin Name: VamTam Elements (B)
  4. * Plugin URI: http://vamtam.com
  5. * Description: Drag&Drop elements and shortcodes used in VamTam themes (requires Beaver Builder)
  6. * Version: 1.8.0
  7. * Author: Vamtam
  8. * Author URI: http://vamtam.com
  9. */
  10. define( 'VAMTAMEL_B_DIR', plugin_dir_path( __FILE__ ) );
  11. define( 'VAMTAMEL_B_URL', plugins_url( '/', __FILE__ ) );
  12. class Vamtam_Elements_B {
  13. public static $dir;
  14. public static $url;
  15. public static $lightboxes = array();
  16. public static function setup() {
  17. if ( ! class_exists( 'Vamtam_Updates_2' ) ) {
  18. require 'vamtam-updates/class-vamtam-updates.php';
  19. }
  20. new Vamtam_Updates_2( __FILE__ );
  21. // enable shortcodes in widgets
  22. add_filter( 'widget_text', 'do_shortcode' );
  23. add_filter( 'widget_title', 'do_shortcode' );
  24. // Beaver integration
  25. if ( ! class_exists( 'FLBuilderModel' ) ) {
  26. return;
  27. }
  28. add_action( 'init', array( __CLASS__, 'init' ) );
  29. add_action( 'wp_head', array( __CLASS__, 'limit_wrapper' ) );
  30. add_action( 'admin_menu', array( __CLASS__, 'admin_menu' ), 100 );
  31. add_action( 'admin_init', array( __CLASS__, 'admin_init' ) );
  32. // show premium buttons
  33. add_filter( 'fl_builder_ui_bar_buttons', array( __CLASS__, 'fl_builder_ui_bar_buttons' ) );
  34. add_filter( 'fl_builder_ui_js_config', array( __CLASS__, 'fl_builder_ui_js_config' ) );
  35. // remove row_width global option
  36. add_filter( 'option__fl_builder_settings', array( __CLASS__, 'option__fl_builder_settings' ) );
  37. add_filter( 'fl_builder_settings_form_defaults', array( __CLASS__, 'option__fl_builder_settings' ) );
  38. add_filter( 'fl_builder_register_settings_form', array( __CLASS__, 'fl_builder_register_settings_form' ), 10, 2 );
  39. // builder CSS
  40. add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ), 100 );
  41. add_action( 'wp_enqueue_scripts', array( __CLASS__, 'early_enqueue_scripts' ), 5 );
  42. // remove "upgrade" screen
  43. add_filter( 'fl_builder_admin_settings_nav_items', array( __CLASS__, 'fl_builder_admin_settings_nav_items' ) );
  44. add_filter( 'fl_builder_content_panel_data', array( __CLASS__, 'fl_builder_content_panel_data' ) );
  45. // no "premium" select options
  46. add_filter( 'fl_builder_render_settings_field', array( __CLASS__, 'fl_builder_render_settings_field' ), 10, 3 );
  47. // reenable the icon manager
  48. add_action( 'fl_builder_admin_settings_render_forms', array( __CLASS__, 'icon_font_manager' ) );
  49. // disable some built-in modules
  50. add_filter( 'fl_builder_register_module', array( __CLASS__, 'fl_builder_register_module' ), 10, 2 );
  51. // override node attributes
  52. add_filter( 'fl_builder_module_attributes', array( __CLASS__, 'fl_builder_module_attributes' ), 10, 2 );
  53. // built-in module overrides
  54. add_filter( 'fl_builder_module_frontend_file', array( __CLASS__, 'fl_builder_module_frontend_file' ), 10, 2 );
  55. // override column attributes
  56. add_filter( 'fl_builder_column_attributes', array( __CLASS__, 'fl_builder_column_attributes' ), 10, 2 );
  57. // Templates CPT arguments
  58. add_filter( 'fl_builder_register_template_post_type_args', array( __CLASS__, 'fl_builder_register_template_post_type_args' ) );
  59. // Some main menu items are disabled, enable them if we provide an alternative
  60. add_filter( 'fl_builder_main_menu', array( __CLASS__, 'fl_builder_main_menu' ) );
  61. add_filter( 'fl_builder_keyboard_shortcuts', array( __CLASS__, 'fl_builder_keyboard_shortcuts' ) );
  62. // custom icons
  63. add_filter( 'fl_builder_icon_sets', array( __CLASS__, 'fl_builder_icon_sets' ) );
  64. add_filter( 'fl_builder_enqueue_custom_styles_by_key', array( __CLASS__, 'fl_builder_enqueue_custom_styles_by_key' ), 10, 2 );
  65. // custom fields
  66. add_filter( 'fl_builder_custom_fields', array( __CLASS__, 'fl_builder_custom_fields' ) );
  67. if ( ! defined( 'VAMTAM_EL_DEFAULT_BRANDING') || ! VAMTAM_EL_DEFAULT_BRANDING ) {
  68. include_once VAMTAMEL_B_DIR . 'classes/white-label.php';
  69. }
  70. if ( ! class_exists( 'FLBuilderTemplateDataExporter' ) ) {
  71. include_once VAMTAMEL_B_DIR . 'classes/extensions.php';
  72. }
  73. include_once VAMTAMEL_B_DIR . 'helpers.php';
  74. $templates_path = VAMTAMEL_B_DIR . 'data/templates.dat';
  75. if ( file_exists( $templates_path ) ) {
  76. FLBuilderModel::register_templates( $templates_path );
  77. }
  78. }
  79. public static function is_beaver_used() {
  80. return class_exists( 'FLBuilderModel' ) && FLBuilderModel::is_builder_enabled() && ! is_archive();
  81. }
  82. public static function limit_wrapper() {
  83. global $vamtam_has_header_sidebars, $vamtam_theme;
  84. $GLOBALS['vamtam_had_limit_wrapper'] =
  85. (
  86. ( ! function_exists( 'rd_vamtam_get_optionb' ) || rd_vamtam_get_optionb( 'boxed-layout-padding' ) ) &&
  87. isset( $vamtam_theme['site-layout-type'] ) && 'full' !== $vamtam_theme['site-layout-type']
  88. ) ||
  89. ! is_singular() ||
  90. ( class_exists( 'VamtamTemplates' ) && VamtamTemplates::get_layout() !== 'full' ) ||
  91. $vamtam_has_header_sidebars ||
  92. ! self::is_beaver_used();
  93. }
  94. public static function had_limit_wrapper() {
  95. return apply_filters( 'vamtam_had_limit_wrapper', isset( $GLOBALS['vamtam_had_limit_wrapper'] ) && $GLOBALS['vamtam_had_limit_wrapper'] );
  96. }
  97. /**
  98. * Register modules and fields
  99. */
  100. public static function init() {
  101. // regular shortcodes
  102. include VAMTAMEL_B_DIR . 'shortcodes/gallery.php';
  103. include VAMTAMEL_B_DIR . 'shortcodes/icons-list.php';
  104. // Beaver modules
  105. if ( class_exists( 'FLBuilder' ) ) {
  106. $modules = glob( VAMTAMEL_B_DIR . 'modules/*', GLOB_ONLYDIR );
  107. $modules = apply_filters( 'vamtam_elements_beaver_supported', array_map( 'basename', $modules ) );
  108. if ( is_array( $modules ) ) {
  109. foreach ( $modules as $module ) {
  110. $path = VAMTAMEL_B_DIR . 'modules/' . trailingslashit( $module ) . $module . '.php';
  111. if ( file_exists( $path ) ) {
  112. require_once $path;
  113. }
  114. }
  115. }
  116. }
  117. }
  118. public static function admin_init() {
  119. $beaver_settings = FLBuilderUserAccess::get_saved_settings();
  120. foreach ( $beaver_settings as $category => $capabilities ) {
  121. // if all capabilities are set to false
  122. if ( count( array_unique( $capabilities ) ) === 1 && ! current( $capabilities ) ) {
  123. // reset capabilities to "all", which is the default
  124. foreach ( $beaver_settings[ $category ] as $role => $enabled ) {
  125. $beaver_settings[ $category ][ $role ] = true;
  126. }
  127. }
  128. }
  129. FLBuilderUserAccess::save_settings( $beaver_settings );
  130. }
  131. /**
  132. * Register custom setting fields
  133. * @param array $custom
  134. * @return array
  135. */
  136. public static function fl_builder_custom_fields( $custom ) {
  137. // Custom Beaver fields
  138. $fields = glob( VAMTAMEL_B_DIR . 'fields/*.php' );
  139. $fields = apply_filters( 'vamtam_elements_beaver_fields', $fields );
  140. $custom = array();
  141. if ( is_array( $fields ) ) {
  142. foreach ( $fields as $field_path ) {
  143. $custom[ basename( $field_path, '.php' ) ] = $field_path;
  144. }
  145. }
  146. return $custom;
  147. }
  148. /**
  149. * Move the "VamTam Builder" admin page under "Appearance"
  150. */
  151. public static function admin_menu() {
  152. global $submenu;
  153. if ( current_user_can( 'delete_users' ) ) {
  154. foreach ( $submenu as $li => $submenu_list ) {
  155. foreach ( $submenu_list as $si => $submenu_item ) {
  156. if ( isset( $submenu_item[2] ) && $submenu_item[2] === 'fl-builder-settings' ) {
  157. unset( $submenu[ $li ][ $si ] );
  158. break;
  159. }
  160. }
  161. }
  162. $title = FLBuilderModel::get_branding();
  163. add_submenu_page( 'edit.php?post_type=fl-builder-template', $title, esc_html__( 'Settings', 'vamtam-elements-b' ), 'delete_users', 'fl-builder-settings', array( 'FLBuilderAdminSettings', 'render' ) );
  164. }
  165. }
  166. /**
  167. * Modify Beaver top UI bar
  168. */
  169. public static function fl_builder_ui_bar_buttons( $bar ) {
  170. unset( $bar['upgrade'] );
  171. unset( $bar['buy'] );
  172. return $bar;
  173. }
  174. /**
  175. * Modify Beaver JS config
  176. */
  177. public static function fl_builder_ui_js_config( $config ) {
  178. $config['lite'] = false;
  179. return $config;
  180. }
  181. /**
  182. * Modify global settings
  183. */
  184. public static function option__fl_builder_settings( $value ) {
  185. global $vamtam_theme;
  186. if ( isset( $vamtam_theme['site-max-width'] ) ) {
  187. if ( is_array( $value ) && isset( $value['module_margins'] ) ) {
  188. $value['row_width'] = $vamtam_theme['site-max-width'] + 2 * $value['module_margins'];
  189. }
  190. if ( is_object( $value ) && isset( $value->module_margins ) ) {
  191. $value->row_width = $vamtam_theme['site-max-width'] + 2 * $value->module_margins;
  192. }
  193. }
  194. if ( is_array( $value ) ) {
  195. $value['show_default_heading'] = '0';
  196. if ( ! isset( $value['css'] ) ) {
  197. $value['css'] = '';
  198. }
  199. if ( ! isset( $value['js'] ) ) {
  200. $value['js'] = '';
  201. }
  202. }
  203. if ( is_object( $value ) ) {
  204. $value->show_default_heading = '0';
  205. if ( ! isset( $value->css ) ) {
  206. $value->css = '';
  207. }
  208. if ( ! isset( $value->js ) ) {
  209. $value->js = '';
  210. }
  211. }
  212. return $value;
  213. }
  214. /**
  215. * Modify global settings form
  216. */
  217. public static function fl_builder_register_settings_form( $form, $id ) {
  218. if ( 'global' === $id ) {
  219. // remove row_width option
  220. unset( $form['tabs']['general']['sections']['rows']['fields']['row_width'] );
  221. // remove page_heading section
  222. unset( $form['tabs']['general']['sections']['page_heading'] );
  223. // remove css and js tabs
  224. unset( $form['tabs']['css'] );
  225. unset( $form['tabs']['js'] );
  226. } elseif ( 'row' === $id ) {
  227. unset( $form['tabs']['style']['sections']['background']['fields']['bg_type']['options']['slideshow'] );
  228. } elseif ( 'col' === $id || 'module_advanced' === $id ) {
  229. $animation_options = array(
  230. 'vamtam_animation_style' => array(
  231. 'type' => 'select',
  232. 'label' => esc_html__( 'Style', 'vamtam-elements-b' ),
  233. 'default' => '',
  234. 'preview' => array(
  235. 'type' => 'none',
  236. ),
  237. 'options' => array(
  238. '' => esc_html_x( 'None', 'Animation style.', 'vamtam-elements-b' ),
  239. 'dummy' => esc_html_x( 'Pin only, no other animations', 'Animation style.', 'vamtam-elements-b' ),
  240. 'rotate' => esc_html_x( 'Rotate 360°', 'Animation style.', 'vamtam-elements-b' ),
  241. 'fade' => esc_html_x( 'Fade In', 'Animation style.', 'vamtam-elements-b' ),
  242. 'move-scale-in-from-top' => esc_html_x( 'Move with Scale (Zoom In) - Top', 'Animation style.', 'vamtam-elements-b' ),
  243. 'move-scale-in-from-bottom' => esc_html_x( 'Move with Scale (Zoom In) - Bottom', 'Animation style.', 'vamtam-elements-b' ),
  244. 'move-scale-in-from-left' => esc_html_x( 'Move with Scale (Zoom In) - Left', 'Animation style.', 'vamtam-elements-b' ),
  245. 'move-scale-in-from-right' => esc_html_x( 'Move with Scale (Zoom In) - Right', 'Animation style.', 'vamtam-elements-b' ),
  246. 'move-scale-out-from-top' => esc_html_x( 'Move with Scale (Zoom Out) - Top', 'Animation style.', 'vamtam-elements-b' ),
  247. 'move-scale-out-from-bottom' => esc_html_x( 'Move with Scale (Zoom Out) - Bottom', 'Animation style.', 'vamtam-elements-b' ),
  248. 'move-scale-out-from-left' => esc_html_x( 'Move with Scale (Zoom Out) - Left', 'Animation style.', 'vamtam-elements-b' ),
  249. 'move-scale-out-from-right' => esc_html_x( 'Move with Scale (Zoom Out) - Right', 'Animation style.', 'vamtam-elements-b' ),
  250. 'move-from-top' => esc_html_x( 'Move from Top', 'Animation style.', 'vamtam-elements-b' ),
  251. 'move-from-bottom' => esc_html_x( 'Move from Bottom', 'Animation style.', 'vamtam-elements-b' ),
  252. 'move-from-left' => esc_html_x( 'Move from Left', 'Animation style.', 'vamtam-elements-b' ),
  253. 'move-from-right' => esc_html_x( 'Move from Right', 'Animation style.', 'vamtam-elements-b' ),
  254. 'scale-in' => esc_html_x( 'Scale In', 'Animation style.', 'vamtam-elements-b' ),
  255. 'scale-out' => esc_html_x( 'Scale Out', 'Animation style.', 'vamtam-elements-b' ),
  256. ),
  257. ),
  258. 'vamtam_animation_type' => array(
  259. 'type' => 'select',
  260. 'label' => esc_html__( 'Type', 'vamtam-elements-b' ),
  261. 'default' => 'progressive',
  262. 'preview' => array(
  263. 'type' => 'none',
  264. ),
  265. 'options' => array(
  266. 'immediate' => esc_html__( 'Immediate', 'vamtam-elements-b' ),
  267. 'progressive' => esc_html__( 'Progressive', 'vamtam-elements-b' ),
  268. ),
  269. 'toggle' => array(
  270. 'progressive' => array(
  271. 'fields' => array( 'vamtam_animation_exit', 'vamtam_animation_pin' ),
  272. ),
  273. ),
  274. ),
  275. 'vamtam_animation_exit' => array(
  276. 'type' => 'select',
  277. 'label' => esc_html__( 'Exit Animation', 'vamtam-elements-b' ),
  278. 'default' => 'true',
  279. 'preview' => array(
  280. 'type' => 'none',
  281. ),
  282. 'options' => array(
  283. '1' => esc_html__( 'Enabled', 'vamtam-elements-b' ),
  284. '0' => esc_html__( 'Disabled', 'vamtam-elements-b' ),
  285. ),
  286. ),
  287. 'vamtam_animation_delay' => array(
  288. 'type' => 'unit',
  289. 'label' => esc_html__( 'Animation Delay', 'vamtam-elements-b' ),
  290. 'help' => esc_html__( 'Entry and exit animamations have a duration of 2. An entry-only animation has a duration of 1. The animation progresses from -1 (bottom of screen), to 0 (middle of screen), to 1 (top of screen). For example, if you want to make it so that 50% animation progress happens in the bottom 75% of the screen (as opposed to the middle), you can set a delay of -0.5.', 'vamtam-elements-b' ),
  291. 'default' => '0',
  292. 'preview' => array(
  293. 'type' => 'none',
  294. ),
  295. 'min' => -1,
  296. 'max' => 1,
  297. 'step' => 0.01,
  298. ),
  299. 'vamtam_animation_origin' => array(
  300. 'type' => 'text',
  301. 'label' => esc_html__( 'Transform Origin', 'vamtam-elements-b' ),
  302. 'default' => 'center center',
  303. 'preview' => array(
  304. 'type' => 'none',
  305. ),
  306. ),
  307. 'vamtam_animation_mobile' => array(
  308. 'type' => 'select',
  309. 'label' => esc_html__( 'Animate on Narrow Screens', 'vamtam-elements-b' ),
  310. 'default' => '0',
  311. 'preview' => array(
  312. 'type' => 'none',
  313. ),
  314. 'options' => array(
  315. '1' => esc_html__( 'Enabled', 'vamtam-elements-b' ),
  316. '0' => esc_html__( 'Disabled', 'vamtam-elements-b' ),
  317. ),
  318. ),
  319. );
  320. if ( current_theme_supports( 'vamtam-scroll-pinning' ) ) {
  321. $animation_options = array_merge( $animation_options, array(
  322. 'vamtam_animation_pin' => array(
  323. 'type' => 'select',
  324. 'label' => esc_html__( 'Pin', 'vamtam-elements-b' ),
  325. 'default' => '0',
  326. 'preview' => array(
  327. 'type' => 'none',
  328. ),
  329. 'options' => array(
  330. '0' => esc_html__( 'Disabled', 'vamtam-elements-b' ),
  331. 'parent' => esc_html__( 'Within Parent Row', 'vamtam-elements-b' ),
  332. 'fixed' => esc_html__( 'Fixed Height (px)', 'vamtam-elements-b' ),
  333. ),
  334. 'toggle' => array(
  335. 'fixed' => array(
  336. 'fields' => array( 'vamtam_animation_pin_duration', 'vamtam_animation_pin_trigger' ),
  337. ),
  338. 'parent' => array(
  339. 'fields' => array( 'vamtam_animation_pin_trigger' ),
  340. ),
  341. ),
  342. ),
  343. 'vamtam_animation_pin_duration' => array(
  344. 'type' => 'unit',
  345. 'label' => esc_html__( 'Pin', 'vamtam-elements-b' ),
  346. 'default' => 300,
  347. 'preview' => array(
  348. 'type' => 'none',
  349. ),
  350. ),
  351. 'vamtam_animation_pin_trigger' => array(
  352. 'type' => 'select',
  353. 'label' => esc_html__( 'Pin Trigger', 'vamtam-elements-b' ),
  354. 'help' => esc_html__( 'Pinning will begin when the top/center/bottom of the element aligns with the top/center/bottom of the viewport.', 'vamtam-elements-b' ),
  355. 'default' => 'center',
  356. 'preview' => array(
  357. 'type' => 'none',
  358. ),
  359. 'options' => array(
  360. 'top' => esc_html__( 'Top', 'vamtam-elements-b' ),
  361. 'center' => esc_html__( 'Center', 'vamtam-elements-b' ),
  362. 'bottom' => esc_html__( 'Bottom', 'vamtam-elements-b' ),
  363. ),
  364. ),
  365. ) );
  366. }
  367. if ( 'module_advanced' === $id ) {
  368. unset( $form['sections']['animation']['fields']['animation'] );
  369. $form['sections']['animation']['fields']['animation_delay']['row_class'] = 'hidden';
  370. $form['sections']['animation']['fields'] = array_merge( $form['sections']['animation']['fields'], $animation_options );
  371. } else {
  372. $form['tabs']['advanced']['sections']['animation'] = array(
  373. 'title' => esc_html__( 'Animation', 'fl-builder' ),
  374. 'fields' => $animation_options,
  375. );
  376. }
  377. } elseif ( 'photo' === $id ) {
  378. $form['general']['sections']['general']['fields']['vamtam_sizes_attr'] = array(
  379. 'type' => 'select',
  380. 'default' => 'beaver',
  381. 'label' => esc_html__( 'Visible Size', 'fl-builder' ),
  382. 'help' => esc_html__( 'Setting this option will improve load times for your site. Use it to make the browser download an image which is not larger than actually needed. If set to "As generated by WP Core", the browser will download the largest image size available.', 'vamtam-elements-b' ),
  383. 'description' => esc_html__( 'Choose "Based on parent column size" if the image expands to the full width of the parent column/row', 'vamtam-elements-b' ),
  384. 'preview' => array(
  385. 'type' => 'none',
  386. ),
  387. 'options' => array(
  388. 'default' => esc_html__( 'As generated by WP Core', 'vamtam-elements-b' ),
  389. 'beaver' => esc_html__( 'Based on parent column size', 'vamtam-elements-b' ),
  390. 'custom' => esc_html__( 'Custom value', 'vamtam-elements-b' ),
  391. ),
  392. 'toggle' => array(
  393. 'custom' => array(
  394. 'fields' => array( 'vamtam_sizes_attr_custom' ),
  395. ),
  396. ),
  397. );
  398. $form['general']['sections']['general']['fields']['vamtam_sizes_attr_custom'] = array(
  399. 'type' => 'text',
  400. 'default' => '',
  401. 'label' => esc_html__( 'Custom sizes="" attribute value', 'fl-builder' ),
  402. );
  403. }
  404. return $form;
  405. }
  406. /**
  407. * Enqueue scripts and styles - lower priority
  408. */
  409. public static function early_enqueue_scripts() {
  410. wp_register_script( 'intersection-observer', VAMTAMEL_B_URL . 'assets/intersection-observer.js', array(), false, true );
  411. wp_register_script( 'vamtam-fl-subscribe-form', VAMTAMEL_B_URL . 'assets/fl-subscribe-form.js', array( 'jquery-core' ), false, true );
  412. }
  413. /**
  414. * Enqueue scripts and styles
  415. */
  416. public static function enqueue_scripts() {
  417. if ( FLBuilderModel::is_builder_active() ) {
  418. global $vamtam_theme;
  419. wp_enqueue_style( 'vamtam-elements-editor-styles', VAMTAMEL_B_URL . 'assets/builder.css', array( 'fl-builder-min' ), '1.0.0' );
  420. wp_enqueue_style( 'vamtam-elements-color-picker', VAMTAMEL_B_URL . 'assets/color-picker.css', array(), '1.0.0' );
  421. // color picker
  422. wp_enqueue_script( 'vamtam-elements-color-picker', VAMTAMEL_B_URL . 'assets/color-picker.js', array( 'jquery-core' ), '1.0.0', true );
  423. wp_localize_script( 'vamtam-elements-color-picker', 'VamtamColorPickerStrings', array(
  424. 'colorPresetsAccents' => esc_html__( 'Color Presets and Accents', 'vamtam-elements-b' ),
  425. 'accentsTitle' => esc_html__( 'Accent Colors', 'vamtam-elements-b' ),
  426. 'accents' => isset( $vamtam_theme[ 'accent-color' ] ) ? $vamtam_theme[ 'accent-color' ] : array(),
  427. ) );
  428. }
  429. wp_dequeue_script( 'jquery-waypoints' );
  430. }
  431. /**
  432. * Modify admin settings
  433. */
  434. public static function fl_builder_admin_settings_nav_items( $items ) {
  435. unset( $items['upgrade'] );
  436. $items['icons']['show'] = true;
  437. return $items;
  438. }
  439. /**
  440. * Beaver moved the icon manager to Beaver Pro, provide an alternative
  441. */
  442. public static function icon_font_manager() {
  443. include VAMTAMEL_B_DIR . 'includes/admin-settings-icons.php';
  444. }
  445. /**
  446. * Remove "premium" attribute of select fields' options
  447. */
  448. public static function fl_builder_render_settings_field( $field, $name, $settings ) {
  449. if ( 'select' === $field['type'] ) {
  450. foreach ( (array) $field['options'] as $option_key => $option_val ) {
  451. // regular options
  452. if ( is_array( $option_val ) && isset( $option_val['premium'] ) ) {
  453. unset( $field['options'][ $option_key ]['premium'] );
  454. }
  455. // option groups
  456. if ( is_array( $option_val ) && isset( $option_val['label'] ) && isset( $option_val['options'] ) ) {
  457. foreach ( (array) $option_val['options'] as $optgroup_option_key => $optgroup_option_val ) {
  458. if ( is_array( $optgroup_option_val ) && isset( $optgroup_option_val['premium'] ) ) {
  459. unset( $field['options'][ $option_key ]['options'][ $optgroup_option_key ]['premium'] );
  460. }
  461. }
  462. }
  463. }
  464. }
  465. return $field;
  466. }
  467. /**
  468. * Disable some built-in Beaver modules
  469. */
  470. public static function fl_builder_register_module( $enabled, $instance ) {
  471. if ( in_array( $instance->slug, array( 'sidebar' ), true ) ) {
  472. $enabled = false;
  473. }
  474. return $enabled;
  475. }
  476. /**
  477. * Add animation attributes to an object
  478. * @param array $attrs original attributes
  479. * @param object $settings object (module, column, etc.) settings
  480. * @return array modified attributes
  481. */
  482. private static function animation_attributes( $attrs, $settings ) {
  483. if ( isset( $attrs['data-animation-delay'] ) ) {
  484. unset( $attrs['data-animation-delay'] );
  485. // clear original class
  486. foreach ( $attrs['class'] as &$class ) {
  487. if ( strpos( $class, 'fl-animation' ) !== false ) {
  488. $class = '';
  489. }
  490. }
  491. }
  492. // no animations for ajax requests
  493. if ( ! isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) || 'XMLHttpRequest' !== $_SERVER['HTTP_X_REQUESTED_WITH'] ) {
  494. if ( ! empty( $settings->vamtam_animation_style ) ) {
  495. $pin = false;
  496. $pinTrigger = '';
  497. if ( isset( $settings->vamtam_animation_pin ) && $settings->vamtam_animation_pin !== '0' ) {
  498. if ( $settings->vamtam_animation_pin === 'parent' ) {
  499. $pin = 'parent';
  500. } elseif ( $settings->vamtam_animation_pin === 'fixed' ) {
  501. $pin = (int) $settings->vamtam_animation_pin_duration;
  502. }
  503. $pinTrigger = $settings->vamtam_animation_pin_trigger;
  504. }
  505. $attrs['data-progressive-animation'] = $settings->vamtam_animation_style;
  506. $attrs['data-vamtam-animation-options'] = esc_attr( json_encode( array(
  507. 'type' => $settings->vamtam_animation_type,
  508. 'origin' => $settings->vamtam_animation_origin,
  509. 'exit' => (bool) $settings->vamtam_animation_exit,
  510. 'delay' => (float) $settings->vamtam_animation_delay,
  511. 'exit' => (bool) $settings->vamtam_animation_exit,
  512. 'mobile' => (bool) $settings->vamtam_animation_mobile,
  513. 'pin' => $pin,
  514. 'pinTrigger' => $pinTrigger,
  515. ) ) );
  516. }
  517. }
  518. return $attrs;
  519. }
  520. /**
  521. * Custom module attributes
  522. *
  523. * @param array $attrs original attributes
  524. * @param object $module module object
  525. * @return array new attributes
  526. */
  527. public static function fl_builder_module_attributes( $attrs, $module ) {
  528. $attrs = self::animation_attributes( $attrs, $module->settings );
  529. if ( $module->settings->type === 'vamtam-blog' ) {
  530. $attrs['class'][] = 'vamtam-blog-' . $module->settings->layout;
  531. }
  532. return $attrs;
  533. }
  534. /**
  535. * Override built-in module templates
  536. *
  537. * @param string $file
  538. * @param string $module
  539. */
  540. public static function fl_builder_module_frontend_file( $file, $module ) {
  541. $override = VAMTAMEL_B_DIR . 'built-in-modules/' . $module->settings->type . '/includes/frontend.php';
  542. if ( file_exists( $override ) ) {
  543. return $override;
  544. }
  545. return $file;
  546. }
  547. /**
  548. * Custom column attributes
  549. *
  550. * @param array $attrs original attributes
  551. * @param object $column column object
  552. * @return array new attributes
  553. */
  554. public static function fl_builder_column_attributes( $attrs, $column ) {
  555. $attrs = self::animation_attributes( $attrs, $column->settings );
  556. return $attrs;
  557. }
  558. /**
  559. * Templates CPT attributes
  560. * @param array $args
  561. * @return array
  562. */
  563. public static function fl_builder_register_template_post_type_args( $args ) {
  564. $args['labels']['menu_name'] = esc_html__( 'VamTam Builder', 'vamtam-elements-b' );
  565. return $args;
  566. }
  567. /**
  568. * Append more icon sets
  569. *
  570. * @param array $sets original core sets
  571. * @return array
  572. */
  573. public static function fl_builder_icon_sets( $sets ) {
  574. if ( defined( 'VAMTAM_ASSETS_DIR' ) ) {
  575. $icomoon_icons = array_keys( include VAMTAM_ASSETS_DIR . 'fonts/icons/list.php' );
  576. foreach ( $icomoon_icons as &$icon ) {
  577. $icon = 'vamtam-icomoon-' . $icon;
  578. }
  579. $sets['vamtam-icomoon'] = array(
  580. 'name' => 'IcoMoon',
  581. 'prefix' => '',
  582. 'type' => 'icomoon',
  583. 'stylesheet' => VAMTAM_ASSETS_URI . 'fonts/icons/style.css',
  584. 'icons' => $icomoon_icons,
  585. );
  586. $theme_icons = array_keys( include VAMTAM_ASSETS_DIR . 'fonts/theme-icons/list.php' );
  587. foreach ( $theme_icons as &$icon ) {
  588. $icon = 'vamtam-theme-' . $icon;
  589. }
  590. $sets['vamtam-theme'] = array(
  591. 'name' => 'VamTam (theme-specific)',
  592. 'prefix' => '',
  593. 'type' => 'icomoon',
  594. 'stylesheet' => VAMTAM_ASSETS_URI . 'fonts/theme-icons/style.css',
  595. 'icons' => $theme_icons,
  596. );
  597. }
  598. return $sets;
  599. }
  600. /**
  601. * Returns an array of slugs for all enabled icon sets.
  602. *
  603. * @since 1.4.6
  604. * @return array
  605. */
  606. public static function get_enabled_icons() {
  607. $value = FLBuilderModel::get_admin_settings_option( '_fl_builder_enabled_icons', true );
  608. return ! $value ? array( 'font-awesome', 'foundation-icons', 'dashicons', 'vamtam-icomoon', 'vamtam-theme' ) : $value;
  609. }
  610. public static function fl_builder_enqueue_custom_styles_by_key( $enqueue, $key ) {
  611. return $enqueue;
  612. }
  613. /**
  614. * Remove the "Update" prompt in the user templates dropdown
  615. * @param array $data
  616. * @return array
  617. */
  618. public static function fl_builder_content_panel_data( $data ) {
  619. if ( isset( $data['tabs']['templates']['views'][0]['handle'] ) && $data['tabs']['templates']['views'][0]['handle'] === 'standard' ) {
  620. unset( $data['tabs']['templates']['views'][0] );
  621. }
  622. return $data;
  623. }
  624. /**
  625. * Some main menu items are disabled, enable them if we provide an alternative
  626. * @param array $menu
  627. * @return array
  628. */
  629. public static function fl_builder_main_menu( $views ) {
  630. $is_user_template = FLBuilderModel::is_post_user_template();
  631. $enabled_templates = FLBuilderModel::get_enabled_templates();
  632. $key_shortcuts = FLBuilder::get_keyboard_shortcuts();
  633. if ( ! $is_user_template && ( 'enabled' == $enabled_templates || 'user' == $enabled_templates ) ) {
  634. $views['main']['items'][10] = array(
  635. 'label' => __( 'Save Template', 'fl-builder' ),
  636. 'type' => 'event',
  637. 'eventName' => 'saveTemplate',
  638. 'accessory' => $key_shortcuts['saveTemplate']['keyLabel'],
  639. );
  640. }
  641. return $views;
  642. }
  643. /**
  644. * Modify keyboard shortcuts
  645. * @param array $shortcuts
  646. * @return array
  647. */
  648. public static function fl_builder_keyboard_shortcuts( $shortcuts ) {
  649. $shortcuts['saveTemplate']['enabled'] = true;
  650. $shortcuts['showSearch']['enabled'] = true;
  651. return $shortcuts;
  652. }
  653. /**
  654. * Removed in 1.2.0, use FLBuilderLoop::query()
  655. */
  656. public static function query( $settings ) {
  657. return FLBuilderLoop::query( $settings );
  658. }
  659. /**
  660. * Used for lightbox-enabled modules
  661. */
  662. public static function enqueue_lightbox_template() {
  663. $hook = array( __CLASS__, 'print_lightbox_template' );
  664. $tag = 'print_footer_scripts';
  665. if ( ! has_action( $tag, $hook ) ) {
  666. add_action( $tag, $hook );
  667. }
  668. }
  669. public static function print_lightbox_template() {
  670. ?>
  671. <script type="text/html" id="vamtam-lightbox-template">
  672. <button class="vamtam-button-lightbox-close"><?php echo vamtam_get_icon_html( array( // xss ok
  673. 'name' => 'vamtam-theme-close-sample',
  674. ) ) ?></button>
  675. <div class="vamtam-button-lightbox-content">
  676. {{ lightbox_content }}
  677. </div>
  678. </script>
  679. <?php
  680. }
  681. }
  682. Vamtam_Elements_B::setup();