PageRenderTime 40ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/functions.php

https://gitlab.com/Magi1053/Extra
PHP | 1203 lines | 869 code | 236 blank | 98 comment | 171 complexity | 7303046b5e982aa233b5df9ae6bb19ec MD5 | raw file
  1. <?php
  2. // Prevent file from being loaded directly
  3. if ( ! defined( 'ABSPATH' ) ) {
  4. die( '-1' );
  5. }
  6. define( 'ET_TAXONOMY_META_OPTION_KEY', "et_taxonomy_meta" );
  7. require dirname( __FILE__ ) . '/widgets.php';
  8. if ( is_admin() ) {
  9. require dirname( __FILE__ ) . '/admin/admin.php';
  10. }
  11. function et_framework_setup() {
  12. if ( current_theme_supports( 'et-post-formats' ) ) {
  13. require dirname( __FILE__ ) . '/post-formats.php';
  14. }
  15. if ( is_admin() ) {
  16. if ( current_theme_supports( 'et-post-formats' ) ) {
  17. require dirname( __FILE__ ) . '/admin/post-formats.php';
  18. }
  19. }
  20. }
  21. add_action( 'after_setup_theme', 'et_framework_setup', 11 );
  22. function et_extra_get_framework_directory_uri() {
  23. $template_template_dir = get_template_directory_uri();
  24. $framework_dir = apply_filters( 'et_framework_directory', 'framework' );
  25. return esc_url( $template_template_dir . '/' . $framework_dir );
  26. }
  27. function et_load_scripts_styles(){
  28. $theme_version = et_get_theme_version();
  29. $framework_template_dir = et_extra_get_framework_directory_uri();
  30. $suffix = SCRIPT_DEBUG ? '.js' : '.min.js';
  31. wp_register_script( 'hashchange', $framework_template_dir . '/scripts/ext/jquery.hashchange' . $suffix, array( 'jquery' ), $theme_version, true );
  32. wp_register_script( 'hash-persistance', $framework_template_dir . '/scripts/jquery.hash-persistance' . $suffix, array( 'jquery', 'hashchange' ), $theme_version, true );
  33. }
  34. add_action( 'wp_enqueue_scripts', 'et_load_scripts_styles' );
  35. /**
  36. * Get Theme Version
  37. */
  38. if ( ! function_exists( 'et_get_theme_version' ) ) :
  39. function et_get_theme_version() {
  40. $theme = wp_get_theme();
  41. // Get parent theme info if a child theme is used.
  42. if ( is_child_theme() ) {
  43. $theme = wp_get_theme( $theme->parent_theme );
  44. }
  45. return $theme->display( 'Version' );
  46. }
  47. endif;
  48. /**
  49. * Get the author post link
  50. *
  51. * @return string The author post link
  52. */
  53. if ( ! function_exists( 'et_get_the_author_posts_link' ) ) :
  54. function et_get_the_author_posts_link(){
  55. global $authordata, $themename;
  56. $link = sprintf(
  57. '<a href="%1$s" title="%2$s" rel="author">%3$s</a>',
  58. esc_url( get_author_posts_url( $authordata->ID, $authordata->user_nicename ) ),
  59. esc_attr( sprintf( et_get_safe_localization( __( 'Posts by %s', $themename ) ), get_the_author() ) ),
  60. get_the_author()
  61. );
  62. return apply_filters( 'the_author_posts_link', $link );
  63. }
  64. endif;
  65. /**
  66. * Get Post Info Meta
  67. *
  68. * @param array $postinfo ...
  69. * @param ... $... ...
  70. * @return array $postinfo Structured postinfo meta
  71. */
  72. if ( ! function_exists( 'et_postinfo_meta' ) ) :
  73. function et_postinfo_meta( $postinfo, $date_format, $comment_zero, $comment_one, $comment_more ){
  74. global $themename;
  75. $postinfo_meta = '';
  76. if ( in_array( 'author', $postinfo ) )
  77. $postinfo_meta .= ' ' . esc_html__( 'by', $themename ) . ' ' . et_get_the_author_posts_link() . ' | ';
  78. if ( in_array( 'date', $postinfo ) )
  79. $postinfo_meta .= get_the_time( $date_format ) . ' | ';
  80. if ( in_array( 'categories', $postinfo ) )
  81. $postinfo_meta .= get_the_category_list( ', ' ) . ' | ';
  82. if ( in_array( 'comments', $postinfo ) )
  83. $postinfo_meta .= et_get_comments_popup_link( $comment_zero, $comment_one, $comment_more );
  84. echo $postinfo_meta;
  85. }
  86. endif;
  87. /**
  88. * Create post excert of a given length
  89. *
  90. * @param int $amount amount of characters to truncate to
  91. * @param bool $echo whether to echo or return the result. Default: true
  92. * @param object $post the post in which to create an excerpt for, if not passed global $post is used.
  93. */
  94. if ( ! function_exists( 'et_truncate_post' ) ):
  95. function et_truncate_post( $amount, $echo = true, $post = '' ) {
  96. global $shortname;
  97. if ( '' == $post ) global $post;
  98. $post_excerpt = '';
  99. $post_excerpt = apply_filters( 'the_excerpt', $post->post_excerpt );
  100. if ( 'on' == et_get_option( $shortname . '_use_excerpt' ) && '' != $post_excerpt ) {
  101. if ( $echo ) echo $post_excerpt;
  102. else return $post_excerpt;
  103. } else {
  104. // get the post content
  105. $truncate = $post->post_content;
  106. // remove caption shortcode from the post content
  107. $truncate = preg_replace( '@\[caption[^\]]*?\].*?\[\/caption]@si', '', $truncate );
  108. // apply content filters
  109. $truncate = apply_filters( 'the_content', $truncate );
  110. // decide if we need to append dots at the end of the string
  111. if ( strlen( $truncate ) <= $amount ) {
  112. $echo_out = '';
  113. } else {
  114. $echo_out = '...';
  115. // $amount = $amount - 3;
  116. }
  117. // trim text to a certain number of characters, also remove spaces from the end of a string ( space counts as a character )
  118. if ( ! $echo ) {
  119. $truncate = rtrim( et_wp_trim_words( $truncate, $amount, '' ) );
  120. } else {
  121. $truncate = rtrim( wp_trim_words( $truncate, $amount, '' ) );
  122. }
  123. // remove the last word to make sure we display all words correctly
  124. if ( '' != $echo_out ) {
  125. $new_words_array = (array) explode( ' ', $truncate );
  126. array_pop( $new_words_array );
  127. $truncate = implode( ' ', $new_words_array );
  128. // append dots to the end of the string
  129. $truncate .= $echo_out;
  130. }
  131. if ( $echo ) echo $truncate;
  132. else return $truncate;
  133. };
  134. }
  135. endif;
  136. if ( ! function_exists( 'et_wp_trim_words' ) ):
  137. function et_wp_trim_words( $text, $num_words = 55, $more = null ) {
  138. if ( null === $more )
  139. $more = esc_html__( '&hellip;' );
  140. $original_text = $text;
  141. $text = wp_strip_all_tags( $text );
  142. $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
  143. preg_match_all( '/./u', $text, $words_array );
  144. $words_array = array_slice( $words_array[0], 0, $num_words + 1 );
  145. $sep = '';
  146. if ( count( $words_array ) > $num_words ) {
  147. array_pop( $words_array );
  148. $text = implode( $sep, $words_array );
  149. $text = $text . $more;
  150. } else {
  151. $text = implode( $sep, $words_array );
  152. }
  153. return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text );
  154. }
  155. endif;
  156. if ( ! function_exists( 'et_get_current_url' ) ) :
  157. function et_get_current_url() {
  158. return ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  159. }
  160. endif;
  161. if ( ! function_exists( 'et_options_stored_in_one_row' ) ):
  162. function et_options_stored_in_one_row(){
  163. global $et_store_options_in_one_row;
  164. return isset( $et_store_options_in_one_row ) ? (bool) $et_store_options_in_one_row : false;
  165. }
  166. endif;
  167. /**
  168. * Transforms an array of posts, pages, post_tags or categories ids
  169. * into corresponding "objects" ids, if WPML plugin is installed
  170. *
  171. * @param array $ids_array Posts, pages, post_tags or categories ids.
  172. * @param string $type "Object" type.
  173. * @return array IDs.
  174. */
  175. if ( ! function_exists( 'et_generate_wpml_ids' ) ):
  176. function et_generate_wpml_ids( $ids_array, $type ) {
  177. if ( function_exists( 'icl_object_id' ) ) {
  178. $wpml_ids = array();
  179. foreach ( $ids_array as $id ) {
  180. $translated_id = icl_object_id( $id, $type, false );
  181. if ( ! is_null( $translated_id ) ) $wpml_ids[] = $translated_id;
  182. }
  183. $ids_array = $wpml_ids;
  184. }
  185. return array_map( 'intval', $ids_array );
  186. }
  187. endif;
  188. if ( !function_exists( 'et_init_options' ) ):
  189. function et_init_options() {
  190. global $et_theme_options, $shortname, $et_theme_options_defaults;
  191. if ( et_options_stored_in_one_row() ) {
  192. $et_theme_options_name = 'et_' . $shortname;
  193. if ( ! isset( $et_theme_options ) ) {
  194. $et_theme_options = get_option( $et_theme_options_name );
  195. if ( empty( $et_theme_options ) ) {
  196. update_option( $et_theme_options_name, $et_theme_options_defaults );
  197. }
  198. }
  199. }
  200. }
  201. endif;
  202. add_action( 'et_theme_init_first', 'et_init_options' );
  203. add_action( 'et_theme_init_upgrade', 'et_init_options' );
  204. if ( ! function_exists( 'et_list_pings' ) ) :
  205. function et_list_pings($comment, $args, $depth) {
  206. $GLOBALS['comment'] = $comment; ?>
  207. <li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?> - <?php comment_excerpt(); ?>
  208. <?php }
  209. endif;
  210. if ( !function_exists( 'et_get_childmost_taxonomy_meta' ) ):
  211. function et_get_childmost_taxonomy_meta( $term_id, $meta_key, $single = false, $default = '', $taxonomy = 'category' ) {
  212. global $et_taxonomy_meta;
  213. if ( !$term = get_term( $term_id, $taxonomy ) ) {
  214. return $default;
  215. }
  216. $result = et_get_taxonomy_meta( $term_id, $meta_key, $single );
  217. if ( empty( $result ) && isset( $term->parent ) && $term->parent !== 0 ) {
  218. return et_get_childmost_taxonomy_meta( $term->parent, $meta_key, $single, $default, $taxonomy );
  219. }
  220. if ( !empty( $result ) ) {
  221. return $result;
  222. }
  223. return $default;
  224. }
  225. endif;
  226. if ( !function_exists( 'et_get_taxonomy_meta' ) ):
  227. function et_get_taxonomy_meta( $term_id, $meta_key = '', $single = false ) {
  228. global $et_taxonomy_meta;
  229. if ( !isset( $et_taxonomy_meta ) ) {
  230. _et_get_taxonomy_meta();
  231. }
  232. if ( !isset( $et_taxonomy_meta[ $term_id ] ) ) {
  233. $et_taxonomy_meta[ $term_id ] = array();
  234. }
  235. if ( empty( $meta_key ) ) {
  236. return $et_taxonomy_meta[ $term_id ];
  237. }
  238. $result = $single ? '' : array();
  239. foreach ( $et_taxonomy_meta[ $term_id ] as $tax_meta_key => $tax_meta ) {
  240. foreach ( $tax_meta as $_meta_key => $_meta_value ) {
  241. if ( $_meta_key === $meta_key ) {
  242. if ( $single ) {
  243. $result = $_meta_value;
  244. break;
  245. }
  246. $result[] = $_meta_value;
  247. }
  248. }
  249. }
  250. return $result;
  251. }
  252. endif;
  253. if ( !function_exists( 'et_update_taxonomy_meta' ) ):
  254. function et_update_taxonomy_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) {
  255. global $et_taxonomy_meta;
  256. if ( !isset( $et_taxonomy_meta ) ) {
  257. _et_get_taxonomy_meta();
  258. }
  259. if ( !isset( $et_taxonomy_meta[ $term_id ] ) ) {
  260. $et_taxonomy_meta[ $term_id ] = array();
  261. }
  262. $meta_key_found = false;
  263. foreach ( $et_taxonomy_meta[ $term_id ] as $tax_meta_key => $tax_meta ) {
  264. foreach ( $tax_meta as $_meta_key => $_meta_value ) {
  265. if ( $meta_key === $_meta_key ) {
  266. $meta_key_found = true;
  267. if ( empty( $prev_value ) ) {
  268. $et_taxonomy_meta[ $term_id ][ $tax_meta_key ][ $_meta_key ] = $meta_value;
  269. } else {
  270. if ( $prev_value === $_meta_value ) {
  271. $et_taxonomy_meta[ $term_id ][ $tax_meta_key ][ $_meta_key ] = $meta_value;
  272. }
  273. }
  274. }
  275. }
  276. }
  277. if ( !$meta_key_found ) {
  278. et_add_taxonomy_meta( $term_id, $meta_key, $meta_value );
  279. }
  280. _et_update_taxonomy_meta();
  281. }
  282. endif;
  283. if ( !function_exists( 'et_add_taxonomy_meta' ) ):
  284. function et_add_taxonomy_meta( $term_id, $meta_key, $meta_value ) {
  285. global $et_taxonomy_meta;
  286. if ( !isset( $et_taxonomy_meta ) ) {
  287. _et_get_taxonomy_meta();
  288. }
  289. if ( !isset( $et_taxonomy_meta[ $term_id ] ) ) {
  290. $et_taxonomy_meta[ $term_id ] = array();
  291. }
  292. $et_taxonomy_meta[ $term_id ][] = array( $meta_key => $meta_value );
  293. _et_update_taxonomy_meta();
  294. }
  295. endif;
  296. if ( !function_exists( 'et_delete_taxonomy_meta' ) ):
  297. function et_delete_taxonomy_meta( $term_id, $meta_key, $meta_value = '' ) {
  298. global $et_taxonomy_meta;
  299. if ( !isset( $et_taxonomy_meta ) ) {
  300. _et_get_taxonomy_meta();
  301. }
  302. foreach ( $et_taxonomy_meta[ $term_id ] as $tax_meta_key => $tax_meta ) {
  303. foreach ( $tax_meta as $_meta_key => $_meta_value ) {
  304. if ( $meta_key === $_meta_key ) {
  305. if ( empty( $meta_value ) ) {
  306. unset( $et_taxonomy_meta[ $term_id ][ $tax_meta_key ] );
  307. } else {
  308. if ( $meta_value === $_meta_value ) {
  309. unset( $et_taxonomy_meta[ $term_id ][ $tax_meta_key ] );
  310. }
  311. }
  312. }
  313. }
  314. }
  315. _et_update_taxonomy_meta();
  316. }
  317. endif;
  318. /*
  319. * Internal use helper function to get and populate the global $et_taxonomy_meta
  320. *
  321. * This function is hooked into and called during init hook
  322. */
  323. function _et_get_taxonomy_meta() {
  324. global $et_taxonomy_meta;
  325. if ( !isset( $et_taxonomy_meta ) ) {
  326. $et_taxonomy_meta = maybe_unserialize( get_option( ET_TAXONOMY_META_OPTION_KEY, null ) );
  327. if ( null === $et_taxonomy_meta ) {
  328. update_option( ET_TAXONOMY_META_OPTION_KEY, array() );
  329. $et_taxonomy_meta = array();
  330. }
  331. }
  332. }
  333. add_action( 'init', '_et_get_taxonomy_meta', 9 );
  334. /*
  335. * Internal use helper function to update and re-populate the global $et_taxonomy_meta
  336. */
  337. function _et_update_taxonomy_meta() {
  338. global $et_taxonomy_meta;
  339. update_option( ET_TAXONOMY_META_OPTION_KEY, $et_taxonomy_meta );
  340. }
  341. function _et_register_sidebar( $args ) {
  342. global $themename;
  343. $default_args = array(
  344. 'name' => '',
  345. 'id' => '',
  346. 'before_widget' => '<div id="%1$s" class="et_pb_widget %2$s">',
  347. 'after_widget' => '</div> <!-- end .et_pb_widget -->',
  348. 'before_title' => '<h4 class="widgettitle">',
  349. 'after_title' => '</h4>',
  350. );
  351. $args = wp_parse_args( $args, $default_args );
  352. if ( empty( $args['name'] ) ) {
  353. $version = sprintf( '%s, Theme: %s', et_get_theme_version(), $themename );
  354. _doing_it_wrong( __FUNCTION__, "'name' argument required", $version );
  355. return;
  356. }
  357. if ( empty( $args['id'] ) ) {
  358. $args['id'] = sanitize_title_with_dashes( $args['name'] );
  359. if ( strpos( $args['id'], '-sidebar' ) !== false ) {
  360. $args['id'] = 'sidebar-' . str_replace( '-sidebar', '', $args['id'] );
  361. }
  362. }
  363. register_sidebar( $args );
  364. }
  365. function et_register_widget_areas() {
  366. if ( !current_theme_supports( 'et_widget_areas' ) ) {
  367. return;
  368. }
  369. $et_widget_areas = get_option( 'et_widget_areas' );
  370. if ( !empty( $et_widget_areas ) ) {
  371. foreach ( $et_widget_areas['areas'] as $id => $name ) {
  372. _et_register_sidebar( array(
  373. 'id' => $id,
  374. 'name' => $name,
  375. ) );
  376. }
  377. }
  378. }
  379. add_action( 'widgets_init', 'et_register_widget_areas', 11 );
  380. function et_add_wp_version( $classes ) {
  381. global $wp_version;
  382. // add 'et-wp-pre-3_8' class if the current WordPress version is less than 3.8
  383. if ( version_compare( $wp_version, '3.7.2', '<=' ) ) {
  384. if ( 'body_class' === current_filter() )
  385. $classes[] = 'et-wp-pre-3_8';
  386. else
  387. $classes = 'et-wp-pre-3_8';
  388. } else {
  389. if ( 'admin_body_class' === current_filter() )
  390. $classes = 'et-wp-after-3_8';
  391. }
  392. return $classes;
  393. }
  394. add_filter( 'admin_body_class', 'et_add_wp_version' );
  395. function et_register_customizer_section( $wp_customize, $settings, $section, $section_options = '', $panel = '' ) {
  396. global $shortname;
  397. if ( empty( $settings ) ) {
  398. return;
  399. }
  400. $section_args = wp_parse_args( $section_options, array(
  401. 'title' => $section,
  402. 'priority' => 10,
  403. ) );
  404. if ( !empty( $panel ) ) {
  405. $section_args['panel'] = $panel;
  406. }
  407. $wp_customize->add_section( $section, $section_args );
  408. foreach ($settings as $option_key => $options) {
  409. if ( !is_array( $options ) ) {
  410. $label = $options;
  411. $options = array();
  412. $options['label'] = $label;
  413. }
  414. $default_options = array(
  415. 'setting_type' => 'option',
  416. 'type' => 'text',
  417. 'transport' => 'postMessage',
  418. 'capability' => 'edit_theme_options',
  419. 'default' => '',
  420. 'description' => '',
  421. 'choices' => array(),
  422. 'priority' => 10,
  423. 'global_option' => false,
  424. 'theme_supports' => '',
  425. );
  426. $options = wp_parse_args( $options, $default_options );
  427. $option_key = true == $options['global_option'] ? $option_key : sprintf( 'et_%s[%s]', $shortname, $option_key );
  428. switch ( $options['type'] ) {
  429. case 'dropdown-font-styles':
  430. $sanitize_callback = 'et_sanitize_font_style';
  431. break;
  432. case 'dropdown-fonts':
  433. $sanitize_callback = 'et_sanitize_font_choices';
  434. break;
  435. case 'color':
  436. $sanitize_callback = 'sanitize_hex_color';
  437. break;
  438. case 'et_coloralpha':
  439. $sanitize_callback = 'et_sanitize_alpha_color';
  440. break;
  441. case 'checkbox':
  442. $sanitize_callback = 'wp_validate_boolean';
  443. break;
  444. case 'range':
  445. if ( isset( $options['input_attrs']['step'] ) && $options['input_attrs']['step'] < 1 ) {
  446. $sanitize_callback = 'et_sanitize_float_number';
  447. } else {
  448. $sanitize_callback = 'et_sanitize_int_number';
  449. }
  450. break;
  451. default:
  452. $sanitize_callback = '';
  453. break;
  454. }
  455. $wp_customize->add_setting( $option_key, array(
  456. 'default' => $options['default'],
  457. 'type' => $options['setting_type'],
  458. 'capability' => $options['capability'],
  459. 'transport' => $options['transport'],
  460. 'theme_supports' => $options['theme_supports'],
  461. 'sanitize_callback' => $sanitize_callback,
  462. ) );
  463. $control_options = array(
  464. 'label' => $options['label'],
  465. 'section' => $section,
  466. 'description' => $options['description'],
  467. 'settings' => $option_key,
  468. 'type' => $options['type'],
  469. 'priority' => $options['priority'],
  470. );
  471. switch ( $options['type'] ) {
  472. case 'color':
  473. $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, $option_key, $control_options ) );
  474. break;
  475. case 'et_coloralpha':
  476. $wp_customize->add_control( new ET_Color_Alpha_Control( $wp_customize, $option_key, $control_options ) );
  477. break;
  478. case 'range':
  479. $control_options = array_merge( $control_options, array(
  480. 'input_attrs' => $options['input_attrs'],
  481. ) );
  482. $wp_customize->add_control( new ET_Range_Control( $wp_customize, $option_key, $control_options ) );
  483. break;
  484. case 'radio':
  485. $control_options = array_merge( $control_options, array(
  486. 'choices' => $options['choices'],
  487. ) );
  488. $wp_customize->add_control( $option_key, $control_options );
  489. break;
  490. case 'dropdown-font-styles':
  491. $control_options = array_merge( $control_options, array(
  492. 'type' => 'select',
  493. 'choices' => et_extra_font_style_choices(),
  494. ) );
  495. $wp_customize->add_control( new ET_Font_Style_Control( $wp_customize, $option_key, $control_options ) );
  496. break;
  497. case 'dropdown-fonts':
  498. if ( et_is_one_font_language() ) {
  499. break;
  500. }
  501. $control_options = array_merge( $control_options, array(
  502. 'type' => 'select',
  503. 'choices' => et_dropdown_google_font_choices(),
  504. ) );
  505. $wp_customize->add_control( new ET_Font_Select_Control( $wp_customize, $option_key, $control_options ) );
  506. break;
  507. case 'select':
  508. default:
  509. $control_options = array_merge( $control_options, array(
  510. 'choices' => $options['choices'],
  511. ) );
  512. $wp_customize->add_control( $option_key, $control_options );
  513. break;
  514. }
  515. $options['priority']++;
  516. }
  517. }
  518. if ( !function_exists( 'et_is_one_font_language' ) ) {
  519. function et_is_one_font_language() {
  520. static $et_is_one_font_language = null;
  521. if ( is_null( $et_is_one_font_language ) ) {
  522. $site_domain = get_locale();
  523. $et_one_font_languages = et_get_one_font_languages();
  524. $et_is_one_font_language = (bool) isset( $et_one_font_languages[$site_domain] );
  525. }
  526. return $et_is_one_font_language;
  527. }
  528. }
  529. if ( !function_exists( 'et_get_one_font_languages' ) ) {
  530. function et_get_one_font_languages() {
  531. $one_font_languages = array(
  532. 'he_IL' => array(
  533. 'language_name' => 'Hebrew',
  534. 'google_font_url' => '//fonts.googleapis.com/earlyaccess/alefhebrew.css',
  535. 'font_family' => "'Alef Hebrew', serif",
  536. ),
  537. 'ja' => array(
  538. 'language_name' => 'Japanese',
  539. 'google_font_url' => '//fonts.googleapis.com/earlyaccess/notosansjapanese.css',
  540. 'font_family' => "'Noto Sans Japanese', serif",
  541. ),
  542. 'ko_KR' => array(
  543. 'language_name' => 'Korean',
  544. 'google_font_url' => '//fonts.googleapis.com/earlyaccess/hanna.css',
  545. 'font_family' => "'Hanna', serif",
  546. ),
  547. 'ar' => array(
  548. 'language_name' => 'Arabic',
  549. 'google_font_url' => '//fonts.googleapis.com/earlyaccess/lateef.css',
  550. 'font_family' => "'Lateef', serif",
  551. ),
  552. 'th' => array(
  553. 'language_name' => 'Thai',
  554. 'google_font_url' => '//fonts.googleapis.com/earlyaccess/notosansthai.css',
  555. 'font_family' => "'Noto Sans Thai', serif",
  556. ),
  557. 'ms_MY' => array(
  558. 'language_name' => 'Malay',
  559. 'google_font_url' => '//fonts.googleapis.com/earlyaccess/notosansmalayalam.css',
  560. 'font_family' => "'Noto Sans Malayalam', serif",
  561. ),
  562. 'zh_CN' => array(
  563. 'language_name' => 'Chinese',
  564. 'google_font_url' => '//fonts.googleapis.com/earlyaccess/cwtexfangsong.css',
  565. 'font_family' => "'cwTeXFangSong', serif",
  566. ),
  567. );
  568. return $one_font_languages;
  569. }
  570. }
  571. if ( !function_exists( 'et_dropdown_google_font_choices' ) ) {
  572. function et_dropdown_google_font_choices() {
  573. static $et_dropdown_google_font_choices = null;
  574. if ( is_null( $et_dropdown_google_font_choices ) ) {
  575. $site_domain = get_locale();
  576. $google_fonts = et_builder_get_google_fonts();
  577. $et_domain_fonts = array(
  578. 'ru_RU' => 'cyrillic',
  579. 'uk' => 'cyrillic',
  580. 'bg_BG' => 'cyrillic',
  581. 'vi' => 'vietnamese',
  582. 'el' => 'greek',
  583. );
  584. $font_choices = array();
  585. $font_choices['none'] = array(
  586. 'label' => 'Default Theme Font',
  587. );
  588. foreach ( $google_fonts as $google_font_name => $google_font_properties ) {
  589. if ( '' !== $site_domain && isset( $et_domain_fonts[$site_domain] ) && false === strpos( $google_font_properties['character_set'], $et_domain_fonts[$site_domain] ) ) {
  590. continue;
  591. }
  592. $font_choices[ $google_font_name ] = array(
  593. 'label' => $google_font_name,
  594. 'data' => array(
  595. 'parent_font' => isset( $google_font_properties['parent_font'] ) ? $google_font_properties['parent_font'] : '',
  596. 'parent_styles' => isset( $google_font_properties['parent_font'] ) && isset( $google_fonts[$google_font_properties['parent_font']]['styles'] ) ? $google_fonts[$google_font_properties['parent_font']]['styles'] : $google_font_properties['styles'],
  597. 'current_styles' => isset( $google_font_properties['parent_font'] ) && isset( $google_fonts[$google_font_properties['parent_font']]['styles'] ) && isset( $google_font_properties['styles'] ) ? $google_font_properties['styles'] : '',
  598. 'parent_subset' => isset( $google_font_properties['parent_font'] ) && isset( $google_fonts[$google_font_properties['parent_font']]['character_set'] ) ? $google_fonts[$google_font_properties['parent_font']]['character_set'] : '',
  599. ),
  600. );
  601. }
  602. $et_dropdown_google_font_choices = $font_choices;
  603. }
  604. return $et_dropdown_google_font_choices;
  605. }
  606. }
  607. /**
  608. * Outputting font-style attributes & values saved by ET_Font_Style_Control on customizer
  609. *
  610. * @return string
  611. */
  612. function et_print_font_style( $styles = '', $important = '', $boldness = 'bold' ) {
  613. // Prepare variable
  614. $font_styles = "";
  615. if ( '' !== $styles && false !== $styles ) {
  616. // Convert string into array
  617. $styles_array = explode( '|', $styles );
  618. // If $important is in use, give it a space
  619. if ( $important && '' !== $important ) {
  620. $important = " " . $important;
  621. }
  622. // Use in_array to find values in strings. Otherwise, display default text
  623. // Font weight
  624. if ( in_array( 'bold', $styles_array ) ) {
  625. $font_styles .= "font-weight: {$boldness}{$important}; ";
  626. } else {
  627. $font_styles .= "font-weight: normal{$important}; ";
  628. }
  629. // Font style
  630. if ( in_array( 'italic', $styles_array ) ) {
  631. $font_styles .= "font-style: italic{$important}; ";
  632. } else {
  633. $font_styles .= "font-style: normal{$important}; ";
  634. }
  635. // Text-transform
  636. if ( in_array( 'uppercase', $styles_array ) ) {
  637. $font_styles .= "text-transform: uppercase{$important}; ";
  638. } else {
  639. $font_styles .= "text-transform: none{$important}; ";
  640. }
  641. // Text-decoration
  642. if ( in_array( 'underline', $styles_array ) ) {
  643. $font_styles .= "text-decoration: underline{$important}; ";
  644. } else {
  645. $font_styles .= "text-decoration: none{$important}; ";
  646. }
  647. }
  648. return esc_html( $font_styles );
  649. }
  650. /**
  651. * Add custom customizer control
  652. * Check for WP_Customizer_Control existence before adding custom control because WP_Customize_Control is loaded on customizer page only
  653. *
  654. * @see _wp_customize_include()
  655. */
  656. if ( class_exists( 'WP_Customize_Control' ) ) {
  657. /**
  658. * Font style control for Customizer
  659. */
  660. class ET_Font_Style_Control extends WP_Customize_Control {
  661. public $type = 'font_style';
  662. public function render_content() {
  663. if ( $this->setting->default ) {
  664. $this->input_attrs['data-default'] = $this->setting->default ;
  665. }
  666. ?>
  667. <label>
  668. <?php if ( ! empty( $this->label ) ) : ?>
  669. <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
  670. <?php endif;
  671. if ( ! empty( $this->description ) ) : ?>
  672. <span class="description customize-control-description"><?php echo $this->description; ?></span>
  673. <?php endif; ?>
  674. </label>
  675. <?php $current_values = explode( '|', $this->value() );
  676. if ( empty( $this->choices ) )
  677. return;
  678. foreach ( $this->choices as $value => $label ) :
  679. $checked_class = in_array( $value, $current_values ) ? ' et_font_style_checked' : '';
  680. ?>
  681. <span class="et_font_style et_font_value_<?php echo $value; echo $checked_class; ?>">
  682. <input type="checkbox" class="et_font_style_checkbox" value="<?php echo esc_attr( $value ); ?>" <?php checked( in_array( $value, $current_values ) ); ?> />
  683. </span>
  684. <?php
  685. endforeach;
  686. ?>
  687. <input type="hidden" class="et_font_styles" <?php $this->input_attrs(); ?> value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />
  688. <?php
  689. }
  690. }
  691. /**
  692. * Icon picker control for Customizer
  693. */
  694. class ET_Icon_Picker_Control extends WP_Customize_Control {
  695. public $type = 'icon_picker';
  696. public function render_content() {
  697. ?>
  698. <label>
  699. <?php if ( ! empty( $this->label ) ) : ?>
  700. <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
  701. <?php endif;
  702. et_pb_font_icon_list(); ?>
  703. <input type="hidden" class="et_selected_icon" <?php $this->input_attrs(); ?> value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />
  704. </label>
  705. <?php
  706. }
  707. }
  708. /**
  709. * Range-based sliding value picker for Customizer
  710. */
  711. class ET_Range_Control extends WP_Customize_Control {
  712. public $type = 'range';
  713. public function render_content() {
  714. ?>
  715. <label>
  716. <?php if ( ! empty( $this->label ) ) : ?>
  717. <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
  718. <?php endif; ?>
  719. <?php if ( ! empty( $this->description ) ) : ?>
  720. <span class="description customize-control-description"><?php echo $this->description; ?></span>
  721. <?php endif; ?>
  722. <input type="<?php echo esc_attr( $this->type ); ?>" <?php $this->input_attrs(); ?> value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> data-reset_value="<?php echo esc_attr( $this->setting->default ); ?>" />
  723. <input type="number" <?php $this->input_attrs(); ?> class="et-pb-range-input" value="<?php echo esc_attr( $this->value() ); ?>" />
  724. <span class="et_divi_reset_slider"></span>
  725. </label>
  726. <?php
  727. }
  728. }
  729. /**
  730. * Custom Select option which supports data attributes for the <option> tags
  731. */
  732. class ET_Select_Control extends WP_Customize_Control {
  733. public $type = 'select';
  734. public function render_content() {
  735. ?>
  736. <label>
  737. <?php if ( ! empty( $this->label ) ) : ?>
  738. <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
  739. <?php endif; ?>
  740. <?php if ( ! empty( $this->description ) ) : ?>
  741. <span class="description customize-control-description"><?php echo $this->description; ?></span>
  742. <?php endif; ?>
  743. <?php $this->_render_select_start_el(); ?>
  744. <?php
  745. foreach ( $this->choices as $value => $attributes ) {
  746. $data_output = '';
  747. if ( ! empty( $attributes['data'] ) ) {
  748. foreach ( $attributes['data'] as $data_name => $data_value ) {
  749. if ( '' !== $data_value ) {
  750. $data_output .= sprintf( ' data-%1$s="%2$s"',
  751. esc_attr( $data_name ),
  752. esc_attr( $data_value )
  753. );
  754. }
  755. }
  756. }
  757. echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . $data_output . '>' . $attributes['label'] . '</option>';
  758. }
  759. ?>
  760. </select>
  761. </label>
  762. <?php
  763. }
  764. public function _render_select_start_el() {
  765. ?>
  766. <select <?php $this->link(); ?>>
  767. <?php
  768. }
  769. }
  770. /**
  771. * Custom Select option which supports data attributes for the <option> tags
  772. */
  773. class ET_Font_Select_Control extends ET_Select_Control {
  774. public function _render_select_start_el() {
  775. ?>
  776. <select <?php $this->link(); ?> class="et-font-select-control">
  777. <?php
  778. }
  779. }
  780. /**
  781. * Color picker with alpha color support for Customizer
  782. */
  783. class ET_Color_Alpha_Control extends WP_Customize_Control {
  784. public $type = 'et_coloralpha';
  785. public $statuses;
  786. public function __construct( $manager, $id, $args = array() ) {
  787. $this->statuses = array( '' => esc_html__( 'Default', 'extra' ) );
  788. parent::__construct( $manager, $id, $args );
  789. }
  790. public function enqueue() {
  791. wp_enqueue_script( 'wp-color-picker-alpha' );
  792. wp_enqueue_style( 'wp-color-picker' );
  793. }
  794. public function to_json() {
  795. parent::to_json();
  796. $this->json['statuses'] = $this->statuses;
  797. $this->json['defaultValue'] = $this->setting->default;
  798. }
  799. public function render_content() {}
  800. public function content_template() {
  801. ?>
  802. <# var defaultValue = '';
  803. if ( data.defaultValue ) {
  804. if ( '#' !== data.defaultValue.substring( 0, 1 ) && 'rgba' !== data.defaultValue.substring( 0, 4 ) ) {
  805. defaultValue = '#' + data.defaultValue;
  806. } else {
  807. defaultValue = data.defaultValue;
  808. }
  809. defaultValue = ' data-default-color=' + defaultValue; // Quotes added automatically.
  810. } #>
  811. <label>
  812. <# if ( data.label ) { #>
  813. <span class="customize-control-title">{{{ data.label }}}</span>
  814. <# } #>
  815. <# if ( data.description ) { #>
  816. <span class="description customize-control-description">{{{ data.description }}}</span>
  817. <# } #>
  818. <div class="customize-control-content">
  819. <input class="color-picker-hex" data-alpha="true" type="text" maxlength="7" placeholder="<?php esc_attr_e( 'Hex Value', 'extra' ); ?>" {{ defaultValue }} />
  820. </div>
  821. </label>
  822. <?php
  823. }
  824. }
  825. }
  826. /* Mostly copied from paginate_links() */
  827. function et_paginate_links( $args = '' ) {
  828. $defaults = array(
  829. 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
  830. 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
  831. 'total' => 1,
  832. 'current' => 0,
  833. 'show_all' => false,
  834. 'prev_next' => true,
  835. 'prev_text' => esc_html__( '&laquo; Previous', 'extra' ),
  836. 'next_text' => esc_html__( 'Next &raquo;', 'extra' ),
  837. 'beg_size' => 1,
  838. 'end_size' => 1,
  839. 'mid_size' => 2,
  840. 'type' => 'plain',
  841. 'add_args' => false, // array of query args to add
  842. 'add_fragment' => '',
  843. 'before_page_number' => '',
  844. 'after_page_number' => '',
  845. );
  846. $args = wp_parse_args( $args, $defaults );
  847. // Who knows what else people pass in $args
  848. $args['total'] = (int) $args['total'];
  849. if ( $args['total'] < 2 )
  850. return;
  851. $args['current'] = (int) $args['current'];
  852. $args['beg_size'] = 0 < (int) $args['beg_size'] ? (int) $args['beg_size'] : 1; // Out of bounds? Make it the default.
  853. $args['end_size'] = 0 < (int) $args['end_size'] ? (int) $args['end_size'] : 1; // Out of bounds? Make it the default.
  854. $args['mid_size'] = 0 <= (int) $args['mid_size'] ? (int) $args['mid_size'] : 2;
  855. $args['add_args'] = is_array( $args['add_args'] ) ? $args['add_args'] : false;
  856. $r = '';
  857. $page_links = array();
  858. $n = 0;
  859. $dots = false;
  860. if ( $args['prev_next'] && $args['current'] && 1 < $args['current'] ) :
  861. $link = str_replace( '%_%', 2 == $args['current'] ? '' : $args['format'], $args['base'] );
  862. $link = str_replace( '%#%', $args['current'] - 1, $link );
  863. if ( $args['add_args'] )
  864. $link = add_query_arg( $args['add_args'], $link );
  865. $link .= $args['add_fragment'];
  866. /**
  867. * Filter the paginated links for the given archive pages.
  868. *
  869. * @since 3.0.0
  870. *
  871. * @param string $link The paginated link URL.
  872. */
  873. $html = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['prev_text'] . '</a>';
  874. $html = $args['type'] == "list" ? '<li class="prev">' . $html . '</li>' : $html;
  875. $page_links[] = $html;
  876. endif;
  877. for ( $n = 1; $n <= $args['total']; $n++ ) :
  878. if ( $n == $args['current'] ) :
  879. $html = "<span class='page-numbers current'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</span>";
  880. $html = $args['type'] == "list" ? '<li class="current">' . $html . '</li>' : $html;
  881. $page_links[] = $html;
  882. $dots = true;
  883. else :
  884. if ( $args['show_all'] || ( $n <= $args['beg_size'] || ( $args['current'] && $n >= $args['current'] - $args['mid_size'] && $n <= $args['current'] + $args['mid_size'] ) || $n > $args['total'] - $args['end_size'] ) ) :
  885. $link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] );
  886. $link = str_replace( '%#%', $n, $link );
  887. if ( $args['add_args'] )
  888. $link = add_query_arg( $args['add_args'], $link );
  889. $link .= $args['add_fragment'];
  890. /** This filter is documented in wp-includes/general-template.php */
  891. $html = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</a>";
  892. $html = $args['type'] == "list" ? '<li>' . $html . '</li>' : $html;
  893. $page_links[] = $html;
  894. $dots = true;
  895. elseif ( $dots && !$args['show_all'] ) :
  896. $html = '<span class="page-numbers dots">' . esc_html__( '&hellip;', 'extra' ) . '</span>';
  897. $html = $args['type'] == "list" ? '<li class="dots">' . $html . '</li>' : $html;
  898. $page_links[] = $html;
  899. $dots = false;
  900. endif;
  901. endif;
  902. endfor;
  903. if ( $args['prev_next'] && $args['current'] && ( $args['current'] < $args['total'] || -1 == $args['total'] ) ) :
  904. $link = str_replace( '%_%', $args['format'], $args['base'] );
  905. $link = str_replace( '%#%', $args['current'] + 1, $link );
  906. if ( $args['add_args'] )
  907. $link = add_query_arg( $args['add_args'], $link );
  908. $link .= $args['add_fragment'];
  909. /** This filter is documented in wp-includes/general-template.php */
  910. $html = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['next_text'] . '</a>';
  911. $html = $args['type'] == "list" ? '<li class="next">' . $html . '</li>' : $html;
  912. $page_links[] = $html;
  913. endif;
  914. switch ( $args['type'] ) :
  915. case 'array' :
  916. return $page_links;
  917. break;
  918. case 'list' :
  919. $r .= "<ul class='page-numbers'>\n\t";
  920. $r .= join( "\n\t", $page_links );
  921. $r .= "\n</ul>\n";
  922. break;
  923. default :
  924. $r = join( "\n", $page_links );
  925. break;
  926. endswitch;
  927. return $r;
  928. }
  929. if ( ! function_exists( 'et_show_cart_total' ) ) {
  930. function et_show_cart_total( $args = array() ) {
  931. global $shortname;
  932. if ( ! class_exists( 'woocommerce' ) ) {
  933. return;
  934. }
  935. $defaults = array(
  936. 'no_text' => false,
  937. );
  938. $args = wp_parse_args( $args, $defaults );
  939. $cart_count = WC()->cart->get_cart_contents_count();
  940. printf(
  941. '<a href="%1$s" class="et-cart" title="%2$s">
  942. <span>%3$s</span>
  943. </a>',
  944. esc_url( WC()->cart->get_cart_url() ),
  945. esc_attr( sprintf( _n( '%d Item in Cart', '%d Items in Cart', $cart_count, $shortname ), $cart_count ) ),
  946. esc_html( ! $args['no_text'] ? sprintf( _n( '%d Item', '%d Items', $cart_count, $shortname ), $cart_count ) : $cart_count )
  947. );
  948. }
  949. }
  950. if ( ! function_exists( 'et_cart_has_total' ) ) {
  951. function et_cart_has_total() {
  952. global $shortname;
  953. if ( ! class_exists( 'woocommerce' ) ) {
  954. return;
  955. }
  956. $cart_count = WC()->cart->get_cart_contents_count();
  957. return (bool) $cart_count;
  958. }
  959. }
  960. if ( ! function_exists( 'et_extra_activate_features' ) ) {
  961. function et_extra_activate_features(){
  962. define( 'ET_SHORTCODES_VERSION', et_get_theme_version() );
  963. /* activate shortcodes */
  964. require_once( get_template_directory() . '/epanel/shortcodes/shortcodes.php' );
  965. }
  966. }
  967. add_action( 'init', 'et_extra_activate_features' );