-
Notifications
You must be signed in to change notification settings - Fork 1
/
kora_gallery.php
354 lines (281 loc) · 14.7 KB
/
kora_gallery.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
<div class="wrap" id="galleries">
<h1>Galleries</h1>
<button class = "addNewGallery" id="addNewGallery">Add New Gallery</button>
<h2>Your Galleries</h2>
<?php
require_once( realpath( dirname(__FILE__) . "/../../../wp-includes/wp-db.php" ) );
require_once( realpath( dirname(__FILE__) . "/../../../wp-blog-header.php"));
require_once( realpath( dirname(__FILE__) . "/dbconfig.php" ) );
define('KORA_PLUGIN_RESTFUL_SUBPATH', 'api/restful.php');
define('KORA_PLUGIN_PATHBASE', plugin_dir_url(__FILE__));
//need to interact with script page
global $wpdb;
$galleries = $wpdb->prefix . "koragallery";
if(empty($wpdb->get_results("SELECT * FROM $galleries"))){
?>
<p>
You have no galleries. Add them via the "Add New Gallery" button above in order for
them to appear here!
</p>
<p>
Galleries are sequences of objects grouped together due to content similarities. A
proper description of what galleries are will appear here. This text will be gone
when a gallery is made.
</p>
<?php
}
//if galleries exist, display
else {
$gal_num = 0;
echo "<div class='gal_accordion'>";
foreach( $wpdb->get_results("SELECT * FROM $galleries") as $key => $row){
$id = $row->id;
$gallery_n = $wpdb->prefix .$row->title;
//gallery name without space to search the table
$gallery_nam=str_replace(" ", "_", $gallery_n);
$gallery_name = str_replace("'","Char_39__", html_entity_decode($gallery_nam, ENT_QUOTES));
$gallery_name_only = $row->title;
$gallery_desc = $row->description;
echo "<div class='gal_gallery' >";
echo "<div class='gal_title'>";
echo "<p class='galleryTitle' alt = '".$row->title."'>".$row->title." "."</p>";
echo "<p class='objectNum'>"." ".count($wpdb->get_results("SELECT * FROM $gallery_name"))." Objects </p>";
echo "<p class='addToGallery' id = '$id'><a>ADD TO / EDIT GALLERY</a></p>";
echo "<span class='close' id='$gallery_name' alt = '$id'><img src='../wp-content/plugins/kora/images/Close.svg'></span>";
echo "</div>";
echo "<div class='gal_body'>";
echo "<div class='gal_koraInfo'>";
echo "<p>".$gallery_desc."</p>";
echo "</div>";
echo "<div class='kora-objs'>";
foreach( $wpdb->get_results("SELECT * FROM $gallery_name") as $key => $row){
$kid = $row -> KID;
$schemeid = $row -> schemeid;
$display_item = explode(",", $row -> display);
unset($display_item[0]);
unset($display_item[1]);
$display_item = array_filter($display_item);
// connect to database
$mysql_hostname = kordat_dbhostname;
// var_dump($mysql_hostname);
$mysql_user = kordat_dbhostuser;
$mysql_database = kordat_dbselectname;
$mysql_password = kordat_dbhostpass;
$bd = new mysqli($mysql_hostname, $mysql_user, $mysql_password, $mysql_database);
if ($bd->connect_error) {
die("Connection failed: " . $bd->connect_error);
}
$dbproj = get_option('kordat_dbproj');
$dbscheme = get_option('kordat_dbscheme');
$dbtoken = get_option('kordat_dbtoken');
$query_sid_pid = "SELECT schemeid,pid FROM scheme WHERE schemeid = '".$schemeid."';";
$stmt = $bd->prepare($query_sid_pid) ;
$stmt->execute();
$stmt->bind_result($sids,$pids);
//$sid_pid_token = array();
while($stmt->fetch()){
$sid = $sids;
$pid = $pids;
//var_dump($sid." ".$pid."<br>");
if (in_array($sid, $dbscheme) && in_array($pid, $dbproj)){
$pos = array_search($pid, $dbproj);
$sid_pid_token = array('schemeid' => $sid, 'projectid' => $pid, 'token' => $dbtoken[$pos]);
}
}
$stmt->close();
$user = kordat_dbuser;
$pass = kordat_dbpass;
if ($kid == "ALL") {
$query = "Display,=,"."True";
} else {
$query = "KID,eq,".$kid;
}
$restful_url = get_option('kordat_dbapi') . KORA_PLUGIN_RESTFUL_SUBPATH;
$fields = 'ALL';
$display='json';
if (!empty($sid_pid_token)) {
$url = $restful_url.'?request=GET&pid='.$sid_pid_token['projectid'].'&sid='.$sid_pid_token['schemeid'].'&token='.$sid_pid_token['token'].'&display='.urlencode($display).'&fields='.urlencode($fields).'&query='.urlencode($query);
}
//var_dump($url);
//initialize post request to KORA API using curl
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $user.':'.$pass);
//capture results and display
$obj_json = curl_exec($ch);
//convert json string to php array
$server_output = json_decode($obj_json, true);
//check image or video or audio
$type = "";
if ($row -> imagefield != 'default' && $row -> imagefield != '') {
$type = 'imagefield';
} else if ($row -> videofield != 'default' && $row -> videofield != '') {
$type = 'videofield';
} else if ($row -> audiofield != 'default' && $row -> audiofield != '') {
$type = 'audiofield';
} else {
$type = 'null';
}
echo "<div class='kora-obj'>";
echo "<div class='kora-obj-left' id = ".$row->KID." >";
//image/video/audio
if ($type == "imagefield" && $server_output[$row -> KID][$row -> imagefield]) {
$thumb_src = get_option('kordat_dbapi').'files/'.$sid_pid_token['projectid'].'/'.$sid_pid_token['schemeid'].'/'.$server_output[$row -> KID][$row -> imagefield]['localName'];
echo "<img src='".$thumb_src."' alt='".$row -> KID."'>";
} else if ($type == "videofield") {
$videoFile = get_option('kordat_dbapi').'files/'.$sid_pid_token['projectid'].'/'.$sid_pid_token['schemeid'].'/'.$server_output[$row -> KID][$row -> videofield]['localName'];
echo '<video width="142" height="110" controls><source src="'.$videoFile.'" type="video/mp4"></video>';
} else if ($type == "audiofield"){
$videoFile = get_option('kordat_dbapi').'files/'.$sid_pid_token['projectid'].'/'.$sid_pid_token['schemeid'].'/'.$server_output[$row -> KID][$row -> videofield]['localName'];
echo '<video width="142" height="110" controls><source src="'.$videoFile.'" type="audio/mpeg"></video>';
} else {?>
<img src="<?php echo KORA_PLUGIN_PATHBASE.'images/placeholder_plugin.svg'?>" alt="<?php $kora_obj -> KID?>">
<?php
}
echo "<input type='button' class = 'edit_detials' id = '".$row -> KID."' value='edit details' gal_name='".$gallery_name."' alt = '".$sid_pid_token['schemeid']."'>"."<span class = 'gallery_name_".$row -> KID."' style = 'display:none'>".$gallery_name_only."</span>";
echo "</div>";
echo "<div class='kora-obj-right'>";
echo "<div class='kora-obj-close' id = ".$row->KID." alt = ".$gallery_name.">
<img src='../wp-content/plugins/kora/images/Close - Tiny.svg' class='closePic'>
</div>";
echo "<ul class='kora-obj-fields'>";
echo "<li><span>KID:</span> ".$row -> KID."</li>";
if (is_array($display_item)) {
foreach ($display_item as $key ) {
if ($key != "KID" ) {
if (is_array($server_output[$row -> KID][$key])) {
echo "<li><span>".$key."</span>: ";
foreach($server_output[$row -> KID][$key] as $k) {
echo $k." ";
}
echo "</li>";
} else {
echo "<li><span>".$key."</span>: ".$server_output[$row -> KID][$key]."</li>";
}
}
}
} else {
if ($display_item != "KID" ) {
if (is_array($server_output[$row -> KID][$display_item])) {
echo "<li><span>".$display_item."</span>: ";
foreach($server_output[$row -> KID][$display_item] as $k) {
echo $k." ";
}
echo "</li>";
} else {
echo "<li><span>".$display_item."</span>: ".$server_output[$row -> KID][$display_item]."</li>";
}
}
}
echo " </ul></div></div>";
}
echo "</div>";
echo "</div>";
echo "</div>";
$gal_num ++;
}
echo "</div>";
}
?>
</div>
<div class="remodal" id="editObjectModal" data-remodal-id="editObjectModal">
<button data-remodal-action="close" class="remodal-close"></button>
<img id="backArrow" src="../wp-content/plugins/kora/images/Arrow%20-%20Left.svg" width="12" height="20" alt="Back Arrow" />
<h2>Edit Details for Object Name</h2>
<div class = "object_details">
</div>
</div>
<link rel="stylesheet" href= "<?php echo "../wp-content/plugins/kora/colorbox.css";?>" type="text/css">
<script src="<?php echo "../wp-content/plugins/kora/js/jquery.colorbox-min.js";?>" type="text/javascript"></script>
<script src="<?php echo "../wp-content/plugins/kora/js/jquery.js";?>" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="<?php echo plugins_url('kora/remodal_v1.0.6/dist/remodal.min.js'); ?>"></script>
<link rel="stylesheet" href="<?php echo plugins_url('kora/remodal_v1.0.6/dist/remodal.css'); ?>" type="text/css"/>
<link rel="stylesheet" href="<?php echo plugins_url('kora/remodal_v1.0.6/dist/remodal-default-theme.css'); ?>" type="text/css"/>
<script> var url_plugin = '<?php echo KORA_PLUGIN_PATHBASE;?>'; </script>
<script>
$('.gal_accordion .gal_title').click(function(e) {
//Close all <div> but the <div> right after the clicked <a>
$(e.target).parent().siblings().children('.gal_body').slideUp('fast');
//Toggle open/close on the <div> after the <h3>, opening it if not open.
$(e.target).next('.gal_body').slideToggle('fast');
});
jQuery(document).ready(function($){
var editObjectModal = $('#editObjectModal.remodal');
if( editObjectModal.remodal().getState() == 'opened' ||
editObjectModal.remodal().getState() == 'opening' ) {
editObjectModal.parent().addClass( 'largeModal' );
}
//// "Edit Details" Modal /////////////////////////////////////////////////
//// Back Arrow Functionality ////
$('#editObjectModal img#backArrow').click( function() {
editObjectModal.remodal().close();
});
//// Checkbox Functionality ////
$('#editObjectModal input[type=checkbox]').click( function(event) {
// Stops click from registering twice
event.stopImmediatePropagation();
var checkboxId = $(this).attr('id');
var checkboxLabel = $('#editObjectModal label[for=' + checkboxId + ']');
var checkboxPar = $('#editObjectModal p#' + checkboxId);
// Toggle 'active' classes on associated label and paragraph
checkboxLabel.toggleClass( 'activeLabel' );
checkboxPar.toggleClass( 'activeParagraph' );
});
//// 'Update Object Details' Button Functionality ////
$('#editObjectModal input[type=submit]').click( function() {
editObjectModal.remodal().close();
});
$('.edit_detials').click(function( ){
$("#editObjectModal").show();
var kid_open = $(this).attr('id');
var schemeID = $(this).attr('alt');
var gallery_name_class = "gallery_name_" + kid_open;
var gallery_name = $(this).attr('gal_name');
$.ajax({
type: "GET",
async: false,
url: plugin.url + "ajaxKORAobject_details_gallery.php",
data: {"kid" : kid_open, "schemeid": schemeID, "gallery_name": gallery_name },
success: function(data){
$('.object_details').html(data);
}
});
editObjectModal.remodal().open();
});
$('.close').click(function(){
var gallery_name = $(this).attr('id');
var id = $(this).attr('alt');
jQuery.ajax({
type: "GET",
async: false,
url: plugin.url+"ajax/delete_gallery.php",
data: {"gallery": gallery_name, 'id': id},
success: function(data){
location.reload(true);
}
});
});
$('.kora-obj-close').click(function(){
var kid = $(this).attr('id');
var gallery_name = $(this).attr('alt');
if (confirm("Are you sure?")) {
jQuery.ajax({
type: "GET",
async: false,
url: plugin.url+"ajax/delete_gallery.php",
data: {"kid": kid, "gallery_name": gallery_name },
success: function(data){
location.reload(true);
}
});
} else {
location.reload(true);
}
});
jQuery('.gal_image').on('click', function(){
$('.popupImage').colorbox({ opacity:0.5 , rel:'group1', Width:'800px', Height:'800px' });
$('.gal_accordion').children().first('.gal_body').slideToggle('fast');
});
});
</script>