Allow sharing wishlist
This commit is contained in:
parent
cfdd49bb23
commit
3dd6c276b4
7 changed files with 155 additions and 8 deletions
|
@ -9,9 +9,11 @@ $(function() {
|
|||
|
||||
if (wishlistValue) {
|
||||
$('.wishlist-view').removeClass('disabled');
|
||||
$('.wishlist-share').removeClass('disabled');
|
||||
$('.wishlist-delete button').removeClass('disabled');
|
||||
} else {
|
||||
$('.wishlist-view').addClass('disabled');
|
||||
$('.wishlist-share').addClass('disabled');
|
||||
$('.wishlist-delete button').addClass('disabled');
|
||||
}
|
||||
});
|
||||
|
|
|
@ -122,7 +122,7 @@ switch ($step) {
|
|||
$database->query('CREATE TABLE `products` (
|
||||
`id` int NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`wishlist` int NOT NULL,
|
||||
`url` VARCHAR(255) NOT NULL,
|
||||
`hash` VARCHAR(255) NOT NULL INDEX,
|
||||
FOREIGN KEY (`wishlist`)
|
||||
REFERENCES `wishlists` (`id`)
|
||||
ON DELETE CASCADE
|
||||
|
|
|
@ -31,8 +31,9 @@ if ('POST' === $_SERVER['REQUEST_METHOD']) {
|
|||
$database->query('ALTER TABLE `users` ADD INDEX(`password`);');
|
||||
|
||||
$database->query('ALTER TABLE `wishlists`
|
||||
ADD `url` VARCHAR(128) NOT NULL AFTER `name`
|
||||
ADD `hash` VARCHAR(128) NOT NULL AFTER `name`
|
||||
;');
|
||||
$database->query('ALTER TABLE `wishlists` ADD INDEX(`hash`);');
|
||||
|
||||
$database->query('INSERT INTO `options` (`key`, `value`) VALUES ("version", "' . VERSION . '");');
|
||||
|
||||
|
|
|
@ -12,8 +12,15 @@ $page = new page(__FILE__, 'Create a wishlist');
|
|||
|
||||
if (isset($_POST['name'])) {
|
||||
$database->query('INSERT INTO `wishlists`
|
||||
(`user`, `name`) VALUES
|
||||
(' . $_SESSION['user']['id'] . ', "' . $_POST['name'] . '")
|
||||
(
|
||||
`user`,
|
||||
`name`,
|
||||
`hash`
|
||||
) VALUES (
|
||||
' . $_SESSION['user']['id'] . ',
|
||||
"' . $_POST['name'] . '",
|
||||
"' . time() . $_SESSION['user']['id'] . $_POST['name'] . '"
|
||||
)
|
||||
;');
|
||||
|
||||
header('Location: /?page=wishlist-product-add');
|
||||
|
|
|
@ -20,8 +20,10 @@ $products = array();
|
|||
*/
|
||||
if (isset($_GET['wishlist'])) {
|
||||
$user = new User();
|
||||
$wishlist = $_GET['wishlist'];
|
||||
$products = $user->getProducts($wishlist);
|
||||
$wishlist = $database->query('SELECT * FROM `wishlists`
|
||||
WHERE `id` = "' . $_GET['wishlist'] . '"')
|
||||
->fetch();
|
||||
$products = $user->getProducts($_GET['wishlist']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,10 +61,10 @@ if (isset($_POST['wishlist_delete_id'])) {
|
|||
<h2 class="ui header">Options</h1>
|
||||
<p>Wishlist related options.</p>
|
||||
|
||||
<button class="ui small labeled icon button disabled">
|
||||
<a class="ui small labeled icon button wishlist-share disabled" href="/?wishlist=<?= $wishlist['hash'] ?? '' ?>" target="_blank">
|
||||
<i class="share icon"></i>
|
||||
Share
|
||||
</button>
|
||||
</a>
|
||||
|
||||
<form class="ui form wishlist-delete" method="post" style="display: inline-block;">
|
||||
<input type="hidden" name="wishlist_delete_id" />
|
||||
|
|
128
includes/pages/wishlist.php
Normal file
128
includes/pages/wishlist.php
Normal file
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* wishlist.php
|
||||
*
|
||||
* @author Jay Trees <github.jay@grandel.anonaddy.me>
|
||||
*/
|
||||
|
||||
use wishthis\{Page, User};
|
||||
use Embed\Embed;
|
||||
|
||||
$page = new page(__FILE__, 'Wishlist');
|
||||
$page->header();
|
||||
$page->navigation();
|
||||
|
||||
$user = new User();
|
||||
|
||||
$wishlist = $database->query('SELECT * FROM `wishlists`
|
||||
WHERE `hash` = "' . $_GET['wishlist'] . '"')
|
||||
->fetch();
|
||||
|
||||
$products = $user->getProducts($wishlist['id']);
|
||||
?>
|
||||
|
||||
<main>
|
||||
<div class="ui container">
|
||||
<h1 class="ui header"><?= $page->title ?></h1>
|
||||
|
||||
<div class="ui segment">
|
||||
<h2 class="ui header"><?= $wishlist['name'] ?></h2>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($products)) { ?>
|
||||
<div class="ui three column grid">
|
||||
|
||||
<?php foreach ($products as $product) { ?>
|
||||
<?php
|
||||
/**
|
||||
* @link https://github.com/oscarotero/Embed
|
||||
*/
|
||||
$embed = new Embed();
|
||||
$info = $embed->get($product['url']);
|
||||
?>
|
||||
<div class="column">
|
||||
<div class="ui fluid card">
|
||||
|
||||
<?php if ($info->image) { ?>
|
||||
<div class="image">
|
||||
<img src="<?= $info->image ?>" />
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="content">
|
||||
<?php if ($info->title) { ?>
|
||||
<div class="header">
|
||||
<?php if ($info->url) { ?>
|
||||
<a href="<?= $info->url ?>" target="_blank"><?= $info->title ?></a>
|
||||
<?php } else { ?>
|
||||
<?= $info->title ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($info->keywords) { ?>
|
||||
<div class="meta">
|
||||
<?= $info->keywords ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($info->description) { ?>
|
||||
<div class="description">
|
||||
<?= $info->description ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="extra content">
|
||||
<?php if ($info->publishedTime) { ?>
|
||||
<span class="right floated">
|
||||
<?= $info->publishedTime ?>
|
||||
</span>
|
||||
<?php } ?>
|
||||
<?php if ($info->favicon) { ?>
|
||||
<?php if ($info->providerName) { ?>
|
||||
<img src="<?= $info->favicon ?>"
|
||||
title="<?= $info->providerName ?>"
|
||||
alt="<?= $info->providerName ?>"
|
||||
/>
|
||||
<?php } else { ?>
|
||||
<img src="<?= $info->favicon ?>" />
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<?php if (isset($_GET['wishlist'])) { ?>
|
||||
<div class="ui icon message">
|
||||
<i class="info circle icon"></i>
|
||||
<div class="content">
|
||||
<div class="header">
|
||||
Empty
|
||||
</div>
|
||||
<p>The selected wishlist seems to be empty.</p>
|
||||
<a class="ui mini button" href="/?page=wishlist-product-add">Add a product</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="ui icon message">
|
||||
<i class="info circle icon"></i>
|
||||
<div class="content">
|
||||
<div class="header">
|
||||
No wishlist selected
|
||||
</div>
|
||||
<p>Select a wishlist to see it's products.</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<?php
|
||||
$page->footer();
|
||||
?>
|
|
@ -79,6 +79,13 @@ if ($options) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wishlist
|
||||
*/
|
||||
if (!isset($_GET['page']) && isset($_GET['wishlist'])) {
|
||||
$page = 'wishlist';
|
||||
}
|
||||
|
||||
/**
|
||||
* Page
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue