-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleView.class.php
More file actions
133 lines (108 loc) · 3.55 KB
/
SimpleView.class.php
File metadata and controls
133 lines (108 loc) · 3.55 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
<?php
class SimpleView {
function slideshow_list() {
global $wpdb, $user_ID;
$sql = sprintf("SELECT ID, slide_name, slide_desc FROM %s WHERE user_id='%s' AND deleted='0' ORDER BY created_time DESC", $wpdb->prefix.'ai_simpleview_slideshow', $user_ID);
$result = $wpdb->get_results( $sql, OBJECT);
return $result;
}
function slideshow_delete( $id ) {
global $wpdb, $user_ID;
// TODO: Delete all assoc images.
$up = $wpdb->update( $wpdb->prefix.'ai_simpleview_slideshow', array( 'deleted' => 1 ), array( 'ID' => $id, 'user_id' => $user_ID ), array( '%d' ), array( '%d', '%d' ) );
return $up;
}
function slideshow_count_images( $id ) {
global $wpdb, $user_ID;
$sql = sprintf( "SELECT COUNT(*) AS cnt FROM %s WHERE slideshow_id='%d' AND deleted='0'", $wpdb->prefix.'ai_simpleview_images', $id, $user_ID );
$row = $wpdb->get_row( $sql );
return $row->cnt;
}
function slideshow_has_images( $id ) {
global $wpdb, $user_ID;
$sql = sprintf( "SELECT * FROM %s WHERE slideshow_id='%d' AND deleted='0' LIMIT 1", $wpdb->prefix.'ai_simpleview_images', $id, $user_ID );
$row = $wpdb->get_row( $sql );
if ( count( $row ) > 0 ) {
return true;
}
return false;
}
function slideshow_is_deleted( $id ) {
global $wpdb, $user_ID;
$sql = sprintf( "SELECT * FROM %s WHERE ID='%d' AND user_id='%s' AND deleted='0' LIMIT 1", $wpdb->prefix.'ai_simpleview_slideshow', $id, $user_ID );
$row = $wpdb->get_row( $sql );
if ( count( $row ) > 0 ) {
return true;
}
return false;
}
function upload_images( $images, $slideshow ) {
global $wpdb, $user_ID;
// TODO: Check quota
$show = (int) $slideshow;
if ( $slideshow == 0 ) return false; // NO SLIDESHOW CHOSEN
if ( !is_array( $images ) ) return false; // NOT A $_FILES array
return true;
}
function slideshow_get_images_preview( $id ) {
global $wpdb;
if ( slideshow_has_images( $id ) ) {
$images = array();
$sql = sprintf( "SELECT * FROM %s WHERE slideshow_id='%d' AND deleted='0'", $wpdb->prefix . 'ai_simpleview_images', $id );
$result = $wpdb->get_results( $sql );
//$updir = get_option( 'upload_path' ) . '/ai-simpleview/' . $id . '/' ;
$updir = get_upload_path().'ai-simpleview/'.$id.'/';
$count = 0;
foreach ( $result as $r ) {
$images[$count]['id'] = $r->id;
$images[$count]['url'] = $updir . $r->file_name;
$images[$count]['description'] = $r->description;
$count++;
}
return $images;
} else {
return false;
}
}
/**
* Returns the number of images in a slide show.
*
* @param string $id
* @return void
* @author Aller Internet, Jonas Björk
*/
function count_images( $id ) {
global $wpdb;
$sql = sprintf( "SELECT COUNT(*) AS cnt FROM %s WHERE slideshow_id='%d' AND deleted='0'", $wpdb->prefix.'ai_simpleview_images', $id);
$row = $wpdb->get_row( $sql );
return $row->cnt;
}
function get_slide_name( $id, $len = 15 ) {
global $wpdb;
$sql = sprintf("SELECT slide_name FROM %s WHERE ID=%d AND deleted='0' LIMIT 1", $wpdb->prefix.'ai_simpleview_slideshow', $id);
$row = $wpdb->get_row($sql);
if ( mb_strlen($row->slide_name) > $len ) {
return mb_substr( $row->slide_name, 0, $len )."...";
} else {
return $row->slide_name;
}
}
/**
* Returns the upload path.
*
* @param void No need to send data here.
* @return string The upload path with ending /
* @author Aller Internet, Jonas Björk
*/
function get_upload_path() {
$up = get_option('upload_path');
if ( substr($up, 0, 1) != '/') {
$up = ABSPATH.$up;
}
if ( substr($up, -1) != '/' ) {
$up = $up.'/';
}
return $up;
}
}
?>