| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU General Public License |
| 6 |
as published by the Free Software Foundation; either version 2 |
| 7 |
of the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with this program; if not, write to the Free Software |
| 16 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 |
|
| 18 |
Copyright 2017 Buttonizer |
| 19 |
*/ |
| 20 |
namespace Buttonizer\Admin; |
| 21 |
|
| 22 |
# No script kiddies |
| 23 |
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
| 24 |
class General |
| 25 |
{ |
| 26 |
private $aSavedData = array() ; |
| 27 |
private $aSubCatagories = array() ; |
| 28 |
private $aSubPages = array() ; |
| 29 |
private $aFontAwesome = array() ; |
| 30 |
private $oIconManager = array() ; |
| 31 |
private $bHasProFeature = false ; |
| 32 |
public function __construct( $aFontAwesome, $oIconManager ) |
| 33 |
{ |
| 34 |
$this->aFontAwesome = $aFontAwesome; |
| 35 |
$this->oIconManager = $oIconManager; |
| 36 |
$this->loadData(); |
| 37 |
$this->registerStylingSettings(); |
| 38 |
$this->registerAdvancedSettings(); |
| 39 |
$this->registerSocialSettings(); |
| 40 |
$this->registerOther(); |
| 41 |
$this->generatePage(); |
| 42 |
} |
| 43 |
|
| 44 |
private function loadData() |
| 45 |
{ |
| 46 |
$this->aSavedData = (array) get_option( 'buttonizer_general_settings' ); |
| 47 |
} |
| 48 |
|
| 49 |
private function generatePage() |
| 50 |
{ |
| 51 |
$sTabs = ''; |
| 52 |
$sTabsContent = ''; |
| 53 |
$bFirstTab = true; |
| 54 |
// Get tabs |
| 55 |
foreach ( $this->aSubCatagories as $sKey => $sTitle ) { |
| 56 |
$sTabs .= '<a href="#tab_' . $sKey . '" onclick="javascript:buttonizer.tabNavigate(\'' . $sKey . '\')" id="tab_container_' . $sKey . '" class="nav-tab ' . (( $bFirstTab ? 'first nav-tab-active' : '' )) . '">' . $sTitle . '</a>'; |
| 57 |
$sTabsContent .= '<div id="tab_container_' . $sKey . '" ' . (( !$bFirstTab ? 'style="display: none;"' : '' )) . ' class="tab-container">' . $this->aSubPages[$sKey] . '</div>'; |
| 58 |
$bFirstTab = false; |
| 59 |
} |
| 60 |
echo '<table class="vertical-tabs"> |
| 61 |
<tr> |
| 62 |
<td class="tabs">' . $sTabs . '</td> |
| 63 |
<td class="tabsholder">' . $sTabsContent . '</td> |
| 64 |
</tr> |
| 65 |
</table>' ; |
| 66 |
} |
| 67 |
|
| 68 |
/* |
| 69 |
* Register settings |
| 70 |
*/ |
| 71 |
public function registerStylingSettings() |
| 72 |
{ |
| 73 |
$this->aSubCatagories['styling'] = 'Styling settings'; |
| 74 |
$this->aSubPages['styling'] = '<table class="form-table"><tbody>'; |
| 75 |
$this->aSubPages['styling'] .= $this->createFormField( 'Right', array( &$this, 'field_position_right' ) ); |
| 76 |
$this->aSubPages['styling'] .= $this->createFormField( 'Bottom', array( &$this, 'field_position_bottom' ) ); |
| 77 |
$this->aSubPages['styling'] .= $this->createFormField( 'Color button unpushed', array( &$this, 'field_button_unpushed' ) ); |
| 78 |
$this->aSubPages['styling'] .= $this->createFormField( 'Color button pushed', array( &$this, 'field_button_pushed' ) ); |
| 79 |
$this->aSubPages['styling'] .= $this->createFormField( 'Icon color', array( &$this, 'field_icon_color' ) ); |
| 80 |
$this->aSubPages['styling'] .= $this->createFormField( 'Main icon<br /><br /><small>Used only when more then one button and there is a menu.</small>', array( &$this, 'field_icon_icon' ) ); |
| 81 |
$this->aSubPages['styling'] .= '</tbody></table>'; |
| 82 |
} |
| 83 |
|
| 84 |
public function registerAdvancedSettings() |
| 85 |
{ |
| 86 |
$this->aSubCatagories['advanced'] = 'Advanced settings'; |
| 87 |
$this->aSubPages['advanced'] = '<table class="form-table"><tbody>'; |
| 88 |
$this->aSubPages['advanced'] .= $this->createFormField( ' |
| 89 |
<span class="info-class"> |
| 90 |
<i class="fa fa-info-circle"></i> |
| 91 |
<span>If you have your Google Analytics tracking code already installed you can ignore this setting. If you want to be sure that your buttons are tracked in your Google Analytics account? Then go to your Google Analytics account > Click on Real Time > Events and open your website in another tab. Click on a Buttonizer button and check if you see that the click gets tracked in Google Analytics. If this doesn\'t happen than go to your google Analytics settings page > Click on tracking code and copy your tracking-ID. It should look like this (UA-00000000-0) |
| 92 |
</span> |
| 93 |
</span> |
| 94 |
Google Analytics', array( &$this, 'field_analytics_code' ) ); |
| 95 |
// Show on scroll |
| 96 |
$this->aSubPages['advanced'] .= $this->createFormField( ' |
| 97 |
<span class="info-class"> |
| 98 |
<i class="fa fa-info-circle"></i> |
| 99 |
<span> |
| 100 |
When selected, the buttons will be shown after the user has scrolled a percentage of the page. |
| 101 |
</span> |
| 102 |
</span> |
| 103 |
Show on scroll?', array( &$this, 'field_show_on_scroll' ) ); |
| 104 |
$this->aSubPages['advanced'] .= $this->createFormField( ' |
| 105 |
<span class="info-class"> |
| 106 |
<i class="fa fa-info-circle"></i> |
| 107 |
<span> |
| 108 |
Enter a percentage, starting from 0, up to 100. |
| 109 |
</span> |
| 110 |
</span> |
| 111 |
% from top to show:', array( &$this, 'field_procent_to_scroll' ) ); |
| 112 |
// Show after timeout |
| 113 |
$this->aSubPages['advanced'] .= $this->createFormField( ' |
| 114 |
<span class="info-class"> |
| 115 |
<i class="fa fa-info-circle"></i> |
| 116 |
<span> |
| 117 |
When selected, the buttons will be shown when the user browsers more than the given seconds. So when you say: Show after 20<i>000</i>ms, the button shows after the user browsed on the website for 20 seconds. |
| 118 |
</span> |
| 119 |
</span> |
| 120 |
Show after timeout?', array( &$this, 'field_show_on_timeout' ) ); |
| 121 |
$this->aSubPages['advanced'] .= $this->createFormField( ' |
| 122 |
<span class="info-class"> |
| 123 |
<i class="fa fa-info-circle"></i> |
| 124 |
<span> |
| 125 |
Enter the miliseconds from when the buttons must get shown to the user.<br /> |
| 126 |
<br /> |
| 127 |
1 second = 1000 miliseconds<br /> |
| 128 |
10 seconds = 10000 miliseconds<br /> |
| 129 |
1 minute = 60000 miliseconds<br /> |
| 130 |
</span> |
| 131 |
</span> |
| 132 |
Milliseconds: ', array( &$this, 'field_time_to_timeout' ) ); |
| 133 |
// Exit intent |
| 134 |
$this->aSubPages['advanced'] .= $this->createFormField( ' |
| 135 |
<span class="info-class"> |
| 136 |
<i class="fa fa-info-circle"></i> |
| 137 |
<span> |
| 138 |
When selected, the buttons will open with a effect when your guest/user tries to escape from your website. The user gets attracted from your buttons. |
| 139 |
</span> |
| 140 |
</span> |
| 141 |
Exit intent', array( &$this, 'field_exit_intent' ) ); |
| 142 |
$this->aSubPages['advanced'] .= $this->createFormField( ' |
| 143 |
<span class="info-class"> |
| 144 |
<i class="fa fa-info-circle"></i> |
| 145 |
<span> |
| 146 |
When the exit intent activates, there will be shown some text next to the head-button. You can edit that here.<br /> |
| 147 |
<br /> |
| 148 |
When empty, no message will be shown. |
| 149 |
</span> |
| 150 |
</span> |
| 151 |
Exit intent text', array( &$this, 'field_exit_intent_text' ) ); |
| 152 |
$this->aSubPages['advanced'] .= '</tbody></table>'; |
| 153 |
if ( !ButtonizerLicense()->is_not_paying() && !ButtonizerLicense()->is_plan( 'premium' ) ) { |
| 154 |
$this->aSubPages['advanced'] .= '<div class="buttonizer-pro-text"><i class="fa fa-lock"></i> You are missing the fun! When upgrading to <a href="admin.php?page=Buttonizer-pricing">Buttonizer Pro</a> you will get these features.</div>'; |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
public function registerSocialSettings() |
| 159 |
{ |
| 160 |
$this->aSubCatagories['social'] = 'Social share settings'; |
| 161 |
$this->aSubPages['social'] = '<table class="form-table"><tbody>'; |
| 162 |
// Facebook share button |
| 163 |
$this->aSubPages['social'] .= $this->createFormField( 'Share on Facebook', array( &$this, 'field_share_facebook' ) ); |
| 164 |
// Twitter share button |
| 165 |
$this->aSubPages['social'] .= $this->createFormField( 'Share on Twitter', array( &$this, 'field_share_twitter' ) ); |
| 166 |
// LinkedIn share button |
| 167 |
$this->aSubPages['social'] .= $this->createFormField( 'Share on LinkedIn', array( &$this, 'field_share_linkedin' ) ); |
| 168 |
$this->aSubPages['social'] .= '</tbody></table>'; |
| 169 |
} |
| 170 |
|
| 171 |
public function registerOther() |
| 172 |
{ |
| 173 |
$this->aSubCatagories['other'] = 'Other'; |
| 174 |
$this->aSubPages['other'] = '<table class="form-table"><tbody>'; |
| 175 |
$this->aSubPages['other'] .= '<tr><th scope="row">Reset Buttonizer</th><td><a href="?page=Buttonizer&tab=buttonizer_page_reset">More info</a></td></tr>'; |
| 176 |
$this->aSubPages['other'] .= '</tbody></table>'; |
| 177 |
} |
| 178 |
|
| 179 |
private function createFormField( $sLabel, $aFunction ) |
| 180 |
{ |
| 181 |
return '<tr><th scope="row">' . $sLabel . '</th><td>' . $aFunction() . '</td></tr>'; |
| 182 |
} |
| 183 |
|
| 184 |
/* |
| 185 |
* Form |
| 186 |
*/ |
| 187 |
public function field_button_unpushed() |
| 188 |
{ |
| 189 |
$button_unpushed = ( isset( $this->aSavedData['button_unpushed'] ) ? $this->aSavedData['button_unpushed'] : '#48A4DC' ); |
| 190 |
return '<input type="text" name="buttonizer_general_settings[button_unpushed]" value="' . $button_unpushed . '" id="button_unpushed" data-default-color="#fffff" />'; |
| 191 |
} |
| 192 |
|
| 193 |
public function field_button_pushed() |
| 194 |
{ |
| 195 |
$button_pushed = ( isset( $this->aSavedData['button_pushed'] ) ? $this->aSavedData['button_pushed'] : '#1D9BDB' ); |
| 196 |
return '<input type="text" name="buttonizer_general_settings[button_pushed]" value="' . $button_pushed . '" id="button_pushed" data-default-color="#fffff" />'; |
| 197 |
} |
| 198 |
|
| 199 |
public function field_icon_color() |
| 200 |
{ |
| 201 |
$icon_color = ( isset( $this->aSavedData['icon_color'] ) ? $this->aSavedData['icon_color'] : '#fffff' ); |
| 202 |
return '<input type="text" name="buttonizer_general_settings[icon_color]" value="' . $icon_color . '" id="icon_color" data-default-color="#fffff" />'; |
| 203 |
} |
| 204 |
|
| 205 |
public function field_icon_icon() |
| 206 |
{ |
| 207 |
$p = $this->oIconManager->generator( array( |
| 208 |
'icon' => ( isset( $this->aSavedData['icon_icon'] ) ? $this->aSavedData['icon_icon'] : '' ), |
| 209 |
'icon_fieldname' => 'buttonizer_general_settings[icon_icon]', |
| 210 |
'image' => ( isset( $this->aSavedData['custom_icon'] ) ? $this->aSavedData['custom_icon'] : '' ), |
| 211 |
'image_fieldname' => 'buttonizer_general_settings[custom_icon]', |
| 212 |
) ); |
| 213 |
return $p; |
| 214 |
} |
| 215 |
|
| 216 |
public function field_position_right() |
| 217 |
{ |
| 218 |
$position_right = ( isset( $this->aSavedData['position_right'] ) ? $this->aSavedData['position_right'] : '5' ); |
| 219 |
return '<input type="text" name="buttonizer_general_settings[position_right]" value="' . $position_right . '"/><small><i>%</i><br />Recommended 5% then it will position itself on the right corner</small>'; |
| 220 |
} |
| 221 |
|
| 222 |
public function field_position_bottom() |
| 223 |
{ |
| 224 |
$position_bottom = ( isset( $this->aSavedData['position_bottom'] ) ? $this->aSavedData['position_bottom'] : '5' ); |
| 225 |
return '<input type="text" name="buttonizer_general_settings[position_bottom]" value="' . $position_bottom . '"/><small><i>%</i><br>Recommended 5% then it will position itself on the bottom corner</small>'; |
| 226 |
} |
| 227 |
|
| 228 |
/* |
| 229 |
* Advanced |
| 230 |
*/ |
| 231 |
public function field_analytics_code() |
| 232 |
{ |
| 233 |
$google_analytics = ( isset( $this->aSavedData['google_analytics'] ) ? $this->aSavedData['google_analytics'] : '' ); |
| 234 |
return '<input type="text" name="buttonizer_general_settings[google_analytics]" value="' . $google_analytics . '" placeholder="Only when not inserted yet" style="width: 250px;"/>'; |
| 235 |
} |
| 236 |
|
| 237 |
public function field_show_on_scroll() |
| 238 |
{ |
| 239 |
return '<input type="checkbox" class="buttonizer-click-to-pro" readonly /> <span class="buttonizer-pro-feature">PRO</span>'; |
| 240 |
} |
| 241 |
|
| 242 |
public function field_procent_to_scroll() |
| 243 |
{ |
| 244 |
return '<input type="text" value="0" class="buttonizer-click-to-pro" readonly /><small><i>%</i></small> <span class="buttonizer-pro-feature">PRO</span>'; |
| 245 |
} |
| 246 |
|
| 247 |
public function field_show_on_timeout() |
| 248 |
{ |
| 249 |
return '<input type="checkbox" class="buttonizer-click-to-pro" readonly /> <span class="buttonizer-pro-feature">PRO</span>'; |
| 250 |
} |
| 251 |
|
| 252 |
public function field_time_to_timeout() |
| 253 |
{ |
| 254 |
return '<input type="text" class="buttonizer-click-to-pro" readonly value="0" /><span class="buttonizer-pro-feature">PRO</span>'; |
| 255 |
} |
| 256 |
|
| 257 |
// Exit intent |
| 258 |
public function field_exit_intent() |
| 259 |
{ |
| 260 |
return '<input type="checkbox" class="buttonizer-click-to-pro" readonly /> <span class="buttonizer-pro-feature">PRO</span>'; |
| 261 |
} |
| 262 |
|
| 263 |
public function field_exit_intent_text() |
| 264 |
{ |
| 265 |
return '<input type="text" class="buttonizer-click-to-pro" readonly value="" /><span class="buttonizer-pro-feature">PRO</span>'; |
| 266 |
} |
| 267 |
|
| 268 |
// Share page |
| 269 |
public function field_share_facebook() |
| 270 |
{ |
| 271 |
$share_facebook = ( isset( $this->aSavedData['share_facebook'] ) ? $this->aSavedData['share_facebook'] : '' ); |
| 272 |
$share_facebook_text = ( isset( $this->aSavedData['share_facebook_text'] ) ? $this->aSavedData['share_facebook_text'] : 'Share this on Facebook' ); |
| 273 |
return '<input type="checkbox" name="buttonizer_general_settings[share_facebook]" value="1" ' . (( $share_facebook == '1' ? 'checked="checked"' : '' )) . ' /> <input type="text" name="buttonizer_general_settings[share_facebook_text]" value="' . $share_facebook_text . '" placeholder="Share this on Facebook" style="vertical-align: middle; margin-left: 10px;" />'; |
| 274 |
} |
| 275 |
|
| 276 |
public function field_share_linkedin() |
| 277 |
{ |
| 278 |
$share_linkedin = ( isset( $this->aSavedData['share_linkedin'] ) ? $this->aSavedData['share_linkedin'] : '' ); |
| 279 |
$share_linkedin_text = ( isset( $this->aSavedData['share_linkedin_text'] ) ? $this->aSavedData['share_linkedin_text'] : 'Share this on LinkedIn' ); |
| 280 |
return '<input type="checkbox" name="buttonizer_general_settings[share_linkedin]" value="1" ' . (( $share_linkedin == '1' ? 'checked="checked"' : '' )) . ' /> <input type="text" name="buttonizer_general_settings[share_linkedin_text]" value="' . $share_linkedin_text . '" placeholder="Share this on LinkedIn" style="vertical-align: middle; margin-left: 10px;" />'; |
| 281 |
} |
| 282 |
|
| 283 |
public function field_share_twitter() |
| 284 |
{ |
| 285 |
$share_twitter = ( isset( $this->aSavedData['share_twitter'] ) ? $this->aSavedData['share_twitter'] : '' ); |
| 286 |
$share_twitter_text = ( isset( $this->aSavedData['share_twitter_text'] ) ? $this->aSavedData['share_twitter_text'] : 'Share this on Twitter' ); |
| 287 |
return '<input type="checkbox" name="buttonizer_general_settings[share_twitter]" value="1" ' . (( $share_twitter == '1' ? 'checked="checked"' : '' )) . ' /> <input type="text" name="buttonizer_general_settings[share_twitter_text]" value="' . $share_twitter_text . '" placeholder="Share this on Twitter" style="vertical-align: middle; margin-left: 10px;" />'; |
| 288 |
} |
| 289 |
|
| 290 |
} |