diff --git a/admin_gallery.php b/admin_gallery.php
index 966b920..5d36eaa 100644
--- a/admin_gallery.php
+++ b/admin_gallery.php
@@ -15,6 +15,21 @@ if (isset($_POST['remove'])) {
$data = explode(":", $_POST['remove']);
$did = (int)$data[0];
echo 'Image '. $did .' removed.';
+
+ $delhash = $_POST['delhash'];
+ $imgurClientID = $config['gallery']['Client ID'];
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, "https://api.imgur.com/3/image/{$delhash}");
+ curl_setopt($ch, CURLOPT_HEADER, false);
+ curl_setopt($ch, CURLOPT_POST, true);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
+ "Authorization: Client-ID {$imgurClientID}"
+ ));
+ $response = json_decode(curl_exec($ch));
+
mysql_delete("DELETE FROM `znote_images` WHERE `id`='$did' LIMIT 1;");
}
@@ -106,6 +121,7 @@ if ($images != false) {
|
diff --git a/config.php b/config.php
index 87edb99..981162b 100644
--- a/config.php
+++ b/config.php
@@ -703,6 +703,16 @@
'debug' => false,
);
+ // website.com/gallery.php
+ // website.com/admin_gallery.php
+ // we use imgur as image host, and need to register app with them and add client/secret id.
+ // https://github.com/Znote/ZnoteAAC/wiki/IMGUR-powered-Gallery-page
+ $config['gallery'] = array(
+ 'Client Name' => 'ZnoteAAC-Gallery',
+ 'Client ID' => '4dfcdc4f2cabca6',
+ 'Client Secret' => '697af737777c99a8c0be07c2f4419aebb2c48ac5'
+ );
+
// Email Server configurations (SMTP)
/* Please consider using a released stable version of PHPMailer or you may run into issues.
Download PHPMailer: https://github.com/PHPMailer/PHPMailer/releases
diff --git a/engine/database/znote_schema.sql b/engine/database/znote_schema.sql
index fce0f4f..11d0fc6 100644
--- a/engine/database/znote_schema.sql
+++ b/engine/database/znote_schema.sql
@@ -40,7 +40,8 @@ CREATE TABLE IF NOT EXISTS `znote_images` (
`desc` text NOT NULL,
`date` int NOT NULL,
`status` int NOT NULL,
- `image` varchar(30) NOT NULL,
+ `image` varchar(50) NOT NULL,
+ `delhash` varchar(30) NOT NULL,
`account_id` int NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
diff --git a/engine/function/users.php b/engine/function/users.php
index 13c2720..39e62ed 100644
--- a/engine/function/users.php
+++ b/engine/function/users.php
@@ -6,21 +6,22 @@
// Fetch Images
function fetchImages($status) {
$status = (int)$status;
- return mysql_select_multi("SELECT `id`, `title`, `desc`, `date`, `status`, `image`, `account_id` FROM znote_images WHERE `status`='$status' ORDER BY `date` DESC;");
+ return mysql_select_multi("SELECT `id`, `title`, `desc`, `date`, `status`, `image`, `delhash`, `account_id` FROM znote_images WHERE `status`='$status' ORDER BY `date` DESC;");
}
// Insert image data
-function insertImage($account_id, $title, $desc, $image) {
+function insertImage($account_id, $title, $desc, $image, $image_delete) {
$title = sanitize($title);
$desc = sanitize($desc);
$image = sanitize($image);
+ $image_delete = sanitize($image_delete);
$account_id = (int)$account_id;
$time = time();
// Insert only if image dosn't already exist there
$exist = mysql_select_single("SELECT `id` FROM `znote_images` WHERE `image`='$image' LIMIT 1;");
if ($exist === false) {
- mysql_insert("INSERT INTO `znote_images` (`title`, `desc`, `date`, `status`, `image`, `account_id`) VALUES ('$title', '$desc', '$time', '1', '$image', '$account_id');");
+ mysql_insert("INSERT INTO `znote_images` (`title`, `desc`, `date`, `status`, `image`, `delhash`, `account_id`) VALUES ('$title', '$desc', '$time', '1', '$image', '$image_delete', '$account_id');");
return true;
}
return false;
diff --git a/gallery.php b/gallery.php
index d667283..4bae2ff 100644
--- a/gallery.php
+++ b/gallery.php
@@ -1,35 +1,51 @@
Create image article
- Works with "Image Code" text from www.freeimagehosting.net
-
loadHTML($imageDom);
- $xml=simplexml_import_dom($doc); // just to make xpath more simple
- $images=$xml->xpath('//img');
- foreach ($images as $img) {
- $imageSrc = (string)$img['src'];
- }
+
+ 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 ($imageSrc !== false) {
+ if ($image_url !== false) {
// Insert to database
- $inserted = insertImage((int)$session_user_id, $title, $desc, $imageSrc);
+ $inserted = insertImage((int)$session_user_id, $title, $desc, $image_url, $image_delete);
if ($inserted === true) {
?>
Image Posted
@@ -43,7 +59,7 @@ if ($logged_in === true) {
-
+
|
@@ -93,7 +109,7 @@ if (empty($_POST)) {
-
+
|