PageRenderTime 15ms CodeModel.GetById 2ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

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

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