Advertisement
rdusnr

Untitled

Oct 17th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 78.17 KB | None | 0 0
  1. <?php
  2. define( 'KLEO_THEME_VERSION', '4.2.12' );
  3.  
  4. /* Configuration array */
  5. global $kleo_config;
  6.  
  7. //Post image sizes for carousels and galleries
  8. $kleo_config['post_gallery_img_width'] = 480;
  9. $kleo_config['post_gallery_img_height'] = 270;
  10.  
  11. //Image width for big images like on single post page
  12. $kleo_config['post_single_img_width'] = 1200;
  13.  
  14. $kleo_config['blog_layouts'] = array(
  15. 'masonry' => 'Grid Masonry',
  16. 'small' => 'Small Left Thumbnail',
  17. 'standard' => 'Standard'
  18. );
  19.  
  20. $kleo_config['blog_meta_elements'] = array(
  21. 'avatar' => 'Author Avatar',
  22. 'date' => 'Date',
  23. 'archive' => 'Archive Link',
  24. 'profile' => 'Profile Icon',
  25. 'author_link' => 'Profile Link',
  26. 'message' => 'Message Link',
  27. 'categories' => 'Categories',
  28. 'tags' => 'Tags',
  29. 'comments' => 'Comments',
  30. );
  31. $kleo_config['blog_meta_defaults'] = array( 'author_link', 'date', 'categories', 'tags', 'comments' );
  32.  
  33. //define dynamic styles path
  34. $upload_dir = wp_upload_dir();
  35. if ( is_ssl() ) {
  36. if ( strpos( $upload_dir['baseurl'], 'https://' ) === false ) {
  37. $upload_dir['baseurl'] = str_ireplace( 'http', 'https', $upload_dir['baseurl'] );
  38. }
  39. }
  40.  
  41. $kleo_config['upload_basedir'] = $upload_dir['basedir'];
  42. $kleo_config['custom_style_path'] = $upload_dir['basedir'] . '/custom_styles';
  43. $kleo_config['custom_style_url'] = $upload_dir['baseurl'] . '/custom_styles';
  44. $kleo_config['image_overlay'] = '<span class="hover-element"><i>+</i></span>';
  45.  
  46. //define site style sets
  47. $kleo_config['style_sets'] = array( 'header', 'main', 'alternate', 'side', 'footer', 'socket' );
  48. $kleo_config['font_sections'] = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'body', 'header' );
  49.  
  50. //physical file template mapping
  51. $kleo_config['tpl_map'] = array(
  52. 'page-templates/left-sidebar.php' => 'left',
  53. 'page-templates/right-sidebar.php' => 'right',
  54. 'page-templates/full-width.php' => 'no',
  55. 'page-templates/left-right-sidebars.php' => '3lr',
  56. 'page-templates/left-two-sidebars.php' => '3ll',
  57. 'page-templates/right-two-sidebars.php' => '3rr',
  58. );
  59.  
  60. /***************************************************
  61. * :: Framework initialization with required plugins
  62. ***************************************************/
  63.  
  64. //instance of our theme framework
  65. global $kleo_theme;
  66.  
  67. /**
  68. * @return Kleo
  69. */
  70. function sq_kleo() {
  71. return Kleo::instance();
  72. }
  73.  
  74. $kleo_theme = sq_kleo();
  75.  
  76. if ( is_admin() ) {
  77. require_once KLEO_LIB_DIR . '/required-plugins.php';
  78. }
  79.  
  80.  
  81. /***************************************************
  82. * :: Load Theme functions
  83. ***************************************************/
  84.  
  85. add_action( 'after_setup_theme', 'kleo_theme_functions', 12 );
  86.  
  87. function kleo_theme_functions() {
  88.  
  89. /* Plugins and functionality */
  90.  
  91. // BuddyPress compatibility
  92. if ( function_exists( 'bp_is_active' ) ) {
  93. require_once( KLEO_LIB_DIR . '/plugin-buddypress/config.php' ); //compatibility with buddypress plugin
  94. }
  95.  
  96. // bbPress compatibility
  97. if ( class_exists( 'bbPress' ) ) {
  98. require_once( KLEO_LIB_DIR . '/plugin-bbpress/config.php' ); //compatibility with bbpress plugin
  99. }
  100.  
  101. /* Woocommerce compatibility */
  102. if ( class_exists( 'WooCommerce' ) ) {
  103. require_once( KLEO_LIB_DIR . '/plugin-woocommerce/config.php' );
  104. }
  105.  
  106. // Paid memberships Pro compatibility
  107. if ( function_exists( 'pmpro_url' ) ) {
  108. require_once( KLEO_LIB_DIR . '/plugin-pmpro/config.php' );
  109. }
  110.  
  111. // Visual composer compatibility
  112. if ( function_exists( 'vc_set_as_theme' ) ) {
  113. require_once( KLEO_LIB_DIR . '/plugin-vc/config.php' );
  114. }
  115.  
  116. // Compatibility with GeoDirectory plugin
  117. if ( defined( 'GEODIRECTORY_VERSION' ) ) {
  118. require_once( KLEO_LIB_DIR . '/plugin-geodirectory/config.php' );
  119. }
  120.  
  121. // Compatibility with Sensei plugin
  122. if ( class_exists( 'WooThemes_Sensei' ) ) {
  123. require_once( KLEO_LIB_DIR . '/plugin-sensei/config.php' );
  124. }
  125.  
  126. // Compatibility Bp Profile Search
  127. if ( defined( 'BPS_VERSION' ) ) {
  128. require_once( KLEO_LIB_DIR . '/plugin-bp-profile-search/config.php' );
  129. }
  130.  
  131. // Posts likes
  132. if ( sq_option( 'likes_status', 1 ) == 1 ) {
  133. require_once( KLEO_LIB_DIR . '/item-likes.php' );
  134. }
  135.  
  136. // Resize on the fly
  137. require_once( KLEO_LIB_DIR . '/aq_resizer.php' );
  138.  
  139. // menu-items-visibility-control plugin compatibility
  140. if ( class_exists( 'Boom_Walker_Nav_Menu_Edit' ) ) {
  141. require_once( KLEO_LIB_DIR . '/plugin-menu-items-visibility-control/config.php' );
  142. }
  143.  
  144. /* Custom menu */
  145. require_if_theme_supports( 'kleo-mega-menu', KLEO_LIB_DIR . '/menu-custom.php' );
  146.  
  147. /* Custom menu items */
  148. require_if_theme_supports( 'kleo-menu-items', KLEO_LIB_DIR . '/menu-items.php' );
  149.  
  150. /* Portfolio module */
  151. if ( sq_option( 'module_portfolio', 1 ) == 1 ) {
  152. require KLEO_LIB_DIR . '/portfolio.php';
  153. }
  154.  
  155. /* Include admin customizations */
  156. if ( is_admin() ) {
  157. //Metaboxes
  158. require_once( KLEO_LIB_DIR . '/metaboxes.php' );
  159. }
  160.  
  161. if ( is_admin() || is_customize_preview() ) {
  162. require_once( KLEO_LIB_DIR . '/options.php' );
  163. }
  164.  
  165. //Modules
  166. require_once( KLEO_LIB_DIR . '/modules.php' );
  167.  
  168. }
  169.  
  170.  
  171. /***************************************************
  172. * :: Theme panel
  173. ***************************************************/
  174. if ( is_admin() ) {
  175. require_once( KLEO_LIB_DIR . '/theme-panel/init.php' );
  176. }
  177.  
  178. /***************************************************
  179. * :: 1 Click Install
  180. ***************************************************/
  181. if ( is_admin() ) {
  182. require_once( KLEO_LIB_DIR . '/importer/import.php' );
  183. }
  184.  
  185.  
  186. /***************************************************
  187. * :: Load post types class
  188. ***************************************************/
  189.  
  190. require_once KLEO_LIB_DIR . '/post-types.php';
  191.  
  192.  
  193. /* Testimonials module */
  194. if ( sq_option( 'module_testimonials', 1 ) == 1 ) {
  195. require KLEO_LIB_DIR . '/testimonials.php';
  196. }
  197.  
  198. /* Clients module */
  199. if ( sq_option( 'module_clients', 1 ) == 1 ) {
  200. require KLEO_LIB_DIR . '/clients.php';
  201. }
  202.  
  203.  
  204. /***************************************************
  205. * :: Theme options
  206. ***************************************************/
  207.  
  208. if ( is_admin() || is_customize_preview() ) {
  209. //Options panel
  210. if ( ! class_exists( 'ReduxFramework' ) && file_exists( KLEO_DIR . '/options/framework.php' ) ) {
  211. require_once( KLEO_DIR . '/options/framework.php' );
  212. }
  213. }
  214.  
  215.  
  216. /***************************************************
  217. * :: Modules Class
  218. ***************************************************/
  219. if ( sq_option( 'performance', 0 ) == 1 ) {
  220. require_once( KLEO_DIR . '/modules.php' );
  221. }
  222.  
  223.  
  224. /***************************************************
  225. * :: Include widgets
  226. ***************************************************/
  227.  
  228. $kleo_widgets = array(
  229. 'recent_posts.php'
  230. );
  231.  
  232. $kleo_widgets = apply_filters( 'kleo_widgets', $kleo_widgets );
  233.  
  234. foreach ( $kleo_widgets as $widget ) {
  235. $file_path = trailingslashit( KLEO_LIB_DIR ) . 'widgets/' . $widget;
  236.  
  237. if ( file_exists( $file_path ) ) {
  238. require_once( $file_path );
  239. }
  240. }
  241.  
  242. if ( ! function_exists( 'kleo_title_section' ) ) {
  243. /**
  244. * Return the breadcrumb area
  245. * @global object $wp_query
  246. *
  247. * @param array $args
  248. *
  249. * @return string
  250. */
  251. function kleo_title_section( $args = false ) {
  252. $defaults = array(
  253. 'title' => get_the_title(),
  254. 'show_title' => true,
  255. 'show_breadcrumb' => true,
  256. 'link' => '',
  257. 'output' => "<section class='{class} border-bottom breadcrumbs-container'><div class='container'>{title_data}<div class='breadcrumb-extra'>{breadcrumb_data}{extra}</div></div></section>",
  258. 'class' => 'container-wrap main-title alternate-color ',
  259. 'extra' => '<p class="page-info">' . do_shortcode( sq_option( 'title_info', '' ) ) . '</p>',
  260. 'heading' => 'h1'
  261. );
  262.  
  263. // Parse incoming $args into an array and merge it with $defaults
  264. $args = wp_parse_args( $args, $defaults );
  265. $args = apply_filters( 'kleo_title_args', $args );
  266.  
  267. // OPTIONAL: Declare each item in $args as its own variable i.e. $type, $before.
  268. extract( $args, EXTR_SKIP );
  269.  
  270. if ( ! empty( $link ) ) {
  271. $title = "<a href='" . $link . "' rel='bookmark' title='" . __( 'Permanent Link:', 'kleo_framework' ) . " " . esc_attr( $title ) . "'>" . $title . "</a>";
  272. }
  273.  
  274. $breadcrumb_data = '';
  275. if ( $show_breadcrumb ) {
  276. $breadcrumb_data = kleo_breadcrumb( array(
  277. 'show_browse' => false,
  278. 'separator' => ' ',
  279. 'show_home' => __( 'Home', 'kleo_framework' ),
  280. 'echo' => false
  281. ) );
  282. }
  283.  
  284. $title_data = '';
  285. if ( $show_title ) {
  286. $title_data = '<{heading} class="page-title">{title}</{heading}>';
  287. }
  288.  
  289. if ( ! $show_breadcrumb && $extra == '' ) {
  290. $class .= ' title-single';
  291. }
  292.  
  293. $title_layout = sq_option( 'title_layout', 'normal' );
  294. if ( is_singular() && get_cfield( 'title_layout' ) && get_cfield( 'title_layout' ) != '' ) {
  295. $title_layout = get_cfield( 'title_layout' );
  296. }
  297. if ( $title_layout == 'center' ) {
  298. $class .= ' main-center-title';
  299. } elseif ( $title_layout == 'right_breadcrumb' ) {
  300. $class .= ' main-right-breadcrumb';
  301. }
  302.  
  303.  
  304. $output = str_replace( '{title_data}', $title_data, $output );
  305. $output = str_replace( '{class}', $class, $output );
  306. $output = str_replace( '{title}', $title, $output );
  307. $output = str_replace( '{breadcrumb_data}', $breadcrumb_data, $output );
  308. $output = str_replace( '{extra}', $extra, $output );
  309. $output = str_replace( '{heading}', $heading, $output );
  310.  
  311. return $output;
  312. }
  313. }
  314.  
  315. /**
  316. * Prepare the title/breadcrumb area using hide/show site options
  317. *
  318. * @param integer $post_id
  319. *
  320. * @return array
  321. */
  322. function kleo_prepare_title( $post_id = null ) {
  323. $title_arr = array();
  324.  
  325. $title_arr['title'] = kleo_title();
  326.  
  327. //hide title?
  328. $title_arr['show_title'] = true;
  329. if ( get_cfield( 'title_checkbox', $post_id ) == 1 ) {
  330. $title_arr['show_title'] = false;
  331. }
  332. if ( sq_option( 'title_location', 'breadcrumb' ) == 'main' ) {
  333. $title_arr['show_title'] = false;
  334. }
  335.  
  336. //hide breadcrumb?
  337. $title_arr['show_breadcrumb'] = true;
  338. if ( sq_option( 'breadcrumb_status', 1 ) == 0 ) {
  339. $title_arr['show_breadcrumb'] = false;
  340. }
  341. if ( get_cfield( 'hide_breadcrumb', $post_id ) == 1 ) {
  342. $title_arr['show_breadcrumb'] = false;
  343. } else if ( get_cfield( 'hide_breadcrumb', $post_id ) === '0' ) {
  344. $title_arr['show_breadcrumb'] = true;
  345. }
  346.  
  347. //hide extra info?
  348. if ( get_cfield( 'hide_info', $post_id ) == 1 ) {
  349. $title_arr['extra'] = '';
  350. }
  351.  
  352. return $title_arr;
  353. }
  354.  
  355.  
  356. /***************************************************
  357. * TOP TOOLBAR - ADMIN BAR
  358. * Enable or disable the bar, depending of the theme option setting
  359. ***************************************************/
  360. if ( sq_option( 'admin_bar', 1 ) == '0' ):
  361. remove_action( 'wp_footer', 'wp_admin_bar_render', 1000 );
  362. add_filter( 'show_admin_bar', '__return_false' );
  363. endif;
  364.  
  365.  
  366. /***************************************************
  367. * :: MAINTENANCE MODE
  368. ***************************************************/
  369. if ( ! function_exists( 'kleo_maintenance_mode' ) ) {
  370. function kleo_maintenance_mode() {
  371.  
  372. $logo_path = apply_filters( 'kleo_logo', sq_option_url( 'logo' ) );
  373. $logo_img = '<img src="' . $logo_path . '" alt="maintenance" style="margin: 0 auto; display: block;" />';
  374.  
  375. if ( sq_option( 'maintenance_mode', 0 ) == 1 ) {
  376.  
  377. /* Theme My Login compatibility */
  378. if ( class_exists( 'Theme_My_Login' ) && Theme_My_Login::is_tml_page( 'login' ) ) {
  379. return;
  380. }
  381.  
  382. if ( ! current_user_can( 'edit_themes' ) || ! is_user_logged_in() ) {
  383. wp_die(
  384. $logo_img
  385. . '<div style="text-align:center">'
  386. . sq_option( 'maintenance_msg', '' )
  387. . '</div>',
  388. get_bloginfo( 'name' )
  389. );
  390. }
  391. }
  392. }
  393.  
  394. add_action( 'get_header', 'kleo_maintenance_mode' );
  395. }
  396.  
  397.  
  398. /***************************************************
  399. * :: Get social profiles
  400. ***************************************************/
  401.  
  402. if ( ! function_exists( 'kleo_get_social_profiles' ) ):
  403.  
  404. function kleo_get_social_profiles( $args = false ) {
  405. $output = '';
  406. $icons = '';
  407. $all_options = get_option( "kleo_" . KLEO_DOMAIN );
  408.  
  409. $defaults = array(
  410. 'container' => 'ul',
  411. 'item_tag' => 'li',
  412. 'target' => '_blank'
  413. );
  414. // Parse incomming $args into an array and merge it with $defaults
  415. $args = wp_parse_args( $args, $defaults );
  416. $args = apply_filters( 'kleo_get_social_profiles_args', $args );
  417.  
  418. //get social data from theme options
  419. if ( ! empty( $all_options ) ) {
  420. foreach ( $all_options as $k => $opt ) {
  421. if ( substr( $k, 0, 7 ) === 'social_' && ! empty( $opt ) ) {
  422. $k = str_replace( 'social_', '', $k );
  423. $title = str_replace(
  424. array( 'gplus', 'vimeo-squared', 'pinterest-circled', 'instagramm' ),
  425. array( 'Google+', 'Vimeo', 'Pinterest', 'Instagram' ),
  426. $k
  427. );
  428.  
  429. $icons .= '<' . $args['item_tag'] . '>';
  430. $icons .= '<a target="' . $args['target'] . '" href="' . $opt . '"><i class="icon-' . $k . '"></i><div class="ts-text">' . ucfirst( $title ) . '</div></a>';
  431. $icons .= '</' . $args['item_tag'] . '>';
  432. }
  433. }
  434. }
  435.  
  436. $icons = apply_filters( 'kleo_get_social_profiles', $icons );
  437. if ( $icons != '' ) {
  438. $output .= '<' . $args['container'] . ' class="kleo-social-icons">';
  439. $output .= $icons;
  440. $output .= '</' . $args['container'] . '>';
  441. }
  442.  
  443. return $output;
  444.  
  445. }
  446.  
  447. add_shortcode( 'kleo_social_icons', 'kleo_get_social_profiles' );
  448.  
  449. endif;
  450.  
  451.  
  452. /***************************************************
  453. * :: Ajax search in header main menu
  454. ***************************************************/
  455.  
  456. //if set from admin to show search
  457. if ( sq_option( 'ajax_search', 1 ) == 1 || sq_option( 'ajax_search', 1 ) == 'logged_in' ) {
  458. add_filter( 'wp_nav_menu_items', 'kleo_search_menu_item', 200, 2 );
  459. }
  460.  
  461. if ( ! function_exists( 'kleo_search_menu_item' ) ) {
  462. /**
  463. * Add search to menu
  464. *
  465. * @param string $items
  466. * @param object $args
  467. *
  468. * @return string
  469. */
  470. function kleo_search_menu_item( $items, $args ) {
  471. if ( sq_option( 'ajax_search', 1 ) == 'logged_in' && ! is_user_logged_in() ) {
  472. return $items;
  473. }
  474.  
  475. $location = sq_option( 'menu_search_location', 'primary' );
  476.  
  477. if ( $args->theme_location == $location ) {
  478. $form = kleo_get_search_menu_item();
  479. $items .= '<li id="nav-menu-item-search" class="menu-item kleo-search-nav">' . $form . '</li>';
  480. }
  481.  
  482. return $items;
  483. }
  484. }
  485.  
  486. /* Custom search form */
  487. if ( sq_option( 'header_custom_search', 0 ) == 1 && sq_option( 'header_search_form', '' ) != '' ) {
  488. add_filter( 'body_class', 'kleo_gsb_body_class' );
  489. if ( ! function_exists( 'kleo_get_search_menu_item' ) ) {
  490. function kleo_get_search_menu_item() {
  491. $output = '';
  492. $output .= '<a class="search-trigger" href="#"><i class="icon icon-search"></i></a>';
  493. $output .= '<div class="kleo-search-wrap searchHidden" id="ajax_search_container">';
  494. $output .= '<div class="gse-loading"></div>';
  495. $output .= sq_option( 'header_search_form', '' );
  496. $output .= '</div>';
  497.  
  498. return $output;
  499. }
  500. }
  501. }
  502.  
  503. function kleo_gsb_body_class( $classes ) {
  504. $classes[] = 'has-google-search-box';
  505. return $classes;
  506. }
  507.  
  508.  
  509. if ( ! function_exists( 'kleo_get_search_menu_item' ) ) {
  510.  
  511. function kleo_get_search_menu_item() {
  512.  
  513. $context = sq_option( 'search_context', '' );
  514. if ( is_array( $context ) ) {
  515. $context = implode( ',', $context );
  516. }
  517.  
  518. //Defaults
  519. $action = home_url( '/' );
  520. $hidden = '';
  521. $input_name = 's';
  522. if ( function_exists( 'bp_is_active' ) && $context == 'members' ) {
  523. //Buddypress members form link
  524. $action = bp_get_members_directory_permalink();
  525.  
  526. } elseif ( function_exists( 'bp_is_active' ) && bp_is_active( 'groups' ) && $context == 'groups' ) {
  527. //Buddypress group directory link
  528. $action = bp_get_groups_directory_permalink();
  529.  
  530. } elseif ( class_exists( 'bbPress' ) && $context == 'forum' ) {
  531. $action = bbp_get_search_url();
  532. $input_name = 'bbp_search';
  533.  
  534. } elseif ( $context == 'product' ) {
  535. $hidden .= '<input type="hidden" name="post_type" value="product">';
  536. $action = home_url( '/' ) . '?post_type=product';
  537. }
  538.  
  539.  
  540. ob_start();
  541. $value = isset( $_REQUEST['s'] ) ? esc_attr( $_REQUEST['s'] ) : '';
  542. $placeholder = esc_html__( "Start typing to search...", "kleo_framework" );
  543. ?>
  544. <a class="search-trigger" href="#"><i class="icon icon-search"></i></a>
  545. <div class="kleo-search-wrap searchHidden" id="ajax_search_container">
  546. <form class="form-inline" id="ajax_searchform" action="<?php echo $action; ?>"
  547. data-context="<?php echo $context; ?>">
  548. <?php echo $hidden; ?>
  549. <input name="<?php echo $input_name; ?>" class="ajax_s form-control" autocomplete="off" type="text"
  550. value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" required>
  551. <span class="kleo-ajax-search-loading"><i class="icon-spin6 animate-spin"></i></span>
  552. </form>
  553. <div class="kleo_ajax_results"></div>
  554. </div>
  555.  
  556. <?php
  557. $form = ob_get_clean();
  558.  
  559. return $form;
  560. }
  561. }
  562. //Catch ajax requests
  563. add_action( 'wp_ajax_kleo_ajax_search', 'kleo_ajax_search' );
  564. add_action( 'wp_ajax_nopriv_kleo_ajax_search', 'kleo_ajax_search' );
  565.  
  566. if ( ! function_exists( 'kleo_ajax_search' ) ) {
  567. function kleo_ajax_search() {
  568. //if "s" input is missing exit
  569. if ( empty( $_REQUEST['s'] ) && empty( $_REQUEST['bbp_search'] ) ) {
  570. die();
  571. }
  572.  
  573. if ( ! empty( $_REQUEST['bbp_search'] ) ) {
  574. $search_string = $_REQUEST['bbp_search'];
  575. } else {
  576. $search_string = $_REQUEST['s'];
  577. }
  578.  
  579. $output = '';
  580. $context = 'any';
  581. $defaults = array(
  582. 'numberposts' => 4,
  583. 'posts_per_page' => 20,
  584. 'post_type' => 'any',
  585. 'post_status' => 'publish',
  586. 'post_password' => '',
  587. 'suppress_filters' => false,
  588. 's' => $_REQUEST['s'],
  589. );
  590.  
  591. if ( isset( $_REQUEST['context'] ) && '' != $_REQUEST['context'] ) {
  592. $context = explode( ',', $_REQUEST['context'] );
  593. $defaults['post_type'] = $context;
  594. }
  595. //Remove forum since it is handled with a different function
  596. if ( ! empty( $defaults['post_type'] ) && is_array( $defaults['post_type'] ) ) {
  597. foreach ( $defaults['post_type'] as $ptk => $ptv ) {
  598. if ( 'forum' == $ptv ) {
  599. unset( $defaults['post_type'][ $ptk ] );
  600. break;
  601. }
  602. }
  603. }
  604. if ( empty( $defaults['post_type'] ) ) {
  605. $posts = null;
  606. } else {
  607.  
  608. $defaults = apply_filters( 'kleo_ajax_query_args', $defaults );
  609.  
  610. $the_query = new WP_Query( $defaults );
  611. $posts = $the_query->get_posts();
  612. }
  613.  
  614. $members = array();
  615. $members['total'] = 0;
  616. $groups = array();
  617. $groups['total'] = 0;
  618. $forums = false;
  619.  
  620.  
  621. if ( function_exists( 'bp_is_active' ) && ( $context == "any" || in_array( "members", $context ) ) ) {
  622. $members = bp_core_get_users( array(
  623. 'search_terms' => $search_string,
  624. 'per_page' => $defaults['numberposts'],
  625. 'populate_extras' => false,
  626. ) );
  627. }
  628.  
  629. if ( function_exists( 'bp_is_active' ) && bp_is_active( "groups" ) && ( $context == "any" || in_array( "groups", $context ) ) ) {
  630. $groups = groups_get_groups( array(
  631. 'search_terms' => $search_string,
  632. 'per_page' => $defaults['numberposts'],
  633. 'populate_extras' => false,
  634. ) );
  635. }
  636.  
  637. if ( class_exists( 'bbPress' ) && ( $context == "any" || in_array( "forum", $context ) ) ) {
  638. $forums = kleo_bbp_get_replies( $search_string );
  639. }
  640.  
  641.  
  642. //if there are no posts, groups nor members
  643. if ( empty( $posts ) && $members['total'] == 0 && $groups['total'] == 0 && ! $forums ) {
  644. $output = "<div class='kleo_ajax_entry ajax_not_found'>";
  645. $output .= "<div class='ajax_search_content'>";
  646. $output .= "<i class='icon icon-attention-circled'></i> ";
  647. $output .= __( "Sorry, we haven't found anything based on your criteria.", 'kleo_framework' );
  648. $output .= "<br>";
  649. $output .= __( "Please try searching by different terms.", 'kleo_framework' );
  650. $output .= "</div>";
  651. $output .= "</div>";
  652. echo $output;
  653. die();
  654. }
  655.  
  656. //if there are members
  657. if ( $members['total'] != 0 ) {
  658.  
  659. $output .= '<div class="kleo-ajax-part kleo-ajax-type-members">';
  660. $output .= '<h4><span>' . __( "Members", 'kleo_framework' ) . '</span></h4>';
  661. foreach ( (array) $members['users'] as $member ) {
  662. $image = '<img src="' . bp_core_fetch_avatar( array(
  663. 'item_id' => $member->ID,
  664. 'width' => 25,
  665. 'height' => 25,
  666. 'html' => false
  667. ) ) . '" class="kleo-rounded" alt="">';
  668. if ( $update = bp_get_user_meta( $member->ID, 'bp_latest_update', true ) ) {
  669. $latest_activity = char_trim( trim( strip_tags( bp_create_excerpt( $update['content'], 50, "..." ) ) ) );
  670. } else {
  671. $latest_activity = '';
  672. }
  673. $output .= "<div class ='kleo_ajax_entry'>";
  674. $output .= "<div class='ajax_search_image'>$image</div>";
  675. $output .= "<div class='ajax_search_content'>";
  676. $output .= "<a href='" . bp_core_get_user_domain( $member->ID ) . "' class='search_title'>";
  677. $output .= $member->display_name;
  678. $output .= "</a>";
  679. $output .= "<span class='search_excerpt'>";
  680. $output .= $latest_activity;
  681. $output .= "</span>";
  682. $output .= "</div>";
  683. $output .= "</div>";
  684. }
  685. $output .= "<a class='ajax_view_all' href='" . esc_url( bp_get_members_directory_permalink() . "?s=" . $search_string ) . "'>" . __( 'View member results', 'kleo_framework' ) . "</a>";
  686. $output .= "</div>";
  687. }
  688.  
  689. //if there are groups
  690. if ( $groups['total'] != 0 ) {
  691.  
  692. $output .= '<div class="kleo-ajax-part kleo-ajax-type-groups">';
  693. $output .= '<h4><span>' . __( "Groups", 'kleo_framework' ) . '</span></h4>';
  694. foreach ( (array) $groups['groups'] as $group ) {
  695. $image = '<img src="' . bp_core_fetch_avatar( array(
  696. 'item_id' => $group->id,
  697. 'object' => 'group',
  698. 'width' => 25,
  699. 'height' => 25,
  700. 'html' => false
  701. ) ) . '" class="kleo-rounded" alt="">';
  702. $output .= "<div class ='kleo_ajax_entry'>";
  703. $output .= "<div class='ajax_search_image'>$image</div>";
  704. $output .= "<div class='ajax_search_content'>";
  705. $output .= "<a href='" . bp_get_group_permalink( $group ) . "' class='search_title'>";
  706. $output .= $group->name;
  707. $output .= "</a>";
  708. $output .= "</div>";
  709. $output .= "</div>";
  710. }
  711. $output .= "<a class='ajax_view_all' href='" . esc_url( bp_get_groups_directory_permalink() . "?s=" . $search_string ) . "'>" . __( 'View group results', 'kleo_framework' ) . "</a>";
  712. $output .= "</div>";
  713. }
  714.  
  715. //if there are posts
  716. if ( ! empty( $posts ) ) {
  717. $post_type_str = array();
  718. $post_types = array();
  719. $post_type_obj = array();
  720. foreach ( $posts as $post ) {
  721. $post_types[ $post->post_type ][] = $post;
  722. if ( empty( $post_type_obj[ $post->post_type ] ) ) {
  723. $post_type_obj[ $post->post_type ] = get_post_type_object( $post->post_type );
  724. }
  725. }
  726.  
  727. foreach ( $post_types as $ptype => $post_type ) {
  728. $output .= '<div class="kleo-ajax-part kleo-ajax-type-' . esc_attr( $post_type_obj[ $ptype ]->name ) . '">';
  729. if ( isset( $post_type_obj[ $ptype ]->labels->name ) ) {
  730. $output .= "<h4><span>" . $post_type_obj[ $ptype ]->labels->name . "</span></h4>";
  731. } else {
  732. $output .= "<hr>";
  733. }
  734. $count = 0;
  735. foreach ( $post_type as $post ) {
  736.  
  737. $post_type_str[$post->post_type] = $post->post_type;
  738. $count ++;
  739. if ( $count > 4 ) {
  740. continue;
  741. }
  742. $format = get_post_format( $post->ID );
  743. if ( $img_url = kleo_get_post_thumbnail_url( $post->ID ) ) {
  744. $image = aq_resize( $img_url, 44, 44, true, true, true );
  745. if ( ! $image ) {
  746. $image = $img_url;
  747. }
  748. $image = '<img src="' . $image . '" class="kleo-rounded">';
  749. } else {
  750. if ( $format == 'video' ) {
  751. $image = "<i class='icon icon-video'></i>";
  752. } elseif ( $format == 'image' || $format == 'gallery' ) {
  753. $image = "<i class='icon icon-picture'></i>";
  754. } else {
  755. $image = "<i class='icon icon-link'></i>";
  756. }
  757. }
  758.  
  759. $excerpt = "";
  760.  
  761. if ( ! empty( $post->post_content ) ) {
  762. $excerpt = $post->post_content;
  763. $excerpt = preg_replace( "/\[(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", '', $excerpt );
  764. $excerpt = wp_strip_all_tags($excerpt); //added to remove gogole adsense code from search excerpt
  765. $excerpt = char_trim( trim( strip_tags( $excerpt ) ), 40, "..." );
  766. }
  767. $link = apply_filters( 'kleo_custom_url', get_permalink( $post->ID ) );
  768. $classes = "format-" . $format;
  769. $output .= "<div class ='kleo_ajax_entry $classes'>";
  770. $output .= "<div class='ajax_search_image'>$image</div>";
  771. $output .= "<div class='ajax_search_content'>";
  772. $output .= "<a href='$link' class='search_title'>";
  773. $output .= get_the_title( $post->ID );
  774. $output .= "</a>";
  775. $output .= "<span class='search_excerpt'>";
  776. $output .= $excerpt;
  777. $output .= "</span>";
  778. $output .= "</div>";
  779. $output .= "</div>";
  780. }
  781. $output .= '</div>';
  782. }
  783.  
  784. if ( ! empty( $post_type_str ) ) {
  785. if ( count( $post_type_str ) > 1 ) {
  786. $search_str_posts = '&post_type[]=' . implode( ',', $post_type_str );
  787. } else {
  788. $search_str_posts = '&post_type=' . implode( ',', $post_type_str );
  789. }
  790.  
  791. } else {
  792. $search_str_posts = '';
  793. }
  794.  
  795. $output .= "<a class='ajax_view_all' href='" . esc_url( home_url( '/' ) . '?s=' . $search_string ) . $search_str_posts . "'>" . __( 'View all results', 'kleo_framework' ) . "</a>";
  796. }
  797.  
  798. /* Forums topics search */
  799. if ( ! empty( $forums ) ) {
  800. $output .= '<div class="kleo-ajax-part kleo-ajax-type-forums">';
  801. $output .= '<h4><span>' . __( "Forums", 'kleo_framework' ) . '</span></h4>';
  802.  
  803. $i = 0;
  804. foreach ( $forums as $fk => $forum ) {
  805.  
  806. $i ++;
  807. if ( $i <= 4 ) {
  808. $image = "<i class='icon icon-chat-1'></i>";
  809.  
  810. $output .= "<div class ='kleo_ajax_entry'>";
  811. $output .= "<div class='ajax_search_image'>$image</div>";
  812. $output .= "<div class='ajax_search_content'>";
  813. $output .= "<a href='" . $forum['url'] . "' class='search_title'>";
  814. $output .= $forum['name'];
  815. $output .= "</a>";
  816. //$output .= "<span class='search_excerpt'>";
  817. //$output .= $latest_activity;
  818. //$output .= "</span>";
  819. $output .= "</div>";
  820. $output .= "</div>";
  821. }
  822. }
  823. $output .= "<a class='ajax_view_all' href='" . esc_url( bbp_get_search_url() . "?bbp_search=" . $search_string ) . "'>" . __( 'View forum results', 'kleo_framework' ) . "</a>";
  824. $output .= "</div>";
  825. }
  826.  
  827.  
  828. echo $output;
  829. die();
  830. }
  831. }
  832.  
  833. if ( ! function_exists( 'kleo_bbp_get_replies' ) ) {
  834. function kleo_bbp_get_replies( $title = '' ) {
  835. global $wpdb;
  836. $topic_matches = array();
  837.  
  838. /* First do a title search */
  839. $topics = $wpdb->get_results( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_title LIKE "%' . esc_sql( trim( $title ) ) . '%" AND post_type="topic" AND post_status="publish"' );
  840.  
  841. /* do a tag search if title search doesn't have results */
  842. if ( ! $topics ) {
  843. $topic_tags = get_terms( 'topic-tag' );
  844.  
  845. if ( empty( $topic_tags ) ) {
  846. return $topic_matches;
  847. }
  848.  
  849. foreach ( $topic_tags as $tid => $tag ) {
  850. $tags[ $tag->term_id ] = $tag->name;
  851. }
  852.  
  853. $tag_matches = kleo_bbp_stristr_array( $title, $tags );
  854.  
  855. $args = array(
  856. 'post_type' => 'topic',
  857. 'showposts' => - 1,
  858. 'tax_query' => array(
  859. array(
  860. 'taxonomy' => 'topic-tag',
  861. 'field' => 'term_id',
  862. 'terms' => $tag_matches
  863. )
  864. )
  865. );
  866.  
  867. $topics = get_posts( $args );
  868. }
  869.  
  870. /* Compile results into array*/
  871. foreach ( $topics as $topic ) {
  872. $topic_matches[ $topic->ID ]['name'] = $topic->post_title;
  873. $topic_matches[ $topic->ID ]['url'] = get_post_permalink( $topic->ID );
  874. }
  875.  
  876.  
  877. return $topic_matches;
  878.  
  879. }
  880. }
  881.  
  882. function kleo_bbp_stristr_array( $haystack, $needles ) {
  883.  
  884. $elements = array();
  885.  
  886.  
  887. foreach ( $needles as $id => $needle ) {
  888. if ( stristr( $haystack, $needle ) ) {
  889. $elements[] = $id;
  890. }
  891. }
  892.  
  893. return $elements;
  894. }
  895.  
  896.  
  897. /***************************************************
  898. * :: WPML language switch
  899. ***************************************************/
  900.  
  901. if ( ! function_exists( 'kleo_wpml_wp_nav_menu_items_filter' ) && function_exists( 'icl_get_languages' ) ) {
  902. function kleo_wpml_wp_nav_menu_items_filter( $items, $args ) {
  903. if ( $args->theme_location == 'primary' ) {
  904. $items = str_replace( '<a href="#" onclick="return false">', '<a href="#" class="js-activated">', $items );
  905. $items = str_replace( '</a><ul class="sub-menu submenu-languages">', '<span class="caret"></span></a><ul class="sub-menu submenu-languages dropdown-menu pull-left">', $items );
  906. }
  907.  
  908. return $items;
  909. }
  910.  
  911. add_filter( 'wp_nav_menu_items', 'kleo_wpml_wp_nav_menu_items_filter', 10, 2 );
  912. }
  913.  
  914. if ( ! function_exists( 'kleo_lang_menu_item' ) ):
  915.  
  916. function kleo_lang_menu_item( $items, $args ) {
  917. if ( $args->theme_location == 'top' ) {
  918. $items .= kleo_get_languages();
  919. }
  920.  
  921. return $items;
  922. }
  923.  
  924. endif;
  925.  
  926. if ( sq_option( 'show_lang', 1 ) == 1 ) {
  927. add_filter( 'wp_nav_menu_items', 'kleo_lang_menu_item', 10, 2 );
  928. }
  929.  
  930. function kleo_get_languages() {
  931.  
  932. global $sitepress_settings;
  933. $output = '';
  934. $active = '';
  935. $items = '';
  936.  
  937. if ( function_exists( 'icl_get_languages' ) ) {
  938. $languages = icl_get_languages( 'skip_missing=0&orderby=code' );
  939.  
  940. if ( ! empty( $languages ) ) {
  941. foreach ( $languages as $code => $lang ) {
  942.  
  943. $items .= '<li>';
  944.  
  945. $alt_title_lang = $sitepress_settings['icl_lso_native_lang'] ? esc_attr( $lang['native_name'] ) : esc_attr( $lang['translated_name'] );
  946.  
  947. $entry = '';
  948.  
  949. if ( $sitepress_settings['icl_lso_flags'] ) {
  950. $entry .= '<img class="iclflag" src="' . $lang['country_flag_url'] . '" width="18" height="12" alt="' . $alt_title_lang . '" title="' . $alt_title_lang . '" /> ';
  951. }
  952. if ( $sitepress_settings['icl_lso_native_lang'] ) {
  953. $entry .= $lang['native_name'];
  954. }
  955. if ( $sitepress_settings['icl_lso_display_lang'] && $sitepress_settings['icl_lso_native_lang'] ) {
  956. $entry .= ' (';
  957. }
  958. if ( $sitepress_settings['icl_lso_display_lang'] ) {
  959. $entry .= $lang['translated_name'];
  960. }
  961. if ( $sitepress_settings['icl_lso_display_lang'] && $sitepress_settings['icl_lso_native_lang'] ) {
  962. $entry .= ')';
  963. }
  964.  
  965.  
  966. if ( ! $lang['active'] ) {
  967. $items .= '<a href="' . $lang['url'] . '">' . $entry . '</a>';
  968. } else {
  969. $active = '<a href="' . $lang['url'] . '" class="dropdown-toggle js-activated current-language" data-toggle="dropdown">' . $entry . ( count( $languages ) > 1 ? ' <span class="caret"></span>' : '' ) . '</a>';
  970. }
  971.  
  972. $items .= '</li>';
  973. }
  974. }
  975.  
  976. $output .= ' <li class="' . ( count( $languages ) > 1 ? 'dropdown' : '' ) . ' kleo-langs">'
  977. . $active
  978. . '<ul class="dropdown-menu pull-right">'
  979. . $items
  980. . '</ul></li>';
  981. }
  982.  
  983. return $output;
  984. }
  985.  
  986.  
  987. /***************************************************
  988. * :: Go up button
  989. ***************************************************/
  990. function kleo_go_up() {
  991. ?>
  992. <a class="kleo-go-top" href="#"><i class="icon-up-open-big"></i></a>
  993. <?php
  994. }
  995.  
  996. if ( sq_option( 'go_top', 1 ) == 1 ) {
  997. add_action( 'kleo_after_footer', 'kleo_go_up' );
  998. }
  999.  
  1000.  
  1001. /***************************************************
  1002. * :: Bottom contact form
  1003. ***************************************************/
  1004.  
  1005. if ( ! function_exists( 'kleo_contact_form' ) ) {
  1006. function kleo_contact_form( $atts, $content = null ) {
  1007. extract( shortcode_atts( array(
  1008. 'title' => 'CONTACT US',
  1009. 'builtin_form' => 1
  1010. ), $atts ) );
  1011.  
  1012. $output = '';
  1013.  
  1014. $output .= '<div class="kleo-quick-contact-wrapper">'
  1015. . '<a class="kleo-quick-contact-link" href="#"><i class="icon-mail-alt"></i></a>'
  1016. . '<div id="kleo-quick-contact">'
  1017. . '<h4 class="kleo-qc-title">' . $title . '</h4>'
  1018. . '<p>' . do_shortcode( $content ) . '</p>';
  1019. if ( $builtin_form == 1 ) {
  1020. $output .= '<form class="kleo-contact-form" action="#" method="post" novalidate>'
  1021. . '<input type="text" placeholder="' . __( "Your Name", 'kleo_framework' ) . '" required id="contact_name" name="contact_name" class="form-control" value="" tabindex="276" />'
  1022. . '<input type="email" required placeholder="' . __( "Your Email", 'kleo_framework' ) . '" id="contact_email" name="contact_email" class="form-control" value="" tabindex="277" />'
  1023. . '<textarea placeholder="' . __( "Type your message...", 'kleo_framework' ) . '" required id="contact_content" name="contact_content" class="form-control" tabindex="278"></textarea>'
  1024. . '<input type="hidden" name="action" value="kleo_sendmail">'
  1025. . '<button tabindex="279" class="btn btn-default pull-right" type="submit">' . __( "Send", 'kleo_framework' ) . '</button>'
  1026. . '<div class="kleo-contact-loading">' . __( "Sending", 'kleo_framework' ) . ' <i class="icon-spinner icon-spin icon-large"></i></div>'
  1027. . '<div class="kleo-contact-success"> </div>'
  1028. . '</form>';
  1029. }
  1030. $output .= '<div class="bottom-arrow"></div>'
  1031. . '</div>'
  1032. . '</div><!--end kleo-quick-contact-wrapper-->';
  1033.  
  1034. return $output;
  1035. }
  1036.  
  1037. add_shortcode( 'kleo_contact_form', 'kleo_contact_form' );
  1038. }
  1039.  
  1040.  
  1041. if ( ! function_exists( 'kleo_sendmail' ) ):
  1042. function kleo_sendmail() {
  1043. if ( isset( $_POST['action'] ) ) {
  1044.  
  1045. $error_tpl = "<span class='mail-error'>%s</span>";
  1046.  
  1047. //contact name
  1048. if ( trim( $_POST['contact_name'] ) === '' ) {
  1049. printf( $error_tpl, __( 'Please enter your name.', 'kleo_framework' ) );
  1050. die();
  1051. } else {
  1052. $name = trim( $_POST['contact_name'] );
  1053. }
  1054.  
  1055. ///contact email
  1056. if ( trim( $_POST['contact_email'] ) === '' ) {
  1057. printf( $error_tpl, __( 'Please enter your email address.', 'kleo_framework' ) );
  1058. die();
  1059. } elseif ( ! preg_match( "/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+.[a-z]{2,4}$/i", trim( $_POST['contact_email'] ) ) ) {
  1060. printf( $error_tpl, __( 'You entered an invalid email address.', 'kleo_framework' ) );
  1061. die();
  1062. } else {
  1063. $email = trim( $_POST['contact_email'] );
  1064. }
  1065.  
  1066. //message
  1067. if ( trim( $_POST['contact_content'] ) === '' ) {
  1068. printf( $error_tpl, __( 'Please enter a message.', 'kleo_framework' ) );
  1069. die();
  1070. } else {
  1071. if ( function_exists( 'stripslashes' ) ) {
  1072. $comment = stripslashes( trim( $_POST['contact_content'] ) );
  1073. } else {
  1074. $comment = trim( $_POST['contact_content'] );
  1075. }
  1076. }
  1077.  
  1078. $emailTo = sq_option( 'contact_form_to', '' );
  1079. if ( ! isset( $emailTo ) || ( $emailTo == '' ) ) {
  1080. $emailTo = get_option( 'admin_email' );
  1081. }
  1082.  
  1083. $subject = __( 'Contact Form Message', 'kleo_framework' );
  1084. apply_filters( 'kleo_contact_form_subject', $subject );
  1085.  
  1086. $body = __( "You received a new contact form message:", 'kleo_framework' ) . "\n";
  1087. $body .= __( "Name: ", 'kleo_framework' ) . $name . "\n";
  1088. $body .= __( "Email: ", 'kleo_framework' ) . $email . "\n";
  1089. $body .= __( "Message: ", 'kleo_framework' ) . $comment . "\n";
  1090.  
  1091. $headers[] = "Content-type: text/html";
  1092. $headers[] = "Reply-To: $name <$email>";
  1093. apply_filters( 'kleo_contact_form_headers', $headers );
  1094.  
  1095. if ( wp_mail( $emailTo, $subject, $body, $headers ) ) {
  1096. echo '<span class="mail-success">' . __( "Thank you. Your message has been sent.", 'kleo_framework' ) . ' <i class="icon-ok icon-large"></i></span>';
  1097.  
  1098. do_action( 'kleo_after_contact_form_mail_send', $name, $email, $comment );
  1099. } else {
  1100. printf( $error_tpl, __( "Mail couldn't be sent. Please try again!", 'kleo_framework' ) );
  1101. }
  1102.  
  1103. } else {
  1104. printf( $error_tpl, __( "Unknown error occurred. Please try again!", 'kleo_framework' ) );
  1105. }
  1106. die();
  1107. }
  1108. endif;
  1109.  
  1110.  
  1111. function kleo_show_contact_form() {
  1112. $title = sq_option( 'contact_form_title', '' );
  1113. $content = sq_option( 'contact_form_text', '' );
  1114. $builtin_form = sq_option( 'contact_form_builtin', 1 );
  1115.  
  1116. echo do_shortcode( '[kleo_contact_form title="' . $title . '" builtin_form="' . $builtin_form . '"]' . $content . '[/kleo_contact_form]' );
  1117. }
  1118.  
  1119. if ( sq_option( 'contact_form', 1 ) == 1 ) {
  1120. add_action( 'wp_ajax_kleo_sendmail', 'kleo_sendmail' );
  1121. add_action( 'wp_ajax_nopriv_kleo_sendmail', 'kleo_sendmail' );
  1122. add_action( 'kleo_after_footer', 'kleo_show_contact_form' );
  1123. }
  1124.  
  1125.  
  1126. /***************************************************
  1127. * :: SOCKET AREA
  1128. ***************************************************/
  1129. function kleo_show_socket() {
  1130. get_template_part( 'page-parts/socket' );
  1131. }
  1132.  
  1133. if ( sq_option( 'socket_enable', 1 ) == 1 ) {
  1134. add_action( 'kleo_after_footer', 'kleo_show_socket' );
  1135. }
  1136.  
  1137.  
  1138. /***************************************************
  1139. * :: EXCERPT
  1140. ***************************************************/
  1141.  
  1142. if ( ! function_exists( 'kleo_new_excerpt_length' ) ) {
  1143. function kleo_new_excerpt_length( $length ) {
  1144. return 60;
  1145. }
  1146.  
  1147. add_filter( 'excerpt_length', 'kleo_new_excerpt_length' );
  1148. }
  1149.  
  1150. if ( ! function_exists( 'kleo_excerpt' ) ) {
  1151. function kleo_excerpt( $limit = 20, $words = true ) {
  1152.  
  1153. $from_content = false;
  1154. $excerpt_initial = get_the_excerpt();
  1155.  
  1156. if ( $excerpt_initial == '' ) {
  1157. $excerpt_initial = get_the_content();
  1158. $from_content = true;
  1159. }
  1160. $excerpt_initial = preg_replace( '`\[[^\]]*\]`', '', $excerpt_initial );
  1161. $excerpt_initial = strip_tags( $excerpt_initial );
  1162.  
  1163. /* If we got it from get_the_content -> apply length restriction */
  1164. if ( $from_content ) {
  1165. $excerpt_length = apply_filters( 'excerpt_length', $limit );
  1166. $excerpt_initial = wp_trim_words( $excerpt_initial, $excerpt_length, '' );
  1167. }
  1168.  
  1169. if ( $words ) {
  1170. $excerpt = explode( ' ', $excerpt_initial, $limit );
  1171. if ( count( $excerpt ) >= $limit ) {
  1172. array_pop( $excerpt );
  1173. $excerpt = implode( " ", $excerpt ) . '...';
  1174. } else {
  1175. $excerpt = implode( " ", $excerpt ) . '';
  1176. }
  1177. } else {
  1178. $excerpt = substr( $excerpt_initial, 0, $limit ) . ( strlen( $excerpt_initial ) > $limit ? '...' : '' );
  1179. }
  1180.  
  1181. return '<p>' . $excerpt . '</p>';
  1182. }
  1183. }
  1184.  
  1185.  
  1186. if ( ! function_exists( 'kleo_has_shortcode' ) ) {
  1187. function kleo_has_shortcode( $shortcode = '', $post_id = null ) {
  1188.  
  1189. if ( ! $post_id ) {
  1190. if ( ! is_singular() ) {
  1191. return false;
  1192. }
  1193. $post_id = get_the_ID();
  1194. }
  1195.  
  1196. if ( is_page() || is_single() ) {
  1197. $current_post = get_post( $post_id );
  1198.  
  1199. if ( post_password_required( $current_post ) ) {
  1200. return false;
  1201. }
  1202.  
  1203. //remove_filter( 'the_content', 'do_shortcode', 11 );
  1204. //$post_content = apply_filters( 'the_content', $current_post->post_content );
  1205. $post_content = $current_post->post_content;
  1206. //add_filter( 'the_content', 'do_shortcode', 11 );
  1207.  
  1208. $found = false;
  1209.  
  1210. if ( ! $shortcode ) {
  1211. return $found;
  1212. }
  1213.  
  1214. if ( stripos( $post_content, '[' . $shortcode ) !== false ) {
  1215. $found = true;
  1216. }
  1217.  
  1218. return $found;
  1219. } else {
  1220. return false;
  1221. }
  1222. }
  1223. }
  1224.  
  1225. if ( ! function_exists( 'kleo_icons_array' ) ) {
  1226. function kleo_icons_array( $prefix = '', $before = array( '' ) ) {
  1227.  
  1228. // Get any existing copy of our transient data
  1229. $transient_name = 'kleo_font_icons_' . $prefix . implode( '', $before );
  1230.  
  1231. if ( false === ( $icons = get_transient( $transient_name ) ) ) {
  1232.  
  1233. // It wasn't there, so regenerate the data and save the transient
  1234. $icons = $before;
  1235.  
  1236. $icons_json = file_get_contents( THEME_DIR . '/assets/font/config.json' );
  1237. if ( is_child_theme() && file_exists( CHILD_THEME_DIR . '/assets/css/fontello.css' ) ) {
  1238. $icons_json = file_get_contents( CHILD_THEME_DIR . '/assets/config.json' );
  1239. }
  1240.  
  1241. if ( $icons_json ) {
  1242. $arr = json_decode( $icons_json, true );
  1243. foreach ( $arr['glyphs'] as $icon ) {
  1244. if ( ( isset( $icon['selected'] ) && $icon['selected'] == true ) || ! isset( $icon['selected'] ) ) {
  1245. $icons[ $prefix . $icon['css'] ] = $icon['css'];
  1246. }
  1247. }
  1248. asort( $icons );
  1249. }
  1250.  
  1251. // set transient for one day
  1252. set_transient( $transient_name, $icons, 86400 );
  1253. }
  1254.  
  1255. return $icons;
  1256. }
  1257. }
  1258. add_action( 'kleo-opts-saved', 'kleo_delete_font_transient' );
  1259. function kleo_delete_font_transient() {
  1260. delete_transient( 'kleo_font_icons_' );
  1261. }
  1262.  
  1263. if ( ! function_exists( 'kleo_post_nav' ) ) :
  1264. /**
  1265. * Display navigation to next/previous post when applicable.
  1266. *
  1267. * @since Kleo 1.0
  1268. *
  1269. * @return void
  1270. */
  1271. function kleo_post_nav( $same_cat = false ) {
  1272. // Don't print empty markup if there's nowhere to navigate.
  1273. $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( $same_cat, '', true );
  1274. $next = get_adjacent_post( $same_cat, '', false );
  1275.  
  1276. if ( ! $next && ! $previous ) {
  1277. return;
  1278. }
  1279. ?>
  1280.  
  1281. <nav class="pagination-sticky member-navigation" role="navigation">
  1282. <?php
  1283. if ( is_attachment() ) :
  1284. previous_post_link( '%link', __( '<span id="older-nav">Go to article</span>', 'kleo_framework' ) );
  1285. else :
  1286. if ( $previous ) {
  1287. previous_post_link( '%link', '<span id="older-nav"><span class="outter-title"><span class="entry-title">' . $previous->post_title . '</span></span></span>', $same_cat );
  1288. }
  1289. if ( $next ) {
  1290. next_post_link( '%link', '<span id="newer-nav"><span class="outter-title"><span class="entry-title">' . $next->post_title . '</span>', $same_cat );
  1291. }
  1292. endif;
  1293. ?>
  1294. </nav><!-- .navigation -->
  1295.  
  1296. <?php
  1297. }
  1298. endif;
  1299.  
  1300. if ( ! function_exists( 'kleo_postmeta_enabled' ) ) {
  1301. /**
  1302. * Check to see if post meta is enabled for a single post
  1303. * @return int
  1304. */
  1305. function kleo_postmeta_enabled() {
  1306.  
  1307. if ( ! is_single() ) {
  1308. return 1;
  1309. }
  1310.  
  1311. /* If we set it via a shortcode */
  1312. global $kleo_config;
  1313. if ( isset( $kleo_config['post_meta_enabled'] ) ) {
  1314. if ( $kleo_config['post_meta_enabled'] ) {
  1315. return 1;
  1316. } else {
  1317. return 0;
  1318. }
  1319. }
  1320.  
  1321. $meta_status = sq_option( 'blog_meta_status', 1 );
  1322.  
  1323. if ( get_cfield( 'meta_checkbox' ) == 1 ) {
  1324. $meta_status = 0;
  1325. }
  1326.  
  1327. return apply_filters( 'kleo_postmeta_enabled', $meta_status );
  1328. }
  1329. }
  1330.  
  1331.  
  1332. /**
  1333. * Check to see if post media is enabled for a single post page
  1334. *
  1335. * @param string media_option
  1336. * @param int default
  1337. *
  1338. * @return int
  1339. */
  1340. function kleo_postmedia_enabled( $media_option = 'blog_media_status', $default = 1, $is_singular = false ) {
  1341.  
  1342.  
  1343. global $conditional_thumb;
  1344. global $wp_query;
  1345.  
  1346. if ( $is_singular === true ) {
  1347. $condition = is_singular();
  1348. } else {
  1349. $condition = is_single();
  1350. }
  1351.  
  1352.  
  1353. if ( ! $condition ) {
  1354.  
  1355. //check for shortcode thumbnail condition
  1356. if ( isset( $conditional_thumb ) ) {
  1357. if ( $wp_query->current_post > ( $conditional_thumb - 1 ) ) {
  1358. return false;
  1359. }
  1360. }
  1361.  
  1362. return 1;
  1363. }
  1364.  
  1365. $media_status = sq_option( $media_option, $default );
  1366. $post_status = get_cfield( 'post_media_status' );
  1367.  
  1368. if ( $post_status != '' ) {
  1369. $media_status = get_cfield( 'post_media_status' );
  1370. }
  1371.  
  1372. return $media_status;
  1373. }
  1374.  
  1375. if ( ! function_exists( 'kleo_get_img_overlay' ) ) {
  1376.  
  1377. function kleo_get_img_overlay() {
  1378. global $kleo_config;
  1379.  
  1380. if ( isset( $kleo_config['image_overlay'] ) ) {
  1381. return $kleo_config['image_overlay'];
  1382. }
  1383.  
  1384. return '';
  1385. }
  1386.  
  1387. }
  1388.  
  1389.  
  1390. /***************************************************
  1391. * :: Facebook Integration
  1392. ***************************************************/
  1393.  
  1394. if ( ! function_exists( 'kleo_fb_button' ) ) :
  1395. function kleo_fb_button() {
  1396. echo kleo_get_fb_button();
  1397. }
  1398. endif;
  1399. if ( ! function_exists( 'kleo_get_fb_button' ) ) :
  1400. function kleo_get_fb_button() {
  1401. ob_start();
  1402. ?>
  1403. <div class="kleo-fb-wrapper text-center">
  1404. <a href="#" class="kleo-facebook-connect btn btn-default "><i class="icon-facebook"></i>
  1405. &nbsp;<?php _e( "Log in with Facebook", 'kleo_framework' ); ?></a>
  1406. </div>
  1407. <div class="gap-20"></div>
  1408. <div class="hr-title hr-full"><abbr> <?php echo __( "or", "kleo_framework" ); ?> </abbr></div>
  1409. <?php
  1410.  
  1411. $output = ob_get_clean();
  1412.  
  1413. return $output;
  1414. }
  1415. endif;
  1416.  
  1417. if ( ! function_exists( 'kleo_fb_button_regpage' ) ) :
  1418. function kleo_fb_button_regpage() {
  1419. echo kleo_get_fb_button_regpage();
  1420. }
  1421. endif;
  1422. if ( ! function_exists( 'kleo_get_fb_button_regpage' ) ) :
  1423. function kleo_get_fb_button_regpage() {
  1424. ob_start();
  1425. ?>
  1426. <div class="kleo-fb-wrapper text-center">
  1427. <a href="#" class="kleo-facebook-connect btn btn-default "><i class="icon-facebook"></i>
  1428. &nbsp;<?php _e( "Log in with Facebook", 'kleo_framework' ); ?></a>
  1429. </div>
  1430. <div class="gap-30"></div>
  1431. <div class="hr-title hr-full"><abbr> <?php echo __( "or", "kleo_framework" ); ?> </abbr></div>
  1432. <div class="gap-10"></div>
  1433. <?php
  1434. $output = ob_get_clean();
  1435.  
  1436. return $output;
  1437. }
  1438. endif;
  1439.  
  1440. if ( ! function_exists( 'kleo_fb_button_shortcode' ) ) :
  1441. function kleo_fb_button_shortcode() {
  1442. $output = '';
  1443. if ( sq_option( 'facebook_login', 0 ) == 1 && get_option( 'users_can_register' ) && ! is_user_logged_in() ) {
  1444. $output .= '<a href="#" class="kleo-facebook-connect btn btn-default "><i class="icon-facebook"></i> &nbsp; ' . __( "Log in with Facebook", 'kleo_framework' ) . '</a>';
  1445. }
  1446.  
  1447. return $output;
  1448. }
  1449.  
  1450. add_shortcode( 'kleo_fb_button', 'kleo_fb_button_shortcode' );
  1451. endif;
  1452.  
  1453. if ( sq_option( 'facebook_login', 0 ) == 1 ) {
  1454. add_action( 'bp_before_login_widget_loggedout', 'kleo_fb_button' );
  1455. add_action( 'login_form', 'kleo_fb_button', 10 );
  1456. add_action( 'kleo_before_login_form', 'kleo_fb_button', 10 );
  1457. add_action( 'kleo_before_register_form_modal', 'kleo_fb_button', 10 );
  1458.  
  1459. if ( class_exists( 'WooCommerce' ) ) {
  1460. add_action( 'woocommerce_login_form_start', 'kleo_fb_button', 10 );
  1461. }
  1462.  
  1463. if ( sq_option( 'facebook_register', 0 ) == 1 ) {
  1464. add_action( 'bp_before_register_page', 'kleo_fb_button_regpage' );
  1465. }
  1466. }
  1467.  
  1468.  
  1469. /***************************************************
  1470. * :: oEmbed manipulation for youtube/vimeo video
  1471. ***************************************************/
  1472.  
  1473. if ( ! function_exists( 'kleo_add_video_wmode_transparent' ) ) :
  1474. /**
  1475. * Automatically add wmode=transparent to embeded media
  1476. * Automatically add showinfo=0 for youtube
  1477. *
  1478. * @param type $html
  1479. * @param type $url
  1480. * @param type $attr
  1481. *
  1482. * @return type
  1483. */
  1484. function kleo_add_video_wmode_transparent( $html, $url, $attr ) {
  1485. if ( strpos( $html, "youtube.com" ) !== null || strpos( $html, "youtu.be" ) !== null ) {
  1486. $info = "&amp;showinfo=0";
  1487. } else {
  1488. $info = "";
  1489. }
  1490.  
  1491. if ( strpos( $html, "<embed src=" ) !== false ) {
  1492. return str_replace( '</param><embed', '</param><param name="wmode" value="opaque"></param><embed wmode="opaque" ', $html );
  1493. } elseif ( strpos( $html, 'feature=oembed' ) !== false ) {
  1494. return str_replace( 'feature=oembed', 'feature=oembed&amp;wmode=opaque' . $info, $html );
  1495. } else {
  1496. return $html;
  1497. }
  1498. }
  1499. endif;
  1500.  
  1501. add_filter( 'oembed_result', 'kleo_add_video_wmode_transparent', 10, 3 );
  1502.  
  1503. if ( ! function_exists( 'kleo_oembed_filter' ) ):
  1504. function kleo_oembed_filter( $return, $data, $url ) {
  1505. $return = str_replace( 'frameborder="0"', 'style="border: none"', $return );
  1506.  
  1507. return $return;
  1508. }
  1509. endif;
  1510.  
  1511. add_filter( 'oembed_dataparse', 'kleo_oembed_filter', 90, 3 );
  1512.  
  1513.  
  1514. /***************************************************
  1515. * :: Apply oEmbed for post video format
  1516. ***************************************************/
  1517. global $wp_embed;
  1518. add_filter( 'kleo_oembed_video', array( $wp_embed, 'autoembed' ), 8 );
  1519.  
  1520.  
  1521. /***************************************************
  1522. * :: Custom taxonomy header content
  1523. ***************************************************/
  1524.  
  1525. if ( function_exists( 'get_term_meta' ) ) {
  1526.  
  1527. /* GET CUSTOM HEADER CONTENT FOR CATEGORY */
  1528. add_action( 'kleo_before_main', 'kleo_taxonomy_header', 9 );
  1529.  
  1530. function kleo_taxonomy_header() {
  1531. $queried_object = get_queried_object();
  1532. if ( isset( $queried_object->term_id ) ) {
  1533.  
  1534. $term_id = $queried_object->term_id;
  1535. $content = get_term_meta( $term_id, 'cat_meta' );
  1536.  
  1537. if ( isset( $content[0]['cat_header'] ) && $content[0]['cat_header'] != '' ) {
  1538. echo '<section class="kleo-cat-header container-wrap main-color">';
  1539. echo do_shortcode( $content[0]['cat_header'] );
  1540. echo '</section>';
  1541. }
  1542. }
  1543. }
  1544.  
  1545. /* ADD CUSTOM META BOX TO CATEGORY PAGES */
  1546. function kleo_taxonomy_edit_meta_field( $term ) {
  1547. // put the term ID into a variable
  1548. $t_id = $term->term_id;
  1549. // retrieve the existing value(s) for this meta field. This returns an array
  1550. $term_meta = get_term_meta( $t_id, 'cat_meta' );
  1551. if ( ! $term_meta ) {
  1552. $term_meta = add_term_meta( $t_id, 'cat_meta', '' );
  1553. }
  1554. ?>
  1555. <tr class="form-field">
  1556. <th scope="row" valign="top"><label
  1557. for="term_meta[cat_header]"><?php _e( 'Top Content', 'kleo_framework' ); ?></label></th>
  1558. <td>
  1559. <?php
  1560. $content = ( isset( $term_meta[0]['cat_header'] ) && $term_meta[0]['cat_header'] != '' ) ? esc_attr( $term_meta[0]['cat_header'] ) : '';
  1561. echo '<textarea id="term_meta[cat_header]" name="term_meta[cat_header]">' . $content . '</textarea>'; ?>
  1562. <p class="description"><?php _e( 'This will be displayed at top of the category page. Shortcodes are allowed.', 'kleo_framework' ); ?></p>
  1563. </td>
  1564. </tr>
  1565. <?php
  1566. }
  1567.  
  1568. add_action( 'product_cat_edit_form_fields', 'kleo_taxonomy_edit_meta_field', 10, 2 );
  1569.  
  1570. /* SAVE CUSTOM META*/
  1571. /**
  1572. * @param $term_id
  1573. */
  1574. function kleo_save_taxonomy_custom_meta( $term_id ) {
  1575. if ( isset( $_POST['term_meta'] ) ) {
  1576. $t_id = $term_id;
  1577. $term_meta = get_term_meta( $t_id, 'cat_meta' );
  1578. $cat_keys = array_keys( $_POST['term_meta'] );
  1579. foreach ( $cat_keys as $key ) {
  1580. if ( isset ( $_POST['term_meta'][ $key ] ) ) {
  1581. $term_meta[ $key ] = $_POST['term_meta'][ $key ];
  1582. }
  1583. }
  1584. // Save the option array.
  1585. update_term_meta( $term_id, 'cat_meta', $term_meta );
  1586.  
  1587. }
  1588. }
  1589.  
  1590. add_action( 'edited_product_cat', 'kleo_save_taxonomy_custom_meta', 10, 2 );
  1591. }
  1592.  
  1593.  
  1594. /***************************************************
  1595. * :: Add custom HTML to page header set from Page edit
  1596. ***************************************************/
  1597.  
  1598. add_action( 'kleo_before_main', 'kleo_header_content', 8 );
  1599.  
  1600. function kleo_header_content() {
  1601. if ( is_singular() || is_home() ) {
  1602. $page_header = get_cfield( 'header_content' );
  1603. if ( $page_header != '' ) {
  1604. echo '<section class="kleo-page-header container-wrap main-color">';
  1605. echo do_shortcode( html_entity_decode( $page_header ) );
  1606. echo '</section>';
  1607. }
  1608. } else {
  1609. return false;
  1610. }
  1611. }
  1612.  
  1613.  
  1614. /***************************************************
  1615. * :: Add custom HTML to bottom page set from Page edit
  1616. ***************************************************/
  1617.  
  1618. add_action( 'kleo_after_main_content', 'kleo_bottom_content', 12 );
  1619.  
  1620. function kleo_bottom_content() {
  1621. if ( is_singular() || is_home() ) {
  1622. $page_bottom = get_cfield( 'bottom_content' );
  1623. if ( $page_bottom != '' ) {
  1624. echo '<div class="kleo-page-bottom">';
  1625. echo do_shortcode( html_entity_decode( $page_bottom ) );
  1626. echo '</div>';
  1627. }
  1628. } else {
  1629. return false;
  1630. }
  1631. }
  1632.  
  1633.  
  1634. /***************************************************
  1635. * :: rtMedia small compatibility
  1636. ***************************************************/
  1637.  
  1638. if ( class_exists( 'RTMedia' ) ) {
  1639. add_action( 'wp_enqueue_scripts', 'kleo_rtmedia_scripts', 999 );
  1640.  
  1641. function kleo_rtmedia_scripts() {
  1642. //wp_dequeue_style('rtmedia-font-awesome');
  1643. wp_dequeue_style( 'rtmedia-magnific' );
  1644. wp_dequeue_script( 'rtmedia-magnific' );
  1645. wp_dequeue_script( 'rtmedia-touchswipe' );
  1646. }
  1647.  
  1648. add_filter( 'body_class', 'kleo_rtmedia_class' );
  1649. function kleo_rtmedia_class( $classes ) {
  1650. $classes[] = 'rtm-' . RTMEDIA_VERSION;
  1651.  
  1652. return $classes;
  1653. }
  1654.  
  1655. global $rtmedia_admin;
  1656. remove_action( 'admin_notices', array( $rtmedia_admin, 'rtmedia_admin_notices' ) );
  1657.  
  1658. /* When BuddyPress is not enabled */
  1659. function kleo_rtmedia_no_buddypress() {
  1660. return locate_template( 'page.php' );
  1661. }
  1662. add_filter( 'rtmedia_main_template_include', 'kleo_rtmedia_no_buddypress', 20 );
  1663.  
  1664. }
  1665.  
  1666.  
  1667. /***************************************************
  1668. * :: WP Multisite Sign-up page
  1669. ***************************************************/
  1670. add_action( 'before_signup_form', 'kleo_mu_before_page' );
  1671. function kleo_mu_before_page() {
  1672. get_template_part( 'page-parts/general-before-wrap' );
  1673. }
  1674.  
  1675. add_action( 'after_signup_form', 'kleo_mu_after_page' );
  1676. function kleo_mu_after_page() {
  1677. get_template_part( 'page-parts/general-after-wrap' );
  1678. echo '<style>'
  1679. . '.mu_register input[type="submit"], .mu_register #blog_title, .mu_register #user_email, .mu_register #blogname, .mu_register #user_name {font-size: inherit;}'
  1680. . '.mu_register input[type="submit"] {width: auto;}'
  1681. . '</style>'
  1682. . '<script>jQuery(document).ready(function() { jQuery(\'.mu_register input[type="submit"]\').addClass("btn btn-default"); });</script>';
  1683.  
  1684. }
  1685.  
  1686. /***************************************************
  1687. * :: WP Multisite Activate page
  1688. ***************************************************/
  1689. if ( defined( 'WP_INSTALLING' ) && WP_INSTALLING == true ) {
  1690. add_action( 'kleo_before_main', 'kleo_mu_before_page' );
  1691. add_action( 'kleo_after_main', 'kleo_mu_after_page' );
  1692. }
  1693.  
  1694.  
  1695.  
  1696. /**
  1697. * GET CUSTOM POST TYPE TAXONOMY LIST
  1698. */
  1699. function kleo_get_category_list( $category_name, $filter = 0, $category_child = "" ) {
  1700.  
  1701. if ( $category_child != "" && $category_child != "All" ) {
  1702.  
  1703. $childcategory = get_term_by( 'slug', $category_child, $category_name );
  1704. $get_category = get_categories( array( 'taxonomy' => $category_name, 'child_of' => $childcategory->term_id ) );
  1705. $category_list = array( '0' => 'All' );
  1706.  
  1707. foreach ( $get_category as $category ) {
  1708. if ( isset( $category->cat_name ) ) {
  1709. $category_list[] = $category->slug;
  1710. }
  1711. }
  1712.  
  1713. return $category_list;
  1714.  
  1715. } else {
  1716. if ( ! $filter ) {
  1717.  
  1718. $get_category = get_categories( array( 'taxonomy' => $category_name ) );
  1719. $category_list = array( '0' => 'All' );
  1720.  
  1721. foreach ( $get_category as $category ) {
  1722. if ( isset( $category->slug ) ) {
  1723. $category_list[] = $category->slug;
  1724. }
  1725. }
  1726.  
  1727. return $category_list;
  1728.  
  1729. } else {
  1730. $get_category = get_categories( array( 'taxonomy' => $category_name ) );
  1731. $category_list = array( '0' => 'All' );
  1732.  
  1733. foreach ( $get_category as $category ) {
  1734. if ( isset( $category->cat_name ) ) {
  1735. $category_list[] = $category->cat_name;
  1736. }
  1737. }
  1738.  
  1739. return $category_list;
  1740. }
  1741.  
  1742. }
  1743. }
  1744.  
  1745. function kleo_get_category_list_key_array( $category_name, $key = 'slug' ) {
  1746.  
  1747. $get_category = get_categories( array( 'taxonomy' => $category_name ) );
  1748. $category_list = array( 'all' => 'All' );
  1749.  
  1750. foreach ( $get_category as $category ) {
  1751. if ( isset( $category->{$key} ) ) {
  1752. $category_list[ $category->{$key} ] = $category->cat_name;
  1753. }
  1754. }
  1755.  
  1756. return $category_list;
  1757. }
  1758.  
  1759.  
  1760. /***************************************************
  1761. * :: Custom main menu select for each page
  1762. ***************************************************/
  1763. if ( ! is_admin() ) {
  1764. add_filter( 'wp_nav_menu_args', 'kleo_set_custom_menu' );
  1765. }
  1766. function kleo_set_custom_menu( $args = '' ) {
  1767.  
  1768. if ( 'primary' != $args['theme_location'] && 'secondary' != $args['theme_location'] ) {
  1769. return $args;
  1770. }
  1771.  
  1772. global $post;
  1773.  
  1774. if ( ! empty( $post ) ) {
  1775.  
  1776. if ( 'primary' == $args['theme_location'] ) {
  1777. $menuslug = get_cfield( 'page_menu', $post->ID );
  1778.  
  1779. if ( ! empty( $menuslug ) && $menuslug != 'default' && is_nav_menu( $menuslug ) ) {
  1780. $args['menu'] = $menuslug;
  1781.  
  1782. }
  1783.  
  1784. } elseif ( 'secondary' == $args['theme_location'] ) {
  1785.  
  1786. $sec_menuslug = get_cfield( 'page_menu_secondary', $post->ID );
  1787.  
  1788. if ( ! empty( $sec_menuslug ) && $sec_menuslug != 'default' && is_nav_menu( $sec_menuslug ) ) {
  1789. $args['menu'] = $sec_menuslug;
  1790. }
  1791.  
  1792. }
  1793.  
  1794. } // END if(!empty($post))
  1795.  
  1796. return $args;
  1797. } // END function kleo_set_custom_menu($args = '')
  1798.  
  1799.  
  1800. /***************************************************
  1801. * :: SIDE MENU
  1802. ***************************************************/
  1803.  
  1804. //if set from admin to show side button
  1805. if ( sq_option( 'side_menu', 0 ) == 1 ) {
  1806.  
  1807. if ( sq_option( 'side_menu_button', 0 ) == 1 ) {
  1808. add_filter( 'wp_nav_menu_items', 'kleo_side_menu_button', 20, 2 );
  1809. }
  1810.  
  1811. add_filter( 'body_class', 'kleo_offcanvas_classes' );
  1812. add_action( 'kleo_after_page', 'kleo_show_side_menu' );
  1813. }
  1814.  
  1815. if ( ! function_exists( 'kleo_side_menu_button' ) ) {
  1816. /**
  1817. * Add side button to menu
  1818. *
  1819. * @param string $items
  1820. * @param object $args
  1821. *
  1822. * @return string
  1823. */
  1824. function kleo_side_menu_button( $items, $args ) {
  1825. if ( $args->theme_location == 'primary' ) {
  1826. $items .= '<li id="nav-menu-item-side" class="menu-item">' .
  1827. '<a href="#" class="open-sidebar" onclick="javascript:return false;">' .
  1828. '<i class="icon-menu"></i>' .
  1829. '</a>' .
  1830. '</li>';
  1831. }
  1832.  
  1833. return $items;
  1834. }
  1835. }
  1836.  
  1837. function kleo_show_side_menu() {
  1838. $side_menu = wp_nav_menu( array(
  1839. 'theme_location' => 'side',
  1840. 'depth' => 3,
  1841. 'container' => '',
  1842. 'menu_class' => 'offcanvas-menu',
  1843. 'fallback_cb' => '',
  1844. 'walker' => new kleo_walker_nav_menu(),
  1845. 'echo' => false
  1846. )
  1847. );
  1848. echo '<div class="offcanvas-sidebar side-color">' .
  1849. '<div class="wrap-canvas-menu">' .
  1850. '<div class="offcanvas-title">' .
  1851. '<a href="#" class="open-sidebar"></a>' .
  1852. '</div>' .
  1853. '<div class="offcanvas-before">' . do_shortcode( sq_option( 'side_menu_before' ) ) . '</div>' .
  1854. '<div class="widget_nav_menu">' .
  1855. $side_menu .
  1856. '</div>' .
  1857. '<div class="offcanvas-after">' . do_shortcode( sq_option( 'side_menu_after' ) ) . '</div>' .
  1858. '</div>' .
  1859. '</div>';
  1860. }
  1861.  
  1862.  
  1863. function kleo_offcanvas_classes( $classes = '' ) {
  1864.  
  1865. if ( sq_option( 'side_menu', 0 ) == 1 ) {
  1866. $classes[] = 'offcanvas-' . sq_option( 'side_menu_position', 'left' );
  1867. $classes[] = 'offcanvas-type-' . sq_option( 'side_menu_type', 'default' );
  1868. }
  1869.  
  1870. return $classes;
  1871.  
  1872. }
  1873.  
  1874.  
  1875. /***************************************************
  1876. * :: BLOG CUSTOMISATIONS
  1877. ***************************************************/
  1878.  
  1879. if ( ! function_exists( 'kleo_view_switch' ) ) {
  1880. /**
  1881. * Show post layout type switcher
  1882. *
  1883. * @param array $layouts
  1884. * @param string $active
  1885. * @param string $identifier
  1886. */
  1887. function kleo_view_switch( $layouts, $active = '', $identifier = '' ) {
  1888.  
  1889. echo '<div class="kleo-view-switch" data-identifier="' . $identifier . '">' .
  1890. '<ul>';
  1891.  
  1892. foreach ( $layouts as $layout ) {
  1893.  
  1894. $selected = '';
  1895. if ( $active == $layout ) {
  1896. $selected = ' active';
  1897. }
  1898. echo '<li><span data-type="' . $layout . '" class="switch-' . $layout . $selected . '"></span></li>';
  1899. }
  1900.  
  1901. echo '</ul>' .
  1902. '</div>' .
  1903. '<div class="clearfix"></div>';
  1904.  
  1905. ?>
  1906.  
  1907. <?php
  1908. }
  1909. }
  1910.  
  1911. /**
  1912. * Return the blog layout from visitor Cookie
  1913. *
  1914. * @param string $layout
  1915. * @param string $identifier
  1916. *
  1917. * @return string
  1918. */
  1919. function kleo_post_grid_layout( $layout = '', $identifier = '' ) {
  1920. $cookie_name = 'kleo-blog-layout' . $identifier;
  1921. if ( isset( $_COOKIE[ $cookie_name ] ) && $_COOKIE[ $cookie_name ] != '' ) {
  1922. $layout = $_COOKIE[ $cookie_name ];
  1923. }
  1924.  
  1925. if ( function_exists( 'get_term_meta' ) ) {
  1926. if ( is_category() ) {
  1927.  
  1928. global $kleo_config;
  1929. $layouts = $kleo_config['blog_layouts'];
  1930. $category = get_category( get_query_var( 'cat' ) );
  1931. $category_meta = get_term_meta( $category->term_id, 'kleo_category_display_type' );
  1932.  
  1933. if ( isset( $category_meta[0] ) && isset( $layouts[ $category_meta[0] ] ) ) {
  1934. $layout = $category_meta[0];
  1935. }
  1936.  
  1937. }
  1938. }
  1939.  
  1940. return $layout;
  1941. }
  1942.  
  1943. add_filter( 'kleo_blog_type', 'kleo_post_grid_layout', 10, 2 );
  1944.  
  1945.  
  1946. /***************************************************
  1947. * :: Let it Snow
  1948. ***************************************************/
  1949.  
  1950. function kleo_site_snow() {
  1951. echo do_shortcode( '[kleo_snow scope="window"]' );
  1952. }
  1953.  
  1954. if ( sq_option( 'let_it_snow', 0 ) == 1 ) {
  1955. add_action( 'kleo_after_page', 'kleo_site_snow' );
  1956. }
  1957.  
  1958.  
  1959. /**
  1960. * Get current post format for posts
  1961. * or custom media settings as post format for custom post type
  1962. * @return mixed|string
  1963. */
  1964. function kleo_get_post_format() {
  1965. if ( get_post_type() == 'portfolio' ) {
  1966. if ( get_cfield( 'media_type' ) && get_cfield( 'media_type' ) != '' ) {
  1967. $media_type = get_cfield( 'media_type' );
  1968. switch ( $media_type ) {
  1969. case 'slider':
  1970. $kleo_post_format = 'gallery';
  1971. break;
  1972.  
  1973. case 'video':
  1974. case 'hosted_video':
  1975. $kleo_post_format = 'video';
  1976. break;
  1977. }
  1978. }
  1979.  
  1980. return $kleo_post_format;
  1981. } else {
  1982. return get_post_format();
  1983. }
  1984. }
  1985.  
  1986.  
  1987. /**
  1988. * Return the URL as requested on the current page load by the user agent.
  1989. *
  1990. * @since KLEO (2.4)
  1991. *
  1992. * @return string Requested URL string.
  1993. */
  1994. function kleo_get_requested_url() {
  1995. $url = is_ssl() ? 'https://' : 'http://';
  1996. $url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  1997.  
  1998. return apply_filters( 'kleo_get_requested_url', esc_url( $url ) );
  1999. }
  2000.  
  2001.  
  2002. /***************************************************
  2003. * :: Profile placeholder in menu for bbPress or Buddypress
  2004. ***************************************************/
  2005.  
  2006. add_filter( 'walker_nav_menu_start_el', 'kleo_bp_replace_placeholders' );
  2007.  
  2008. function kleo_bp_replace_placeholders( $output ) {
  2009.  
  2010. $initial_output = $output;
  2011.  
  2012. if ( strpos( $output, '##profile_link##' ) !== false ) {
  2013.  
  2014. if ( ! is_user_logged_in() ) {
  2015. return '';
  2016. }
  2017.  
  2018. if ( function_exists( 'bp_is_active' ) ) {
  2019. $logged_in_link = bp_loggedin_user_domain();
  2020. $output = str_replace( '##profile_link##', $logged_in_link, $output );
  2021. } elseif ( class_exists( 'bbPress' ) ) {
  2022. $logged_in_link = bbp_get_user_profile_url( bbp_get_current_user_id() );
  2023. $output = str_replace( '##profile_link##', $logged_in_link, $output );
  2024. }
  2025. }
  2026.  
  2027. if ( strpos( $output, '##member_name##' ) !== false ) {
  2028.  
  2029. if ( ! is_user_logged_in() ) {
  2030. return '';
  2031. }
  2032. if ( function_exists( 'bp_is_active' ) ) {
  2033. $logged_in_username = bp_get_loggedin_user_fullname();
  2034. $output = str_replace( '##member_name##', $logged_in_username, $output );
  2035. } elseif ( class_exists( 'bbPress' ) ) {
  2036. $logged_in_username = bbp_get_user_nicename( bbp_get_current_user_id() );
  2037. $output = str_replace( '##member_name##', $logged_in_username, $output );
  2038. }
  2039.  
  2040. }
  2041. if( is_user_logged_in() ){
  2042.  
  2043. $current_user_firstname = wp_get_current_user()->user_firstname;
  2044. if ($current_user_firstname) {
  2045. $output = str_replace('##member_first_name##', $current_user_firstname, $output);
  2046. }
  2047. $current_user_lastname = wp_get_current_user()->user_lastname;
  2048. if ($current_user_lastname) {
  2049. $output = str_replace('##member_last_name##', $current_user_lastname, $output);
  2050. }
  2051. }
  2052.  
  2053. $output = apply_filters( 'kleo_bp_replace_placeholders', $output, $initial_output );
  2054.  
  2055. return $output;
  2056. }
  2057.  
  2058.  
  2059. /***************************************************
  2060. * :: Custom redirect from Theme options - Miscellaneous
  2061. ***************************************************/
  2062.  
  2063. if ( sq_option( 'login_redirect', 'default' ) == 'custom' && sq_option( 'login_redirect_custom', '' ) != '' ) {
  2064. add_filter( 'login_redirect', 'kleo_custom_redirect', 12 );
  2065. }
  2066.  
  2067. function kleo_custom_redirect() {
  2068.  
  2069. $redirect_to = sq_option( 'login_redirect_custom', '' );
  2070.  
  2071. return $redirect_to;
  2072. }
  2073.  
  2074. if ( ! function_exists( 'kleo_get_post_media' ) ) {
  2075. /**
  2076. * Return post media by format
  2077. *
  2078. * @param $post_format
  2079. * @param $options
  2080. *
  2081. * @return string
  2082. *
  2083. * @since 3.0
  2084. */
  2085. function kleo_get_post_media( $post_format = 'standard', $options = array() ) {
  2086.  
  2087. global $kleo_config;
  2088.  
  2089. if ( isset( $options['icons'] ) && $options['icons'] ) {
  2090. $icons = true;
  2091. } else {
  2092. $icons = false;
  2093. }
  2094.  
  2095. if ( isset( $options['media_width'] ) && isset( $options['media_height'] ) ) {
  2096. $media_width = $options['media_width'];
  2097. $media_height = $options['media_height'];
  2098. } else {
  2099. $media_width = $kleo_config['post_gallery_img_width'];
  2100. $media_height = $kleo_config['post_gallery_img_height'];
  2101. }
  2102.  
  2103. $output = '';
  2104.  
  2105. switch ( $post_format ) {
  2106.  
  2107. case 'video':
  2108.  
  2109. //oEmbed video
  2110. $video = get_cfield( 'embed' );
  2111. // video bg self hosted
  2112. $bg_video_args = array();
  2113. $k_video = '';
  2114.  
  2115. if ( get_cfield( 'video_mp4' ) ) {
  2116. $bg_video_args['mp4'] = get_cfield( 'video_mp4' );
  2117. }
  2118. if ( get_cfield( 'video_ogv' ) ) {
  2119. $bg_video_args['ogv'] = get_cfield( 'video_ogv' );
  2120. }
  2121. if ( get_cfield( 'video_webm' ) ) {
  2122. $bg_video_args['webm'] = get_cfield( 'video_webm' );
  2123. }
  2124.  
  2125. if ( ! empty( $bg_video_args ) ) {
  2126. $attr_strings = array(
  2127. 'preload="none"'
  2128. );
  2129.  
  2130. if ( get_cfield( 'video_poster' ) ) {
  2131. $attr_strings[] = 'poster="' . get_cfield( 'video_poster' ) . '"';
  2132. }
  2133.  
  2134. $k_video .= '<div class="kleo-video-wrap"><video ' . join( ' ', $attr_strings ) . ' controls="controls" class="kleo-video" style="width: 100%; height: 100%;">';
  2135.  
  2136. $source = '<source type="%s" src="%s" />';
  2137. foreach ( $bg_video_args as $video_type => $video_src ) {
  2138. $video_type = wp_check_filetype( $video_src, wp_get_mime_types() );
  2139. $k_video .= sprintf( $source, $video_type['type'], esc_url( $video_src ) );
  2140. }
  2141.  
  2142. $k_video .= '</video></div>';
  2143.  
  2144. $output .= $k_video;
  2145. } // oEmbed
  2146. elseif ( ! empty( $video ) ) {
  2147. global $wp_embed;
  2148. $output .= apply_filters( 'kleo_oembed_video', $video );
  2149. }
  2150.  
  2151. break;
  2152.  
  2153. case 'audio':
  2154.  
  2155. $audio = get_cfield( 'audio' );
  2156.  
  2157. if ( ! empty( $audio ) ) {
  2158. $output .=
  2159. '<div class="post-audio">' .
  2160. '<audio preload="none" class="kleo-audio" id="audio_' . get_the_ID() . '" style="width:100%;" src="' . $audio . '"></audio>' .
  2161. '</div>';
  2162. }
  2163. break;
  2164.  
  2165. case 'gallery':
  2166.  
  2167. $slides = get_cfield( 'slider' );
  2168.  
  2169. $output .= '<div class="kleo-banner-slider">'
  2170. . '<div class="kleo-banner-items" >';
  2171.  
  2172. if ( $slides ) {
  2173. foreach ( $slides as $slide ) {
  2174. if ( $slide ) {
  2175. $image = aq_resize( $slide, $media_width, $media_height, true, true, true );
  2176. //small hack for non-hosted images
  2177. if ( ! $image ) {
  2178. $image = $slide;
  2179. }
  2180. $output .= '<article>
  2181. <a href="' . $slide . '" data-rel="modalPhoto[inner-gallery]">
  2182. <img src="' . $image . '" alt="' . get_the_title() . '">'
  2183. . kleo_get_img_overlay()
  2184. . '</a>
  2185. </article>';
  2186. }
  2187. }
  2188. }
  2189.  
  2190. $output .= '</div>'
  2191. . '<a href="#" class="kleo-banner-prev"><i class="icon-angle-left"></i></a>'
  2192. . '<a href="#" class="kleo-banner-next"><i class="icon-angle-right"></i></a>'
  2193. . '<div class="kleo-banner-features-pager carousel-pager"></div>'
  2194. . '</div>';
  2195.  
  2196. break;
  2197.  
  2198.  
  2199. case 'aside':
  2200. if ( $icons ) {
  2201. $output .= '<div class="post-format-icon"><i class="icon icon-doc"></i></div>';
  2202. }
  2203. break;
  2204.  
  2205. case 'link':
  2206. if ( $icons ) {
  2207. $output .= '<div class="post-format-icon"><i class="icon icon-link"></i></div>';
  2208. }
  2209. break;
  2210.  
  2211. case 'quote':
  2212. if ( $icons ) {
  2213. $output .= '<div class="post-format-icon"><i class="icon icon-quote-right"></i></div>';
  2214. }
  2215. break;
  2216.  
  2217. case 'image':
  2218. default:
  2219. if ( kleo_get_post_thumbnail_url() != '' ) {
  2220. $output .= '<div class="post-image">';
  2221.  
  2222. $img_url = kleo_get_post_thumbnail_url();
  2223. $image = aq_resize( $img_url, $media_width, $media_height, true, true, true );
  2224. if ( ! $image ) {
  2225. $image = $img_url;
  2226. }
  2227. $output .= '<a href="' . get_permalink() . '" class="element-wrap">'
  2228. . '<img src="' . $image . '" alt="' . get_the_title() . '">'
  2229. . kleo_get_img_overlay()
  2230. . '</a>';
  2231.  
  2232. $output .= '</div><!--end post-image-->';
  2233. } elseif ( $icons ) {
  2234. $post_icon = $post_format == 'image' ? 'picture' : 'doc';
  2235. $output .= '<div class="post-format-icon"><i class="icon icon-' . $post_icon . '"></i></div>';
  2236. }
  2237.  
  2238. break;
  2239. }
  2240.  
  2241. return $output;
  2242. }
  2243. }
  2244.  
  2245.  
  2246. /***************************************************
  2247. * :: Custom taxonomy category template
  2248. ***************************************************/
  2249.  
  2250. if ( function_exists( 'get_term_meta' ) ) {
  2251.  
  2252. function kleo_category_display_type_form( $category = false ) {
  2253.  
  2254. global $kleo_config;
  2255. $layouts = array_merge( $kleo_config['blog_layouts'], array( 'kb' => 'Knowledge Base' ) );
  2256. $category_layout = '';
  2257.  
  2258. if ( $category && is_object( $category ) ) {
  2259. $category_id = $category->term_id;
  2260. $category_meta = get_term_meta( $category_id, 'kleo_category_display_type' );
  2261. if ( isset( $category_meta[0] ) && isset( $layouts[ $category_meta[0] ] ) ) {
  2262. $category_layout = $category_meta[0];
  2263. }
  2264. }
  2265.  
  2266. ?>
  2267. <tr class="form-field">
  2268. <th scope="row" valign="top"><label
  2269. for="kleo_category_display_type"><?php _e( 'Display type', 'kleo_framework' ); ?></label></th>
  2270. <td>
  2271. <div class="form-field term-meta-wrap">
  2272. <select id="kleo_category_display_type" name="kleo_category_display_type">
  2273. <option value=""><?php _e( 'Use default display type', 'kleo_framework' ); ?></option>
  2274. <?php foreach ( $layouts as $layout => $layout_name ) { ?>
  2275. <option
  2276. value="<?php echo esc_attr( $layout ); ?>" <?php echo( $layout == $category_layout ? 'selected="selected"' : '' ); ?>><?php echo esc_html( $layout_name ); ?></option>
  2277. <?php } ?>
  2278. </select>
  2279. <p class="description"><?php _e( 'The "Display type" will override the default display layout for each category in part.', 'kleo_framework' ); ?></p>
  2280. </div>
  2281. </td>
  2282. </tr>
  2283. <?php
  2284.  
  2285. }
  2286.  
  2287. add_action( 'category_add_form_fields', 'kleo_category_display_type_form' );
  2288. add_action( 'category_edit_form_fields', 'kleo_category_display_type_form' );
  2289.  
  2290. function kleo_category_display_type_save( $category_id ) {
  2291.  
  2292. if ( isset( $_POST['kleo_category_display_type'] ) ) {
  2293.  
  2294. global $kleo_config;
  2295. $layouts = array_merge( $kleo_config['blog_layouts'], array( 'kb' => 'Knowledge Base' ) );
  2296. $category_layout = esc_attr( $_POST['kleo_category_display_type'] );
  2297.  
  2298. if ( isset( $layouts[ $category_layout ] ) ) {
  2299. update_term_meta( $category_id, 'kleo_category_display_type', $category_layout );
  2300. } else {
  2301. delete_term_meta( $category_id, 'kleo_category_display_type' );
  2302. }
  2303.  
  2304. }
  2305.  
  2306. }
  2307.  
  2308. add_action( 'created_category', 'kleo_category_display_type_save' );
  2309. add_action( 'edited_category', 'kleo_category_display_type_save' );
  2310.  
  2311. function kleo_category_display_type_template( $template ) {
  2312. if ( is_category() ) {
  2313.  
  2314. $category = get_category( get_query_var( 'cat' ) );
  2315. $category_meta = get_term_meta( $category->term_id, 'kleo_category_display_type' );
  2316.  
  2317. if ( isset( $category_meta[0] ) && $category_meta[0] == 'kb' && locate_template( 'page-parts/posts-layout-kb.php' ) ) {
  2318. return locate_template( 'page-parts/posts-layout-kb.php' );
  2319. }
  2320.  
  2321. }
  2322.  
  2323. return $template;
  2324. }
  2325.  
  2326. add_filter( 'template_include', 'kleo_category_display_type_template' );
  2327.  
  2328. }
  2329.  
  2330.  
  2331. /***************************************************
  2332. * :: Allow site layout overriding at page/post level
  2333. ***************************************************/
  2334.  
  2335. function kleo_custom_site_style( $style ) {
  2336. if ( is_singular() ) {
  2337. $page_style = get_cfield( 'site_style' );
  2338. if ( $page_style ) {
  2339. $style = $page_style == 'boxed' ? ' page-boxed' : '';
  2340. }
  2341. }
  2342. if ( $style == ' page-boxed' ) {
  2343. add_filter( 'body_class', 'kleo_boxed_bg_body_class' );
  2344. }
  2345.  
  2346. return $style;
  2347. }
  2348.  
  2349. add_filter( 'kleo_site_style', 'kleo_custom_site_style' );
  2350.  
  2351. function kleo_boxed_bg_body_class( $classes ) {
  2352. $classes[] = 'page-boxed-bg';
  2353.  
  2354. return $classes;
  2355. }
  2356.  
  2357.  
  2358. /***************************************************
  2359. * :: Blog tags in footer
  2360. ***************************************************/
  2361.  
  2362. function kleo_show_post_tags( $content ) {
  2363. if ( is_single() ) {
  2364. $tag_list = get_the_tag_list( '', __( ', ', 'kleo_framework' ) );
  2365. if ( isset( $tag_list ) && $tag_list ) {
  2366. $tags_array = explode( ',', $tag_list );
  2367.  
  2368. $tag_html = '';
  2369. foreach ( $tags_array as $tag ) {
  2370. $tag_html .= '<span class="label label-default">' . $tag . '</span> ';
  2371. }
  2372. $content .= esc_html__( 'Tags: ', 'kleo_framework' ) . $tag_html;
  2373. }
  2374. }
  2375.  
  2376. return $content;
  2377. }
  2378.  
  2379. if ( sq_option( 'blog_tags_footer', 0 ) ) {
  2380. add_action( 'the_content', 'kleo_show_post_tags', 20 );
  2381. }
  2382.  
  2383.  
  2384. /*
  2385. * Force URLs in srcset attributes into HTTPS scheme.
  2386. * This is particularly useful when you're running a Flexible SSL frontend like Cloudflare
  2387. */
  2388. function ssl_srcset( $sources ) {
  2389. if ( is_ssl() ) {
  2390. foreach ( $sources as &$source ) {
  2391. $source['url'] = set_url_scheme( $source['url'], 'https' );
  2392. }
  2393. }
  2394.  
  2395. return $sources;
  2396. }
  2397.  
  2398. add_filter( 'wp_calculate_image_srcset', 'ssl_srcset' );
  2399.  
  2400.  
  2401. /***************************************************
  2402. * :: Manage custom page redirects
  2403. ***************************************************/
  2404.  
  2405. function kleo_template_redirect() {
  2406. if ( is_user_logged_in() ) {
  2407. $homepage_redirect = sq_option( 'homepage_redirect', 'disabled' );
  2408. if ( is_front_page() && ( $homepage_redirect == 'profile' || $homepage_redirect == 'custom' ) ) {
  2409. if ( function_exists( 'bp_is_active' ) ) {
  2410. $logged_in_link = bp_loggedin_user_domain( '/' );
  2411. } elseif ( class_exists( 'bbPress' ) ) {
  2412. $logged_in_link = bbp_get_user_profile_url( bbp_get_current_user_id() );
  2413. } else {
  2414. $logged_in_link = home_url( 'author' );
  2415. }
  2416.  
  2417. if ( $homepage_redirect == 'profile' ) {
  2418. wp_redirect( $logged_in_link );
  2419. }
  2420. if ( $homepage_redirect == 'custom' ) {
  2421. $homepage_redirect_custom = sq_option( 'homepage_redirect_custom', $logged_in_link );
  2422. if ( strpos( $homepage_redirect_custom, '##profile_link##' ) !== false ) {
  2423. $homepage_redirect_custom = str_replace( '##profile_link##', $logged_in_link, $homepage_redirect_custom );
  2424. }
  2425. wp_redirect( $homepage_redirect_custom );
  2426. }
  2427. exit;
  2428. }
  2429. }
  2430. }
  2431.  
  2432. add_action( 'template_redirect', 'kleo_template_redirect' );
  2433.  
  2434.  
  2435. /**
  2436. * Remove hentry class from pages to stop google structured data errors
  2437. *
  2438. * @param array $classes
  2439. *
  2440. * @return array
  2441. */
  2442. function kleo_remove_hentry_on_pages( $classes ) {
  2443. if ( is_page() && ! ( function_exists( 'bp_is_group_forum_topic' ) && bp_is_group_forum_topic() ) ) {
  2444. $classes = array_diff( $classes, array( 'hentry' ) );
  2445. }
  2446.  
  2447. return $classes;
  2448. }
  2449.  
  2450. add_filter( 'post_class', 'kleo_remove_hentry_on_pages' );
  2451.  
  2452.  
  2453. /* Re-enable theme auto-update for Go Pricing Tables */
  2454. add_action( 'admin_init', 'kleo_go_pricing_enable_updates', 11 );
  2455.  
  2456. function kleo_go_pricing_enable_updates() {
  2457. if ( class_exists( 'GW_GoPricing_Update' ) ) {
  2458. remove_filter( 'pre_set_site_transient_update_plugins', array(
  2459. GW_GoPricing_Update::instance(),
  2460. 'check_update'
  2461. ) );
  2462. remove_filter( 'plugins_api', array( GW_GoPricing_Update::instance(), 'update_info' ), 10, 3 );
  2463. }
  2464. }
  2465.  
  2466.  
  2467. if ( sq_option( 'mobile_app_capable', 1 ) ) {
  2468. add_action( 'wp_head', 'kleo_add_mobile_app_capable_tag' );
  2469. }
  2470. function kleo_add_mobile_app_capable_tag() {
  2471. ?>
  2472. <meta name="mobile-web-app-capable" content="yes">
  2473. <?php
  2474. }
  2475.  
  2476. if ( sq_option( 'apple_mobile_app_capable', 1 ) ) {
  2477. add_action( 'wp_head', 'kleo_add_apple_mobile_app_capable_tag' );
  2478. }
  2479. function kleo_add_apple_mobile_app_capable_tag() {
  2480. ?>
  2481. <meta name="apple-mobile-web-app-capable" content="yes">
  2482. <?php
  2483. }
  2484.  
  2485.  
  2486. if ( sq_option( 'meta_theme_color', '' ) != '' && sq_option( 'meta_theme_color', '' ) != 'transparent' ) {
  2487. add_action( 'wp_head', 'kleo_add_meta_color' );
  2488. }
  2489. function kleo_add_meta_color() {
  2490. ?>
  2491. <!-- Chrome, Firefox OS and Opera -->
  2492. <meta name="theme-color" content="<?php echo sq_option( 'meta_theme_color', '' ); ?>">
  2493. <!-- Windows Phone -->
  2494. <meta name="msapplication-navbutton-color" content="<?php echo sq_option( 'meta_theme_color', '' ); ?>">
  2495. <!-- Safari -->
  2496. <meta name="apple-mobile-web-app-status-bar-style" content="<?php echo sq_option( 'meta_theme_color', '' ); ?>">
  2497. <?php
  2498. }
  2499.  
  2500.  
  2501. /* Schema org for body */
  2502. if ( ! function_exists( 'kleo_get_schema_org_markup' ) ) {
  2503.  
  2504. function kleo_get_schema_org_markup() {
  2505. $schema = 'http://schema.org/';
  2506. if ( is_singular( 'post' ) ) {
  2507. $type = "Article";
  2508. } elseif ( is_singular( 'portfolio' ) ) {
  2509. $type = "VisualArtwork";
  2510. } else if (bp_is_user()) {
  2511. $type = 'ProfilePage';
  2512. } else {
  2513. if ( is_author() ) {
  2514. $type = 'ProfilePage';
  2515. } // Is search results page
  2516. elseif ( is_search() ) {
  2517. $type = 'SearchResultsPage';
  2518. } else {
  2519. $type = 'WebPage';
  2520. }
  2521. }
  2522.  
  2523. $type = apply_filters( 'kleo_schema_org_type', $type );
  2524.  
  2525. return 'itemscope itemtype="' . $schema . $type . '"';
  2526. }
  2527.  
  2528. }
  2529.  
  2530. function kleo_schema_org_markup() {
  2531. echo kleo_get_schema_org_markup();
  2532. }
  2533.  
  2534.  
  2535. /**
  2536. *
  2537. * Override header layout at page level
  2538. *
  2539. * @param $output
  2540. * @param $option
  2541. *
  2542. * @return bool|mixed
  2543. */
  2544. function kleo_override_header_layout( $output, $option ) {
  2545. if ( $option == 'header_layout' ) {
  2546. $output = get_cfield( 'header_layout' );
  2547. }
  2548.  
  2549. return $output;
  2550. }
  2551.  
  2552.  
  2553. /* Remove blog posts from main blog loop */
  2554. if ( sq_option( 'blog_exclude_cat' ) ) {
  2555. function sq_exclude_blog_category( $query ) {
  2556. $to_exclude = sq_option( 'blog_exclude_cat' );
  2557. if ( ! empty( $to_exclude ) && is_array( $to_exclude ) ) {
  2558. if ( $query->is_home() && $query->is_main_query() ) {
  2559. $query->set( 'category__not_in', $to_exclude );
  2560. }
  2561. }
  2562. }
  2563.  
  2564. add_action( 'pre_get_posts', 'sq_exclude_blog_category' );
  2565. }
  2566.  
  2567. /* Tag cloud font size */
  2568. if ( sq_option( 'blog_tag_cloud', 0 ) == 0 ) {
  2569. add_action( 'init', 'sq_tag_cloud_size' );
  2570. function sq_tag_cloud_size() {
  2571. sq_kleo()->add_css( '.widget_tag_cloud a { font-size: small !important; }' );
  2572. }
  2573. }
  2574.  
  2575. /* Ajax for posts grid element */
  2576. add_action( 'wp_ajax_nopriv_vc_post_items', 'sq_vc_posts_ajax' );
  2577. add_action( 'wp_ajax_vc_post_items', 'sq_vc_posts_ajax' );
  2578.  
  2579. function sq_vc_posts_ajax() {
  2580. // Check the nonce, if it fails the function will break
  2581. check_ajax_referer( 'kleo-ajax-posts-nonce', 'security' );
  2582.  
  2583. /* If not our action, bail out */
  2584. if ( ! isset( $_POST['action'] ) || 'vc_post_items' != $_POST['action'] ) {
  2585. return false;
  2586. }
  2587.  
  2588. $count_id = (int) $_POST['pitem'];
  2589. $post_id = $_POST['post_id'];
  2590. if (isset( $_POST['paged'] )) {
  2591. $paged = $_POST['paged'];
  2592. } else {
  2593. $paged = '';
  2594. }
  2595.  
  2596. $args = get_transient( 'kleo_post_' . $post_id . '_' . $count_id );
  2597. if ( $args ) {
  2598. $args = maybe_unserialize( $args );
  2599. }
  2600.  
  2601. if ( ! is_array( $args ) ) {
  2602. wp_send_json_error( array( 'message' => __( 'Something went wrong. Please reload page.', 'kleo_framework' ) ) );
  2603. exit;
  2604. }
  2605.  
  2606. $args['ajax_paged'] = $paged;
  2607. $args['ajax_post'] = $post_id;
  2608. $items = vc_do_shortcode( $args, null, 'vc_posts_grid' );
  2609. wp_send_json_success( array( 'message' => $items ) );
  2610. exit;
  2611. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement