plugin_localization(); // Check if WPML is active. If not display warning message and not load CMS Navigation if(!defined('ICL_SITEPRESS_VERSION') || ICL_PLUGIN_INACTIVE){ if ( !function_exists('is_multisite') || !is_multisite() ) { add_action('admin_notices', array($this, '_no_wpml_warning')); } return false; }elseif(version_compare(ICL_SITEPRESS_VERSION, '2.0.5', '<')){ add_action('admin_notices', array($this, '_old_wpml_warning')); return false; } // Load plugin settings $this->settings = get_option('wpml_cms_nav_settings'); // Use WPML legacy. Read settings from WPML if they exist there. if(empty($this->settings) && defined('ICL_SITEPRESS_VERSION')){ require_once WPML_CMS_NAV_PLUGIN_PATH . '/inc/cms-navigation-schema.php'; wpml_cms_nav_default_settings(); } // Initialize cache $this->cache['offsite_url_cache'] = new wpml_cms_nav_cache('cms_nav_offsite_url', true); // Determine User agent to be used in rendering the menu correctly for IE $cms_nav_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : false; if($cms_nav_user_agent && preg_match('#MSIE ([0-9]+)\.[0-9]#',$cms_nav_user_agent,$matches)){ $cms_nav_ie_ver = $matches[1]; } // Setup the WP-Admin resources add_action( 'admin_init', array($this, 'admin_init') ); // Setup the WP-Admin menus add_action('admin_menu', array($this, 'menu')); // Clear cache hook add_action('wp_ajax_wpml_cms_nav_clear_nav_cache', array($this, 'clear_cache')); // Save form(options) hook add_action('wp_ajax_wpml_cms_nav_save_form', array($this, 'save_form')); // theme hooks add_action('icl_navigation_breadcrumb', array($this, 'cms_navigation_breadcrumb')); add_action('icl_navigation_menu', array($this, 'cms_navigation_menu_nav')); add_action('icl_navigation_sidebar', array( $this, 'page_navigation' )); // more hooks add_action('save_post', array($this, 'cms_navigation_update_post_settings'), 4, 2); add_action('admin_head', array($this, 'cms_navigation_page_edit_options')); add_action('admin_head', array($this, 'cms_navigation_js')); // offsite urls hooks add_filter('page_link', array($this, 'rewrite_page_link'), 15, 2); add_action('parse_query', array($this, 'redirect_offsite_urls')); // situations to clear the cache add_filter('permalink_structure_changed', array($this,'clear_cache')); add_filter('update_option_show_on_front', array($this,'clear_cache')); add_filter('update_option_page_on_front', array($this,'clear_cache')); add_filter('update_option_page_for_posts', array($this,'clear_cache')); add_action('delete_post', array($this, 'clear_cache')); add_action('delete_category', array($this, 'clear_cache')); add_action('create_category', array($this, 'clear_cache')); add_action('edited_category', array($this, 'clear_cache')); // add message to WPML dashboard widget add_action('icl_dashboard_widget_content', array($this, 'icl_dashboard_widget_content')); return true; } function plugins_loaded() { // Initialize sidebar navigation widget add_action( 'widgets_init', array( $this, 'sidebar_navigation_widget_init' ) ); // Load resources add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ) ); } function script_and_styles() { } function admin_init() { wp_enqueue_script( 'wpml-cms-nav-js', WPML_CMS_NAV_PLUGIN_URL . '/res/js/navigation.js', array(), WPML_CMS_NAV_VERSION ); } function wp_enqueue_scripts() { if ( ! defined( 'ICL_DONT_LOAD_NAVIGATION_CSS' ) || ! ICL_DONT_LOAD_NAVIGATION_CSS ) { wp_enqueue_style( 'wpml-cms-nav-css', WPML_CMS_NAV_PLUGIN_URL . '/res/css/navigation.css', array(), WPML_CMS_NAV_VERSION ); } $this->cms_navigation_css(); } function _no_wpml_warning(){ ?>

WPML in order to work.', 'wpml-cms-nav'), 'https://wpml.org/'); ?>

WPML versions prior 2.0.5.', 'wpml-cms-nav'), 'https://wpml.org/'); ?>

settings; } function save_settings(){ update_option('wpml_cms_nav_settings', $this->settings); } function menu(){ if(!defined('ICL_PLUGIN_PATH')) return; global $sitepress; if(!isset($sitepress) || (method_exists($sitepress,'get_setting') && !$sitepress->get_setting( 'setup_complete'))) return; $top_page = apply_filters('icl_menu_main_page', basename(ICL_PLUGIN_PATH).'/menu/languages.php'); add_submenu_page($top_page, __('Navigation','wpml-cms-nav'), __('Navigation','wpml-cms-nav'), 'wpml_manage_navigation', basename(WPML_CMS_NAV_PLUGIN_PATH).'/menu/navigation.php'); } function save_form(){ global $wpdb; if ( !wp_verify_nonce( filter_input( INPUT_POST, 'icl_cms_nav_nonce' ), 'icl_cms_nav_nonce' ) ) { return false; } $this->settings['page_order'] = $_POST['icl_navigation_page_order']; $this->settings['show_cat_menu'] = @intval($_POST['icl_navigation_show_cat_menu']); if($_POST['icl_navigation_cat_menu_title']){ $this->settings['cat_menu_title'] = stripslashes($_POST['icl_navigation_cat_menu_title']); if(function_exists('icl_register_string')){ icl_register_string('WPML', 'Categories Menu', stripslashes($_POST['icl_navigation_cat_menu_title'])); } } $this->settings['cat_menu_page_order'] = $_POST['icl_navigation_cat_menu_page_order']; $this->settings['cat_menu_contents'] = $_POST['icl_blog_menu_contents']; $this->settings['heading_start'] = stripslashes($_POST['icl_navigation_heading_start']); $this->settings['heading_end'] = stripslashes($_POST['icl_navigation_heading_end']); $this->settings['cache'] = isset($_POST['icl_navigation_caching'])?$_POST['icl_navigation_caching']:0; $this->settings['breadcrumbs_separator'] = stripslashes($_POST['icl_breadcrumbs_separator']); $this->save_settings(); // clear the cms navigation caches /** @var $offsite_url_cache wpml_cms_nav_cache */ $offsite_url_cache = $this->cache[ 'offsite_url_cache' ]; $offsite_url_cache->clear(); $wpdb->query("TRUNCATE {$wpdb->prefix}icl_cms_nav_cache"); return true; } function clear_cache(){ global $wpdb; // clear the cache. /** @var $offsite_url_cache wpml_cms_nav_cache */ $offsite_url_cache = $this->cache[ 'offsite_url_cache' ]; $offsite_url_cache->clear(); $wpdb->query("TRUNCATE {$wpdb->prefix}icl_cms_nav_cache"); return true; } function cms_navigation_breadcrumb(){ global $post, $wpdb, $wp_query; global $sitepress, $sitepress_settings; if(func_num_args()){ $args = func_get_args(); $separator = $args[0]; } if(!empty($separator) && is_string($separator) && $separator != $this->settings['breadcrumbs_separator']){ $this->settings['breadcrumbs_separator'] = $separator; } $output = null; $use_cache = isset($this->settings['cache']) && $this->settings['cache'] && !(defined('WPML_CMS_NAV_DISABLE_CACHE') && WPML_CMS_NAV_DISABLE_CACHE); $cache_key = false; if ($use_cache) { $cache_key = $_SERVER['REQUEST_URI'].'-'.$sitepress->get_current_language(); $output_prepared = $wpdb->prepare( " SELECT data FROM {$wpdb->prefix}icl_cms_nav_cache WHERE cache_key=%s AND type='nav_breadcrumb' AND DATE_SUB(NOW(), INTERVAL " . WPML_CMS_NAV_CACHE_EXPIRE . ") < timestamp", $cache_key ); $output = $wpdb->get_var( $output_prepared ); } if (!$output) { // save the menu to a cache ob_start(); if(0 === strpos('page', get_option('show_on_front'))){ $page_on_front = (int)get_option('page_on_front'); $page_for_posts = (int)get_option('page_for_posts'); }else{ $page_on_front = 0; $page_for_posts = 0; } if(isset($post) && $page_on_front!=$post->ID){ if($page_on_front){ $permalink = $sitepress->language_url(); if($sitepress_settings['language_negotiation_type'] != 3){ $permalink = trailingslashit($permalink); } ?>settings['breadcrumbs_separator']; }elseif(!is_home() || (is_home() && !$page_on_front && $page_for_posts)){ ?>settings['breadcrumbs_separator']; } } $post_types = $sitepress->get_translatable_documents(true); $post_type = (array)get_query_var('post_type'); $post_type = reset($post_type); unset($post_types['post'],$post_types['page']); if((($pn = get_query_var('pagename')) || (!$post_type && !get_query_var('p') && !get_query_var($post_type))) && isset($post_types[$post_type])){ if (empty($pn)) { echo $post_type_name = $post_types[$post_type]->labels->name; } else { echo $post_type_name = $post_types[$pn]->labels->name; } if(get_query_var('name')){ echo $this->settings['breadcrumbs_separator']; } }elseif(($post_type) && get_query_var($post_type)){ if (isset($post_types[$post_type]->has_archive) && $post_types[$post_type]->has_archive && function_exists('get_post_type_archive_link')) { echo '' . $post_types[$post_type]->labels->name . ' ' . $this->settings['breadcrumbs_separator']; } else if (isset($post_types[$post_type]->taxonomies) && !empty($post_types[$post_type]->taxonomies)) { $custom_post_tax = false; foreach ($post_types[$post_type]->taxonomies as $temp_tax) { $terms = wp_get_post_terms($wp_query->get_queried_object_id(), $temp_tax); if (!empty($terms)) { $custom_post_tax = $temp_tax; break; } } if (empty($terms)) { echo $post_types[$post_type]->labels->name . $this->settings['breadcrumbs_separator']; } else { $term_parents[] = array('name'=>$terms[0]->name, 'url'=>get_term_link($terms[0], $custom_post_tax)); $term_parent = $terms[0]->parent; while($term_parent){ $term = get_term($term_parent, $custom_post_tax); $term_parent = $term->parent; $term_parents[] = array('name'=>$term->name, 'url'=>get_term_link((int)$term->term_id, $custom_post_tax)); } if(!empty($term_parents)){ $term_parents = array_reverse($term_parents); foreach($term_parents as $term){ echo ''.$term['name'].' ' . $this->settings['breadcrumbs_separator']; }; } } } elseif ( isset( $post_types[$post_type]->labels->name ) ) { echo $post_types[$post_type]->labels->name . $this->settings['breadcrumbs_separator']; } } elseif( is_archive() && isset( $post_types[$post_type]->labels->name ) ) { echo $post_types[$post_type]->labels->name; }elseif(!is_page() && !is_home() && !is_tax() && $page_for_posts){ // get all custom post types $custom_post_types = get_post_types( array( 'public' => true, '_builtin' => false ), 'objects', 'and' ); // if custom post type if( isset( $custom_post_types[$post_type] ) ) { // if custom post type has archive if( $custom_post_types[$post_type]->has_archive ) { echo '' . $custom_post_types[$post_type]->labels->name . '' . $this->settings['breadcrumbs_separator']; } } else { ?>settings['breadcrumbs_separator']; } } if(is_home() && $page_for_posts && !isset($post_type_name)){ echo get_the_title($page_for_posts); }elseif(($post_type) && get_query_var($post_type)){ the_post(); echo get_the_title(); rewind_posts(); }elseif(is_page() && $page_on_front!=$post->ID){ the_post(); if ( $this->post_has_ancestors( $post ) ) { $ancestors = array_reverse($post->ancestors); foreach($ancestors as $anc){ if($page_on_front==$anc) {continue;} ?> settings['breadcrumbs_separator']; } } echo get_the_title(); rewind_posts(); }elseif(is_single()){ the_post(); $cat = get_the_category(); if ( isset( $cat ) && is_array( $cat ) && count( $cat ) ) { $cat_id = $cat[ 0 ]->cat_ID; $parents = get_category_parents( $cat_id, true, $this->settings[ 'breadcrumbs_separator' ] ); if ( is_string( $parents ) ) { echo $parents; } } the_title(); rewind_posts(); }elseif (is_category()) { $cat = get_term(intval( get_query_var('cat')), 'category', OBJECT, 'display'); if(!empty($cat->parent)){ $category_parent = get_category_parents( $cat->parent, true, $this->settings[ 'breadcrumbs_separator' ] ); echo $category_parent; } single_cat_title(); }elseif(is_tag()){ echo __('Articles tagged ', 'wpml-cms-nav') ,'‘'; single_tag_title(); echo '’'; }elseif (is_tax()){ $term = get_term($wp_query->get_queried_object_id(), get_query_var('taxonomy')); $term_name = $term->name; $term_parent = $term->parent; while($term_parent){ $term = get_term($term_parent, get_query_var('taxonomy')); $term_parent = $term->parent; $term_parents[] = array('name'=>$term->name, 'url'=>get_term_link((int)$term->term_id, get_query_var('taxonomy'))); } if(!empty($term_parents)){ $term_parents = array_reverse($term_parents); foreach($term_parents as $term){ echo ''.$term['name'].' ' . $this->settings['breadcrumbs_separator']; }; } echo $term_name; }elseif (is_month()){ echo get_the_time('F, Y'); }elseif (is_search()){ echo __('Search for: ', 'wpml-cms-nav'), strip_tags(get_query_var('s')); } $output = ob_get_contents(); ob_end_clean(); if (!$output){ $output = ' '; } if ($use_cache) { $delete_prepared = $wpdb->prepare( "DELETE FROM {$wpdb->prefix}icl_cms_nav_cache WHERE cache_key= %s AND type='nav_breadcrumb'", $cache_key ); $wpdb->query( $delete_prepared ); $wpdb->insert($wpdb->prefix.'icl_cms_nav_cache', array( 'cache_key'=>$cache_key, 'type'=>'nav_breadcrumb', 'data'=>$output ) ); } } echo $output; } function cms_navigation_menu_nav(){ global $wpdb, $post, $cms_nav_ie_ver, $wp_query; global $sitepress, $sitepress_settings; $current_language = $sitepress->get_current_language(); $default_language = $sitepress->get_default_language(); if(function_exists('icl_t')){ $cat_menu_title = $this->settings['cat_menu_title']? icl_t('WPML', 'Categories Menu', $this->settings['cat_menu_title']):__('News', 'wpml-cms-nav'); }else{ $cat_menu_title = $this->settings['cat_menu_title']? $this->settings['cat_menu_title']:__('News', 'wpml-cms-nav'); } $use_cache = $this->settings['cache'] && !(defined('WPML_CMS_NAV_DISABLE_CACHE') && WPML_CMS_NAV_DISABLE_CACHE); $output = null; $cache_key = false; if ($use_cache) { $cache_key = $_SERVER['REQUEST_URI'].'-'. $current_language; if (isset($cms_nav_ie_ver)) { $cache_key .= '-ie-'.$cms_nav_ie_ver; } $output_prepared = $wpdb->prepare( " SELECT data FROM {$wpdb->prefix}icl_cms_nav_cache WHERE cache_key = %s AND type='nav_menu' AND DATE_SUB(NOW(), INTERVAL " . WPML_CMS_NAV_CACHE_EXPIRE . ") < timestamp", $cache_key ); $output = $wpdb->get_var( $output_prepared ); } if (!$output) { // save the menu to a cache ob_start(); $order = esc_sql( isset( $this->settings['page_order'] ) ? $this->settings['page_order'] : 'menu_order' ); $show_cat_menu = isset($this->settings['show_cat_menu']) ? $this->settings['show_cat_menu'] : false; if(0 === strpos('page', get_option('show_on_front'))){ $page_on_front = (int)get_option('page_on_front'); $page_for_posts = (int)get_option('page_for_posts'); }else{ $page_on_front = 0; $page_for_posts = 0; } $pages_query = new WPML_CMS_Nav_Pages( $wpdb, new WPML_Display_As_Translated_Posts_Query( $wpdb, 'p' ) ); list( $pages, $excluded_pages ) = $pages_query->get_pages( $current_language, $default_language, $show_cat_menu, $page_for_posts, $sitepress_settings['existing_content_language_verified'], $order, $sitepress->is_display_as_translated_post_type( 'page' ) ); $sitepress->switch_lang( $default_language ); $page_for_posts_abs = get_option('page_for_posts'); $sitepress->switch_lang(); if($show_cat_menu && (0 !== strpos('page', get_option('show_on_front')) || !$page_for_posts_abs)){ $res = false; if($pages){ $res_prepared = "SELECT ID, menu_order FROM {$wpdb->posts} WHERE ID IN (" . wpml_prepare_in( $pages, '%d' ) . ") ORDER BY menu_order"; $res = $wpdb->get_results( $res_prepared ); } if($res){ foreach($res as $row){ $orders[$row->ID] = $row->menu_order; } } $blog_special_page_inserted = false; $incpages = array(); foreach($pages as $p){ if(!$blog_special_page_inserted && (isset($orders[$p]) && $orders[$p] > $this->settings['cat_menu_page_order'])){ $incpages[] = 0; $blog_special_page_inserted = true; } $incpages[] = $p; } if(!$blog_special_page_inserted){ $pages[] = 0; }else{ $pages = $incpages; } } if($pages){ ?>
prepare( "DELETE FROM {$wpdb->prefix}icl_cms_nav_cache WHERE cache_key=%s AND type='nav_menu'", $cache_key ); $wpdb->query( $delete_prepared ); $wpdb->insert($wpdb->prefix.'icl_cms_nav_cache', array( 'cache_key'=>$cache_key, 'type'=>'nav_menu', 'data'=>$output ) ); } } echo $output; } function page_navigation($instance = false){ if(!is_page()) return; global $post, $wpdb; global $sitepress; if($post == null) { return; } $use_cache = isset($this->settings['cache']) && $this->settings['cache'] && !(defined('WPML_CMS_NAV_DISABLE_CACHE') && WPML_CMS_NAV_DISABLE_CACHE); $output = null; $cache_key = false; if ($use_cache) { $cache_key = $_SERVER['REQUEST_URI'].'-'.$sitepress->get_current_language(); $output_prepared = $wpdb->prepare( " SELECT data FROM {$wpdb->prefix}icl_cms_nav_cache WHERE cache_key=%s AND type='nav_page' AND DATE_SUB(NOW(), INTERVAL " . WPML_CMS_NAV_CACHE_EXPIRE . ") < timestamp", $cache_key ); $output = $wpdb->get_var( $output_prepared ); } if (!$output) { // save the menu to a cache ob_start(); $order = esc_sql( isset($this->settings['page_order']) ? $this->settings['page_order'] : 'menu_order' ); $heading_start = isset($this->settings['heading_start']) ? $this->settings['heading_start'] : '

'; $heading_end = isset($this->settings['heading_end']) ? $this->settings['heading_end'] : '

'; // is home? $is_home = get_post_meta($post->ID,'_cms_nav_minihome',true); if ( $is_home || ! $this->post_has_ancestors( $post ) ) { $pid = $post->ID; } elseif ( $this->post_has_ancestors( $post ) ) { //get top level page parent or home $parent = $post->ancestors[0]; do{ $uppost_prepared = $wpdb->prepare(" SELECT p1.ID, p1.post_parent, p2.meta_value, (p2.meta_value IS NOT NULL && p2.meta_value <> '') AS minihome FROM {$wpdb->posts} p1 LEFT JOIN {$wpdb->postmeta} p2 ON p1.ID=p2.post_id AND (meta_key='_cms_nav_minihome' OR meta_key IS NULL) WHERE post_type='page' AND p1.ID=%d",$parent); $uppost = $wpdb->get_row( $uppost_prepared ); $pid = $uppost->ID; $parent = $uppost->post_parent; $minihome = $uppost->minihome; }while($parent!=0 && !$minihome); } echo $heading_start; if($pid!=$post->ID){ ?>ID){ ?> prepare( " SELECT p1.ID, meta_value AS section FROM {$wpdb->posts} p1 LEFT JOIN {$wpdb->postmeta} p2 ON p1.ID=p2.post_id AND (meta_key='_cms_nav_section' OR meta_key IS NULL) WHERE post_parent=%d AND post_type='page' AND post_status='publish' ORDER BY " . $order, $pid ); $sub = $wpdb->get_results( $sub_prepared ); if(empty($sub)) return; foreach($sub as $s){ $sections[$s->section][] = $s->ID; } ksort($sections); echo '