Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 82.62 KB | None | 0 0
  1. <?php
  2. define( 'KLEO_THEME_VERSION', '4.4' );
  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' => array('publish','inherit'),
  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( $post->post_type == 'attachment') {
  744. $img_url = wp_get_attachment_thumb_url( $post->ID );
  745. $image = '<img src="'.aq_resize( $img_url, 44, 44, true, true, true ).'" class="kleo-rounded"/>';
  746. } else {
  747. if ($img_url = kleo_get_post_thumbnail_url($post->ID)) {
  748. $image = aq_resize($img_url, 44, 44, true, true, true);
  749. if (!$image) {
  750. $image = $img_url;
  751. }
  752. $image = '<img src="' . $image . '" class="kleo-rounded">';
  753. } else {
  754. if ($format == 'video') {
  755. $image = "<i class='icon icon-video'></i>";
  756. } elseif ($format == 'image' || $format == 'gallery') {
  757. $image = "<i class='icon icon-picture'></i>";
  758. } else {
  759. $image = "<i class='icon icon-link'></i>";
  760. }
  761. }
  762. }
  763. $excerpt = "";
  764.  
  765. if ( ! empty( $post->post_content ) ) {
  766. $excerpt = $post->post_content;
  767. $excerpt = preg_replace( "/\[(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", '', $excerpt );
  768. $excerpt = wp_strip_all_tags($excerpt); //added to remove gogole adsense code from search excerpt
  769. $excerpt = char_trim( trim( strip_tags( $excerpt ) ), 40, "..." );
  770. }
  771. $link = apply_filters( 'kleo_custom_url', get_permalink( $post->ID ) );
  772. $classes = "format-" . $format;
  773. $output .= "<div class ='kleo_ajax_entry $classes'>";
  774. $output .= "<div class='ajax_search_image'>$image</div>";
  775. $output .= "<div class='ajax_search_content'>";
  776. $output .= "<a href='$link' class='search_title'>";
  777. $output .= get_the_title( $post->ID );
  778. $output .= "</a>";
  779. $output .= "<span class='search_excerpt'>";
  780. $output .= $excerpt;
  781. $output .= "</span>";
  782. $output .= "</div>";
  783. $output .= "</div>";
  784. }
  785. $output .= '</div>';
  786. }
  787.  
  788. if ( ! empty( $post_type_str ) ) {
  789. if ( count( $post_type_str ) > 1 ) {
  790. $search_str_posts = '&post_type[]=' . implode( ',', $post_type_str );
  791. } else {
  792. $search_str_posts = '&post_type=' . implode( ',', $post_type_str );
  793. }
  794.  
  795. } else {
  796. $search_str_posts = '';
  797. }
  798.  
  799. $output .= "<a class='ajax_view_all' href='" . esc_url( home_url( '/' ) . '?s=' . $search_string ) . $search_str_posts . "'>" . __( 'View all results', 'kleo_framework' ) . "</a>";
  800. }
  801.  
  802. /* Forums topics search */
  803. if ( ! empty( $forums ) ) {
  804. $output .= '<div class="kleo-ajax-part kleo-ajax-type-forums">';
  805. $output .= '<h4><span>' . __( "Forums", 'kleo_framework' ) . '</span></h4>';
  806.  
  807. $i = 0;
  808. foreach ( $forums as $fk => $forum ) {
  809.  
  810. $i ++;
  811. if ( $i <= 4 ) {
  812. $image = "<i class='icon icon-chat-1'></i>";
  813.  
  814. $output .= "<div class ='kleo_ajax_entry'>";
  815. $output .= "<div class='ajax_search_image'>$image</div>";
  816. $output .= "<div class='ajax_search_content'>";
  817. $output .= "<a href='" . $forum['url'] . "' class='search_title'>";
  818. $output .= $forum['name'];
  819. $output .= "</a>";
  820. //$output .= "<span class='search_excerpt'>";
  821. //$output .= $latest_activity;
  822. //$output .= "</span>";
  823. $output .= "</div>";
  824. $output .= "</div>";
  825. }
  826. }
  827. $output .= "<a class='ajax_view_all' href='" . esc_url( bbp_get_search_url() . "?bbp_search=" . $search_string ) . "'>" . __( 'View forum results', 'kleo_framework' ) . "</a>";
  828. $output .= "</div>";
  829. }
  830.  
  831.  
  832. echo $output;
  833. die();
  834. }
  835. }
  836.  
  837. if ( ! function_exists( 'kleo_bbp_get_replies' ) ) {
  838. function kleo_bbp_get_replies( $title = '' ) {
  839. global $wpdb;
  840. $topic_matches = array();
  841.  
  842. /* First do a title search */
  843. $topics = $wpdb->get_results( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_title LIKE "%' . esc_sql( trim( $title ) ) . '%" AND post_type="topic" AND post_status="publish"' );
  844.  
  845. /* do a tag search if title search doesn't have results */
  846. if ( ! $topics ) {
  847. $topic_tags = get_terms( 'topic-tag' );
  848.  
  849. if ( empty( $topic_tags ) ) {
  850. return $topic_matches;
  851. }
  852.  
  853. foreach ( $topic_tags as $tid => $tag ) {
  854. $tags[ $tag->term_id ] = $tag->name;
  855. }
  856.  
  857. $tag_matches = kleo_bbp_stristr_array( $title, $tags );
  858.  
  859. $args = array(
  860. 'post_type' => 'topic',
  861. 'showposts' => - 1,
  862. 'tax_query' => array(
  863. array(
  864. 'taxonomy' => 'topic-tag',
  865. 'field' => 'term_id',
  866. 'terms' => $tag_matches
  867. )
  868. )
  869. );
  870.  
  871. $topics = get_posts( $args );
  872. }
  873.  
  874. /* Compile results into array*/
  875. foreach ( $topics as $topic ) {
  876. $topic_matches[ $topic->ID ]['name'] = $topic->post_title;
  877. $topic_matches[ $topic->ID ]['url'] = get_post_permalink( $topic->ID );
  878. }
  879.  
  880.  
  881. return $topic_matches;
  882.  
  883. }
  884. }
  885.  
  886. function kleo_bbp_stristr_array( $haystack, $needles ) {
  887.  
  888. $elements = array();
  889.  
  890.  
  891. foreach ( $needles as $id => $needle ) {
  892. if ( stristr( $haystack, $needle ) ) {
  893. $elements[] = $id;
  894. }
  895. }
  896.  
  897. return $elements;
  898. }
  899.  
  900.  
  901. /***************************************************
  902. * :: WPML language switch
  903. ***************************************************/
  904.  
  905. if ( ! function_exists( 'kleo_wpml_wp_nav_menu_items_filter' ) && function_exists( 'icl_get_languages' ) ) {
  906. function kleo_wpml_wp_nav_menu_items_filter( $items, $args ) {
  907. if ( $args->theme_location == 'primary' ) {
  908. $items = str_replace( '<a href="#" onclick="return false">', '<a href="#" class="js-activated">', $items );
  909. $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 );
  910. }
  911.  
  912. return $items;
  913. }
  914.  
  915. add_filter( 'wp_nav_menu_items', 'kleo_wpml_wp_nav_menu_items_filter', 10, 2 );
  916. }
  917.  
  918. if ( ! function_exists( 'kleo_lang_menu_item' ) ):
  919.  
  920. function kleo_lang_menu_item( $items, $args ) {
  921. if ( $args->theme_location == 'top' ) {
  922. $items .= kleo_get_languages();
  923. }
  924.  
  925. return $items;
  926. }
  927.  
  928. endif;
  929.  
  930. if ( sq_option( 'show_lang', 1 ) == 1 ) {
  931. add_filter( 'wp_nav_menu_items', 'kleo_lang_menu_item', 10, 2 );
  932. }
  933.  
  934. function kleo_get_languages() {
  935.  
  936. global $sitepress_settings;
  937. $output = '';
  938. $active = '';
  939. $items = '';
  940.  
  941. if ( function_exists( 'icl_get_languages' ) ) {
  942. $languages = icl_get_languages( 'skip_missing=0&orderby=code' );
  943.  
  944. if ( ! empty( $languages ) ) {
  945. foreach ( $languages as $code => $lang ) {
  946.  
  947. $items .= '<li>';
  948.  
  949. $alt_title_lang = $sitepress_settings['icl_lso_native_lang'] ? esc_attr( $lang['native_name'] ) : esc_attr( $lang['translated_name'] );
  950.  
  951. $entry = '';
  952.  
  953. if ( isset($sitepress_settings['icl_lso_flags']) ) {
  954. $entry .= '<img class="iclflag" src="' . $lang['country_flag_url'] . '" width="18" height="12" alt="' . $alt_title_lang . '" title="' . $alt_title_lang . '" /> ';
  955. }
  956. if ( isset($sitepress_settings['icl_lso_native_lang']) ) {
  957. $entry .= $lang['native_name'];
  958. }
  959. if ( isset( $sitepress_settings['icl_lso_display_lang'] ) && isset( $sitepress_settings['icl_lso_native_lang'] ) ) {
  960. $entry .= ' (';
  961. }
  962. if (isset( $sitepress_settings['icl_lso_display_lang']) ) {
  963. $entry .= $lang['translated_name'];
  964. }
  965. if (isset( $sitepress_settings['icl_lso_display_lang'] ) && isset( $sitepress_settings['icl_lso_native_lang'] ) ) {
  966. $entry .= ')';
  967. }
  968.  
  969.  
  970. if ( ! $lang['active'] ) {
  971. $items .= '<a href="' . $lang['url'] . '">' . $entry . '</a>';
  972. } else {
  973. $active = '<a href="' . $lang['url'] . '" class="dropdown-toggle js-activated current-language" data-toggle="dropdown">' . $entry . ( count( $languages ) > 1 ? ' <span class="caret"></span>' : '' ) . '</a>';
  974. }
  975.  
  976. $items .= '</li>';
  977. }
  978. }
  979.  
  980. $output .= ' <li class="' . ( count( $languages ) > 1 ? 'dropdown' : '' ) . ' kleo-langs">'
  981. . $active
  982. . '<ul class="dropdown-menu pull-right">'
  983. . $items
  984. . '</ul></li>';
  985. }
  986.  
  987. return $output;
  988. }
  989.  
  990.  
  991. /***************************************************
  992. * :: Go up button
  993. ***************************************************/
  994. function kleo_go_up() {
  995. ?>
  996. <a class="kleo-go-top" href="#"><i class="icon-up-open-big"></i></a>
  997. <?php
  998. }
  999.  
  1000. if ( sq_option( 'go_top', 1 ) == 1 ) {
  1001. add_action( 'kleo_after_footer', 'kleo_go_up' );
  1002. }
  1003.  
  1004.  
  1005. /***************************************************
  1006. * :: Bottom contact form
  1007. ***************************************************/
  1008.  
  1009. if ( ! function_exists( 'kleo_contact_form' ) ) {
  1010. function kleo_contact_form( $atts, $content = null ) {
  1011. extract( shortcode_atts( array(
  1012. 'title' => 'CONTACT US',
  1013. 'builtin_form' => 1
  1014. ), $atts ) );
  1015.  
  1016. $output = '';
  1017.  
  1018. $output .= '<div class="kleo-quick-contact-wrapper">'
  1019. . '<a class="kleo-quick-contact-link" href="#"><i class="icon-mail-alt"></i></a>'
  1020. . '<div id="kleo-quick-contact">'
  1021. . '<h4 class="kleo-qc-title">' . $title . '</h4>'
  1022. . '<p>' . do_shortcode( $content ) . '</p>';
  1023. if ( $builtin_form == 1 ) {
  1024. $output .= '<form class="kleo-contact-form" action="#" method="post" novalidate>'
  1025. . '<input type="text" placeholder="' . __( "Your Name", 'kleo_framework' ) . '" required id="contact_name" name="contact_name" class="form-control" value="" tabindex="276" />'
  1026. . '<input type="email" required placeholder="' . __( "Your Email", 'kleo_framework' ) . '" id="contact_email" name="contact_email" class="form-control" value="" tabindex="277" />'
  1027. . '<textarea placeholder="' . __( "Type your message...", 'kleo_framework' ) . '" required id="contact_content" name="contact_content" class="form-control" tabindex="278"></textarea>'
  1028. . '<input type="hidden" name="action" value="kleo_sendmail">'
  1029. . '<button tabindex="279" class="btn btn-default pull-right" type="submit">' . __( "Send", 'kleo_framework' ) . '</button>'
  1030. . '<div class="kleo-contact-loading">' . __( "Sending", 'kleo_framework' ) . ' <i class="icon-spinner icon-spin icon-large"></i></div>'
  1031. . '<div class="kleo-contact-success"> </div>'
  1032. . '</form>';
  1033. }
  1034. $output .= '<div class="bottom-arrow"></div>'
  1035. . '</div>'
  1036. . '</div><!--end kleo-quick-contact-wrapper-->';
  1037.  
  1038. return $output;
  1039. }
  1040.  
  1041. add_shortcode( 'kleo_contact_form', 'kleo_contact_form' );
  1042. }
  1043.  
  1044.  
  1045. if ( ! function_exists( 'kleo_sendmail' ) ):
  1046. function kleo_sendmail() {
  1047. if ( isset( $_POST['action'] ) ) {
  1048.  
  1049. $error_tpl = "<span class='mail-error'>%s</span>";
  1050.  
  1051. //contact name
  1052. if ( trim( $_POST['contact_name'] ) === '' ) {
  1053. printf( $error_tpl, __( 'Please enter your name.', 'kleo_framework' ) );
  1054. die();
  1055. } else {
  1056. $name = trim( $_POST['contact_name'] );
  1057. }
  1058.  
  1059. ///contact email
  1060. if ( trim( $_POST['contact_email'] ) === '' ) {
  1061. printf( $error_tpl, __( 'Please enter your email address.', 'kleo_framework' ) );
  1062. die();
  1063. } elseif ( ! preg_match( "/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+.[a-z]{2,4}$/i", trim( $_POST['contact_email'] ) ) ) {
  1064. printf( $error_tpl, __( 'You entered an invalid email address.', 'kleo_framework' ) );
  1065. die();
  1066. } else {
  1067. $email = trim( $_POST['contact_email'] );
  1068. }
  1069.  
  1070. //message
  1071. if ( trim( $_POST['contact_content'] ) === '' ) {
  1072. printf( $error_tpl, __( 'Please enter a message.', 'kleo_framework' ) );
  1073. die();
  1074. } else {
  1075. if ( function_exists( 'stripslashes' ) ) {
  1076. $comment = stripslashes( trim( $_POST['contact_content'] ) );
  1077. } else {
  1078. $comment = trim( $_POST['contact_content'] );
  1079. }
  1080. }
  1081.  
  1082. $emailTo = sq_option( 'contact_form_to', '' );
  1083. if ( ! isset( $emailTo ) || ( $emailTo == '' ) ) {
  1084. $emailTo = get_option( 'admin_email' );
  1085. }
  1086.  
  1087. $subject = __( 'Contact Form Message', 'kleo_framework' );
  1088. apply_filters( 'kleo_contact_form_subject', $subject );
  1089.  
  1090. $body = __( "You received a new contact form message:", 'kleo_framework' ) . "\n";
  1091. $body .= __( "Name: ", 'kleo_framework' ) . $name . "\n";
  1092. $body .= __( "Email: ", 'kleo_framework' ) . $email . "\n";
  1093. $body .= __( "Message: ", 'kleo_framework' ) . $comment . "\n";
  1094.  
  1095. $headers[] = "Content-type: text/html";
  1096. $headers[] = "Reply-To: $name <$email>";
  1097. apply_filters( 'kleo_contact_form_headers', $headers );
  1098.  
  1099. if ( wp_mail( $emailTo, $subject, $body, $headers ) ) {
  1100. echo '<span class="mail-success">' . __( "Thank you. Your message has been sent.", 'kleo_framework' ) . ' <i class="icon-ok icon-large"></i></span>';
  1101.  
  1102. do_action( 'kleo_after_contact_form_mail_send', $name, $email, $comment );
  1103. } else {
  1104. printf( $error_tpl, __( "Mail couldn't be sent. Please try again!", 'kleo_framework' ) );
  1105. }
  1106.  
  1107. } else {
  1108. printf( $error_tpl, __( "Unknown error occurred. Please try again!", 'kleo_framework' ) );
  1109. }
  1110. die();
  1111. }
  1112. endif;
  1113.  
  1114.  
  1115. function kleo_show_contact_form() {
  1116. $title = sq_option( 'contact_form_title', '' );
  1117. $content = sq_option( 'contact_form_text', '' );
  1118. $builtin_form = sq_option( 'contact_form_builtin', 1 );
  1119.  
  1120. echo do_shortcode( '[kleo_contact_form title="' . $title . '" builtin_form="' . $builtin_form . '"]' . $content . '[/kleo_contact_form]' );
  1121. }
  1122.  
  1123. if ( sq_option( 'contact_form', 1 ) == 1 ) {
  1124. add_action( 'wp_ajax_kleo_sendmail', 'kleo_sendmail' );
  1125. add_action( 'wp_ajax_nopriv_kleo_sendmail', 'kleo_sendmail' );
  1126. add_action( 'kleo_after_footer', 'kleo_show_contact_form' );
  1127. }
  1128.  
  1129.  
  1130. /***************************************************
  1131. * :: SOCKET AREA
  1132. ***************************************************/
  1133. function kleo_show_socket() {
  1134. get_template_part( 'page-parts/socket' );
  1135. }
  1136.  
  1137. if ( sq_option( 'socket_enable', 1 ) == 1 ) {
  1138. add_action( 'kleo_after_footer', 'kleo_show_socket' );
  1139. }
  1140.  
  1141.  
  1142. /***************************************************
  1143. * :: EXCERPT
  1144. ***************************************************/
  1145.  
  1146. if ( ! function_exists( 'kleo_new_excerpt_length' ) ) {
  1147. function kleo_new_excerpt_length( $length ) {
  1148. return 60;
  1149. }
  1150.  
  1151. add_filter( 'excerpt_length', 'kleo_new_excerpt_length' );
  1152. }
  1153.  
  1154. if ( ! function_exists( 'kleo_excerpt' ) ) {
  1155. function kleo_excerpt( $limit = 20, $words = true ) {
  1156.  
  1157. $from_content = false;
  1158. $excerpt_initial = get_the_excerpt();
  1159.  
  1160. if ( $excerpt_initial == '' ) {
  1161. $excerpt_initial = get_the_content();
  1162. $from_content = true;
  1163. }
  1164. $excerpt_initial = preg_replace( '`\[[^\]]*\]`', '', $excerpt_initial );
  1165. $excerpt_initial = strip_tags( $excerpt_initial );
  1166.  
  1167. /* If we got it from get_the_content -> apply length restriction */
  1168. if ( $from_content ) {
  1169. $excerpt_length = apply_filters( 'excerpt_length', $limit );
  1170. $excerpt_initial = wp_trim_words( $excerpt_initial, $excerpt_length, '' );
  1171. }
  1172.  
  1173. if ( $words ) {
  1174. $excerpt = explode( ' ', $excerpt_initial, $limit );
  1175. if ( count( $excerpt ) >= $limit ) {
  1176. array_pop( $excerpt );
  1177. $excerpt = implode( " ", $excerpt ) . '...';
  1178. } else {
  1179. $excerpt = implode( " ", $excerpt ) . '';
  1180. }
  1181. } else {
  1182. $excerpt = substr( $excerpt_initial, 0, $limit ) . ( strlen( $excerpt_initial ) > $limit ? '...' : '' );
  1183. }
  1184.  
  1185. return '<p>' . $excerpt . '</p>';
  1186. }
  1187. }
  1188.  
  1189.  
  1190. if ( ! function_exists( 'kleo_has_shortcode' ) ) {
  1191. function kleo_has_shortcode( $shortcode = '', $post_id = null ) {
  1192.  
  1193. if ( ! $post_id ) {
  1194. if ( ! is_singular() ) {
  1195. return false;
  1196. }
  1197. $post_id = get_the_ID();
  1198. }
  1199.  
  1200. if ( is_page() || is_single() ) {
  1201. $current_post = get_post( $post_id );
  1202.  
  1203. if ( post_password_required( $current_post ) ) {
  1204. return false;
  1205. }
  1206.  
  1207. //remove_filter( 'the_content', 'do_shortcode', 11 );
  1208. //$post_content = apply_filters( 'the_content', $current_post->post_content );
  1209. $post_content = $current_post->post_content;
  1210. //add_filter( 'the_content', 'do_shortcode', 11 );
  1211.  
  1212. $found = false;
  1213.  
  1214. if ( ! $shortcode ) {
  1215. return $found;
  1216. }
  1217.  
  1218. if ( stripos( $post_content, '[' . $shortcode ) !== false ) {
  1219. $found = true;
  1220. }
  1221.  
  1222. return $found;
  1223. } else {
  1224. return false;
  1225. }
  1226. }
  1227. }
  1228.  
  1229. if ( ! function_exists( 'kleo_icons_array' ) ) {
  1230. function kleo_icons_array( $prefix = '', $before = array( '' ) ) {
  1231.  
  1232. // Get any existing copy of our transient data
  1233. $transient_name = 'kleo_font_icons_' . $prefix . implode( '', $before );
  1234. delete_transient($transient_name);
  1235.  
  1236. if ( false === ( $icons = get_transient( $transient_name ) ) ) {
  1237.  
  1238. // It wasn't there, so regenerate the data and save the transient
  1239. $icons = $before;
  1240.  
  1241. if ( 1 == sq_option( 'full_fontawesome', 0 ) ) {
  1242. $icons_json = file_get_contents( THEME_DIR . '/assets/font-all/font/config.json' );
  1243. } else {
  1244. $icons_json = file_get_contents( THEME_DIR . '/assets/font/config.json' );
  1245. }
  1246.  
  1247. if ( is_child_theme() && file_exists( CHILD_THEME_DIR . '/assets/css/fontello.css' ) ) {
  1248. $icons_json = file_get_contents( CHILD_THEME_DIR . '/assets/config.json' );
  1249. }
  1250.  
  1251. if ( $icons_json ) {
  1252. $arr = json_decode( $icons_json, true );
  1253. foreach ( $arr['glyphs'] as $icon ) {
  1254. if ( ( isset( $icon['selected'] ) && $icon['selected'] == true ) || ! isset( $icon['selected'] ) ) {
  1255. $icons[ $prefix . $icon['css'] ] = $icon['css'];
  1256. }
  1257. }
  1258. asort( $icons );
  1259. }
  1260.  
  1261. // set transient for one day
  1262. set_transient( $transient_name, $icons, 86400 );
  1263. }
  1264.  
  1265. return $icons;
  1266. }
  1267. }
  1268. add_action( 'kleo-opts-saved', 'kleo_delete_font_transient' );
  1269. function kleo_delete_font_transient() {
  1270. delete_transient( 'kleo_font_icons_' );
  1271. }
  1272.  
  1273. if ( ! function_exists( 'kleo_post_nav' ) ) :
  1274. /**
  1275. * Display navigation to next/previous post when applicable.
  1276. *
  1277. * @since Kleo 1.0
  1278. *
  1279. * @return void
  1280. */
  1281. function kleo_post_nav( $same_cat = false ) {
  1282. // Don't print empty markup if there's nowhere to navigate.
  1283. $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( $same_cat, '', true );
  1284. $next = get_adjacent_post( $same_cat, '', false );
  1285.  
  1286. if ( ! $next && ! $previous ) {
  1287. return;
  1288. }
  1289. ?>
  1290.  
  1291. <nav class="pagination-sticky member-navigation" role="navigation">
  1292. <?php
  1293. if ( is_attachment() ) :
  1294. previous_post_link( '%link', __( '<span id="older-nav">Go to article</span>', 'kleo_framework' ) );
  1295. else :
  1296. if ( $previous ) {
  1297. previous_post_link( '%link', '<span id="older-nav"><span class="outter-title"><span class="entry-title">' . $previous->post_title . '</span></span></span>', $same_cat );
  1298. }
  1299. if ( $next ) {
  1300. next_post_link( '%link', '<span id="newer-nav"><span class="outter-title"><span class="entry-title">' . $next->post_title . '</span>', $same_cat );
  1301. }
  1302. endif;
  1303. ?>
  1304. </nav><!-- .navigation -->
  1305.  
  1306. <?php
  1307. }
  1308. endif;
  1309.  
  1310. if ( ! function_exists( 'kleo_postmeta_enabled' ) ) {
  1311. /**
  1312. * Check to see if post meta is enabled for a single post
  1313. * @return int
  1314. */
  1315. function kleo_postmeta_enabled() {
  1316.  
  1317. if ( ! is_single() ) {
  1318. return 1;
  1319. }
  1320.  
  1321. /* If we set it via a shortcode */
  1322. global $kleo_config;
  1323. if ( isset( $kleo_config['post_meta_enabled'] ) ) {
  1324. if ( $kleo_config['post_meta_enabled'] ) {
  1325. return 1;
  1326. } else {
  1327. return 0;
  1328. }
  1329. }
  1330.  
  1331. $meta_status = sq_option( 'blog_meta_status', 1 );
  1332.  
  1333. if ( get_cfield( 'meta_checkbox' ) == 1 ) {
  1334. $meta_status = 0;
  1335. }
  1336.  
  1337. return apply_filters( 'kleo_postmeta_enabled', $meta_status );
  1338. }
  1339. }
  1340.  
  1341.  
  1342. /**
  1343. * Check to see if post media is enabled for a single post page
  1344. *
  1345. * @param string media_option
  1346. * @param int default
  1347. *
  1348. * @return int
  1349. */
  1350. function kleo_postmedia_enabled( $media_option = 'blog_media_status', $default = 1, $is_singular = false ) {
  1351.  
  1352.  
  1353. global $conditional_thumb;
  1354. global $wp_query;
  1355.  
  1356. if ( $is_singular === true ) {
  1357. $condition = is_singular();
  1358. } else {
  1359. $condition = is_single();
  1360. }
  1361.  
  1362.  
  1363. if ( ! $condition ) {
  1364.  
  1365. //check for shortcode thumbnail condition
  1366. if ( isset( $conditional_thumb ) ) {
  1367. if ( $wp_query->current_post > ( $conditional_thumb - 1 ) ) {
  1368. return false;
  1369. }
  1370. }
  1371.  
  1372. return 1;
  1373. }
  1374.  
  1375. $media_status = sq_option( $media_option, $default );
  1376. $post_status = get_cfield( 'post_media_status' );
  1377.  
  1378. if ( $post_status != '' ) {
  1379. $media_status = get_cfield( 'post_media_status' );
  1380. }
  1381.  
  1382. return $media_status;
  1383. }
  1384.  
  1385. if ( ! function_exists( 'kleo_get_img_overlay' ) ) {
  1386.  
  1387. function kleo_get_img_overlay() {
  1388. global $kleo_config;
  1389.  
  1390. if ( isset( $kleo_config['image_overlay'] ) ) {
  1391. return $kleo_config['image_overlay'];
  1392. }
  1393.  
  1394. return '';
  1395. }
  1396.  
  1397. }
  1398.  
  1399.  
  1400. /***************************************************
  1401. * :: Facebook Integration
  1402. ***************************************************/
  1403.  
  1404. if ( ! function_exists( 'kleo_fb_button' ) ) :
  1405. function kleo_fb_button() {
  1406. echo kleo_get_fb_button();
  1407. }
  1408. endif;
  1409. if ( ! function_exists( 'kleo_get_fb_button' ) ) :
  1410. function kleo_get_fb_button() {
  1411. ob_start();
  1412. ?>
  1413. <div class="kleo-fb-wrapper text-center">
  1414. <a href="#" class="kleo-facebook-connect btn btn-default "><i class="icon-facebook"></i>
  1415. &nbsp;<?php _e( "Log in with Facebook", 'kleo_framework' ); ?></a>
  1416. </div>
  1417. <div class="gap-20"></div>
  1418. <div class="hr-title hr-full"><abbr> <?php echo __( "or", "kleo_framework" ); ?> </abbr></div>
  1419. <?php
  1420.  
  1421. $output = ob_get_clean();
  1422.  
  1423. return $output;
  1424. }
  1425. endif;
  1426.  
  1427. if ( ! function_exists( 'kleo_fb_button_regpage' ) ) :
  1428. function kleo_fb_button_regpage() {
  1429. echo kleo_get_fb_button_regpage();
  1430. }
  1431. endif;
  1432. if ( ! function_exists( 'kleo_get_fb_button_regpage' ) ) :
  1433. function kleo_get_fb_button_regpage() {
  1434. ob_start();
  1435. ?>
  1436. <div class="kleo-fb-wrapper text-center">
  1437. <a href="#" class="kleo-facebook-connect btn btn-default "><i class="icon-facebook"></i>
  1438. &nbsp;<?php _e( "Log in with Facebook", 'kleo_framework' ); ?></a>
  1439. </div>
  1440. <div class="gap-30"></div>
  1441. <div class="hr-title hr-full"><abbr> <?php echo __( "or", "kleo_framework" ); ?> </abbr></div>
  1442. <div class="gap-10"></div>
  1443. <?php
  1444. $output = ob_get_clean();
  1445.  
  1446. return $output;
  1447. }
  1448. endif;
  1449.  
  1450. if ( ! function_exists( 'kleo_fb_button_shortcode' ) ) :
  1451. function kleo_fb_button_shortcode() {
  1452. $output = '';
  1453. if ( sq_option( 'facebook_login', 0 ) == 1 && get_option( 'users_can_register' ) && ! is_user_logged_in() ) {
  1454. $output .= '<a href="#" class="kleo-facebook-connect btn btn-default "><i class="icon-facebook"></i> &nbsp; ' . __( "Log in with Facebook", 'kleo_framework' ) . '</a>';
  1455. }
  1456.  
  1457. return $output;
  1458. }
  1459.  
  1460. add_shortcode( 'kleo_fb_button', 'kleo_fb_button_shortcode' );
  1461. endif;
  1462.  
  1463. if ( sq_option( 'facebook_login', 0 ) == 1 ) {
  1464. add_action( 'bp_before_login_widget_loggedout', 'kleo_fb_button' );
  1465. add_action( 'login_form', 'kleo_fb_button', 10 );
  1466. add_action( 'kleo_before_login_form', 'kleo_fb_button', 10 );
  1467. add_action( 'kleo_before_register_form_modal', 'kleo_fb_button', 10 );
  1468.  
  1469. if ( class_exists( 'WooCommerce' ) ) {
  1470. add_action( 'woocommerce_login_form_start', 'kleo_fb_button', 10 );
  1471. }
  1472.  
  1473. if ( sq_option( 'facebook_register', 0 ) == 1 ) {
  1474. add_action( 'bp_before_register_page', 'kleo_fb_button_regpage' );
  1475. }
  1476. }
  1477.  
  1478.  
  1479. /***************************************************
  1480. * :: oEmbed manipulation for youtube/vimeo video
  1481. ***************************************************/
  1482.  
  1483. if ( ! function_exists( 'kleo_add_video_wmode_transparent' ) ) :
  1484. /**
  1485. * Automatically add wmode=transparent to embeded media
  1486. * Automatically add showinfo=0 for youtube
  1487. *
  1488. * @param type $html
  1489. * @param type $url
  1490. * @param type $attr
  1491. *
  1492. * @return type
  1493. */
  1494. function kleo_add_video_wmode_transparent( $html, $url, $attr ) {
  1495. if ( strpos( $html, "youtube.com" ) !== null || strpos( $html, "youtu.be" ) !== null ) {
  1496. $info = "&amp;showinfo=0";
  1497. } else {
  1498. $info = "";
  1499. }
  1500.  
  1501. if ( strpos( $html, "<embed src=" ) !== false ) {
  1502. return str_replace( '</param><embed', '</param><param name="wmode" value="opaque"></param><embed wmode="opaque" ', $html );
  1503. } elseif ( strpos( $html, 'feature=oembed' ) !== false ) {
  1504. return str_replace( 'feature=oembed', 'feature=oembed&amp;wmode=opaque' . $info, $html );
  1505. } else {
  1506. return $html;
  1507. }
  1508. }
  1509. endif;
  1510.  
  1511. add_filter( 'oembed_result', 'kleo_add_video_wmode_transparent', 10, 3 );
  1512.  
  1513. if ( ! function_exists( 'kleo_oembed_filter' ) ):
  1514. function kleo_oembed_filter( $return, $data, $url ) {
  1515. $return = str_replace( 'frameborder="0"', 'style="border: none"', $return );
  1516.  
  1517. return $return;
  1518. }
  1519. endif;
  1520.  
  1521. add_filter( 'oembed_dataparse', 'kleo_oembed_filter', 90, 3 );
  1522.  
  1523.  
  1524. /***************************************************
  1525. * :: Apply oEmbed for post video format
  1526. ***************************************************/
  1527. global $wp_embed;
  1528. add_filter( 'kleo_oembed_video', array( $wp_embed, 'autoembed' ), 8 );
  1529.  
  1530.  
  1531. /***************************************************
  1532. * :: Custom taxonomy header content
  1533. ***************************************************/
  1534.  
  1535. if ( function_exists( 'get_term_meta' ) ) {
  1536.  
  1537. /* GET CUSTOM HEADER CONTENT FOR CATEGORY */
  1538. add_action( 'kleo_before_main', 'kleo_taxonomy_header', 9 );
  1539.  
  1540. function kleo_taxonomy_header() {
  1541. $queried_object = get_queried_object();
  1542. if ( isset( $queried_object->term_id ) ) {
  1543.  
  1544. $term_id = $queried_object->term_id;
  1545. $content = get_term_meta( $term_id, 'cat_meta' );
  1546.  
  1547. if ( isset( $content[0]['cat_header'] ) && $content[0]['cat_header'] != '' ) {
  1548. echo '<section class="kleo-cat-header container-wrap main-color">';
  1549. echo do_shortcode( $content[0]['cat_header'] );
  1550. echo '</section>';
  1551. }
  1552. }
  1553. }
  1554.  
  1555. /* ADD CUSTOM META BOX TO CATEGORY PAGES */
  1556. function kleo_taxonomy_edit_meta_field( $term ) {
  1557. // put the term ID into a variable
  1558. $t_id = $term->term_id;
  1559. // retrieve the existing value(s) for this meta field. This returns an array
  1560. $term_meta = get_term_meta( $t_id, 'cat_meta' );
  1561. if ( ! $term_meta ) {
  1562. $term_meta = add_term_meta( $t_id, 'cat_meta', '' );
  1563. }
  1564. ?>
  1565. <tr class="form-field">
  1566. <th scope="row" valign="top"><label
  1567. for="term_meta[cat_header]"><?php _e( 'Top Content', 'kleo_framework' ); ?></label></th>
  1568. <td>
  1569. <?php
  1570. $content = ( isset( $term_meta[0]['cat_header'] ) && $term_meta[0]['cat_header'] != '' ) ? esc_attr( $term_meta[0]['cat_header'] ) : '';
  1571. echo '<textarea id="term_meta[cat_header]" name="term_meta[cat_header]">' . $content . '</textarea>'; ?>
  1572. <p class="description"><?php _e( 'This will be displayed at top of the category page. Shortcodes are allowed.', 'kleo_framework' ); ?></p>
  1573. </td>
  1574. </tr>
  1575. <?php
  1576. }
  1577.  
  1578. add_action( 'product_cat_edit_form_fields', 'kleo_taxonomy_edit_meta_field', 10, 2 );
  1579.  
  1580. /* SAVE CUSTOM META*/
  1581. /**
  1582. * @param $term_id
  1583. */
  1584. function kleo_save_taxonomy_custom_meta( $term_id ) {
  1585. if ( isset( $_POST['term_meta'] ) ) {
  1586. $t_id = $term_id;
  1587. $term_meta = get_term_meta( $t_id, 'cat_meta' );
  1588. $cat_keys = array_keys( $_POST['term_meta'] );
  1589. foreach ( $cat_keys as $key ) {
  1590. if ( isset ( $_POST['term_meta'][ $key ] ) ) {
  1591. $term_meta[ $key ] = $_POST['term_meta'][ $key ];
  1592. }
  1593. }
  1594. // Save the option array.
  1595. update_term_meta( $term_id, 'cat_meta', $term_meta );
  1596.  
  1597. }
  1598. }
  1599.  
  1600. add_action( 'edited_product_cat', 'kleo_save_taxonomy_custom_meta', 10, 2 );
  1601. }
  1602.  
  1603.  
  1604. /***************************************************
  1605. * :: Add custom HTML to page header set from Page edit
  1606. ***************************************************/
  1607.  
  1608. add_action( 'kleo_before_main', 'kleo_header_content', 8 );
  1609.  
  1610. function kleo_header_content() {
  1611. if ( is_singular() || is_home() ) {
  1612. $page_header = get_cfield( 'header_content' );
  1613. if ( $page_header != '' ) {
  1614. echo '<section class="kleo-page-header container-wrap main-color">';
  1615. echo do_shortcode( html_entity_decode( $page_header ) );
  1616. echo '</section>';
  1617. }
  1618. } else {
  1619. return false;
  1620. }
  1621. }
  1622.  
  1623.  
  1624. /***************************************************
  1625. * :: Add custom HTML to bottom page set from Page edit
  1626. ***************************************************/
  1627.  
  1628. add_action( 'kleo_after_main_content', 'kleo_bottom_content', 12 );
  1629.  
  1630. function kleo_bottom_content() {
  1631. if ( is_singular() || is_home() ) {
  1632. $page_bottom = get_cfield( 'bottom_content' );
  1633. if ( $page_bottom != '' ) {
  1634. echo '<div class="kleo-page-bottom">';
  1635. echo do_shortcode( html_entity_decode( $page_bottom ) );
  1636. echo '</div>';
  1637. }
  1638. } else {
  1639. return false;
  1640. }
  1641. }
  1642.  
  1643.  
  1644. /***************************************************
  1645. * :: rtMedia small compatibility
  1646. ***************************************************/
  1647.  
  1648. if ( class_exists( 'RTMedia' ) ) {
  1649. add_action( 'wp_enqueue_scripts', 'kleo_rtmedia_scripts', 999 );
  1650.  
  1651. function kleo_rtmedia_scripts() {
  1652. //wp_dequeue_style('rtmedia-font-awesome');
  1653. wp_dequeue_style( 'rtmedia-magnific' );
  1654. wp_dequeue_script( 'rtmedia-magnific' );
  1655. wp_dequeue_script( 'rtmedia-touchswipe' );
  1656. }
  1657.  
  1658. add_filter( 'body_class', 'kleo_rtmedia_class' );
  1659. function kleo_rtmedia_class( $classes ) {
  1660. $classes[] = 'rtm-' . RTMEDIA_VERSION;
  1661.  
  1662. return $classes;
  1663. }
  1664.  
  1665. global $rtmedia_admin;
  1666. remove_action( 'admin_notices', array( $rtmedia_admin, 'rtmedia_admin_notices' ) );
  1667.  
  1668. /* When BuddyPress is not enabled */
  1669. function kleo_rtmedia_no_buddypress() {
  1670. return locate_template( 'page.php' );
  1671. }
  1672. add_filter( 'rtmedia_main_template_include', 'kleo_rtmedia_no_buddypress', 20 );
  1673.  
  1674. /* TEMPORARY Deque the mediaelement added by the rtmedia plugin in non-Buddypress pages*/
  1675. if ( ! function_exists( 'sq7r_deque_rtmedia_mediaelement' ) ) {
  1676. function sq7r_deque_rtmedia_mediaelement() {
  1677. if( function_exists('bp_is_active') && !bp_is_members_component()) {
  1678. wp_dequeue_script('rt-mediaelement');
  1679. wp_dequeue_style('rt-mediaelement');
  1680. wp_dequeue_style('rt-mediaelement-wp');
  1681. wp_dequeue_script('rt-mediaelement-wp');
  1682. }
  1683. }
  1684. add_action('wp_enqueue_scripts', 'sq7r_deque_rtmedia_mediaelement',999);
  1685. }
  1686.  
  1687. }
  1688.  
  1689.  
  1690. /***************************************************
  1691. * :: WP Multisite Sign-up page
  1692. ***************************************************/
  1693. add_action( 'before_signup_form', 'kleo_mu_before_page' );
  1694. function kleo_mu_before_page() {
  1695. get_template_part( 'page-parts/general-before-wrap' );
  1696. }
  1697.  
  1698. add_action( 'after_signup_form', 'kleo_mu_after_page' );
  1699. function kleo_mu_after_page() {
  1700. get_template_part( 'page-parts/general-after-wrap' );
  1701. echo '<style>'
  1702. . '.mu_register input[type="submit"], .mu_register #blog_title, .mu_register #user_email, .mu_register #blogname, .mu_register #user_name {font-size: inherit;}'
  1703. . '.mu_register input[type="submit"] {width: auto;}'
  1704. . '</style>'
  1705. . '<script>jQuery(document).ready(function() { jQuery(\'.mu_register input[type="submit"]\').addClass("btn btn-default"); });</script>';
  1706.  
  1707. }
  1708.  
  1709. /***************************************************
  1710. * :: WP Multisite Activate page
  1711. ***************************************************/
  1712. if ( defined( 'WP_INSTALLING' ) && WP_INSTALLING == true ) {
  1713. add_action( 'kleo_before_main', 'kleo_mu_before_page' );
  1714. add_action( 'kleo_after_main', 'kleo_mu_after_page' );
  1715. }
  1716.  
  1717.  
  1718. /**
  1719. * GET CUSTOM POST TYPE TAXONOMY LIST
  1720. */
  1721. function kleo_get_category_list( $category_name, $filter = 0, $category_child = "" ) {
  1722.  
  1723. if ( $category_child != "" && $category_child != "All" ) {
  1724.  
  1725. $childcategory = get_term_by( 'slug', $category_child, $category_name );
  1726. $get_category = get_categories( array( 'taxonomy' => $category_name, 'child_of' => $childcategory->term_id ) );
  1727. $category_list = array( '0' => 'All' );
  1728.  
  1729. foreach ( $get_category as $category ) {
  1730. if ( isset( $category->cat_name ) ) {
  1731. $category_list[] = $category->slug;
  1732. }
  1733. }
  1734.  
  1735. return $category_list;
  1736.  
  1737. } else {
  1738. if ( $filter === 0 ) {
  1739.  
  1740. $get_category = get_categories( array( 'taxonomy' => $category_name ) );
  1741. $category_list = array( '0' => 'All' );
  1742.  
  1743. foreach ( $get_category as $category ) {
  1744. if ( isset( $category->slug ) ) {
  1745. $category_list[] = $category->slug;
  1746. }
  1747. }
  1748.  
  1749. return $category_list;
  1750.  
  1751. } elseif($filter === 1) {
  1752. $get_category = get_categories( array( 'taxonomy' => $category_name ) );
  1753. $category_list = array( '0' => 'All' );
  1754.  
  1755. foreach ( $get_category as $category ) {
  1756. if ( isset( $category->cat_name ) ) {
  1757. $category_list[] = $category->cat_name;
  1758. }
  1759. }
  1760.  
  1761. return $category_list;
  1762. } else {
  1763. $get_category = get_categories( array( 'taxonomy' => $category_name ) );
  1764. $category_list = array( '0' => 'All' );
  1765.  
  1766. foreach ( $get_category as $category ) {
  1767. if ( isset( $category->cat_name ) ) {
  1768. $category_list[ $category->cat_name ] = $category->slug;
  1769. }
  1770. }
  1771.  
  1772. return $category_list;
  1773. }
  1774.  
  1775. }
  1776. }
  1777.  
  1778. function kleo_get_category_list_key_array( $category_name, $key = 'slug' ) {
  1779.  
  1780. $get_category = get_categories( array( 'taxonomy' => $category_name ) );
  1781. $category_list = array( 'all' => 'All' );
  1782.  
  1783. foreach ( $get_category as $category ) {
  1784. if ( isset( $category->{$key} ) ) {
  1785. $category_list[ $category->{$key} ] = $category->cat_name;
  1786. }
  1787. }
  1788.  
  1789. return $category_list;
  1790. }
  1791.  
  1792.  
  1793. /***************************************************
  1794. * :: Custom main menu select for each page
  1795. ***************************************************/
  1796. if ( ! is_admin() ) {
  1797. add_filter( 'wp_nav_menu_args', 'kleo_set_custom_menu' );
  1798. }
  1799. function kleo_set_custom_menu( $args = '' ) {
  1800.  
  1801. if ( 'primary' != $args['theme_location'] && 'secondary' != $args['theme_location'] ) {
  1802. return $args;
  1803. }
  1804.  
  1805. global $post;
  1806.  
  1807. if ( ! empty( $post ) ) {
  1808.  
  1809. if ( 'primary' == $args['theme_location'] ) {
  1810. $menuslug = get_cfield( 'page_menu', $post->ID );
  1811.  
  1812. if ( ! empty( $menuslug ) && $menuslug != 'default' && is_nav_menu( $menuslug ) ) {
  1813. $args['menu'] = $menuslug;
  1814.  
  1815. }
  1816.  
  1817. } elseif ( 'secondary' == $args['theme_location'] ) {
  1818.  
  1819. $sec_menuslug = get_cfield( 'page_menu_secondary', $post->ID );
  1820.  
  1821. if ( ! empty( $sec_menuslug ) && $sec_menuslug != 'default' && is_nav_menu( $sec_menuslug ) ) {
  1822. $args['menu'] = $sec_menuslug;
  1823. }
  1824.  
  1825. }
  1826.  
  1827. } // END if(!empty($post))
  1828.  
  1829. return $args;
  1830. } // END function kleo_set_custom_menu($args = '')
  1831.  
  1832.  
  1833. /***************************************************
  1834. * :: SIDE MENU
  1835. ***************************************************/
  1836.  
  1837. //if set from admin to show side button
  1838. if ( sq_option( 'side_menu', 0 ) == 1 ) {
  1839.  
  1840. if ( sq_option( 'side_menu_button', 0 ) == 1 ) {
  1841. add_filter( 'wp_nav_menu_items', 'kleo_side_menu_button', 20, 2 );
  1842. }
  1843.  
  1844. add_filter( 'body_class', 'kleo_offcanvas_classes' );
  1845. add_action( 'kleo_after_page', 'kleo_show_side_menu' );
  1846. }
  1847.  
  1848. if ( ! function_exists( 'kleo_side_menu_button' ) ) {
  1849. /**
  1850. * Add side button to menu
  1851. *
  1852. * @param string $items
  1853. * @param object $args
  1854. *
  1855. * @return string
  1856. */
  1857. function kleo_side_menu_button( $items, $args ) {
  1858. if ( $args->theme_location == 'primary' ) {
  1859. $items .= '<li id="nav-menu-item-side" class="menu-item">' .
  1860. '<a href="#" class="open-sidebar" onclick="javascript:return false;">' .
  1861. '<i class="icon-menu"></i>' .
  1862. '</a>' .
  1863. '</li>';
  1864. }
  1865.  
  1866. return $items;
  1867. }
  1868. }
  1869.  
  1870. function kleo_show_side_menu() {
  1871. $side_menu = wp_nav_menu( array(
  1872. 'theme_location' => 'side',
  1873. 'depth' => 3,
  1874. 'container' => '',
  1875. 'menu_class' => 'offcanvas-menu',
  1876. 'fallback_cb' => '',
  1877. 'walker' => new kleo_walker_nav_menu(),
  1878. 'echo' => false
  1879. )
  1880. );
  1881. echo '<div class="offcanvas-sidebar side-color">' .
  1882. '<div class="wrap-canvas-menu">' .
  1883. '<div class="offcanvas-title">' .
  1884. '<a href="#" class="open-sidebar"></a>' .
  1885. '</div>' .
  1886. '<div class="offcanvas-before">' . do_shortcode( sq_option( 'side_menu_before' ) ) . '</div>' .
  1887. '<div class="widget_nav_menu">' .
  1888. $side_menu .
  1889. '</div>' .
  1890. '<div class="offcanvas-after">' . do_shortcode( sq_option( 'side_menu_after' ) ) . '</div>' .
  1891. '</div>' .
  1892. '</div>';
  1893. }
  1894.  
  1895.  
  1896. function kleo_offcanvas_classes( $classes = '' ) {
  1897.  
  1898. if ( sq_option( 'side_menu', 0 ) == 1 ) {
  1899. $classes[] = 'offcanvas-' . sq_option( 'side_menu_position', 'left' );
  1900. $classes[] = 'offcanvas-type-' . sq_option( 'side_menu_type', 'default' );
  1901. }
  1902.  
  1903. return $classes;
  1904.  
  1905. }
  1906.  
  1907.  
  1908. /***************************************************
  1909. * :: BLOG CUSTOMISATIONS
  1910. ***************************************************/
  1911.  
  1912. if ( ! function_exists( 'kleo_view_switch' ) ) {
  1913. /**
  1914. * Show post layout type switcher
  1915. *
  1916. * @param array $layouts
  1917. * @param string $active
  1918. * @param string $identifier
  1919. */
  1920. function kleo_view_switch( $layouts, $active = '', $identifier = '' ) {
  1921.  
  1922. echo '<div class="kleo-view-switch" data-identifier="' . $identifier . '">' .
  1923. '<ul>';
  1924.  
  1925. foreach ( $layouts as $layout ) {
  1926.  
  1927. $selected = '';
  1928. if ( $active == $layout ) {
  1929. $selected = ' active';
  1930. }
  1931. echo '<li><span data-type="' . $layout . '" class="switch-' . $layout . $selected . '"></span></li>';
  1932. }
  1933.  
  1934. echo '</ul>' .
  1935. '</div>' .
  1936. '<div class="clearfix"></div>';
  1937.  
  1938. ?>
  1939.  
  1940. <?php
  1941. }
  1942. }
  1943.  
  1944. /**
  1945. * Return the blog layout from visitor Cookie
  1946. *
  1947. * @param string $layout
  1948. * @param string $identifier
  1949. *
  1950. * @return string
  1951. */
  1952. function kleo_post_grid_layout( $layout = '', $identifier = '' ) {
  1953. $cookie_name = 'kleo-blog-layout' . $identifier;
  1954. if ( isset( $_COOKIE[ $cookie_name ] ) && $_COOKIE[ $cookie_name ] != '' ) {
  1955. $layout = $_COOKIE[ $cookie_name ];
  1956. }
  1957.  
  1958. if ( function_exists( 'get_term_meta' ) ) {
  1959. if ( is_category() ) {
  1960.  
  1961. global $kleo_config;
  1962. $layouts = $kleo_config['blog_layouts'];
  1963. $category = get_category( get_query_var( 'cat' ) );
  1964. $category_meta = get_term_meta( $category->term_id, 'kleo_category_display_type' );
  1965.  
  1966. if ( isset( $category_meta[0] ) && isset( $layouts[ $category_meta[0] ] ) ) {
  1967. $layout = $category_meta[0];
  1968. }
  1969.  
  1970. }
  1971. }
  1972.  
  1973. return $layout;
  1974. }
  1975.  
  1976. add_filter( 'kleo_blog_type', 'kleo_post_grid_layout', 10, 2 );
  1977.  
  1978.  
  1979. /***************************************************
  1980. * :: Let it Snow
  1981. ***************************************************/
  1982.  
  1983. function kleo_site_snow() {
  1984. echo do_shortcode( '[kleo_snow scope="window"]' );
  1985. }
  1986.  
  1987. if ( sq_option( 'let_it_snow', 0 ) == 1 ) {
  1988. add_action( 'kleo_after_page', 'kleo_site_snow' );
  1989. }
  1990.  
  1991.  
  1992. /**
  1993. * Get current post format for posts
  1994. * or custom media settings as post format for custom post type
  1995. * @return mixed|string
  1996. */
  1997. function kleo_get_post_format() {
  1998. if ( get_post_type() == 'portfolio' ) {
  1999. if ( get_cfield( 'media_type' ) && get_cfield( 'media_type' ) != '' ) {
  2000. $media_type = get_cfield( 'media_type' );
  2001. switch ( $media_type ) {
  2002. case 'slider':
  2003. $kleo_post_format = 'gallery';
  2004. break;
  2005.  
  2006. case 'video':
  2007. case 'hosted_video':
  2008. $kleo_post_format = 'video';
  2009. break;
  2010. }
  2011. }
  2012.  
  2013. return $kleo_post_format;
  2014. } else {
  2015. return get_post_format();
  2016. }
  2017. }
  2018.  
  2019.  
  2020. /**
  2021. * Return the URL as requested on the current page load by the user agent.
  2022. *
  2023. * @since KLEO (2.4)
  2024. *
  2025. * @return string Requested URL string.
  2026. */
  2027. function kleo_get_requested_url() {
  2028. $url = is_ssl() ? 'https://' : 'http://';
  2029. $url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  2030.  
  2031. return apply_filters( 'kleo_get_requested_url', esc_url( $url ) );
  2032. }
  2033.  
  2034.  
  2035. /***************************************************
  2036. * :: Profile placeholder in menu for bbPress or Buddypress
  2037. ***************************************************/
  2038.  
  2039. add_filter( 'walker_nav_menu_start_el', 'kleo_bp_replace_placeholders' );
  2040.  
  2041. function kleo_bp_replace_placeholders( $output ) {
  2042.  
  2043. $initial_output = $output;
  2044.  
  2045. if ( strpos( $output, '##profile_link##' ) !== false ) {
  2046.  
  2047. if ( ! is_user_logged_in() ) {
  2048. return '';
  2049. }
  2050.  
  2051. if ( function_exists( 'bp_is_active' ) ) {
  2052. $logged_in_link = bp_loggedin_user_domain();
  2053. $output = str_replace( '##profile_link##', $logged_in_link, $output );
  2054. } elseif ( class_exists( 'bbPress' ) ) {
  2055. $logged_in_link = bbp_get_user_profile_url( bbp_get_current_user_id() );
  2056. $output = str_replace( '##profile_link##', $logged_in_link, $output );
  2057. }
  2058. }
  2059.  
  2060. if ( strpos( $output, '##member_name##' ) !== false ) {
  2061.  
  2062. if ( ! is_user_logged_in() ) {
  2063. return '';
  2064. }
  2065. if ( function_exists( 'bp_is_active' ) ) {
  2066. $logged_in_username = bp_get_loggedin_user_fullname();
  2067. $output = str_replace( '##member_name##', $logged_in_username, $output );
  2068. } elseif ( class_exists( 'bbPress' ) ) {
  2069. $logged_in_username = bbp_get_user_nicename( bbp_get_current_user_id() );
  2070. $output = str_replace( '##member_name##', $logged_in_username, $output );
  2071. }
  2072.  
  2073. }
  2074. if( is_user_logged_in() ){
  2075.  
  2076. $current_user_firstname = wp_get_current_user()->user_firstname;
  2077. if ($current_user_firstname) {
  2078. $output = str_replace('##member_first_name##', $current_user_firstname, $output);
  2079. }
  2080. $current_user_lastname = wp_get_current_user()->user_lastname;
  2081. if ($current_user_lastname) {
  2082. $output = str_replace('##member_last_name##', $current_user_lastname, $output);
  2083. }
  2084. }
  2085.  
  2086. $output = apply_filters( 'kleo_bp_replace_placeholders', $output, $initial_output );
  2087.  
  2088. return $output;
  2089. }
  2090.  
  2091.  
  2092. /***************************************************
  2093. * :: Custom redirect from Theme options - Miscellaneous
  2094. ***************************************************/
  2095.  
  2096. if ( sq_option( 'login_redirect', 'default' ) == 'custom' && sq_option( 'login_redirect_custom', '' ) != '' ) {
  2097. add_filter( 'login_redirect', 'kleo_custom_redirect', 12 );
  2098. }
  2099.  
  2100. function kleo_custom_redirect() {
  2101.  
  2102. $redirect_to = sq_option( 'login_redirect_custom', '' );
  2103.  
  2104. return $redirect_to;
  2105. }
  2106.  
  2107. if ( ! function_exists( 'kleo_get_post_media' ) ) {
  2108. /**
  2109. * Return post media by format
  2110. *
  2111. * @param $post_format
  2112. * @param $options
  2113. *
  2114. * @return string
  2115. *
  2116. * @since 3.0
  2117. */
  2118. function kleo_get_post_media( $post_format = 'standard', $options = array() ) {
  2119.  
  2120. global $kleo_config;
  2121.  
  2122. if ( isset( $options['icons'] ) && $options['icons'] ) {
  2123. $icons = true;
  2124. } else {
  2125. $icons = false;
  2126. }
  2127.  
  2128. if ( isset( $options['media_width'] ) && isset( $options['media_height'] ) ) {
  2129. $media_width = $options['media_width'];
  2130. $media_height = $options['media_height'];
  2131. } else {
  2132. $media_width = $kleo_config['post_gallery_img_width'];
  2133. $media_height = $kleo_config['post_gallery_img_height'];
  2134. }
  2135.  
  2136. $output = '';
  2137.  
  2138. switch ( $post_format ) {
  2139.  
  2140. case 'video':
  2141.  
  2142. //oEmbed video
  2143. $video = get_cfield( 'embed' );
  2144. // video bg self hosted
  2145. $bg_video_args = array();
  2146. $k_video = '';
  2147.  
  2148. if ( get_cfield( 'video_mp4' ) ) {
  2149. $bg_video_args['mp4'] = get_cfield( 'video_mp4' );
  2150. }
  2151. if ( get_cfield( 'video_ogv' ) ) {
  2152. $bg_video_args['ogv'] = get_cfield( 'video_ogv' );
  2153. }
  2154. if ( get_cfield( 'video_webm' ) ) {
  2155. $bg_video_args['webm'] = get_cfield( 'video_webm' );
  2156. }
  2157.  
  2158. if ( ! empty( $bg_video_args ) ) {
  2159. $attr_strings = array(
  2160. 'preload="none"'
  2161. );
  2162.  
  2163. if ( get_cfield( 'video_poster' ) ) {
  2164. $attr_strings[] = 'poster="' . get_cfield( 'video_poster' ) . '"';
  2165. }
  2166.  
  2167. $k_video .= '<div class="kleo-video-wrap"><video ' . join( ' ', $attr_strings ) . ' controls="controls" class="kleo-video" style="width: 100%; height: 100%;">';
  2168.  
  2169. $source = '<source type="%s" src="%s" />';
  2170. foreach ( $bg_video_args as $video_type => $video_src ) {
  2171. $video_type = wp_check_filetype( $video_src, wp_get_mime_types() );
  2172. $k_video .= sprintf( $source, $video_type['type'], esc_url( $video_src ) );
  2173. }
  2174.  
  2175. $k_video .= '</video></div>';
  2176.  
  2177. $output .= $k_video;
  2178. } // oEmbed
  2179. elseif ( ! empty( $video ) ) {
  2180. global $wp_embed;
  2181. $output .= apply_filters( 'kleo_oembed_video', $video );
  2182. }
  2183.  
  2184. break;
  2185.  
  2186. case 'audio':
  2187.  
  2188. $audio = get_cfield( 'audio' );
  2189.  
  2190. if ( ! empty( $audio ) ) {
  2191. $output .=
  2192. '<div class="post-audio">' .
  2193. '<audio preload="none" class="kleo-audio" id="audio_' . get_the_ID() . '" style="width:100%;" src="' . $audio . '"></audio>' .
  2194. '</div>';
  2195. }
  2196. break;
  2197.  
  2198. case 'gallery':
  2199.  
  2200. $slides = get_cfield( 'slider' );
  2201.  
  2202. $output .= '<div class="kleo-banner-slider">'
  2203. . '<div class="kleo-banner-items" >';
  2204.  
  2205. if ( $slides ) {
  2206. foreach ( $slides as $slide ) {
  2207. if ( $slide ) {
  2208. $image = aq_resize( $slide, $media_width, $media_height, true, true, true );
  2209. //small hack for non-hosted images
  2210. if ( ! $image ) {
  2211. $image = $slide;
  2212. }
  2213. $output .= '<article>
  2214. <a href="' . $slide . '" data-rel="modalPhoto[inner-gallery]">
  2215. <img src="' . $image . '" alt="' . get_the_title() . '">'
  2216. . kleo_get_img_overlay()
  2217. . '</a>
  2218. </article>';
  2219. }
  2220. }
  2221. }
  2222.  
  2223. $output .= '</div>'
  2224. . '<a href="#" class="kleo-banner-prev"><i class="icon-angle-left"></i></a>'
  2225. . '<a href="#" class="kleo-banner-next"><i class="icon-angle-right"></i></a>'
  2226. . '<div class="kleo-banner-features-pager carousel-pager"></div>'
  2227. . '</div>';
  2228.  
  2229. break;
  2230.  
  2231.  
  2232. case 'aside':
  2233. if ( $icons ) {
  2234. $output .= '<div class="post-format-icon"><i class="icon icon-doc"></i></div>';
  2235. }
  2236. break;
  2237.  
  2238. case 'link':
  2239. if ( $icons ) {
  2240. $output .= '<div class="post-format-icon"><i class="icon icon-link"></i></div>';
  2241. }
  2242. break;
  2243.  
  2244. case 'quote':
  2245. if ( $icons ) {
  2246. $output .= '<div class="post-format-icon"><i class="icon icon-quote-right"></i></div>';
  2247. }
  2248. break;
  2249.  
  2250. case 'image':
  2251. default:
  2252. if ( kleo_get_post_thumbnail_url() != '' ) {
  2253. $output .= '<div class="post-image">';
  2254.  
  2255. $img_url = kleo_get_post_thumbnail_url();
  2256. $image = aq_resize( $img_url, $media_width, $media_height, true, true, true );
  2257. if ( ! $image ) {
  2258. $image = $img_url;
  2259. }
  2260. $output .= '<a href="' . get_permalink() . '" class="element-wrap">'
  2261. . '<img src="' . $image . '" alt="' . get_the_title() . '">'
  2262. . kleo_get_img_overlay()
  2263. . '</a>';
  2264.  
  2265. $output .= '</div><!--end post-image-->';
  2266. } elseif ( $icons ) {
  2267. $post_icon = $post_format == 'image' ? 'picture' : 'doc';
  2268. $output .= '<div class="post-format-icon"><i class="icon icon-' . $post_icon . '"></i></div>';
  2269. }
  2270.  
  2271. break;
  2272. }
  2273.  
  2274. return $output;
  2275. }
  2276. }
  2277.  
  2278.  
  2279. /***************************************************
  2280. * :: Custom taxonomy category template
  2281. ***************************************************/
  2282.  
  2283. if ( function_exists( 'get_term_meta' ) ) {
  2284.  
  2285. function kleo_category_display_type_form( $category = false ) {
  2286.  
  2287. global $kleo_config;
  2288. $layouts = array_merge( $kleo_config['blog_layouts'], array( 'kb' => 'Knowledge Base' ) );
  2289. $category_layout = '';
  2290.  
  2291. if ( $category && is_object( $category ) ) {
  2292. $category_id = $category->term_id;
  2293. $category_meta = get_term_meta( $category_id, 'kleo_category_display_type' );
  2294. if ( isset( $category_meta[0] ) && isset( $layouts[ $category_meta[0] ] ) ) {
  2295. $category_layout = $category_meta[0];
  2296. }
  2297. }
  2298.  
  2299. ?>
  2300. <tr class="form-field">
  2301. <th scope="row" valign="top"><label
  2302. for="kleo_category_display_type"><?php _e( 'Display type', 'kleo_framework' ); ?></label></th>
  2303. <td>
  2304. <div class="form-field term-meta-wrap">
  2305. <select id="kleo_category_display_type" name="kleo_category_display_type">
  2306. <option value=""><?php _e( 'Use default display type', 'kleo_framework' ); ?></option>
  2307. <?php foreach ( $layouts as $layout => $layout_name ) { ?>
  2308. <option
  2309. value="<?php echo esc_attr( $layout ); ?>" <?php echo( $layout == $category_layout ? 'selected="selected"' : '' ); ?>><?php echo esc_html( $layout_name ); ?></option>
  2310. <?php } ?>
  2311. </select>
  2312. <p class="description"><?php _e( 'The "Display type" will override the default display layout for each category in part.', 'kleo_framework' ); ?></p>
  2313. </div>
  2314. </td>
  2315. </tr>
  2316. <?php
  2317.  
  2318. }
  2319.  
  2320. add_action( 'category_add_form_fields', 'kleo_category_display_type_form' );
  2321. add_action( 'category_edit_form_fields', 'kleo_category_display_type_form' );
  2322.  
  2323. function kleo_category_display_type_save( $category_id ) {
  2324.  
  2325. if ( isset( $_POST['kleo_category_display_type'] ) ) {
  2326.  
  2327. global $kleo_config;
  2328. $layouts = array_merge( $kleo_config['blog_layouts'], array( 'kb' => 'Knowledge Base' ) );
  2329. $category_layout = esc_attr( $_POST['kleo_category_display_type'] );
  2330.  
  2331. if ( isset( $layouts[ $category_layout ] ) ) {
  2332. update_term_meta( $category_id, 'kleo_category_display_type', $category_layout );
  2333. } else {
  2334. delete_term_meta( $category_id, 'kleo_category_display_type' );
  2335. }
  2336.  
  2337. }
  2338.  
  2339. }
  2340.  
  2341. add_action( 'created_category', 'kleo_category_display_type_save' );
  2342. add_action( 'edited_category', 'kleo_category_display_type_save' );
  2343.  
  2344. function kleo_category_display_type_template( $template ) {
  2345. if ( is_category() ) {
  2346.  
  2347. $category = get_category( get_query_var( 'cat' ) );
  2348. $category_meta = get_term_meta( $category->term_id, 'kleo_category_display_type' );
  2349.  
  2350. if ( isset( $category_meta[0] ) && $category_meta[0] == 'kb' && locate_template( 'page-parts/posts-layout-kb.php' ) ) {
  2351. return locate_template( 'page-parts/posts-layout-kb.php' );
  2352. }
  2353.  
  2354. }
  2355.  
  2356. return $template;
  2357. }
  2358.  
  2359. add_filter( 'template_include', 'kleo_category_display_type_template' );
  2360.  
  2361. }
  2362.  
  2363.  
  2364. /***************************************************
  2365. * :: Allow site layout overriding at page/post level
  2366. ***************************************************/
  2367.  
  2368. function kleo_custom_site_style( $style ) {
  2369. if ( is_singular() ) {
  2370. $page_style = get_cfield( 'site_style' );
  2371. if ( $page_style ) {
  2372. $style = $page_style == 'boxed' ? ' page-boxed' : '';
  2373. }
  2374. }
  2375. if ( $style == ' page-boxed' ) {
  2376. add_filter( 'body_class', 'kleo_boxed_bg_body_class' );
  2377. }
  2378.  
  2379. return $style;
  2380. }
  2381.  
  2382. add_filter( 'kleo_site_style', 'kleo_custom_site_style' );
  2383.  
  2384. function kleo_boxed_bg_body_class( $classes ) {
  2385. $classes[] = 'page-boxed-bg';
  2386.  
  2387. return $classes;
  2388. }
  2389.  
  2390.  
  2391. /***************************************************
  2392. * :: Blog tags in footer
  2393. ***************************************************/
  2394.  
  2395. function kleo_show_post_tags( $content ) {
  2396. if ( is_single() ) {
  2397. $tag_list = get_the_tag_list( '', __( ', ', 'kleo_framework' ) );
  2398. if ( isset( $tag_list ) && $tag_list ) {
  2399. $tags_array = explode( ',', $tag_list );
  2400.  
  2401. $tag_html = '';
  2402. foreach ( $tags_array as $tag ) {
  2403. $tag_html .= '<span class="label label-default">' . $tag . '</span> ';
  2404. }
  2405. $content .= esc_html__( 'Tags: ', 'kleo_framework' ) . $tag_html;
  2406. }
  2407. }
  2408.  
  2409. return $content;
  2410. }
  2411.  
  2412. if ( sq_option( 'blog_tags_footer', 0 ) ) {
  2413. add_action( 'the_content', 'kleo_show_post_tags', 20 );
  2414. }
  2415.  
  2416.  
  2417. /*
  2418. * Force URLs in srcset attributes into HTTPS scheme.
  2419. * This is particularly useful when you're running a Flexible SSL frontend like Cloudflare
  2420. */
  2421. function ssl_srcset( $sources ) {
  2422. if ( is_ssl() ) {
  2423. foreach ( $sources as &$source ) {
  2424. $source['url'] = set_url_scheme( $source['url'], 'https' );
  2425. }
  2426. }
  2427.  
  2428. return $sources;
  2429. }
  2430.  
  2431. add_filter( 'wp_calculate_image_srcset', 'ssl_srcset' );
  2432.  
  2433.  
  2434. /***************************************************
  2435. * :: Manage custom page redirects
  2436. ***************************************************/
  2437.  
  2438. function kleo_template_redirect() {
  2439. if ( is_user_logged_in() ) {
  2440. $homepage_redirect = sq_option( 'homepage_redirect', 'disabled' );
  2441. if ( is_front_page() && ( $homepage_redirect == 'profile' || $homepage_redirect == 'custom' ) ) {
  2442. if ( function_exists( 'bp_is_active' ) ) {
  2443. $logged_in_link = bp_loggedin_user_domain( '/' );
  2444. } elseif ( class_exists( 'bbPress' ) ) {
  2445. $logged_in_link = bbp_get_user_profile_url( bbp_get_current_user_id() );
  2446. } else {
  2447. $logged_in_link = home_url( 'author' );
  2448. }
  2449.  
  2450. if ( $homepage_redirect == 'profile' ) {
  2451. wp_redirect( $logged_in_link );
  2452. }
  2453. if ( $homepage_redirect == 'custom' ) {
  2454. $homepage_redirect_custom = sq_option( 'homepage_redirect_custom', $logged_in_link );
  2455. if ( strpos( $homepage_redirect_custom, '##profile_link##' ) !== false ) {
  2456. $homepage_redirect_custom = str_replace( '##profile_link##', $logged_in_link, $homepage_redirect_custom );
  2457. }
  2458. wp_redirect( $homepage_redirect_custom );
  2459. }
  2460. exit;
  2461. }
  2462. }
  2463. }
  2464.  
  2465. add_action( 'template_redirect', 'kleo_template_redirect' );
  2466.  
  2467.  
  2468. /**
  2469. * Remove hentry class from pages to stop google structured data errors
  2470. *
  2471. * @param array $classes
  2472. *
  2473. * @return array
  2474. */
  2475. function kleo_remove_hentry_on_pages( $classes ) {
  2476. if ( is_page() && ! ( function_exists( 'bp_is_group_forum_topic' ) && bp_is_group_forum_topic() ) ) {
  2477. $classes = array_diff( $classes, array( 'hentry' ) );
  2478. }
  2479.  
  2480. return $classes;
  2481. }
  2482.  
  2483. add_filter( 'post_class', 'kleo_remove_hentry_on_pages' );
  2484.  
  2485.  
  2486. /* Re-enable theme auto-update for Go Pricing Tables */
  2487. add_action( 'admin_init', 'kleo_go_pricing_enable_updates', 11 );
  2488.  
  2489. function kleo_go_pricing_enable_updates() {
  2490. if ( class_exists( 'GW_GoPricing_Update' ) ) {
  2491. remove_filter( 'pre_set_site_transient_update_plugins', array(
  2492. GW_GoPricing_Update::instance(),
  2493. 'check_update'
  2494. ) );
  2495. remove_filter( 'plugins_api', array( GW_GoPricing_Update::instance(), 'update_info' ), 10, 3 );
  2496. }
  2497. }
  2498.  
  2499.  
  2500. if ( sq_option( 'mobile_app_capable', 1 ) ) {
  2501. add_action( 'wp_head', 'kleo_add_mobile_app_capable_tag' );
  2502. }
  2503. function kleo_add_mobile_app_capable_tag() {
  2504. ?>
  2505. <meta name="mobile-web-app-capable" content="yes">
  2506. <?php
  2507. }
  2508.  
  2509. if ( sq_option( 'apple_mobile_app_capable', 1 ) ) {
  2510. add_action( 'wp_head', 'kleo_add_apple_mobile_app_capable_tag' );
  2511. }
  2512. function kleo_add_apple_mobile_app_capable_tag() {
  2513. ?>
  2514. <meta name="apple-mobile-web-app-capable" content="yes">
  2515. <?php
  2516. }
  2517.  
  2518.  
  2519. if ( sq_option( 'meta_theme_color', '' ) != '' && sq_option( 'meta_theme_color', '' ) != 'transparent' ) {
  2520. add_action( 'wp_head', 'kleo_add_meta_color' );
  2521. }
  2522. function kleo_add_meta_color() {
  2523. ?>
  2524. <!-- Chrome, Firefox OS and Opera -->
  2525. <meta name="theme-color" content="<?php echo sq_option( 'meta_theme_color', '' ); ?>">
  2526. <!-- Windows Phone -->
  2527. <meta name="msapplication-navbutton-color" content="<?php echo sq_option( 'meta_theme_color', '' ); ?>">
  2528. <!-- Safari -->
  2529. <meta name="apple-mobile-web-app-status-bar-style" content="<?php echo sq_option( 'meta_theme_color', '' ); ?>">
  2530. <?php
  2531. }
  2532.  
  2533.  
  2534. /* Schema org for body */
  2535. if ( ! function_exists( 'kleo_get_schema_org_markup' ) ) {
  2536.  
  2537. function kleo_get_schema_org_markup() {
  2538. $type = '';
  2539. $schema = 'http://schema.org/';
  2540. if ( is_singular( 'portfolio' ) ) {
  2541. $type = "VisualArtwork";
  2542. }
  2543. elseif ( function_exists('bp_is_active') && bp_is_user() ) {
  2544. $type = 'ProfilePage';
  2545. }
  2546. elseif ( is_author() ) {
  2547. $type = 'ProfilePage';
  2548. } // Is search results page
  2549. elseif ( is_search() ) {
  2550. $type = 'SearchResultsPage';
  2551. }
  2552.  
  2553. $type = apply_filters( 'kleo_schema_org_type', $type );
  2554. if ($type !== '' ) {
  2555. return ' itemscope itemtype="' . $schema . $type . '"';
  2556. }
  2557. return '';
  2558. }
  2559.  
  2560. }
  2561.  
  2562. function kleo_schema_org_markup() {
  2563. echo kleo_get_schema_org_markup();
  2564. }
  2565.  
  2566. function check_bbpress_components_add_schema() {
  2567. /* If bbpress plugin it's active add schema for their forum/topics components */
  2568. if(class_exists( 'bbPress')) {
  2569. if (bbp_is_forum_archive() || bbp_is_topic_archive() || bbp_is_single_forum() || bbp_is_single_topic() || bbp_is_single_reply() || bbp_is_single_view()) {
  2570. add_filter('kleo_schema_org_type', function () {
  2571. return 'DiscussionForumPosting';
  2572. });
  2573. }
  2574. }
  2575. }
  2576. add_action( 'wp', 'check_bbpress_components_add_schema' );
  2577.  
  2578. /**
  2579. *
  2580. * Override header layout at page level
  2581. *
  2582. * @param $output
  2583. * @param $option
  2584. *
  2585. * @return bool|mixed
  2586. */
  2587. function kleo_override_header_layout( $output, $option ) {
  2588. if ( $option == 'header_layout' ) {
  2589. $output = get_cfield( 'header_layout' );
  2590. }
  2591.  
  2592. return $output;
  2593. }
  2594.  
  2595.  
  2596. /* Remove blog posts from main blog loop */
  2597. if ( sq_option( 'blog_exclude_cat' ) ) {
  2598. function sq_exclude_blog_category( $query ) {
  2599. $to_exclude = sq_option( 'blog_exclude_cat' );
  2600. if ( ! empty( $to_exclude ) && is_array( $to_exclude ) ) {
  2601. if ( $query->is_home() && $query->is_main_query() ) {
  2602. $query->set( 'category__not_in', $to_exclude );
  2603. }
  2604. }
  2605. }
  2606.  
  2607. add_action( 'pre_get_posts', 'sq_exclude_blog_category' );
  2608. }
  2609.  
  2610. /* Tag cloud font size */
  2611. if ( sq_option( 'blog_tag_cloud', 0 ) == 0 ) {
  2612. add_action( 'init', 'sq_tag_cloud_size' );
  2613. function sq_tag_cloud_size() {
  2614. sq_kleo()->add_css( '.widget_tag_cloud a { font-size: small !important; }' );
  2615. }
  2616. }
  2617.  
  2618. /* Ajax for posts grid element */
  2619. add_action( 'wp_ajax_nopriv_vc_post_items', 'sq_vc_posts_ajax' );
  2620. add_action( 'wp_ajax_vc_post_items', 'sq_vc_posts_ajax' );
  2621.  
  2622. function sq_vc_posts_ajax() {
  2623. // Check the nonce, if it fails the function will break
  2624. check_ajax_referer( 'kleo-ajax-posts-nonce', 'security' );
  2625.  
  2626. /* If not our action, bail out */
  2627. if ( ! isset( $_POST['action'] ) || 'vc_post_items' != $_POST['action'] ) {
  2628. return false;
  2629. }
  2630.  
  2631. $count_id = (int) $_POST['pitem'];
  2632. $post_id = $_POST['post_id'];
  2633. if (isset( $_POST['paged'] )) {
  2634. $paged = $_POST['paged'];
  2635. } else {
  2636. $paged = '';
  2637. }
  2638.  
  2639. $args = get_transient( 'kleo_post_' . $post_id . '_' . $count_id );
  2640. if ( $args ) {
  2641. $args = maybe_unserialize( $args );
  2642. }
  2643.  
  2644. if ( ! is_array( $args ) ) {
  2645. wp_send_json_error( array( 'message' => __( 'Something went wrong. Please reload page.', 'kleo_framework' ) ) );
  2646. exit;
  2647. }
  2648.  
  2649. $args['ajax_paged'] = $paged;
  2650. $args['ajax_post'] = $post_id;
  2651. $items = vc_do_shortcode( $args, null, 'vc_posts_grid' );
  2652. wp_send_json_success( array( 'message' => $items ) );
  2653. exit;
  2654. }
  2655.  
  2656. /* Check if the function exists */
  2657. if( ! function_exists( 'sq_kleo_ajax_search_on_default_search' ) ) {
  2658. /* Add kleo_search_form top default search page wordpress only when k-elements plugin its activated */
  2659. function sq_kleo_ajax_search_on_default_search()
  2660. { /* Check if K-elements plugin it-s activated. */
  2661. if ( defined( 'K_ELEM_PLUGIN_FILE' ) ) {
  2662. if ( is_search() ) {
  2663. echo '<div class="sq-kleo-ajax-seach-page container" style="padding-bottom:20px">';
  2664. echo do_shortcode( '[kleo_search_form context="" placeholder="'.__('Search here..','kleo_framework').'"]' );
  2665. echo '</div>';
  2666. }
  2667. }
  2668. }
  2669. /* TODO Check the search replacement */
  2670. //add_action('kleo_before_main_content', 'sq_kleo_ajax_search_on_default_search');
  2671. }
  2672.  
  2673.  
  2674.  
  2675. /* Essential Real Estate plugin compat */
  2676. //https://wordpress.org/plugins/essential-real-estate/
  2677. if ( defined( 'ERE_PLUGIN_VER' ) ) {
  2678.  
  2679. if ( ! function_exists( 'kleo_ere_before_main_content' ) ) {
  2680. function kleo_ere_before_main_content() {
  2681. remove_action( 'kleo_before_main_content', 'kleo_title_main_content' );
  2682. get_template_part( 'page-parts/general-before-wrap' );
  2683. }
  2684.  
  2685. add_action( 'ere_before_main_content', 'kleo_ere_before_main_content' );
  2686. }
  2687. if ( ! function_exists( 'kleo_ere_after_main_content' ) ) {
  2688. function kleo_ere_after_main_content() {
  2689. get_template_part( 'page-parts/general-after-wrap' );
  2690. }
  2691.  
  2692. add_action( 'ere_after_main_content', 'kleo_ere_after_main_content', 1 );
  2693. }
  2694. }
  2695.  
  2696.  
  2697. /* When theme options are saved, remove the dynamic css file */
  2698. if (! function_exists('kleo_write_dynamic_css_file')) {
  2699. function kleo_write_dynamic_css_file() {
  2700.  
  2701. global $kleo_config;
  2702. if ( file_exists( trailingslashit( $kleo_config['custom_style_path'] ) . 'dynamic.css' ) ) {
  2703. unlink( trailingslashit( $kleo_config['custom_style_path'] ) . 'dynamic.css' ); // Delete it
  2704. }
  2705.  
  2706. delete_transient( KLEO_DOMAIN . '_google_link' );
  2707. }
  2708. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement