-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
236 lines (204 loc) · 10.1 KB
/
Copy pathindex.php
File metadata and controls
236 lines (204 loc) · 10.1 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
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
<?php
error_reporting(E_ALL & ~E_DEPRECATED);
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/includes/database.php';
require_once __DIR__ . '/includes/functions.php';
require_once __DIR__ . '/config/cloudinary_config.php';
use Dotenv\Dotenv;
use Cloudinary\Configuration\Configuration;
use Cloudinary\Cloudinary;
use Cloudinary\Api\Admin\AdminApi;
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
// Initialize Configuration
$config = new Configuration($_ENV['CLOUDINARY_URL']);
$api = new AdminAPI($config);
$metadataFieldExists = false;
try {
$uploadPreset = $api->uploadPreset("php_demo_preset");
// Attempt to fetch the metadata fields + upload preset by ID
$allFieldsResponse = $api->listMetadataFields();
$allFields = $allFieldsResponse['metadata_fields'] ?? [];
$categoryField = false;
$descriptionField = false;
$priceField = false;
$skuField = false;
foreach ($allFields as $field) {
if ($field['label'] === "Description") {
$descriptionField = true;
if ($priceField && $categoryField && $skuField) {
break;
}
}
if ($field['label'] === "Price") {
$priceField = true;
if ($descriptionField && $categoryField&& $skuField) {
break;
}
}
if ($field['label'] === "Category") {
// Field with exact label and external ID found
$categoryField = true;
if ($priceField && $descriptionField && $skuField) {
break;
}
}
if ($field['label'] === "SKU") {
$skuField = true;
if ($priceField === true && $categoryField === true && $descriptionField === true) {
break;
}
}
}
// If all fields exist, set skuFieldExists to true
if ($categoryField && $descriptionField && $priceField && $skuField && $uploadPreset) {
$metadataFieldExists = true;
} else {
$metadataFieldExists = false;
}
} catch (Exception $e) {
// Handle the exception if needed
$metadataFieldExists = false;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Product Catalog</title>
<link rel="stylesheet" href="../static/styles.css">
<script src="https://upload-widget.cloudinary.com/global/all.js"></script>
<style>
/* General body styling */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f8f9fa;
}
p, li {
font-size: 10px;
}
li {
margin-top: 3px;
}
h4 {
margin-bottom: -3px;
}
.action-buttons {
margin-top: 20px;
}
.action-buttons button {
background-color: #007bff;
color: white;
border: none;
padding: 10px 20px;
font-size: 14px;
margin-right: 10px;
border-radius: 5px;
cursor: pointer;
}
.action-buttons button:hover {
background-color: #0056b3;
}
li{color:grey;}
</style>
</head>
<body>
<!-- Navigation Bar -->
<nav id="nav">
<ul>
<li><a style="font-size:1.3rem;font-weight:75;color:white;" href="">Catalog Creation App</a></li>
<li style="margin-left:60px;"><a href="public/products.php">View Products</a></li>
<li><a href="public/product_submission.php">Add Product</a></li>
</ul>
</nav>
<p style="height:50px;"></p>
<h2>Welcome to the Product Catalog Creation App!</h2>
<div id="setupSequence" class="action-buttons" style="display:flex;justify-content:center;flex-direction:column;margin-top:-10px;">
<h4 id="setupMsg" style="align-self:center;">Make sure you copied your <a href="https://console.cloudinary.com/settings/api-keys">credentials</a> into your .env file, then click this button to run setup:</h4>
<button id="setupButton" onclick="window.location.href='../config/setup_metadata.php'">Set Up Metadata, Create Upload Preset, Upload Samples</button>
<p style="align-self:center;color:black;font-size:15px;" id="metadataMsg">Your metadata and other configurations are all set!</p>
<h4 style="align-self:center;" id="addProduct" >Click <a href="public/product_submission.php">Add Product</a> to start.</h4>
<div id="spinner" style="display:none;margin-top:20px;justify-content:center; align-items:center;">
<div class="loader"></div>
</div>
</div>
<script>
var metadataFieldExists = <?php echo json_encode($metadataFieldExists); ?>;
if (metadataFieldExists) {
// Hide the setup button if the metadata field exists
document.getElementById('setupButton').style.disabled = true;
document.getElementById('setupButton').style.pointerEvents = 'none';
document.getElementById('setupButton').style.opacity = '0.3';
document.getElementById('setupMsg').style.opacity = '0.3';
document.getElementById('setupMsg').style.pointerEvents = 'none';
document.getElementById('metadataMsg').style.display=true;
} else {
document.getElementById('nav').style.disabled = true;
document.getElementById('nav').style.pointerEvents = 'none';
document.getElementById('nav').style.opacity = '0.5';
document.getElementById('addProduct').style.disabled = true;
document.getElementById('addProduct').style.pointerEvents = 'none';
document.getElementById('addProduct').style.opacity = '0.5';
document.getElementById('metadataMsg').style.display='none';
}
document.getElementById('setupButton').addEventListener('click', function () {
// Show the spinner
document.getElementById('spinner').style.display = 'flex';
// Disable the button to prevent multiple clicks
this.disabled = true;
// Redirect to the setup script
window.location.href = '../config/setup_metadata.php';
});
</script>
<div class="container">
<h4>Overview</h4>
<p>This app helps you manage a catalog of products, each featuring a name, metadata (description, SKU, price, and category), an image with AI-generated alt text, and a video that undergoes content moderation for appropriateness.</p>
<p>You can:</p>
<ul>
<li><a href="public/product_submission.php">Add new products.</a></li>
<li><a href="public/products.php">View all products in the catalog.</a></li>
<li>View individual products in detail.</li>
<li>Edit product details.</li>
</ul>
<h4>Database Integration</h4>
<ul>
<li>The database securely stores product information, including:
<ul>
<li style="margin-top:5px;">User-entered product names.</li>
<li>Auto-generated Cloudinary <a href="https://cloudinary.com/documentation/cloudinary_glossary#public_id">public IDs</a> for images and videos.</li>
<li>Video moderation status.</li>
<li>AI-generated image alt texts.</li>
</ul>
</li>
<li style="margin-top:5px;">Storing this information ensures consistent access for app features.</li>
</ul>
<H4>Product Images</H4>
<ul>
<li><b>Client-Side Upload</b>: Images are uploaded directly from the client side using the <a href="https://cloudinary.com/documentation/upload_widget">Upload Widget</a>, eliminating backend dependencies.</li>
<li><b>Synchronous Processing with AI-Generated Alt Text</b>: Images are processed immediately automatically generating alt text using <a href="https://cloudinary.com/documentation/cloudinary_ai_content_analysis_addon">Cloudinary's AI Content Analysis</a>.</li>
<li><b>Dynamic Delivery</b>: Public IDs are stored in the database to <a href="https://cloudinary.com/documentation/php_image_manipulation#direct_url_building">generate delivery URLs</a> with <a href="https://cloudinary.com/documentation/transformation_reference#c_fill"> transformations like resizing and cropping</a>. <a href="https://cloudinary.com/documentation/transformation_reference#g_gravity">Automatic gravity</a> ensures the important parts of the image stay in focus, while <a href="https://cloudinary.com/documentation/transformation_reference#l_layer">overlays</a> are applied for branding.</li>
<li><b>Metadata Management</b>: User-provided metadata is saved in Cloudinary and retrieved for display using the <a href="https://cloudinary.com/documentation/admin_api#get_details_of_a_single_resource_by_public_id">resource</a> endpoint of the Admin API.</li>
</ul>
<H4>Product Videos</H4>
<ul>
<li><b>Client-Side Upload</b>: Videos are uploaded directly from the client side using the <a href="https://cloudinary.com/documentation/php_image_and_video_upload#php_video_upload">Upload API</a>, bypassing backend processes.</li>
<li><b>Asynchronous Processing with Content Moderation</b>: Videos are moderated in the background using <a href="https://cloudinary.com/documentation/php_image_and_video_upload#php_video_upload">Amazon Rekognition Video Moderation</a>, allowing users to continue using the app during processing.</li>
<ul>
<li>Approved videos are saved to the database and displayed.</li>
<li>Rejected videos are excluded, with a message explaining the reason.</li>
</ul>
<li><b>Enhanced Video Playback</b>: Videos are rendered using Cloudinary's <a href="https://cloudinary.com/documentation/cloudinary_video_player">Video Player</a>.</li>
</ul>
<H4>Optional</H4>
<ul>
<li><b>Webhook Integration</b>: Receive real-time <a href="https://cloudinary.com/documentation/notifications">notifications</a> when moderation results are ready.</li>
<li><b>Live Updates</b>: Product pages auto-refresh to display newly approved videos without manual intervention.</li>
</ul>
</ul>
<p>Explore the app's features and manage your catalog seamlessly!</p>
</div>
</body>
</html>