| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
Plugin Name: oik base plugin |
| 5 |
Plugin URI: http://www.oik-plugins.com/oik |
| 6 |
Description: Easy to use shortcode macros for Often Included Key-information |
| 7 |
Version: 1.9 |
| 8 |
Author: bobbingwide |
| 9 |
Author URI: http://www.bobbingwide.com |
| 10 |
License: GPL2 |
| 11 |
|
| 12 |
Copyright 2010, 2011 Bobbing Wide (email : herb@bobbingwide.com ) |
| 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, |
| 16 |
as published by the Free Software Foundation. |
| 17 |
|
| 18 |
You may NOT assume that you can use any other version of the GPL. |
| 19 |
|
| 20 |
This program is distributed in the hope that it will be useful, |
| 21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
GNU General Public License for more details. |
| 24 |
|
| 25 |
The license for this software can likely be found here: |
| 26 |
http://www.gnu.org/licenses/gpl-2.0.html |
| 27 |
|
| 28 |
*/ |
| 29 |
global $bw_options; |
| 30 |
|
| 31 |
|
| 32 |
//echo '<p>BATa='.$bwapi_trace_test.'=aBAT</p>'; |
| 33 |
/* All of the oik plugins and many of the common functions include calls to bw_trace so we |
| 34 |
need to include it |
| 35 |
*/ |
| 36 |
|
| 37 |
require_once( 'bwtrace.inc' ); |
| 38 |
require_once( "bobbfunc.inc" ); |
| 39 |
require_once( "bobblink.inc" ); |
| 40 |
require_once( "bobbcomp.inc" ); |
| 41 |
require_once( "bwlink.inc" ); |
| 42 |
require_once( "bobbgoog.inc" ); |
| 43 |
|
| 44 |
function oik_version() { |
| 45 |
return bw_oik_version(); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
if (!function_exists( 'oik_path' )) { |
| 50 |
function oik_path() { |
| 51 |
return( plugin_dir_path( __FILE__ )); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
$bobb_prefix = NULL; |
| 56 |
$bw_echo = NULL; |
| 57 |
|
| 58 |
$theme = "bobbingwide"; |
| 59 |
$art_theme = NULL; |
| 60 |
$bobb_theme = NULL; |
| 61 |
|
| 62 |
require_once( "oik-shortc-shortcodes.php" ); |
| 63 |
require_once( "oik-add-shortcodes.php" ); |
| 64 |
|
| 65 |
add_filter('widget_text', 'do_shortcode'); |
| 66 |
add_filter('the_title', 'do_shortcode' ); |
| 67 |
//add_filter('wpbody-content', 'do_shortcode' ); |
| 68 |
add_filter('wp_footer', 'do_shortcode' ); |
| 69 |
|
| 70 |
add_filter('get_the_excerpt', 'do_shortcode' ); |
| 71 |
add_filter('the_excerpt', 'do_shortcode' ); |
| 72 |
add_filter('the_content', 'do_shortcode' ); |
| 73 |
//add_filter('get_pages', 'do_shortcode' ); |
| 74 |
|
| 75 |
$bw_options = get_option( 'bw_options' ); |
| 76 |
|
| 77 |
//add_action('wp_print_styles', 'oik_enqueue_stylesheets'); |
| 78 |
add_action('wp_enqueue_scripts', 'oik_enqueue_stylesheets'); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
/** |
| 83 |
* enqueue the oik.css, bwlink.css and $customCSS stylesheets |
| 84 |
* |
| 85 |
* oik.css contains styles for oik shortcodes |
| 86 |
* bwlink.css contains styles for the bobbingwide and oik branding colours |
| 87 |
* $customCSS is embedded only if selected on oik options |
| 88 |
* |
| 89 |
* Note: in an earlier version of this code I attempted to ensure |
| 90 |
* that these stylesheets were embedded after the theme's stylesheet |
| 91 |
* BUT this only works if the theme's stylesheet is enqueued using wp_enqueue_style |
| 92 |
* So it worked for child theme's (of buddypress) BUT it didn't work for themes |
| 93 |
* generated by Artisteer where the stylesheets are defined directly in header.php |
| 94 |
* The solution is this callback function invoked for the 'wp_print_styles' action |
| 95 |
* Note: For WordPress 3.3 we've been recommended to use the wp_enqueue_scripts' action instead of 'wp_print_styles' |
| 96 |
*/ |
| 97 |
function oik_enqueue_stylesheets() { |
| 98 |
global $wp_styles; |
| 99 |
wp_enqueue_style( 'oikCSS', WP_PLUGIN_URL . '/oik/oik.css' ); |
| 100 |
wp_enqueue_style( 'bwlinkCSS', WP_PLUGIN_URL . '/oik/bwlink.css' ); |
| 101 |
|
| 102 |
$customCSS = bw_get_company( 'customCSS' ); |
| 103 |
if ( !empty( $customCSS) ) { |
| 104 |
|
| 105 |
//bw_trace( $wp_styles, __FUNCTION__, __LINE__, __FILE__, "wp_styles"); |
| 106 |
|
| 107 |
//$deps = array( get_current_theme() ); |
| 108 |
|
| 109 |
//bw_trace( $deps, __FUNCTION__, __LINE__, __FILE__, "deps"); |
| 110 |
//bw_trace( $customCSS, __FUNCTION__, __LINE__, __FILE__, "customCSS"); |
| 111 |
$customCSSurl = get_stylesheet_directory_uri() . '/' . $customCSS; |
| 112 |
|
| 113 |
bw_trace( $customCSSurl, __FUNCTION__, __LINE__, __FILE__, "customCSSurl"); |
| 114 |
|
| 115 |
//wp_register_style( 'customCSS', $customCSSurl, $deps); |
| 116 |
wp_register_style( 'customCSS', $customCSSurl ); |
| 117 |
|
| 118 |
wp_enqueue_style( 'customCSS' ); |
| 119 |
} |
| 120 |
// bw_trace( $wp_styles, __FUNCTION__, __LINE__, __FILE__, "wp_styles"); |
| 121 |
|
| 122 |
} |
| 123 |
|
| 124 |
add_action('admin_init', 'oik_options_init' ); |
| 125 |
add_action('admin_menu', 'oik_options_add_page'); |
| 126 |
|
| 127 |
// Init plugin options |
| 128 |
function oik_options_init() { |
| 129 |
register_setting( 'oik_options_options', 'bw_options', 'oik_options_validate' ); |
| 130 |
} |
| 131 |
|
| 132 |
// Add the options page |
| 133 |
function oik_options_add_page() { |
| 134 |
add_options_page('[oik] Options', 'oik options', 'manage_options', 'bw_options', 'oik_options_do_page'); |
| 135 |
oik_enqueue_stylesheets(); |
| 136 |
} |
| 137 |
|
| 138 |
// Draw the oik options page |
| 139 |
function oik_options_do_page() { |
| 140 |
require_once( "bobbforms.inc" ); |
| 141 |
sdiv( "column span-15 wrap" ); |
| 142 |
h2( bw_oik(). " shortcode options" ); |
| 143 |
e( '<form method="post" action="options.php">' ); |
| 144 |
$options = get_option('bw_options'); |
| 145 |
|
| 146 |
stag( 'table class="form-table"' ); |
| 147 |
bw_flush(); |
| 148 |
settings_fields('oik_options_options'); |
| 149 |
|
| 150 |
textfield( "bw_options[telephone]", 50, "Telephone [bw_telephone] / [bw_tel]", $options['telephone'] ); |
| 151 |
textfield( "bw_options[fax]", 50, "Fax [bw_fax]", $options['fax'] ); |
| 152 |
textfield( "bw_options[mobile]", 50, "Mobile [bw_mobile] / [bw_mob]", $options['mobile'] ); |
| 153 |
textfield( "bw_options[emergency]", 50, "Emergency [bw_emergency]", $options['emergency'] ); |
| 154 |
|
| 155 |
textfield( "bw_options[company]", 50, "Company [bw_company]", $options['company'] ); |
| 156 |
textfield( "bw_options[business]", 50, "Business [bw_business]", $options['business'] ); |
| 157 |
textfield( "bw_options[formal]", 50, "Formal [bw_formal]", $options['formal'] ); |
| 158 |
textfield( "bw_options[abbr]", 50, "Abbreviation [bw_abbr]", $options['abbr'] ); |
| 159 |
|
| 160 |
|
| 161 |
textfield( "bw_options[main-slogan]", 50, "Main slogan [bw_slogan]", $options['main-slogan'] ); |
| 162 |
textfield( "bw_options[alt-slogan]", 50, "Alt. slogan [bw_alt_slogan]", $options['alt-slogan'] ); |
| 163 |
|
| 164 |
textfield( "bw_options[contact]", 50, "Contact [bw_contact]", $options['contact'] ); |
| 165 |
textfield( "bw_options[email]", 50, "Email [bw_mailto]/[bw_email]", $options['email'] ); |
| 166 |
textfield( "bw_options[admin]", 50, "Admin [bw_admin]", $options['admin'] ); |
| 167 |
textfield( "bw_options[contact-link]", 50, "Contact button page permalink [bw_contact_button]", $options['contact-link'] ); |
| 168 |
textfield( "bw_options[contact-text]", 50, "Contact button text ", $options['contact-text'] ); |
| 169 |
textfield( "bw_options[contact-title]", 50, "Contact button tooltip", $options['contact-title'] ); |
| 170 |
|
| 171 |
|
| 172 |
// extended-address e.g. Bobbing Wide |
| 173 |
// street-address e.g. 41 Redhill Road |
| 174 |
// locality e.g Rowlands Castle |
| 175 |
// region e.g. HANTS |
| 176 |
// postal-code e.g. PO9 6DE |
| 177 |
// country-name e.g. UK |
| 178 |
|
| 179 |
|
| 180 |
textfield( "bw_options[extended-address]", 50, "Extended-address [bw_address]", $options['extended-address'] ); |
| 181 |
textfield( "bw_options[street-address]", 50, "Street-address", $options['street-address'] ); |
| 182 |
textfield( "bw_options[locality]", 50, "Locality", $options['locality'] ); |
| 183 |
textfield( "bw_options[region]", 50, "Region", $options['region'] ); |
| 184 |
textfield( "bw_options[postal-code]", 50, "Post code", $options['postal-code'] ); |
| 185 |
textfield( "bw_options[country-name]", 50, "Country name", $options['country-name'] ); |
| 186 |
|
| 187 |
textfield( "bw_options[lat]", 50, "Latitude [bw_geo] [bw_directions]", $options['lat'] ); |
| 188 |
textfield( "bw_options[long]", 50, "Longitude", $options['long'] ); |
| 189 |
|
| 190 |
// ABQIAAAAEraXBMl-kX5b-Swk0AR98BQiFdr9vy7axdrApFjkJGV6ZRaqtxRqjZfTaNvU9q3jxZ50yMHK-mrzag |
| 191 |
// Note: this is now optional since [bw_show_googlemap] uses the newer API that no longer requires this |
| 192 |
textfield( "bw_options[google_maps_api_key]", 87, "Google Maps API key [bw_show_googlemap]", $options['google_maps_api_key'] ); |
| 193 |
textfield( "bw_options[width]", 10, "Google Map width", $options['width'] ); |
| 194 |
textfield( "bw_options[height]", 10, "Google Map height", $options['height'] ); |
| 195 |
|
| 196 |
|
| 197 |
textfield( "bw_options[domain]", 50, "Domain [bw_domain] [bw_wpadmin]", $options['domain'] ); |
| 198 |
textfield( "bw_options[customCSS]", 50, "Custom CSS in theme directory " . get_stylesheet_directory_uri(), $options['customCSS'] ); |
| 199 |
|
| 200 |
textfield( "bw_options[twitter]", 50, "Twitter URL [bw_twitter]", $options['twitter'] ); |
| 201 |
textfield( "bw_options[facebook]", 50, "Facebook URL [bw_facebook]", $options['facebook'] ); |
| 202 |
textfield( "bw_options[linkedin]", 50, "LinkedIn URL [bw_linkedin]", $options['linkedin'] ); |
| 203 |
textfield( "bw_options[googleplus]", 50, "Google Plus URL [bw_googleplus]", $options['googleplus'] ); |
| 204 |
textfield( "bw_options[youtube]", 50, "YouTube URL [bw_youtube]", $options['youtube'] ); |
| 205 |
textfield( "bw_options[flickr]", 50, "Flickr URL [bw_flickr]", $options['flickr'] ); |
| 206 |
textfield( "bw_options[picasa]", 50, "Picasa URL [bw_picasa]", $options['picasa'] ); |
| 207 |
textfield( "bw_options[skype]", 50, "Skype Name [bw_skype]", $options['skype'] ); |
| 208 |
|
| 209 |
|
| 210 |
textfield( "bw_options[paypal-email]", 50, "PayPal email [bw_paypal]", $options['paypal-email'] ); |
| 211 |
|
| 212 |
$upload_dir = wp_upload_dir(); |
| 213 |
$baseurl = $upload_dir['baseurl']; |
| 214 |
|
| 215 |
textfield( "bw_options[logo-image]", 50, "Logo image [bw_logo] in uploads: " . $baseurl, $options['logo-image'] ); |
| 216 |
textfield( "bw_options[qrcode-image]", 50, "QR code image [bw_qrcode] in uploads", $options['qrcode-image'] ); |
| 217 |
textfield( "bw_options[art-version]", 50, "Artisteer version 31/30/25/na [bw_art_version]", $options['art-version'] ); |
| 218 |
|
| 219 |
tablerow( "", "<input type=\"submit\" name=\"ok\" value=\"Save changes\" />" ); |
| 220 |
|
| 221 |
etag( "table" ); |
| 222 |
etag( "form" ); |
| 223 |
|
| 224 |
ediv(); |
| 225 |
sdiv("column span-9 wrap last"); |
| 226 |
|
| 227 |
h2( "Usage notes" ); |
| 228 |
p("Use the shortcode options in your pages, widgets and titles. e.g." ); |
| 229 |
p("[bw_telephone] for your telephone number" ); |
| 230 |
p( bw_telephone() ); |
| 231 |
p("[bw_address] to print your address" ); |
| 232 |
p( bw_address()); |
| 233 |
p( "[bw_follow_me] for ALL your Follow me buttons" ); |
| 234 |
p( bw_follow_me() ); |
| 235 |
|
| 236 |
|
| 237 |
bw_edit_custom_css_link( $options['customCSS'] ); |
| 238 |
|
| 239 |
|
| 240 |
p("For more information:" ); |
| 241 |
art_button( "http://www.oik-plugins.com/oik", "oik documentation", "Read the documentation for the oik plugin" ); |
| 242 |
|
| 243 |
ediv(); |
| 244 |
bw_flush(); |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
// Sanitize and validate input. Accepts an array, return a sanitized array. |
| 249 |
|
| 250 |
|
| 251 |
function oik_options_validate( $input ) { |
| 252 |
$customCSS = bw_array_get( $input, 'customCSS', NULL ); |
| 253 |
if ( $customCSS ) { |
| 254 |
$sanfile = sanitize_file_name( $customCSS ); |
| 255 |
// Should we check the sanitized file name with the original ? |
| 256 |
bw_create_file( get_stylesheet_directory(), $sanfile, plugin_dir_path( __FILE__ ) . 'custom.css' ); |
| 257 |
} |
| 258 |
|
| 259 |
return $input; |
| 260 |
} |
| 261 |
|
| 262 |
/** |
| 263 |
* Create a file with the specified name in the specified directory |
| 264 |
* @param string base - the base path for the file name - may be absolute |
| 265 |
* @param string path - the rest of the file name - as specified by the user |
| 266 |
* @param string default - the fully qualified filename of the base source file to copy |
| 267 |
*/ |
| 268 |
function bw_create_file( $base, $path, $default ) { |
| 269 |
$target = path_join( $base, $path ); |
| 270 |
|
| 271 |
if ( !file_exists( $target ) ) { |
| 272 |
// create an empty file - or copy the original |
| 273 |
// $info = pathinfo( $target ); |
| 274 |
// $name = basename( $target ); |
| 275 |
if ( $default ) { |
| 276 |
$success = copy( $default, $target ); |
| 277 |
} else { |
| 278 |
// write an empty file |
| 279 |
$resource = fopen( $target, 'xb' ); |
| 280 |
fclose( $resource ); |
| 281 |
} |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
/** |
| 287 |
* Link to allow the custom CSS file to be edited |
| 288 |
* @param string $customCSS Name of the custom.css file. Probably 'custom.css' |
| 289 |
* |
| 290 |
* Note: you can't specify a relative path to this file. If you do you may see this message |
| 291 |
* |
| 292 |
* Sorry, can't edit files with ".." in the name. |
| 293 |
* If you are trying to edit a file in your WordPress home directory, you can just type the name of the file in. |
| 294 |
* |
| 295 |
* With WPMS, the link takes you to style.css rather than custom.css. Don't know why! |
| 296 |
*/ |
| 297 |
function bw_edit_custom_css_link( $customCSS ) { |
| 298 |
p( "If you have defined a custom CSS file use this link to edit it." ); |
| 299 |
p( "Note: This only works when the file is in the current theme directory." ); |
| 300 |
p( "If you change themes then you will start with a new custom CSS file" ); |
| 301 |
p( get_current_theme() . " in " . get_stylesheet_directory() ); |
| 302 |
|
| 303 |
|
| 304 |
$link = admin_url( "theme-editor.php" ); |
| 305 |
$link .= '?file='; |
| 306 |
//$link .= 'oik/custom.css'; |
| 307 |
$link .= path_join( get_stylesheet_directory(), $customCSS ); |
| 308 |
|
| 309 |
|
| 310 |
alink( NULL, $link, "edit custom CSS" ); |
| 311 |
} |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|