|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace florinp\messenger; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
class ext extends \phpbb\extension\base |
|
7
|
|
|
{ |
|
8
|
|
|
|
|
9
|
|
|
public function enable_step($old_state) |
|
10
|
|
|
{ |
|
11
|
|
|
global $phpbb_root_path; |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
switch ($old_state) { |
|
14
|
|
|
case '': |
|
15
|
|
|
$db = new \florinp\messenger\libs\database(); |
|
16
|
|
|
$db->exec(" |
|
17
|
|
|
CREATE TABLE IF NOT EXISTS messages ( |
|
18
|
|
|
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, |
|
19
|
|
|
`sender_id` INTEGER NOT NULL, |
|
20
|
|
|
`receiver_id` INTEGER NOT NULL, |
|
21
|
|
|
`text` TEXT NOT NULL, |
|
22
|
|
|
`newMsg` INTEGER DEFAULT 0, |
|
23
|
|
|
`sentAt` INTEGER NOT NULL |
|
24
|
|
|
); |
|
25
|
|
|
CREATE TABLE IF NOT EXISTS files ( |
|
26
|
|
|
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, |
|
27
|
|
|
`sender_id` INTEGER NOT NULL, |
|
28
|
|
|
`receiver_id` INTEGER NOT NULL, |
|
29
|
|
|
`fileName` VARCHAR(255) NOT NULL, |
|
30
|
|
|
`file` VARCHAR(255) NOT NULL, |
|
31
|
|
|
`type` VARCHAR(255) NOT NULL, |
|
32
|
|
|
`sentAt` INTEGER NOT NULL |
|
33
|
|
|
); |
|
34
|
|
|
"); |
|
35
|
|
|
|
|
36
|
|
|
$messengerDir = $phpbb_root_path . 'store/messenger'; |
|
37
|
|
|
if (!is_dir($messengerDir)) { |
|
38
|
|
|
mkdir($messengerDir, 0777); |
|
39
|
|
|
$filesDir = $messengerDir . '/files'; |
|
40
|
|
|
if (!is_dir($filesDir)) { |
|
41
|
|
|
mkdir($filesDir, 0777); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
return 'notifications'; |
|
45
|
|
|
break; |
|
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
case 'notifications': |
|
48
|
|
|
$phpbb_notifications = $this->container->get('notification_manager'); |
|
49
|
|
|
$phpbb_notifications->enable_notifications('florinp.messenger.notification.type.friend_request'); |
|
50
|
|
|
return 'step2'; |
|
51
|
|
|
break; |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
default: |
|
54
|
|
|
return parent::enable_step($old_state); |
|
55
|
|
|
break; |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function disable_step($old_state) |
|
61
|
|
|
{ |
|
62
|
|
|
switch ($old_state) { |
|
63
|
|
|
case '': |
|
64
|
|
|
$phpbb_notifications = $this->container->get('notification_manager'); |
|
65
|
|
|
$phpbb_notifications->disable_notifications('florinp.messenger.notification.type.friend_request'); |
|
66
|
|
|
return 'notifications'; |
|
67
|
|
|
break; |
|
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
default: |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
return parent::disable_step($old_state); |
|
72
|
|
|
break; |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function purge_step($old_state) |
|
77
|
|
|
{ |
|
78
|
|
|
global $phpbb_root_path; |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
$database = $phpbb_root_path . 'store/messenger.db'; |
|
81
|
|
|
if (is_file($database)) { |
|
82
|
|
|
unlink($database); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$messengerDir = $phpbb_root_path . 'store/messenger'; |
|
86
|
|
|
if (is_dir($messengerDir)) { |
|
87
|
|
|
$objects = scandir($messengerDir); |
|
88
|
|
|
foreach ($objects as $object) { |
|
89
|
|
|
if ($object != '.' && $object != '..') { |
|
90
|
|
|
if (filetype($messengerDir . "/" . $object) == "dir") { |
|
91
|
|
|
$dir = $messengerDir . "/" . $object; |
|
92
|
|
|
$subObjects = scandir($dir); |
|
93
|
|
|
if(count($subObjects) > 0) { |
|
94
|
|
|
foreach($subObjects as $subObject) { |
|
95
|
|
|
if($subObject != '.' && $subObject != '..') { |
|
96
|
|
|
if(filetype($dir . '/' . $subObject) != 'dir') { |
|
97
|
|
|
unlink($dir . '/' . $subObject); |
|
98
|
|
|
} |
|
99
|
|
|
} else { |
|
100
|
|
|
continue; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
rmdir($messengerDir . "/" . $object); |
|
106
|
|
|
} else { |
|
107
|
|
|
unlink($messengerDir . "/" . $object); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
reset($objects); |
|
112
|
|
|
rmdir($messengerDir); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
return parent::purge_step($old_state); |
|
116
|
|
|
|
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
} |
|
120
|
|
|
|
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state