| 1 |
<?php |
| 2 |
/* |
| 3 |
This program is free software; you can redistribute it and/or |
| 4 |
modify it under the terms of the GNU General Public License |
| 5 |
as published by the Free Software Foundation; either version 2 |
| 6 |
of the License, or (at your option) any later version. |
| 7 |
|
| 8 |
This program is distributed in the hope that it will be useful, |
| 9 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
GNU General Public License for more details. |
| 12 |
|
| 13 |
You should have received a copy of the GNU General Public License |
| 14 |
along with this program; if not, write to the Free Software |
| 15 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 16 |
|
| 17 |
Copyright 2017 Buttonizer |
| 18 |
*/ |
| 19 |
namespace Buttonizer; |
| 20 |
|
| 21 |
# No script kiddies |
| 22 |
defined( 'ABSPATH' ) or die('No script kiddies please!'); |
| 23 |
|
| 24 |
class Maintain { |
| 25 |
|
| 26 |
// Construct |
| 27 |
public function __construct($sReady = false) { |
| 28 |
if(!$sReady) return; |
| 29 |
|
| 30 |
if (!session_id()) |
| 31 |
session_start(); |
| 32 |
|
| 33 |
register_activation_hook('buttonizer', array(&$this, 'pluginActivate')); |
| 34 |
register_deactivation_hook('buttonizer', array(&$this, 'pluginDeactivate')); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Activate Buttonizer, AWESOMAAH! |
| 39 |
*/ |
| 40 |
public function pluginActivate() { |
| 41 |
/* |
| 42 |
* General settings |
| 43 |
*/ |
| 44 |
$aGeneralSettings = get_option('buttonizer_general_settings'); |
| 45 |
|
| 46 |
// Check stored old data |
| 47 |
if($aGeneralSettings == ''){ |
| 48 |
$aGeneralSettings = array( |
| 49 |
'button_unpushed' => '#48A4DC', |
| 50 |
'button_pushed' => '#1D9BDB', |
| 51 |
'icon_color' => '#FFFFFF', |
| 52 |
'icon_icon' => 'fa-plus', |
| 53 |
'position_right' => '5', |
| 54 |
'position_bottom' => '5', |
| 55 |
'google_analytics' => '' |
| 56 |
); |
| 57 |
|
| 58 |
// Update and save general default settings |
| 59 |
update_option('buttonizer_general_settings', $aGeneralSettings); |
| 60 |
} |
| 61 |
|
| 62 |
/* |
| 63 |
* Add default buttons |
| 64 |
*/ |
| 65 |
$aButtonizerDefaultButtons = get_option('buttonizer_buttons'); |
| 66 |
|
| 67 |
// Check stored old data |
| 68 |
if($aButtonizerDefaultButtons == ''){ |
| 69 |
$aButtonizerDefaultButtons = []; |
| 70 |
|
| 71 |
// Update and save general default settings |
| 72 |
update_option('buttonizer_buttons', $aButtonizerDefaultButtons); |
| 73 |
} |
| 74 |
|
| 75 |
/* |
| 76 |
* Opening settings |
| 77 |
*/ |
| 78 |
$aDefaultOpeningSettings = get_option('buttonizer_opening_settings'); |
| 79 |
|
| 80 |
// Do we have old opening data? |
| 81 |
if($aDefaultOpeningSettings == '') { |
| 82 |
$aDefaultOpeningSettings = |
| 83 |
array( |
| 84 |
// Monday |
| 85 |
'monday_opened_from' => '10:00', |
| 86 |
'monday_closing_on' => '17:00', |
| 87 |
'monday_opened' => false, |
| 88 |
|
| 89 |
// Tuesday |
| 90 |
'tuesday_opened_from' => '10:00', |
| 91 |
'tuesday_closing_on' => '17:00', |
| 92 |
'tuesday_opened' => false, |
| 93 |
|
| 94 |
// Wednesday |
| 95 |
'wednesday_opened_from' => '10:00', |
| 96 |
'wednesday_closing_on' => '17:00', |
| 97 |
'wednesday_opened' => false, |
| 98 |
|
| 99 |
// Thursday |
| 100 |
'thursday_opened_from' => '10:00', |
| 101 |
'thursday_closing_on' => '17:00', |
| 102 |
'thursday_opened' => false, |
| 103 |
|
| 104 |
// Friday |
| 105 |
'friday_opened_from' => '10:00', |
| 106 |
'friday_closing_on' => '17:00', |
| 107 |
'friday_opened' => false, |
| 108 |
|
| 109 |
// Saturday |
| 110 |
'saturday_opened_from' => '10:00', |
| 111 |
'saturday_closing_on' => '17:00', |
| 112 |
'saturday_opened' => true, |
| 113 |
|
| 114 |
// Sunday |
| 115 |
'sunday_opened_from' => '10:00', |
| 116 |
'sunday_closing_on' => '17:00', |
| 117 |
'sunday_opened' => true, |
| 118 |
); |
| 119 |
|
| 120 |
// Update and save default opening settings |
| 121 |
update_option('buttonizer_opening_settings', $aDefaultOpeningSettings); |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Deactivate plugin, SEE YOU SOON! |
| 127 |
*/ |
| 128 |
public function pluginDeactivate(){ |
| 129 |
// Nothing to handle right now. Maybe later |
| 130 |
} |
| 131 |
|
| 132 |
/* |
| 133 |
* Mobile or desktop check |
| 134 |
*/ |
| 135 |
public function isMobile() { |
| 136 |
if ( |
| 137 |
isset($_SERVER['HTTP_USER_AGENT']) && |
| 138 |
( |
| 139 |
strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false || |
| 140 |
strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false || |
| 141 |
strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false || |
| 142 |
strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false || |
| 143 |
strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false || |
| 144 |
strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false || |
| 145 |
strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false |
| 146 |
) |
| 147 |
) |
| 148 |
{ |
| 149 |
// Is mobile |
| 150 |
return true; |
| 151 |
} else { |
| 152 |
// Is desktop |
| 153 |
return false; |
| 154 |
} |
| 155 |
} |
| 156 |
} |
| 157 |
|