PluginProbe ʕ •ᴥ•ʔ
LiteSpeed Cache / 1.9.1.1
LiteSpeed Cache v1.9.1.1
trunk 1.0.15 1.9.1.1 2.9.9.2 3.6.4 4.6 5.7.0.1 6.5.4 7.0.0.1 7.0.1 7.1 7.2 7.3 7.3.0.1 7.4 7.5 7.5.0.1 7.6 7.6.1 7.6.2 7.7 7.8 7.8.0.1 7.8.1
litespeed-cache / inc / data.class.php
litespeed-cache / inc Last commit date
activation.class.php 8 years ago api.class.php 8 years ago cdn.class.php 8 years ago config.class.php 8 years ago control.class.php 8 years ago crawler-sitemap.class.php 8 years ago crawler.class.php 8 years ago data.class.php 8 years ago esi.class.php 8 years ago gui.class.php 8 years ago import.class.php 8 years ago litespeed-cache.class.php 8 years ago litespeed.autoload.php 8 years ago log.class.php 8 years ago media.class.php 8 years ago object.class.php 8 years ago object.lib.php 8 years ago optimize.class.php 8 years ago optimizer.class.php 8 years ago purge.class.php 8 years ago router.class.php 8 years ago tag.class.php 8 years ago task.class.php 8 years ago utility.class.php 8 years ago vary.class.php 8 years ago
data.class.php
195 lines
1 <?php
2
3 /**
4 * The class to store and manage litespeed db data.
5 *
6 * @since 1.3.1
7 * @since 1.5 Moved into /inc
8 * @package LiteSpeed_Cache
9 * @subpackage LiteSpeed_Cache/inc
10 * @author LiteSpeed Technologies <info@litespeedtech.com>
11 */
12
13 class LiteSpeed_Cache_Data
14 {
15 private static $_instance ;
16
17 const TB_OPTIMIZER = 'litespeed_optimizer' ;
18
19 private $_charset_collate ;
20 private $_tb_optm ;
21
22 /**
23 * Init
24 *
25 * @since 1.3.1
26 * @access private
27 */
28 private function __construct()
29 {
30 LiteSpeed_Cache_Log::debug2( 'Data init' ) ;
31 global $wpdb ;
32
33 $this->_charset_collate = $wpdb->get_charset_collate() ;
34
35 $this->_tb_optm = $wpdb->base_prefix . self::TB_OPTIMIZER ;
36
37 $this->_optm_sync() ;
38 }
39
40 /**
41 * Get optimizer table
42 *
43 * @since 1.4
44 * @access public
45 */
46 public static function get_optm_table()
47 {
48 return self::get_instance()->_tb_optm ;
49 }
50
51 /**
52 * Check if optimizer table exists or not
53 *
54 * @since 1.3.1.1
55 * @access public
56 */
57 public static function optm_available()
58 {
59 global $wpdb ;
60 $instance = self::get_instance() ;
61 return $wpdb->get_var( "SHOW TABLES LIKE '$instance->_tb_optm'" ) ;
62 }
63
64 /**
65 * Create optimizer table
66 *
67 * @since 1.3.1
68 * @access private
69 */
70 private function _optm_sync()
71 {
72 if ( defined( 'LITESPEED_DID_' . __FUNCTION__ ) ) {
73 return ;
74 }
75 define( 'LITESPEED_DID_' . __FUNCTION__, true ) ;
76
77 global $wpdb ;
78
79 LiteSpeed_Cache_Log::debug2( 'Data: Checking optm table' ) ;
80
81 // Check if table exists first
82 if ( $wpdb->get_var( "SHOW TABLES LIKE '$this->_tb_optm'" ) ) {
83 LiteSpeed_Cache_Log::debug2( 'Data: Existed' ) ;
84 return ;
85 }
86
87 LiteSpeed_Cache_Log::debug( 'Data: Creating optm table' ) ;
88
89 $sql = sprintf(
90 'CREATE TABLE IF NOT EXISTS `%1$s` (
91 `id` int(11) NOT NULL AUTO_INCREMENT,
92 `hash_name` varchar(60) NOT NULL COMMENT "hash.filetype",
93 `src` text NOT NULL COMMENT "full url array set",
94 `dateline` int(11) NOT NULL,
95 `refer` varchar(255) NOT NULL COMMENT "The container page url",
96 PRIMARY KEY (`id`),
97 UNIQUE KEY `hash_name` (`hash_name`),
98 KEY `dateline` (`dateline`)
99 ) %2$s;',
100 $this->_tb_optm,
101 $this->_charset_collate
102 ) ;
103
104 $wpdb->query( $sql ) ;
105
106 // Move data from wp_options to here
107 $hashes = get_option( 'litespeed-cache-optimized' ) ;
108 if ( $hashes ) {
109 foreach ( $hashes as $k => $v ) {
110 $f = array(
111 'hash_name' => $k,
112 'src' => serialize( $v ),
113 'dateline' => time(),
114 'refer' => '',
115 ) ;
116 $wpdb->replace( $this->_tb_optm, $f ) ;
117 }
118 }
119 delete_option( 'litespeed-cache-optimized' ) ;
120
121 // Record tb version
122 update_option( $this->_tb_optm, LiteSpeed_Cache::PLUGIN_VERSION ) ;
123
124 }
125
126 /**
127 * save optimizer src to db
128 *
129 * @since 1.3.1
130 * @access public
131 */
132 public static function optm_save_src( $filename, $src )
133 {
134 $instance = self::get_instance() ;
135 return $instance->_optm_save_src( $filename, $src ) ;
136 }
137 private function _optm_save_src( $filename, $src )
138 {
139 global $wpdb ;
140
141 $src = serialize( $src ) ;
142 $f = array(
143 'hash_name' => $filename,
144 'src' => $src,
145 'dateline' => time(),
146 'refer' => ! empty( $_SERVER[ 'SCRIPT_URI' ] ) ? $_SERVER[ 'SCRIPT_URI' ] : '',
147 ) ;
148
149 $res = $wpdb->replace( $this->_tb_optm, $f ) ;
150
151 return $res ;
152 }
153
154 /**
155 * Get src set from hash in optimizer
156 *
157 * @since 1.3.1
158 * @access public
159 */
160 public static function optm_hash2src( $filename )
161 {
162 $instance = self::get_instance() ;
163 return $instance->_optm_hash2src( $filename ) ;
164 }
165 private function _optm_hash2src( $filename )
166 {
167 global $wpdb ;
168
169 $sql = $wpdb->prepare( 'SELECT src FROM `' . $this->_tb_optm . '` WHERE `hash_name` = %s', $filename ) ;
170 $res = $wpdb->get_var( $sql ) ;
171
172 LiteSpeed_Cache_Log::debug2( 'Data: Loaded hash2src ' . $res ) ;
173
174 $res = unserialize( $res ) ;
175
176 return $res ;
177 }
178
179 /**
180 * Get the current instance object.
181 *
182 * @since 1.3.1
183 * @access public
184 * @return Current class instance.
185 */
186 public static function get_instance()
187 {
188 if ( ! isset( self::$_instance ) ) {
189 self::$_instance = new self() ;
190 }
191
192 return self::$_instance ;
193 }
194
195 }