This repository has been archived by the owner on Sep 8, 2023. It is now read-only.
/
class.active.php
173 lines (150 loc) · 6.02 KB
/
class.active.php
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/*
* Copyright (c) Codiad & Kent Safranski (codiad.com), distributed
* as-is and without warranty under the MIT License. See
* [root]/license.txt for more. This information must remain intact.
*/
require_once('../../common.php');
class Active extends Common
{
//////////////////////////////////////////////////////////////////
// PROPERTIES
//////////////////////////////////////////////////////////////////
public $username = "";
public $path = "";
public $new_path = "";
public $actives = "";
//////////////////////////////////////////////////////////////////
// METHODS
//////////////////////////////////////////////////////////////////
// -----------------------------||----------------------------- //
//////////////////////////////////////////////////////////////////
// Construct
//////////////////////////////////////////////////////////////////
public function __construct()
{
$this->actives = getJSON('active.php');
}
//////////////////////////////////////////////////////////////////
// List User's Active Files
//////////////////////////////////////////////////////////////////
public function ListActive()
{
$active_list = array();
$tainted = false;
$root = WORKSPACE;
if ($this->actives) {
foreach ($this->actives as $active => $data) {
if (is_array($data) && isset($data['username']) && $data['username']==$this->username) {
if ($this->isAbsPath($data['path'])) {
$root = "";
} else {
$root = $root.'/';
}
if (file_exists($root.$data['path'])) {
$focused = isset($data['focused']) ? $data['focused'] : false;
$active_list[] = array('path'=>$data['path'], 'focused'=>$focused);
} else {
unset($this->actives[$active]);
$tainted = true;
}
}
}
}
if ($tainted) {
saveJSON('active.php', $this->actives);
}
echo formatJSEND("success", $active_list);
}
//////////////////////////////////////////////////////////////////
// Check File
//////////////////////////////////////////////////////////////////
public function Check()
{
$cur_users = array();
foreach ($this->actives as $active => $data) {
if (is_array($data) && isset($data['username']) && $data['username']!=$this->username && $data['path']==$this->path) {
$cur_users[] = $data['username'];
}
}
if (count($cur_users)!=0) {
echo formatJSEND("error", "Warning: File ".substr($this->path, strrpos($this->path, "/")+1)." Currently Opened By: " . implode(", ", $cur_users));
} else {
echo formatJSEND("success");
}
}
//////////////////////////////////////////////////////////////////
// Add File
//////////////////////////////////////////////////////////////////
public function Add()
{
$process_add = true;
foreach ($this->actives as $active => $data) {
if (is_array($data) && isset($data['username']) && $data['username']==$this->username && $data['path']==$this->path) {
$process_add = false;
}
}
if ($process_add) {
$this->actives[] = array("username"=>$this->username,"path"=>$this->path);
saveJSON('active.php', $this->actives);
echo formatJSEND("success");
}
}
//////////////////////////////////////////////////////////////////
// Rename File
//////////////////////////////////////////////////////////////////
public function Rename()
{
$revised_actives = array();
foreach ($this->actives as $active => $data) {
if (is_array($data) && isset($data['username'])) {
$revised_actives[] = array("username"=>$data['username'],"path"=>str_replace($this->path, $this->new_path, $data['path']));
}
}
saveJSON('active.php', $revised_actives);
echo formatJSEND("success");
}
//////////////////////////////////////////////////////////////////
// Remove File
//////////////////////////////////////////////////////////////////
public function Remove()
{
foreach ($this->actives as $active => $data) {
if (is_array($data) && isset($data['username']) && $this->username==$data['username'] && $this->path==$data['path']) {
unset($this->actives[$active]);
}
}
saveJSON('active.php', $this->actives);
echo formatJSEND("success");
}
//////////////////////////////////////////////////////////////////
// Remove All Files
//////////////////////////////////////////////////////////////////
public function RemoveAll()
{
foreach ($this->actives as $active => $data) {
if (is_array($data) && isset($data['username']) && $this->username==$data['username']) {
unset($this->actives[$active]);
}
}
saveJSON('active.php', $this->actives);
echo formatJSEND("success");
}
//////////////////////////////////////////////////////////////////
// Mark File As Focused
// All other files will be marked as non-focused.
//////////////////////////////////////////////////////////////////
public function MarkFileAsFocused()
{
foreach ($this->actives as $active => $data) {
if (is_array($data) && isset($data['username']) && $this->username==$data['username']) {
$this->actives[$active]['focused']=false;
if ($this->path==$data['path']) {
$this->actives[$active]['focused']=true;
}
}
}
saveJSON('active.php', $this->actives);
echo formatJSEND("success");
}
}