| 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 Buttons |
| 25 |
{ |
| 26 |
private $aSavedData = array() ; |
| 27 |
private $aPageCategories = array() ; |
| 28 |
private $aFontAwesome = array() ; |
| 29 |
public function __construct( $aFontAwesome ) |
| 30 |
{ |
| 31 |
$this->aFontAwesome = $aFontAwesome; |
| 32 |
$this->loadData(); |
| 33 |
$this->loadButtons(); |
| 34 |
} |
| 35 |
|
| 36 |
private function loadData() |
| 37 |
{ |
| 38 |
$this->aSavedData = (array) get_option( 'buttonizer_buttons' ); |
| 39 |
$this->aPageCategories = (array) get_option( 'buttonizer_page_categories' ); |
| 40 |
} |
| 41 |
|
| 42 |
private function loadButtons() |
| 43 |
{ |
| 44 |
// Get buttons |
| 45 |
$aButtons = ( isset( $this->aSavedData['buttonorder'] ) && is_array( $this->aSavedData['buttonorder'] ) ? $this->aSavedData['buttonorder'] : array( |
| 46 |
0 => -1, |
| 47 |
) ); |
| 48 |
if ( $aButtons[0] != '-1' ) { |
| 49 |
$aButtons[-1] = '-1'; |
| 50 |
} |
| 51 |
echo '<ul id="button-rows">' ; |
| 52 |
$iButtonCount = 0; |
| 53 |
foreach ( $aButtons as $sButtonKey => $iButtonId ) { |
| 54 |
$this->loadIndividialButtonRow( $sButtonKey, $iButtonId, ( isset( $bDisabled ) ? true : false ) ); |
| 55 |
$iButtonCount++; |
| 56 |
} |
| 57 |
echo '</ul>' ; |
| 58 |
echo '<img src="' . plugins_url( '/assets/no-buttons.jpg', BUTTONIZER_PLUGIN_DIR ) . '" style="' . (( 0 == $iButtonCount - 1 ? 'display: block;' : 'display: none;' )) . '" class="buttonizer-no-buttons" />' ; |
| 59 |
} |
| 60 |
|
| 61 |
private function loadIndividialButtonRow( $sButtonKey, $iButtonId, $bDisabled ) |
| 62 |
{ |
| 63 |
$sButtonTitle = ( isset( $this->aSavedData['button_' . $iButtonId . '_title'] ) ? $this->aSavedData['button_' . $iButtonId . '_title'] : 'Button ' . ($iButtonId + 1) ); |
| 64 |
$onMobile = ( isset( $this->aSavedData['button_' . $iButtonId . '_show_on_phone'] ) ? $this->aSavedData['button_' . $iButtonId . '_show_on_phone'] : '' ); |
| 65 |
$onDesktop = ( isset( $this->aSavedData['button_' . $iButtonId . '_show_on_desktop'] ) ? $this->aSavedData['button_' . $iButtonId . '_show_on_desktop'] : '' ); |
| 66 |
?> |
| 67 |
<li> |
| 68 |
<div class="button-row" id="btn_row_<?php |
| 69 |
echo $iButtonId ; |
| 70 |
?> |
| 71 |
" button-id="<?php |
| 72 |
echo $iButtonId ; |
| 73 |
?> |
| 74 |
"<?php |
| 75 |
if ( $iButtonId == -1 ) { |
| 76 |
echo ' style="display: none"' ; |
| 77 |
} |
| 78 |
?> |
| 79 |
> |
| 80 |
<input type="checkbox" name="buttonizer_buttons[buttonorder][]" value="<?php |
| 81 |
echo $iButtonId ; |
| 82 |
?> |
| 83 |
" checked="checked" style="display: none;" /> |
| 84 |
|
| 85 |
<div class="row-info drag-handle"> |
| 86 |
<div class="mover"></div> |
| 87 |
<span><i class="fa <?php |
| 88 |
echo $this->buttonOutputIcon( $iButtonId ) ; |
| 89 |
?> |
| 90 |
button-icon"></i> <span class="row-title"><?php |
| 91 |
echo ( $iButtonId == -1 ? 'New button' : $sButtonTitle ) ; |
| 92 |
?> |
| 93 |
</span> <i class="fa fa-pencil pencil-edit"></i></span> |
| 94 |
|
| 95 |
<a href="javascript:buttonizer.removeRow(<?php |
| 96 |
echo $iButtonId ; |
| 97 |
?> |
| 98 |
)" class="delete-button">Delete <i class="fa fa-trash-o"></i></a> |
| 99 |
|
| 100 |
<a href="javascript:buttonizer.toggleMobile(<?php |
| 101 |
echo $iButtonId ; |
| 102 |
?> |
| 103 |
)" class="mobiledesktop mobile-button <?php |
| 104 |
echo ( $onMobile == '' ? 'selected' : '' ) ; |
| 105 |
?> |
| 106 |
"><i class="fa fa-mobile"></i></a> |
| 107 |
<a href="javascript:buttonizer.toggleDesktop(<?php |
| 108 |
echo $iButtonId ; |
| 109 |
?> |
| 110 |
)" class="mobiledesktop desktop-button <?php |
| 111 |
echo ( $onDesktop == '' ? 'selected' : '' ) ; |
| 112 |
?> |
| 113 |
"><i class="fa fa-desktop"></i></a> |
| 114 |
|
| 115 |
<a href="javascript:void(0)" class="is-live-button" style="<?php |
| 116 |
echo ( $onMobile != '' || $onDesktop != '' ? '' : 'display: none;' ) ; |
| 117 |
?> |
| 118 |
"><i class="fa fa-circle"></i> Live</a> |
| 119 |
|
| 120 |
<button type="submit" class="must-save-button savebutton " style="display: none;"><i class="fa fa-floppy-o"></i> Save changes</button> |
| 121 |
</div> |
| 122 |
|
| 123 |
<div class="button-data"> |
| 124 |
<table> |
| 125 |
<tr style="display: none;"> |
| 126 |
<td width="20%"></td> |
| 127 |
<td width="20%"></td> |
| 128 |
<td></td> |
| 129 |
</tr> |
| 130 |
<tr> |
| 131 |
<td> |
| 132 |
<label for="button_text" class="label-top"> |
| 133 |
<span class="info-class"><i class="fa fa-info-circle"></i> <span>This is for internal use only.<br /><br />When using Google Analytics, this will be the title of the event when clicking this button.</span></span> |
| 134 |
Button name: |
| 135 |
</label> |
| 136 |
<input type="text" name="buttonizer_buttons[button_<?php |
| 137 |
echo $iButtonId ; |
| 138 |
?> |
| 139 |
_title]" value="<?php |
| 140 |
echo $sButtonTitle ; |
| 141 |
?> |
| 142 |
" class="button_title" /> |
| 143 |
</td> |
| 144 |
<td class="button-pdr" colspan="2"> |
| 145 |
<label for="button_icon" class="label-top"> |
| 146 |
<span class="info-class"><i class="fa fa-info-circle"></i> <span>This will be the icon of the button. You can choose from the build-in Font Awesome icons.<br /><br />When you want to use your own icon or image, you can click the 'or upload an image' link to use your own icon.</span></span> |
| 147 |
Button icon: |
| 148 |
</label> |
| 149 |
<?php |
| 150 |
echo $this->buttonGetIcon( $iButtonId ) ; |
| 151 |
?> |
| 152 |
</td> |
| 153 |
</tr> |
| 154 |
|
| 155 |
<tr> |
| 156 |
<td> </td> |
| 157 |
<td></td> |
| 158 |
<td></td> |
| 159 |
</tr> |
| 160 |
|
| 161 |
<tr> |
| 162 |
<td> |
| 163 |
<label for="button_text" class="label-top"> |
| 164 |
<span class="info-class"><i class="fa fa-info-circle"></i> <span>This is the label what the guest on your website will see. Something like 'Contact me!', or 'Like us on Facebook'</span></span> |
| 165 |
Button label: |
| 166 |
</label> |
| 167 |
<?php |
| 168 |
echo $this->buttonGetText( $iButtonId ) ; |
| 169 |
?> |
| 170 |
</td> |
| 171 |
<td colspan="2"> |
| 172 |
<label for="button_category" class="label-top"> |
| 173 |
<span class="info-class"><i class="fa fa-info-circle"></i> <span>Select a page category. You can add more page rules at the 'Page categories' tab.</span></span> |
| 174 |
Button page category: |
| 175 |
</label> |
| 176 |
<?php |
| 177 |
echo $this->buttonGetShowOnPages( $iButtonId ) ; |
| 178 |
?> |
| 179 |
</td> |
| 180 |
</tr> |
| 181 |
|
| 182 |
<tr> |
| 183 |
<td> </td> |
| 184 |
<td></td> |
| 185 |
<td></td> |
| 186 |
</tr> |
| 187 |
|
| 188 |
<tr class="settings-row"> |
| 189 |
<td> |
| 190 |
<i class="fa fa-globe setting-icon"></i> URL or phone-number |
| 191 |
<span class="info-class"><i class="fa fa-info-circle"></i> <span>This is the click-action of your button. You can input a full url (http://myawesomewebsite.com), a URI (/contact), an anchor-link (#anchor) or a phone number. Note that if you input a phone number that you select the option ‘Is phone number’. This will be a direct click-to-call action. Please don’t add a full url without the http:// (like: www.myawesomewebsite.com). </span></span> |
| 192 |
</td> |
| 193 |
<td colspan="2"><?php |
| 194 |
echo $this->buttonGetUrl( $iButtonId ) ; |
| 195 |
?> |
| 196 |
</td> |
| 197 |
</tr> |
| 198 |
|
| 199 |
<tr class="settings-row"> |
| 200 |
<td> |
| 201 |
<i class="fa fa-phone setting-icon"></i> Is phone number |
| 202 |
</td> |
| 203 |
<td><?php |
| 204 |
echo $this->buttonGetIsPhoneNumber( $iButtonId ) ; |
| 205 |
?> |
| 206 |
<label for="button_<?php |
| 207 |
echo $iButtonId ; |
| 208 |
?> |
| 209 |
_is_phonenumber"> Yes</label></td> |
| 210 |
<td></td> |
| 211 |
</tr> |
| 212 |
|
| 213 |
<tr class="settings-row setting-new-tab"> |
| 214 |
<td> |
| 215 |
<i class="fa fa-external-link setting-icon"></i> Open in new tab |
| 216 |
</td> |
| 217 |
<td><?php |
| 218 |
echo $this->buttonGetNewTab( $iButtonId ) ; |
| 219 |
?> |
| 220 |
<label for="button_<?php |
| 221 |
echo $iButtonId ; |
| 222 |
?> |
| 223 |
_url_newtab"> Yes</label></td> |
| 224 |
<td></td> |
| 225 |
</tr> |
| 226 |
|
| 227 |
<tr> |
| 228 |
<td> </td> |
| 229 |
<td></td> |
| 230 |
<td></td> |
| 231 |
</tr> |
| 232 |
|
| 233 |
<tr class="settings-row"> |
| 234 |
<td> |
| 235 |
<i class="fa fa-mobile setting-icon"></i> Show on mobile |
| 236 |
</td> |
| 237 |
<td><?php |
| 238 |
echo $this->buttonGetShowPhone( $iButtonId ) ; |
| 239 |
?> |
| 240 |
<label for="button_<?php |
| 241 |
echo $iButtonId ; |
| 242 |
?> |
| 243 |
_show_on_phone"> Yes</label></td> |
| 244 |
<td></td> |
| 245 |
</tr> |
| 246 |
|
| 247 |
<tr class="settings-row"> |
| 248 |
<td> |
| 249 |
<i class="fa fa-desktop setting-icon"></i> Show on desktop |
| 250 |
</td> |
| 251 |
<td><?php |
| 252 |
echo $this->buttonGetShowDesktop( $iButtonId ) ; |
| 253 |
?> |
| 254 |
<label for="button_<?php |
| 255 |
echo $iButtonId ; |
| 256 |
?> |
| 257 |
_show_on_desktop"> Yes</label></td> |
| 258 |
<td></td> |
| 259 |
</tr> |
| 260 |
|
| 261 |
<tr class="settings-row"> |
| 262 |
<td> |
| 263 |
<i class="fa fa-tag setting-icon"></i> Hide label |
| 264 |
|
| 265 |
<span class="info-class"> |
| 266 |
<i class="fa fa-info-circle"></i> |
| 267 |
<span> |
| 268 |
This is the label what the guest on your website will see. Something like 'Contact me!', or 'Like us on Facebook' |
| 269 |
</span> |
| 270 |
</span> |
| 271 |
</td> |
| 272 |
<td><?php |
| 273 |
echo $this->buttonGetHideLabel( $iButtonId ) ; |
| 274 |
?> |
| 275 |
<label for="button_<?php |
| 276 |
echo $iButtonId ; |
| 277 |
?> |
| 278 |
_hide_label"> Yes</label></td> |
| 279 |
<td></td> |
| 280 |
</tr> |
| 281 |
|
| 282 |
<tr> |
| 283 |
<td> </td> |
| 284 |
<td></td> |
| 285 |
<td></td> |
| 286 |
</tr> |
| 287 |
|
| 288 |
<?php |
| 289 |
?> |
| 290 |
<tr class="settings-row"> |
| 291 |
<td> |
| 292 |
<i class="fa fa-clock-o setting-icon"></i> Show <b>only</b> on opening hours |
| 293 |
</td> |
| 294 |
<td><input type="checkbox" class="buttonizer-click-to-pro" readonly=""> <label> Yes</label> <span class="buttonizer-pro-feature">PRO</span></td> <td></td> |
| 295 |
</tr> |
| 296 |
|
| 297 |
<tr class="settings-row"> |
| 298 |
<td> |
| 299 |
<i class="fa fa-times-circle-o setting-icon"></i> Show <b>only outside</b> opening hours |
| 300 |
</td> |
| 301 |
<td><input type="checkbox" class="buttonizer-click-to-pro" readonly=""> <label> Yes</label> <span class="buttonizer-pro-feature">PRO</span></td> |
| 302 |
<td></td> |
| 303 |
</tr> |
| 304 |
<?php |
| 305 |
?> |
| 306 |
</table> |
| 307 |
</div> |
| 308 |
</div> |
| 309 |
</li> |
| 310 |
<?php |
| 311 |
} |
| 312 |
|
| 313 |
/* |
| 314 |
* Form functions |
| 315 |
*/ |
| 316 |
// Get the text of the button |
| 317 |
public function buttonGetText( $iButtonId = 0 ) |
| 318 |
{ |
| 319 |
$fieldName = 'button_' . $iButtonId . '_text'; |
| 320 |
$fieldValue = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : 'New button' ); |
| 321 |
return '<input type="text" name="buttonizer_buttons[' . $fieldName . ']" id="' . $fieldName . '" value="' . $fieldValue . '" class="button_textfield" placeholder="Button text" />'; |
| 322 |
} |
| 323 |
|
| 324 |
// Get button icon |
| 325 |
public function buttonGetIcon( $iButtonId = 0 ) |
| 326 |
{ |
| 327 |
$fieldName = 'button_' . $iButtonId . '_icon'; |
| 328 |
$fab_icon_image = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : '' ); |
| 329 |
$p = '<select name="buttonizer_buttons[' . $fieldName . ']" id="' . $fieldName . '" style="font-family: \'FontAwesome\', \'Helvetica\';" class="button_iconfield fa-chooser">'; |
| 330 |
foreach ( $this->aFontAwesome as $key => $row ) { |
| 331 |
$p .= '<option value="' . $key . '" ' . (( $fab_icon_image == $key ? 'selected="selected"' : '' )) . '>' . $row . ' ' . $key . '</option>'; |
| 332 |
} |
| 333 |
return $p; |
| 334 |
} |
| 335 |
|
| 336 |
// Get button icon |
| 337 |
public function buttonOutputIcon( $iButtonId = 0 ) |
| 338 |
{ |
| 339 |
$fieldName = 'button_' . $iButtonId . '_icon'; |
| 340 |
return ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : 'fa-info' ); |
| 341 |
} |
| 342 |
|
| 343 |
// Only show this button on phone? |
| 344 |
public function buttonGetShowPhone( $iButtonId = 0 ) |
| 345 |
{ |
| 346 |
$fieldName = 'button_' . $iButtonId . '_show_on_phone'; |
| 347 |
$is_selected = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : '' ); |
| 348 |
return '<input type="checkbox" name="buttonizer_buttons[' . $fieldName . ']" id="' . $fieldName . '" value="1" class="button_showonphone" ' . (( $is_selected == '1' ? 'checked="checked"' : '' )) . ' />'; |
| 349 |
} |
| 350 |
|
| 351 |
// buttonGetShowOnPages |
| 352 |
public function buttonGetShowOnPages( $iButtonId = 0 ) |
| 353 |
{ |
| 354 |
$fieldName = 'button_' . $iButtonId . '_show_on_pages'; |
| 355 |
$is_selected = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : '' ); |
| 356 |
$pageOrders = ( isset( $this->aPageCategories['categorieOrder'] ) ? $this->aPageCategories['categorieOrder'] : array() ); |
| 357 |
/* |
| 358 |
* Generate <select> |
| 359 |
*/ |
| 360 |
$html = '<select name="buttonizer_buttons[' . $fieldName . ']" id="button_category"><option value="-5">Show on every page</option><option value="-4">Hide everywhere</option>'; |
| 361 |
foreach ( $pageOrders as $arrayKey => $pageKey ) { |
| 362 |
if ( $pageKey == -1 ) { |
| 363 |
continue; |
| 364 |
} |
| 365 |
$html .= '<option value="' . $pageKey . '"' . (( $pageKey == $is_selected ? 'selected="selected"' : '' )) . '>' . $this->aPageCategories['category_' . $pageKey . '_title'] . '</option>'; |
| 366 |
} |
| 367 |
return $html . '</select>'; |
| 368 |
} |
| 369 |
|
| 370 |
// Only show this button on desktop? |
| 371 |
public function buttonGetShowDesktop( $iButtonId = 0 ) |
| 372 |
{ |
| 373 |
$fieldName = 'button_' . $iButtonId . '_show_on_desktop'; |
| 374 |
$is_selected = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : '' ); |
| 375 |
return '<input type="checkbox" name="buttonizer_buttons[' . $fieldName . ']" id="' . $fieldName . '" value="1" class="button_showondesktop" ' . (( $is_selected == '1' ? 'checked="checked"' : '' )) . ' />'; |
| 376 |
} |
| 377 |
|
| 378 |
// Only show when company is open? |
| 379 |
public function buttonGetShowWenOpen( $iButtonId = 0 ) |
| 380 |
{ |
| 381 |
$fieldName = 'button_' . $iButtonId . '_show_when_opened'; |
| 382 |
$is_selected = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : '' ); |
| 383 |
return '<input type="checkbox" name="buttonizer_buttons[' . $fieldName . ']" id="' . $fieldName . '" value="1" class="button_showwhenopened" ' . (( $is_selected == '1' ? 'checked="checked"' : '' )) . ' />'; |
| 384 |
} |
| 385 |
|
| 386 |
// Only show when company is open? |
| 387 |
public function buttonGetShowNotWenOpen( $iButtonId = 0 ) |
| 388 |
{ |
| 389 |
$fieldName = 'button_' . $iButtonId . '_show_not_when_opened'; |
| 390 |
$is_selected = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : '' ); |
| 391 |
return '<input type="checkbox" name="buttonizer_buttons[' . $fieldName . ']" id="' . $fieldName . '" value="1" class="button_showwhenopened" ' . (( $is_selected == '1' ? 'checked="checked"' : '' )) . ' />'; |
| 392 |
} |
| 393 |
|
| 394 |
public function buttonGetHideLabel( $iButtonId = 0 ) |
| 395 |
{ |
| 396 |
$fieldName = 'button_' . $iButtonId . '_hide_label'; |
| 397 |
$is_selected = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : '' ); |
| 398 |
return '<input type="checkbox" name="buttonizer_buttons[' . $fieldName . ']" id="' . $fieldName . '" value="1" class="button_hidelabel" ' . (( $is_selected == '1' ? 'checked="checked"' : '' )) . ' />'; |
| 399 |
} |
| 400 |
|
| 401 |
// Is this a phone number? |
| 402 |
public function buttonGetIsPhoneNumber( $iButtonId = 0 ) |
| 403 |
{ |
| 404 |
$fieldName = 'button_' . $iButtonId . '_is_phonenumber'; |
| 405 |
$is_selected = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : '' ); |
| 406 |
return '<input type="checkbox" name="buttonizer_buttons[' . $fieldName . ']" id="' . $fieldName . '" value="1" class="button_isphonenumber" ' . (( $is_selected == '1' ? 'checked="checked"' : '' )) . ' />'; |
| 407 |
} |
| 408 |
|
| 409 |
public function buttonGetUrl( $iButtonId = 0 ) |
| 410 |
{ |
| 411 |
$fieldName = 'button_' . $iButtonId . '_url'; |
| 412 |
$fieldValue = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : '' ); |
| 413 |
return '<input type="text" name="buttonizer_buttons[' . $fieldName . ']" id="' . $fieldName . '" value="' . $fieldValue . '" class="button_isurl" placeholder="URL/Phone number" />'; |
| 414 |
} |
| 415 |
|
| 416 |
// Only show this button on phone? |
| 417 |
public function buttonGetNewTab( $iButtonId = 0 ) |
| 418 |
{ |
| 419 |
$fieldName = 'button_' . $iButtonId . '_url_newtab'; |
| 420 |
$is_selected = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : '' ); |
| 421 |
return '<input type="checkbox" name="buttonizer_buttons[' . $fieldName . ']" id="' . $fieldName . '" value="1" class="button_isnewtab" ' . (( $is_selected == '1' ? 'checked="checked"' : '' )) . ' />'; |
| 422 |
} |
| 423 |
|
| 424 |
} |