This repository has been archived by the owner on Jan 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
wpmanga.php
380 lines (320 loc) · 12 KB
/
wpmanga.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<?php
/**
* @package WP Manga Project Manager
* @version 0.2.91
*/
/*
Plugin Name: WP Manga Project Manager
Plugin URI: http://dev.xengi.org/blog/
Description: WP Manga Project Manager allows administrators and editors to manage information regarding project and release information. This plugin allows the changes to be made throughout the database and avoids displaying inaccurate information to the users.
Author: TEAM SEPTiCORE
Version: 0.2.91
Author URI: http://dev.xengi.org/blog/
*/
/**
* Include Core WP Functions
*/
include('admin/admin_menu.php');
include('includes/database_migration.php');
include('includes/wp_dashboard.php');
include('includes/wp_functions.php');
include('includes/wp_languages_unit.php');
include('includes/wp_options.php');
include('includes/wp_shortcode.php');
include('includes/wp_widget.php');
$wpmanga_plugin = "0.2.91";
/**
* Activates the Manga Project Manager Plugin.
* @return true
*/
register_activation_hook(__FILE__, 'wpmanga_activate');
add_action('admin_menu', 'wpmanga_adminmenu');
function wpmanga_activate() {
modify_sDatabase();
return true;
}
/**
* Returns the projects that belonged to the specified category.
* @param integer|NULL $id ID of the category.
* @return object
*/
function get_sListCategory($int = NULL, $list = TRUE) {
global $wpdb;
if ($list) {
return $wpdb->get_results( $wpdb->prepare("SELECT * FROM `{$wpdb->prefix}projects` WHERE `category` = '%d' ORDER BY `title` ASC", $int) );
} else {
$result = $wpdb->get_row( $wpdb->prepare("SELECT COUNT(*) as `total` FROM `{$wpdb->prefix}projects` WHERE `category` = '%d' ORDER BY `title` ASC", $int) );
return $result->total;
}
}
/**
* Returns the list of categories stored in the database.
* @return object
*/
function get_sListCategories() {
global $wpdb;
return $wpdb->get_results("SELECT * FROM `{$wpdb->prefix}projects_category` ORDER BY `index` ASC");
}
/**
* Returns the list of projects stored in the database.
* @return object
*/
function get_sListProject() {
global $wpdb;
$projects = $wpdb->get_results("SELECT * FROM `{$wpdb->prefix}projects` ORDER BY `title` ASC");
return $projects;
}
/**
* Returns the List of Latest Releases.
* @param integer $limit Limit the number of results returned.
* @return object
*/
function get_sListLatest($limit = 5, $all = FALSE) {
global $wpdb;
if ($all)
$display = "WHERE `unixtime_mod` <= '" . time() . "'";
else
$display = '';
if ($limit)
return $wpdb->get_results($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}projects_releases` {$display} ORDER BY `unixtime_mod` DESC LIMIT 0, %d", $limit));
else
return $wpdb->get_results($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}projects_releases` {$display} ORDER BY `unixtime_mod` DESC", $limit));
}
/**
* Returns the title or name of the category specified.
* @param integer|NULL $id ID of the category.
* @return string
*/
function get_sTitleCategory($id = NULL) {
global $wpdb;
$category = $wpdb->get_row($wpdb->prepare("SELECT `name` FROM `{$wpdb->prefix}projects_category` WHERE `id` = '%d'", $id));
return (string) $category->name;
}
/**
* Returns the title or name of the project specified.
* @param integer|NULL $id ID of the project.
* @return string
*/
function get_sTitleProject($id = NULL) {
global $wp, $wpdb;
if (!is_int($id))
$pid = get_sProjectId($wp->query_vars["pid"]);
else
$pid = (int) $id;
$project = $wpdb->get_row($wpdb->prepare("SELECT `title` FROM `{$wpdb->prefix}projects` WHERE `id` = '%d' ORDER BY `title` ASC", $pid));
return (string) $project->title;
}
/**
* Returns the Project ID of the project specified.
* @param integer|string $query Query the integer/string to obtain ID.
* @return integer
*/
function get_sProjectId($query) {
global $wpdb;
if (isset($query->project_id)) return (int) $query->project_id;
if (isset($query->id)) return (int) $query->id;
if (is_int($query)) return (int) $query;
$pid = $wpdb->get_row($wpdb->prepare("SELECT `id` FROM `{$wpdb->prefix}projects` WHERE `slug` = '%s'", $query));
if ($pid)
return (int) $pid->id;
else
return (int) $query;
}
/**
* Returns the Project Details of the project specified.
* @param integer|string $project Query the integer/string to obtain ID.
* @param boolean $count Count hits to the project or not.
* @return object
*/
function get_sProject($project, $count = true) {
global $wpdb;
$id = get_sProjectId($project);
if ($count && !is_user_logged_in() ) { $wpdb->query($wpdb->prepare("UPDATE `{$wpdb->prefix}projects` SET `hit` = hit + 1 WHERE `id` = '%d'", $id)); }
$project = $wpdb->get_row($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}projects` WHERE `id` = '%d'", $id));
if ($project->description != NULL) $project->description = nl2br($project->description);
if ($project->information != NULL) $project->information = nl2br($project->information);
return $project;
}
/**
* Returns the Project Volumes.
* @param integer|string $project Query the integer/string to obtain ID.
* @return object
*/
function get_sProjectVolumes($project) {
global $wp, $wpdb;
$id = get_sProjectId($project);
return $wpdb->get_results($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}projects_volumes` WHERE `project_id` = '%d' ORDER BY `volume` ASC", $id));
}
/**
* Returns the Project Releases by Volume.
* @param integer|string $project Query the integer/string to obtain ID.
* @return object
*/
function get_sProjectReleasesByVolume($project, $volume, $all = FALSE) {
global $wp, $wpdb;
if ($all)
$display = "AND `unixtime_mod` <= '" . time() . "'";
else
$display = '';
$id = get_sProjectId($project);
return $wpdb->get_results($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}projects_releases` WHERE `project_id` = '%d' AND `volume` = '%d' {$display} ORDER BY `volume` ASC, `chapter` ASC, `subchapter` ASC, `type` ASC", $id, $volume));
}
/**
* Returns the Project Releases.
* @param integer|string $project Query the integer/string to obtain ID.
* @return object
*/
function get_sProjectReleases($project, $all = FALSE) {
global $wp, $wpdb;
if ($all)
$display = "AND `unixtime_mod` <= '" . time() . "'";
else
$display = '';
$id = get_sProjectId($project);
return $wpdb->get_results($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}projects_releases` WHERE `project_id` = '%d' {$display} ORDER BY `volume` ASC, `chapter` ASC, `subchapter` ASC, `type` ASC", $id));
}
/**
* Returns the Release Downloads Modified.
* @param object $release Modifies the release data passed.
* @return object
*/
function get_sReleaseDownloads($release) {
$downloads = new stdClass();
foreach ($release as $download => $link) {
if (preg_match("/download_(.*?)/i", $download) && $link) {
if (wpmanga_get('wpmanga_disable_' . str_replace('download_', '', $download), 0))
unset($release->{$download});
elseif (wpmanga_get('wpmanga_delay_' . str_replace('download_', '', $download), 0) && (($release->unixtime + wpmanga_get('wpmanga_delay', 0)*60*60) >= time()))
unset($release->{$download});
else
$downloads->{$download} = $release->{$download};
}
}
return $downloads;
}
/**
* Returns the Release Information for specified ID.
* @param integer $project Query the integer to obtain ID.
* @return object
*/
function get_sRelease($id) {
global $wpdb;
$release = $wpdb->get_row($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}projects_releases` WHERE `id` = '%d'", $id));
return $release;
}
/**
* Returns the Release Information for LAST release.
* @param integer $project Query the integer to obtain ID.
* @return object
*/
function get_sLastRelease($id) {
global $wpdb;
#$release = $wpdb->get_row($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}projects_releases` WHERE `project_id` = '%d' ORDER BY `volume` DESC, `chapter` DESC, `subchapter` DESC LIMIT 1", $id));
$release = $wpdb->get_row($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}projects_releases` WHERE `project_id` = '%d' ORDER BY `unixtime_mod` DESC, `unixtime` DESC LIMIT 1", $id));
return $release;
}
/**
* Returns the Release Information for specified ID.
* @param integer $project Query the integer to obtain ID.
* @return object
*/
function get_sFormatRelease($project, $release, $v = true, $c = true, $r = true) {
$custom_chp = get_sJSON($project->custom, 'chapter');
$custom_sub = get_sJSON($project->custom, 'subchapter');
$output = '';
switch ($release->type) {
case 5:
$output .= 'Volume ' . str_pad($release->volume, 2, '0', STR_PAD_LEFT);
break;
case 10:
if ($v && $release->volume) $output .= 'Volume ' . str_pad($release->volume, 2, '0', STR_PAD_LEFT) . ' ';
$output .= 'Special';
if ($release->subchapter > 0) $output .= ' ' . $release->subchapter;
break;
case 20:
if ($v && $release->volume) $output .= 'Volume ' . str_pad($release->volume, 2, '0', STR_PAD_LEFT) . ' ';
$output .= 'Oneshot';
if ($release->subchapter > 0) $output .= ' ' . $release->subchapter;
break;
default:
if ($v && $release->volume) $output .= 'Volume ' . str_pad($release->volume, 2, '0', STR_PAD_LEFT) . ' ';
if ($c) {
if ($custom_chp)
$output .= str_replace('%num%', str_pad($release->chapter, 2, '0', STR_PAD_LEFT), $custom_chp);
else
$output .= 'Chapter ' . str_pad($release->chapter, 2, '0', STR_PAD_LEFT);
if ($release->subchapter > 0) {
if ($custom_sub)
$output .= ' ' . str_replace('%num%', str_pad($release->subchapter, 2, '0', STR_PAD_LEFT), $custom_sub);
else
$output .= '.' . $release->subchapter;
}
}
}
if ($r && $release->revision > 1) $output .= ' v' . $release->revision;
return $output;
}
/**
* Returns the Thumbnail Generated for the source and dimensions specified.
* @param string $dimensions The dimensions of the thumbnail generated by WIDTHxHEIGHT.
* @param string $limit The original source of the thumbnail.
* @return string
*/
function get_sThumbnail($dimensions, $source = NULL) {
if ($source != NULL && file_exists(plugin_sDIR() . 'cache/' . $dimensions . '__' . basename($source)))
return plugin_sURL() . 'cache/' . $dimensions . '__' . basename($source);
else
return plugin_sURL() . 'images/__blank.png';
}
/**
* Generates a link to the corresponding chapter in FoOlSlide. This is still under some test and has not been tested under certain circumstances.
* @param object $project Process the project array provided.
* @param object $release Process the release array provided.
* @return string
*/
function get_sReaderLink($project, $release) {
switch (wpmanga_get('wpmanga_reader')) {
// FoOlSlide
case 1:
$url = str_replace('/reader/comic/', '/reader/read/', $project->reader) . $release->language . '/' . $release->volume . '/' . $release->chapter . '/';
$url = str_replace('/reader/serie/', '/reader/read/', $url); //FoOlSlide below 0.8.4 link style
$url = str_replace('/reader/series/', '/reader/read/', $url); //FoOlSlide 0.8.4 link style
if ($release->subchapter) $url .= $release->subchapter . '/';
break;
// None: Return $reader or individual link for chapter release
default:
$url = $project->reader;
if ($release->link_reader) $url = $release->link_reader;
break;
}
return $url;
}
/**
* Returns the Permalink for the project specified.
* @param integer $id Query the ID to obtain the permalink.
* @return string
*/
function get_sPermalink($project = NULL) {
global $wp, $wpdb;
if (!$project) {
$id = get_sProjectId($wp->query_vars["pid"]);
$project = $wpdb->get_row($wpdb->prepare("SELECT `id`, `slug` FROM `{$wpdb->prefix}projects` WHERE `id` = '%d' ORDER BY `title` ASC", $id));
}
elseif (is_int($project)) {
$id = (int) $project;
$project = $wpdb->get_row($wpdb->prepare("SELECT `id`, `slug` FROM `{$wpdb->prefix}projects` WHERE `id` = '%d' ORDER BY `title` ASC", $id));
}
if ($project->slug != NULL)
return (string) get_bloginfo('siteurl') . '/projects/' . $project->slug . '/';
else
return (string) get_bloginfo('siteurl') . '/projects/' . $project->id . '/';
}
/**
* Returns the sanitized format of the title specified.
* @param string $title Title of the project to be sanitized.
* @return string
*/
function get_sSanitizedSlug($title) {
return sanitize_title_with_dashes(remove_accents($title));
}
/* EOF: wpmanga.php */