| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
Plugin Name: oik base plugin |
| 5 |
Plugin URI: http://www.oik-plugins.com/oik |
| 6 |
Description: Lazy smart shortcodes for displaying often included key-information and other WordPress content |
| 7 |
Version: 1.15 |
| 8 |
Author: bobbingwide |
| 9 |
Author URI: http://www.bobbingwide.com |
| 10 |
License: GPL2 |
| 11 |
|
| 12 |
Copyright 2010-2012 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 |
require_once( "oik_boot.inc" ); |
| 31 |
|
| 32 |
/* All of the oik plugins and many of the common functions include calls to bw_trace(), bw_trace2() or bw_backtrace() so we need to include bwtrace.inc |
| 33 |
*/ |
| 34 |
require_once( 'bwtrace.inc' ); |
| 35 |
require_once( "bobbfunc.inc" ); |
| 36 |
require_once( "bobbcomp.inc" ); |
| 37 |
|
| 38 |
/** |
| 39 |
* Return the oik_version |
| 40 |
* @returns string oik version number e.g. 1.15 |
| 41 |
*/ |
| 42 |
function oik_version() { |
| 43 |
return bw_oik_version(); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
require_once( "oik-add-shortcodes.php" ); |
| 48 |
|
| 49 |
add_filter('widget_text', 'do_shortcode'); |
| 50 |
add_filter('the_title', 'do_shortcode' ); |
| 51 |
//add_filter('wpbody-content', 'do_shortcode' ); |
| 52 |
add_filter('wp_footer', 'do_shortcode' ); |
| 53 |
|
| 54 |
add_filter('get_the_excerpt', 'do_shortcode' ); |
| 55 |
add_filter('the_excerpt', 'do_shortcode' ); |
| 56 |
// The big question is... do we need to add this filter |
| 57 |
// or can we rely on it having been already added |
| 58 |
// Well it all depends on how add_filter works **?** |
| 59 |
// add_filter('the_content', 'do_shortcode', 11 ); |
| 60 |
//add_filter('get_pages', 'do_shortcode' ); |
| 61 |
|
| 62 |
$bw_options = get_option( 'bw_options' ); |
| 63 |
|
| 64 |
//add_action('wp_print_styles', 'oik_enqueue_stylesheets'); |
| 65 |
add_action('wp_enqueue_scripts', 'oik_enqueue_stylesheets'); |
| 66 |
add_action('init', 'oik_main_init' ); |
| 67 |
|
| 68 |
add_action( 'wp_ajax_oik_ajax_list_shortcodes', 'oik_ajax_list_shortcodes' ); |
| 69 |
add_action( 'wp_ajax_oik_ajax_load_shortcode_syntax', 'oik_ajax_load_shortcode_syntax' ); |
| 70 |
add_action( 'wp_ajax_oik_ajax_load_shortcode_help', 'oik_ajax_load_shortcode_help' ); |
| 71 |
//add_action( 'admin_enqueue_scripts', 'bw_button_options' ); |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
/** |
| 76 |
* enqueue the oik.css, bwlink.css and $customCSS stylesheets |
| 77 |
* |
| 78 |
* oik.css contains styles for oik shortcodes |
| 79 |
* bwlink.css contains styles for the bobbingwide and oik branding colours |
| 80 |
* $customCSS is embedded only if selected on oik options |
| 81 |
* |
| 82 |
* Note: in an earlier version of this code I attempted to ensure |
| 83 |
* that these stylesheets were embedded after the theme's stylesheet |
| 84 |
* BUT this only works if the theme's stylesheet is enqueued using wp_enqueue_style |
| 85 |
* So it worked for child theme's (of buddypress) BUT it didn't work for themes |
| 86 |
* generated by Artisteer where the stylesheets are defined directly in header.php |
| 87 |
* The solution is this callback function invoked for the 'wp_print_styles' action |
| 88 |
* Note: For WordPress 3.3 we've been recommended to use the wp_enqueue_scripts' action instead of 'wp_print_styles' |
| 89 |
*/ |
| 90 |
function oik_enqueue_stylesheets() { |
| 91 |
//global $wp_styles; |
| 92 |
//bw_trace2(); |
| 93 |
wp_enqueue_style( 'oikCSS', WP_PLUGIN_URL . '/oik/oik.css' ); |
| 94 |
// **?** suggest this stylesheet is only enqueued for bob-bing-wide and oik admin |
| 95 |
wp_enqueue_style( 'bwlinkCSS', WP_PLUGIN_URL . '/oik/bwlink.css', 'oikCSS' ); |
| 96 |
|
| 97 |
$customCSS = bw_get_option( 'customCSS' ); |
| 98 |
if ( !empty( $customCSS) ) { |
| 99 |
$customCSSurl = get_stylesheet_directory_uri() . '/' . $customCSS; |
| 100 |
|
| 101 |
bw_trace( $customCSSurl, __FUNCTION__, __LINE__, __FILE__, "customCSSurl"); |
| 102 |
|
| 103 |
wp_register_style( 'customCSS', $customCSSurl ); |
| 104 |
|
| 105 |
wp_enqueue_style( 'customCSS' ); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
/** |
| 111 |
* Implement the 'init' action |
| 112 |
* |
| 113 |
* start oik and let oik dependent plugins know it's OK to use the oik API |
| 114 |
*/ |
| 115 |
function oik_main_init() { |
| 116 |
add_action( 'admin_menu', 'oik_admin_menu' ); |
| 117 |
add_action( "activate_plugin", "oik_load_plugins" ); |
| 118 |
add_action( "network_admin_notices", "oik_admin_menu" ); |
| 119 |
bw_load_plugin_textdomain(); |
| 120 |
do_action( 'oik_loaded' ); |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Implement the 'admin_menu' action |
| 125 |
* |
| 126 |
* Note: This comes before 'admin_init' and after '_admin_menu' |
| 127 |
* |
| 128 |
*/ |
| 129 |
function oik_admin_menu() { |
| 130 |
require_once( 'admin/oik-admin.inc' ); |
| 131 |
oik_options_add_page(); |
| 132 |
add_action('admin_init', 'oik_admin_init' ); |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Implement 'admin_init' |
| 137 |
*/ |
| 138 |
function oik_admin_init() { |
| 139 |
oik_options_init(); |
| 140 |
} |
| 141 |
|
| 142 |
function oik_ajax_list_shortcodes() { |
| 143 |
oik_require( 'shortcodes/oik-codes.php' ); |
| 144 |
|
| 145 |
$sc_list = bw_shortcode_list(); |
| 146 |
$sc_json = json_encode( $sc_list ); |
| 147 |
bw_trace2( $sc_json ); |
| 148 |
echo $sc_json; |
| 149 |
die(); |
| 150 |
|
| 151 |
} |
| 152 |
|
| 153 |
function oik_ajax_load_shortcode_syntax() { |
| 154 |
|
| 155 |
oik_require( "includes/oik-sc-help.inc" ); |
| 156 |
$shortcode = bw_array_get( $_REQUEST, 'shortcode', 'oik' ); |
| 157 |
$sc_syntax = _bw_lazy_sc_syntax( $shortcode ); |
| 158 |
$sc_json = json_encode( $sc_syntax ); |
| 159 |
bw_trace2( $sc_json, "sc_json" ); |
| 160 |
echo $sc_json; |
| 161 |
die(); |
| 162 |
|
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
function oik_ajax_load_shortcode_help() { |
| 167 |
|
| 168 |
oik_require( "includes/oik-sc-help.inc" ); |
| 169 |
$shortcode = bw_array_get( $_REQUEST, 'shortcode', 'oik' ); |
| 170 |
|
| 171 |
bw_trace2( $shortcode, "shortcode" ); |
| 172 |
$sc_help = bw_lazy_sc_example( $shortcode ); |
| 173 |
bw_trace2( $sc_help, "sc_help" ); |
| 174 |
echo $sc_help; |
| 175 |
bw_flush(); |
| 176 |
|
| 177 |
die(); |
| 178 |
|
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
/** |
| 183 |
* let ajax know what to call on jQuery.post **?** not necessary as we can use WordPress's ajaxurl variable |
| 184 |
* |
| 185 |
*/ |
| 186 |
|
| 187 |
function bw_add_ajaxurl() { |
| 188 |
// Do we need the protocol? |
| 189 |
|
| 190 |
wp_enqueue_script( 'otherbits', plugin_dir_url( __FILE__). 'otherbits.js', array( 'jquery' ) ); |
| 191 |
//wp_enqueue_script( 'otherbits2', plugin_dir_url( __FILE__). 'otherbits2.js', array( 'jquery' ) ); |
| 192 |
$otherbits = array( "ajaxurl" => admin_url( 'admin-ajax.php' )); |
| 193 |
wp_localize_script( 'otherbits', 'otherbits', $otherbits ); |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
/** |
| 198 |
* Return all the jQuery/JavaScript to enable shortcode creation from the editor buttons |
| 199 |
**?** Changed to not working 2012/03/19 |
| 200 |
*/ |
| 201 |
function bw_preload_button_options() { |
| 202 |
|
| 203 |
wp_enqueue_script( 'bw_shortcodes', plugin_dir_url( __FILE__). 'bw_shortcodes.js', array( 'jquery' ) ); |
| 204 |
|
| 205 |
// $data = array( 'some_string' => __( 'Some string to translate' ) ); |
| 206 |
oik_require( "shortcodes/oik-codes.php" ); |
| 207 |
$data = bw_shortcode_list(); |
| 208 |
wp_localize_script( 'bw_shortcodes', 'bw_shortcodes', $data ); |
| 209 |
// bw_add_ajaxurl( 'bw_shortcodes' ); |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|