forked from publishpress/publishpress-series
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorgSeries-icon.php
108 lines (92 loc) · 3.04 KB
/
orgSeries-icon.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
<?php
##SERIES-ICON RELATED STUFF
function default_seriesicons_upload() {
$def_path = apply_filters( 'orgseries_icons_path', ABSPATH );
$def_url = apply_filters( 'orgseries_icons_url', home_url() . '/' );
return array($def_path, $def_url);
}
/**
* Get series icons from database
* @param int $series Series ID
* @return icon url
*/
function series_get_icons($series) {
global $wpdb;
$tablename = $wpdb->prefix . 'orgseriesicons';
if ($row = $wpdb->get_row( $wpdb->prepare("SELECT icon FROM $tablename WHERE term_id=%d", $series) ) ) {
return $row->icon;
} else return false;
}
/**
* Get series path and url (next two functions)
* function seriesicons_path
* @return path of series icons
* function seriesicons_url
* @return path of series urls
*/
function seriesicons_path() {
$def = default_seriesicons_upload();
return $def[0];
}
function seriesicons_url() {
$def = default_seriesicons_upload();
return $def[1];
}
/**
* Utility function to compute a rectangle to fit a given rectangle by maintaining the aspect ration.
* @return array containing computed height and width
*/
function series_fit_rect($width, $height, $max_width=-1, $max_height=-1, $expand=false) {
$h = $height;
$w = $width;
if ($max_width>0 && ($w > $max_width || $expand)) {
$w = $max_width;
$h = floor(($w*$height)/$width);
}
if ($max_height>0 && $h>$max_height) {
$h = $max_height;
$w = floor(($h*$width)/$height);
}
return array($w,$h);
}
/**
* Utility function to take in a referenced variable and sanitize the contents. First seen in the category-icons plugin by Ivan Georgiev ([email protected])
*/
if (!function_exists('stripslaghes_gpc_arr')) {
function stripslaghes_gpc_arr(&$arr) {
foreach(array_keys($arr) as $k) {
$arr[$k] = stripslashes($arr[$k]);
}
}
}
/**
* Database write function to add the series icon/series relationship to the database
* @param int $series Series ID
* @param string $icon Series icon
* @return boolean true if db write is successful
*/
function seriesicons_write($series, $icon) {
global $wpdb;
$tablename = $wpdb->prefix . 'orgseriesicons';
if ( empty($series) || '' == $series || empty($icon) || '' == $icon ) return false;
if ($wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $tablename WHERE term_id=%d", $series) ) ) {
$wpdb->query( $wpdb->prepare("UPDATE $tablename SET icon=%s WHERE term_id=%d", $icon, $series) );
} else {
$wpdb->query( $wpdb->prepare("INSERT INTO $tablename (term_id, icon) VALUES (%d,%s)", $series, $icon) );
}
return true;
}
/**
* Database delete function to remove the series icon/series relationship from the database.
* @param int $series Series ID
* @param string $icon Series Icon
* @return boolean true if db delete is successful
*/
function seriesicons_delete($series) {
global $wpdb;
$tablename = $wpdb->prefix . 'orgseriesicons';
if ( empty($series) || '' == $series ) return false;
$wpdb->query( $wpdb->prepare("DELETE FROM $tablename WHERE term_id=%d", $series) );
return true;
}
?>