. */ if(is_admin() && !in_array($pagenow, array('page.php','page-new.php'))) return; define('CMS_NAVIGATION_VERSION', 0.3); if(!defined('PHP_EOL')){ define ('PHP_EOL',"\r\n"); } define('CMS_NAV_CACHE_EXPIRE', '1 HOUR'); class CMSNavigation{ var $settings; function __construct(){ global $cms_nav_ie_ver, $sitepress; if(!isset($sitepress)){ $sitepress = new SitePress(); $sitepress->initialize_cache(); } $sitepress_settings = $sitepress->get_settings(); $this->settings = $sitepress_settings['modules']['cms-navigation']; $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]; } 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')); add_action('save_post', array($this, 'cms_navigation_update_post_settings')); add_action('admin_head', array($this, 'cms_navigation_page_edit_options')); add_action('admin_head', array($this, 'cms_navigation_js')); add_action('init', array($this, 'cms_navigation_css')); add_action('plugins_loaded', array($this, 'sidebar_navigation_widget_init')); add_filter('page_link', array($this, 'rewrite_page_link'), 15, 2); add_action('parse_query', array($this, 'redirect_offsite_urls')); 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')); // not needed - save_post handles this //add_action('trashed_post', array($this,'clear_cache')); //add_action('untrashed_post', array($this,'clear_cache')); } function clear_cache($data){ global $sitepress, $wpdb; // clear the cache. $sitepress->icl_cms_nav_offsite_url_cache->clear(); @mysql_query("TRUNCATE {$wpdb->prefix}icl_cms_nav_cache"); return $data; } function cms_navigation_breadcrumb(){ global $post, $sitepress, $current_user, $wpdb, $sitepress_settings, $wp_rewrite; if(func_num_args()){ $args = func_get_args(); $separator = $args[0]; } if(!empty($separator) && $separator != $this->settings['breadcrumbs_separator']){ $this->settings['breadcrumbs_separator'] = $separator; } $cache_key = $_SERVER['REQUEST_URI'].'-'.$sitepress->get_current_language(); $output = $wpdb->get_var(" SELECT data FROM {$wpdb->prefix}icl_cms_nav_cache WHERE cache_key='{$cache_key}' AND type='nav_breadcrumb' AND DATE_SUB(NOW(), INTERVAL ".CMS_NAV_CACHE_EXPIRE.") < timestamp"); if (!$output || !$this->settings['cache'] || ICL_DISABLE_CACHE) { // 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($page_on_front!=$post->ID){ if($page_on_front){ //$permalink = get_permalink($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; }elseif(($post_type = get_query_var('post_type')) && get_query_var($post_type)){ $custom_post_tax = $post_types[$post_type]->taxonomies[0]; $terms = wp_get_post_terms($GLOBALS['wp_query']->get_queried_object_id(), $custom_post_tax); $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(!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($id); $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($cat->category_parent){ echo get_category_parents($cat->category_parent, TRUE, $this->settings['breadcrumbs_separator']); } single_cat_title(); }elseif(is_tag()){ echo __('Articles tagged ', 'sitepress') ,'‘'; 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: ', 'sitepress'), strip_tags(get_query_var('s')); /* }elseif (is_404()){ echo __('Not found', 'sitepress'); */ } $output = ob_get_contents(); ob_end_clean(); if (!$output){ $output = ' '; } $wpdb->query("DELETE FROM {$wpdb->prefix}icl_cms_nav_cache WHERE cache_key='{$cache_key}' AND type='nav_breadcrumb'"); $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 $sitepress, $sitepress_settings, $wpdb, $post, $cms_nav_ie_ver, $wp_query, $current_user; $show_cat_menu = $this->settings['show_cat_menu']?$this->settings['show_cat_menu']:false; $cat_menu_title = $this->settings['cat_menu_title']?icl_t('WPML', 'Categories Menu', $this->settings['cat_menu_title']):__('News', 'sitepress'); $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(" SELECT data FROM {$wpdb->prefix}icl_cms_nav_cache WHERE cache_key='{$cache_key}' AND type='nav_menu' AND DATE_SUB(NOW(), INTERVAL ".CMS_NAV_CACHE_EXPIRE.") < timestamp"); if (!$output || !$this->settings['cache'] || ICL_DISABLE_CACHE) { // save the menu to a cache ob_start(); $order = $this->settings['page_order']?$this->settings['page_order']:'menu_order'; $show_cat_menu = $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(" 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 = '{$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) && !$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){ ?>