PluginProbe
Hello Bar Popup Builder / 1.5.2
Hello Bar Popup Builder v1.5.2
1.5.3 trunk 0.3 1.5 1.5.1 1.5.2
hellobar / hellobar.php

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

234 lines 9.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Hello Bar: The Original Popup Software (Top Bars, Exit Intents, Sliders, & More to Grow Your Email List!)
4 *
5 * Easily add your HelloBar to your WordPress blog!
6 *
7 * @package Hello Bar: The Original Popup Software (Top Bars, Exit Intents, Sliders, & More to Grow Your Email List!)
8 *
9 * @author hellobar
10 * @version 1.5.2
11 */
12 /*
13 Plugin Name: Hello Bar for WordPress
14 Plugin URI: http://www.hellobar.com/
15 Description: The Original Popup Software (Top Bars, Exit Intents, Sliders, & More to Grow Your Email List!)
16 Version: 1.5.2
17 Tested up to: 6.8
18 Requires at least: 5.0
19 Requires PHP: 7.4
20 Author: hellobar
21 Author URI: http://www.hellobar.com
22 License: GPLv2 or later
23 License URI: https://www.gnu.org/licenses/gpl-2.0.html
24
25 Copyright 2018 Hello Bar (email:support@hellobar.com)
26 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
27 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
28 You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 */
30 class HelloBarForWordPress
31 {
32 var $longname = "Hello Bar for WordPress";
33 var $shortname = "HelloBar";
34 var $namespace = 'hellobar-for-wordpress';
35 var $version = '1.5.2';
36 var $defaults = array('hellobar_code'=>"",'load_hellobar_in'=>'footer');
37 var $url_path;
38 var $option_name;
39 var $options;
40 public static function init()
41 {
42 $class = __CLASS__;
43 new $class;
44 }
45 function __construct()
46 {
47 $this->url_path = plugin_dir_url(__FILE__);
48 $this->option_name = '_'.$this->namespace.'--options';
49 add_action('admin_menu', array($this,'admin_menu'));
50 if (is_admin()) {
51 } else {
52 if ($this->get_option('load_hellobar_in') == 'header') {
53 add_action('wp_head', array($this,'hellobar_print_script'));
54 add_action('wp_head', array($this,'hellobar_insert_tags'));
55 } else {
56 if (function_exists('wp_print_footer_scripts')) {
57 add_action('wp_print_footer_scripts', array($this,'hellobar_print_script'));
58 add_action('wp_print_footer_scripts', array($this,'hellobar_insert_tags'));
59 } else {
60 add_action('wp_footer', array($this,'hellobar_print_script'));
61 add_action('wp_footer', array($this,'hellobar_insert_tags'));
62 }
63 }
64 }
65 /* Loading Admin CSS only for Hellobar option page */
66 if (isset($_GET['page']) && $_GET['page']=='hellobar.php') {
67 add_action('admin_enqueue_scripts', array($this,'add_css_in_admin'));
68 add_action('admin_enqueue_scripts', array($this,'add_js_in_admin'));
69 }
70 }
71 public function add_css_in_admin()
72 {
73 wp_register_style('hellobaradmincss', $this->url_path.'/assets/css/hellobar-admin.css');
74 wp_enqueue_style('hellobaradmincss');
75 }
76 public function add_js_in_admin()
77 {
78 wp_register_script('qtipjs', $this->url_path.'/assets/js/jquery.qtip.min.js', array('jquery'), '3.0.3', false);
79 wp_enqueue_script('qtipjs');
80 }
81 public function hellobar_insert_tags()
82 {
83 if (is_home()) {
84 return;
85 }
86 $posttags = get_the_tags();
87 if ($posttags) {
88 foreach($posttags as $tag) {
89 echo '<script type="text/javascript">window._hellobar_wordpress_tags = window._hellobar_wordpress_tags || []; window._hellobar_wordpress_tags.push(' . json_encode(strval($tag->name)) . '); </script>';
90 }
91 }
92 }
93 public function hellobar_print_script()
94 {
95 $hellobar_code = $this->get_option('hellobar_code');
96 $newapikey = get_option('hellobar_api_key', true);
97 if ($newapikey) {
98 echo '<script src="' . esc_url('https://my.hellobar.com/' . $hellobar_code . '.js') . '" type="text/javascript" charset="utf-8" async="async"></script>';
99 } else {
100 if (!empty($hellobar_code)) {
101 $hellobar_code = html_entity_decode($hellobar_code);
102 if ($this->get_option('load_hellobar_in')=='header') {
103 $output = preg_replace("/<noscript>(.*)<\/noscript>/ism", "", $hellobar_code);
104 } else {
105 $output = $hellobar_code;
106 }
107 echo "\n".$output;
108 }
109 }
110 }
111 public function admin_menu()
112 {
113 add_menu_page($this->shortname, $this->shortname, 'manage_options', basename(__FILE__), array($this,'admin_options_page'), ($this->url_path.'/images/icon.png'));
114 }
115 public function admin_options_page()
116 {
117 if (!current_user_can('manage_options')) {
118 wp_die('You do not have sufficient permissions to access this page');
119 }
120 if (isset($_POST) && !empty($_POST)) {
121 if (isset($_REQUEST[$this->namespace.'_update_wpnonce']) && wp_verify_nonce($_REQUEST[$this->namespace.'_update_wpnonce'], $this->namespace.'_options')) {
122 $data = array();
123 foreach ($_POST as $key => $val) {
124 $data[$key] = $this->sanitize_data($val);
125 }
126 switch($data['form_action']){
127 case "update_options":
128 $options = array(
129 'hellobar_code' => (string) $this->sanitize_hellobar_code(stripslashes($_POST['hellobar_code'])),
130 'load_hellobar_in' => (string) (!empty($data['load_hellobar_in']) ? $data['load_hellobar_in'] : 'footer')
131 );
132 update_option($this->option_name, $options);
133 $this->options = get_option($this->option_name);
134 break;
135 }
136 }
137 }
138 $page_title = $this->longname.' Options';
139 $namespace = $this->namespace;
140 $defaults = $this->defaults;
141 $plugin_path = $this->url_path;
142 foreach ($this->defaults as $name => $default_value) {
143 $$name = $this->get_option($name);
144 }
145 include dirname(__FILE__).'/views/options.php';
146 }
147 private function get_option( $option_name )
148 {
149 // Load option values if they haven't been loaded already
150 if (!isset($this->options) || empty($this->options)) {
151 $this->options = get_option($this->option_name, $this->defaults);
152 }
153 if (isset($this->options[$option_name])) {
154 return $this->options[$option_name];
155 } elseif (isset($this->defaults[$option_name])) {
156 return $this->defaults[$option_name];
157 }
158 return false;
159 }
160 private function sanitize_data($str="")
161 {
162 if (!function_exists('wp_kses')) {
163 include_once ABSPATH.'wp-includes/kses.php';
164 }
165 global $allowedposttags;
166 global $allowedprotocols;
167 if (is_string($str)) {
168 $str = sanitize_text_field(stripslashes($str));
169 }
170 return $str;
171 }
172 private function sanitize_hellobar_code($code="")
173 {
174 $code = trim($code);
175 // Old stored values may be entity-encoded — decode first so the pattern match works
176 // html_entity_decode on a plain string is harmless
177 $code = html_entity_decode($code, ENT_QUOTES, 'UTF-8');
178 // Accept a full <script> embed pointing to the hellobar CDN
179 if (preg_match('/^<script\b[^>]*\bsrc=["\']https:\/\/my\.hellobar\.com\/[a-zA-Z0-9_-]+\.js["\'][^>]*>\s*<\/script>$/i', $code)) {
180 return $code;
181 }
182 // Accept a bare API key (used by reset_old_api migration path)
183 if (preg_match('/^[a-zA-Z0-9_-]+$/', $code)) {
184 return $code;
185 }
186 return '';
187 }
188 public static function is_script()
189 {
190 $options = get_option('_hellobar-for-wordpress--options');
191 $hellobar_code = '';
192 if (is_array($options) && isset($options['hellobar_code'])) {
193 $hellobar_code = html_entity_decode($options['hellobar_code']);
194 }
195 if ($hellobar_code) {
196 $count = preg_match('/src=(["\'])(.*?)\1/', $hellobar_code, $match);
197 if ($count === false) {
198 return false;
199 } else {
200 if (!empty($match)) {
201 $jsurl = $match[2];
202 $parts = parse_url($jsurl);
203 $path = $parts['path'];
204 return HelloBarForWordPress::get_api_code($path);
205 } else {
206 return false;
207 }
208 }
209 } else {
210 return false;
211 }
212 }
213 public static function get_api_code($path)
214 {
215 $path1 = str_replace('/', '', $path);
216 $path2 = str_replace('.js', '', $path1);
217 return $path2;
218 }
219 public static function reset_old_api($api)
220 {
221 update_option('hellobar_api_key', $api);
222 $options = array(
223 'hellobar_code' => $api,
224 'load_hellobar_in' => 'footer'
225 );
226 update_option('_hellobar-for-wordpress--options', $options);
227 }
228 }
229 /**
230 * Load Class on Plugin Load
231 */
232 add_action('plugins_loaded', array('HelloBarForWordPress','init'));
233 ?>
234