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); // Determing User agent to be used in rendering the menu correctly for IE $cms_nav_user_agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match('#MSIE ([0-9]+)\.[0-9]#',$cms_nav_user_agent,$matches)){ $cms_nav_ie_ver = $matches[1]; } // Initialize sidebar navigation wiget $this->sidebar_navigation_widget_init(); // Load some resources if(is_admin()){ wp_enqueue_script('wpml-cms-nav-js', WPML_CMS_NAV_PLUGIN_URL . '/res/js/navigation.js', array(), WPML_CMS_NAV_VERSION); } 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(); // 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, 'cms_navigation_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')); } function _no_wpml_warning(){ ?>

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

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

settings; } function save_settings(){ update_option('wpml_cms_nav_settings', $this->settings); } function menu(){ $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'), 'manage_options', basename(WPML_CMS_NAV_PLUGIN_PATH).'/menu/navigation.php'); } function save_form(){ global $wpdb; if($_POST['icl_cms_nav_nonce'] != wp_create_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 $this->cache['offsite_url_cache']->clear(); @mysql_query("TRUNCATE {$wpdb->prefix}icl_cms_nav_cache"); } function clear_cache(){ global $wpdb; // clear the cache. $this->cache['offsite_url_cache']->clear(); @mysql_query("TRUNCATE {$wpdb->prefix}icl_cms_nav_cache"); return true; } function cms_navigation_breadcrumb(){ global $post, $current_user, $wpdb, $wp_rewrite; global $sitepress, $sitepress_settings; if(func_num_args()){ $args = func_get_args(); $separator = $args[0]; } if(!empty($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); if ($use_cache) { $cache_key = $_SERVER['REQUEST_URI'].'-'.$sitepress->get_current_language(); $output = $wpdb->get_var($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)); } 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); unset($post_types['post'],$post_types['page']); if((($pn = get_query_var('pagename')) || (($pn = get_query_var('post_type')) && !get_query_var('p') && !get_query_var($pn))) && isset($post_types[$pn])){ 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')) && 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)) { foreach ($post_types[$post_type]->taxonomies as $temp_tax) { $terms = wp_get_post_terms($GLOBALS['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']; }; } } } else { echo $post_types[$post_type]->labels->name . $this->settings['breadcrumbs_separator']; } }elseif(!is_page() && !is_home() && !is_tax() && $page_for_posts){ ?>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')) && get_query_var($post_type)){ the_post(); echo get_the_title(); rewind_posts(); }elseif(is_page() && $page_on_front!=$post->ID){ the_post(); if(is_array($post->ancestors)){ $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(); $cat = $cat[0]->cat_ID; $parents = get_category_parents($cat, 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)){ echo get_category_parents($cat->parent, TRUE, $this->settings['breadcrumbs_separator']); } single_cat_title(); }elseif(is_tag()){ echo __('Articles tagged ', 'wpml-cms-nav') ,'‘'; single_tag_title(); echo '’'; }elseif (is_tax()){ $term = get_term($GLOBALS['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 the_time('F, Y'); }elseif (is_search()){ echo __('Search for: ', 'wpml-cms-nav'), strip_tags(get_query_var('s')); /* }elseif (is_404()){ echo __('Not found', 'wpml-cms-nav'); */ } $output = ob_get_contents(); ob_end_clean(); if (!$output){ $output = ' '; } if ($use_cache) { $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}icl_cms_nav_cache WHERE cache_key= %s AND type='nav_breadcrumb'", $cache_key)); $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, $current_user; global $sitepress, $sitepress_settings; $show_cat_menu = $this->settings['show_cat_menu']?$this->settings['show_cat_menu']:false; 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; if ($use_cache) { $cache_key = $_SERVER['REQUEST_URI'].'-'.$sitepress->get_current_language(); if (isset($cms_nav_ie_ver)) { $cache_key .= '-ie-'.$cms_nav_ie_ver; } $output = $wpdb->get_var($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)); } if (!$output) { // save the menu to a cache ob_start(); $order = 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; } // exclude some pages $excluded_pages = $wpdb->get_col($wpdb->prepare(" SELECT post_id FROM {$wpdb->postmeta} pm LEFT JOIN {$wpdb->prefix}icl_translations tr ON pm.post_id = tr.element_id AND element_type='post_page' WHERE meta_key='_top_nav_excluded' AND meta_value <> '' AND tr.language_code = %s ", $sitepress->get_current_language())); $excluded_pages[] = 0; //add this so we don't have an empty array if(!$show_cat_menu && $page_for_posts){ $excluded_pages[] = $page_for_posts; } $excluded_pages = join(',', $excluded_pages); if(!empty($post) && !isset($post->ancestors)){ $post->ancestors = array(); } if(current_user_can('read_private_pages')){ $private = " OR post_status='private'"; }else{ $private = ""; } if( $sitepress_settings['existing_content_language_verified'] && 'all' != $sitepress->get_current_language()){ // user has initialized $pages = $wpdb->get_col(" SELECT p.ID FROM {$wpdb->posts} p JOIN {$wpdb->prefix}icl_translations tr ON p.ID = tr.element_id AND element_type='post_page' WHERE post_type='page' AND (post_status='publish' {$private}) AND post_parent=0 AND p.ID NOT IN ({$excluded_pages}) AND tr.language_code = '{$sitepress->get_current_language()}' ORDER BY {$order}"); }else{ $pages = $wpdb->get_col(" SELECT p.ID FROM {$wpdb->posts} p WHERE post_type='page' AND (post_status='publish' {$private}) AND post_parent=0 AND p.ID NOT IN ({$excluded_pages}) ORDER BY {$order}"); } if($show_cat_menu && (0 !== strpos('page', get_option('show_on_front')) || !get_option('page_for_posts'))){ if($pages){ $res = $wpdb->get_results("SELECT ID, menu_order FROM {$wpdb->posts} WHERE ID IN (".join(',', $pages).") ORDER BY menu_order"); } if($res){ foreach($res as $row){ $orders[$row->ID] = $row->menu_order; } } $blog_special_page_inserted = false; foreach($pages as $k=>$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){ ?>
query($wpdb->prepare("DELETE FROM {$wpdb->prefix}icl_cms_nav_cache WHERE cache_key=%s AND type='nav_menu'", $cache_key)); $wpdb->insert($wpdb->prefix.'icl_cms_nav_cache', array( 'cache_key'=>$cache_key, 'type'=>'nav_menu', 'data'=>$output ) ); } } echo $output; } function cms_navigation_page_navigation(){ if(!is_page()) return; global $post, $wpdb, $current_user; 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; if ($use_cache) { $cache_key = $_SERVER['REQUEST_URI'].'-'.$sitepress->get_current_language(); $output = $wpdb->get_var($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)); } if (!$output) { // save the menu to a cache ob_start(); $order = 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 || !$post->ancestors){ $pid = $post->ID; }else{ //get top level page parent or home $parent = $post->ancestors[0]; do{ $uppost = $wpdb->get_row(" 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={$parent} "); $pid = $uppost->ID; $parent = $uppost->post_parent; $minihome = $uppost->minihome; }while($parent!=0 && !$minihome); } echo $heading_start; if($pid!=$post->ID){ ?>ID){ ?> get_results(" 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='{$pid}' AND post_type='page' AND post_status='publish' ORDER BY {$order}"); if(empty($sub)) return; foreach($sub as $s){ $sections[$s->section][] = $s->ID; } ksort($sections); echo '