PluginProbe
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more / 3.6.1
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more v3.6.1
3.7.2 3.7.1 3.7.0 3.6.0 3.6.1 3.5.2 trunk 2.0 2.1 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.6.0 2.6.1 All 73 releases
stockpack / src / class-stockpackmedia.php

class-stockpackmedia.php in StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more 3.6.1, at src/class-stockpackmedia.php

809 lines 45.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7 if ( ! class_exists( 'StockpackMedia' ) ) {
8 class StockpackMedia {
9 /**
10 * @var Singleton The reference the *Singleton* instance of this class
11 */
12 private static $instance;
13
14 /**
15 * @var WeDevs_Settings_API
16 */
17 public $settings_api;
18
19 /** @var StockpackAdmin */
20 public $admin;
21
22 /** @var StockpackSettings */
23 public $settings;
24
25 /**
26 * @var string plugin version
27 */
28 public $version = '3.6.1';
29
30 /**
31 * Returns the *Singleton* instance of this class.
32 *
33 * @return Singleton The *Singleton* instance.
34 */
35 public static function get_instance() {
36 if ( null === self::$instance ) {
37 self::$instance = new self();
38 }
39
40 return self::$instance;
41 }
42
43 /**
44 * StockPack constructor.
45 */
46 protected function __construct() {
47 add_action( 'init', array( $this, 'init' ) );
48 }
49
50 /**
51 *
52 */
53 public function init() {
54 $this->admin = \StockpackAdmin::get_instance();
55 $this->settings = \StockpackSettings::get_instance();
56 $this->filters();
57 $this->actions();
58 }
59
60 /**
61 *
62 */
63 public function enqueue( $admin = true, $no_dialog = false ) {
64 global $pagenow;
65
66 if(stockpack_early_admin_enqueue()){
67 wp_enqueue_media();
68 }
69
70 if(did_action('wp_enqueue_media') || (isset($_GET['page']) && $_GET['page'] === 'stockpack') || stockpack_frontend_load()) {
71 $this->enqueue_scripts($admin);
72 $this->enqueue_styles($no_dialog);
73 }
74 $this->enqueue_settings( $admin );
75 }
76
77 public function enqueue_scripts( $admin ) {
78 $name = 'stockpack-load-admin.js';
79 $script = 'stockpack';
80
81 $acfe_classic_editor = false;
82 if (is_plugin_active( 'acf-extended-pro/acf-extended.php' )) {
83 if( function_exists('acfe_get_setting') ) {
84 $acfe_classic_editor = acfe_get_setting('modules/classic_editor');
85 }
86 }
87
88 if ( ! $admin || is_plugin_active( 'classic-editor/classic-editor.php' ) || is_plugin_active( 'classic-editor-addon/classic-editor-addon.php' ) || $acfe_classic_editor ) {
89 add_thickbox();
90 wp_enqueue_media();
91 $name = 'stockpack-load-frontend.js';
92 $script = 'b-stockpack';
93 }
94
95
96 // only brizy removes these scripts
97 if ( wp_script_is( 'wp-color-picker' ) === false ) {
98 wp_register_script( 'wp-color-picker', "/wp-admin/js/color-picker.min.js", array( 'mediaelement' ), false, 1 );
99 }
100
101 $this->register_dialog_js();
102
103 wp_enqueue_script( $script, plugins_url( '/dist/js/' . $name, STOCKPACK_DIR ), array(
104 'media-views',
105 'wp-color-picker',
106 'jquery-ui-dialog'
107 ), $this->version, !stockpack_early_admin_enqueue() );
108
109 // make sure divi media library is added after
110 if ( wp_script_is( 'et_pb_media_library' ) === true ) {
111 wp_dequeue_script( 'et_pb_media_library' );
112 wp_deregister_script( 'et_pb_media_library' );
113 wp_enqueue_script( 'et_pb_media_library', ET_BUILDER_URI . '/scripts/ext/media-library.js', array(
114 'media-editor',
115 $script
116 ), ET_BUILDER_PRODUCT_VERSION, true );
117 }
118 }
119
120 public function enqueue_styles( $no_dialog ) {
121 global $wp_version;
122
123 wp_enqueue_style( 'wp-color-picker' );
124 if ( ! $no_dialog && ! ( isset( $_GET['ct_builder'] ) ) ) {
125 wp_enqueue_style( 'wp-jquery-ui-dialog' );
126 }
127 wp_enqueue_style( 'stockpack-admin', plugins_url( '/dist/css/stockpack.css', STOCKPACK_DIR ), false, $this->version );
128
129
130 if ( version_compare( $wp_version, '5.3', '<=' ) ) {
131 wp_enqueue_style( 'stockpack-admin-old', plugins_url( '/dist/css/stockpack-old-admin.css', STOCKPACK_DIR ), false, $this->version );
132 }
133
134 if(is_plugin_active( 'media-library-organizer/media-library-organizer.php' ) ){
135 wp_enqueue_style( 'stockpack-mlo-compatibility', plugins_url( '/dist/css/stockpack-mlo-compatibility.css', STOCKPACK_DIR ), false, $this->version );
136 }
137 }
138
139 public function enqueue_settings( $admin ) {
140 if ( $admin && function_exists( 'get_current_screen' ) ) {
141 $screen = get_current_screen();
142 if ( $screen->id === 'settings_page_stockpack' ) {
143 wp_enqueue_script( 'stockpack-admin', plugins_url( '/dist/js/stockpack-settings.js', STOCKPACK_DIR ), array( 'jquery' ), $this->version, true );
144 wp_enqueue_style( 'settings-stockpack', plugins_url( '/dist/css/stockpack-settings.css', STOCKPACK_DIR ), array(), $this->version );
145 }
146 }
147 }
148
149 public function upscale_row_action( $actions, $post ) {
150 if ( ! current_user_can( 'upload_files' ) || ! wp_attachment_is_image( $post->ID ) ) {
151 return $actions;
152 }
153
154 $source = function_exists( 'wp_get_original_image_url' )
155 ? wp_get_original_image_url( $post->ID )
156 : false;
157
158 $url = esc_url( $source ? $source : wp_get_attachment_url( $post->ID ) );
159
160 foreach ( array( 2, 4 ) as $factor ) {
161 $actions[ 'stockpack_upscale_' . $factor ] = sprintf(
162 '<a href="#" class="stockpack-upscale" data-url="%s" data-factor="%d">%s</a>',
163 $url,
164 $factor,
165 /* translators: %d: upscale factor, 2 or 4 */
166 sprintf( esc_html__( 'Upscale %dx', 'stockpack' ), $factor )
167 );
168 }
169
170 return $actions;
171 }
172
173 public function enqueue_upscale() {
174 global $pagenow;
175
176 if ( 'upload.php' !== $pagenow || ! current_user_can( 'upload_files' ) ) {
177 return;
178 }
179
180 wp_enqueue_script( 'stockpack-upscale', plugins_url( '/dist/js/stockpack-upscale.js', STOCKPACK_DIR ),
181 array( 'jquery' ), $this->version, true );
182
183 wp_localize_script( 'stockpack-upscale', 'stockpackUpscale', array(
184 'nonceGenerate' => wp_create_nonce( 'stockpack_generate' ),
185 'nonceDownload' => wp_create_nonce( 'stockpack_download' ),
186 'editUrl' => admin_url( 'post.php?action=edit&post=' ),
187 'strings' => array(
188 'confirm' => __( "Upscaling uses credits on your Magnific plan. Precision upscales are priced by the size of the result, usually 200 credits or more.\n\nUpscale this image?", 'stockpack' ),
189 'working' => __( 'Upscaling with Magnific, this can take a minute. Keep this page open, or the upscale is still charged but the image is not saved.', 'stockpack' ),
190 'saving' => __( 'Saving the upscaled image to your media library. Keep this page open, it will open the image when it is done.', 'stockpack' ),
191 'leaving' => __( 'The upscale is still running. Leaving now still costs credits, but the image will not be saved.', 'stockpack' ),
192 'busy' => __( 'An upscale is already running. Wait for it to finish before starting another.', 'stockpack' ),
193 'done' => __( 'Upscaled image saved. Opening it now...', 'stockpack' ),
194 'timeout' => __( 'The upscale is taking longer than expected. Check your Magnific account before retrying.',
195 'stockpack' ),
196 'failed' => __( 'The upscale could not be completed.', 'stockpack' ),
197 ),
198 ) );
199 }
200
201 public function enqueue_frontend() {
202 $this->enqueue( false );
203 }
204
205 public function enqueue_elementor() {
206 $this->enqueue( true, true );
207 }
208
209 public function enqueue_elementor_before() {
210 wp_enqueue_style( 'wp-jquery-ui-dialog' );
211 }
212
213 public function enqueue_themefusion() {
214 $this->enqueue( true, true );
215 $this->load_frontend_style();
216 }
217
218 public function register_dialog_js()
219 {
220 if(wp_script_is('jquery-ui-dialog') === false) {
221 wp_register_script('jquery-ui-dialog', "/wp-includes/js/jquery/ui/dialog.min.js", array(
222 'jquery-ui-resizable',
223 'jquery-ui-draggable',
224 'jquery-ui-button',
225 'jquery-ui-position'
226 ), false, 1);
227 }
228 }
229
230 public function enqueue_admin_script_tag() {
231 echo '<script src="' . plugins_url( '/dist/js/stockpack-load-admin.js', STOCKPACK_DIR ) . '"></script>';
232 }
233
234 public function enqueue_dialog_script_tag() {
235 echo '<script src="' . includes_url( '/js/jquery/ui/resizable.js' ) . '"></script>';
236 echo '<script src="' . includes_url( '/js/jquery/ui/draggable.js' ) . '"></script>';
237 echo '<script src="' . includes_url( '/js/jquery/ui/button.js' ) . '"></script>';
238 echo '<script src="' . includes_url( '/js/jquery/ui/dialog.js' ) . '"></script>';
239 }
240
241 public function enqueue_dialog_style_tag() {
242 echo '<link rel="stylesheet" href="' . includes_url( '/css/jquery-ui-dialog.css' ) . '"></style>';
243 }
244
245 public function enqueue_admin_script_localization() {
246 $strings = $this->settings(array(),null);
247 echo '<script type="text/javascript">
248 window.wp = window.wp || {};
249 window.wp.media = window.wp.media || {};
250 window.wp.media.view = window.wp.media.view || {};
251 window.wp.media.view.settings = window.wp.media.view.settings || {};
252 window.wp.media.view.settings["stockpack"]='.json_encode($strings['stockpack']).';
253 console.log(wp.media.view.settings.stockpack);
254 </script>';
255 }
256
257 public function enqueue_admin() {
258 $this->enqueue( true );
259 }
260
261 public function load_frontend_style() {
262 wp_enqueue_style( 'stockpack-frontend', plugins_url( '/dist/css/stockpack-frontend.css', STOCKPACK_DIR ), false, $this->version );
263 }
264
265
266 /**
267 *
268 */
269 public function filters() {
270 add_filter( 'media_row_actions', array( $this, 'upscale_row_action' ), 10, 2 );
271 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_upscale' ) );
272 add_filter( 'media_view_strings', array( $this, 'tab_text' ), 10, 2 );
273 add_filter( 'media_view_settings', array( $this, 'settings' ), 10, 2 );
274 }
275
276 public function actions() {
277 add_action( 'admin_head', array( $this, 'templates' ) );
278 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin' ), stockpack_early_admin_enqueue() ? 1 : 99 );
279 add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'enqueue_elementor_before' ) );
280 add_action( 'elementor/editor/footer', array( $this, 'templates' ) );
281 // elementor is special
282 add_action( 'elementor/editor/footer', array( $this, 'enqueue_elementor' ), 99 );
283 add_action( 'elementor/editor/footer', array( $this, 'load_frontend_style' ), 99 );
284
285 add_action( 'fusion_builder_enqueue_live_scripts', array( $this, 'enqueue_themefusion' ), 99 );
286
287
288 if ( stockpack_frontend_load() ) {
289 add_action( 'wp_enqueue_scripts', array( $this, 'templates' ) );
290
291 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend' ) );
292
293 add_action( 'wp_enqueue_scripts', array( $this, 'load_frontend_style' ), 99 );
294
295 }
296
297 if ( ( isset( $_GET['fl_builder'] ) )&& !isset($_GET['fl_builder_iframe']) ) {
298 add_action( 'wp_head', array( $this, 'enqueue_dialog_style_tag'), 100 );
299 add_action( 'wp_footer', array( $this, 'enqueue_dialog_script_tag'), 100 );
300 add_action( 'wp_footer', array( $this, 'enqueue_admin_script_tag' ), 100 );
301 }
302
303 if ( ( isset( $_GET['tve'] ) ) ) {
304 add_action( 'tcb_hook_editor_footer', array( $this, 'templates' ), 1 );
305 add_action( 'tcb_hook_template_redirect', array( $this, 'load_frontend_style' ), 100 );
306 add_action( 'tcb_hook_template_redirect', array( $this, 'enqueue' ), 100 );
307 }
308 }
309
310
311 /**
312 *
313 */
314 public function templates() {
315
316 if (!did_action('wp_enqueue_media') || (isset($_GET['page']) && $_GET['page'] === 'stockpack') ) {
317 if(!stockpack_frontend_load()) {
318 return;
319 }
320 }
321
322 include_once(__DIR__ . '/../templates/attachment.php');
323 include_once(__DIR__ . '/../templates/empty.php');
324 include_once(__DIR__ . '/../templates/details.php');
325 include_once(__DIR__ . '/../templates/downloader.php');
326 include_once(__DIR__ . '/../templates/dialog.php');
327 include_once(__DIR__ . '/../templates/attribution.php');
328 include_once(__DIR__ . '/../templates/no-search.php');
329
330 }
331
332 /**
333 * @param $strings
334 * @param $post
335 *
336 * @return array
337 */
338 public function tab_text( $strings, $post ) {
339 if ( ! defined( 'STOCKPACK_DASHBOARD_URL' ) ) {
340 $dashboard_url = 'https://stockpack.co';
341 } else {
342 $dashboard_url = STOCKPACK_DASHBOARD_URL;
343 }
344
345 $plugin_url = str_replace( '/src/', '', plugin_dir_url( __FILE__ ) );
346
347 $strings['stockpack'] = array(
348 'title' => __( 'StockPack', 'stockpack' ),
349 'button' => __( 'Insert into post', 'stockpack' ),
350 'retry' => __( 'Retry', 'stockpack' ),
351 'noMedia' => __( 'No images have been found', 'stockpack' ),
352 'noSearch' => __( 'Start searching for images', 'stockpack' ),
353 'inspiration' => array(
354 'unsure' => __( 'Not sure what to search for?', 'stockpack' ),
355 'random' => array(
356 'item_1' => array(
357 'message' => __( 'Try "balloons" in the top right search input', 'stockpack' ),
358 'image' => $plugin_url . '/images/balloons.png',
359 ),
360 'item_2' => array(
361 'message' => __( 'Try "unicorn" in the top right search input', 'stockpack' ),
362 'image' => $plugin_url . '/images/unicorn.png',
363 ),
364 'item_3' => array(
365 'message' => __( 'Try "ice cream" in the top right search input', 'stockpack' ),
366 'image' => $plugin_url . '/images/icecream.png',
367 ),
368 'item_4' => array(
369 'message' => __( 'Try "moon" in the top right search input', 'stockpack' ),
370 'image' => $plugin_url . '/images/moon.png',
371 ),
372 'item_5' => array(
373 'message' => __( 'Try "coffee" in the top right search input', 'stockpack' ),
374 'image' => $plugin_url . '/images/coffee.png',
375 ),
376 'item_6' => array(
377 'message' => __( 'Try "tea" in the top right search input', 'stockpack' ),
378 'image' => $plugin_url . '/images/tea.png',
379 ),
380 'item_7' => array(
381 'message' => __( 'Try "lighthouse" in the top right search input', 'stockpack' ),
382 'image' => $plugin_url . '/images/lighthouse.png',
383 ),
384 'item_8' => array(
385 'message' => __( 'Try "mountains" in the top right search input', 'stockpack' ),
386 'image' => $plugin_url . '/images/mountains.png',
387 )
388
389
390 ),
391 ),
392 'error' => [
393 'default' => __( 'There has been an error', 'stockpack' ),
394 'token_expired' => __( 'The access you granted for this provider has expired', 'stockpack' ),
395 'invalid_token' => __( 'Double check the token on the settings page!', 'stockpack' ),
396 'premium_limit_reached' => __( 'Premium account requests limit reached', 'stockpack' ),
397 'free_limit_reached' => __( 'Free account requests limit reached', 'stockpack' ),
398 'anonymous_limit_reached' => __( 'Anonymous requests limit reached', 'stockpack' ),
399 ],
400 'link' => __( 'Set token', 'stockpack' ),
401 'search' => __( 'Search images', 'stockpack' ),
402 'generate' => [
403 'prompt' => __( 'Describe the image you want', 'stockpack' ),
404 'button' => __( 'Generate', 'stockpack' ),
405 'clear' => __( 'Clear', 'stockpack' ),
406 'working' => __( 'Generating...', 'stockpack' ),
407 'timeout' => __( 'The image is taking longer than expected. Check your Magnific account before retrying.', 'stockpack' ),
408 'models' => $this->ai_model_labels(),
409 'credits' => $this->ai_model_costs(),
410 'refine' => [
411 'label' => __( 'Refine the selected image', 'stockpack' ),
412 'hint' => __( 'Select a generated image first, then refine it with a new prompt.', 'stockpack' ),
413 'note' => __( 'Refining sends the selected image along with your prompt. Magnific charges more for a reference image, so expect roughly double.', 'stockpack' ),
414 'multiply' => $this->ai_refine_multiplier(),
415 ],
416 /* translators: %s: price per image, already formatted */
417 'cost' => __( '%s / image', 'stockpack' ),
418 'note' => __( 'Each image is charged to the Magnific account you connected. Generating through StockPack always costs, even when your plan shows unlimited generation inside the Magnific app.', 'stockpack' ),
419 ],
420 'close' => __( 'Close', 'stockpack' ),
421 'download' => __( 'Download', 'stockpack' ),
422 'licenseAction' => __( 'License', 'stockpack' ),
423 'alreadyLicensed' => __( 'Licensed', 'stockpack' ),
424 'noFreeDownload' => __( 'This provider has no free tier. Use License to download, it will tell you the cost first.', 'stockpack' ),
425 'license' => __( 'Your token is not valid', 'stockpack' ),
426 'advanced' => __( 'Advanced search', 'stockpack' ),
427 'filters' => [
428 'gender' => [
429 'label' => __( 'Gender', 'stockpack' ),
430 'female' => __( 'Female', 'stockpack' ),
431 'male' => __( 'Male', 'stockpack' ),
432 ],
433 'provider' => [
434 'label' => __( 'Provider', 'stockpack' ),
435 'default' => __( 'Default', 'stockpack' ),
436 'values' => $this->getProviders()
437 ],
438 'orientation' => [
439 'label' => __( 'Orientation', 'stockpack' ),
440 'horizontal' => __( 'Horizontal', 'stockpack' ),
441 'vertical' => __( 'Vertical', 'stockpack' ),
442 ],
443 'image_type' => [
444 'label' => __( 'Image type', 'stockpack' ),
445 'photo' => __( 'Photos', 'stockpack' ),
446 'vector' => __( 'Vectors', 'stockpack' ),
447 'illustration' => __( 'Illustrations', 'stockpack' ),
448 ],
449 'categories' => [
450 'label' => __( 'Category', 'stockpack' ),
451 'default' => __( 'Any Category', 'stockpack' ),
452 'values' => [
453 'Abstract' => __( 'Abstract', 'stockpack' ),
454 'Animals/Wildlife' => __( 'Animals/Wildlife', 'stockpack' ),
455 'The Arts' => __( 'The Arts', 'stockpack' ),
456 'Backgrounds/Textures' => __( 'Backgrounds/Textures', 'stockpack' ),
457 'Beauty/Fashion' => __( 'Beauty/Fashion', 'stockpack' ),
458 'Buildings/Landmarks' => __( 'Buildings/Landmarks', 'stockpack' ),
459 'Business/Finance' => __( 'Business/Finance', 'stockpack' ),
460 'Celebrities' => __( 'Celebrities', 'stockpack' ),
461 'Editorial' => __( 'Editorial', 'stockpack' ),
462 'Education' => __( 'Education', 'stockpack' ),
463 'Food and Drink' => __( 'Food and Drink', 'stockpack' ),
464 'Healthcare/Medical' => __( 'Healthcare/Medical', 'stockpack' ),
465 'Holidays' => __( 'Holidays', 'stockpack' ),
466 'Illustrations/Clip-Art' => __( 'Illustrations/Clip-Art', 'stockpack' ),
467 'Industrial' => __( 'Industrial', 'stockpack' ),
468 'Interiors' => __( 'Interiors', 'stockpack' ),
469 'Miscellaneous' => __( 'Miscellaneous', 'stockpack' ),
470 'Nature' => __( 'Nature', 'stockpack' ),
471 'Objects' => __( 'Objects', 'stockpack' ),
472 'Parks/Outdoor' => __( 'Parks/Outdoor', 'stockpack' ),
473 'People' => __( 'People', 'stockpack' ),
474 'Religion' => __( 'Religion', 'stockpack' ),
475 'Science' => __( 'Science', 'stockpack' ),
476 'Signs/Symbols' => __( 'Signs/Symbols', 'stockpack' ),
477 'Sports/Recreation' => __( 'Sports/Recreation', 'stockpack' ),
478 'Technology' => __( 'Technology', 'stockpack' ),
479 'Transportation' => __( 'Transportation', 'stockpack' ),
480 'Vectors' => __( 'Vectors', 'stockpack' ),
481 'Vintage' => __( 'Vintage', 'stockpack' ),
482 ]
483 ],
484 'safe' => [
485 'label' => __( 'Safe', 'stockpack' ),
486 'yes' => __( 'Yes', 'stockpack' ),
487 'no' => __( 'No', 'stockpack' ),
488 ],
489 'color' => [
490 'text' => __( 'Color', 'stockpack' ),
491 ],
492
493 ],
494 'terms' => [
495 'agree' => __( 'I agree', 'stockpack' ),
496 'cancel' => __( 'Cancel', 'stockpack' ),
497 'adobe_stock' => [
498 'title' => __( 'Terms agreement', 'stockpack' ),
499 'message' => __( 'Before you download the first image you need to agree to the terms of service of Adobe Stock. This will only be asked once and then we will store it for all subsequent downloads. You are a direct user of the Adobe Stock website and their terms apply. ', 'stockpack' ),
500 'link' => 'https://stock.adobe.com/license-terms'
501 ],
502 'getty' => [
503 'title' => __( 'Terms agreement', 'stockpack' ),
504 'message' => __( 'Before you download the first image you need to agree to the terms of service of Getty Images. This will only be asked once and then we will store it for all subsequent downloads. You are a direct user of the Getty images website and their terms apply. ', 'stockpack' ),
505 'link' => 'https://www.gettyimages.com/eula'
506 ],
507 'istock' => [
508 'title' => __( 'Terms agreement', 'stockpack' ),
509 'message' => __( 'Before you download the first image you need to agree to the terms of service of iStock. This will only be asked once and then we will store it for all subsequent downloads. You are a direct user of the iStock website and their terms apply. ', 'stockpack' ),
510 'link' => 'https://www.istockphoto.com/legal/license-agreement'
511 ],
512 'pixabay' => [
513 'title' => __( 'Terms agreement', 'stockpack' ),
514 'message' => __( 'Before you download the first image you need to agree to the terms of service of Pixabay. This will only be asked once and then we will store it for all subsequent downloads. You are a direct user of the Pixabay website and their terms apply. ', 'stockpack' ),
515 'link' => 'https://pixabay.com/service/terms/'
516 ],
517 'pexels' => [
518 'title' => __( 'Terms agreement', 'stockpack' ),
519 'message' => __( 'Before you download the first image you need to agree to the terms of service of Pexels. This will only be asked once and then we will store it for all subsequent downloads. You are a direct user of the Pexels website and their terms apply. ', 'stockpack' ),
520 'link' => 'https://pexels.com/service/terms/'
521 ],
522 'unsplash' => [
523 'title' => __( 'Terms agreement', 'stockpack' ),
524 'message' => __( 'Before you download the first image you need to agree to the terms of service of Unsplash. This will only be asked once and then we will store it for all subsequent downloads. You are a direct user of the Unsplash website and their terms apply. ', 'stockpack' ),
525 'link' => 'https://unsplash.com/terms'
526 ],
527 'deposit_photos' => [
528 'title' => __( 'Terms agreement', 'stockpack' ),
529 'message' => __( 'Before you download the first image you need to agree to the terms of service of Deposit Photos. This will only be asked once and then we will store it for all subsequent downloads. You are a direct user of the Deposit Photos website and their terms apply. ', 'stockpack' ),
530 'link' => 'https://depositphotos.com/terms-of-use.html'
531 ],
532 'freepik' => [
533 'title' => __( 'Terms agreement', 'stockpack' ),
534 'message' => __( 'Before you download the first image you need to agree to the terms of service of Magnific, formerly Freepik. This will only be asked once and then we will store it for all subsequent downloads. Downloads are made with your own Magnific account, so you are a direct user of their website and their terms apply. ', 'stockpack' ),
535 'link' => 'https://www.magnific.com/legal/terms-of-use'
536 ],
537 'magnific' => [
538 'title' => __( 'Terms agreement', 'stockpack' ),
539 'message' => __( 'Before you use the first generated image you need to agree to the terms of service of Magnific. This will only be asked once and then we will store it for all subsequent images. Images are generated on your own Magnific account, so you are a direct user of their website and their terms apply. ', 'stockpack' ),
540 'link' => 'https://www.magnific.com/legal/terms-of-use'
541 ],
542 ],
543 'licensePopup' => [
544 'proceed' => __( 'Proceed', 'stockpack' ),
545 'checkInProgress' => __( 'Cost checking is in progress, please wait', 'stockpack' ),
546 'cancel' => __( 'Cancel', 'stockpack' ),
547 'adobe_stock' => [
548 'title' => __( 'License and download', 'stockpack' ),
549 'message' => __( 'Licensing an image will provide you a non watermarked image from Adobe Stock.', 'stockpack' ),
550 'status' => __( 'Fetching cost...', 'stockpack' ),
551 'external' => __( 'Adobe stock offers multiple types of accounts and multiple types of licenses. Currently only Standard is supported trough the plugin. You can use the url bellow to license this directly on the Adobe Stock website, in case your account allows that. In the case of credits missing, you can add more credits and retry.', 'stockpack' ),
552 'directLicenseUrl' => __( 'Adobe License Page', 'stockpack' ),
553 ],
554 'getty' => [
555 'title' => __( 'License and download', 'stockpack' ),
556 'message' => __( 'Licensing an image will provide you a non watermarked image from Getty Images.', 'stockpack' ),
557 'status' => __( 'Fetching cost...', 'stockpack' ),
558 'external' => __( 'Getty images offers multiple types of accounts and multiple types of licenses. Currently we couldn\'t find an appropriate package linked to your account for this image. You can license the image from the Getty website. If you make sure that you account has the credits and the package required you can retry to license.', 'stockpack' ),
559 'directLicenseUrl' => __( 'Getty License Page', 'stockpack' ),
560 ],
561 'istock' => [
562 'title' => __( 'License and download', 'stockpack' ),
563 'message' => __( 'Licensing an image will provide you a non watermarked image from iStock', 'stockpack' ),
564 'status' => __( 'Fetching cost...', 'stockpack' ),
565 'external' => __( 'iStock images offers multiple types of accounts and multiple types of licenses. Currently we couldn\'t find an appropriate package linked to your account for this image. You can license the image from the iStock website. If you make sure that you account has the credits and the package required you can retry to license.', 'stockpack' ),
566 'directLicenseUrl' => __( 'iStock License Page', 'stockpack' ),
567 ],
568 'deposit_photos' => [
569 'title' => __( 'License and download', 'stockpack' ),
570 'message' => __( 'Licensing an image will provide you a non watermarked image from Deposit Photos.', 'stockpack' ),
571 'status' => __( 'Fetching cost...', 'stockpack' ),
572 'external' => __( 'Currently only sizes available trough the subscription package are supported by the plugin. You can use the url bellow to license this directly on the Deposit Photos website, in case your account allows that. If you subscription expired renew it and retry.', 'stockpack' ),
573 'directLicenseUrl' => __( 'Deposit Photos License Page', 'stockpack' ),
574 ],
575 'freepik' => [
576 'title' => __( 'License and download', 'stockpack' ),
577 'message' => __( 'Magnific does not offer watermarked previews, so downloading an image gives you the full file straight away.', 'stockpack' ),
578 'status' => __( 'Fetching cost...', 'stockpack' ),
579 'external' => __( 'You can also download this image directly from the Magnific website with the account you connected.', 'stockpack' ),
580 'directLicenseUrl' => __( 'Open on Magnific', 'stockpack' ),
581 ],
582 ],
583 'attribution' => [
584 'adobe_stock' => [
585 'message' => __( 'You are searching images from', 'stockpack' ),
586 'link' => 'https://stockpack.co/recommended/adobe_stock',
587 'link_title' => 'Adobe Stock'
588 ],
589 'default' => [
590 'author_info' => __( 'Stock provider is being fetched...', 'stockpack' ),
591 'message' => __( 'Loading data...', 'stockpack' ),
592 'link' => '',
593 'link_title' => ''
594 ],
595 'getty' => [
596 'message' => __( 'You are searching images from', 'stockpack' ),
597 'link' => 'https://stockpack.co/recommended/getty',
598 'link_title' => 'Getty Images',
599 'warning' => __( 'Watermarked images from Getty Images are allowed for test only (not publicly available), for up to 30 days following download', 'stockpack' ),
600 ],
601 'istock' => [
602 'message' => __( 'You are searching images from', 'stockpack' ),
603 'link' => 'https://stockpack.co/recommended/istock',
604 'link_title' => 'iStock',
605 'warning' => __( 'Watermarked images from iStock are allowed for test only (not publicly available), for up to 30 days following download', 'stockpack' ),
606 ],
607 'pixabay' => [
608 'message' => __( 'You are searching images from', 'stockpack' ),
609 'link' => 'https://stockpack.co/recommended/pixabay',
610 'link_title' => 'Pixabay'
611 ],
612 'pexels' => [
613 'message' => __( 'You are searching images from', 'stockpack' ),
614 'link' => 'https://stockpack.co/recommended/pexels',
615 'link_title' => 'Pexels'
616 ],
617 'unsplash' => [
618 'message' => __( 'You are searching images from', 'stockpack' ),
619 'link' => 'https://stockpack.co/recommended/unsplash',
620 'link_title' => 'Unsplash'
621 ],
622 'deposit_photos' => [
623 'message' => __( 'You are searching images from', 'stockpack' ),
624 'link' => 'https://stockpack.co/recommended/deposit_photos',
625 'link_title' => 'Deposit Photos',
626 'warning' => __( 'Watermarked images from Deposit Photos are allowed for testing only', 'stockpack' ),
627 ],
628 'freepik' => [
629 'author_info' => __( 'Beta. Runs on the Magnific API key you connect', 'stockpack' ),
630 'message' => __( 'You are searching images from', 'stockpack' ),
631 'link' => 'https://www.magnific.com',
632 'link_title' => 'Freepik',
633 ],
634 'magnific' => [
635 'author_info' => __( 'Beta. Runs on the Magnific API key you connect. Earlier images are shown while Magnific still hosts them; download the ones you want to keep.', 'stockpack' ),
636 'message' => __( 'You are generating images with', 'stockpack' ),
637 'link' => 'https://www.magnific.com',
638 'link_title' => 'Magnific',
639 ],
640 ],
641 'limit' => [
642 'premium' => [
643 'title' => __( 'Requests limit reached', 'stockpack' ),
644 'message' => __( 'You have reached the requests limit. This gets reset, but if you reach this often and you need a bigger solution you can contact StockPack support to discuss available options.', 'stockpack' )
645 ],
646 'anonymous' => [
647 'title' => __( 'You need an account to continue', 'stockpack' ),
648 'message' => __( 'You have used all the requests available without an account.', 'stockpack' ),
649 'iframe' => [
650 'src' => $dashboard_url . '/register?skim=1',
651 'id' => 'stockpack-token-iframe',
652 ],
653 'status' => [
654 'initial' => __( 'Fetching remote website ...', 'stockpack' ),
655 'login' => __( 'Sign in using the form below to continue', 'stockpack' ),
656 'register' => __( 'Create an account in the window below to continue', 'stockpack' ),
657 'providers' => __( 'Token is being stored, you will be able to continue shortly', 'stockpack' ),
658 'elsewhere' => __( 'To get back to login you can close this window and open it again, or use the back buttons inside the window', 'stockpack' )
659 ]
660 ],
661 'free' => [
662 'title' => __( 'You need the premium upgrade to continue', 'stockpack' ),
663 'message' => __( 'You have reached the requests limit for the free account.', 'stockpack' ),
664 'iframe' => [
665 'src' => $dashboard_url . '/login?skim=1&upgrade=1',
666 'id' => 'stockpack-upgrade-iframe',
667 ],
668 'status' => [
669 'initial' => __( 'Fetching remote website ...', 'stockpack' ),
670 'providers' => __( 'Refreshing token, you will be able to continue shortly', 'stockpack' ),
671 'login' => __( 'Sign in using the form below to continue', 'stockpack' ),
672 'register' => __( 'Create an account in the window below to continue', 'stockpack' ),
673 'billing' => __( 'Once you upgrade your account you will get upgraded limits which will allow you to proceed right away', 'stockpack' ),
674 'elsewhere' => __( 'To get back to login you can close this window and open it again, or use the back buttons inside the window', 'stockpack' )
675 ]
676 ],
677 'reset' => __( 'Reset time passed, you can try again', 'stockpack' ),
678 'contact' => __( 'Contact', 'stockpack' ),
679 'cancel' => __( 'Cancel', 'stockpack' )
680 ],
681 'filename' => [
682 'placeholder' => __( 'Overwrite filename (No extension)' )
683 ]
684 );
685
686 return $strings;
687 }
688
689 public function settings( $strings, $post ) {
690 $strings['stockpack'] = array(
691 'terms' => [
692 'adobe_stock' => get_option( 'terms_accepted_adobe_stock', false ),
693 'getty' => get_option( 'terms_accepted_getty', false ),
694 'istock' => get_option( 'terms_accepted_istock', false ),
695 'pixabay' => get_option( 'terms_accepted_pixabay', false ),
696 'pexels' => get_option( 'terms_accepted_pexels', false ),
697 'unsplash' => get_option( 'terms_accepted_unsplash', false ),
698 'deposit_photos' => get_option( 'terms_accepted_deposit_photos', false ),
699 'freepik' => get_option( 'terms_accepted_freepik', false ),
700 'magnific' => get_option( 'terms_accepted_magnific', false ),
701 ],
702 'cache_key' => substr( md5( get_current_blog_id() . '|' . get_current_user_id() ), 0, 12 ),
703 'nonce_terms' => wp_create_nonce( 'stockpack_terms' ),
704 'nonce_license_cost' => wp_create_nonce( 'stockpack_license_cost' ),
705 'nonce_query' => wp_create_nonce( 'stockpack_query' ),
706 'nonce_download' => wp_create_nonce( 'stockpack_download' ),
707 'nonce_cache' => wp_create_nonce( 'stockpack_cache' ),
708 'nonce_generate' => wp_create_nonce( 'stockpack_generate' ),
709 'nonce_token' => wp_create_nonce( 'stockpack_token' ),
710 'nonce_validate' => wp_create_nonce( 'stockpack_validate' ),
711 'settings_url' => admin_url( 'options-general.php?page=stockpack' ),
712 'contact_url' => 'https://stockpack.co/contact',
713 'filename_change' => $this->settings->get_file_name_change_setting(),
714 'premium_provider_caption' => $this->settings->get_premium_providers_caption_setting()
715 );
716
717 return $strings;
718 }
719
720
721
722 public function enque_dialog_js() {
723 wp_enqueue_script( 'jquery-ui-dialog', "/wp-includes/js/jquery/ui/dialog.min.js", array(
724 'media-editor',
725 ), false, 1 );
726 }
727
728
729
730 private function ai_models() {
731 $prices = StockPack::get_instance()->query->get_ai_prices();
732
733 if ( isset( $prices['models'] ) && is_array( $prices['models'] ) && $prices['models'] ) {
734 return $prices['models'];
735 }
736
737 return array(
738 'flux-1' => array( 'label' => 'Flux.1', 'eur' => 0.01, 'default' => true ),
739 'mystic-25' => array( 'label' => 'Mystic 2.5', 'eur' => 0.10, 'default' => true ),
740 );
741 }
742
743 private function enabled_ai_models() {
744 $models = $this->ai_models();
745 $selected = $this->settings->get_selected_ai_models();
746
747 if ( $selected === null ) {
748 return array_filter( $models, function ( $model ) {
749 return ! empty( $model['default'] );
750 } );
751 }
752
753 $enabled = array_intersect_key( $models, array_flip( $selected ) );
754
755 return $enabled ?: $models;
756 }
757
758 private function ai_model_labels() {
759 return array_map( function ( $model ) {
760 return isset( $model['label'] ) ? $model['label'] : '';
761 }, $this->enabled_ai_models() );
762 }
763
764 private function ai_model_costs() {
765 return array_map( function ( $model ) {
766 if ( ! isset( $model['eur'] ) ) {
767 return '';
768 }
769
770 return '€' . rtrim( rtrim( number_format( (float) $model['eur'], 3 ), '0' ), '.' );
771 }, $this->enabled_ai_models() );
772 }
773
774 private function ai_refine_multiplier() {
775 $prices = StockPack::get_instance()->query->get_ai_prices();
776
777 return isset( $prices['refine_multiplier'] ) ? (int) $prices['refine_multiplier'] : 2;
778 }
779
780 private function getProviders()
781 {
782 $selected_providers = $this->settings->get_selected_providers_setting();
783 $providers = array(
784 'Adobe Stock' => __('Adobe Stock', 'stockpack'),
785 'Deposit Photos' => __('Deposit Photos', 'stockpack'),
786 'Freepik' => __('Freepik (Magnific, beta)', 'stockpack'),
787 'Magnific AI' => __('Magnific AI (generate, beta)', 'stockpack'),
788 'Getty' => __('Getty Images', 'stockpack'),
789 'iStock' => __('iStock', 'stockpack'),
790 'Pixabay' => __('Pixabay', 'stockpack'),
791 'Pexels' => __('Pexels', 'stockpack'),
792 'Unsplash' => __('Unsplash', 'stockpack'),
793 );
794 foreach ($providers as $key => $value) {
795 if (!in_array($key, $selected_providers)) {
796 unset($providers[$key]);
797 }
798 }
799
800
801 return apply_filters('stockpack_providers', $providers);
802 }
803
804
805 }
806
807 $GLOBALS['stockpack_media'] = StockpackMedia::get_instance();
808 }
809