HTML
1 year ago
views
5 months ago
Apply.php
6 months ago
Cron.php
1 year ago
CronJob.php
7 months ago
CronJobs.php
2 months ago
Crypt.php
1 month ago
DownloadStats.php
5 months ago
Email.php
4 days ago
EmailCron.php
1 year ago
FileSystem.php
1 year ago
Installer.php
2 hours ago
Messages.php
1 year ago
Query.php
4 months ago
Session.php
2 hours ago
Settings.php
4 years ago
SimpleMath.php
4 years ago
TempStorage.php
2 hours ago
Template.php
5 months ago
UI.php
6 months ago
Updater.php
4 years ago
UserAgent.php
2 years ago
__.php
1 month ago
__MailUI.php
3 years ago
TempStorage.php
102 lines
| 1 | <?php |
| 2 | /** |
| 3 | * User: shahnuralam |
| 4 | * Date: 4/11/18 |
| 5 | * Time: 1:10 PM |
| 6 | * From v4.7.9 |
| 7 | * Last Updated: 10/11/2018 |
| 8 | */ |
| 9 | |
| 10 | |
| 11 | namespace WPDM\__; |
| 12 | |
| 13 | class TempStorage |
| 14 | { |
| 15 | static $data; |
| 16 | |
| 17 | // deviceID scope for durable rows (e.g. shareable/emailed download keys) that |
| 18 | // must survive cache-clear (TempStorage::clear) and session reset (Session::reset). |
| 19 | const DURABLE_SCOPE = 'wpdmkey'; |
| 20 | |
| 21 | function __construct() |
| 22 | { |
| 23 | /*if(file_exists(WPDM_CACHE_DIR.'/temp-storage.txt')) { |
| 24 | $data = file_get_contents(WPDM_CACHE_DIR . '/temp-storage.txt'); |
| 25 | $data = Crypt::decrypt($data); |
| 26 | if(!is_array($data)) $data = array(); |
| 27 | } else { |
| 28 | $data = array(); |
| 29 | } |
| 30 | self::$data = $data;*/ |
| 31 | |
| 32 | //register_shutdown_function(array($this, 'saveData')); |
| 33 | } |
| 34 | |
| 35 | static function set($name, $value, $expire = 604800, $deviceID = 'alldevice') |
| 36 | { // 604800 secs = 1 week |
| 37 | global $wpdb; |
| 38 | self::kill($name); |
| 39 | $wpdb->insert("{$wpdb->prefix}ahm_sessions", array('deviceID' => $deviceID, 'name' => $name, 'value' => maybe_serialize($value), 'lastAccess' => time(), 'expire' => time() + $expire)); |
| 40 | } |
| 41 | |
| 42 | static function get($name, $deviceID = null) |
| 43 | { |
| 44 | global $wpdb; |
| 45 | $now = time(); |
| 46 | if ($deviceID !== null) |
| 47 | $value = $wpdb->get_var($wpdb->prepare("select `value` from {$wpdb->prefix}ahm_sessions where `expire` > %d and `name` = %s and `deviceID` = %s", $now, $name, $deviceID)); |
| 48 | else |
| 49 | $value = $wpdb->get_var($wpdb->prepare("select `value` from {$wpdb->prefix}ahm_sessions where `expire` > %d and `name` = %s", $now, $name)); |
| 50 | return maybe_unserialize($value); |
| 51 | } |
| 52 | |
| 53 | static function kill($name, $deviceID = null) |
| 54 | { |
| 55 | global $wpdb; |
| 56 | if ($deviceID !== null) |
| 57 | $wpdb->delete("{$wpdb->prefix}ahm_sessions", ["name" => $name, "deviceID" => $deviceID]); |
| 58 | else |
| 59 | $wpdb->delete("{$wpdb->prefix}ahm_sessions", ["name" => $name]); |
| 60 | } |
| 61 | |
| 62 | static function clear() |
| 63 | { |
| 64 | global $wpdb; |
| 65 | $wpdb->query("delete from {$wpdb->prefix}ahm_sessions where deviceID = 'alldevice'"); |
| 66 | } |
| 67 | |
| 68 | function __destruct() |
| 69 | { |
| 70 | /*if(is_array(self::$data)) { |
| 71 | foreach (self::$data as $name => $_value){ |
| 72 | extract($_value); |
| 73 | if(!is_array($_value) || !isset($_value['expire']) || $_value['expire'] < time()) { |
| 74 | unset(self::$data[$name]); |
| 75 | } |
| 76 | } |
| 77 | $data = Crypt::encrypt(self::$data); |
| 78 | file_put_contents(WPDM_CACHE_DIR . '/temp-storage.txt', $data); |
| 79 | }*/ |
| 80 | } |
| 81 | |
| 82 | static function saveData() |
| 83 | { |
| 84 | /*if(is_array(self::$data)) { |
| 85 | foreach (self::$data as $name => $_value){ |
| 86 | extract($_value); |
| 87 | if(!is_array($_value) || !isset($_value['expire']) || $_value['expire'] < time()) { |
| 88 | unset(self::$data[$name]); |
| 89 | } |
| 90 | } |
| 91 | $data = Crypt::encrypt(self::$data); |
| 92 | if(!file_exists(WPDM_CACHE_DIR)) |
| 93 | @mkdir(WPDM_CACHE_DIR, 0755, true); |
| 94 | file_put_contents(WPDM_CACHE_DIR . '/temp-storage.txt', $data); |
| 95 | }*/ |
| 96 | |
| 97 | } |
| 98 | |
| 99 | } |
| 100 | |
| 101 | new TempStorage(); |
| 102 |