PluginProbe
Hello Bar Popup Builder / 0.3
Hello Bar Popup Builder v0.3
1.5.3 trunk 0.3 1.5 1.5.1 1.5.2
hellobar / hellobar.php

hellobar.php in Hello Bar Popup Builder 0.3, at hellobar.php

181 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The Hello Bar
4 *
5 * Easily add your HelloBar to your WordPress blog!
6 *
7 * @package HelloBar
8 *
9 * @author digital-telepathy
10 * @version 0.3
11 */
12 /*
13 Plugin Name: HelloBar for WordPress
14 Plugin URI: http://www.hellobar.com/
15 Description: Easily add your HelloBar to your WordPress blog!
16 Version: 0.2
17 Author: digital-telepathy
18 Author URI: http://www.dtelepathy.com
19 License: GPL2
20
21 Copyright 2010 digital-telepathy (email : support@digital-telepathy.com)
22
23 This program is free software; you can redistribute it and/or modify
24 it under the terms of the GNU General Public License as published by
25 the Free Software Foundation; either version 2 of the License, or
26 (at your option) any later version.
27
28 This program is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU General Public License for more details.
32
33 You should have received a copy of the GNU General Public License
34 along with this program; if not, write to the Free Software
35 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
36 */
37
38 class HelloBarForWordPress {
39 var $longname = "Hello Bar for WordPress";
40 var $shortname = "HelloBar";
41 var $namespace = 'hellobar-for-wordpress';
42 var $version = '0.2';
43
44 var $defaults = array(
45 'hellobar_code' => "",
46 'load_hellobar_in' => 'footer'
47 );
48
49 function __construct() {
50 $this->url_path = WP_PLUGIN_URL . "/" . plugin_basename( dirname( __FILE__ ) );
51
52 if( isset( $_SERVER['HTTPS'] ) ) {
53 if( (boolean) $_SERVER['HTTPS'] === true ) {
54 $this->url_path = str_replace( 'http://', 'https://', $this->url_path );
55 }
56 }
57
58 $this->option_name = '_' . $this->namespace . '--options';
59
60 add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
61
62 if( is_admin() ) {
63
64 wp_register_style( $this->namespace, $this->url_path . '/' . $this->namespace . '.css', array(), $this->version );
65 wp_enqueue_style( $this->namespace );
66
67 wp_register_script( $this->namespace, $this->url_path . '/' . $this->namespace . '.js', array( 'jquery' ), $this->version );
68 wp_enqueue_script( $this->namespace );
69
70 } else {
71
72 if( $this->get_option( 'load_hellobar_in' ) == 'header' ){
73 add_action( 'wp_head', array( &$this, 'hellobar_print_script' ) );
74 } else {
75 if( function_exists( 'wp_print_footer_scripts' ) ) {
76 add_action( 'wp_print_footer_scripts', array( &$this, 'hellobar_print_script' ) );
77 } else {
78 add_action( 'wp_footer', array( &$this, 'hellobar_print_script' ) );
79 }
80 }
81
82 }
83 }
84
85 function hellobar_print_script () {
86 $hellobar_code = $this->get_option( 'hellobar_code' );
87
88 if( !empty( $hellobar_code ) ) {
89 $hellobar_code = html_entity_decode( $hellobar_code );
90
91 if( $this->get_option( 'load_hellobar_in' ) == 'header' ) {
92 $output = preg_replace( "/<noscript>(.*)<\/noscript>/ism", "", $hellobar_code );
93 } else {
94 $output = $hellobar_code;
95 }
96
97 echo "\n" . $output;
98 }
99 }
100
101 function admin_menu() {
102 add_menu_page( $this->shortname, $this->shortname, 2, basename( __FILE__ ), array( &$this, 'admin_options_page' ), ( $this->url_path.'/images/icon.png' ) );
103 }
104 function admin_options_page() {
105 if( !current_user_can( 'manage_options' ) ) {
106 wp_die( 'You do not have sufficient permissions to access this page' );
107 }
108
109 if( isset( $_POST ) && !empty( $_POST ) ) {
110 if( wp_verify_nonce( $_REQUEST[$this->namespace . '_update_wpnonce'], $this->namespace . '_options' ) ) {
111 $data = array();
112 foreach( $_POST as $key => $val ) {
113 $data[$key] = $this->sanitize_data( $val );
114 }
115
116 switch( $data['form_action'] ) {
117 case "update_options":
118 $options = array(
119 'hellobar_code' => (string) $data['hellobar_code'],
120 'load_hellobar_in' => (string) $data['load_hellobar_in']
121 );
122
123 update_option( $this->option_name, $options );
124 $this->options = get_option( $this->option_name );
125 break;
126 }
127 }
128 }
129
130 $page_title = $this->longname . ' Options';
131 $namespace = $this->namespace;
132 $options = $this->options;
133 $defaults = $this->defaults;
134 $plugin_path = $this->url_path;
135
136 foreach( $this->defaults as $name => $default_value ) {
137 $$name = $this->get_option( $name );
138 }
139 include( dirname( __FILE__ ) . '/views/options.php' );
140 }
141
142 private function get_option( $option_name ) {
143 // Load option values if they haven't been loaded already
144 if( !isset( $this->options ) || empty( $this->options ) ) {
145 $this->options = get_option( $this->option_name, $this->defaults );
146 }
147
148 if( isset( $this->options[$option_name] ) ) {
149 return $this->options[$option_name]; // Return user's specified option value
150 } elseif( isset( $this->defaults[$option_name] ) ) {
151 return $this->defaults[$option_name]; // Return default option value
152 }
153 return false;
154 }
155
156 private function sanitize_data( $str="" ) {
157 if ( !function_exists( 'wp_kses' ) ) {
158 require_once( ABSPATH . 'wp-includes/kses.php' );
159 }
160 global $allowedposttags;
161 global $allowedprotocols;
162
163 if ( is_string( $str ) ) {
164 $str = htmlentities( stripslashes( $str ), ENT_QUOTES, 'UTF-8' );
165 }
166
167 $str = wp_kses( $str, $allowedposttags, $allowedprotocols );
168
169 return $str;
170 }
171
172 }
173
174 add_action( 'init', 'HelloBarForWordPress' );
175 function HelloBarForWordPress() {
176 global $HelloBarForWordPress;
177
178 $HelloBarForWordPress = new HelloBarForWordPress();
179 }
180 ?>
181