PageRenderTime 2ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/Web/wp-content/themes/responsive/includes/functions.php

https://bitbucket.org/jimjenkins5/blog
PHP | 557 lines | 334 code | 97 blank | 126 comment | 49 complexity | 7b970092368d8df2c7780df129bd19b4 MD5 | raw file
  1<?php
  2
  3// Exit if accessed directly
  4if ( !defined('ABSPATH')) exit;
  5
  6/**
  7 * Theme's Functions and Definitions
  8 *
  9 *
 10 * @file           functions.php
 11 * @package        Responsive 
 12 * @author         Emil Uzelac 
 13 * @copyright      2003 - 2012 ThemeID
 14 * @license        license.txt
 15 * @version        Release: 1.1.1
 16 * @filesource     wp-content/themes/responsive/includes/functions.php
 17 * @link           http://codex.wordpress.org/Theme_Development#Functions_File
 18 * @since          available since Release 1.0
 19 */
 20?>
 21<?php
 22/**
 23 * Fire up the engines boys and girls let's start theme setup.
 24 */
 25add_action('after_setup_theme', 'responsive_setup');
 26
 27if (!function_exists('responsive_setup')):
 28
 29    function responsive_setup() {
 30
 31        global $content_width;
 32
 33        /**
 34         * Global content width.
 35         */
 36        if (!isset($content_width))
 37            $content_width = 550;
 38
 39        /**
 40         * Responsive is now available for translations.
 41         * Add your files into /languages/ directory.
 42		 * @see http://codex.wordpress.org/Function_Reference/load_theme_textdomain
 43         */
 44	    load_theme_textdomain('responsive', get_template_directory().'/languages');
 45
 46            $locale = get_locale();
 47            $locale_file = get_template_directory().'/languages/$locale.php';
 48            if (is_readable( $locale_file))
 49	            require_once( $locale_file);
 50						
 51        /**
 52         * Add callback for custom TinyMCE editor stylesheets. (editor-style.css)
 53         * @see http://codex.wordpress.org/Function_Reference/add_editor_style
 54         */
 55        add_editor_style();
 56
 57        /**
 58         * This feature enables post and comment RSS feed links to head.
 59         * @see http://codex.wordpress.org/Function_Reference/add_theme_support#Feed_Links
 60         */
 61        add_theme_support('automatic-feed-links');
 62
 63        /**
 64         * This feature enables post-thumbnail support for a theme.
 65         * @see http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
 66         */
 67        add_theme_support('post-thumbnails');
 68
 69        /**
 70         * This feature enables custom-menus support for a theme.
 71         * @see http://codex.wordpress.org/Function_Reference/register_nav_menus
 72         */	
 73        register_nav_menus(array(
 74			'top-menu'         => __('Top Menu', 'responsive'),
 75	        'header-menu'      => __('Header Menu', 'responsive'),
 76	        'sub-header-menu'  => __('Sub-Header Menu', 'responsive'),
 77			'footer-menu'      => __('Footer Menu', 'responsive')
 78		    )
 79	    );
 80
 81		if ( function_exists('get_custom_header')) {
 82			
 83        add_theme_support('custom-background');
 84		
 85		} else {
 86		
 87		// < 3.4 Backward Compatibility
 88		
 89		/**
 90         * This feature allows users to use custom background for a theme.
 91         * @see http://codex.wordpress.org/Function_Reference/add_custom_background
 92         */
 93		
 94        add_custom_background();
 95		
 96		}
 97
 98		// WordPress 3.4 >
 99		if (function_exists('get_custom_header')) {
100			
101		add_theme_support('custom-header', array (
102	        // Header image default
103	       'default-image'			=> get_template_directory_uri() . '/images/default-logo.png',
104	        // Header text display default
105	       'header-text'			=> false,
106	        // Header image flex width
107		   'flex-width'             => true,
108	        // Header image width (in pixels)
109	       'width'				    => 300,
110		    // Header image flex height
111		   'flex-height'            => true,
112	        // Header image height (in pixels)
113	       'height'			        => 100,
114	        // Admin header style callback
115	       'admin-head-callback'	=> 'responsive_admin_header_style'));
116		   
117		// gets included in the admin header
118        function responsive_admin_header_style() {
119            ?><style type="text/css">
120                .appearance_page_custom-header #headimg {
121					background-repeat:no-repeat;
122					border:none;
123				}
124             </style><?php
125        }		  
126	   
127	    } else {
128		   
129        // Backward Compatibility
130		
131		/**
132         * This feature adds a callbacks for image header display.
133		 * In our case we are using this to display logo.
134         * @see http://codex.wordpress.org/Function_Reference/add_custom_image_header
135         */
136        define('HEADER_TEXTCOLOR', '');
137        define('HEADER_IMAGE', '%s/images/default-logo.png'); // %s is the template dir uri
138        define('HEADER_IMAGE_WIDTH', 300); // use width and height appropriate for your theme
139        define('HEADER_IMAGE_HEIGHT', 100);
140        define('NO_HEADER_TEXT', true);
141		
142		
143		// gets included in the admin header
144        function responsive_admin_header_style() {
145            ?><style type="text/css">
146                #headimg {
147	                background-repeat:no-repeat;
148                    border:none !important;
149                    width:<?php echo HEADER_IMAGE_WIDTH; ?>px;
150                    height:<?php echo HEADER_IMAGE_HEIGHT; ?>px;
151                }
152             </style><?php
153         }
154         
155		 add_custom_image_header('', 'responsive_admin_header_style');
156		
157	    }
158    }
159
160endif;
161
162/**
163 * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
164 */
165function responsive_page_menu_args( $args ) {
166	$args['show_home'] = true;
167	return $args;
168}
169add_filter( 'wp_page_menu_args', 'responsive_page_menu_args' );
170
171/**
172 * Remove div from wp_page_menu() and replace with ul.
173 */
174function responsive_wp_page_menu ($page_markup) {
175    preg_match('/^<div class=\"([a-z0-9-_]+)\">/i', $page_markup, $matches);
176        $divclass = $matches[1];
177        $replace = array('<div class="'.$divclass.'">', '</div>');
178        $new_markup = str_replace($replace, '', $page_markup);
179        $new_markup = preg_replace('/^<ul>/i', '<ul class="'.$divclass.'">', $new_markup);
180        return $new_markup; }
181
182add_filter('wp_page_menu', 'responsive_wp_page_menu');
183
184/**
185 * Filter 'get_comments_number'
186 * 
187 * Filter 'get_comments_number' to display correct 
188 * number of comments (count only comments, not 
189 * trackbacks/pingbacks)
190 *
191 * Courtesy of Chip Bennett
192 */
193function responsive_comment_count( $count ) {  
194	if ( ! is_admin() ) {
195		global $id;
196		$comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));
197		return count($comments_by_type['comment']);
198	} else {
199		return $count;
200	}
201}
202add_filter('get_comments_number', 'responsive_comment_count', 0);
203
204/**
205 * wp_list_comments() Pings Callback
206 * 
207 * wp_list_comments() Callback function for 
208 * Pings (Trackbacks/Pingbacks)
209 */
210function responsive_comment_list_pings( $comment ) {
211	$GLOBALS['comment'] = $comment;
212?>
213	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"><?php echo comment_author_link(); ?></li>
214<?php }
215
216/**
217 * Sets the post excerpt length to 40 words.
218 * Next few lines are adopted from Coraline
219 */
220function responsive_excerpt_length($length) {
221    return 40;
222}
223
224add_filter('excerpt_length', 'responsive_excerpt_length');
225
226/**
227 * Returns a "Read more" link for excerpts
228 */
229function responsive_read_more() {
230    return '<div class="read-more"><a href="' . get_permalink() . '">' . __('Read more &#8250;', 'responsive') . '</a></div><!-- end of .read-more -->';
231}
232
233/**
234 * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and responsive_read_more_link().
235 */
236function responsive_auto_excerpt_more($more) {
237    return '<span class="ellipsis">&hellip;</span>' . responsive_read_more();
238}
239
240add_filter('excerpt_more', 'responsive_auto_excerpt_more');
241
242/**
243 * Adds a pretty "Read more" link to custom post excerpts.
244 */
245function responsive_custom_excerpt_more($output) {
246    if (has_excerpt() && !is_attachment()) {
247        $output .= responsive_read_more();
248    }
249    return $output;
250}
251
252add_filter('get_the_excerpt', 'responsive_custom_excerpt_more');
253
254
255/**
256 * This function removes inline styles set by WordPress gallery.
257 */
258function responsive_remove_gallery_css($css) {
259    return preg_replace("#<style type='text/css'>(.*?)</style>#s", '', $css);
260}
261
262add_filter('gallery_style', 'responsive_remove_gallery_css');
263
264
265/**
266 * This function removes default styles set by WordPress recent comments widget.
267 */
268function responsive_remove_recent_comments_style() {
269	global $wp_widget_factory;
270	remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
271}
272add_action( 'widgets_init', 'responsive_remove_recent_comments_style' );
273
274
275/**
276 * Breadcrumb Lists
277 * Allows visitors to quickly navigate back to a previous section or the root page.
278 *
279 * Courtesy of Dimox
280 *
281 * bbPress compatibility patch by Dan Smith
282 */
283function responsive_breadcrumb_lists () {
284  
285  $chevron = '<span class="chevron">&#8250;</span>';
286  $home = __('Home','responsive'); // text for the 'Home' link
287  $before = '<span class="breadcrumb-current">'; // tag before the current crumb
288  $after = '</span>'; // tag after the current crumb
289 
290  if ( !is_home() && !is_front_page() || is_paged() ) {
291 
292    echo '<div class="breadcrumb-list">';
293 
294    global $post;
295    $homeLink = home_url();
296    echo '<a href="' . $homeLink . '">' . $home . '</a> ' . $chevron . ' ';
297 
298    if ( is_category() ) {
299      global $wp_query;
300      $cat_obj = $wp_query->get_queried_object();
301      $thisCat = $cat_obj->term_id;
302      $thisCat = get_category($thisCat);
303      $parentCat = get_category($thisCat->parent);
304      if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $chevron . ' '));
305      echo $before . __('Archive for ','responsive') . single_cat_title('', false) . $after;
306 
307    } elseif ( is_day() ) {
308      echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $chevron . ' ';
309      echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $chevron . ' ';
310      echo $before . get_the_time('d') . $after;
311 
312    } elseif ( is_month() ) {
313      echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $chevron . ' ';
314      echo $before . get_the_time('F') . $after;
315 
316    } elseif ( is_year() ) {
317      echo $before . get_the_time('Y') . $after;
318 
319    } elseif ( is_single() && !is_attachment() ) {
320      if ( get_post_type() != 'post' ) {
321        $post_type = get_post_type_object(get_post_type());
322        $slug = $post_type->rewrite;
323        echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> ' . $chevron . ' ';
324        echo $before . get_the_title() . $after;
325      } else {
326        $cat = get_the_category(); $cat = $cat[0];
327        echo get_category_parents($cat, TRUE, ' ' . $chevron . ' ');
328        echo $before . get_the_title() . $after;
329      }
330 
331    } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
332      $post_type = get_post_type_object(get_post_type());
333      echo $before . $post_type->labels->singular_name . $after;
334 
335    } elseif ( is_attachment() ) {
336      $parent = get_post($post->post_parent);
337      $cat = get_the_category($parent->ID); $cat = $cat[0];
338      echo get_category_parents($cat, TRUE, ' ' . $chevron . ' ');
339      echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $chevron . ' ';
340      echo $before . get_the_title() . $after;
341 
342    } elseif ( is_page() && !$post->post_parent ) {
343      echo $before . get_the_title() . $after;
344 
345    } elseif ( is_page() && $post->post_parent ) {
346      $parent_id  = $post->post_parent;
347      $breadcrumbs = array();
348      while ($parent_id) {
349        $page = get_page($parent_id);
350        $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
351        $parent_id  = $page->post_parent;
352      }
353      $breadcrumbs = array_reverse($breadcrumbs);
354      foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $chevron . ' ';
355      echo $before . get_the_title() . $after;
356 
357    } elseif ( is_search() ) {
358      echo $before . __('Search results for ','responsive') . get_search_query() . $after;
359 
360    } elseif ( is_tag() ) {
361      echo $before . __('Posts tagged ','responsive') . single_tag_title('', false) . $after;
362 
363    } elseif ( is_author() ) {
364       global $author;
365      $userdata = get_userdata($author);
366      echo $before . __('All posts by ','responsive') . $userdata->display_name . $after;
367 
368    } elseif ( is_404() ) {
369      echo $before . __('Error 404 ','responsive') . $after;
370    }
371 
372    if ( get_query_var('paged') ) {
373      if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
374      echo __('Page','responsive') . ' ' . get_query_var('paged');
375      if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
376    }
377 
378    echo '</div>';
379 
380  }
381} 
382
383
384    /**
385     * A safe way of adding JavaScripts to a WordPress generated page.
386     */
387    if (!is_admin())
388        add_action('wp_enqueue_scripts', 'responsive_js');
389
390    if (!function_exists('responsive_js')) {
391
392        function responsive_js() {
393			// JS at the bottom for fast page loading. 
394			// except for Modernizr which enables HTML5 elements & feature detects.
395			wp_enqueue_script('modernizr', get_template_directory_uri() . '/js/responsive-modernizr.js', array('jquery'), '2.6.1', false);
396            wp_enqueue_script('responsive-scripts', get_template_directory_uri() . '/js/responsive-scripts.js', array('jquery'), '1.2.1', true);
397			wp_enqueue_script('responsive-plugins', get_template_directory_uri() . '/js/responsive-plugins.js', array('jquery'), '1.1.1', true);
398        }
399
400    }
401
402    /**
403     * A comment reply.
404     */
405        function responsive_enqueue_comment_reply() {
406    if ( is_singular() && comments_open() && get_option('thread_comments')) { 
407            wp_enqueue_script('comment-reply'); 
408        }
409    }
410
411    add_action( 'wp_enqueue_scripts', 'responsive_enqueue_comment_reply' );
412
413    /**
414     * Theme Options Support and Information
415     */	
416    function responsive_theme_support () {
417    ?>
418    
419    <div id="info-box-wrapper" class="grid col-940">
420        <div class="info-box notice">
421            <a class="blue button" href="<?php echo esc_url(__('http://themeid.com/support/','responsive')); ?>" title="<?php esc_attr_e('Theme Support', 'responsive'); ?>" target="_blank">
422            <?php printf(__('Theme Support','responsive')); ?></a>
423            
424            <a class="gray button" href="<?php echo esc_url(__('http://themeid.com/themes/','responsive')); ?>" title="<?php esc_attr_e('More Themes', 'responsive'); ?>" target="_blank">
425            <?php printf(__('More Themes','responsive')); ?></a>
426            
427            <a class="gray button" href="<?php echo esc_url(__('http://themeid.com/showcase/','responsive')); ?>" title="<?php esc_attr_e('Showcase', 'responsive'); ?>" target="_blank">
428            <?php printf(__('Showcase','responsive')); ?></a>
429            
430            <a class="gold button" href="<?php echo esc_url(__('http://themeid.com/donate/','responsive')); ?>" title="<?php esc_attr_e('Donate Now', 'responsive'); ?>" target="_blank">
431            <?php printf(__('Donate Now','responsive')); ?></a>
432        </div>
433    </div>
434
435    <?php }
436 
437    add_action('responsive_theme_options','responsive_theme_support');
438
439	 
440    /**
441     * WordPress Widgets start right here.
442     */
443    function responsive_widgets_init() {
444
445        register_sidebar(array(
446            'name' => __('Main Sidebar', 'responsive'),
447            'description' => __('Area One - sidebar.php', 'responsive'),
448            'id' => 'main-sidebar',
449            'before_title' => '<div class="widget-title">',
450            'after_title' => '</div>',
451            'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
452            'after_widget' => '</div>'
453        ));
454
455        register_sidebar(array(
456            'name' => __('Right Sidebar', 'responsive'),
457            'description' => __('Area Two - sidebar-right.php', 'responsive'),
458            'id' => 'right-sidebar',
459            'before_title' => '<div class="widget-title">',
460            'after_title' => '</div>',
461            'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
462            'after_widget' => '</div>'
463        ));
464				
465        register_sidebar(array(
466            'name' => __('Left Sidebar', 'responsive'),
467            'description' => __('Area Three - sidebar-left.php', 'responsive'),
468            'id' => 'left-sidebar',
469            'before_title' => '<div class="widget-title">',
470            'after_title' => '</div>',
471            'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
472            'after_widget' => '</div>'
473        ));
474		
475        register_sidebar(array(
476            'name' => __('Left Sidebar Half Page', 'responsive'),
477            'description' => __('Area Four - sidebar-left-half.php', 'responsive'),
478            'id' => 'left-sidebar-half',
479            'before_title' => '<div class="widget-title">',
480            'after_title' => '</div>',
481            'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
482            'after_widget' => '</div>'
483        ));
484		
485        register_sidebar(array(
486            'name' => __('Right Sidebar Half Page', 'responsive'),
487            'description' => __('Area Five - sidebar-right-half.php', 'responsive'),
488            'id' => 'right-sidebar-half',
489            'before_title' => '<div class="widget-title">',
490            'after_title' => '</div>',
491            'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
492            'after_widget' => '</div>'
493        ));
494
495        register_sidebar(array(
496            'name' => __('Home Widget 1', 'responsive'),
497            'description' => __('Area Six - sidebar-home.php', 'responsive'),
498            'id' => 'home-widget-1',
499            'before_title' => '<div id="widget-title-one" class="widget-title-home"><h3>',
500            'after_title' => '</h3></div>',
501            'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
502            'after_widget' => '</div>'
503        ));
504
505        register_sidebar(array(
506            'name' => __('Home Widget 2', 'responsive'),
507            'description' => __('Area Seven - sidebar-home.php', 'responsive'),
508            'id' => 'home-widget-2',
509            'before_title' => '<div id="widget-title-two" class="widget-title-home"><h3>',
510            'after_title' => '</h3></div>',
511            'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
512            'after_widget' => '</div>'
513        ));
514
515        register_sidebar(array(
516            'name' => __('Home Widget 3', 'responsive'),
517            'description' => __('Area Eight - sidebar-home.php', 'responsive'),
518            'id' => 'home-widget-3',
519            'before_title' => '<div id="widget-title-three" class="widget-title-home"><h3>',
520            'after_title' => '</h3></div>',
521            'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
522            'after_widget' => '</div>'
523        ));
524
525        register_sidebar(array(
526            'name' => __('Gallery Sidebar', 'responsive'),
527            'description' => __('Area Nine - sidebar-gallery.php', 'responsive'),
528            'id' => 'gallery-widget',
529            'before_title' => '<div class="widget-title">',
530            'after_title' => '</div>',
531            'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
532            'after_widget' => '</div>'
533        ));
534		
535        register_sidebar(array(
536            'name' => __('Colophon Widget', 'responsive'),
537            'description' => __('Area Ten - sidebar-colophon.php', 'responsive'),
538            'id' => 'colophon-widget',
539            'before_title' => '<div class="widget-title">',
540            'after_title' => '</div>',
541            'before_widget' => '<div id="%1$s" class="colophon-widget widget-wrapper %2$s">',
542            'after_widget' => '</div>'
543        ));
544		
545        register_sidebar(array(
546            'name' => __('Top Widget', 'responsive'),
547            'description' => __('Area Twelve - sidebar-top.php', 'responsive'),
548            'id' => 'top-widget',
549            'before_title' => '<div class="widget-title">',
550            'after_title' => '</div>',
551            'before_widget' => '<div id="%1$s" class="%2$s">',
552            'after_widget' => '</div>'
553        ));
554    }
555	
556    add_action('widgets_init', 'responsive_widgets_init');
557?>