-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclass.droplets.php
More file actions
184 lines (165 loc) · 5.37 KB
/
Copy pathclass.droplets.php
File metadata and controls
184 lines (165 loc) · 5.37 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
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
174
175
176
177
178
179
180
181
182
183
184
<?php
/**
* dbMultipleChoice
*
* @author Ralf Hertsch <ralf.hertsch@phpmanufaktur.de>
* @link https://phpmanufaktur.de
* @copyright 2010 - 2013 phpManufaktur by Ralf Hertsch
* @license MIT License (MIT) http://www.opensource.org/licenses/MIT
*/
// include class.secure.php to protect this file and the whole CMS!
if (defined('WB_PATH')) {
if (defined('LEPTON_VERSION'))
include(WB_PATH.'/framework/class.secure.php');
}
else {
$oneback = "../";
$root = $oneback;
$level = 1;
while (($level < 10) && (!file_exists($root.'/framework/class.secure.php'))) {
$root .= $oneback;
$level += 1;
}
if (file_exists($root.'/framework/class.secure.php')) {
include($root.'/framework/class.secure.php');
}
else {
trigger_error(sprintf("[ <b>%s</b> ] Can't include class.secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
}
}
// end include class.secure.php
require_once(WB_PATH.'/modules/'.basename(dirname(__FILE__)).'/initialize.php');
class dbDroplets extends dbConnectLE {
const field_id = 'id';
const field_name = 'name';
const field_code = 'code';
const field_description = 'description';
const field_modified_when = 'modified_when';
const field_modified_by = 'modified_by';
const field_active = 'active';
const field_comments = 'comments';
public function __construct() {
parent::__construct();
$this->setTableName('mod_droplets');
$this->addFieldDefinition(self::field_id, "INT(11) NOT NULL AUTO_INCREMENT", true);
$this->addFieldDefinition(self::field_name, "VARCHAR(32) NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_code, "TEXT NOT NULL DEFAULT ''", false, false, true);
$this->addFieldDefinition(self::field_description, "TEXT NOT NULL DEFAULT ''");
$this->addFieldDefinition(self::field_modified_when, "INT(11) NOT NULL DEFAULT '0'");
$this->addFieldDefinition(self::field_modified_by, "INT(11) NOT NULL DEFAULT '0'");
$this->addFieldDefinition(self::field_active, "INT(11) NOT NULL DEFAULT '0'");
$this->addFieldDefinition(self::field_comments, "TEXT NOT NULL DEFAULT ''");
$this->checkFieldDefinitions();
} // __construct()
} // class dbDroplets
class checkDroplets {
var $droplet_path = '';
var $error = '';
public function __construct() {
$this->droplet_path = WB_PATH . '/modules/' . basename(dirname(__FILE__)) . '/droplets/' ;
} // __construct()
/**
* Set $this->error to $error
*
* @param STR $error
*/
public function setError($error) {
$this->error = $error;
} // setError()
/**
* Get Error from $this->error;
*
* @return STR $this->error
*/
public function getError() {
return $this->error;
} // getError()
/**
* Check if $this->error is empty
*
* @return BOOL
*/
public function isError() {
return (bool) !empty($this->error);
} // isError
public function insertDropletsIntoTable() {
global $admin;
// Read droplets from directory
$folder = opendir($this->droplet_path.'.');
$names = array();
while (false !== ($file = readdir($folder))) {
if (basename(strtolower($file)) != 'index.php') {
$ext = strtolower(substr($file,-4));
if ($ext == ".php") {
$names[count($names)] = $file;
}
}
}
closedir($folder);
// init droplets
$dbDroplets = new dbDroplets();
if (!$dbDroplets->sqlTableExists()) {
// Droplets not installed!
return false;
}
// walk through array
foreach ($names as $dropfile) {
//$droplet = addslashes($this->getDropletCodeFromFile($dropfile));
$droplet = $this->getDropletCodeFromFile($dropfile);
if ($droplet != "") {
// get droplet name
$name = substr($dropfile,0,-4);
$where = array();
$where[dbDroplets::field_name] = $name;
$result = array();
if (!$dbDroplets->sqlSelectRecord($where, $result)) {
// error exec query
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbDroplets->getError()));
return false;
}
if (sizeof($result) < 1) {
// insert this droplet into table
$description = "Example Droplet";
$comments = "Example Droplet";
$cArray = explode("\n",$droplet);
if (substr($cArray[0],0,3) == "//:") {
// extract description
$description = trim(substr($cArray[0],3));
array_shift($cArray);
}
if (substr($cArray[0],0,3) == "//:") {
// extract comment
$comments = trim(substr($cArray[0],3));
array_shift($cArray);
}
$data = array();
$data[dbDroplets::field_name] = $name;
$code = implode("\r\n", $cArray);
$data[dbDroplets::field_code] = $code;
$data[dbDroplets::field_description] = $description;
$data[dbDroplets::field_comments] = $comments;
$data[dbDroplets::field_active] = 1;
$data[dbDroplets::field_modified_by] = $admin->get_user_id();
$data[dbDroplets::field_modified_when] = time();
if (!$dbDroplets->sqlInsertRecord($data)) {
// error exec query
$this->setError(sprintf('[%s - %s] %s', __METHOD__, __LINE__, $dbDroplets->getError()));
return false;
}
}
}
}
return true;
} // insertDropletsIntoTable()
public function getDropletCodeFromFile($dropletfile) {
$data = "";
$filename = $this->droplet_path.$dropletfile;
if (file_exists($filename)) {
$filehandle = fopen ($filename, "r");
$data = fread ($filehandle, filesize ($filename));
fclose($filehandle);
}
return $data;
} // getDropletCodeFromFile()
} // checkDroplets
?>