cat = strtoupper(trim($snapqueryarray['cat'])); } else { if (is_category()) { $nav->cat = get_query_var('cat'); } elseif (is_tag()) { $nav->tag = get_query_var('tag_id'); } } if (isset($snapqueryarray['child'])) { $nav->ifchildren = true; } else { $nav->ifchildren = false; } if (isset($snapqueryarray['menu'])) { $nav->menustyle = $snapqueryarray['menu']; } if (isset($snapqueryarray['firstload'])) { $nav->firstload = strtoupper(trim($snapqueryarray['firstload'])); } if (isset($_GET['cp'])) { $nav->first_letters = $_GET['cp']; } elseif (isset($_GET['snap'])) { if ($_GET['snap'] == 'misc') { $nav->first_letters = '#'; } else { $nav->first_letters = urldecode($_GET['snap']); } } $results = $nav->navigation(); return $results; } class wp_snap_core { var $cat; var $tag; var $ifchildren; var $first_letters; var $menustyle; var $firstload; function current_url($fancyurl, $fancyurlname = '') { $url = "http://" . $_SERVER['HTTP_HOST']; if ($fancyurl == 1 && get_option('permalink_structure') !== '') { $url .= preg_replace('@' . $fancyurlname . '.*@', '', $_SERVER['REQUEST_URI']); } else { $url .= preg_replace('@[\?\&]snap.*@', '', $_SERVER['REQUEST_URI']); } return $url; } function accents($str) { $str = htmlentities($str); $str = preg_replace('/&([a-zA-Z])(uml|acute|grave|circ|tilde);/','$1',$str); return html_entity_decode($str); } function navigation() { global $wpdb, $wp_query, $user_ID, $gengo, $wp_version; // Define variables $wp_snap_options = array( 'menu' => get_option('key_snap_menu'), 'menumisc' => get_option('key_snap_menumisc'), 'recent' => get_option('key_snap_recent'), 'csscls1' => get_option('key_snap_csscls1'), 'csscls2' => get_option('key_snap_csscls2'), 'tab1' => get_option('key_snap_tab1'), 'fancyurl' => get_option('key_snap_fancyurl'), 'fancyurlname' => get_option('key_snap_fancyurlname')); $ver = (float)$wp_version; $url = wp_snap_core::current_url($wp_snap_options['fancyurl'],$wp_snap_options['fancyurlname']); $date = gmdate('Y-m-d H:i:59'); $sch = array('"e;', '&apost;', ' '); $rst = array('"', '\'', ''); // '" $exclude[0] = str_replace($sch, $rst, get_option('key_snap_exclude')); $excsch = array('/[\|]+[0-9A-Z]+[\|]*|[\|]*[0-9A-Z]+[\|]+/i', '/^[0-9A-Z]+$/i'); $excrst = array('|', ''); $exclude[1] = preg_replace($excsch, $excrst, $exclude[0]); $excsch = array('/[\|]+[^0-9A-Z]+[\|]*|[\|]*[^0-9A-Z]+[\|]+/i', '/^[^0-9A-Z]+$/i'); $excrst = array('|', ''); $exclude[2] = preg_replace($excsch, $excrst, $exclude[0]); $tempstr['1']['0'] = '#' . __('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'wp-snap'); $tempstr['1']['1'] = '#' . __('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'wp-snap'); $tempstr['2']['0'] = '#' . __('A-DE-HI-LM-PQ-TU-Z', 'wp-snap'); $tempstr['2']['1'] = '#' . __('0-9A-DE-HI-LM-PQ-TU-Z', 'wp-snap'); $tempstr['2']['2'] = '#'; $tempstr['2']['3'] = __('0123456789', 'wp-snap'); $tempstr['2']['4'] = __('ABCD', 'wp-snap'); $tempstr['2']['5'] = __('EFGH', 'wp-snap'); $tempstr['2']['6'] = __('IJKL', 'wp-snap'); $tempstr['2']['7'] = __('MNOP', 'wp-snap'); $tempstr['2']['8'] = __('QRST', 'wp-snap'); $tempstr['2']['9'] = __('UVWXYZ', 'wp-snap'); $tempstr['3']['0'] = '#' . __('A-MN-Z', 'wp-snap'); $tempstr['3']['1'] = '#' . __('0-9A-MN-Z', 'wp-snap'); $tempstr['3']['2'] = '#'; $tempstr['3']['3'] = __('0123456789', 'wp-snap'); $tempstr['3']['4'] = __('ABCDEFGHIJKLM', 'wp-snap'); $tempstr['3']['5'] = __('NOPQRSTUVWXYZ', 'wp-snap'); if (empty($this->menustyle)) { $this->menustyle = $wp_snap_options['menu']; } // Database query if ($ver < 2.3) { if (!empty($this->cat)) { $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id)"; if (get_query_var('cat') == NULL) { $join .= " LEFT JOIN $wpdb->categories ON ($wpdb->post2cat.category_id = $wpdb->categories.cat_ID)"; } if ($this->cat !== 'ALL') { $where = " AND $wpdb->post2cat.category_id IN (" . $this->cat . ", "; if ($this->ifchildren == TRUE) { $where .= get_category_children($this->cat, '', ', '); } $where = substr($where, 0, -2); $where .= ")"; } } $where .= " AND (post_type = 'post' AND (post_status = 'publish'"; if (is_admin()) { $where .= " OR post_status = 'future' OR post_status = 'draft'"; } if ( is_user_logged_in() ) { if (current_user_can('read_private_posts')) { $where .= " OR post_status = 'private'"; } else { $where .= " OR post_author = $user_ID AND post_status = 'private'"; } } // Gengo support (hopefully) if (isset($gengo)) { $where .= " AND $wpdb->posts.ID = $wpdb->post2lang.post_ID AND $wpdb->post2lang.language_id = $gengo->language_preference_id AND $wpdb->post2lang.language_id = $wpdb->languages.language_id"; $from = ", $wpdb->post2lang, $wpdb->languages"; } } else { if (!empty($this->cat)) { $join = " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)"; if ($this->cat !== 'ALL') { $where = " AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id IN ('" . $this->cat . "', "; if ($this->ifchildren == TRUE) { $where .= "'" . implode("', '", get_term_children($this->cat, 'category')) . "'"; } else { $where = substr($where, 0, -2); } $where .= ")"; } } elseif (!empty($this->tag)) { $join = " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)"; $where = " AND $wpdb->term_taxonomy.taxonomy = 'post_tag' AND $wpdb->term_taxonomy.term_id IN ('" . $this->tag . "')"; } $where .= " AND (post_type = 'post' AND (post_status = 'publish'"; if (is_admin()) { $where .= " OR post_status = 'future' OR post_status = 'draft' OR post_status = 'pending'"; } if (is_user_logged_in()) { $where .= current_user_can("read_private_" . get_query_var('post_type') . "s") ? " OR post_status = 'private'" : " OR post_author = $user_ID AND post_status = 'private'"; } } $where .= '))'; $groupby = " GROUP BY $wpdb->posts.ID"; $request = "SELECT SQL_CALC_FOUND_ROWS $wpdb->posts.* FROM $wpdb->posts" . $from . $join . " WHERE 1=1" . $where . $groupby . " ORDER BY post_date DESC"; $request = apply_filters('posts_request', $request); $all_posts = $wpdb->get_results($request); // Create a string containing the first letters of the post titles retrieved above for ($i=0; $i < count($all_posts); $i++) { $word_results[$i] = preg_replace('/^(' . $exclude[1] . ')+((' . $exclude[2] . ')[\s]+)*|^(' . $exclude[2] . ')[\s]+/i', '', wp_snap_core::accents($all_posts[$i]->post_title)); } // Performs a "natural sort" then re-orders the array's key values to match the new order natcasesort($word_results); $word_results = array_values($word_results); foreach ($word_results as $word_result) { $first_letter_all_posts .= strtoupper(substr($word_result, 0, 1)); } // If no query is found in the url, select first post title letter if ($this->first_letters == NULL && $this->firstload !== 'RECENT') { if ($this->firstload == 'NONE') { $this->first_letters = ' '; } elseif ($this->firstload == 'ALL') { $this->first_letters = '#0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; } elseif ((preg_match('/[^0-9A-Z]+/i', substr($first_letter_all_posts, 0, 1))) || (($wp_snap_options['menumisc'] == '1') && (preg_match('/[^A-Z]+/i', substr($first_letter_all_posts, 0, 1))))) { $this->first_letters = '#'; } elseif ($this->menustyle == '1') { for ($i=0; $i < strlen($first_letter_all_posts); $i++) $temp_letter[$i] = substr($first_letter_all_posts, $i, 1); natsort($temp_letter); $temp_letter = array_values($temp_letter); $this->first_letters = $temp_letter['0']; } else { for ($i=3; $i < count($tempstr[$this->menustyle]); $i++) if (strstr($tempstr[$this->menustyle][$i], substr($first_letter_all_posts, 0, 1))) $this->first_letters = $tempstr[$this->menustyle][$i]; } } if ($this->firstload == 'RECENT' && $this->first_letters == NULL) { for ($i=0; $i < count($all_posts); $i++) { if ($wp_snap_options['recent'] <= $i) { $all_posts[$i] = NULL; } } } else { // Resorts $wp_snap_posttitles, taking excluded words into account for ($i=0; $i < count($all_posts); $i++) { if (preg_replace('/^(' . $exclude[1] . ')+((' . $exclude[2] . ')[\s]+)*|^(' . $exclude[2] . ')[\s]+/i', '', wp_snap_core::accents($all_posts[$i]->post_title)) !== $word_results[$i]) { $wp_snap_holdtitle = $all_posts[$i]; for ($j=$i+1; $j < count($all_posts); $j++) { if (preg_replace('/^(' . $exclude[1] . ')+((' . $exclude[2] . ')[\s]+)*|^(' . $exclude[2] . ')[\s]+/i', '', wp_snap_core::accents($all_posts[$j]->post_title)) == $word_results[$i]) { $all_posts[$i] = $all_posts[$j]; $all_posts[$j] = $wp_snap_holdtitle; break; } } } if (($wp_snap_options['menumisc'] == '2' && $this->first_letters == '#' && preg_match('/^[0-9A-Z]+/i', substr($word_results[$i], 0, 1))) || ($wp_snap_options['menumisc'] == '1' && $this->first_letters == '#' && preg_match('/^[A-Z]+/i', substr($word_results[$i], 0, 1))) || ($this->first_letters !== '#' && preg_match('/^[^' . $this->first_letters . ']+/i', substr($word_results[$i], 0, 1)))) { $all_posts[$i] = NULL; } } } foreach ($all_posts as $key => $value) { if ($value == NULL) { unset($all_posts[$key]); } } $all_posts = array_values($all_posts); // Creates where statement needed to modify the wordpress loop $wp_query->post_count = count($all_posts); $wp_query->posts = $all_posts; // Test for post titles beginning with numbers $numlogic = '0'; $numtest = '0'; for ($i = 0; $i < strlen($first_letter_all_posts); $i++) { if (is_numeric(substr($first_letter_all_posts, $i, 1))) { $numlogic = '1'; $numtest = '1'; } } if ($wp_snap_options['menumisc'] == '1') { $numtest = '0'; } // Create tabs based on number input in admin menu $num_tabs = ''; for ($y = 0; $y < $wp_snap_options['tab1']; $y++) { $num_tabs .= "\t"; } // Insert ordered list tag for navigational menu, include class information $results = $num_tabs . '
Options successfully updated.
this plugin\'s page.', 'wp-snap'); ?>