PluginProbe
Hello Bar Popup Builder / 1.5.1
Hello Bar Popup Builder v1.5.1
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.1, at hellobar.php

219 lines 8.8 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.1
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.1
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.1';
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("'.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="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) $data['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 = htmlentities(stripslashes($str), ENT_QUOTES, 'UTF-8');
169 }
170 $str = wp_kses($str, $allowedposttags, $allowedprotocols);
171 return $str;
172 }
173 public static function is_script()
174 {
175 $options = get_option('_hellobar-for-wordpress--options');
176 $hellobar_code = '';
177 if (is_array($options) && isset($options['hellobar_code'])) {
178 $hellobar_code = html_entity_decode($options['hellobar_code']);
179 }
180 if ($hellobar_code) {
181 $count = preg_match('/src=(["\'])(.*?)\1/', $hellobar_code, $match);
182 if ($count === false) {
183 return false;
184 } else {
185 if (!empty($match)) {
186 $jsurl = $match[2];
187 $parts = parse_url($jsurl);
188 $path = $parts['path'];
189 return HelloBarForWordPress::get_api_code($path);
190 } else {
191 return false;
192 }
193 }
194 } else {
195 return false;
196 }
197 }
198 public static function get_api_code($path)
199 {
200 $path1 = str_replace('/', '', $path);
201 $path2 = str_replace('.js', '', $path1);
202 return $path2;
203 }
204 public static function reset_old_api($api)
205 {
206 update_option('hellobar_api_key', $api);
207 $options = array(
208 'hellobar_code' => $api,
209 'load_hellobar_in' => 'footer'
210 );
211 update_option('_hellobar-for-wordpress--options', $options);
212 }
213 }
214 /**
215 * Load Class on Plugin Load
216 */
217 add_action('plugins_loaded', array('HelloBarForWordPress','init'));
218 ?>
219