forked from gogobody/SmmsForTypecho
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmms.function.php
More file actions
72 lines (61 loc) · 2.08 KB
/
Copy pathsmms.function.php
File metadata and controls
72 lines (61 loc) · 2.08 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
<?php
global $tdb;
$tdb = Typecho_Db::get();
define('MY_NEW_TABLE_NAME', 'smms_image_list');
define('MY_NEW_TABLE', $tdb->getPrefix() . 'smms_image_list');
// 插件激活时,运行回调方法创建数据表, 在WP原有的options表中插入插件版本号
function plugin_activation_cretable()
{
global $tdb;
$charset_collate = '';
if (!empty($tdb->charset)) {
$charset_collate = "DEFAULT CHARACTER SET {$tdb->charset}";
}
if (!empty($tdb->collate)) {
$charset_collate .= " COLLATE {$tdb->collate}";
}
$db = Typecho_Db::get();
$prefix = $db->getPrefix();
$type = explode('_', $db->getAdapterName());
$type = array_pop($type);
if($type == "SQLite"){
$sql ="SELECT count(*) FROM sqlite_master WHERE type='table' AND name='".MY_NEW_TABLE."';";
$checkTabel = $db->query($sql);
$row = $checkTabel->fetchAll();
if ($row[0]["count(*)"] == '0'){
$sql = "CREATE TABLE " . MY_NEW_TABLE . " (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
width INTEGER NOT NULL,
height INTEGER NOT NULL,
size INTEGER NOT NULL,
hash varchar(255) NOT NULL,
url varchar(255) NOT NULL
) $charset_collate;";
$tdb->query($sql);
}
}else{
$sql = 'SHOW TABLES LIKE "' . $prefix . 'smms_image_list' . '"';
$checkTabel = $db->query($sql);
$row = $checkTabel->fetchAll();
if ('1' == count($row)) {
// exist
}else{
$sql = "CREATE TABLE " . MY_NEW_TABLE . " (
id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
width int NOT NULL,
height int NOT NULL,
size int NOT NULL,
hash varchar(255) NOT NULL,
url varchar(255) NOT NULL
) $charset_collate;";
$tdb->query($sql);
}
}
}
// 插件停用时,运行回调方法删除数据表,删除options表中的插件版本号
function plugin_deactivation_deltable()
{
// global $tdb;
// 暂时不删除数据表
// $tdb->query("DROP TABLE IF EXISTS " . MY_NEW_TABLE);
}