-
Notifications
You must be signed in to change notification settings - Fork 1
/
backuplib.php
207 lines (158 loc) · 7.64 KB
/
backuplib.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
require_once($CFG->dirroot . '/mod/lightboxgallery/lib.php');
function lightboxgallery_backup_mods($bf, $preferences) {
$status = true;
if ($galleries = get_records('lightboxgallery', 'course', $preferences->backup_course, 'id')) {
foreach ($galleries as $gallery) {
if (backup_mod_selected($preferences, 'lightboxgallery', $gallery->id)) {
$status = lightboxgallery_backup_one_mod($bf, $preferences, $gallery);
}
}
}
return $status;
}
function lightboxgallery_backup_one_mod($bf, $preferences, $gallery) {
$status = true;
if (is_numeric($gallery)) {
$gallery = get_record('lightboxgallery', 'id', $gallery);
}
fwrite($bf, start_tag('MOD', 3, true));
fwrite($bf, full_tag('ID', 4, false, $gallery->id));
fwrite($bf, full_tag('MODTYPE', 4, false, 'lightboxgallery'));
fwrite($bf, full_tag('FOLDER', 4, false, $gallery->folder));
fwrite($bf, full_tag('NAME', 4, false, $gallery->name));
fwrite($bf, full_tag('DESCRIPTION', 4, false, $gallery->description));
fwrite($bf, full_tag('PERPAGE', 4, false, $gallery->perpage));
fwrite($bf, full_tag('COMMENTS', 4, false, $gallery->comments));
fwrite($bf, full_tag('PUBLIC', 4, false, $gallery->ispublic));
fwrite($bf, full_tag('RSS', 4, false, $gallery->rss));
fwrite($bf, full_tag('AUTORESIZE', 4, false, $gallery->autoresize));
fwrite($bf, full_tag('RESIZE', 4, false, $gallery->resize));
fwrite($bf, full_tag('EXTINFO', 4, false, $gallery->extinfo));
$status = backup_lightboxgallery_files_instance($bf, $preferences, $gallery);
if ($status) {
if (backup_userdata_selected($preferences, 'lightboxgallery', $gallery->id)) {
$status = backup_lightboxgallery_metadata($bf, $preferences, $gallery->id);
}
}
$status = fwrite($bf, end_tag('MOD', 3, true));
return $status;
}
function backup_lightboxgallery_metadata($bf, $preferences, $galleryid) {
$status = true;
if ($records = get_records('lightboxgallery_image_meta', 'gallery', $galleryid, 'id')) {
$status = fwrite($bf, start_tag('IMAGEMETAS', 4, true));
foreach ($records as $record) {
fwrite($bf, start_tag('IMAGEMETA', 5, true));
fwrite($bf, full_tag('ID', 6, false, $record->id));
fwrite($bf, full_tag('IMAGE', 6, false, $record->image));
fwrite($bf, full_tag('METATYPE', 6, false, $record->metatype));
fwrite($bf, full_tag('DESCRIPTION', 6, false, $record->description));
$status = fwrite($bf, end_tag('IMAGEMETA', 5,true));
}
$status = fwrite($bf, end_tag('IMAGEMETAS', 4, true));
}
return $status;
}
function backup_lightboxgallery_files_instance($bf, $preferences, $gallery) {
global $CFG;
$status = true;
if (is_numeric($gallery)) {
$gallery = get_record('lightboxgallery', 'id', $gallery);
}
$tmppath = $CFG->dataroot . '/temp/backup/' . $preferences->backup_unique_code . '/' . $gallery->folder;
$status = check_dir_exists($tmppath, true, true);
if ($status) {
$oldpath = $CFG->dataroot . '/' . $preferences->backup_course . '/' . $gallery->folder;
if (is_dir($oldpath)) {
$status = backup_copy_file($oldpath, $tmppath);
}
}
return $status;
}
/***************************************************************************************************************************************************/
function lightboxgallery_check_backup_mods($course, $user_data = false, $backup_unique_code, $instances = null) {
if (!empty($instances) && is_array($instances) && count($instances)) {
$info = array();
foreach ($instances as $id => $instance) {
$info += lightboxgallery_check_backup_mods_instances($instance, $backup_unique_code);
}
return $info;
}
$info[0][0] = get_string('modulenameplural', 'lightboxgallery');
if ($ids = lightboxgallery_ids($course)) {
$info[0][1] = count($ids);
} else {
$info[0][1] = 0;
}
if ($user_data) {
$info[2][0] = get_string('metadata', 'lightboxgallery');
if ($ids = lightboxgallery_meta_ids_by_course($course)) {
$info[2][1] = count($ids);
} else {
$info[2][1] = 0;
}
}
return $info;
}
function lightboxgallery_check_backup_mods_instances($instance, $backup_unique_code) {
$info[$instance->id.'0'][0] = '<b>'.$instance->name.'</b>';
$info[$instance->id.'0'][1] = '';
$info[$instance->id.'1'][0] = get_string('imagecount', 'lightboxgallery');
if ($images = lightboxgallery_images_by_instance($instance->id)) {
$info[$instance->id.'1'][1] = count($images);
} else {
$info[$instance->id.'1'][1] = 0;
}
if (!empty($instance->userdata)) {
$info[$instance->id.'2'][0] = get_string('metadata', 'lightboxgallery');
if ($ids = lightboxgallery_meta_ids_by_instance($instance->id)) {
$info[$instance->id.'2'][1] = count($ids);
} else {
$info[$instance->id.'2'][1] = 0;
}
}
return $info;
}
/***************************************************************************************************************************************************/
function lightboxgallery_encode_content_links($content, $preferences) {
global $CFG;
$base = preg_quote($CFG->wwwroot, '/');
$search = "/(".$base."\/mod\/lightboxgallery\/index.php\?id\=)([0-9]+)/";
$result = preg_replace($search, '$@GALLERYINDEX*$2@$', $content);
$search = "/(".$base."\/mod\/lightboxgallery\/view.php\?id\=)([0-9]+)/";
$result = preg_replace($search, '$@GALLERYVIEWBYID*$2@$', $result);
$search = "/(".$base."\/mod\/lightboxgallery\/view.php\?l\=)([0-9]+)/";
$result = preg_replace($search, '$@GALLERYVIEWBYL*$2@$', $result);
return $result;
}
function lightboxgallery_ids($course) {
global $CFG;
return get_records_sql("SELECT l.id, l.course
FROM {$CFG->prefix}lightboxgallery l
WHERE l.course = '$course'");
}
function lightboxgallery_meta_ids_by_course($course) {
global $CFG;
return get_records_sql("SELECT m.id, m.gallery
FROM {$CFG->prefix}lightboxgallery_image_meta m,
{$CFG->prefix}lightboxgallery l
WHERE l.course = '$course' AND
m.gallery = l.id");
}
function lightboxgallery_meta_ids_by_instance($instanceid) {
global $CFG;
return get_records_sql("SELECT m.id, m.gallery
FROM {$CFG->prefix}lightboxgallery_image_meta m
WHERE m.gallery = $instanceid");
}
function lightboxgallery_images_by_instance($instanceid) {
global $CFG;
$result = false;
if ($gallery = get_record('lightboxgallery', 'id', $instanceid)) {
$directory = $CFG->dataroot . '/' . $gallery->course . '/' . $gallery->folder;
$result = lightboxgallery_directory_images($directory);
}
return $result;
}
?>