__construct(); } // PHP 5 function __construct() { // Pre-load Options $this->load_options(); if (!$this->opts) { $this->load_default_options(); } // Launch if (!is_admin()) { add_action('init', array(&$this,'public_init')); } else { add_action('init', array(&$this,'admin_init')); } } /** * Option helper functions */ function load_default_options() { $this->opts = array( 'sitemap_page' => false, 'sel_sitemap_position' => 'after', 'sel_use_title' => 'original', 'exclude_pages' => array(), 'exclude_cats' => array(), ); } function load_options() { $this->opts = get_option($this->option_key); } function save_options($options = false) { if (!$options) { $options = $this->opts; } update_option($this->option_key, $options); } /** * Check if 'All In One SEO' Plugin is active */ function check_allineoneseo() { // Flag so that we only run once... if (isset($this->flag_allineoneseo)) return $this->flag_allineoneseo; // Check active plugins $plugins = get_option('active_plugins'); $this->flag_allineoneseo = (in_array('all-in-one-seo-pack/all_in_one_seo_pack.php', $plugins)) ? true : false; return $this->flag_allineoneseo; } /** * Public functions */ function public_init() { add_action('template_redirect', array(&$this,'template_redirect')); } function template_redirect() { // Register Shortcode add_shortcode($this->shortcode, array(&$this,'handle_shortcode')); // Only filter content if a page was selected if (empty($this->opts['sitemap_page']) || !is_page($this->opts['sitemap_page'])) return; add_filter('the_content', array(&$this,'do_sitemap')); } // Shortcode Handler: view=pages|posts function handle_shortcode($atts=false) { extract(shortcode_atts(array( 'view' => 'all' ), $atts)); ob_start(); switch ($view) { case 'pages': $this->sitemap_show_pages(); break; case 'posts': $this->sitemap_show_posts(); break; default: echo $this->do_sitemap(); break; } return ob_get_clean(); } // Returns "Regular Page Content"+sitemap function do_sitemap($content='') { ob_start(); // List Pages echo '

Pages

'."\n"; $this->sitemap_show_pages(); // List Posts echo '

Posts

'."\n"; $this->sitemap_show_posts(); $output = ob_get_clean(); // Decide where the $content goes. Defaults to 'after' if option not set. if ($this->opts['sel_sitemap_position'] == 'before') { $content = $output.$content; } else { $content = $content.$output; } // Return Output return $content; } // Output pages as UL/LI function sitemap_show_pages($parent=0, $type='page', $class='sitemap_pages') { if (!is_array($this->opts['exclude_pages'])) $this->opts['exclude_pages'] = array(); ob_start(); $posts = get_posts(array( 'post_type' => $type, 'orderby' => 'menu_order', 'numberposts' => -1, 'post_parent' => $parent, 'post__not_in' => $this->opts['exclude_pages'], )); foreach ($posts as $post) { // $label = apply_filters('the_title',$post->post_title); $label = $this->sitemap_postitem_title($post); echo '
  • '.$label.''; $this->sitemap_show_pages($post->ID, 'page', 'sitemap_pages'); echo '
  • '."\n"; } $items = ob_get_clean(); // Doing buffering now to prevent outputting empty