Advertisement
Guest User

Untitled

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