-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwp-dtree-cache.php
More file actions
96 lines (87 loc) · 2.71 KB
/
wp-dtree-cache.php
File metadata and controls
96 lines (87 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
//In WP 2.6, I suddenly got problems with global variables "dissapearing", so these getters are... Q&D.
function wpdt_get_table_name(){
global $wpdb; return $wpdb->prefix . "dtree_cache";
}
function wpdt_install_cache(){
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
global $wpdb;
$wpdt_cache = wpdt_get_table_name();
wpdt_uninstall_cache();
$charset_collate = '';
if(version_compare(mysql_get_server_info(), '4.1.0', '>=')){
if(!empty($wpdb->charset)){
$charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
}
if(!empty($wpdb->collate)){
$charset_collate .= " COLLATE {$wpdb->collate}";
}
}
$sql = "CREATE TABLE {$wpdt_cache} (
hash BINARY(16) NOT NULL,
content MEDIUMTEXT NOT NULL,
UNIQUE KEY hash (hash)
) {$charset_collate};";
dbDelta($sql);
}
function wpdt_uninstall_cache(){
global $wpdb;
$wpdt_cache = wpdt_get_table_name();
if($wpdb->get_var("SHOW TABLES LIKE '$wpdt_cache'") == $wpdt_cache) {
$wpdb->query("DROP TABLE " . $wpdt_cache);
}
}
/*we no longer have a single monoholotic cache.
when the blog changes, we simply invalidate all stored cache rows.*/
function wpdt_update_cache(){
global $wpdb;
$wpdt_cache = wpdt_get_table_name();
$wpdb->query("DELETE FROM {$wpdt_cache}");
}
function wpdt_get_seed($args){
global $wpdb;
return $wpdb->escape(serialize($args));
}
function wpdt_insert_tree_data($treedata, $seed){
if(!isset($treedata) || $treedata == ""){
return;
}
global $wpdb;
$wpdt_cache = wpdt_get_table_name();
$safeRow = $wpdb->escape($treedata);
$sql = "INSERT INTO ".$wpdt_cache
." (hash, content)
VALUES (UNHEX(MD5('{$seed}')),'".$safeRow."')";
$wpdb->query($sql);
}
function wpdt_get_cached_data($seed){
global $wpdb;
$wpdt_cache = wpdt_get_table_name();
$results = $wpdb->get_var("SELECT content FROM {$wpdt_cache} WHERE hash = UNHEX(MD5('{$seed}')) LIMIT 1");
return ($results) ? $results : '';
}
function wpdt_clear_cache($seed){ /*args = settings array for a tree*/
global $wpdb;
$wpdt_cache = wpdt_get_table_name();
$wpdb->query("DELETE FROM {$wpdt_cache} WHERE hash = UNHEX(MD5('{$seed}'))");
}
function wpdt_clean_exclusion_list($excluded){
$cleanlist = '';
if(empty($excluded)){ return $cleanlist; }
$exposts = preg_split('/[\s,]+/',$excluded);
if(!count($exposts)){ return $cleanlist; }
$exposts = array_unique($exposts);
foreach($exposts as $expostID){
if(!is_numeric($expostID)){continue;}
if(empty($cleanlist)){
$cleanlist = intval($expostID);
} else{
$cleanlist = $cleanlist . "," . intval($expostID);
}
}
return $cleanlist;
}
function wpdt_build_exclude_statement($excluded, $field = 'ID'){
return ($excluded) ? " AND {$field} NOT IN ($excluded) " : '';
}
?>