/src/engine/includes/base.php
PHP | 562 lines | 332 code | 64 blank | 166 comment | 33 complexity | 416561d0e6e3c7cd42f069adfbe52e7c MD5 | raw file
Possible License(s): AGPL-1.0
- <?php
- /**
- * Infinity Theme: base
- *
- * @author Bowe Frankema <bowe@presscrew.com>
- * @link http://infinity.presscrew.com/
- * @copyright Copyright (C) 2010-2013 Bowe Frankema
- * @license http://www.gnu.org/licenses/gpl.html GPLv2 or later
- * @package Infinity
- * @subpackage base
- * @since 1.1
- */
- /**
- * Add support for base features.
- */
- function infinity_base_features()
- {
- // WordPress Support
- add_theme_support( 'title-tag' );
- add_theme_support( 'menus' );
- add_theme_support( 'post-thumbnails' );
- // WordPress Setup
- add_theme_support( 'infinity:post', 'intro-boxes', 'avatars', 'author-boxes', 'pagination' );
- add_theme_support( 'infinity:wp', 'support', 'style' );
- add_theme_support( 'infinity:base', 'script' );
-
- // Fonts
- add_theme_support( 'infinity:font', 'iconsweets' );
- // Responsive Support
- add_theme_support( 'infinity:resp', 'support', 'menu', 'videos' );
- // Extension Layouts
- add_theme_support( 'infinity:ext', 'support' );
- add_theme_support( 'infinity:typog', 'style' );
- add_theme_support( 'infinity:layout', 'style' );
- add_theme_support( 'infinity:buttons', 'style', 'color' );
- add_theme_support( 'infinity:design', 'style' );
- add_theme_support( 'infinity:icons', 'style' );
- // Extension Options
- add_theme_support( 'infinity:header', 'layout' );
- add_theme_support( 'infinity:header-logo', 'support' );
- add_theme_support( 'infinity:sidebar', 'setup', 'layout' );
- add_theme_support( 'infinity:top-menu', 'setup', 'layout' );
- add_theme_support( 'infinity:main-menu', 'setup', 'layout' );
- add_theme_support( 'infinity:sub-menu', 'setup', 'layout' );
- add_theme_support( 'infinity:footer-menu', 'setup' );
- add_theme_support( 'infinity:core', 'options' );
- add_theme_support( 'infinity:body', 'layout' );
- add_theme_support( 'infinity:content', 'layout' );
- add_theme_support( 'infinity:footer', 'layout' );
- add_theme_support( 'infinity:widget', 'layout' );
- add_theme_support( 'infinity:custom', 'css' );
- add_theme_support( 'infinity:slider', 'custom', 'category' );
- // BuddyPress
- add_theme_support( 'infinity:bp', 'support', 'style', 'sidebar-setup' );
- add_theme_support( 'infinity:bp-fbconnect', 'support' );
- add_theme_support( 'infinity:bp-protect', 'support' );
- add_theme_support( 'infinity:bp-tour', 'activity' );
- // Other plugins
- add_theme_support( 'infinity:plugins', 'other' );
- }
- add_action( 'after_setup_theme', 'infinity_base_features' );
- // register base assets
- function infinity_base_assets()
- {
- // style.css
- ice_register_style(
- 'infinity-style',
- array(
- 'src' => get_stylesheet_uri(),
- 'priority' => 99999,
- 'condition' => 'is_not_admin'
- )
- );
- // superfish script
- ice_register_script(
- 'superfish',
- array(
- 'src' => INFINITY_THEME_URL . '/assets/js/superfish.js',
- 'in_footer' => true,
- 'condition' => 'is_not_admin'
- )
- );
- }
- add_action( 'after_setup_theme', 'infinity_base_assets' );
- // load infinity text domain
- function infinity_base_textdomain()
- {
- load_theme_textdomain( 'infinity-engine', INFINITY_LANGUAGES_PATH );
- }
- add_action( 'after_setup_theme', 'infinity_base_textdomain' );
- // add post formats
- function infinity_base_post_formats()
- {
- add_theme_support(
- 'post-formats',
- array(
- 'aside',
- 'audio',
- 'chat',
- 'gallery',
- 'image',
- 'link',
- 'quote',
- 'status',
- 'video'
- )
- );
- }
- add_action( 'after_setup_theme', 'infinity_base_post_formats' );
- /**
- * Set the content width based on the theme's design and stylesheet.
- * Used to set the width of images and content. Should be equal to the
- * width the theme is designed for, generally via the style.css stylesheet.
- */
- function infinity_base_set_content_width()
- {
- global $content_width;
- if ( false === isset( $content_width ) ) {
- $content_width = 760;
- add_theme_support( 'automatic-feed-links' );
- }
- }
- add_action( 'after_setup_theme', 'infinity_base_set_content_width' );
- /**
- * Render a <title> tag if current version of WordPress doesn't support the title-tag feature.
- */
- function infinity_base_title()
- {
- // determine if we need to inject a title tag into head ourselves
- if (
- // is title-tag feature support missing from running version of WP?
- false === function_exists( '_wp_render_title_tag' )
- ) {
- // no native support, render a title tag
- ?>
- <title><?php wp_title( '|', true, 'right' ); ?></title>
- <?php
- }
- }
- add_filter( 'wp_head', 'infinity_base_title', 1 );
- /**
- * For WordPress versions older than 4.1, filter contents of
- * the <title> tag based on what is being viewed.
- *
- * @uses infinity_plugin_supported()
- *
- * @global int $page
- * @global int $paged
- *
- * @param string $title Incoming title string.
- * @param string $sep Separator string.
- * @param string $seplocation Separator location (left or right).
- */
- function infinity_base_title_filter( $title, $sep, $seplocation )
- {
- global $page, $paged;
- // should we filter the title?
- if (
- // is title-tag support missing from the running copy of WordPress?
- false === function_exists( '_wp_render_title_tag' ) &&
- // is the current screen NOT a feed?
- false === is_feed() &&
- // is WordPress SEO plugin NOT supported?
- false === infinity_plugin_supported( 'wordpress-seo' )
- ) {
- // we are formatting our own custom title string
- // first, append the blog name.
- $title .= get_bloginfo( 'name' );
- // now try to get the blog description
- $site_description = get_bloginfo( 'description', 'display' );
- // did we get a site desc AND on home/front page?
- if (
- false === empty( $site_description ) &&
- true === (
- true === is_home() ||
- true === is_front_page()
- )
- ) {
- // yes, append it (including separator)
- $title .= sprintf( ' %s %s', $sep, $site_description );
- }
- // last thing... do we have a page number?
- if ( $paged >= 2 || $page >= 2 ) {
- // yes, append it (including separator)
- $title .=
- sprintf( ' %s ', $sep ) .
- sprintf( __( 'Page %s', 'infinity-engine' ), max( $paged, $page ) );
- }
- }
- // return title
- return $title;
- }
- add_filter( 'wp_title', 'infinity_base_title_filter', 1, 3 );
- /**
- * Add special "admin bar is showing" body class
- */
- function infinity_base_admin_bar_class( $classes )
- {
- if ( is_admin_bar_showing() ) {
- // *append* class to the array
- $classes[] = 'admin-bar-showing';
- }
- // return it!
- return $classes;
- }
- add_filter( 'body_class', 'infinity_base_admin_bar_class' );
- /**
- * Setup post thumbnail sizes
- *
- * @package Infinity
- * @subpackage base
- */
- function infinity_base_post_thumb_sizes()
- {
- if (
- current_theme_supports( 'post-thumbnails' )
- ) {
- set_post_thumbnail_size( 35, 35, true );
- add_image_size( 'post-image', 674, 140, true );
- add_image_size( 'thumbnail-large', 600, 200, true );
- add_image_size( 'thumbnail-post', 210, 160, true );
- }
- }
- add_action( 'after_setup_theme', 'infinity_base_post_thumb_sizes', 20 );
- /**
- * Enqueue Comment Script
- *
- * @package Infinity
- * @subpackage base
- */
- function infinity_enqueue_comments_reply()
- {
- if( get_option( 'thread_comments' ) ) {
- wp_enqueue_script( 'comment-reply' );
- }
- }
- add_action( 'comment_form_before', 'infinity_enqueue_comments_reply' );
- /**
- * Register menus
- *
- * @package Infinity
- * @subpackage base
- */
- function infinity_base_register_menus()
- {
- if ( current_theme_supports( 'infinity:top-menu', 'setup' ) ) {
- register_nav_menu( 'over-menu', __( 'Above Header', 'infinity-engine' ) );
- }
- if ( current_theme_supports( 'infinity:main-menu', 'setup' ) ) {
- register_nav_menu( 'main-menu', __( 'Inside Header', 'infinity-engine' ) );
- }
- if ( current_theme_supports( 'infinity:sub-menu', 'setup' ) ) {
- register_nav_menu( 'sub-menu', __( 'Below Header', 'infinity-engine' ) );
- }
- if ( current_theme_supports( 'infinity:footer-menu', 'setup' ) ) {
- register_nav_menu( 'footer-menu', __( 'Inside Footer', 'infinity-engine' ) );
- }
- }
- add_action( 'init', 'infinity_base_register_menus' );
- /**
- * Display a nav menu using a custom walker
- *
- * @author Marshall Sorenson <marshall@presscrew.com>
- * @package Infinity
- * @subpackage base
- * @see wp_nav_menu()
- * @param string $theme_location Theme location, 'theme_location' arg passed to wp_nav_menu()\
- */
- function infinity_base_nav_menu( $theme_location )
- {
- wp_nav_menu( array(
- 'theme_location' => $theme_location,
- 'menu_class' => 'sf-menu',
- 'container' => '',
- 'fallback_cb' => 'infinity_base_page_menu',
- 'walker' => new Infinity_Base_Walker_Nav_Menu()
- ));
- }
- /**
- * Display a page menu using a custom page walker
- *
- * @author Marshall Sorenson <marshall@presscrew.com>
- * @package Infinity
- * @subpackage base
- * @see wp_list_pages()
- */
- function infinity_base_page_menu()
- {
- // open the list ?>
- <ul class="sf-menu"><?php
- wp_list_pages(array(
- 'title_li' => null,
- 'walker' => new Infinity_Base_Walker_Page_Menu()
- ));
- // close list?>
- </ul><?php
- }
- /**
- * Render a single superfish list item
- *
- * @param array $args
- * @param boolean $output
- * @return void|string
- */
- function infinity_base_superfish_list_item( $args, $output = true )
- {
- // default values
- $defaults = array(
- 'id' => null,
- 'title' => null,
- 'close_item' => true,
- 'li_id' => null,
- 'li_classes' => array(),
- 'a_id' => null,
- 'a_classes' => array(),
- 'a_target' => null,
- 'a_rel' => null,
- 'a_href' => null,
- 'a_before' => null,
- 'a_after' => null,
- 'a_open' => null,
- 'a_close' => null
- );
- // parse and extract
- $r = wp_parse_args( $args, $defaults );
- extract( $r );
- // handle empty list id
- if ( empty( $li_id ) ) {
- $li_id = 'menu-item-' . $id;
- }
- // list attributes
- $attr_li[] = sprintf( 'id="%s"', esc_attr( $li_id ) );
- if ( count( $li_classes ) ) {
- $attr_li[] = sprintf( 'class="%s"', esc_attr( implode( ' ', $li_classes ) ) );
- }
- // anchor attributes
- $attr_anchor = array();
- if ( $a_id ) {
- $attr_anchor[] = sprintf( 'id="%s"', esc_attr( $a_id ) );
- }
- if ( count( $a_classes ) ) {
- $attr_anchor[] = sprintf( 'class="%s"', esc_attr( implode( ' ', $a_classes ) ) );
- }
- if ( $a_href ) {
- $attr_anchor[] = sprintf( 'href="%s"', esc_attr( $a_href ) );
- }
- if ( $a_title ) {
- $attr_anchor[] = sprintf( 'title="%s"', esc_attr( $a_title ) );
- }
- if ( $a_target ) {
- $attr_anchor[] = sprintf( 'target="%s"', esc_attr( $a_target ) );
- }
- if ( $a_rel ) {
- $attr_anchor[] = sprintf( 'rel="%s"', esc_attr( $a_rel ) );
- }
- // turn on output buffering if we are returning a string
- if ( !$output ) {
- ob_start();
- }
- // render the list item ?>
- <li <?php print implode( ' ', $attr_li ) ?>>
- <?php print $a_before ?>
- <a <?php print implode( ' ', $attr_anchor ) ?>>
- <?php print $a_open ?>
- <span><?php print esc_html( $title ) ?></span>
- <?php print $a_close ?>
- </a>
- <?php print $a_after ?>
- <?php if ( $close_item ): ?>
- </li>
- <?php endif; ?>
- <?php
- if ( !$output ) {
- return ob_get_clean();
- }
- }
- /**
- * Render custom pagination links
- *
- * @package Infinity
- * @subpackage base
- * @todo write a paginator from scratch, this is mental
- */
- function infinity_base_paginate()
- {
- global $wp_query, $wp_rewrite;
- // is pagination feature enabled?
- if ( false == current_theme_supports( 'infinity:post', 'pagination' ) ) {
- // not enabled, abort
- return;
- }
- $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
- $pagination = array(
- 'base' => @add_query_arg('page','%#%'),
- 'format' => '',
- 'total' => $wp_query->max_num_pages,
- 'current' => $current,
- 'show_all' => false,
- 'end_size' => 3,
- 'mid_size' => 5,
- 'type' => 'list'
- );
- if ( $wp_rewrite->using_permalinks() ) {
- $pagination['base'] =
- user_trailingslashit(
- trailingslashit(
- remove_query_arg( 's', get_pagenum_link( 1 ) )
- ) . 'page/%#%/', 'paged'
- );
- }
- if ( !empty( $wp_query->query_vars['s'] ) ) {
- $pagination['add_args'] = array(
- 's' => urlencode( get_query_var( 's' ) )
- );
- }
- print paginate_links( $pagination );
- }
- /**
- * Add Breadcrumb functionality for WordPress SEO
- *
- * @package Infinity
- * @subpackage base
- * @todo move this to a feature extension, no direct plugin support
- */
- function infinity_base_yoast_breadcrumbs()
- {
- if ( function_exists( 'yoast_breadcrumb' ) ) {
- yoast_breadcrumb( '<p id="breadcrumbs">', '</p>' );
- }
- }
- add_action( 'open_content', 'infinity_base_yoast_breadcrumbs' );
- /**
- * Clean up image output and turn it into nice HTML5 Fig captions
- *
- * @package Infinity
- * @subpackage base
- */
- function infinity_base_cleaner_caption( $output, $attr, $content )
- {
- /* We're not worried abut captions in feeds, so just return the output here. */
- if ( is_feed() )
- return $output;
- //Set up the default arguments.
- $defaults = array(
- 'id' => '',
- 'align' => 'alignnone',
- 'width' => '',
- 'caption' => ''
- );
- // Merge the defaults with user input.
- $attr = shortcode_atts( $defaults, $attr );
- // If the width is less than 1 or there is no caption, return the content wrapped between the [caption]< tags.
- if ( 1 > $attr['width'] || empty( $attr['caption'] ) ) {
- return $content;
- }
- // allow filtering of content since we are overriding caption template
- $content = apply_filters( 'infinity_base_cleaner_caption_content', $content );
- // Set up the attributes for the caption <div>.
- $attributes = ' class="figure ' . esc_attr( $attr['align'] ) . '"';
- // is image center aligned?
- if ( 'aligncenter' === $attr['align'] ) {
- // yes, add fixed width
- $attributes .= ' style="max-width:'. esc_attr( $attr['width'] ) . 'px"';
- }
-
- // Open the caption <div>
- $output = '<figure' . $attributes .'>';
- // Allow shortcodes for the content the caption was created for.
- $output .= do_shortcode( $content );
- // Append the caption text.
- $output .= '<figcaption class="wp-caption">' . $attr['caption'] . '</figcaption>';
- // Close the caption </div>
- $output .= '</figure>';
- // Return the formatted, clean caption.
- return $output;
- }
- add_filter( 'img_caption_shortcode', 'infinity_base_cleaner_caption', 10, 3 );
- /**
- * Remove hard coded width/height attr from caption images
- *
- * @param string $content
- * @return string
- */
- function infinity_base_cleaner_caption_content( $content )
- {
- return preg_replace( '/\s+(width|height)="[^"]*"/', '', $content );
- }
- add_filter( 'infinity_base_cleaner_caption_content', 'infinity_base_cleaner_caption_content' );
- /**
- * Clean the output of attributes of images in editor. Courtesy of SitePoint. http://www.sitepoint.com/wordpress-change-img-tag-html/
- *
- * @package Infinity
- * @subpackage base
- */
- function infinity_base_get_image_tag_class( $class, $id, $align, $size )
- {
- $align = 'align' . esc_attr( $align );
- return $align;
- }
- add_filter( 'get_image_tag_class', 'infinity_base_get_image_tag_class', 0, 4 );