Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 93.17 KB | None | 0 0
  1. <?php
  2. define('AZEXO_FRAMEWORK', 'AZEXO');
  3. define('AZEXO_FRAMEWORK_VERSION', '1.26');
  4.  
  5. add_action('admin_notices', 'azexo_admin_notices');
  6.  
  7. function azexo_admin_notices() {
  8. if (version_compare(phpversion(), '5.3.6', '<')) {
  9. ?>
  10. <div class="error">
  11. <p><?php esc_html_e('PHP version must be >= 5.3.6', 'pilgrim'); ?></p>
  12. </div>
  13. <?php
  14. }
  15. }
  16.  
  17. add_action('after_setup_theme', 'azexo_after_setup_theme');
  18.  
  19. function azexo_after_setup_theme() {
  20. load_theme_textdomain('pilgrim', get_template_directory() . '/languages');
  21. add_theme_support('custom-logo');
  22. add_theme_support('post-formats', array('gallery', 'video'));
  23. add_theme_support('post-thumbnails');
  24. add_theme_support('automatic-feed-links');
  25. add_theme_support('title-tag');
  26. }
  27.  
  28. add_action('admin_enqueue_scripts', 'azexo_admin_scripts');
  29.  
  30. function azexo_admin_scripts() {
  31. wp_enqueue_script('azexo-admin', get_template_directory_uri() . '/js/admin.js', array('jquery'), AZEXO_FRAMEWORK_VERSION, true);
  32. $options = get_option(AZEXO_FRAMEWORK);
  33. wp_localize_script('azexo-admin', 'azexo', array(
  34. 'framework_confirmation' => isset($options['framework_confirmation']) ? $options['framework_confirmation'] : 0,
  35. 'templates_configuration' => esc_html__('Templates configuration', 'pilgrim'),
  36. 'fields_configuration' => esc_html__('Fields configuration', 'pilgrim'),
  37. 'post_types_settings' => esc_html__('Post types settings', 'pilgrim'),
  38. 'woocommerce_templates_configuration' => esc_html__('WooCommerce templates configuration', 'pilgrim'),
  39. 'section_alert' => esc_html__('Please click "Ok" to confirm this info. Theme not provide CSS styles for all possible configurations in this section. Please use configurations only provided with demo content. Of course you can use it with complete freedom, but in this case it may be necessary to add CSS styles. You can save confirmation of this alert in "AZEXO Options > General settings".', 'pilgrim'),
  40. 'element_alert' => esc_html__('Please click "Ok" to confirm this info. Theme not provide CSS styles for all possible settings of this element. Please use settings only provided with demo content. Of course you can use it with complete freedom, but in this case it may be necessary to add CSS styles. You can save confirmation of this alert in "AZEXO Options > General settings".', 'pilgrim'),
  41. ));
  42. }
  43.  
  44. function azexo_locate_template($template_names) {
  45. $located = '';
  46. foreach ((array) $template_names as $template_name) {
  47. if (!$template_name) {
  48. continue;
  49. }
  50. if (file_exists(get_stylesheet_directory() . '/' . $template_name)) {
  51. $located = get_stylesheet_directory() . '/' . $template_name;
  52. break;
  53. }
  54. if (file_exists(get_template_directory() . '/' . $template_name)) {
  55. $located = get_template_directory() . '/' . $template_name;
  56. break;
  57. }
  58. }
  59. return $located;
  60. }
  61.  
  62. function azexo_is_empty($var) {
  63. return empty($var);
  64. }
  65.  
  66. function azexo_get_templates() {
  67. $options = get_option(AZEXO_FRAMEWORK);
  68. global $azexo_templates;
  69. if (!isset($azexo_templates)) {
  70. $azexo_templates = array();
  71. }
  72. $azexo_templates = array_merge($azexo_templates, array(
  73. 'post' => esc_html__('Post', 'pilgrim'), //default template
  74. 'masonry_post' => esc_html__('Masonry post', 'pilgrim'), //fixed selector in JS
  75. 'navigation_post' => esc_html__('Navigation post', 'pilgrim'), //fixed in full post navigation
  76. 'related_post' => esc_html__('Related post', 'pilgrim'), //fixed in YARP template
  77. ));
  78.  
  79. if (isset($options['templates']) && is_array($options['templates'])) {
  80. $options['templates'] = array_filter($options['templates']);
  81. if (!empty($options['templates'])) {
  82. $azexo_templates = array_merge($azexo_templates, array_combine(array_map('sanitize_title', $options['templates']), $options['templates']));
  83. }
  84. }
  85.  
  86. $azexo_templates = apply_filters('azexo_templates', $azexo_templates);
  87. return $azexo_templates;
  88. }
  89.  
  90. add_action('admin_bar_menu', 'azexo_admin_bar_menu', 999);
  91.  
  92. function azexo_admin_bar_menu($wp_admin_bar) {
  93. $args = array(
  94. 'id' => 'edit-links',
  95. 'title' => esc_html__('Edit links', 'pilgrim'),
  96. 'href' => '#',
  97. 'meta' => array(
  98. 'class' => 'active',
  99. ),
  100. );
  101. $wp_admin_bar->add_node($args);
  102. }
  103.  
  104. function azexo_get_skin() {
  105. $options = get_option(AZEXO_FRAMEWORK);
  106. $skin = '';
  107. if (isset($options['skin'])) {
  108. if (file_exists(get_template_directory() . '/less/' . $options['skin'] . '/skin.less')) {
  109. $skin = $options['skin'];
  110. }
  111. }
  112. if (empty($skin)) {
  113. $skin = get_template();
  114. }
  115. return $skin;
  116. }
  117.  
  118. function azexo_filesystem() {
  119. static $creds = false;
  120.  
  121. require_once ABSPATH . '/wp-admin/includes/template.php';
  122. require_once ABSPATH . '/wp-admin/includes/file.php';
  123.  
  124. if ($creds === false) {
  125. if (false === ( $creds = request_filesystem_credentials(admin_url()) )) {
  126. exit();
  127. }
  128. }
  129.  
  130. if (!WP_Filesystem($creds)) {
  131. request_filesystem_credentials(admin_url(), '', true);
  132. exit();
  133. }
  134. }
  135.  
  136. add_action('init', 'azexo_load_default_skin_options', 12); // after options-init.php
  137.  
  138. function azexo_load_default_skin_options() {
  139.  
  140. $options = get_option(AZEXO_FRAMEWORK);
  141. if (!isset($options['skin']) || !file_exists(get_template_directory() . '/options/' . $options['skin'] . '.json')) {
  142. $skin = get_template();
  143. $file = get_template_directory() . '/options/' . $skin . '.json';
  144. if (file_exists($file) && is_admin()) {
  145.  
  146. azexo_filesystem();
  147. global $wp_filesystem;
  148. $file_contents = $wp_filesystem->get_contents($file);
  149.  
  150.  
  151. $options = json_decode($file_contents, true);
  152. if (is_admin() && function_exists('get_redux_instance')) {
  153. $redux = get_redux_instance(AZEXO_FRAMEWORK);
  154. $redux->set_options($options);
  155. } else {
  156. update_option(AZEXO_FRAMEWORK, $options);
  157. }
  158. }
  159. }
  160. }
  161.  
  162. function azexo_dynamic_css() {
  163. $css = '';
  164.  
  165. $post_categories = get_categories();
  166. global $azexo_category_fields;
  167.  
  168. if (!empty($post_categories)) {
  169. foreach ($post_categories as $cat) {
  170. $cat_color = $azexo_category_fields->get_category_meta($cat->cat_ID, 'color');
  171. $css .= $cat_color ? 'a.' . esc_attr(str_replace('_', '-', $cat->slug)) . '[rel="category tag"], a.' . esc_attr(str_replace('_', '-', $cat->slug)) . '[rel="category"] { background-color:' . esc_attr($cat_color) . ' !important;}' : '';
  172. }
  173. }
  174.  
  175. $azexo_custom_css = get_option('azexo_wpb_shortcodes_custom_css', array());
  176. if (is_array($azexo_custom_css)) {
  177. foreach ($azexo_custom_css as $custom_css) {
  178. $css .= $custom_css;
  179. }
  180. }
  181.  
  182. return $css;
  183. }
  184.  
  185. add_filter('embed_defaults', 'azexo_embed_defaults');
  186.  
  187. function azexo_embed_defaults() {
  188. return array('width' => 1000, 'height' => 500);
  189. }
  190.  
  191. function azexo_excerpt($content, $excerpt_length = false, $trim_by_words = true) {
  192. if (empty($excerpt_length)) {
  193. $excerpt_length = isset($options['excerpt_length']) ? $options['excerpt_length'] : 15;
  194. }
  195. $options = get_option(AZEXO_FRAMEWORK);
  196. if (isset($options['strip_excerpt']) && $options['strip_excerpt'] && is_numeric($excerpt_length)) {
  197. $excerpt = wp_strip_all_tags(strip_shortcodes($content));
  198. if ($trim_by_words) {
  199. $excerpt = wp_trim_words($excerpt, $excerpt_length);
  200. } else {
  201. $excerpt = substr($excerpt, 0, $excerpt_length) . '...';
  202. }
  203. return $excerpt;
  204. } else {
  205. return $content;
  206. }
  207. }
  208.  
  209. function azexo_comment_excerpt($content) {
  210. $options = get_option(AZEXO_FRAMEWORK);
  211. $excerpt = wp_trim_words(wp_strip_all_tags(strip_shortcodes($content)), isset($options['comment_excerpt_length']) ? $options['comment_excerpt_length'] : 15);
  212. return $excerpt;
  213. }
  214.  
  215. if (!isset($content_width)) {
  216. $content_width = 1;
  217. }
  218.  
  219. class AZEXO_Walker_Comment extends Walker_Comment {
  220.  
  221. protected function comment($comment, $depth, $args) {
  222. if ('div' == $args['style']) {
  223. $tag = 'div';
  224. $add_below = 'comment';
  225. } else {
  226. $tag = 'li';
  227. $add_below = 'div-comment';
  228. }
  229. $options = get_option(AZEXO_FRAMEWORK);
  230. ?>
  231. <<?php print $tag; ?> <?php comment_class($this->has_children ? 'parent' : '' ); ?> id="comment-<?php comment_ID(); ?>">
  232. <?php if ('div' != $args['style']) : ?>
  233. <div id="div-comment-<?php comment_ID(); ?>" class="comment-body">
  234. <?php endif; ?>
  235. <div class="comment-author">
  236. <?php if (0 != $args['avatar_size']) echo get_avatar($comment, $args['avatar_size']); ?>
  237. </div>
  238. <div class="comment-data">
  239. <?php printf(wp_kses(__('<cite class="fn">%s</cite>', 'pilgrim'), array('cite' => array('class' => array()))), get_comment_author_link()); ?>
  240. <?php if ('0' == $comment->comment_approved) : ?>
  241. <em class="comment-awaiting-moderation"><?php esc_html_e('Your comment is awaiting moderation.', 'pilgrim') ?></em>
  242. <br />
  243. <?php endif; ?>
  244. <div class="comment-meta commentmetadata"><a href="<?php echo esc_url(get_comment_link($comment->comment_ID, $args)); ?>">
  245. <?php
  246. /* translators: 1: date, 2: time */
  247. printf(esc_html__('%1$s at %2$s', 'pilgrim'), get_comment_date(), get_comment_time());
  248. ?></a><?php edit_comment_link(esc_html__('(Edit)', 'pilgrim'), '&nbsp;&nbsp;', '');
  249. ?>
  250. </div>
  251. <?php comment_text(get_comment_id(), array_merge($args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
  252. <div class="reply">
  253. <?php comment_reply_link(array_merge($args, array('reply_text' => esc_html__('Reply', 'pilgrim'), 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
  254. </div>
  255. <?php if (isset($options['comment_likes']) && $options['comment_likes']) : ?>
  256. <div class="like"> <?php if (function_exists('azpl_get_simple_likes_button')) {
  257. print azpl_get_simple_likes_button($comment->comment_ID, true);
  258. } ?> </div>
  259. <?php endif; ?>
  260. </div>
  261. <?php if ('div' != $args['style']) : ?>
  262. </div>
  263. <?php endif; ?>
  264. <?php
  265. }
  266.  
  267. }
  268.  
  269. if (function_exists('register_nav_menus')) {
  270. register_nav_menus(array(
  271. 'primary' => esc_html__('Top primary menu', 'pilgrim'),
  272. 'secondary' => esc_html__('Secondary menu', 'pilgrim'),
  273. ));
  274. }
  275.  
  276.  
  277. add_filter('update_post_metadata', 'azexo_update_post_metadata', 10, 5);
  278.  
  279. function azexo_update_post_metadata($check, $object_id, $meta_key, $meta_value, $prev_value) {
  280. if ($meta_key == '_wpb_shortcodes_custom_css') {
  281. $azexo_custom_css = get_option('azexo_wpb_shortcodes_custom_css', array());
  282. $azexo_custom_css[$object_id] = $meta_value;
  283. update_option('azexo_wpb_shortcodes_custom_css', $azexo_custom_css);
  284. }
  285. return $check;
  286. }
  287.  
  288. function azexo_get_post_wpb_css($id = NULL) {
  289. if ($id == NULL) {
  290. $id = get_the_ID();
  291. }
  292.  
  293. $azexo_custom_css = get_option('azexo_wpb_shortcodes_custom_css', array());
  294. if (!isset($azexo_custom_css[$id])) {
  295. $azexo_custom_css[$id] = get_post_meta($id, '_wpb_shortcodes_custom_css', true);
  296. update_option('azexo_wpb_shortcodes_custom_css', $azexo_custom_css);
  297.  
  298. $shortcodes_custom_css = $azexo_custom_css[$id];
  299. if (!empty($shortcodes_custom_css)) {
  300. return '<style type="text/css" data-type="vc_shortcodes-custom-css" scoped>' . $shortcodes_custom_css . '</style>';
  301. }
  302. }
  303. return '';
  304. }
  305.  
  306. function azexo_replace_vc_ids($content) {
  307. $matches = array();
  308. preg_match_all('/tab\_id\=\"([^\"]+)\"/', $content, $matches);
  309. foreach ($matches[0] as $match) {
  310. $content = str_replace($match, 'tab_id="azexo-' . rand(0, 99999999) . '"', $content);
  311. }
  312. return $content;
  313. }
  314.  
  315. global $azexo_current_post_stack;
  316. $azexo_current_post_stack = array();
  317. add_action('the_post', 'azexo_the_post');
  318.  
  319. function azexo_the_post($post) {
  320. global $azexo_current_post_stack;
  321. $index = count($azexo_current_post_stack);
  322. while ($index) {
  323. $index--;
  324. if ($azexo_current_post_stack[$index]->ID == $post->ID) {
  325. array_splice($azexo_current_post_stack, $index);
  326. }
  327. }
  328. $azexo_current_post_stack[] = $post;
  329. }
  330.  
  331. add_filter('document_title_parts', 'azexo_document_title_parts');
  332.  
  333. function azexo_document_title_parts($title) {
  334. if (!isset($title['title']) || is_null($title['title'])) {
  335. global $azexo_queried_object;
  336. if (isset($azexo_queried_object) && is_object($azexo_queried_object) && property_exists($azexo_queried_object, 'post_title')) {
  337. $title['title'] = $azexo_queried_object->post_title;
  338. }
  339. }
  340. return $title;
  341. }
  342.  
  343. add_filter('template_include', 'azexo_template_include');
  344.  
  345. function azexo_template_include($template) {
  346. if (is_singular() || is_home()) {
  347. global $azexo_current_post_stack, $wp_query;
  348. $queried_object = $wp_query->get_queried_object();
  349. if (is_object($queried_object)) {
  350. if (property_exists($queried_object, 'ID')) {
  351. $azexo_current_post_stack = array($queried_object);
  352. }
  353. }
  354. }
  355. return $template;
  356. }
  357.  
  358. function azexo_get_earliest_current_post($post_type, $equal = true) {
  359. global $azexo_current_post_stack;
  360. $post = null;
  361. $index = 0;
  362. $post_type = (array) $post_type;
  363. while ($index < count($azexo_current_post_stack)) {
  364. if ($equal) {
  365. if (in_array($azexo_current_post_stack[$index]->post_type, $post_type)) {
  366. $post = $azexo_current_post_stack[$index];
  367. break;
  368. }
  369. } else {
  370. if (!in_array($azexo_current_post_stack[$index]->post_type, $post_type)) {
  371. $post = $azexo_current_post_stack[$index];
  372. break;
  373. }
  374. }
  375. $index++;
  376. }
  377. if (is_null($post)) {
  378. $post = apply_filters('azexo_get_earliest_current_post', $post, $post_type, $equal);
  379. }
  380. return $post;
  381. }
  382.  
  383. function azexo_get_closest_current_post($post_type, $equal = true) {
  384. global $azexo_current_post_stack;
  385. $post = null;
  386. $index = count($azexo_current_post_stack);
  387. $post_type = (array) $post_type;
  388. while ($index) {
  389. $index--;
  390. if ($equal) {
  391. if (in_array($azexo_current_post_stack[$index]->post_type, $post_type)) {
  392. $post = $azexo_current_post_stack[$index];
  393. break;
  394. }
  395. } else {
  396. if (!in_array($azexo_current_post_stack[$index]->post_type, $post_type)) {
  397. $post = $azexo_current_post_stack[$index];
  398. break;
  399. }
  400. }
  401. }
  402. if (is_null($post)) {
  403. $post = apply_filters('azexo_get_closest_current_post', $post, $post_type, $equal);
  404. }
  405. return $post;
  406. }
  407.  
  408. function azexo_is_current_post($id) {
  409. global $azexo_current_post_stack;
  410. $current_post = reset($azexo_current_post_stack);
  411. return $current_post && is_object($current_post) && (is_single() || is_page()) && ($current_post->ID == $id);
  412. }
  413.  
  414. function azexo_get_post_content($id = NULL) {
  415. if ($id == NULL) {
  416. $content = get_the_content('');
  417. $content = azexo_replace_vc_ids($content);
  418. $content = '<div class="scoped-style" data-content-id="' . esc_attr(get_the_ID()) . '">' . azexo_get_post_wpb_css(get_the_ID()) . apply_filters('the_content', $content) . '</div>';
  419. } else {
  420. global $post, $wp_query;
  421. $original = $post;
  422. $post = get_post($id);
  423. setup_postdata($post);
  424. $content = get_the_content('');
  425. $content = azexo_replace_vc_ids($content);
  426. $content = '<div class="scoped-style" data-content-id="' . esc_attr($id) . '">' . azexo_get_post_wpb_css($id) . apply_filters('the_content', $content) . '</div>';
  427. $wp_query->post = $original;
  428. wp_reset_postdata();
  429. }
  430.  
  431. return $content;
  432. }
  433.  
  434. add_filter('nav_menu_link_attributes', 'azexo_nav_menu_link_attributes', 10, 4);
  435.  
  436. function azexo_nav_menu_link_attributes($atts, $item, $args, $depth) {
  437. if (strpos($atts['title'], 'mega') !== false) {
  438. $atts['title'] = str_replace('mega', '', $atts['title']);
  439. $atts['href'] = '#';
  440. }
  441. $atts['class'] = 'menu-link';
  442. return $atts;
  443. }
  444.  
  445. add_filter('nav_menu_css_class', 'azexo_nav_menu_css_class', 10, 4);
  446.  
  447. function azexo_nav_menu_css_class($classes, $item, $args, $depth) {
  448. if (strpos($item->attr_title, 'mega') !== false && $depth == 0) {
  449. $classes[] = 'mega';
  450. }
  451. return $classes;
  452. }
  453.  
  454. add_filter('widget_nav_menu_args', 'azexo_widget_nav_menu_args', 10, 3);
  455.  
  456. function azexo_widget_nav_menu_args($nav_menu_args, $nav_menu, $args) {
  457. $nav_menu_args['walker'] = new AZEXO_Walker_Nav_Menu();
  458. if (isset($args['vc']) && $args['vc']) {
  459. $nav_menu_args['vc'] = true;
  460. $nav_menu_args['menu_class'] = 'menu vc';
  461. }
  462. return $nav_menu_args;
  463. }
  464.  
  465. class AZEXO_Walker_Nav_Menu extends Walker_Nav_Menu {
  466.  
  467. public function start_lvl(&$output, $depth = 0, $args = array()) {
  468. $indent = str_repeat("\t", $depth);
  469. if (is_array($args) && isset($args['vc']) && $args['vc'] || is_object($args) && isset($args->vc) && $args->vc) {
  470. $output .= "\n$indent<ul class=\"sub-menu vc\">\n";
  471. } else {
  472. $output .= "\n$indent<ul class=\"sub-menu\">\n";
  473. }
  474. }
  475.  
  476. public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
  477. $item->additions = '';
  478. $item = apply_filters('azexo_menu_start_el', $item, $args);
  479. if (preg_match('/icon\(([^\)]*)\)/i', $item->attr_title, $icon)) {
  480. $item->attr_title = str_replace($icon[0], '', $item->attr_title);
  481. $args->link_before = ' <span class="' . $icon[1] . '"></span>';
  482. }
  483. if (is_array($item->classes)) {
  484. if (in_array('fa', $item->classes)) {
  485. $item->classes = array_diff($item->classes, array('fa'));
  486. $searchword = 'fa-';
  487. $matches = array_filter($item->classes, function($var) use ($searchword) {
  488. return preg_match("/\b$searchword\b/i", $var);
  489. });
  490. foreach ($matches as $match) {
  491. $item->classes = array_diff($item->classes, array($match));
  492. $args->link_before = ' <span class="fa ' . $match . '"></span>';
  493. }
  494. }
  495. $searchword = 'ti-';
  496. $matches = array_filter($item->classes, function($var) use ($searchword) {
  497. return preg_match("/\b$searchword\b/i", $var);
  498. });
  499. foreach ($matches as $match) {
  500. $item->classes = array_diff($item->classes, array($match));
  501. $args->link_before = ' <span class="' . $match . '"></span>';
  502. }
  503. }
  504. if (isset($item->description) && !empty($item->description)) {
  505. $args->link_after = '<span class="description">' . $item->description . '</span>';
  506. }
  507. parent::start_el($output, $item, $depth, $args, $id);
  508. if (is_object($args)) {
  509. $args->link_before = '';
  510. $args->link_after = '';
  511. }
  512. }
  513.  
  514. public function end_el(&$output, $item, $depth = 0, $args = array()) {
  515. if (strpos($item->attr_title, 'mega') !== false && $depth == 0) {
  516. $output .= '<div class="page">' . azexo_get_post_content($item->object_id) . '</div>';
  517. }
  518. $output .= $item->additions;
  519. $item->additions = '';
  520. $output .= "</li>\n";
  521. }
  522.  
  523. }
  524.  
  525. add_filter('widget_categories_args', 'azexo_widget_categories_args');
  526.  
  527. function azexo_widget_categories_args($args) {
  528. $args['walker'] = new AZEXO_Walker_Category();
  529. return $args;
  530. }
  531.  
  532. function azexo_list_cats($name, $category = false) {
  533. if ($category) {
  534. if (function_exists('get_term_meta')) {
  535. $thumbnail_id = get_term_meta($category->term_id, 'thumbnail_id', true);
  536. if ($thumbnail_id) {
  537. return wp_get_attachment_image($thumbnail_id) . '<span>' . $name . '</span>';
  538. }
  539. }
  540. }
  541. return $name;
  542. }
  543.  
  544. class AZEXO_Walker_Category extends Walker_Category {
  545.  
  546. public function start_el(&$output, $category, $depth = 0, $args = array(), $id = 0) {
  547. $show_count = 0;
  548. if (isset($args['show_count'])) {
  549. $show_count = $args['show_count'];
  550. $args['show_count'] = 0;
  551. }
  552.  
  553. add_filter('list_cats', 'azexo_list_cats', 10, 2);
  554. parent::start_el($output, $category, $depth, $args, $id);
  555. remove_filter('list_cats', 'azexo_list_cats', 10, 2);
  556.  
  557. $args['show_count'] = $show_count;
  558.  
  559. if ($show_count) {
  560. $output .= ' <span class="count">' . number_format_i18n($category->count) . '</span>';
  561. }
  562. }
  563.  
  564. }
  565.  
  566. add_filter('get_archives_link', 'azexo_get_archives_link', 10, 6);
  567.  
  568. function azexo_get_archives_link($link_html, $url, $text, $format, $before, $after) {
  569. $text = wptexturize($text);
  570. $url = esc_url($url);
  571.  
  572. if ('link' == $format)
  573. $link_html = "\t<link rel='archives' title='" . esc_attr($text) . "' href='" . esc_url($url) . "' />\n";
  574. elseif ('option' == $format)
  575. $link_html = "\t<option value='" . esc_url($url) . "'>$before $text $after</option>\n";
  576. elseif ('html' == $format)
  577. $link_html = "\t<li><span class='before'>$before</span><a href='" . esc_url($url) . "'>$text</a><span class='after'>$after</span></li>\n";
  578. else // custom
  579. $link_html = "\t<span class='before'>$before</span><a href='" . esc_url($url) . "'>$text</a><span class='after'>$after</span>\n";
  580.  
  581. return $link_html;
  582. }
  583.  
  584. add_action('widgets_init', 'azexo_widgets_init');
  585.  
  586. function azexo_widgets_init() {
  587. if (function_exists('register_sidebar')) {
  588. register_sidebar(array('name' => esc_html__('Right/Left sidebar', 'pilgrim'), 'id' => "sidebar", 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<div class="widget-title"><h3>', 'after_title' => '</h3></div>'));
  589. register_sidebar(array('name' => esc_html__('Header sidebar', 'pilgrim'), 'id' => "header_sidebar", 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<div class="widget-title"><h3>', 'after_title' => '</h3></div>'));
  590. register_sidebar(array('name' => esc_html__('Middle sidebar', 'pilgrim'), 'id' => "middle_sidebar", 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<div class="widget-title"><h3>', 'after_title' => '</h3></div>'));
  591. register_sidebar(array('name' => esc_html__('Footer sidebar', 'pilgrim'), 'id' => "footer_sidebar", 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<div class="widget-title"><h3>', 'after_title' => '</h3></div>'));
  592. register_sidebar(array('name' => esc_html__('Dashboard sidebar', 'pilgrim'), 'id' => "dashboard_sidebar", 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<div class="widget-title"><h3>', 'after_title' => '</h3></div>'));
  593. register_sidebar(array('name' => esc_html__('Additional sidebar', 'pilgrim'), 'id' => "additional_sidebar", 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<div class="widget-title"><h3>', 'after_title' => '</h3></div>'));
  594. }
  595. }
  596.  
  597. function azexo_add_element($settings) {
  598. if (function_exists('vc_map')) {
  599. vc_map($settings);
  600. global $azh_shortcodes;
  601. if (isset($azh_shortcodes)) {
  602. $azh_shortcodes[$settings['base']] = $settings;
  603. }
  604. } else {
  605. if (function_exists('azh_add_element')) {
  606. azh_add_element($settings);
  607. }
  608. }
  609. }
  610.  
  611. if (file_exists(get_template_directory() . '/framework/az_bookings.php') && function_exists('azb_plugins_loaded')) {
  612. require_once(trailingslashit(get_template_directory()) . 'framework/az_bookings.php');
  613. }
  614. if (file_exists(get_template_directory() . '/framework/az_group_buying.php') && function_exists('azgb_plugins_loaded')) {
  615. require_once(trailingslashit(get_template_directory()) . 'framework/az_group_buying.php');
  616. }
  617. if (file_exists(get_template_directory() . '/framework/az_listings.php') && function_exists('azl_plugins_loaded')) {
  618. require_once(trailingslashit(get_template_directory()) . 'framework/az_listings.php');
  619. }
  620. if (file_exists(get_template_directory() . '/framework/profiles.php') && function_exists('azl_plugins_loaded')) {
  621. require_once(trailingslashit(get_template_directory()) . 'framework/profiles.php');
  622. }
  623. if (file_exists(get_template_directory() . '/framework/az_query_form.php') && function_exists('azqf_plugins_loaded')) {
  624. require_once(trailingslashit(get_template_directory()) . 'framework/az_query_form.php');
  625. }
  626. if (file_exists(get_template_directory() . '/framework/az_vouchers.php') && function_exists('azv_plugins_loaded')) {
  627. require_once(trailingslashit(get_template_directory()) . 'framework/az_vouchers.php');
  628. }
  629. if (file_exists(get_template_directory() . '/framework/az_deals.php') && function_exists('azd_plugins_loaded')) {
  630. require_once(trailingslashit(get_template_directory()) . 'framework/az_deals.php');
  631. }
  632. if (file_exists(get_template_directory() . '/framework/woocommerce.php')) {
  633. require_once(trailingslashit(get_template_directory()) . 'framework/woocommerce.php');
  634. }
  635. if (file_exists(get_template_directory() . '/framework/azh.php')) {
  636. require_once(trailingslashit(get_template_directory()) . 'framework/azh.php');
  637. }
  638. if (file_exists(get_template_directory() . '/framework/contact-form-7.php')) {
  639. require_once(trailingslashit(get_template_directory()) . 'framework/contact-form-7.php');
  640. }
  641. require_once(trailingslashit(get_template_directory()) . 'framework/class.category-custom-fields.php');
  642. require_once(trailingslashit(get_template_directory()) . 'framework/class.breadcrumb.php');
  643. if (is_admin()) {
  644. require_once(trailingslashit(get_template_directory()) . 'framework/redux-extensions/loader.php');
  645. require_once(trailingslashit(get_template_directory()) . 'framework/options-init.php');
  646. require_once(trailingslashit(get_template_directory()) . 'tgm/class-tgm-plugin-activation.php');
  647. require_once(trailingslashit(get_template_directory()) . 'framework/tgm-init.php');
  648. }
  649. require_once(trailingslashit(get_template_directory()) . 'framework/options-wpml.php');
  650. require_once(trailingslashit(get_template_directory()) . 'framework/widgets.php');
  651.  
  652. add_action('init', 'azexo_init', 12); // after options-init.php
  653.  
  654. function azexo_init() {
  655. if (file_exists(get_template_directory() . '/framework/vc_extend.php')) {
  656. require_once(trailingslashit(get_template_directory()) . 'framework/vc_extend.php');
  657. }
  658. global $azexo_fields_post_types;
  659. if (!isset($azexo_fields_post_types)) {
  660. $azexo_fields_post_types = array();
  661. }
  662. global $azexo_post_fields;
  663. if (!isset($azexo_post_fields)) {
  664. $azexo_post_fields = array();
  665. }
  666. if (!empty($azexo_post_fields)) {
  667. $azexo_fields_post_types = array_merge($azexo_fields_post_types, array_combine(array_keys($azexo_post_fields), array_fill(0, count(array_keys($azexo_post_fields)), 'post')));
  668. }
  669.  
  670. $azexo_fields_post_types = apply_filters('azexo_fields_post_types', $azexo_fields_post_types);
  671. }
  672.  
  673. function azexo_removeDemoModeLink() {
  674. if (class_exists('ReduxFrameworkPlugin')) {
  675. remove_filter('plugin_row_meta', array(ReduxFrameworkPlugin::get_instance(), 'plugin_metalinks'), null, 2);
  676. remove_action('admin_notices', array(ReduxFrameworkPlugin::get_instance(), 'admin_notices'));
  677. }
  678. }
  679.  
  680. add_action('init', 'azexo_removeDemoModeLink');
  681.  
  682. add_filter('use_default_gallery_style', '__return_false');
  683.  
  684. if (is_admin()) {
  685. require_once(trailingslashit(get_template_directory()) . 'framework/exporter/export.php');
  686. require_once(trailingslashit(get_template_directory()) . 'framework/importer/import.php');
  687. }
  688.  
  689. function azexo_header_parts() {
  690. $options = get_option(AZEXO_FRAMEWORK);
  691. if (isset($options['header'])) {
  692. foreach ((array) $options['header'] as $part) {
  693.  
  694. $template_part = azexo_is_template_part_exists('template-parts/header', $part);
  695. if (!empty($template_part)) {
  696. get_template_part('template-parts/header', $part);
  697. } else {
  698. switch ($part) {
  699. case 'logo':
  700. ?>
  701. <a class="site-title" href="<?php print esc_url(home_url('/')); ?>" rel="home">
  702. <?php if (isset($options['logo']['url']) && !empty($options['logo']['url'])): ?>
  703. <img src="<?php print esc_url($options['logo']['url']); ?>" alt="logo">
  704. <?php else: ?>
  705. <span class="title"><?php print esc_html(get_bloginfo('name')); ?></span>
  706. <?php endif; ?>
  707. </a>
  708. <?php
  709. break;
  710. case 'search':
  711. azexo_get_search_form();
  712. break;
  713. case 'mobile_menu_button':
  714. ?>
  715. <div class="mobile-menu-button"><span><i class="fa fa-bars"></i></span></div>
  716. <?php
  717. break;
  718. case 'mobile_menu':
  719. ?><nav class="site-navigation mobile-menu"><?php
  720. if (has_nav_menu('primary')) {
  721. wp_nav_menu(array(
  722. 'theme_location' => 'primary',
  723. 'menu_class' => 'nav-menu',
  724. 'menu_id' => 'primary-menu-mobile',
  725. 'walker' => new AZEXO_Walker_Nav_Menu(),
  726. ));
  727. }
  728. ?></nav><?php
  729. break;
  730. case 'primary_menu':
  731. ?><nav class="site-navigation primary-navigation"><?php
  732. if (has_nav_menu('primary')) {
  733. wp_nav_menu(array(
  734. 'theme_location' => 'primary',
  735. 'menu_class' => 'nav-menu',
  736. 'menu_id' => 'primary-menu',
  737. 'walker' => new AZEXO_Walker_Nav_Menu(),
  738. ));
  739. }
  740. ?></nav><?php
  741. break;
  742. case 'secondary_menu':
  743. ?><nav class="secondary-navigation"><?php
  744. if (has_nav_menu('secondary')) {
  745. wp_nav_menu(array(
  746. 'theme_location' => 'secondary',
  747. 'menu_class' => 'nav-menu',
  748. 'menu_id' => 'secondary-menu',
  749. 'walker' => new AZEXO_Walker_Nav_Menu(),
  750. ));
  751. }
  752. ?></nav><?php
  753. break;
  754. default:
  755. break;
  756. }
  757. }
  758. }
  759. }
  760. }
  761.  
  762. add_action('wp_insert_comment', 'azexo_insert_comment', 10, 2);
  763.  
  764. function azexo_insert_comment($id, $comment) {
  765. delete_post_meta($comment->comment_post_ID, 'last_comment_date');
  766. add_post_meta($comment->comment_post_ID, 'last_comment_date', $comment->comment_date);
  767. }
  768.  
  769. function azexo_is_post_type_query($query, $post_type) {
  770. $post_types = $query->get('post_type');
  771. if (!is_array($post_types)) {
  772. $post_types = array($post_types);
  773. }
  774.  
  775. $taxonomy = false;
  776. $taxonomy_names = get_object_taxonomies($post_type);
  777. foreach ($taxonomy_names as $taxonomy_name) {
  778. if ($query->get($taxonomy_name)) {
  779. $taxonomy = true;
  780. break;
  781. }
  782. }
  783. return (in_array($post_type, $post_types) && count($post_types) == 1) || $taxonomy;
  784. }
  785.  
  786. add_action('pre_get_posts', 'azexo_pre_get_posts');
  787.  
  788. function azexo_pre_get_posts($query) {
  789. if ($query->is_main_query()) {
  790. $post_type = isset($query->query['post_type']) ? $query->query['post_type'] : 'post';
  791. if (is_array($post_type)) {
  792. $post_type = reset($post_type);
  793. }
  794. $options = get_option(AZEXO_FRAMEWORK);
  795. $orderby_value = isset($_GET['orderby']) ? $_GET['orderby'] : 'menu_order';
  796. $order = explode('-', $orderby_value);
  797. $order = !empty($order[1]) ? $order[1] : '';
  798. $order = strtoupper($order);
  799. $order = ($order == 'DESC') ? 'DESC' : 'ASC';
  800.  
  801. switch ($orderby_value) {
  802. case 'menu_order':
  803. if (isset($options[$post_type . '_custom_sorting']) && is_array($options[$post_type . '_custom_sorting'])) {
  804. if (in_array('menu_order', $options[$post_type . '_custom_sorting'])) {
  805. $query->set('orderby', 'menu_order title');
  806. $query->set('order', $order);
  807. }
  808. }
  809. break;
  810. case 'date':
  811. if (isset($options[$post_type . '_custom_sorting']) && is_array($options[$post_type . '_custom_sorting'])) {
  812. if (in_array('date', $options[$post_type . '_custom_sorting'])) {
  813. $query->set('orderby', 'date ID');
  814. $query->set('order', $order);
  815. }
  816. }
  817. break;
  818. default:
  819. if (isset($options[$post_type . '_custom_sorting_numeric_meta_keys']) && is_array($options[$post_type . '_custom_sorting_numeric_meta_keys'])) {
  820. foreach ($options[$post_type . '_custom_sorting_numeric_meta_keys'] as $meta_key) {
  821. if ($meta_key . '-asc' == $orderby_value) {
  822. $query->set('orderby', 'meta_value_num');
  823. $query->set('order', 'ASC');
  824. $query->set('meta_key', $meta_key);
  825. }
  826. if ($meta_key . '-desc' == $orderby_value) {
  827. $query->set('orderby', 'meta_value_num');
  828. $query->set('order', 'DESC');
  829. $query->set('meta_key', $meta_key);
  830. }
  831. }
  832. }
  833. break;
  834. }
  835. }
  836. }
  837.  
  838. function azexo_before_list($post_type) {
  839. global $wp_query;
  840. $options = get_option(AZEXO_FRAMEWORK);
  841. $orderby_options = array(
  842. 'menu_order' => esc_html__('Default sorting', 'pilgrim'),
  843. 'date' => esc_html__('Sort by newness', 'pilgrim'),
  844. );
  845. if (isset($options[$post_type . '_custom_sorting']) && is_array($options[$post_type . '_custom_sorting'])) {
  846. $orderby_options = array_intersect_key($orderby_options, array_combine($options[$post_type . '_custom_sorting'], $options[$post_type . '_custom_sorting']));
  847. }
  848. if (isset($options[$post_type . '_custom_sorting_numeric_meta_keys']) && is_array($options[$post_type . '_custom_sorting_numeric_meta_keys'])) {
  849. foreach ($options[$post_type . '_custom_sorting_numeric_meta_keys'] as $meta_key) {
  850. if (!empty($meta_key)) {
  851. $orderby_options[esc_attr($meta_key) . '-desc'] = sprintf(esc_attr__('Sort by %s: high to low', 'pilgrim'), esc_attr($meta_key));
  852. $orderby_options[esc_attr($meta_key) . '-asc'] = sprintf(esc_attr__('Sort by %s: low to high', 'pilgrim'), esc_attr($meta_key));
  853. }
  854. }
  855. }
  856. $orderby = isset($_GET['orderby']) ? $_GET['orderby'] : 'menu_order';
  857.  
  858. if (isset($options[$post_type . '_before_list']) && is_array($options[$post_type . '_before_list']) && !empty($options[$post_type . '_before_list'])) {
  859. ?><div class="before-list"><?php
  860. foreach ((array) $options[$post_type . '_before_list'] as $part) {
  861. switch ($part) {
  862. case 'result_count':
  863. ?><p class="result-count"><?php
  864. $paged = max(1, $wp_query->get('paged'));
  865. $per_page = $wp_query->get('posts_per_page');
  866. $total = $wp_query->found_posts;
  867. $first = ( $per_page * $paged ) - $per_page + 1;
  868. $last = min($total, $wp_query->get('posts_per_page') * $paged);
  869.  
  870. if ($total <= $per_page || -1 === $per_page) {
  871. printf(_n('Showing the single result', 'Showing all %d results', $total, 'pilgrim'), $total);
  872. } else {
  873. printf(_nx('Showing the single result', 'Showing %1$d&ndash;%2$d of %3$d results', $total, '%1$d = first, %2$d = last, %3$d = total', 'pilgrim'), $first, $last, $total);
  874. }
  875. ?></p><?php
  876. break;
  877. case 'ordering':
  878. ?>
  879. <form class="ordering" method="get">
  880. <select name="orderby" class="orderby">
  881. <?php foreach ($orderby_options as $id => $name) : ?>
  882. <option value="<?php echo esc_attr($id); ?>" <?php selected(esc_attr($orderby), $id); ?>><?php echo esc_html($name); ?></option>
  883. <?php endforeach; ?>
  884. </select>
  885. <?php
  886. foreach ($_GET as $key => $val) {
  887. if ('orderby' === $key || 'submit' === $key) {
  888. continue;
  889. }
  890. if (is_array($val)) {
  891. foreach ($val as $innerVal) {
  892. echo '<input type="hidden" name="' . esc_attr($key) . '[]" value="' . esc_attr($innerVal) . '" />';
  893. }
  894. } else {
  895. echo '<input type="hidden" name="' . esc_attr($key) . '" value="' . esc_attr($val) . '" />';
  896. }
  897. }
  898. ?>
  899. </form>
  900. <?php
  901. break;
  902. default:
  903. break;
  904. }
  905. }
  906. ?></div><?php
  907. }
  908. }
  909.  
  910. function azexo_paging_nav() {
  911. global $wp_query, $wp_rewrite;
  912.  
  913. // Don't print empty markup if there's only one page.
  914. if ($wp_query->max_num_pages < 2) {
  915. return;
  916. }
  917.  
  918. $paged = get_query_var('paged') ? intval(get_query_var('paged')) : 1;
  919. $pagenum_link = html_entity_decode(get_pagenum_link());
  920. $query_args = array();
  921. $url_parts = explode('?', $pagenum_link);
  922.  
  923. if (isset($url_parts[1])) {
  924. wp_parse_str($url_parts[1], $query_args);
  925. }
  926.  
  927. $pagenum_link = remove_query_arg(array_keys($query_args), $pagenum_link);
  928. $pagenum_link = trailingslashit($pagenum_link) . '%_%';
  929.  
  930. $format = $wp_rewrite->using_index_permalinks() && !strpos($pagenum_link, 'index.php') ? 'index.php/' : '';
  931. $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit($wp_rewrite->pagination_base . '/%#%', 'paged') : '?paged=%#%';
  932.  
  933. // Set up paginated links.
  934. $links = paginate_links(array(
  935. 'base' => $pagenum_link,
  936. 'format' => $format,
  937. 'total' => $wp_query->max_num_pages,
  938. 'current' => $paged,
  939. 'mid_size' => 1,
  940. 'add_args' => array_map('urlencode', $query_args),
  941. 'prev_text' => '<i class="prev"></i>' . '<span>' . esc_html__('Previous', 'pilgrim') . '</span>',
  942. 'next_text' => '<span>' . esc_html__('Next', 'pilgrim') . '</span>' . '<i class="next"></i>',
  943. ));
  944.  
  945. if ($links) :
  946. ?>
  947. <nav class="navigation paging-navigation">
  948. <div class="pagination loop-pagination">
  949. <?php print $links; ?>
  950. </div><!-- .pagination -->
  951. </nav><!-- .navigation -->
  952. <?php
  953. endif;
  954. }
  955.  
  956. function azexo_post_nav_full() {
  957. global $post;
  958.  
  959. // Don't print empty markup if there's nowhere to navigate.
  960. $previous = ( is_attachment() ) ? get_post($post->post_parent) : get_adjacent_post(false, '', true);
  961. $next = get_adjacent_post(false, '', false);
  962. $options = get_option(AZEXO_FRAMEWORK);
  963. if (!$next && !$previous)
  964. return;
  965. ?>
  966. <nav class="navigation post-navigation-full clearfix">
  967. <div class="prev-post">
  968. <?php
  969. global $post, $wp_query;
  970. $original = $post;
  971. $post = $previous;
  972. setup_postdata($post);
  973.  
  974. $template_name = 'navigation_post';
  975. include(azexo_locate_template(apply_filters('azexo_post_template_path', 'content.php', $template_name)));
  976.  
  977. $wp_query->post = $original;
  978. wp_reset_postdata();
  979. ?>
  980. </div>
  981. <div class="next-post">
  982. <?php
  983. global $post, $wp_query;
  984. $original = $post;
  985. $post = $next;
  986. setup_postdata($post);
  987.  
  988. $template_name = 'navigation_post';
  989. include(azexo_locate_template(apply_filters('azexo_post_template_path', 'content.php', $template_name)));
  990.  
  991. $wp_query->post = $original;
  992. wp_reset_postdata();
  993. ?>
  994. </div>
  995. </nav><!-- .navigation -->
  996. <?php
  997. }
  998.  
  999. function azexo_post_nav() {
  1000. global $post;
  1001.  
  1002. // Don't print empty markup if there's nowhere to navigate.
  1003. $previous = ( is_attachment() ) ? get_post($post->post_parent) : get_adjacent_post(false, '', true);
  1004. $next = get_adjacent_post(false, '', false);
  1005. $options = get_option(AZEXO_FRAMEWORK);
  1006. if (!$next && !$previous)
  1007. return;
  1008. ?>
  1009. <nav class="navigation post-navigation clearfix">
  1010. <div class="nav-links">
  1011.  
  1012. <?php previous_post_link('%link', '<i class="prev"></i><div class="prev-post"><span class="helper">' . (isset($options['post_navigation_previous']) ? $options['post_navigation_previous'] : '') . '</span><span class="title">%title</span></div>'); ?>
  1013. <?php next_post_link('%link', '<i class="next"></i><div class="next-post"><span class="helper">' . (isset($options['post_navigation_next']) ? $options['post_navigation_next'] : '') . '</span><span class="title">%title</span></div>'); ?>
  1014.  
  1015. </div><!-- .nav-links -->
  1016. </nav><!-- .navigation -->
  1017. <?php
  1018. }
  1019.  
  1020. function azexo_get_the_category_list($separator = '', $parents = '', $post_id = false) {
  1021. global $wp_rewrite;
  1022. if (!is_object_in_taxonomy(get_post_type($post_id), 'category')) {
  1023. /** This filter is documented in wp-includes/category-template.php */
  1024. return apply_filters('the_category', '', $separator, $parents);
  1025. }
  1026.  
  1027. $categories = get_the_category($post_id);
  1028. if (empty($categories)) {
  1029. /** This filter is documented in wp-includes/category-template.php */
  1030. return apply_filters('the_category', esc_html__('Uncategorized', 'pilgrim'), $separator, $parents);
  1031. }
  1032.  
  1033. $rel = ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"';
  1034.  
  1035. $thelist = '';
  1036. if ('' == $separator) {
  1037. $thelist .= '<ul class="post-categories">';
  1038. foreach ($categories as $category) {
  1039. $thelist .= "\n\t<li>";
  1040. switch (strtolower($parents)) {
  1041. case 'multiple':
  1042. if ($category->parent)
  1043. $thelist .= get_category_parents($category->parent, true, $separator);
  1044. $thelist .= '<a class="' . str_replace('_', '-', $category->slug) . '" href="' . esc_url(get_category_link($category->term_id)) . '" ' . $rel . '>' . $category->name . '</a></li>';
  1045. break;
  1046. case 'single':
  1047. $thelist .= '<a class="' . str_replace('_', '-', $category->slug) . '" href="' . esc_url(get_category_link($category->term_id)) . '" ' . $rel . '>';
  1048. if ($category->parent)
  1049. $thelist .= get_category_parents($category->parent, false, $separator);
  1050. $thelist .= $category->name . '</a></li>';
  1051. break;
  1052. case '':
  1053. default:
  1054. $thelist .= '<a class="' . str_replace('_', '-', $category->slug) . '" href="' . esc_url(get_category_link($category->term_id)) . '" ' . $rel . '>' . $category->name . '</a></li>';
  1055. }
  1056. }
  1057. $thelist .= '</ul>';
  1058. } else {
  1059. $i = 0;
  1060. foreach ($categories as $category) {
  1061. if (0 < $i)
  1062. $thelist .= $separator;
  1063. switch (strtolower($parents)) {
  1064. case 'multiple':
  1065. if ($category->parent)
  1066. $thelist .= get_category_parents($category->parent, true, $separator);
  1067. $thelist .= '<a class="' . str_replace('_', '-', $category->slug) . '" href="' . esc_url(get_category_link($category->term_id)) . '" ' . $rel . '>' . $category->name . '</a>';
  1068. break;
  1069. case 'single':
  1070. $thelist .= '<a class="' . str_replace('_', '-', $category->slug) . '" href="' . esc_url(get_category_link($category->term_id)) . '" ' . $rel . '>';
  1071. if ($category->parent)
  1072. $thelist .= get_category_parents($category->parent, false, $separator);
  1073. $thelist .= "$category->name</a>";
  1074. break;
  1075. case '':
  1076. default:
  1077. $thelist .= '<a class="' . str_replace('_', '-', $category->slug) . '" href="' . esc_url(get_category_link($category->term_id)) . '" ' . $rel . '>' . $category->name . '</a>';
  1078. }
  1079. ++$i;
  1080. }
  1081. }
  1082. return apply_filters('the_category', $thelist, $separator, $parents);
  1083. }
  1084.  
  1085. function azexo_post_thumbnail_field($template_name = false) {
  1086. if (!$template_name) {
  1087. $template_name = get_post_type();
  1088. }
  1089. $options = get_option(AZEXO_FRAMEWORK);
  1090. $thumbnail_size = isset($options[$template_name . '_thumbnail_size']) && !empty($options[$template_name . '_thumbnail_size']) ? $options[$template_name . '_thumbnail_size'] : 'large';
  1091. $lazy = isset($options[$template_name . '_lazy']) && !empty($options[$template_name . '_lazy']) ? $options[$template_name . '_lazy'] : false;
  1092. if ($lazy) {
  1093. wp_enqueue_script('waypoints');
  1094. }
  1095. $url = azexo_get_the_post_thumbnail(get_the_ID(), $thumbnail_size, true);
  1096. $size = azexo_get_image_sizes($thumbnail_size);
  1097. $zoom = isset($options[$template_name . '_zoom']) && esc_attr($options[$template_name . '_zoom']) ? 'zoom' : '';
  1098. ?>
  1099. <a href="<?php esc_url(the_permalink()); ?>">
  1100. <?php if ($lazy): ?>
  1101. <?php if ($thumbnail_size == 'full'): ?>
  1102. <img class="image lazy <?php print esc_attr($zoom); ?>" data-src="<?php print esc_url($url[0]); ?>" alt="">
  1103. <?php else: ?>
  1104. <div class="image lazy <?php print esc_attr($zoom); ?>" data-src="<?php print esc_url($url[0]); ?>" style="height: <?php print esc_attr($size['height']); ?>px;" data-width="<?php print esc_attr($size['width']); ?>" data-height="<?php print esc_attr($size['height']); ?>">
  1105. </div>
  1106. <?php endif; ?>
  1107. <?php else: ?>
  1108. <?php if ($thumbnail_size == 'full'): ?>
  1109. <img class="image <?php print esc_attr($zoom); ?>" src="<?php print esc_url($url[0]); ?>" alt="">
  1110. <?php else: ?>
  1111. <div class="image <?php print esc_attr($zoom); ?>" style='background-image: url("<?php print esc_url($url[0]); ?>"); height: <?php print esc_attr($size['height']); ?>px;' data-width="<?php print esc_attr($size['width']); ?>" data-height="<?php print esc_attr($size['height']); ?>">
  1112. </div>
  1113. <?php endif; ?>
  1114. <?php endif; ?>
  1115. </a>
  1116. <?php
  1117. }
  1118.  
  1119. function azexo_post_gallery_field($template_name = false) {
  1120. if (!$template_name) {
  1121. $template_name = get_post_type();
  1122. }
  1123. $options = get_option(AZEXO_FRAMEWORK);
  1124. $thumbnail_size = isset($options[$template_name . '_thumbnail_size']) && !empty($options[$template_name . '_thumbnail_size']) ? $options[$template_name . '_thumbnail_size'] : 'large';
  1125. $show_carousel = isset($options[$template_name . '_show_carousel']) && $options[$template_name . '_show_carousel'];
  1126. $gallery_slider_thumbnails = isset($options[$template_name . '_gallery_slider_thumbnails']) && $options[$template_name . '_gallery_slider_thumbnails'];
  1127. $gallery_slider_thumbnails_vertical = isset($options[$template_name . '_gallery_slider_thumbnails_vertical']) && $options[$template_name . '_gallery_slider_thumbnails_vertical'];
  1128. $lazy = isset($options[$template_name . '_lazy']) && !empty($options[$template_name . '_lazy']) ? $options[$template_name . '_lazy'] : false;
  1129. $zoom = isset($options[$template_name . '_zoom']) && !empty($options[$template_name . '_zoom']) ? 'zoom' : '';
  1130. $gallery = get_post_gallery(get_the_ID(), false);
  1131. if (is_array($gallery)) {
  1132. if (isset($gallery['ids'])) {
  1133. $attachment_ids = explode(",", $gallery['ids']);
  1134. print azexo_entry_gallery($attachment_ids, $show_carousel, $gallery_slider_thumbnails, $thumbnail_size, $gallery_slider_thumbnails_vertical, $lazy, $zoom);
  1135. return;
  1136. }
  1137. }
  1138. $attachment_ids = get_post_meta(get_the_ID(), '_gallery', true);
  1139. if ($attachment_ids) {
  1140. $attachment_ids = explode(",", $attachment_ids);
  1141. print azexo_entry_gallery($attachment_ids, $show_carousel, $gallery_slider_thumbnails, $thumbnail_size, $gallery_slider_thumbnails_vertical, $lazy, $zoom);
  1142. return;
  1143. }
  1144. $attachment_ids = get_children(array('post_parent' => get_the_ID(), 'fields' => 'ids', 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID'));
  1145. if (!empty($attachment_ids)) {
  1146. print azexo_entry_gallery($attachment_ids, $show_carousel, $gallery_slider_thumbnails, $thumbnail_size, $gallery_slider_thumbnails_vertical, $lazy, $zoom);
  1147. return;
  1148. }
  1149. if (is_array($gallery)) {
  1150. if (isset($gallery['src']) && is_array($gallery['src'])) {
  1151. print azexo_entry_gallery($gallery['src'], $show_carousel, $gallery_slider_thumbnails, $thumbnail_size, $gallery_slider_thumbnails_vertical, $lazy, $zoom);
  1152. return;
  1153. }
  1154. }
  1155. }
  1156.  
  1157. function azexo_post_video_field() {
  1158. $embed = azexo_get_first_shortcode(get_the_content(''), 'embed');
  1159. if ($embed) {
  1160. global $wp_embed;
  1161. return $wp_embed->run_shortcode($embed);
  1162. } else {
  1163. $url = get_post_meta(get_the_ID(), '_video');
  1164. if ($url) {
  1165. return wp_oembed_get($url);
  1166. }
  1167. }
  1168. }
  1169.  
  1170. function azexo_get_field_templates() {
  1171. $field_templates = get_transient('field_templates');
  1172. if (!is_array($field_templates) && is_admin()) {
  1173.  
  1174. $field_templates = array();
  1175. foreach (array(get_template_directory(), get_stylesheet_directory()) as $path) {
  1176. if (is_dir($path . '/fields')) {
  1177. $directory_iterator = new RecursiveDirectoryIterator($path . '/fields');
  1178. foreach ($directory_iterator as $fileInfo) {
  1179. if ($fileInfo->isFile() && $fileInfo->getExtension() == 'php') {
  1180. azexo_filesystem();
  1181. global $wp_filesystem;
  1182. $file_contents = $wp_filesystem->get_contents($fileInfo->getPathname());
  1183.  
  1184. if (!preg_match('|Field Name:(.*)$|mi', $file_contents, $header)) {
  1185. continue;
  1186. }
  1187. $field_templates[$fileInfo->getFilename()] = _cleanup_header_comment($header[1]);
  1188. }
  1189. }
  1190. }
  1191. }
  1192. set_transient('field_templates', $field_templates);
  1193. }
  1194.  
  1195. return $field_templates;
  1196. }
  1197.  
  1198. function azexo_get_the_term_list($id, $taxonomy, $before = '', $sep = '', $after = '') {
  1199. $terms = get_the_terms($id, $taxonomy);
  1200.  
  1201. if (is_wp_error($terms)) {
  1202. return $terms;
  1203. }
  1204.  
  1205. if (empty($terms)) {
  1206. return false;
  1207. }
  1208.  
  1209. $links = array();
  1210.  
  1211. foreach ($terms as $term) {
  1212. $link = get_term_link($term, $taxonomy);
  1213. if (is_wp_error($link)) {
  1214. return $link;
  1215. }
  1216. $links[] = '<a class="' . esc_attr($term->slug) . '" href="' . esc_url($link) . '" rel="tag">' . $term->name . '</a>';
  1217. }
  1218. $term_links = apply_filters("term_links-$taxonomy", $links);
  1219.  
  1220. return $before . join($sep, $term_links) . $after;
  1221. }
  1222.  
  1223. function azexo_entry_field($name) {
  1224. $options = get_option(AZEXO_FRAMEWORK);
  1225.  
  1226. $output = apply_filters('azexo_entry_field', false, $name);
  1227. if ($output) {
  1228. return $output;
  1229. }
  1230.  
  1231. if (is_numeric($name)) {
  1232. return azexo_get_post_content($name);
  1233. }
  1234.  
  1235. if (strpos($name, '.php') !== false) {
  1236. ob_start();
  1237. include(trailingslashit(get_template_directory()) . 'fields/' . $name);
  1238. return ob_get_clean();
  1239. }
  1240.  
  1241. $image = (isset($options[$name . '_image']) && !empty($options[$name . '_image']['url'])) ? '<img src="' . esc_html($options[$name . '_image']['url']) . '" alt="">' : '';
  1242. $label = (isset($options[$name . '_prefix']) && !empty($options[$name . '_prefix'])) ? '<label>' . esc_html($options[$name . '_prefix']) . '</label>' : '';
  1243. $hide_empty = isset($options[$name . '_hide_empty']) ? $options[$name . '_hide_empty'] : false;
  1244.  
  1245. switch ($name) {
  1246. case 'post_title':
  1247. return the_title('<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>', false);
  1248. break;
  1249. case 'post_summary':
  1250. return '<div class="entry-summary">' . get_the_excerpt() . '</div>';
  1251. break;
  1252. case 'post_content':
  1253. return '<div class="entry-content">' . get_the_content('') . '</div>';
  1254. break;
  1255. case 'post_thumbnail':
  1256. ob_start();
  1257. azexo_post_thumbnail_field();
  1258. return '<div class="entry-thumbnail">' . ob_get_clean() . '</div>';
  1259. break;
  1260. case 'post_video':
  1261. ob_start();
  1262. azexo_post_video_field();
  1263. return '<div class="entry-video">' . ob_get_clean() . '</div>';
  1264. break;
  1265. case 'post_gallery':
  1266. ob_start();
  1267. azexo_post_gallery_field();
  1268. return '<div class="entry-gallery">' . ob_get_clean() . '</div>';
  1269. break;
  1270. case 'post_sticky':
  1271. if (is_sticky() && is_home() && !is_paged())
  1272. return '<span class="featured-post">' . esc_html__('Sticky', 'pilgrim') . '</span>';
  1273. break;
  1274. case 'post_splitted_date':
  1275. return azexo_entry_splitted_date(false);
  1276. break;
  1277. case 'post_date':
  1278. return azexo_entry_date(false);
  1279. break;
  1280. case 'post_category':
  1281. $categories_list = azexo_get_the_category_list('<span class="delimiter">,</span> ');
  1282. if ($categories_list) {
  1283. return '<span class="categories-links">' . (isset($options['post_category_prefix']) ? '<span class="label">' . esc_html($options['post_category_prefix']) : '') . '</span>' . $categories_list . '</span>';
  1284. }
  1285. break;
  1286. case 'post_tags':
  1287. $tag_list = get_the_tag_list('', '<span class="delimiter">,</span> ');
  1288. if ($tag_list) {
  1289. return '<span class="tags-links">' . (isset($options['post_tags_prefix']) ? '<span class="label">' . esc_html($options['post_tags_prefix']) : '') . '</span>' . $tag_list . '</span>';
  1290. }
  1291. break;
  1292. case 'post_author':
  1293. return sprintf('<span class="author vcard">' . (isset($options['post_author_prefix']) ? '<span class="label">' . esc_html($options['post_author_prefix']) : '') . '</span>' . '<a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>', esc_url(get_author_posts_url(get_the_author_meta('ID'))), esc_attr(sprintf(esc_html__('View all posts by %s', 'pilgrim'), get_the_author())), esc_html(get_the_author()));
  1294. break;
  1295. case 'post_author_avatar':
  1296. return '<span class="avatar">' . get_avatar(get_the_author_meta('ID')) . sprintf('<span class="author vcard">' . $label . '<a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>', esc_url(get_author_posts_url(get_the_author_meta('ID'))), esc_attr(sprintf(esc_html__('View all posts by %s', 'pilgrim'), get_the_author())), esc_html(get_the_author())) . '</span>';
  1297. break;
  1298. case 'post_like':
  1299. if (function_exists('azpl_get_simple_likes_button')) {
  1300. return '<span class="like">' . azpl_get_simple_likes_button(get_the_ID()) . '</span>';
  1301. }
  1302. break;
  1303. case 'post_last_comment':
  1304. $args = array(
  1305. 'post_id' => get_the_ID(),
  1306. 'status' => 'approve',
  1307. 'number' => '1',
  1308. );
  1309. $comments = get_comments($args); //get_comments have caching
  1310. $comment = reset($comments);
  1311. if ($comment) {
  1312. return '<div class="last-comment">' . esc_html(azexo_comment_excerpt($comment->comment_content)) . '</div>';
  1313. }
  1314. break;
  1315. case 'post_last_comment_author':
  1316. $args = array(
  1317. 'post_id' => get_the_ID(),
  1318. 'status' => 'approve',
  1319. 'number' => '1',
  1320. );
  1321. $comments = get_comments($args); //get_comments have caching
  1322. $comment = reset($comments);
  1323. if ($comment) {
  1324. return sprintf('<span class="author vcard last-comment">' . $label . '<a class="url fn n" href="%1$s" rel="author">%2$s</a></span>', esc_url(get_author_posts_url(username_exists($comment->comment_author))), esc_html($comment->comment_author));
  1325. }
  1326. break;
  1327. case 'post_last_comment_author_avatar':
  1328. $args = array(
  1329. 'post_id' => get_the_ID(),
  1330. 'status' => 'approve',
  1331. 'number' => '1',
  1332. );
  1333. $comments = get_comments($args); //get_comments have caching
  1334. $comment = reset($comments);
  1335. if ($comment) {
  1336. return '<span class="avatar last-comment">' . get_avatar($comment->comment_author_email) . sprintf('<span class="author vcard">' . $label . '<a class="url fn n" href="%1$s" rel="author">%2$s</a></span>', esc_url(get_author_posts_url(username_exists($comment->comment_author))), esc_html($comment->comment_author)) . '</span>';
  1337. }
  1338. break;
  1339. case 'post_last_comment_date':
  1340. $args = array(
  1341. 'post_id' => get_the_ID(),
  1342. 'status' => 'approve',
  1343. 'number' => '1',
  1344. );
  1345. $comments = get_comments($args); //get_comments have caching
  1346. $comment = reset($comments);
  1347. if ($comment) {
  1348. return '<div class="last-comment-date">' . azexo_comment_date(false, $comment) . '</div>';
  1349. }
  1350. break;
  1351. case 'post_comments_count':
  1352. $comment_count = get_comment_count(get_the_ID());
  1353. $comments = '<a href="' . esc_url(get_comments_link()) . '"><span class="count">' . $comment_count['total_comments'] . '</span><span class="label">' . esc_html__('comments', 'pilgrim') . '</span></a>';
  1354. return '<span class="comments">' . $comments . '</span>';
  1355. break;
  1356. case 'post_read_more':
  1357. $more_link_text = sprintf(esc_html__('Read more', 'pilgrim'));
  1358. return '<div class="entry-more">' . apply_filters('the_content_more_link', ' <a href="' . esc_url(get_permalink()) . "#more-" . get_the_ID() . "\" class=\"more-link\">" . $more_link_text . "</a>", $more_link_text) . '</div>';
  1359. break;
  1360. case 'post_share':
  1361. ob_start();
  1362. azexo_entry_share();
  1363. return '<div class="entry-share">' . '<div class="helper">' . (isset($options['post_share_prefix']) ? esc_html($options['post_share_prefix']) : '') . '</div><span class="links">' . ob_get_clean() . '</span></div>';
  1364. break;
  1365. case 'post_comments':
  1366. ob_start();
  1367. if (comments_open()) {
  1368. comments_template();
  1369. }
  1370. return ob_get_clean();
  1371. break;
  1372. default:
  1373. if (isset($options['meta_fields']) && in_array($name, array_filter($options['meta_fields']))) {
  1374. $value = get_post_meta(get_the_ID(), $name, true);
  1375. $value = trim($value);
  1376. $value = apply_filters('azexo_entry_field_meta_field', $value, $name);
  1377. if (!empty($value) || (empty($value) && !$hide_empty)) {
  1378. return '<span class="meta-field ' . str_replace(array('_', ' '), '-', strtolower($name)) . ' ' . (empty($value) ? 'empty' : '') . '">' . $image . ' ' . $label . ' <span class="value">' . $value . ((isset($options[$name . '_suffix']) && !empty($value)) ? ' <span class="units">' . esc_html($options[$name . '_suffix']) . '</span>' : '') . '</span>' . '</span>';
  1379. }
  1380. } else {
  1381. $taxonomies = get_object_taxonomies(get_post_type());
  1382. $slug = str_replace('taxonomy_', '', $name);
  1383. $term_list = false;
  1384. if (in_array($slug, $taxonomies)) {
  1385. $term_list = azexo_get_the_term_list(get_the_ID(), $slug, '', '<span class="delimiter">,</span> ', '');
  1386. $term_list = apply_filters('azexo_entry_field_taxonomy_field', $term_list, $name);
  1387. $term_list = trim($term_list);
  1388. if (!empty($term_list) || (empty($term_list) && !$hide_empty)) {
  1389. return '<span class="taxonomy ' . str_replace('_', '-', $slug) . ' ' . (empty($term_list) ? 'empty' : '') . '">' . $image . ' ' . $label . ' <span class="links">' . $term_list . '</span></span>';
  1390. }
  1391. }
  1392. }
  1393. return apply_filters('azexo_entry_field_default', '', $name);
  1394. break;
  1395. }
  1396. return '';
  1397. }
  1398.  
  1399. function azexo_entry_meta($template_name = 'post', $place = 'meta') {
  1400. static $cache = array();
  1401. if (isset($cache[get_the_ID()][$template_name][$place])) {
  1402. return $cache[get_the_ID()][$template_name][$place];
  1403. }
  1404. $options = get_option(AZEXO_FRAMEWORK);
  1405. $meta = '';
  1406. if (isset($options[$template_name . '_' . $place]) && is_array($options[$template_name . '_' . $place])) {
  1407. foreach ($options[$template_name . '_' . $place] as $field) {
  1408. $meta .= azexo_entry_field($field);
  1409. }
  1410. }
  1411. $cache[get_the_ID()][$template_name][$place] = $meta;
  1412. return $meta;
  1413. }
  1414.  
  1415. function azexo_entry_share() {
  1416. global $post;
  1417. $image = null;
  1418. if (is_object($post)) {
  1419. $image = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
  1420. }
  1421. print '<a class="facebook-share" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=' . rawurlencode(esc_url(apply_filters('the_permalink', get_permalink()))) . '"><span class="share-box"><i class="fa fa-facebook"></i></span></a>';
  1422. print '<a class="twitter-share" target="_blank" href="https://twitter.com/home?status=' . rawurlencode(esc_attr__('Check out this article: ', 'pilgrim')) . rawurlencode(get_the_title()) . '%20-%20' . rawurlencode(esc_url(apply_filters('the_permalink', get_permalink()))) . '"><span class="share-box"><i class="fa fa-twitter"></i></span></a>';
  1423. if (!empty($image)) {
  1424. print '<a class="pinterest-share" target="_blank" href="https://pinterest.com/pin/create/button/?url=' . rawurlencode(esc_url(apply_filters('the_permalink', get_permalink()))) . '&media=' . rawurlencode($image) . '&description=' . rawurlencode(get_the_title()) . '"><span class="share-box"><i class="fa fa-pinterest"></i></span></a>';
  1425. }
  1426. print '<a class="linkedin-share" target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&url=' . rawurlencode(esc_url(apply_filters('the_permalink', get_permalink()))) . '&title=' . rawurlencode(get_the_title()) . '&source=LinkedIn"><span class="share-box"><i class="fa fa-linkedin"></i></span></a>';
  1427. print '<a class="google-plus-share" target="_blank" href="https://plus.google.com/share?url=' . rawurlencode(esc_url(apply_filters('the_permalink', get_permalink()))) . '"><span class="share-box"><i class="fa fa-google-plus"></i></span></a>';
  1428. if (comments_open() && !is_single() && !is_page()) {
  1429. $comments = '<span class="share-box"><i class="fa fa-comment-o"></i></span>';
  1430. comments_popup_link($comments, $comments, $comments, '', '');
  1431. }
  1432. }
  1433.  
  1434. function azexo_entry_splitted_date($echo = true) {
  1435.  
  1436. $date = '<div class="date"><div class="day">' . get_the_date('d') . '</div><div class="month">' . get_the_date('M') . '</div><div class="year">' . get_the_date('Y') . '</div></div>';
  1437.  
  1438. if ($echo)
  1439. print $date;
  1440.  
  1441. return $date;
  1442. }
  1443.  
  1444. function azexo_entry_date($echo = true, $post = null) {
  1445. if (has_post_format(array('chat', 'status'), $post))
  1446. $format_prefix = _x('%1$s on %2$s', '1: post format name. 2: date', 'pilgrim');
  1447. else
  1448. $format_prefix = '%2$s';
  1449.  
  1450. $options = get_option(AZEXO_FRAMEWORK);
  1451. $date = sprintf('<span class="date">' . (isset($options['post_date_prefix']) ? esc_html($options['post_date_prefix']) : '') . '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a></span>', esc_url(get_permalink($post)), esc_attr(sprintf(esc_html__('Permalink to %s', 'pilgrim'), the_title_attribute(array('echo' => false, 'post' => $post)))), esc_attr(get_the_date('c', $post)), esc_html(sprintf($format_prefix, get_post_format_string(get_post_format($post)), get_the_date('', $post)))
  1452. );
  1453.  
  1454. if ($echo) {
  1455. print $date;
  1456. }
  1457.  
  1458. return $date;
  1459. }
  1460.  
  1461. function azexo_comment_date($echo = true, $comment = null) {
  1462.  
  1463. $format_prefix = '%2$s';
  1464.  
  1465. $options = get_option(AZEXO_FRAMEWORK);
  1466. $date = sprintf('<span class="date">' . (isset($options['post_date_prefix']) ? esc_html($options['post_date_prefix']) : '') . '<a href="%1$s" title="%2$s" rel="bookmark"><time class="comment-date" datetime="%3$s">%4$s</time></a></span>', esc_url(get_comment_link($comment)), esc_attr(sprintf(esc_html__('Permalink to %s', 'pilgrim'), the_title_attribute(array('echo' => false, 'post' => $comment)))
  1467. ), esc_attr(get_comment_date('c', $comment->comment_ID)), esc_html(sprintf($format_prefix, get_post_format_string(get_post_format($comment)), get_comment_date('', $comment->comment_ID))
  1468. )
  1469. );
  1470.  
  1471. if ($echo) {
  1472. print $date;
  1473. }
  1474.  
  1475. return $date;
  1476. }
  1477.  
  1478. function azexo_the_attached_image() {
  1479. $attachment_size = apply_filters('azexo_attachment_size', array(724, 724));
  1480. $next_attachment_url = wp_get_attachment_url();
  1481. $post = get_post();
  1482.  
  1483. $attachment_ids = get_posts(array(
  1484. 'post_parent' => $post->post_parent,
  1485. 'fields' => 'ids',
  1486. 'numberposts' => -1,
  1487. 'post_status' => 'inherit',
  1488. 'post_type' => 'attachment',
  1489. 'post_mime_type' => 'image',
  1490. 'order' => 'ASC',
  1491. 'orderby' => 'menu_order ID'
  1492. ));
  1493.  
  1494. // If there is more than 1 attachment in a gallery...
  1495. if (count($attachment_ids) > 1) {
  1496. foreach ($attachment_ids as $attachment_id) {
  1497. if ($attachment_id == $post->ID) {
  1498. $next_id = current($attachment_ids);
  1499. break;
  1500. }
  1501. }
  1502.  
  1503. // get the URL of the next image attachment...
  1504. if ($next_id)
  1505. $next_attachment_url = get_attachment_link($next_id);
  1506.  
  1507. // or get the URL of the first image attachment.
  1508. else
  1509. $next_attachment_url = get_attachment_link(array_shift($attachment_ids));
  1510. }
  1511.  
  1512. printf('<a href="%1$s" title="%2$s" rel="attachment">%3$s</a>', esc_url($next_attachment_url), the_title_attribute(array('echo' => false)), wp_get_attachment_image($post->ID, $attachment_size)
  1513. );
  1514. }
  1515.  
  1516. function azexo_entry_gallery($attachment_ids, $carousel, $thumbnails, $img_size, $vertical = 0, $lazy = false, $zoom = '') {
  1517. $output = '';
  1518. azexo_add_image_size($img_size);
  1519. $size = azexo_get_image_sizes($img_size);
  1520. if ($carousel) {
  1521. wp_enqueue_script('owl.carousel');
  1522. wp_enqueue_style('owl.carousel');
  1523. } else {
  1524. wp_enqueue_style('flexslider');
  1525. wp_enqueue_script('flexslider');
  1526. }
  1527. $output .= '<div class="images ' . ($thumbnails ? 'thumbnails' : '') . ' ' . ($carousel ? 'carousel' : '') . '" data-width="' . esc_attr($size['width']) . '" data-height="' . esc_attr($size['height']) . '" data-vertical="' . esc_attr($vertical) . '">';
  1528. foreach ($attachment_ids as $attachment_id) {
  1529. $image_url = $attachment_id;
  1530. $full_image_url = $attachment_id;
  1531. if (is_numeric($attachment_id)) {
  1532. $image_url = azexo_get_attachment_thumbnail($attachment_id, $img_size, true);
  1533. $image_url = $image_url[0];
  1534.  
  1535. $full_image_url = azexo_get_attachment_thumbnail($attachment_id, 'full', true);
  1536. $full_image_url = $full_image_url[0];
  1537. }
  1538. if (!empty($image_url)) {
  1539. if ($lazy) {
  1540. if ($img_size == 'full') {
  1541. $output .= '<img class="image lazy" data-src="' . esc_url($image_url) . '" data-popup="' . esc_url($full_image_url) . '" alt="">';
  1542. } else {
  1543. $output .= '<div class="image lazy ' . esc_attr($zoom) . '" data-src="' . esc_url($image_url) . '" data-popup="' . esc_url($full_image_url) . '" style=\'height: ' . esc_attr($size['height']) . 'px;\'></div>';
  1544. }
  1545. } else {
  1546. if ($img_size == 'full') {
  1547. $output .= '<img class="image" src="' . esc_url($image_url) . '" data-popup="' . esc_url($full_image_url) . '" alt="">';
  1548. } else {
  1549. $output .= '<div class="image ' . esc_attr($zoom) . '" data-popup="' . esc_url($full_image_url) . '" style=\'background-image: url("' . esc_url($image_url) . '"); height: ' . esc_attr($size['height']) . 'px;\'></div>';
  1550. }
  1551. }
  1552. }
  1553. }
  1554. $output .= "</div><!-- images -->\n";
  1555. return $output;
  1556. }
  1557.  
  1558. function azexo_get_link_url() {
  1559. $content = get_the_content();
  1560. $has_url = get_url_in_content($content);
  1561. return ( $has_url ) ? $has_url : apply_filters('the_permalink', get_permalink());
  1562. }
  1563.  
  1564. function azexo_get_image_sizes($size = '') {
  1565.  
  1566. global $_wp_additional_image_sizes;
  1567.  
  1568. $sizes = array();
  1569. $get_intermediate_image_sizes = get_intermediate_image_sizes();
  1570.  
  1571. // Create the full array with sizes and crop info
  1572. foreach ($get_intermediate_image_sizes as $_size) {
  1573.  
  1574. if (in_array($_size, array('thumbnail', 'medium', 'large'))) {
  1575.  
  1576. $sizes[$_size]['width'] = get_option($_size . '_size_w');
  1577. $sizes[$_size]['height'] = get_option($_size . '_size_h');
  1578. $sizes[$_size]['crop'] = (bool) get_option($_size . '_crop');
  1579. } elseif (isset($_wp_additional_image_sizes[$_size])) {
  1580.  
  1581. $sizes[$_size] = array(
  1582. 'width' => $_wp_additional_image_sizes[$_size]['width'],
  1583. 'height' => $_wp_additional_image_sizes[$_size]['height'],
  1584. 'crop' => $_wp_additional_image_sizes[$_size]['crop']
  1585. );
  1586. }
  1587. }
  1588.  
  1589. // Get only 1 size if found
  1590. if ($size) {
  1591.  
  1592. if (isset($sizes[$size])) {
  1593. return $sizes[$size];
  1594. } else {
  1595. return false;
  1596. }
  1597. }
  1598.  
  1599. return $sizes;
  1600. }
  1601.  
  1602. function azexo_add_image_size($size) {
  1603. if (!has_image_size($size) && !in_array($size, array('thumbnail', 'medium', 'large'))) {
  1604. $size_array = explode('x', $size);
  1605. if (count($size_array) == 2) {
  1606. add_image_size($size, $size_array[0], $size_array[1], true);
  1607. }
  1608. }
  1609. }
  1610.  
  1611. function azexo_get_attachment_thumbnail($attachment_id, $size, $url = false) {
  1612. azexo_add_image_size($size);
  1613.  
  1614. $metadata = wp_get_attachment_metadata($attachment_id);
  1615. if (is_array($metadata)) {
  1616. $regenerate = false;
  1617. $size_array = explode('x', $size);
  1618. if (count($size_array) == 2) {
  1619. $regenerate = true;
  1620. if (isset($metadata['width']) && isset($metadata['height'])) {
  1621. if ((intval($metadata['width']) < intval($size_array[0])) && (intval($metadata['height']) < intval($size_array[1]))) {
  1622. $regenerate = false;
  1623. }
  1624. } else {
  1625. $regenerate = false;
  1626. }
  1627. }
  1628. if ($regenerate && (!isset($metadata['sizes']) || !isset($metadata['sizes'][$size]))) {
  1629. if (isset($metadata['sizes']) && is_array($metadata['sizes'])) {
  1630. foreach ($metadata['sizes'] as $meta => $data) {
  1631. azexo_add_image_size($meta);
  1632. }
  1633. }
  1634. require_once(ABSPATH . 'wp-admin/includes/image.php');
  1635. require_once(ABSPATH . 'wp-admin/includes/post.php');
  1636. wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, get_attached_file($attachment_id)));
  1637. $metadata = wp_get_attachment_metadata($attachment_id);
  1638. }
  1639. }
  1640. if ($url) {
  1641. $image = wp_get_attachment_image_src($attachment_id, $size);
  1642. if (empty($image)) {
  1643. $image = wp_get_attachment_image_src($attachment_id, 'full');
  1644. }
  1645. return $image;
  1646. } else {
  1647. $image = wp_get_attachment_image($attachment_id, $size);
  1648. if (empty($image)) {
  1649. $image = wp_get_attachment_image_src($attachment_id, 'full');
  1650. }
  1651. return $image;
  1652. }
  1653. }
  1654.  
  1655. function azexo_get_the_post_thumbnail($post_id, $size, $url = false) {
  1656. azexo_add_image_size($size);
  1657. $post_thumbnail_id = get_post_thumbnail_id($post_id);
  1658. if (empty($post_thumbnail_id)) {
  1659. if ($url) {
  1660.  
  1661. } else {
  1662.  
  1663. }
  1664. }
  1665. return azexo_get_attachment_thumbnail($post_thumbnail_id, $size, $url);
  1666. }
  1667.  
  1668. function azexo_get_attachment_image_src($attachment_id, $size) {
  1669. return azexo_get_attachment_thumbnail($attachment_id, $size, true);
  1670. }
  1671.  
  1672. function azexo_strip_first_shortcode($content, $first_shortcode) {
  1673. preg_match_all('/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER);
  1674. if (!empty($matches)) {
  1675. foreach ($matches as $shortcode) {
  1676. if ($first_shortcode === $shortcode[2]) {
  1677. $pos = strpos($content, $shortcode[0]);
  1678. if ($pos !== false)
  1679. return substr_replace($content, '', $pos, strlen($shortcode[0]));
  1680. }
  1681. }
  1682. }
  1683. return $content;
  1684. }
  1685.  
  1686. function azexo_get_first_shortcode($content, $first_shortcode) {
  1687. preg_match_all('/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER);
  1688. if (!empty($matches)) {
  1689. foreach ($matches as $shortcode) {
  1690. if ($first_shortcode === $shortcode[2]) {
  1691. $pos = strpos($content, $shortcode[0]);
  1692. if ($pos !== false)
  1693. return $shortcode[0];
  1694. }
  1695. }
  1696. }
  1697. return false;
  1698. }
  1699.  
  1700. function azexo_get_search_form($echo = true) {
  1701. $result = '<div class="search-wrapper">';
  1702. $result .= get_search_form(false);
  1703. $result .= '<i class="fa fa-search"></i></div>';
  1704. if ($echo) {
  1705. print $result;
  1706. } else {
  1707. return $result;
  1708. }
  1709. }
  1710.  
  1711. function azexo_unparse_url(array $parsed) {
  1712. $scheme = & $parsed['scheme'];
  1713. $host = & $parsed['host'];
  1714. $port = & $parsed['port'];
  1715. $user = & $parsed['user'];
  1716. $pass = & $parsed['pass'];
  1717. $path = & $parsed['path'];
  1718. $query = & $parsed['query'];
  1719. $fragment = & $parsed['fragment'];
  1720.  
  1721. $userinfo = !strlen($pass) ? $user : "$user:$pass";
  1722. $host = !"$port" ? $host : "$host:$port";
  1723. $authority = !strlen($userinfo) ? $host : "$userinfo@$host";
  1724. $hier_part = !strlen($authority) ? $path : "//$authority$path";
  1725. $url = !strlen($scheme) ? $hier_part : "$scheme:$hier_part";
  1726. $url = !strlen($query) ? $url : "$url?$query";
  1727. $url = !strlen($fragment) ? $url : "$url#$fragment";
  1728.  
  1729. return $url;
  1730. }
  1731.  
  1732. add_filter('embed_oembed_html', 'azexo_embed_oembed_html', 10, 4);
  1733.  
  1734. function azexo_embed_oembed_html($html, $url, $attr, $post_ID) {
  1735. if (preg_match('/src="([^"]*)"/', $html, $matches)) {
  1736. $oembed_src = parse_url($matches[1]);
  1737. $user_src = parse_url($url);
  1738. if (isset($user_src['query'])) {
  1739. $oembed_src['query'] = $user_src['query'];
  1740. }
  1741. $html = preg_replace('/src="[^"]*"/', 'src="' . esc_url(azexo_unparse_url($oembed_src)) . '"', $html); //HTML5 query url fix - htmlentities(esc_url(azexo_unparse_url($oembed_src)))
  1742. }
  1743. $html = str_replace(array('frameborder="0"', 'webkitallowfullscreen', 'mozallowfullscreen', 'allowfullscreen'), '', $html);
  1744. return $html;
  1745. }
  1746.  
  1747. function azexo_display_select_tree($term, $selected = '', $level = 0) {
  1748. if (is_object($term)) {
  1749. if (!empty($term->children)) {
  1750. echo '<option value="" disabled>' . str_repeat('&nbsp;&nbsp;', $level) . '' . $term->name . '</option>';
  1751. $level++;
  1752. foreach ($term->children as $key => $child) {
  1753. azexo_display_select_tree($child, $selected, $level);
  1754. }
  1755. } else {
  1756. echo '<option value="' . $term->slug . '" ' . ( $term->slug == $selected ? 'selected="selected"' : '' ) . '>' . str_repeat('&nbsp;&nbsp;', $level) . '' . $term->name . '</option>';
  1757. }
  1758. }
  1759. }
  1760.  
  1761. function azexo_array_filter_recursive($input) {
  1762. foreach ($input as &$value) {
  1763. if (is_array($value)) {
  1764. $value = azexo_array_filter_recursive($value);
  1765. }
  1766. }
  1767. return array_filter($input);
  1768. }
  1769.  
  1770. function azexo_time_left($date_to, $label = '') {
  1771. if (!empty($date_to)) {
  1772. $expire = $date_to - current_time('timestamp');
  1773. if ($expire < 0) {
  1774. $expire = 0;
  1775. }
  1776. $days = floor($expire / 60 / 60 / 24);
  1777. $hours = floor(($expire - $days * 60 * 60 * 24) / 60 / 60);
  1778. $minutes = floor(($expire - $days * 60 * 60 * 24 - $hours * 60 * 60) / 60);
  1779. $seconds = $expire - $days * 60 * 60 * 24 - $hours * 60 * 60 - $minutes * 60;
  1780. wp_enqueue_script('countdown');
  1781. ?>
  1782. <div class="time-left">
  1783. <?php print (empty($label) ? '' : '<label>' . esc_html($label) . '</label>'); ?>
  1784. <div class="time" data-time="<?php print date('Y/m/d H:i:s', $date_to); ?>">
  1785. <div class="days"><span class="count"><?php print $days; ?></span><span class="title"><?php print esc_html__('day', 'pilgrim'); ?></span></div>
  1786. <div class="hours"><span class="count"><?php print $hours; ?></span><span class="title"><?php print esc_html__('hrs', 'pilgrim'); ?></span></div>
  1787. <div class="minutes"><span class="count"><?php print $minutes; ?></span><span class="title"><?php print esc_html__('min', 'pilgrim'); ?></span></div>
  1788. <div class="seconds"><span class="count"><?php print $seconds; ?></span><span class="title"><?php print esc_html__('sec', 'pilgrim'); ?></span></div>
  1789. </div>
  1790. </div>
  1791. <?php
  1792. }
  1793. }
  1794.  
  1795. function azexo_current_time_ordering_filter($args, $query) {
  1796. if (isset($query->query['orderby'])) {
  1797. if ($query->query['orderby'] == 'meta_value') {
  1798. if (isset($query->meta_query) && isset($query->meta_query->meta_table)) {
  1799. if ($query->query['order'] == 'DESC') {
  1800. $args['where'] .= " AND ( " . esc_sql($query->meta_query->meta_table) . ".meta_value <= unix_timestamp()) ";
  1801. } else {
  1802. $args['where'] .= " AND ( " . esc_sql($query->meta_query->meta_table) . ".meta_value >= unix_timestamp()) ";
  1803. }
  1804. }
  1805. }
  1806. }
  1807. return $args;
  1808. }
  1809.  
  1810. function azexo_current_user_author_filter($args, $query) {
  1811. global $wpdb;
  1812.  
  1813. $args['where'] .= " AND ( $wpdb->posts.post_author = " . esc_sql(get_current_user_id()) . ") ";
  1814.  
  1815. return $args;
  1816. }
  1817.  
  1818. add_filter('comment_form_fields', 'azexo_comment_form_fields');
  1819.  
  1820. function azexo_comment_form_fields($comment_fields) {
  1821. $comment = $comment_fields['comment'];
  1822. unset($comment_fields['comment']);
  1823. $comment_fields = $comment_fields + array('comment' => $comment);
  1824. return $comment_fields;
  1825. }
  1826.  
  1827. function azexo_is_template_part_exists($slug, $name = null) {
  1828. $templates = array();
  1829. $name = (string) $name;
  1830. if ('' !== $name) {
  1831. $templates[] = "{$slug}-{$name}.php";
  1832. }
  1833. $templates[] = "{$slug}.php";
  1834. return azexo_locate_template($templates);
  1835. }
  1836.  
  1837. add_filter('infinite_scroll_js_options', 'azexo_infinite_scroll_js_options');
  1838.  
  1839. function azexo_infinite_scroll_js_options($options) {
  1840. $options['nextSelector'] = 'nav.navigation .loop-pagination a.next';
  1841. $options['navSelector'] = 'nav.navigation .loop-pagination';
  1842. $options['itemSelector'] = '#content > .entry.post';
  1843. $options['contentSelector'] = '#content.infinite-scroll';
  1844. $options['loading']['img'] = get_template_directory_uri() . "/images/infinitescroll-loader.svg";
  1845. $options['loading']['msgText'] = '<em class="infinite-scroll-loading">' . esc_html__('Loading ...', 'pilgrim') . '</em>';
  1846. $options['loading']['finishedMsg'] = '<em class="infinite-scroll-done">' . esc_html__('Done', 'pilgrim') . '</em>';
  1847. return $options;
  1848. }
  1849.  
  1850. add_filter('wp_update_comment_count', 'azexo_wp_update_comment_count');
  1851.  
  1852. function azexo_wp_update_comment_count($post_id) {
  1853. delete_post_meta($post_id, '_az_review_count');
  1854. }
  1855.  
  1856. function azexo_review_count($post) {
  1857. $count = apply_filters('azexo_review_count', false, $post);
  1858. if ($count) {
  1859. return $count;
  1860. }
  1861. global $wpdb;
  1862. if (!metadata_exists('post', $post->ID, '_az_review_count')) {
  1863. $count = $wpdb->get_var($wpdb->prepare("
  1864. SELECT COUNT(*) FROM $wpdb->comments
  1865. WHERE comment_parent = 0
  1866. AND comment_post_ID = %d
  1867. AND comment_approved = '1'
  1868. ", $post->ID));
  1869.  
  1870. update_post_meta($post->ID, '_az_review_count', $count);
  1871. } else {
  1872. $count = get_post_meta($post->ID, '_az_review_count', true);
  1873. }
  1874. return $count;
  1875. }
  1876.  
  1877. function azexo_review_allowed($customer_email, $user_id, $post) {
  1878. return apply_filters('azexo_review_allowed', false, $customer_email, $user_id, $post);
  1879. }
  1880.  
  1881. function azexo_get_dashboard_links() {
  1882. if (!is_user_logged_in()) {
  1883. return array();
  1884. }
  1885. static $links = false;
  1886. if ($links) {
  1887. return $links;
  1888. }
  1889. global $wp;
  1890. $current_url = add_query_arg($wp->query_string, '', esc_url(home_url($wp->request)));
  1891. $links = array(
  1892. array(
  1893. 'url' => esc_url(wp_logout_url($current_url)),
  1894. 'title' => esc_html__('Log out', 'pilgrim'),
  1895. )
  1896. );
  1897. $options = get_option(AZEXO_FRAMEWORK);
  1898. if (isset($options['custom_dashboard_pages']) && !empty($options['custom_dashboard_pages'])) {
  1899. $custom_dashboard_pages = array();
  1900. foreach ($options['custom_dashboard_pages'] as $page) {
  1901. $custom_dashboard_pages[] = array(
  1902. 'id' => $page,
  1903. 'url' => esc_url(get_permalink($page)),
  1904. 'title' => get_the_title($page),
  1905. );
  1906. }
  1907. $links = array_merge($custom_dashboard_pages, $links);
  1908. }
  1909. $links = apply_filters('azexo_dashboard_links', $links);
  1910. foreach ($links as &$link) {
  1911. if (!isset($link['active'])) {
  1912. if (isset($link['id'])) {
  1913. $link['active'] = azexo_is_current_post($link['id']);
  1914. } else {
  1915. $link['active'] = ($link['url'] == add_query_arg(NULL, NULL) || strpos($current_url, untrailingslashit($link['url'])) !== false );
  1916. }
  1917. }
  1918. }
  1919. return $links;
  1920. }
  1921.  
  1922. function azexo_is_dashboard() {
  1923. if (isset($_GET['disable-dashboard']) && $_GET['disable-dashboard'] == '1') {
  1924. return false;
  1925. }
  1926. $links = azexo_get_dashboard_links();
  1927. foreach ($links as $link) {
  1928. if (isset($link['active']) && $link['active']) {
  1929. return true;
  1930. }
  1931. }
  1932. return false;
  1933. }
  1934.  
  1935. add_action('is_active_sidebar', 'azexo_is_active_sidebar', 20, 2);
  1936.  
  1937. function azexo_is_active_sidebar($is_active_sidebar, $index) {
  1938. if (($index == 'sidebar' || $index == 'shop') && azexo_is_dashboard()) {
  1939. return is_active_sidebar('dashboard_sidebar');
  1940. }
  1941. return $is_active_sidebar;
  1942. }
  1943.  
  1944. add_filter('azexo_page_title', 'azexo_page_title');
  1945.  
  1946. function azexo_page_title($page_title) {
  1947. $links = azexo_get_dashboard_links();
  1948. foreach ($links as $link) {
  1949. if (isset($link['active']) && $link['active']) {
  1950. return $link['title'];
  1951. }
  1952. }
  1953. return $page_title;
  1954. }
  1955.  
  1956. add_filter('body_class', 'azexo_body_class');
  1957.  
  1958. function azexo_body_class($classes) {
  1959.  
  1960. if (azexo_is_dashboard()) {
  1961. $classes[] = 'dashboard';
  1962. }
  1963.  
  1964. return $classes;
  1965. }
  1966.  
  1967. add_action('wp_update_comment_count', 'azexo_update_comment_count');
  1968.  
  1969. function azexo_update_comment_count($post_id) {
  1970. $review_marks = azexo_review_marks();
  1971. if (!empty($review_marks)) {
  1972. foreach ($review_marks as $slug => $label) {
  1973. delete_post_meta($post_id, '_' . $slug . '_average_rating');
  1974. delete_post_meta($post_id, '_' . $slug . '_rating_count');
  1975. }
  1976. }
  1977. }
  1978.  
  1979. function azexo_review_marks() {
  1980. $options = get_option(AZEXO_FRAMEWORK);
  1981. if (isset($options['review_marks']) && is_array($options['review_marks'])) {
  1982. $options['review_marks'] = array_filter($options['review_marks']);
  1983. if (!empty($options['review_marks'])) {
  1984. return array_combine(array_map('sanitize_title', $options['review_marks']), $options['review_marks']);
  1985. }
  1986. }
  1987. return array();
  1988. }
  1989.  
  1990. function azexo_buildQuery($atts) {
  1991.  
  1992. $atts['items_per_page'] = $atts['query_items_per_page'] = isset($atts['max_items']) ? $atts['max_items'] : '';
  1993. $atts['query_offset'] = isset($atts['offset']) ? $atts['offset'] : '';
  1994.  
  1995. $defaults = array(
  1996. 'post_type' => 'post',
  1997. 'orderby' => '',
  1998. 'order' => 'DESC',
  1999. 'meta_key' => '',
  2000. 'max_items' => '10',
  2001. 'offset' => '0',
  2002. 'taxonomies' => '',
  2003. 'custom_query' => '',
  2004. 'include' => '',
  2005. 'exclude' => '',
  2006. );
  2007. $atts = wp_parse_args($atts, $defaults);
  2008.  
  2009. // Set include & exclude
  2010. if ($atts['post_type'] !== 'ids' && !empty($atts['exclude'])) {
  2011. $atts['exclude'] .= ',' . $atts['exclude'];
  2012. } else {
  2013. $atts['exclude'] = $atts['exclude'];
  2014. }
  2015. if ($atts['post_type'] !== 'ids') {
  2016. $settings = array(
  2017. 'posts_per_page' => $atts['query_items_per_page'],
  2018. 'offset' => $atts['query_offset'],
  2019. 'orderby' => $atts['orderby'],
  2020. 'order' => $atts['order'],
  2021. 'meta_key' => in_array($atts['orderby'], array(
  2022. 'meta_value',
  2023. 'meta_value_num',
  2024. )) ? $atts['meta_key'] : '',
  2025. 'post_type' => $atts['post_type'],
  2026. 'exclude' => $atts['exclude'],
  2027. );
  2028. if (!empty($atts['taxonomies'])) {
  2029. $vc_taxonomies_types = get_taxonomies(array('public' => true));
  2030. $terms = get_terms(array_keys($vc_taxonomies_types), array(
  2031. 'hide_empty' => false,
  2032. 'include' => $atts['taxonomies'],
  2033. ));
  2034. $settings['tax_query'] = array();
  2035. $tax_queries = array(); // List of taxnonimes
  2036. foreach ($terms as $t) {
  2037. if (!isset($tax_queries[$t->taxonomy])) {
  2038. $tax_queries[$t->taxonomy] = array(
  2039. 'taxonomy' => $t->taxonomy,
  2040. 'field' => 'id',
  2041. 'terms' => array($t->term_id),
  2042. 'operator' => 'IN'
  2043. );
  2044. } else {
  2045. $tax_queries[$t->taxonomy]['terms'][] = $t->term_id;
  2046. }
  2047. }
  2048. $settings['tax_query'] = array_values($tax_queries);
  2049. $settings['tax_query']['relation'] = 'OR';
  2050. }
  2051. } else {
  2052. if (empty($atts['include'])) {
  2053. $atts['include'] = - 1;
  2054. } elseif (!empty($atts['exclude'])) {
  2055. $atts['include'] = preg_replace(
  2056. '/(('
  2057. . preg_replace(
  2058. array('/^\,\*/', '/\,\s*$/', '/\s*\,\s*/'), array('', '', '|'), $atts['exclude']
  2059. )
  2060. . ')\,*\s*)/', '', $atts['include']);
  2061. }
  2062. $settings = array(
  2063. 'include' => $atts['include'],
  2064. 'posts_per_page' => $atts['query_items_per_page'],
  2065. 'offset' => $atts['query_offset'],
  2066. 'post_type' => 'any',
  2067. 'orderby' => 'post__in',
  2068. );
  2069. }
  2070.  
  2071. return $settings;
  2072. }
  2073.  
  2074. function azexo_filterQuerySettings($args) {
  2075. $defaults = array(
  2076. 'numberposts' => 5,
  2077. 'offset' => 0,
  2078. 'category' => 0,
  2079. 'orderby' => 'date',
  2080. 'order' => 'DESC',
  2081. 'include' => array(),
  2082. 'exclude' => array(),
  2083. 'meta_key' => '',
  2084. 'meta_value' => '',
  2085. 'post_type' => 'post',
  2086. 'public' => true
  2087. );
  2088.  
  2089. $r = wp_parse_args($args, $defaults);
  2090. if (empty($r['post_status'])) {
  2091. $r['post_status'] = ( 'attachment' == $r['post_type'] ) ? 'inherit' : 'publish';
  2092. }
  2093. if (!empty($r['numberposts']) && empty($r['posts_per_page'])) {
  2094. $r['posts_per_page'] = $r['numberposts'];
  2095. }
  2096. if (!empty($r['category'])) {
  2097. $r['cat'] = $r['category'];
  2098. }
  2099. if (!empty($r['include'])) {
  2100. $incposts = wp_parse_id_list($r['include']);
  2101. $r['posts_per_page'] = count($incposts); // only the number of posts included
  2102. $r['post__in'] = $incposts;
  2103. } elseif (!empty($r['exclude'])) {
  2104. $r['post__not_in'] = wp_parse_id_list($r['exclude']);
  2105. }
  2106.  
  2107. $r['ignore_sticky_posts'] = true;
  2108. $r['no_found_rows'] = true;
  2109.  
  2110. return azexo_array_filter_recursive($r);
  2111. }
  2112.  
  2113. function azexo_posts_list_filters($posts, $taxonomy) {
  2114. $filter_terms = array();
  2115. foreach ($posts as $post) {
  2116. $terms = apply_filters('azexo_posts_list_post_terms', false, $post, $taxonomy);
  2117. if (!$terms) {
  2118. $terms = wp_get_post_terms($post->ID, $taxonomy);
  2119. }
  2120. if (!empty($terms)) {
  2121. foreach ($terms as $term) {
  2122. $filter_terms[$term->term_id] = $term;
  2123. }
  2124. }
  2125. }
  2126. return $filter_terms;
  2127. }
  2128.  
  2129. function azexo_posts_list_post($only_content, $template, $filter, $item_wrapper) {
  2130. global $post;
  2131. if ($only_content) {
  2132. print azexo_get_post_content($post->ID);
  2133. } else {
  2134. $template_name = $template;
  2135. $azexo_woo_base_tag = 'div';
  2136. if (!empty($filter)) {
  2137. $filter_terms = apply_filters('azexo_posts_list_post_terms', false, $post, $filter);
  2138. if (!$filter_terms) {
  2139. $filter_terms = wp_get_post_terms($post->ID, $filter);
  2140. }
  2141. if (is_array($filter_terms)) {
  2142. $filter_terms = array_map(function($term) {
  2143. return $term->slug;
  2144. }, $filter_terms);
  2145. print '<div class="filterable ' . esc_attr(implode(' ', $filter_terms)) . '">';
  2146. }
  2147. }
  2148. if ($item_wrapper) {
  2149. print '<div class="item">';
  2150. }
  2151. include(azexo_locate_template(apply_filters('azexo_post_template_path', 'content.php', $template)));
  2152. if ($item_wrapper) {
  2153. print '</div>';
  2154. }
  2155. if (!empty($filter)) {
  2156. print '</div>';
  2157. }
  2158. }
  2159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement