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

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

https://github.com/bfay/maniacal-kitten
PHP | 480 lines | 317 code | 64 blank | 99 comment | 37 complexity | 414b3ec83070868ddc5c99a6d54d0246 MD5 | raw file
  1<?php
  2/**
  3 * Theme's Functions and Definitions
  4 *
  5 *
  6 * @file           functions.php
  7 * @package        StrapPress 
  8 * @author         Brad Williams 
  9 * @copyright      2011 - 2012 Brag Interactive
 10 * @license        license.txt
 11 * @version        Release: 2.3.0
 12 * @filesource     wp-content/themes/responsive/includes/functions.php
 13 * @link           http://codex.wordpress.org/Theme_Development#Functions_File
 14 * @since          available since Release 1.0
 15 */
 16?>
 17<?php
 18/**
 19 * Fire up the engines boys and girls let's start theme setup.
 20 */
 21add_action('after_setup_theme', 'responsive_setup');
 22
 23if (!function_exists('responsive_setup')):
 24
 25    function responsive_setup() {
 26
 27        global $content_width;
 28
 29        /**
 30         * Global content width.
 31         */
 32        if (!isset($content_width))
 33            $content_width = 550;
 34
 35        /**
 36         * Responsive is now available for translations.
 37         * Add your files into /languages/ directory.
 38		 * @see http://codex.wordpress.org/Function_Reference/load_theme_textdomain
 39         */
 40	    load_theme_textdomain('responsive', get_template_directory().'/languages');
 41
 42            $locale = get_locale();
 43            $locale_file = get_template_directory().'/languages/$locale.php';
 44            if (is_readable( $locale_file))
 45	            require_once( $locale_file);
 46						
 47        /**
 48         * Add callback for custom TinyMCE editor stylesheets. (editor-style.css)
 49         * @see http://codex.wordpress.org/Function_Reference/add_editor_style
 50         */
 51        add_editor_style();
 52
 53        /**
 54         * This feature enables post and comment RSS feed links to head.
 55         * @see http://codex.wordpress.org/Function_Reference/add_theme_support#Feed_Links
 56         */
 57        add_theme_support('automatic-feed-links');
 58
 59        /**
 60         * This feature enables post-thumbnail support for a theme.
 61         * @see http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
 62         */
 63
 64        add_theme_support('post-thumbnails');
 65        add_image_size( 'port-thumb', 250, 200 );
 66        add_image_size( 'port-full', 600, 400 );
 67        add_image_size( 'portfolio-two-column',  562, 380, true ); // portfolio column image
 68        add_image_size( 'portfolio-three-column',  362, 300, true ); // portfolio 3 column image
 69        add_image_size( 'portfolio-four-column',  262, 200, true ); // portfolio 4 column image
 70
 71
 72        $options = get_option('responsive_theme_options');    
 73		
 74        register_nav_menus(array(
 75			'footer-menu'  => __('Footer Menu', 'responsive')
 76		    )
 77	    );
 78    }
 79
 80endif;
 81
 82/**
 83 * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
 84 */
 85function responsive_page_menu_args( $args ) {
 86	$args['show_home'] = true;
 87	return $args;
 88}
 89add_filter( 'wp_page_menu_args', 'responsive_page_menu_args' );
 90
 91/**
 92 * Remove div from wp_page_menu() and replace with ul.
 93 */
 94function responsive_wp_page_menu ($page_markup) {
 95    preg_match('/^<div class=\"([a-z0-9-_]+)\">/i', $page_markup, $matches);
 96        $divclass = $matches[1];
 97        $replace = array('<div class="'.$divclass.'">', '</div>');
 98        $new_markup = str_replace($replace, '', $page_markup);
 99        $new_markup = preg_replace('/^<ul>/i', '<ul class="'.$divclass.'">', $new_markup);
100        return $new_markup; }
101
102add_filter('wp_page_menu', 'responsive_wp_page_menu');
103
104/**
105 * Filter 'get_comments_number'
106 * 
107 * Filter 'get_comments_number' to display correct 
108 * number of comments (count only comments, not 
109 * trackbacks/pingbacks)
110 *
111 * Courtesy of Chip Bennett
112 */
113function responsive_comment_count( $count ) {  
114	if ( ! is_admin() ) {
115		global $id;
116		$comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));
117		return count($comments_by_type['comment']);
118	} else {
119		return $count;
120	}
121}
122add_filter('get_comments_number', 'responsive_comment_count', 0);
123
124/**
125 * wp_list_comments() Pings Callback
126 * 
127 * wp_list_comments() Callback function for 
128 * Pings (Trackbacks/Pingbacks)
129 */
130function responsive_comment_list_pings( $comment ) {
131	$GLOBALS['comment'] = $comment;
132?>
133	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"><?php echo comment_author_link(); ?></li>
134<?php }
135
136/**
137 * Sets the post excerpt length to 40 characters.
138 * Next few lines are adopted from Coraline
139 */
140function responsive_excerpt_length($length) {
141    return 40;
142}
143
144add_filter('excerpt_length', 'responsive_excerpt_length');
145
146/**
147 * Returns a "Read more" link for excerpts
148 */
149function responsive_read_more() {
150    return ' <a href="' . get_permalink() . '">' . __('<div class="read-more">Read more &#8250;</div><!-- end of .read-more -->', 'responsive') . '</a>';
151}
152
153/**
154 * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and responsive_read_more_link().
155 */
156function responsive_auto_excerpt_more($more) {
157    return '<span class="ellipsis">&hellip;</span>' . responsive_read_more();
158}
159
160add_filter('excerpt_more', 'responsive_auto_excerpt_more');
161
162/**
163 * Adds a pretty "Read more" link to custom post excerpts.
164 */
165function responsive_custom_excerpt_more($output) {
166    if (has_excerpt() && !is_attachment()) {
167        $output .= responsive_read_more();
168    }
169    return $output;
170}
171
172add_filter('get_the_excerpt', 'responsive_custom_excerpt_more');
173
174
175/**
176 * This function removes inline styles set by WordPress gallery.
177 */
178function responsive_remove_gallery_css($css) {
179    return preg_replace("#<style type='text/css'>(.*?)</style>#s", '', $css);
180}
181
182add_filter('gallery_style', 'responsive_remove_gallery_css');
183
184
185/**
186 * This function removes default styles set by WordPress recent comments widget.
187 */
188function responsive_remove_recent_comments_style() {
189	global $wp_widget_factory;
190	remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
191}
192add_action( 'widgets_init', 'responsive_remove_recent_comments_style' );
193
194
195/**
196 * Breadcrumb Lists
197 * Allows visitors to quickly navigate back to a previous section or the root page.
198 *
199 * Courtesy of Dimox
200 *
201 * bbPress compatibility patch by Dan Smith
202 */
203function responsive_breadcrumb_lists() {
204
205    $chevron = '<span class="divider">/</span>';
206    $name = __('Home','responsive'); //text for the 'Home' link
207    $currentBefore = '<li class="current">';
208    $currentAfter = '</li>';
209
210    echo '<ul class="breadcrumb">';
211
212    global $post;
213    $home = home_url();
214    echo '<li><a href="' . $home . '">' . $name . '</a>' . $chevron . '</li>';
215
216    if (is_category()) {
217        global $wp_query;
218        $cat_obj = $wp_query->get_queried_object();
219        $thisCat = $cat_obj->term_id;
220        $thisCat = get_category($thisCat);
221        $parentCat = get_category($thisCat->parent);
222        if ($thisCat->parent != 0)
223            echo(get_category_parents($parentCat, TRUE, ' ' . $chevron . ' '));
224        echo $currentBefore . 'Archive by category &#39;';
225        single_cat_title();
226        echo '&#39;' . $currentAfter;
227    } elseif (is_day()) {
228        echo '<li><a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $chevron . '</li>  ';
229        echo '<li><a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '">' . get_the_time('F') . '</a>' . $chevron . '</li> ';
230        echo $currentBefore . get_the_time('d') . $currentAfter;
231    } elseif (is_month()) {
232        echo '<li><a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $chevron . '</li> ';
233        echo $currentBefore . get_the_time('F') . $currentAfter;
234    } elseif (is_year()) {
235        echo $currentBefore . get_the_time('Y') . $currentAfter;
236    } elseif (is_single()) {
237        $pid = $post->ID;
238        $pdata = get_the_category($pid);
239        $adata = get_post($pid);
240        if(!empty($pdata)){
241            echo '<li>' .get_category_parents($pdata[0]->cat_ID, TRUE, ' ' . $chevron . ' '). '</li> ';
242            echo $currentBefore;
243        }
244        echo $adata->post_title;
245        echo $currentAfter;
246    } elseif (is_page() && !$post->post_parent) {
247        echo $currentBefore;
248        the_title();
249        echo $currentAfter;
250    } elseif (is_page() && $post->post_parent) {
251        $parent_id = $post->post_parent;
252        $breadcrumb_lists = array();
253        while ($parent_id) {
254            $page = get_page($parent_id);
255            $breadcrumb_lists[] = '<li><a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a></li>';
256            $parent_id = $page->post_parent;
257        }
258        $breadcrumb_lists = array_reverse($breadcrumb_lists);
259        foreach ($breadcrumb_lists as $crumb)
260            echo $crumb . ' ' . $chevron . ' ';
261        echo $currentBefore;
262        the_title();
263        echo $currentAfter;
264    } elseif (is_search()) {
265        echo $currentBefore . __('Search results for &#39;','responsive') . get_search_query() . __('&#39;','responsive') . $currentAfter;
266    } elseif (is_tag()) {
267        echo $currentBefore . __('Posts tagged &#39;','responsive');
268        single_tag_title();
269        echo '&#39;' . $currentAfter;
270    } elseif (is_author()) {
271        global $author;
272        $userdata = get_userdata($author);
273        echo $currentBefore . __('Articles posted by ','responsive') . $userdata->display_name . $currentAfter;
274    } elseif (is_404()) {
275        echo $currentBefore . __('Error 404','responsive') . $currentAfter;
276    }
277
278    if (get_query_var('paged')) {
279        if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author())
280            echo ' (';
281        echo __('Page','responsive') . ' ' . get_query_var('paged');
282        if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author())
283            echo ')';
284    }
285
286    echo '</ul>';
287}
288
289
290    /**
291     * A safe way of adding javascripts to a WordPress generated page.
292     */
293    if (!is_admin())
294        add_action('wp_enqueue_scripts', 'responsive_js');
295
296    if (!function_exists('responsive_js')) {
297
298        function responsive_js() {
299			// JS at the bottom for fast page loading. 
300			// except for Modernizr which enables HTML5 elements & feature detects.
301			wp_enqueue_script('modernizr', get_template_directory_uri() . '/js/responsive-modernizr.js', array('jquery'), '2.5.3', false);
302            wp_enqueue_script('responsive-scripts', get_template_directory_uri() . '/js/responsive-scripts.js', array('jquery'), '1.1.0', true);
303			wp_enqueue_script('responsive-plugins', get_template_directory_uri() . '/js/responsive-plugins.js', array('jquery'), '1.1.0', true);
304            wp_enqueue_script('colorbox', get_template_directory_uri() . '/js/jquery.colorbox-min.js', array('jquery'), '1.3.19', true);
305        }
306
307    }
308
309    /**
310     * A comment reply.
311     */
312        function responsive_enqueue_comment_reply() {
313    if ( is_singular() && comments_open() && get_option('thread_comments')) { 
314            wp_enqueue_script('comment-reply'); 
315        }
316    }
317
318    add_action( 'wp_enqueue_scripts', 'responsive_enqueue_comment_reply' );
319	
320    /**
321     * Where the post has no post title, but must still display a link to the single-page post view.
322     */
323    add_filter('the_title', 'responsive_title');
324
325    function responsive_title($title) {
326        if ($title == '') {
327            return __('Untitled','responsive');
328        } else {
329            return $title;
330        }
331    }
332
333    /**
334     * WordPress Widgets start right here.
335     */
336    function responsive_widgets_init() {
337
338        register_sidebar(array(
339            'name' => __('Main Sidebar', 'responsive'),
340            'description' => __('Area One - sidebar.php', 'responsive'),
341            'id' => 'main-sidebar',
342            'before_title' => '<div class="widget-title">',
343            'after_title' => '</div>',
344            'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
345            'after_widget' => '</div>'
346        ));
347
348        register_sidebar(array(
349            'name' => __('Home Page Right Sidebar', 'responsive'),
350            'description' => __('Area One/2 - sidebar-home-right.php', 'responsive'),
351            'id' => 'sidebar-home-right',
352            'before_title' => '<div class="widget-title">',
353            'after_title' => '</div>',
354            'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
355            'after_widget' => '</div>'
356        ));
357
358        register_sidebar(array(
359            'name' => __('Right Sidebar', 'responsive'),
360            'description' => __('Area Two - sidebar-right.php', 'responsive'),
361            'id' => 'right-sidebar',
362            'before_title' => '<div class="widget-title">',
363            'after_title' => '</div>',
364            'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
365            'after_widget' => '</div>'
366        ));
367				
368        register_sidebar(array(
369            'name' => __('Left Sidebar', 'responsive'),
370            'description' => __('Area Three - sidebar-left.php', 'responsive'),
371            'id' => 'left-sidebar',
372            'before_title' => '<div class="widget-title">',
373            'after_title' => '</div>',
374            'before_widget' => '<div id="%1$s" class="widget-wrapper-left %2$s">',
375            'after_widget' => '</div>'
376        ));
377		
378        register_sidebar(array(
379            'name' => __('Left Sidebar Half Page', 'responsive'),
380            'description' => __('Area Four - sidebar-left-half.php', 'responsive'),
381            'id' => 'left-sidebar-half',
382            'before_title' => '<div class="widget-title">',
383            'after_title' => '</div>',
384            'before_widget' => '<div id="%1$s" class="widget-wrapper-left %2$s">',
385            'after_widget' => '</div>'
386        ));
387		
388        register_sidebar(array(
389            'name' => __('Right Sidebar Half Page', 'responsive'),
390            'description' => __('Area Five - sidebar-right-half.php', 'responsive'),
391            'id' => 'right-sidebar-half',
392            'before_title' => '<div class="widget-title">',
393            'after_title' => '</div>',
394            'before_widget' => '<div id="%1$s" class="widget-wrapper %2$s">',
395            'after_widget' => '</div>'
396        ));
397
398        register_sidebar(array(
399            'name' => __('Home Widget 1', 'responsive'),
400            'description' => __('Area Six - sidebar-home.php', 'responsive'),
401            'id' => 'home-widget-1',
402            'before_title' => '<div id="widget-title-one" class="widget-title-home"><h3>',
403            'after_title' => '</h3></div>',
404            'before_widget' => '<div id="%1$s" class="%2$s">',
405            'after_widget' => '</div>'
406        ));
407
408        register_sidebar(array(
409            'name' => __('Home Widget 2', 'responsive'),
410            'description' => __('Area Seven - sidebar-home.php', 'responsive'),
411            'id' => 'home-widget-2',
412            'before_title' => '<div id="widget-title-two" class="widget-title-home"><h3>',
413            'after_title' => '</h3></div>',
414            'before_widget' => '<div id="%1$s" class="%2$s">',
415            'after_widget' => '</div>'
416        ));
417
418        register_sidebar(array(
419            'name' => __('Home Widget 3', 'responsive'),
420            'description' => __('Area Eight - sidebar-home.php', 'responsive'),
421            'id' => 'home-widget-3',
422            'before_title' => '<div id="widget-title-three" class="widget-title-home"><h3>',
423            'after_title' => '</h3></div>',
424            'before_widget' => '<div id="%1$s" class="%2$s">',
425            'after_widget' => '</div>'
426        ));
427
428        register_sidebar(array(
429            'name' => __('Home Widget Site Map', 'responsive'),
430            'description' => __('Area Eight - sidebar-home.php', 'responsive'),
431            'id' => 'home-site-map',
432            'before_title' => '<div id="widget-title-three" class="widget-title-home"><h4>',
433            'after_title' => '</h4></div>',
434            'before_widget' => '<div id="%1$s" class="span3 %2$s">',
435            'after_widget' => '</div>'
436        ));
437
438          register_sidebar(array(
439            'name' => __('Contact', 'responsive'),
440            'description' => __('Area Nine - contact.php', 'responsive'),
441            'id' => 'contact-widget',
442            'before_title' => '<div id="widget-title-three" class="widget-contact"><h3>',
443            'after_title' => '</h3></div>',
444            'before_widget' => '<div id="%1$s" class="%2$s">',
445            'after_widget' => '</div>'
446        ));
447
448          register_sidebar(array(
449              'name' => __('Membership Option Silver', 'responsive'),
450              'description' => __('Area Ten - sidebar-membership.php', 'responsive'),
451              'id' => 'membership-option-silver',
452              'before_title' => '<div id="widget-title-one" class="widget-title-home"><h3>',
453              'after_title' => '</h3></div>',
454              'before_widget' => '<div id="%1$s" class="%2$s">',
455              'after_widget' => '</div>'
456          ));
457
458          register_sidebar(array(
459              'name' => __('Membership Option Gold', 'responsive'),
460              'description' => __('Area Eleven - sidebar-membership.php', 'responsive'),
461              'id' => 'membership-option-gold',
462              'before_title' => '<div id="widget-title-one" class="widget-title-home"><h3>',
463              'after_title' => '</h3></div>',
464              'before_widget' => '<div id="%1$s" class="%2$s">',
465              'after_widget' => '</div>'
466          ));
467
468          register_sidebar(array(
469              'name' => __('Membership Option Platinum', 'responsive'),
470              'description' => __('Area Twelve - sidebar-membership.php', 'responsive'),
471              'id' => 'membership-option-platinum',
472              'before_title' => '<div id="widget-title-one" class="widget-title-home"><h3>',
473              'after_title' => '</h3></div>',
474              'before_widget' => '<div id="%1$s" class="%2$s">',
475              'after_widget' => '</div>'
476          ));
477    }
478	
479    add_action('widgets_init', 'responsive_widgets_init');
480?>