Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2010
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 52.08 KB | None | 0 0
  1. <?php /* Mystique/digitalnature */
  2.  
  3. function mystique_getTinyUrl($url) {
  4. $response = wp_remote_retrieve_body(wp_remote_get('http://tinyurl.com/api-create.php?url='.$url)); // replaces curl (thanks Joseph!)
  5. return $response;
  6. }
  7.  
  8. function mystique_objectToArray($object){
  9. if(!is_object($object) && !is_array($object)) return $object;
  10. if(is_object($object)) $object = get_object_vars($object);
  11. return array_map('mystique_objectToArray', $object);
  12. }
  13.  
  14. // category walker
  15. class mystique_CategoryWalker extends Walker {
  16. var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
  17. var $selected = array();
  18.  
  19. function mystique_CategoryWalker($type='list', $tag='ul', $selected=array()){
  20. $this->tag = $tag;
  21. $this->selected = $selected;
  22. $this->type = $type;
  23. $this->level = 1;
  24. }
  25.  
  26. function start_lvl(&$output){
  27. $this->level++;
  28. $output .= "\n<".$this->tag." class=\"level-".$this->level."\">\n";
  29. }
  30.  
  31. function end_lvl(&$output) {
  32. $this->level--;
  33. $output .= "</".$this->tag.">\n";
  34. }
  35.  
  36. function start_el(&$output, $category, $depth, $args) {
  37. extract($args);
  38.  
  39. $count_text = sprintf(_n('%s post', '%s posts', intval($category->count), 'mystique'),intval($category->count));
  40.  
  41. if (in_array($category->term_id, $this->selected)) $checked = ' checked="checked"'; else $checked = '';
  42.  
  43. $classes = array();
  44. $classes[] = 'category category-'.$category->slug;
  45. $classes[] = 'count-'.intval($category->count);
  46.  
  47. if (isset($current_category) && $current_category) $_current_category = get_category($current_category);
  48.  
  49. $active_class = '';
  50. if((isset($current_category) && $current_category && ($category->term_id == $current_category))) $active_class = 'active';
  51. elseif (isset($_current_category) && $_current_category && ($category->term_id == $_current_category->parent)) $active_class = 'active-parent';
  52.  
  53. $classes[] = $active_class;
  54.  
  55. $output .= '<li class="'.join(' ', $classes).'">';
  56. if($this->type == 'checkbox'):
  57. $output .= '<input class="checkbox '.$active_class.'" id="opt-category-'. $category->term_id. '" name="exclude_categories[]" type="checkbox" value="'. $category->term_id. '"'. $checked. ' />';
  58. $output .= '<label for="opt-category-'. $category->term_id. '"> <a href="' . get_category_link($category->term_id) . '">'.attribute_escape($category->name).'</a>';
  59. if($count) $output .= ' <span>('.$count_text.')</span> ';
  60. $output .= '</label>';
  61. else:
  62.  
  63. if ($category->description) $title = $category->description; else $title = $count_text;
  64. $output .= '<a class="fadeThis '.$active_class.'" href="'.get_category_link($category->term_id).'" title="'.$title.'"><span class="title">'.attribute_escape($category->name).'</span><span class="pointer"></span></a>';
  65. if($count) $output .= ' <span class="post-count">('.intval($category->count).')</span> ';
  66. endif;
  67. }
  68.  
  69. function end_el(&$output, $page) { $output .= "</li>\n"; }
  70. }
  71.  
  72. // page walker
  73. class mystique_PageWalker extends Walker {
  74. var $db_fields = array('parent' => 'post_parent', 'id' => 'ID');
  75. var $selected = array();
  76.  
  77. function mystique_PageWalker($type='list', $tag='ul', $selected=array()){
  78. $this->tag = $tag;
  79. $this->selected = $selected;
  80. $this->type = $type;
  81. $this->level = 1;
  82. }
  83.  
  84. function start_lvl(&$output) {
  85. $this->level++;
  86. $output .= "\n<".$this->tag." class=\"level-".$this->level."\">\n";
  87. }
  88.  
  89. function end_lvl(&$output) {
  90. $this->level--;
  91. $output .= "</".$this->tag.">\n";
  92. }
  93.  
  94. function start_el(&$output, $page, $depth, $args, $current_page) {
  95. extract($args);
  96.  
  97. if (in_array($page->ID, $this->selected)) $checked = ' checked="checked"'; else $checked = '';
  98.  
  99. $classes = array();
  100. $classes[] = 'page page-'.$page->post_name;
  101.  
  102. $active_class = '';
  103. if (!empty($current_page)):
  104. $_current_page = get_page($current_page);
  105. if (isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors)) $active_class = 'active-ancestor';
  106. elseif (($page->ID == $current_page)) $active_class = 'active';
  107. elseif ($_current_page && $page->ID == $_current_page->post_parent) $active_class = 'active-parent';
  108. endif;
  109.  
  110. $classes[] = $active_class;
  111.  
  112. //$classes = implode(' ', apply_filters('page_css_class', $css_class, $page));
  113.  
  114. $output .= '<li class="'.join(' ', $classes).'">';
  115.  
  116. if($this->type == 'checkbox'):
  117. $output .= '<input class="checkbox '.join(' ', $classes).'" id="opt-page-'. $page->ID. '" name="exclude_pages[]" type="checkbox" value="'.$page->ID.'"'. $checked. ' /> <label for="opt-page-'.$page->ID.'"> <a title="'. __('View page','mystique'). '" href="'.get_page_link($page->ID).'">'. apply_filters('the_title', $page->post_title). '</a> </label>';
  118. else:
  119. $output .= '<a class="fadeThis '.$active_class.'" href="'.get_page_link($page->ID).'" title="'.$page->post_title.'"><span class="title">'. apply_filters('the_title', $page->post_title). '</span><span class="pointer"></span></a>';
  120. endif;
  121.  
  122. }
  123.  
  124. function end_el(&$output, $page) { $output .= "</li>\n"; }
  125. }
  126.  
  127. // menu walker
  128. class mystique_MenuWalker extends Walker {
  129. var $tree_type = array('post_type', 'taxonomy', 'custom');
  130. var $db_fields = array('parent' => 'menu_item_parent', 'id' => 'db_id');
  131.  
  132. function start_lvl(&$output, $depth) {
  133. $indent = str_repeat("\t", $depth);
  134. $output .= "\n$indent<ul class=\"level-".($depth+2)."\">\n";
  135. }
  136.  
  137. function end_lvl(&$output, $depth) {
  138. $indent = str_repeat("\t", $depth);
  139. $output .= "$indent</ul>\n";
  140. }
  141.  
  142. function start_el(&$output, $item, $depth, $args) {
  143. global $wp_query;
  144. $indent = ($depth) ? str_repeat("\t", $depth) : '';
  145. $class_names = $value = '';
  146. $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  147.  
  148. $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
  149. if($class_names) $class_names = ' class="' .esc_attr($class_names). '"';
  150.  
  151. $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
  152.  
  153. $attributes = ! empty($item->attr_title) ? ' title="' . esc_attr($item->attr_title) .'"' : '';
  154. $attributes .= ! empty($item->target) ? ' target="' . esc_attr($item->target) .'"' : '';
  155. $attributes .= ! empty($item->xfn) ? ' rel="' . esc_attr($item->xfn) .'"' : '';
  156. $attributes .= ! empty($item->url) ? ' href="' . esc_attr($item->url) .'"' : '';
  157.  
  158. $item_output .= '<a'. $attributes .' class="fadeThis">';
  159. $item_output .= '<span class="title">' . apply_filters('the_title', $item->title, $item->ID) . '</span>';
  160. $item_output .= '<span class="pointer"></span></a>';
  161.  
  162. $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  163. }
  164.  
  165. function end_el(&$output, $item, $depth) {
  166. $output .= "</li>\n";
  167. }
  168. }
  169.  
  170. function _mystique_menu_item_classes_by_context( &$menu_items ) {
  171. global $wp_query;
  172.  
  173. $queried_object = $wp_query->get_queried_object();
  174. $queried_object_id = (int) $wp_query->queried_object_id;
  175.  
  176. $active_object = '';
  177. $active_parent_item_ids = array();
  178. $active_parent_object_ids = array();
  179. $possible_object_parents = array();
  180. $home_page_id = (int) get_option( 'page_for_posts' );
  181.  
  182. if ( $wp_query->is_singular && ! empty( $queried_object->post_type ) && ! is_post_type_hierarchical( $queried_object->post_type ) ) {
  183. foreach ( (array) get_object_taxonomies( $queried_object->post_type ) as $taxonomy ) {
  184. if ( is_taxonomy_hierarchical( $taxonomy ) ) {
  185. $terms = wp_get_object_terms( $queried_object_id, $taxonomy, array( 'fields' => 'ids' ) );
  186. if ( is_array( $terms ) )
  187. $possible_object_parents = array_merge( $possible_object_parents, $terms );
  188. }
  189. }
  190. } elseif ( ! empty( $queried_object->post_type ) && is_post_type_hierarchical( $queried_object->post_type ) ) {
  191. _get_post_ancestors( $queried_object );
  192. }
  193.  
  194. $possible_object_parents = array_filter( $possible_object_parents );
  195.  
  196. foreach ( (array) $menu_items as $key => $menu_item ) {
  197. // if the menu item corresponds to a taxonomy term for the currently-queried non-hierarchical post object
  198. if ( $wp_query->is_singular && 'taxonomy' == $menu_item->type && in_array( $menu_item->object_id, $possible_object_parents ) ) {
  199. $active_parent_object_ids[] = (int) $menu_item->object_id;
  200. $active_parent_item_ids[] = (int) $menu_item->db_id;
  201. $active_object = $queried_object->post_type;
  202.  
  203. // if the menu item corresponds to the currently-queried post or taxonomy object
  204. } elseif (
  205. $menu_item->object_id == $queried_object_id &&
  206. (
  207. ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id ) ||
  208. ( 'post_type' == $menu_item->type && $wp_query->is_singular ) ||
  209. ( 'taxonomy' == $menu_item->type && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ) )
  210. )
  211. ) {
  212. $menu_items[$key]->classes[] = 'active';
  213. $active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
  214. $active_parent_object_ids[] = (int) $menu_item->post_parent;
  215. $active_object = $menu_item->object;
  216.  
  217. // if the menu item corresponds to the currently-requested URL
  218. } elseif ( 'custom' == $menu_item->object ) {
  219. $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  220. $item_url = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url;
  221. if ( $item_url == $current_url ) {
  222. $menu_items[$key]->classes[] = 'active';
  223. if ( untrailingslashit($current_url) == home_url() )
  224. $menu_items[$key]->classes[] = 'home';
  225. $active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
  226. $active_parent_object_ids[] = (int) $menu_item->post_parent;
  227. $active_object = $menu_item->object;
  228. }
  229. }
  230.  
  231. // back-compat with wp_page_menu: add "current_page_parent" to static home page link for any non-page query
  232. if ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && empty( $wp_query->is_page ) && $home_page_id == $menu_item->object_id )
  233. $menu_items[$key]->classes[] = 'active-parent';
  234. }
  235.  
  236. $active_parent_item_ids = array_filter( array_unique( $active_parent_item_ids ) );
  237. $active_parent_object_ids = array_filter( array_unique( $active_parent_object_ids ) );
  238.  
  239. // set parent's class
  240. foreach ( (array) $menu_items as $key => $parent_item ) {
  241. if (
  242. isset( $parent_item->type ) &&
  243. 'post_type' == $parent_item->type &&
  244. ! empty( $queried_object->post_type ) &&
  245. is_post_type_hierarchical( $queried_object->post_type ) &&
  246. in_array( $parent_item->object_id, $queried_object->ancestors )
  247. )
  248. $menu_items[$key]->classes[] = 'active-' . $queried_object->post_type . '-ancestor active-ancestor';
  249. if ( in_array( $parent_item->db_id, $active_parent_item_ids ) )
  250. $menu_items[$key]->classes[] = 'active-parent';
  251. if ( in_array( $parent_item->object_id, $active_parent_object_ids ) )
  252. $menu_items[$key]->classes[] = 'active-' . $active_object . '-parent';
  253. }
  254. }
  255.  
  256. // replaces wp_list_categories (didn't like the <li> classes)
  257. function mystique_list_categories($args = array()) {
  258. global $wp_query;
  259. $categories = &get_categories($args);
  260. $walker = new mystique_CategoryWalker();
  261. if (!empty($categories)) echo $walker->walk($categories, 0, array('count' => false, 'current_category' =>$wp_query->get_queried_object_id()));
  262. }
  263.  
  264. // replaces wp_list_pages
  265. function mystique_list_pages($args = array()) {
  266. global $wp_query;
  267. $pages = &get_pages($args);
  268. $walker = new mystique_PageWalker();
  269. if (!empty($pages)) echo $walker->walk($pages,0, array(),$wp_query->get_queried_object_id());
  270. }
  271.  
  272. function mystique_list_menu($args = array()) {
  273. $locations = get_nav_menu_locations();
  274. $menu = wp_get_nav_menu_object($locations['primary']);
  275.  
  276. $menu_items = wp_get_nav_menu_items($menu->term_id);
  277. if(empty($menu_items)): printf('<li><a><span class="error">'.__("Empty menu (%s)","mystique").'</span></a></li>', $menu->slug); return; endif;
  278. $nav_menu = '';
  279. $items = '';
  280. _mystique_menu_item_classes_by_context($menu_items);
  281. $sorted_menu_items = array();
  282. foreach ((array) $menu_items as $key => $menu_item) $sorted_menu_items[$menu_item->menu_order] = wp_setup_nav_menu_item($menu_item);
  283.  
  284. $walker = new mystique_MenuWalker();
  285. $items .= $walker->walk($sorted_menu_items, 0, array());
  286.  
  287. // Allow plugins to hook into the menu to add their own <li>'s
  288. $items = apply_filters('wp_nav_menu_items', $items, $args);
  289. $items = apply_filters("wp_nav_menu_{$menu->slug}_items", $items, $args);
  290. $nav_menu .= $items;
  291.  
  292. $nav_menu = apply_filters('wp_nav_menu', $nav_menu, $args);
  293. echo $nav_menu;
  294. }
  295.  
  296. // print the main navigation menu
  297. function mystique_navigation($navtype = false) {
  298. if(!$navtype): // main navi?
  299. $navtype = get_mystique_option('navigation');
  300. $nav_extra = apply_filters("mystique_navigation_extra", ''); // check for new icons and output
  301. endif;
  302. if($navtype): ?>
  303.  
  304. <div class="shadow-left">
  305. <div class="shadow-right clear-block">
  306. <?php
  307. if($nav_extra) echo '<p class="nav-extra">'.$nav_extra.'</p>'; ?>
  308.  
  309. <ul class="navigation <?php echo $nav_type; ?> clear-block">
  310. <?php
  311. if((get_option('show_on_front')<>'page') && get_mystique_option('exclude_home')<>'1'):
  312. if(is_home() && !is_paged()): ?>
  313. <li class="active home"><a class="home active fadeThis" href="<?php echo get_settings('home'); ?>" title="<?php _e('You are Home','mystique'); ?>"><span class="title"><?php _e('Home','mystique'); ?></span><span class="pointer"></span></a></li>
  314. <?php else: ?>
  315. <li class="home"><a class="home fadeThis" href="<?php echo get_option('home'); ?>" title="<?php _e('Click for Home','mystique'); ?>"><span class="title"><?php _e('Home','mystique'); ?></span><span class="pointer"></span></a></li>
  316. <?php
  317. endif;
  318. endif; ?>
  319. <?php
  320. if($navtype=='categories'):
  321. mystique_list_categories(array('hide_empty' => false, 'exclude' => get_mystique_option('exclude_categories')));
  322.  
  323. elseif($navtype=='links'):
  324. $links = get_bookmarks(array(
  325. 'orderby' => 'name',
  326. 'order' => 'ASC',
  327. 'limit' => -1,
  328. 'category' => null,
  329. 'category_name' => get_mystique_option('navigation_links'),
  330. 'hide_invisible' => true,
  331. 'show_updated' => 0,
  332. 'include' => null,
  333. 'search' => '.'));
  334.  
  335. foreach ($links as $link):
  336. if($link->link_target) $target = ' target="'.wp_specialchars($link->link_target).'"'; else $target = '';
  337. if($link->link_rel) $rel = ' rel="'.wp_specialchars($link->link_rel).'"'; else $rel = '';
  338. if($link->link_description) $title = ' title="'.wp_specialchars($link->link_description).'"'; else $title = '';
  339. echo '<li><a class="fadeThis" href="'.$link->link_url.'"'.$target.$rel.$title.'><span class="title">'.$link->link_name.'</span><span class="pointer"></span></a><li>';
  340. endforeach;
  341.  
  342. elseif($navtype=='pages'):
  343. mystique_list_pages(array('exclude' => get_mystique_option('exclude_pages'), 'sort_column' => 'menu_order'));
  344. else:
  345. mystique_list_menu();
  346. endif;
  347.  
  348. do_action('mystique_navigation'); ?>
  349. </ul>
  350. </div>
  351. </div>
  352. <?php endif;
  353. }
  354.  
  355. // based on hybrid theme's title
  356. function mystique_title($separator = ' « '){
  357. global $wp_query;
  358.  
  359. if (is_front_page() && is_home()):
  360. $doctitle = get_bloginfo('name').$separator.get_bloginfo('description');
  361. elseif (is_home() || is_singular()):
  362. $id = $wp_query->get_queried_object_id();
  363. $doctitle = get_post_meta($id, 'title', true);
  364. $doctitle = (!$doctitle && is_front_page()) ? get_bloginfo('name').$separator.get_bloginfo('description') : get_post_field('post_title', $id);
  365.  
  366. elseif (is_archive()):
  367.  
  368. if (is_category() || is_tag() || is_tax()):
  369. $term = $wp_query->get_queried_object();
  370. $doctitle = $term->name;
  371. elseif (is_author()):
  372. $doctitle = get_the_author_meta('display_name', get_query_var('author'));
  373. elseif (is_date()):
  374. if (is_day())
  375. $doctitle = sprintf(__('Archive for %s', "mystique"), get_the_time(__('F jS, Y', "mystique")));
  376. elseif (get_query_var('w'))
  377. $doctitle = sprintf(__('Archive for week %1$s of %2$s', "mystique"), get_the_time(__('W', "mystique")), get_the_time(__('Y', "mystique")));
  378. elseif (is_month())
  379. $doctitle = sprintf(__('Archive for %s', "mystique"), single_month_title(' ', false));
  380. elseif (is_year())
  381. $doctitle = sprintf(__('Archive for year %s', "mystique"), get_the_time(__('Y', "mystique")));
  382. endif;
  383.  
  384. elseif (is_search()):
  385. $doctitle = sprintf(__('Search results for %s', "mystique"),'"'.esc_attr(get_search_query()).'"');
  386.  
  387. elseif (is_404()):
  388. $doctitle = __('404 Not Found', "mystique");
  389.  
  390. endif;
  391.  
  392. /* If paged. */
  393. if ((($page = $wp_query->get('paged')) || ($page = $wp_query->get('page'))) && $page > 1)
  394. $doctitle .= $separator.sprintf(__('Page %s', "mystique"), $page);
  395.  
  396. /* if comment page... */
  397. if (get_query_var('cpage'))
  398. $doctitle .= $separator.sprintf(__('Comment Page %s', "mystique"), get_query_var('cpage'));
  399.  
  400. /* Apply the wp_title filters so we're compatible with plugins. */
  401. $doctitle = apply_filters('wp_title', $doctitle, $separator, '');
  402.  
  403. echo $doctitle;
  404. }
  405.  
  406. function mystique_category_breadcrumb($id, $visited = array()){
  407. $chain = '';
  408. $parent = &get_category($id);
  409. $level = 1;
  410. if (is_wp_error($parent)) return $parent;
  411.  
  412. $name = $parent->cat_name;
  413. if ($parent->parent && ($parent->parent != $parent->term_id) && !in_array($parent->parent, $visited)):
  414. $visited[] = $parent->parent;
  415. $chain .= mystique_category_breadcrumb($parent->parent, $visited);
  416. $level++;
  417. endif;
  418.  
  419. $chain .= '<a class="category level-'.$level.'" href="'.get_category_link($parent->term_id).'" title="'.esc_attr(sprintf(__("View all posts in %s","mystique"), $parent->cat_name)).'">'.$name.'</a>';
  420. echo ' '.$chain.' ';
  421. }
  422.  
  423. function mystique_top_category($categorylist,$link = true){
  424. if($categorylist[0]->category_parent) $top_category = get_category($categorylist[0]->category_parent); else $top_category = get_category($categorylist[0]->cat_ID);
  425.  
  426. ($top_category->description) ? $top_category_description = $top_category->description : $top_category_description = sprintf(_n('%s post', '%s posts', intval($top_category->count), 'mystique'),intval($top_category->count));
  427.  
  428. if($top_category) echo '<a title="'.$top_category_description.'" href="'.get_category_link($top_category->cat_ID).'" class="category">'.$top_category->cat_name.'</a>';
  429. }
  430.  
  431. function mystique_logo(){
  432. $options = get_option('mystique');
  433. $size = $options['logo_size'];
  434. if($size) $size = 'width="'.substr($size, 0, strpos($size, "x")).'" height="'.substr($size, strpos($size, 'x')+1).'"';
  435.  
  436. $sitename = get_bloginfo('name');
  437. $siteurl = get_bloginfo('url');
  438.  
  439. $tag = (is_home() || is_front_page()) ? 'h1' : 'div';
  440.  
  441. $output = '<'.$tag.' id="logo">';
  442.  
  443. if($options['logo']) // logo image?
  444. $output .= '<a href="'.$siteurl.'"><img src="'.$options['logo'].'" title="'.$sitename.'" '.$size.' alt="'.$sitename.'" /></a>';
  445. else
  446. $output .= '<a href="'.$siteurl.'">'.$sitename.'</a>';
  447. $output .= '</'.$tag.'>';
  448. echo apply_filters('mystique_logo', $output);
  449. }
  450.  
  451. function mystique_shareThis(){
  452. global $post;
  453. $content = get_the_excerpt();
  454. ?>
  455. <!-- socialize -->
  456. <div class="shareThis clear-block">
  457. <a href="#" class="control share"><?php _e("Share this post!","mystique"); ?></a>
  458. <ul class="bubble">
  459. <li><a href="http://twitter.com/home?status=<?php the_title(); ?>+-+<?php echo mystique_getTinyUrl(get_permalink()); ?>" class="twitter" title="Tweet This!"><span>Twitter</span></a></li>
  460. <li><a href="http://digg.com/submit?phase=2&url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" class="digg" title="Digg this!"><span>Digg</span></a></li>
  461. <li><a href="http://www.facebook.com/share.php?u=<?php the_permalink(); ?>&t=<?php the_title(); ?>" class="facebook" title="Share this on Facebook"><span>Facebook</span></a></li>
  462. <li><a href="http://del.icio.us/post?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" class="delicious" title="Share this on del.icio.us"><span>Delicious</span></a></li>
  463. <li><a href="http://www.stumbleupon.com/submit?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" class="stumbleupon" title="Stumbled upon something good? Share it on StumbleUpon"><span>StumbleUpon</span></a></li>
  464. <li><a href="http://www.google.com/bookmarks/mark?op=add&bkmk=<?php the_permalink(); ?>&title=<?php the_title(); ?>" class="google" title="Add this to Google Bookmarks"><span>Google Bookmarks</span></a></li>
  465. <li><a href="http://www.linkedin.com/shareArticle?mini=true&url=<?php the_permalink(); ?>&title=<?php the_title(); ?>&summary=<?php echo strip_tags($content); ?>&source=<?php bloginfo('name'); ?>" class="linkedin" title="Share this on Linkedin"><span>LinkedIn</span></a></li>
  466. <li><a href="http://buzz.yahoo.com/buzz?targetUrl=<?php the_permalink(); ?>&headline=<?php the_title(); ?>&summary=<?php echo strip_tags($content); ?>" class="yahoo" title="Buzz up!"><span>Yahoo Bookmarks</span></a></li>
  467. <li><a href="http://technorati.com/faves?add=<?php the_permalink(); ?>" class="technorati" title="Share this on Technorati"><span>Technorati Favorites</span></a></li>
  468. </ul>
  469. </div>
  470. <!-- /socialize -->
  471. <?php
  472. }
  473.  
  474. function mystique_search_form(){ ?>
  475. <!-- search form -->
  476. <div class="search-form">
  477. <form method="get" id="searchform" action="<?php bloginfo('url'); ?>/" class="clear-block">
  478. <fieldset>
  479. <div id="searchfield">
  480. <input type="text" name="s" id="searchbox" class="text clearField" value="<?php _e("Search","mystique"); ?>" />
  481. </div>
  482. <input type="submit" value="" class="submit" />
  483. </fieldset>
  484. </form>
  485. </div>
  486. <!-- /search form -->
  487. <?php
  488. }
  489.  
  490. function mystique_highlight_search_query(){
  491. $referer = urldecode($_SERVER['HTTP_REFERER']);
  492.  
  493. if (preg_match('@^http://(.*)?\.?(google|yahoo|lycos).*@i', $referer)) $query = preg_replace('/^.*(&q|query|p)=([^&]+)&?.*$/i','$2', $referer);
  494. else $query = attribute_escape(get_search_query());
  495.  
  496. if(strlen($query) > 0): ?>
  497. var highlight_search_query = "<?php echo $query; ?>";
  498. jQuery(".hentry").each(function(){
  499. jQuery(this).highlight(highlight_search_query, 1, "highlight");
  500. });
  501. <?php
  502. endif;
  503. }
  504.  
  505. function mystique_trim_string($input, $string){
  506. $input = trim($input);
  507. $string = escape_string_for_regex($string);
  508. $startPattern = "/^($string)+/i";
  509. $endPattern = "/($string)+$/i";
  510. return trim(preg_replace($endPattern, '', preg_replace($startPattern, '', $input)));
  511. }
  512.  
  513. // filter post content (for other pages than single)
  514. function mystique_trim_the_content($the_contents, $read_more_tag, $perma_link_to = '', $all_words = 100, $allowed_tags = array('a', 'abbr', 'blockquote', 'b', 'cite', 'pre', 'code', 'em', 'label', 'i', 'p', 'span', 'strong', 'ul', 'ol', 'li')) {
  515.  
  516. if($the_contents != ''):
  517.  
  518. // process allowed tags
  519. $allowed_tags = '<' .implode('><',$allowed_tags).'>';
  520. $the_contents = str_replace(']]>', ']]>', $the_contents);
  521.  
  522. // exclude HTML and shortcodes from counting words
  523. $the_contents = strip_tags($the_contents, $allowed_tags);
  524. $the_contents = strip_shortcodes($the_contents);
  525.  
  526. if(!is_numeric($all_words)) $all_words = 9999; // assuming full post
  527.  
  528. // count all
  529. if($all_words > count(preg_split('/[\s]+/', strip_tags($the_contents), -1))) return $the_contents;
  530.  
  531. $all_chunks = preg_split('/([\s]+)/', $the_contents, -1, PREG_SPLIT_DELIM_CAPTURE);
  532.  
  533. $the_contents = '';
  534. $count_words = 0;
  535. $enclosed_by_tag = false;
  536. foreach($all_chunks as $chunk):
  537.  
  538. // is tag opened?
  539. if(0 < preg_match('/<[^>]*$/s', $chunk)) $enclosed_by_tag = true; elseif(0 < preg_match('/>[^<]*$/s', $chunk)) $enclosed_by_tag = false;
  540.  
  541. // get entire word
  542. if(!$enclosed_by_tag && '' != trim($chunk) && substr($chunk, -1, 1) != '>') $count_words ++;
  543. $the_contents .= $chunk;
  544. if($count_words >= $all_words && !$enclosed_by_tag) break;
  545.  
  546. endforeach;
  547.  
  548. // note the class named 'more-link'. style it on your own
  549. $the_contents = $the_contents.' <a class="more-link" href="'.$perma_link_to.'">'.$read_more_tag.'</a>';
  550.  
  551. // native WordPress check for unclosed tags
  552. $the_contents = force_balance_tags($the_contents);
  553. endif;
  554. return $the_contents;
  555. }
  556.  
  557. // strip tags and attributes from a string that can be used to XSS
  558. function mystique_strip_tags_attributes($string, $allowed_tags = '<a><br><style><abbr><blockquote><b><cite><pre><code><em><label><i><p><div><span><strong><ul><ol><li><dt><dd><dl><table><td><tr><th><tbody><tfoot><thead><colgroup><h1><h2><h3><h4><h5><h6><u>', $allowed_attributes = 'class,title,alt,href,dir,id,cite,lang,width,height,border,colspan,rowspan,align,rel,type'){
  559.  
  560. $string = preg_replace('#/*\*()[^>]*\*/#i', '', $string); // remove /**/
  561. $string = preg_replace('#([a-z]*)[\x00-\x20]*e[\x00-\x20]*x[\x00-\x20]*p[\x00-\x20]*r[\x00-\x20]*e[\x00-\x20]*s[\x00-\x20]*s[\x00-\x20]*i[\x00-\x20]*o[\x00-\x20]*n#iU', '', $string); // remove 'expression'
  562. $string = preg_replace('#([a-z]*)[\x00-\x20]*([\
  563. `
  564. \'\"]*)[\\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iU', '', $string); // remove "javascript"
  565. $string = preg_replace('#([a-z]*)([\'\"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iU', '', $string); // remove "vbscript"
  566. $string = preg_replace('#([a-z]*)[\x00-\x20]*([\\\]*)[\\x00-\x20]*@([\\\]*)[\x00-\x20]*i([\\\]*)[\x00-\x20]*m([\\\]*)[\x00-\x20]*p([\\\]*)[\x00-\x20]*o([\\\]*)[\x00-\x20]*r([\\\]*)[\x00-\x20]*t#iU', '', $string); // take out @import
  567.  
  568. $string = strip_tags($string, $allowed_tags);
  569.  
  570. if (!is_null($allowattributes)):
  571. if(!is_array($allowattributes)) $allowattributes = explode(",", $allowattributes);
  572. if(is_array($allowattributes)) $allowattributes = implode(")(?<!", $allowattributes);
  573. if(strlen($allowattributes) > 0) $allowattributes = "(?<!".$allowattributes.")";
  574. $string = preg_replace_callback("/<[^>]*>/i",create_function(
  575. '$matches',
  576. 'return preg_replace("/ [^ =]*'.$allowattributes.'=(\"[^\"]*\"|\'[^\']*\')/i", "", $matches[0]);'
  577. ), $string);
  578. endif;
  579. return $string;
  580. }
  581.  
  582. function mystique_strip_string($intLength = 0, $strText = "") {
  583. $strText = strip_tags($strText);
  584. if(strlen($strText) > $intLength):
  585. $strText = mb_substr($strText,0,$intLength);
  586. $strText = mb_substr($strText,0,strrpos($strText,' '));
  587. return $strText.'...';
  588. else:
  589. return $strText;
  590. endif;
  591. }
  592.  
  593. function mystique_comment_count($comment_types = 'comments', $post_id = false) {
  594. global $id;
  595. $post_id = (int)$post_id;
  596. if (!$post_id) $post_id = $id;
  597. $comments = get_approved_comments($post_id);
  598. $num_pings = 0;
  599. $num_comments = 0;
  600. foreach($comments as $comment) if (get_comment_type() != "comment") $num_pings++; else $num_comments++;
  601. return ($comment_types == 'comments') ? $num_comments : $num_pings;
  602. }
  603.  
  604. function mystique_post_thumb($size = 'post-thumbnail', $post_id = false){
  605. global $post, $id;
  606. $post_id = (int)$post_id;
  607. if (!$post_id) $post_id = $id;
  608. $image = '';
  609.  
  610. if (has_post_thumbnail($post_id)) $image = get_the_post_thumbnail($post_id, $size);
  611.  
  612. if(get_mystique_option('post_thumb_auto') && !$image): // get the 1st image
  613. $attachments = get_children(array('post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID'));
  614. if($attachments):
  615. $attachment = array_shift($attachments);
  616. $image = wp_get_attachment_image($attachment->ID, $size);
  617. endif;
  618. endif;
  619.  
  620. if($image && !get_post_meta($post->ID, 'asides', true)):
  621. echo '<a href="'.get_permalink($post_id).'">'.apply_filters("mystique_post_thumbnail", $image).'</a>';
  622. return true;
  623. endif;
  624. return false;
  625. }
  626.  
  627. // only inside the loop!
  628. function mystique_post(){
  629. global $post, $id, $comment;
  630.  
  631. $category = get_the_category();
  632. $category_name = $category[0]->cat_name;
  633.  
  634. if(!empty($category_name)) $category_link = '<a>cat_ID).'">'.$category_name.'</a>';
  635. else $category_link = "[...]";
  636.  
  637. $post_tags = get_the_tags();
  638. $post_settings = apply_filters('mystique_post_settings', get_option("mystique"));
  639. $comment_count = mystique_comment_count('comments');
  640.  
  641. do_action('mystique_before_post'); ?>
  642.  
  643. <!-- post -->
  644. <div id="post-<?php the_ID(); ?>" class="<?php mystique_post_class('clear-block'); ?>">
  645.  
  646. <?php
  647. $post_thumb = mystique_post_thumb();
  648. if($post_settings['post_title']):
  649. $title_url = get_post_meta($post->ID, 'title_url', true); ?>
  650. <h2 class="title"><a>" rel="bookmark" title="<?php _e('Permanent Link:','mystique'); echo ' '; the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
  651. <?php endif; ?>
  652.  
  653. <?php if($post_settings['post_info'] && !get_post_meta($post->ID, 'asides', true)): ?>
  654. <div class="post-date">
  655. <p class="day"><?php the_time(__('M jS','mystique')); ?></p>
  656. </div>
  657.  
  658. <div class="post-info clear-block <?php if ($post_thumb) echo 'with-thumbs' ?>">
  659. <p class="author alignleft"><?php printf(__('Posted by %1$s in %2$s','mystique'),'<a href="'. get_author_posts_url(get_the_author_meta('ID')) .'">'. get_the_author() .'</a>', $category_link);
  660. ?>
  661. <?php if(function_exists('the_views')): ?><span class="postviews">| <?php the_views(); ?></span><?php endif; ?>
  662. <?php edit_post_link(__('Edit','mystique'),' | '); ?>
  663. </p>
  664. <?php
  665. if((comments_open() || $comment_count > 0)): ?>
  666. <p class="comments alignright"><a>#comments" class="<?php if ($comment_count < 1) echo "no"; ?> comments"><?php comments_number(__('No comments', 'mystique'), __('1 comment', 'mystique'), __('% comments', 'mystique')); ?></a></p>
  667. <?php endif; ?>
  668. </div>
  669. <?php endif; ?>
  670.  
  671. <?php if($post_settings['post_content']): ?>
  672. <div class="post-content clear-block">
  673. <?php
  674.  
  675. if($post_settings['post_content_length'] == 'f'): the_content(__('More >','mystique'));
  676. elseif($post_settings['post_content_length'] == 'e'): the_excerpt();
  677. else:
  678. $word_count = $post_settings['post_content_length'];
  679.  
  680. // save original post content to variable
  681. $content = get_the_content();
  682.  
  683. // prevent tags strip | it's a bug in WordPress!
  684. $content = apply_filters('the_content', $content);
  685. $content = str_replace(']]>', ']]>', $content);
  686.  
  687. // throw out trimmed: content to process, read more tag, post permalink, words length
  688. echo mystique_trim_the_content($content, __('More >','mystique'), get_permalink($post->ID), $word_count);
  689. endif; ?>
  690. </div>
  691. <?php endif; ?>
  692. <?php if(function_exists('the_ratings')) the_ratings(); ?>
  693.  
  694. <?php if ($post_tags && $post_settings['post_tags']): ?>
  695. <div class="post-tags">
  696. <?php
  697. $tags = array();
  698. $i = 0;
  699. foreach($post_tags as $tag):
  700. $tags[$i] .= '<a>term_id).'" rel="tag" title="'.sprintf(__('%1$s (%2$s topics)'),$tag->name,$tag->count).'">'.$tag->name.'</a>';
  701. $i++;
  702. endforeach;
  703. echo implode(', ',$tags); ?>
  704. </div>
  705. <?php endif; ?>
  706.  
  707. </div>
  708. <!-- /post -->
  709. <?php do_action('mystique_after_post');
  710.  
  711. }
  712.  
  713. // only inside the loop!
  714. function mystique_page(){
  715. global $post, $id, $comment;
  716.  
  717. $tags = get_the_tags();
  718. $comment_count = mystique_comment_count('comments');
  719.  
  720. do_action('mystique_before_page'); ?>
  721.  
  722. <!-- post -->
  723. <div class="<?php mystique_post_class("clear-block"); ?>">
  724.  
  725. <?php
  726. $hide_title = get_post_meta($post->ID, 'hide_title', true);
  727. if(!$hide_title): ?>
  728. <h1 class="title">
  729. <?php
  730. the_title();
  731. ?>
  732. </h1> <?php
  733. endif;
  734.  
  735. the_content();
  736. wp_link_pages(array('before' => '<p><strong>'.__("Pages: ","mystique").'</strong> ', 'after' => '</p>', 'next_or_number' => 'number'));
  737. if(function_exists('wp_print')): ?><div class="alignright"><?php print_link(); ?></div><?php endif;
  738. edit_post_link(__('Edit this page', 'mystique'));
  739. ?>
  740.  
  741. </div>
  742. <!-- /post -->
  743. <?php
  744. do_action('mystique_after_page');
  745. }
  746.  
  747. function mystique_excerpt_more($excerpt) {
  748. $link = ' <a href="'.get_permalink().'">'.__('More >', 'mystique').'</a>';
  749. }
  750.  
  751. function mystique_meta_redirect(){
  752. if(is_single() || is_page()):
  753. global $post;
  754. $field = get_post_meta($post->ID, 'redirect', true);
  755. if($field) wp_redirect(clean_url($field), 301);
  756. endif;
  757. }
  758.  
  759. function mystique_n_round($num, $tonearest) {
  760. return floor($num/$tonearest)*$tonearest;
  761. }
  762.  
  763. // wp-pagenavi - http://wordpress.org/extend/plugins/wp-pagenavi
  764. function mystique_pagenavi($class='',$pages_to_show = 5) {
  765. global $wp_query;
  766. if (!is_single()):
  767. $posts_per_page = intval(get_query_var('posts_per_page'));
  768. $paged = intval(get_query_var('paged'));
  769. $max_page = $wp_query->max_num_pages;
  770. if(empty($paged) || $paged == 0) $paged = 1;
  771. $larger_page_to_show = 3;
  772. $larger_page_multiple = 10;
  773. $pages_to_show_minus_1 = $pages_to_show - 1;
  774. $half_page_start = floor($pages_to_show_minus_1/2);
  775. $half_page_end = ceil($pages_to_show_minus_1/2);
  776. $start_page = $paged - $half_page_start;
  777. if($start_page <= 0) $start_page = 1;
  778. $end_page = $paged + $half_page_end;
  779. if(($end_page - $start_page) != $pages_to_show_minus_1) $end_page = $start_page + $pages_to_show_minus_1;
  780. if($end_page > $max_page):
  781. $start_page = $max_page - $pages_to_show_minus_1;
  782. $end_page = $max_page;
  783. endif;
  784. if($start_page <= 0) $start_page = 1;
  785. $larger_per_page = $larger_page_to_show*$larger_page_multiple;
  786. $larger_start_page_start = (mystique_n_round($start_page, 10) + $larger_page_multiple) - $larger_per_page;
  787. $larger_start_page_end = mystique_n_round($start_page, 10) + $larger_page_multiple;
  788. $larger_end_page_start = mystique_n_round($end_page, 10) + $larger_page_multiple;
  789. $larger_end_page_end = mystique_n_round($end_page, 10) + ($larger_per_page);
  790. if($larger_start_page_end - $larger_page_multiple == $start_page):
  791. $larger_start_page_start = $larger_start_page_start - $larger_page_multiple;
  792. $larger_start_page_end = $larger_start_page_end - $larger_page_multiple;
  793. endif;
  794. if($larger_start_page_start <= 0) $larger_start_page_start = $larger_page_multiple;
  795. if($larger_start_page_end > $max_page) $larger_start_page_end = $max_page;
  796. if($larger_end_page_end > $max_page) $larger_end_page_end = $max_page;
  797. if($max_page > 1): ?>
  798.  
  799. <!-- page navigation -->
  800. <div class="page-navigation <?php echo $class; ?> clear-block">
  801.  
  802. <?php
  803. if ($start_page >= 2 && $pages_to_show < $max_page):
  804. echo '<a href="'.clean_url(get_pagenum_link()).'" title="'.__('Go to the first page','mystique').'">'.__('« First','mystique').'</a>';
  805. echo '<span class="extend">...</span>';
  806. endif;
  807.  
  808. if($larger_page_to_show > 0 && $larger_start_page_start > 0 && $larger_start_page_end <= $max_page)
  809. for($i = $larger_start_page_start; $i < $larger_start_page_end; $i+=$larger_page_multiple)
  810. echo '<a href="'.clean_url(get_pagenum_link($i)).'">'.$i.'</a>';
  811.  
  812. previous_posts_link('«');
  813.  
  814. for($i = $start_page; $i <= $end_page; $i++)
  815. if($i == $paged) echo '<span class="current">'.$i.'</span>';
  816. else echo '<a href="'.clean_url(get_pagenum_link($i)).'">'.$i.'</a>';
  817.  
  818. next_posts_link('»', $max_page);
  819.  
  820. if($larger_page_to_show > 0 && $larger_end_page_start < $max_page)
  821. for($i = $larger_end_page_start; $i <= $larger_end_page_end; $i+=$larger_page_multiple)
  822. echo '<a href="'.clean_url(get_pagenum_link($i)).'">'.$i.'</a>';
  823.  
  824. if ($end_page < $max_page):
  825. echo '<span class="extend">...</span>';
  826. echo '<a href="'.clean_url(get_pagenum_link($max_page)).'" title="'.__('Go to the last page','mystique').'">'.__('Last »','mystique').'</a>';
  827. endif; ?>
  828.  
  829. </div>
  830. <!-- /page navigation -->
  831. <?php
  832. endif;
  833. endif;
  834. }
  835.  
  836. // don't show page contents in search results
  837. function mystique_exclude_pages_from_search($query){
  838. if ($query->is_search && !is_admin()) $query->set('post_type', 'post');
  839. return $query;
  840. }
  841.  
  842. // search within taxonomies - based on http://wordpress.org/extend/plugins/search-tags
  843. function mystique_search_where($where){
  844. if (is_search()):
  845. global $table_prefix, $wpdb, $wp_query;
  846. $tabletags = $table_prefix . "terms";
  847. $tablepost2tag = $table_prefix . "term_relationships";
  848. $tabletaxonomy = $table_prefix . "term_taxonomy";
  849. $searchInput = $wp_query->query_vars['s'];
  850. $searchInput = str_replace('"', '', $searchInput);
  851. $searchInput = str_replace("'", '', $searchInput);
  852. $where .= " OR (tr.name like '%" . $searchInput . "%' AND post_status = 'publish' AND post_type = 'post')";
  853. endif;
  854. return $where;
  855. }
  856.  
  857. function mystique_search_join($join){
  858. if (is_search()):
  859. global $table_prefix, $wpdb;
  860. $tabletags = $table_prefix . "terms";
  861. $tablepost2tag = $table_prefix . "term_relationships";
  862. $tabletaxonomy = $table_prefix . "term_taxonomy";
  863. $join .= " LEFT JOIN (select distinct tr.object_id, t.name from $tablepost2tag tr inner join $tabletaxonomy tt on tt.term_taxonomy_id = tr.term_taxonomy_id inner join $tabletags t on t.term_id = tt.term_id) tr on $wpdb->posts.ID = tr.object_id ";
  864. endif;
  865. return $join;
  866. }
  867.  
  868. function mystique_search_groupby($groupby){
  869. global $wpdb;
  870. if(!is_search()) return $groupby;
  871.  
  872. // we need to group on post ID
  873. $mygroupby = "{$wpdb->posts}.ID";
  874. if(preg_match("/$mygroupby/", $groupby)) return $groupby; // grouping we need is already there
  875. if(!strlen(trim($groupby))) return $mygroupby; // groupby was empty, use ours
  876.  
  877. // wasn't empty, append ours
  878. return $groupby . ", " . $mygroupby;
  879. }
  880.  
  881. function mystique_timeSince($older_date, $newer_date = false){
  882. $chunks = array(
  883. 'year' => 60 * 60 * 24 * 365, // 31,536,000 seconds
  884. 'month' => 60 * 60 * 24 * 30, // 2,592,000 seconds
  885. 'week' => 60 * 60 * 24 * 7, // 604,800 seconds
  886. 'day' => 60 * 60 * 24, // 86,400 seconds
  887. 'hour' => 60 * 60, // 3600 seconds
  888. 'minute' => 60, // 60 seconds
  889. 'second' => 1 // 1 second
  890. );
  891.  
  892. $newer_date = ($newer_date == false) ? (time()+(60*60*get_settings("gmt_offset"))) : $newer_date;
  893. $since = $newer_date - $older_date;
  894.  
  895. foreach ($chunks as $key => $seconds)
  896. if (($count = floor($since / $seconds)) != 0) break;
  897.  
  898. $messages = array(
  899. 'year' => _n('about %s year ago', 'about %s years ago', $count, 'mystique'),
  900. 'month' => _n('about %s month ago', 'about %s months ago', $count, 'mystique'),
  901. 'week' => _n('about %s week ago', 'about %s weeks ago', $count, 'mystique'),
  902. 'day' => _n('about %s day ago', 'about %s days ago', $count, 'mystique'),
  903. 'hour' => _n('about %s hour ago', 'about %s hours ago', $count, 'mystique'),
  904. 'minute' => _n('about %s minute ago', 'about %s minutes ago', $count, 'mystique'),
  905. 'second' => _n('about %s second ago', 'about %s seconds ago', $count, 'mystique'),
  906. );
  907. return sprintf($messages[$key],$count);
  908. }
  909.  
  910. // returns the layout type that the current page has
  911. function mystique_layout_type(){
  912. $layout = get_mystique_option('layout');
  913.  
  914. // override if layout page templates are used
  915. if(is_page_template('page-col-1.php')) $layout = 'col-1';
  916. if(is_page_template('page-col-2-left.php')) $layout = 'col-2-left';
  917. if(is_page_template('page-col-2-right.php')) $layout = 'col-2-right';
  918. if(is_page_template('page-col-3.php')) $layout = 'col-3';
  919. if(is_page_template('page-col-3-left.php')) $layout = 'col-3-left';
  920. if(is_page_template('page-col-3-right.php')) $layout = 'col-3-right';
  921.  
  922. // override again if 'layout' custom field is present
  923. if (is_single() || is_page()):
  924. global $post;
  925. $lcf = get_post_meta($post->ID, 'layout', true);
  926. if($lcf) $layout = $lcf;
  927. endif;
  928.  
  929. return $layout;
  930. }
  931.  
  932. // Generates semantic classes for BODY element - based on the sandbox theme
  933. function mystique_body_class($class = '') {
  934. global $wp_query, $current_user, $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
  935.  
  936. // Generic semantic classes for what type of content is displayed
  937. is_front_page() ? $classes[] = 'home' : null; // For the front page, if set
  938. is_home() ? $classes[] = 'blog' : null; // For the blog posts page, if set
  939. is_archive() ? $classes[] = 'archive' : null;
  940. is_date() ? $classes[] = 'date' : null;
  941. is_search() ? $classes[] = 'search' : null;
  942. is_attachment() ? $classes[] = 'attachment' : null;
  943. is_404() ? $classes[] = 'not-found' : null; // CSS does not allow a digit as first character
  944.  
  945. // Special classes for BODY element when a single post
  946. if (is_single()):
  947. $postname = $wp_query->post->post_name;
  948.  
  949. the_post();
  950.  
  951. // Adds 'single' class and class with the post ID
  952. $classes[] = 'single-post title-' . $postname;
  953.  
  954. // Adds category classes for each category on single posts
  955. if ($cats = get_the_category()) foreach ($cats as $cat) $classes[] = 'category-'.$cat->slug;
  956.  
  957. // Adds tag classes for each tags on single posts
  958. if ($tags = get_the_tags()) foreach ($tags as $tag) $classes[] = 'tag-'.$tag->slug;
  959.  
  960. // Adds author class for the post author
  961. $classes[] = 'author-' . sanitize_title_with_dashes(strtolower(get_the_author_meta('login')));
  962. rewind_posts();
  963.  
  964. elseif (is_author()): // Author name classes for BODY on author archives
  965. $author = $wp_query->get_queried_object();
  966. $classes[] = 'author';
  967. $classes[] = 'author-' . $author->user_nicename;
  968.  
  969. elseif (is_category()): // Category name classes for BODY on category archvies
  970. $cat = $wp_query->get_queried_object();
  971. $classes[] = 'category';
  972. $classes[] = 'category-' . $cat->slug;
  973.  
  974. elseif (is_tag()): // Tag name classes for BODY on tag archives
  975. $tags = $wp_query->get_queried_object();
  976. $classes[] = 'tag';
  977. $classes[] = 'tag-' . $tags->slug;
  978.  
  979. elseif (is_page()): // Page author for BODY on 'pages'
  980. $pagename = $wp_query->post->post_name;
  981. $pageID = $wp_query->post->ID;
  982. $page_children = wp_list_pages("child_of=$pageID&echo=0");
  983. the_post();
  984. $classes[] = 'single-page page-' . $pagename;
  985. $classes[] = 'author-' . sanitize_title_with_dashes(strtolower(get_the_author('login')));
  986. // Checks to see if the page has children and/or is a child page; props to Adam
  987. if ($page_children) $classes[] = 'level-parent';
  988. if ($wp_query->post->post_parent) $classes[] = 'level-child';
  989. rewind_posts();
  990.  
  991. elseif (is_search()): // Search classes for results or no results
  992. the_post();
  993. if (have_posts()) $classes[] = 'search-results'; else $classes[] = 'search-no-results';
  994. rewind_posts();
  995. endif;
  996.  
  997. // layout type
  998. $classes[] = mystique_layout_type();
  999.  
  1000. $classes[] = get_mystique_option('page_width');
  1001.  
  1002. // For when a visitor is logged in while browsing
  1003. if ($current_user->ID) $classes[] = 'loggedin';
  1004.  
  1005. // detect browser
  1006. if($is_lynx) $browser = 'lynx';
  1007. elseif($is_gecko) $browser = 'gecko';
  1008. elseif($is_opera) $browser = 'opera';
  1009. elseif($is_NS4) $browser = 'ns4';
  1010. elseif($is_safari) $browser = 'safari';
  1011. elseif($is_chrome) $browser = 'chrome';
  1012. elseif($is_IE) $browser = 'ie';
  1013. else $browser = 'unknown';
  1014. if($is_iphone) $browser .= '-iphone';
  1015.  
  1016. $classes[] = 'browser-'.$browser;
  1017.  
  1018. // user classes
  1019. if (!empty($class)):
  1020. if (!is_array($class)) $class = preg_split('#\s+#', $class);
  1021. $classes = array_merge($classes, $class);
  1022. endif;
  1023.  
  1024. $class = join(' ', apply_filters('body_class', $classes));
  1025.  
  1026. echo $class;
  1027. }
  1028.  
  1029. function mystique_post_class($class = '') {
  1030. global $post;
  1031. static $post_alt;
  1032.  
  1033. // add hentry for microformats compliance and the post type
  1034. $classes = array('hentry', $post->post_type);
  1035.  
  1036. // post alt
  1037. $classes[] = 'post-' . ++$post_alt;
  1038. $classes[] = ($post_alt % 2) ? 'odd' : 'even alt';
  1039.  
  1040. // author
  1041. $classes[] = 'author-'.sanitize_html_class(get_the_author_meta('user_nicename'), get_the_author_meta('ID'));
  1042.  
  1043. if(!is_single() && get_post_meta($post->ID, 'asides', true)) $classes[] = 'asides'; // asides
  1044. elseif (is_home() && is_sticky()) $classes[] = 'sticky'; // sticky (only on home/blog page)
  1045.  
  1046. // password-protected?
  1047. if (post_password_required()) $classes[] = 'protected';
  1048.  
  1049. // post category & tags */
  1050. if ('post' == $post->post_type)
  1051. foreach (array('category', 'post_tag') as $tax)
  1052. foreach ((array)get_the_terms($post->ID, $tax) as $term)
  1053. if (!empty($term->slug)) $classes[] = $tax . '-' . sanitize_html_class($term->slug, $term->term_id);
  1054.  
  1055. // user classes
  1056. if (!empty($class)):
  1057. if (!is_array($class)) $class = preg_split('#\s+#', $class);
  1058. $classes = array_merge($classes, $class);
  1059. endif;
  1060.  
  1061. // join all and output them
  1062. $class = join(' ', $classes);
  1063. echo apply_filters("mystique_post_class", $class);
  1064. }
  1065.  
  1066. function escape_string_for_regex($str){
  1067. //All regex special chars (according to arkani at iol dot pt below):
  1068. // \ ^ . $ | ( ) [ ]
  1069. // * + ? { } ,
  1070. $patterns = array('/\//', '/\^/', '/\./', '/\$/', '/\|/',
  1071. '/\(/', '/\)/', '/\[/', '/\]/', '/\*/', '/\+/',
  1072. '/\?/', '/\{/', '/\}/', '/\,/');
  1073. $replace = array('\/', '\^', '\.', '\$', '\|', '\(', '\)',
  1074. '\[', '\]', '\*', '\+', '\?', '\{', '\}', '\,');
  1075. return preg_replace($patterns,$replace, $str);
  1076. }
  1077.  
  1078. function get_first_image($post) {
  1079. $first_img = '';
  1080. $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  1081. $first_img = $matches [1][0];
  1082. return $first_img;
  1083. }
  1084.  
  1085. // check if sidebar has widgets
  1086. function is_sidebar_active($index = 1) {
  1087. global $wp_registered_sidebars;
  1088.  
  1089. if (is_int($index)): $index = "sidebar-$index";
  1090. else :
  1091. $index = sanitize_title($index);
  1092. foreach ((array) $wp_registered_sidebars as $key => $value):
  1093. if (sanitize_title($value['name']) == $index):
  1094. $index = $key;
  1095. break;
  1096. endif;
  1097. endforeach;
  1098. endif;
  1099. $sidebars_widgets = wp_get_sidebars_widgets();
  1100. if (empty($wp_registered_sidebars[$index]) || !array_key_exists($index, $sidebars_widgets) || !is_array($sidebars_widgets[$index]) || empty($sidebars_widgets[$index]))
  1101. return false;
  1102. else
  1103. return true;
  1104. }
  1105.  
  1106. function mystique_curPageURL() {
  1107. $request = esc_url($_SERVER["REQUEST_URI"]);
  1108.  
  1109. // wp-themes fake request url fix :)
  1110. if (strpos($_SERVER["SERVER_NAME"], 'wp-themes.com') !== false) $request = str_replace($request, '/wordpress/', '/');
  1111.  
  1112. $pageURL = (is_ssl() ? 'https' : 'http').'://';
  1113. if ($_SERVER["SERVER_PORT"] != "80") $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$request; else $pageURL .= $_SERVER["SERVER_NAME"].$request;
  1114.  
  1115. if (false === strpos(get_option('home'), '://www.')) $pageURL = str_replace('://www.', '://', $pageURL);
  1116. if (false !== strpos(get_option('home'), '://www.') && false === strpos($pageURL, '://www.')) $pageURL = str_replace('://', '://www.', $pageURL);
  1117.  
  1118. return $pageURL;
  1119. }
  1120.  
  1121. // experimental
  1122. function mystique_compress_html(){
  1123. function remove_spaces($buffer){
  1124. $search = array('/\>[^\S ]+/s','/[^\S ]+\</s','/(\s)+/s');
  1125. $replace = array('>','<','\\1');
  1126. $buffer = preg_replace($search, $replace, $buffer);
  1127. return $buffer;
  1128. }
  1129. if(!@ob_start("ob_gzhandler")) ob_start('remove_spaces');
  1130. }
  1131.  
  1132. function mystique_meta_description() {
  1133. global $wp_query;
  1134. if (is_home()): $description = get_bloginfo('description');
  1135. elseif (is_singular()):
  1136. if(function_exists('get_metadata')): $description = get_metadata('post', $wp_query->post->ID, 'description', true); endif;
  1137. if (empty($description) && is_front_page()):
  1138. $description = get_bloginfo('description');
  1139. elseif (empty($description)):
  1140. $description = get_post_field('post_excerpt', $wp_query->post->ID);
  1141. endif;
  1142. elseif (is_archive()):
  1143. if (is_author()):
  1144. $description = get_the_author_meta('description', get_query_var('author'));
  1145. elseif (is_category() || is_tag() || is_tax()):
  1146. $description = term_description('', get_query_var('taxonomy'));
  1147. endif;
  1148. endif;
  1149.  
  1150. if (!empty($description) && get_mystique_option('seo')) echo '<meta name="description" content="'.str_replace(array("\r", "\n", "\t"),'',esc_attr(strip_tags($description))).'" />'."\n";
  1151. }
  1152.  
  1153. function mystique_comment_class($class = '') {
  1154. global $post, $comment;
  1155. $classes = get_comment_class();
  1156. if (get_option('show_avatars')) $classes[] = 'withAvatars';
  1157.  
  1158. if ($comment->user_id > 0):
  1159. $user = new WP_User($comment->user_id);
  1160. if (is_array($user->roles))
  1161. foreach ($user->roles as $role) $classes[] = "role-{$role}";
  1162. $classes[] = 'user-'.sanitize_html_class($user->user_nicename, $user->user_id);
  1163. else:
  1164. $classes[] = 'reader name-'.get_comment_author();
  1165. endif;
  1166.  
  1167. // user classes
  1168. if (!empty($class)):
  1169. if (!is_array($class)) $class = preg_split('#\s+#', $class);
  1170. $classes = array_merge($classes, $class);
  1171. endif;
  1172.  
  1173. echo join(' ', apply_filters("comment_class", $classes));
  1174. }
  1175.  
  1176. function mystique_get_page_by_slug($page_slug) {
  1177. $page = get_page_by_path($page_slug);
  1178. if ($page) return get_permalink($page->ID); else return false;
  1179. }
  1180.  
  1181. function mystique_get_avatar($email, $size = 48){
  1182. if(date('m-d') == '04-01') return '<img class="avatar" src="http://unicornify.appspot.com/avatar/'.md5($email).'?s='.$size.'" alt="one trick pony" width="'.$size.'" height="'.$size.'" />'; // 1st april? :)
  1183. else return get_avatar($email, $size);
  1184. }
  1185.  
  1186. // list pings
  1187. function mystique_list_pings($comment, $args, $depth) {
  1188. $GLOBALS['comment'] = $comment;
  1189. ?>
  1190. <li class="ping" id="comment-<?php comment_ID(); ?>"><a>" rel="nofollow"><?php comment_author(); ?></a>
  1191. <?php
  1192. } // is added by WP
  1193.  
  1194. // list comments
  1195. function mystique_list_comments($comment, $args, $depth) {
  1196. $GLOBALS['comment'] = $comment;
  1197. global $commentcount;
  1198.  
  1199. if(!$commentcount) $commentcount = 0; ?>
  1200.  
  1201. <!-- comment entry -->
  1202. <li class="<?php mystique_comment_class(); ?>" id="comment-<?php comment_ID() ?>">
  1203. <div class="comment-head <?php mystique_comment_class(); ?>">
  1204.  
  1205. <?php if(get_option('show_avatars')): ?><div class="avatar-box"><?php echo mystique_get_avatar($comment->comment_author_email, 48); ?></div><?php endif; ?>
  1206. <div class="author">
  1207. <?php
  1208. if (get_comment_author_url()) $authorlink='<a href="'.get_comment_author_url().'" rel="nofollow">'.get_comment_author().'</a>';
  1209. else $authorlink='<b class="comment-author" id="comment-author-'.get_comment_ID().'">'.get_comment_author().'</b>';
  1210.  
  1211. $authorlink = apply_filters("mystique_comment_author_link", $authorlink); ?>
  1212.  
  1213. <span class="by"><?php printf(__('%1$s written by %2$s', 'mystique'), '<a href="#comment-'.get_comment_ID().'">#'.++$commentcount.'</a>', $authorlink); ?> </span>
  1214.  
  1215. <?php echo mystique_timeSince(abs(strtotime($comment->comment_date . " GMT"))); ?>
  1216. </div>
  1217.  
  1218. <div class="controls bubble">
  1219. <?php if (get_mystique_option('jquery') && (comments_open())): ?>
  1220. <?php if(get_option('thread_comments')): ?>
  1221. <a>" href="<?php echo esc_url(add_query_arg('replytocom', $comment->comment_ID)); ?>#respond"><?php _e("Reply","mystique"); ?></a>
  1222. <?php endif; ?>
  1223. <a>" href="#respond"><?php _e('Quote','mystique'); ?></a>
  1224. <?php endif; ?>
  1225. <?php edit_comment_link('Edit','',''); ?>
  1226. </div>
  1227. </div>
  1228. <div class="comment-body clear-block" id="comment-body-<?php comment_ID() ?>">
  1229. <?php if ($comment->comment_approved == '0'): ?><p class="error"><?php _e('Your comment is awaiting moderation.','mystique'); ?></p><?php endif; ?>
  1230. <div class="comment-text"><?php comment_text(); ?></div>
  1231. <a>"></a>
  1232. </div>
  1233. <?php
  1234. } // is added by WP
  1235. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement