Overview

Namespaces

  • None
  • PHP

Classes

  • Sidecar
  • Sidecar_Admin_Page
  • Sidecar_Admin_Tab
  • Sidecar_Field
  • Sidecar_Form
  • Sidecar_Plugin_Base
  • Sidecar_Settings
  • Sidecar_Shortcode
  • Sidecar_Singleton_Base

Functions

  • body
  • format_gmt_string
  • headers
  • output_css
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
  1: <?php
  2: /*
  3:  * Plugin Name: Sidecar for WordPress
  4:  * Plugin URI: http://github.com/newclarity/sidecar
  5:  * Description:
  6:  * Version: 0.5.0
  7:  * Author: NewClarity, MikeSchinkel
  8:  * Author URI: http://newclarity.net
  9:  * Text Domain: sidecar
 10:  * License: GPLv2
 11:  *
 12:  *  Copyright 2012
 13:  *
 14:  *  This program is free software; you can redistribute it and/or modify
 15:  *  it under the terms of the GNU General Public License, version 2, as
 16:  *  published by the Free Software Foundation.
 17:  *
 18:  *  This program is distributed in the hope that it will be useful,
 19:  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 20:  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 21:  *  GNU General Public License for more details.
 22:  *
 23:  *  You should have received a copy of the GNU General Public License
 24:  *  along with this program; if not, write to the Free Software
 25:  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 26:  */
 27: define( 'SIDECAR_FILE', __FILE__ );
 28: define( 'SIDECAR_DIR', dirname( __FILE__ ) );
 29: define( 'SIDECAR_PATH', plugin_dir_path( __FILE__ ) );
 30: 
 31: define( 'SIDECAR_VER', '0.5.0' );
 32: define( 'SIDECAR_MIN_PHP', '5.2.4' );
 33: define( 'SIDECAR_MIN_WP', '3.2' );
 34: 
 35: /**
 36:  * TODO: Change this to use a class auto-loader (maybe)
 37:  */
 38: 
 39: require(SIDECAR_DIR . '/classes/class-singleton-base.php');
 40: require(SIDECAR_DIR . '/classes/class-plugin-base.php');
 41: require(SIDECAR_DIR . '/classes/class-admin-page.php');
 42: require(SIDECAR_DIR . '/classes/class-admin-tab.php');
 43: require(SIDECAR_DIR . '/classes/class-form.php');
 44: require(SIDECAR_DIR . '/classes/class-field.php');
 45: require(SIDECAR_DIR . '/classes/class-shortcode.php');
 46: 
 47: /**
 48:  *
 49:  */
 50: final class Sidecar {
 51:   /**
 52:    * @var string
 53:    */
 54:   private static $_installed_dir = false;
 55: 
 56:   /**
 57:    * @var string
 58:    */
 59:   private static $_this_url = false;
 60: 
 61:   /**
 62:    * @var string
 63:    */
 64:   private static $_this_domain = false;
 65: 
 66: 
 67:   /**
 68:    * @param string $message
 69:    * @param array $args
 70:    */
 71:   static function show_error( $message, $args ) {
 72:     $args = func_get_args();
 73:     echo '<div class="error"><p><strong>ERROR</strong>[Sidecar]: ' . call_user_func_array( 'sprintf', $args ) . '</p></div>';
 74:   }
 75: 
 76:   /**
 77:    * Tests an array element for value, first checking for isset().
 78:    *
 79:    * @param array $array
 80:    * @param string $element
 81:    * @param mixed $value
 82:    * @param bool $exactly
 83:    * @return bool
 84:    */
 85:   static function element_is( $array, $element, $value = true, $exactly = false ) {
 86:     return isset( $array[$element] ) && ( $exactly ? $value === $array[$element] : $value == $array[$element] );
 87:   }
 88: 
 89:   /**
 90:      * Returns the domain for this site.
 91:    *
 92:      * @return string
 93:      */
 94:     static function this_domain() {
 95:       if ( ! self::$_this_domain ) {
 96:         $parts = explode( '/', site_url() );
 97:       self::$_this_domain = $parts[2];
 98:      }
 99:      return self::$_this_domain;
100:   }
101: 
102:   /**
103:      * Returns the directory in which WordPress is installed, or '/' if root.
104:    *
105:    * Preceded with a '/' but no trailing '/'
106:      *
107:      * @return string
108:      */
109:     static function installed_dir() {
110:       if ( ! self::$_installed_dir ) {
111:         $site_url = site_url();
112:       if ( 2 == substr_count( $site_url, '/' ) ) {
113:         self::$_installed_dir = '/';
114:       } else {
115:         $regex = '^https?://' . preg_quote( self::this_domain() ) . '(/.*)/?$';
116:         self::$_installed_dir = preg_replace( "#{$regex}#", '$1', site_url() );
117:       }
118:     }
119:     return self::$_installed_dir;
120:   }
121: 
122:   /**
123:    * Returns the current URL.
124:    *
125:    * @return bool
126:    */
127:   static function this_url() {
128:       if ( ! self::$_this_url ) {
129:        $installed_dir = self::installed_dir();
130:        $requested_path = substr( $_SERVER['REQUEST_URI'], strlen( $installed_dir ) );
131:        self::$_this_url = site_url( $requested_path );
132:     }
133:     return self::$_this_url;
134:     }
135: }
136: 
137: 
API documentation generated by ApiGen 2.8.0