| @@ -160,8 +160,47 @@ | ||
| 160 | 160 | return $hash; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
| 164 | + * Returns the installation date of the plugin. | |
| 165 | + * | |
| 166 | + * @return string|null | |
| 167 | + * | |
| 168 | + * @since 1.8.8 | |
| 169 | + */ | |
| 170 | + public static function getInstallDate() | |
| 171 | + { | |
| 172 | + // fetch install date from database | |
| 173 | + $date = get_option('vikbooking_install_date'); | |
| 174 | + | |
| 175 | + if ($date) { | |
| 176 | + return $date; | |
| 177 | + } | |
| 178 | + | |
| 179 | + // Date not registered on database... | |
| 180 | + // We can estimate the installation date fairly accurately by checking the creation | |
| 181 | + // timestamp of the "vikbooking" folder in the WordPress uploads directory. | |
| 182 | + $uploadsDir = wp_upload_dir(); | |
| 183 | + | |
| 184 | + if (!is_array($uploadsDir) || empty($uploadsDir['basedir'])) { | |
| 185 | + // uploads folder not configured | |
| 186 | + return null; | |
| 187 | + } | |
| 188 | + | |
| 189 | + // create path | |
| 190 | + $path = JPath::clean($uploadsDir['basedir'] . '/vikbooking'); | |
| 191 | + | |
| 192 | + // make sure the folder exists | |
| 193 | + if (!JFolder::exists($path)) { | |
| 194 | + // missing folder | |
| 195 | + return null; | |
| 196 | + } | |
| 197 | + | |
| 198 | + // read modify timestamp for uploads folder | |
| 199 | + return date('Y-m-d H:i:s', filemtime($path)); | |
| 200 | + } | |
| 201 | + | |
| 202 | + /** | |
| 164 | 203 | * Registers some options upon installation of the plugin. |
| 165 | 204 | * |
| 166 | 205 | * @return void |
| 167 | 206 | */ |
| @@ -170,8 +209,9 @@ | ||
| 170 | 209 | update_option('vikbooking_license_key', ''); |
| 171 | 210 | update_option('vikbooking_license_expdate', 0); |
| 172 | 211 | update_option('vikbooking_license_hash', ''); |
| 173 | 212 | update_option('vikbooking_hide_vcmad', 0); |
| 213 | + update_option('vikbooking_install_date', date('Y-m-d H:i:s')); | |
| 174 | 214 | } |
| 175 | 215 | |
| 176 | 216 | /** |
| 177 | 217 | * Deletes all the options upon uninstallation of the plugin. |
| @@ -183,6 +223,7 @@ | ||
| 183 | 223 | delete_option('vikbooking_license_key'); |
| 184 | 224 | delete_option('vikbooking_license_expdate'); |
| 185 | 225 | delete_option('vikbooking_license_hash'); |
| 186 | 226 | delete_option('vikbooking_hide_vcmad'); |
| 227 | + delete_option('vikbooking_install_date'); | |
| 187 | 228 | } |
| 188 | 229 | } |