forked from Znote/ZnoteAAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gallery.php
131 lines (121 loc) · 4.01 KB
/
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
<?php require_once 'engine/init.php'; include 'layout/overall/header.php';
/* SETUP INSTALLATION
- See comments above $config['gallery'] in config.php */
$logged_in = user_logged_in();
if ($logged_in === true) {
if (!empty($_POST['new'])) {
?>
<h1>Create image article</h1>
<p>This gallery is powered by IMGUR image host.</p>
<form action="" method="post" enctype="multipart/form-data">
Select image to upload:<br><input type="file" name="imagefile" id="imagefile"><br>
Image Title:<br /><input type="text" name="title" size="70"><br />
Image Description:<br /><textarea name="desc" cols="55" rows="15"></textarea><br />
<input type="submit" value="Upload Image" name="submit">
</form>
<?php
}
if (isset($_FILES['imagefile']) && !empty($_FILES['imagefile'])) {
$image = file_get_contents($_FILES['imagefile']['tmp_name']);
$imgurClientID = $config['gallery']['Client ID'];
// Post image to imgur
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.imgur.com/3/image/");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
"type" => "file",
"name" => $_FILES['imagefile']['name'],
"image" => $image
]);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Client-ID {$imgurClientID}"
));
$response = json_decode(curl_exec($ch));
$image_url = $response->data->link;
$image_delete = $response->data->deletehash;
$title = $_POST['title'];
$desc = $_POST['desc'];
if ($image_url !== false) {
// Insert to database
$inserted = insertImage((int)$session_user_id, $title, $desc, $image_url, $image_delete);
if ($inserted === true) {
?>
<h1>Image Posted</h1>
<p>However, your image will not be listed until a GM have verified it.<br />
Feel free to remind the GM in-game to login on website and approve the image post.</p>
<h2>Preview:</h2>
<table>
<tr class="yellow">
<td><h3><?php echo $title; ?></h3></td>
</tr>
<tr>
<td>
<a href="<?php echo $image_url; ?>" target="_BLANK"><img class="galleryImage" style="max-width: 100%;" src="<?php echo $image_url; ?>" alt="<?php echo $title; ?>"/></a>
</td>
</tr>
<tr>
<td>
<?php
$descr = str_replace("\\r", "", $desc);
$descr = str_replace("\\n", "<br />", $descr);
?>
<p><?php echo $descr; ?></p>
</td>
</tr>
</table>
<?php
} else { // Image not inserted because it already exist
?>
<h1>Image already exist</h1>
<p>The image has already been posted. However, images will not be listed until a GM have verified it.</p>
<?php
}
} else { // Failed to locate imageSrc
?>
<h1>Failed to find the image</h1>
<p>We failed to find the image, did you give us the Image code from <a href="http://www.freeimagehosting.net/">www.freeimagehosting.net</a>?</p>
<?php
}
}
}
if (empty($_POST)) {
?>
<h1>Gallery</h1>
<?php if ($logged_in === true) { ?>
<form action="" method="post">
Got some cool images to show the community? <input type="submit" name="new" value="Add Image">
</form>
<?php
}
$cache = new Cache('engine/cache/gallery');
$images = $cache->load();
if (is_array($images) && !empty($images)) {
foreach($images as $image) {
?>
<table>
<tr class="yellow">
<td><h3><?php echo $image['title']; ?></h3></td>
</tr>
<tr>
<td>
<a href="<?php echo $image['image']; ?>" target="_BLANK"><img class="galleryImage" style="max-width: 100%;" src="<?php echo $image['image']; ?>" alt="<?php echo $image['title']; ?>"/></a>
</td>
</tr>
<tr>
<td>
<?php
$descr = str_replace("\\r", "", $image['desc']);
$descr = str_replace("\\n", "<br />", $descr);
?>
<p><?php echo $descr; ?></p>
</td>
</tr>
</table>
<?php }
} else echo '<h2>There are currently no public images.</h2>';
if ($logged_in === false) echo 'You need to be logged in to add images.';
}
include 'layout/overall/footer.php';
?>