PluginProbe
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more / 3.7.0
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more v3.7.0
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 3.0.0 3.0.1 All 71 releases
← All changes | src/class-stockpackmedia.php +619 -44 2.13.7.0 View file →
@@ -15,9 +15,20 @@
15 15 * @var WeDevs_Settings_API
16 16 */
17 17 public $settings_api;
18 18
19 + /** @var StockpackAdmin */
20 + public $admin;
21 +
22 + /** @var StockpackSettings */
23 + public $settings;
24 +
19 25 /**
26 + * @var string plugin version
27 + */
28 + public $version = '3.7.0';
29 +
30 + /**
20 31 * Returns the *Singleton* instance of this class.
21 32 *
22 33 * @return Singleton The *Singleton* instance.
23 34 */
@@ -32,9 +43,9 @@
32 43 /**
33 44 * StockPack constructor.
34 45 */
35 46 protected function __construct() {
36 - add_action( 'plugins_loaded', array( $this, 'init' ) );
47 + add_action( 'init', array( $this, 'init' ) );
37 48 }
38 49
39 50 /**
40 51 *
@@ -39,46 +50,265 @@
39 50 /**
40 51 *
41 52 */
42 53 public function init() {
54 + $this->admin = \StockpackAdmin::get_instance();
55 + $this->settings = \StockpackSettings::get_instance();
43 56 $this->filters();
44 57 $this->actions();
45 58 }
46 59
47 -
48 60 /**
49 61 *
50 62 */
51 - public function enqueue() {
52 - $screen = get_current_screen();
53 - wp_enqueue_script( 'stockpack', plugins_url( '../dist/js/stockpack.js', __FILE__ ), array(
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(
54 104 'media-views',
55 105 'wp-color-picker',
56 106 'jquery-ui-dialog'
57 - ), false, true );
107 + ), $this->version, !stockpack_early_admin_enqueue() );
58 108
59 - if ( $screen->id === 'settings_page_stockpack' ) {
60 - wp_enqueue_script( 'stockpack-admin', plugins_url( '../dist/js/stockpack-settings.js', __FILE__ ), array( 'jquery' ), false, true );
61 - wp_enqueue_style( 'settings-stockpack', plugins_url( '../dist/css/stockpack-settings.css', __FILE__ ), array(), false );
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 );
62 117 }
118 + }
119 +
120 + public function enqueue_styles( $no_dialog ) {
121 + global $wp_version;
122 +
63 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 + 'wallet' => $this->ai_wallet(),
188 + 'upscale' => $this->upscale_quotes(),
189 + 'strings' => array(
190 + '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' ),
191 + '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' ),
192 + 'saving' => __( 'Saving the upscaled image to your media library. Keep this page open, it will open the image when it is done.', 'stockpack' ),
193 + 'leaving' => __( 'The upscale is still running. Leaving now still costs credits, but the image will not be saved.', 'stockpack' ),
194 + 'busy' => __( 'An upscale is already running. Wait for it to finish before starting another.', 'stockpack' ),
195 + 'done' => __( 'Upscaled image saved. Opening it now...', 'stockpack' ),
196 + 'timeout' => __( 'The upscale is taking longer than expected. Check your Magnific account before retrying.',
197 + 'stockpack' ),
198 + 'failed' => __( 'The upscale could not be completed.', 'stockpack' ),
199 + 'topUp' => __( 'Top up credits', 'stockpack' ),
200 + ),
201 + ) );
202 + }
203 +
204 + public function enqueue_frontend() {
205 + $this->enqueue( false );
206 + }
207 +
208 + public function enqueue_elementor() {
209 + $this->enqueue( true, true );
210 + }
211 +
212 + public function enqueue_elementor_before() {
64 213 wp_enqueue_style( 'wp-jquery-ui-dialog' );
65 - wp_enqueue_style( 'stockpack-', plugins_url( '../dist/css/stockpack.css', __FILE__ ), false );
214 + }
66 215
216 + public function enqueue_themefusion() {
217 + $this->enqueue( true, true );
218 + $this->load_frontend_style();
67 219 }
68 220
221 + public function register_dialog_js()
222 + {
223 + if(wp_script_is('jquery-ui-dialog') === false) {
224 + wp_register_script('jquery-ui-dialog', "/wp-includes/js/jquery/ui/dialog.min.js", array(
225 + 'jquery-ui-resizable',
226 + 'jquery-ui-draggable',
227 + 'jquery-ui-button',
228 + 'jquery-ui-position'
229 + ), false, 1);
230 + }
231 + }
69 232
233 + public function enqueue_admin_script_tag() {
234 + echo '<script src="' . plugins_url( '/dist/js/stockpack-load-admin.js', STOCKPACK_DIR ) . '"></script>';
235 + }
236 +
237 + public function enqueue_dialog_script_tag() {
238 + echo '<script src="' . includes_url( '/js/jquery/ui/resizable.js' ) . '"></script>';
239 + echo '<script src="' . includes_url( '/js/jquery/ui/draggable.js' ) . '"></script>';
240 + echo '<script src="' . includes_url( '/js/jquery/ui/button.js' ) . '"></script>';
241 + echo '<script src="' . includes_url( '/js/jquery/ui/dialog.js' ) . '"></script>';
242 + }
243 +
244 + public function enqueue_dialog_style_tag() {
245 + echo '<link rel="stylesheet" href="' . includes_url( '/css/jquery-ui-dialog.css' ) . '"></style>';
246 + }
247 +
248 + public function enqueue_admin_script_localization() {
249 + $strings = $this->settings(array(),null);
250 + echo '<script type="text/javascript">
251 + window.wp = window.wp || {};
252 + window.wp.media = window.wp.media || {};
253 + window.wp.media.view = window.wp.media.view || {};
254 + window.wp.media.view.settings = window.wp.media.view.settings || {};
255 + window.wp.media.view.settings["stockpack"]='.json_encode($strings['stockpack']).';
256 + console.log(wp.media.view.settings.stockpack);
257 + </script>';
258 + }
259 +
260 + public function enqueue_admin() {
261 + $this->enqueue( true );
262 + }
263 +
264 + public function load_frontend_style() {
265 + wp_enqueue_style( 'stockpack-frontend', plugins_url( '/dist/css/stockpack-frontend.css', STOCKPACK_DIR ), false, $this->version );
266 + }
267 +
268 +
70 269 /**
71 270 *
72 271 */
73 272 public function filters() {
273 + add_filter( 'media_row_actions', array( $this, 'upscale_row_action' ), 10, 2 );
274 + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_upscale' ) );
74 275 add_filter( 'media_view_strings', array( $this, 'tab_text' ), 10, 2 );
75 276 add_filter( 'media_view_settings', array( $this, 'settings' ), 10, 2 );
76 277 }
77 278
78 279 public function actions() {
79 - add_action( 'admin_enqueue_scripts', array( $this, 'templates' ) );
80 - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
280 + add_action( 'admin_head', array( $this, 'templates' ) );
281 + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin' ), stockpack_early_admin_enqueue() ? 1 : 99 );
282 + add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'enqueue_elementor_before' ) );
283 + add_action( 'elementor/editor/footer', array( $this, 'templates' ) );
284 + // elementor is special
285 + add_action( 'elementor/editor/footer', array( $this, 'enqueue_elementor' ), 99 );
286 + add_action( 'elementor/editor/footer', array( $this, 'load_frontend_style' ), 99 );
287 +
288 + add_action( 'fusion_builder_enqueue_live_scripts', array( $this, 'enqueue_themefusion' ), 99 );
289 +
290 +
291 + if ( stockpack_frontend_load() ) {
292 + add_action( 'wp_enqueue_scripts', array( $this, 'templates' ) );
293 +
294 + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend' ) );
295 +
296 + add_action( 'wp_enqueue_scripts', array( $this, 'load_frontend_style' ), 99 );
297 +
298 + }
299 +
300 + if ( ( isset( $_GET['fl_builder'] ) )&& !isset($_GET['fl_builder_iframe']) ) {
301 + add_action( 'wp_head', array( $this, 'enqueue_dialog_style_tag'), 100 );
302 + add_action( 'wp_footer', array( $this, 'enqueue_dialog_script_tag'), 100 );
303 + add_action( 'wp_footer', array( $this, 'enqueue_admin_script_tag' ), 100 );
304 + }
305 +
306 + if ( ( isset( $_GET['tve'] ) ) ) {
307 + add_action( 'tcb_hook_editor_footer', array( $this, 'templates' ), 1 );
308 + add_action( 'tcb_hook_template_redirect', array( $this, 'load_frontend_style' ), 100 );
309 + add_action( 'tcb_hook_template_redirect', array( $this, 'enqueue' ), 100 );
310 + }
81 311 }
82 312
83 313
84 314 /**
@@ -84,15 +314,23 @@
84 314 /**
85 315 *
86 316 */
87 317 public function templates() {
88 - include_once( __DIR__ . '/../templates/attachment.php' );
89 - include_once( __DIR__ . '/../templates/empty.php' );
90 - include_once( __DIR__ . '/../templates/details.php' );
91 - include_once( __DIR__ . '/../templates/downloader.php' );
92 - include_once( __DIR__ . '/../templates/dialog.php' );
93 - include_once( __DIR__ . '/../templates/attribution.php' );
94 - include_once( __DIR__ . '/../templates/no-search.php' );
318 +
319 + if (!did_action('wp_enqueue_media') || (isset($_GET['page']) && $_GET['page'] === 'stockpack') ) {
320 + if(!stockpack_frontend_load()) {
321 + return;
322 + }
323 + }
324 +
325 + include_once(__DIR__ . '/../templates/attachment.php');
326 + include_once(__DIR__ . '/../templates/empty.php');
327 + include_once(__DIR__ . '/../templates/details.php');
328 + include_once(__DIR__ . '/../templates/downloader.php');
329 + include_once(__DIR__ . '/../templates/dialog.php');
330 + include_once(__DIR__ . '/../templates/attribution.php');
331 + include_once(__DIR__ . '/../templates/no-search.php');
332 +
95 333 }
96 334
97 335 /**
98 336 * @param $strings
@@ -153,16 +391,44 @@
153 391
154 392
155 393 ),
156 394 ),
157 - 'error' => __( 'There has been an issue with your license key', 'stockpack' ),
158 - 'link' => __( 'Set license key', 'stockpack' ),
395 + 'error' => [
396 + 'default' => __( 'There has been an error', 'stockpack' ),
397 + 'token_expired' => __( 'The access you granted for this provider has expired', 'stockpack' ),
398 + 'invalid_token' => __( 'Double check the token on the settings page!', 'stockpack' ),
399 + 'premium_limit_reached' => __( 'Premium account requests limit reached', 'stockpack' ),
400 + 'free_limit_reached' => __( 'Free account requests limit reached', 'stockpack' ),
401 + 'anonymous_limit_reached' => __( 'Anonymous requests limit reached', 'stockpack' ),
402 + 'insufficient_credits' => __( 'Not enough credits', 'stockpack' ),
403 + ],
404 + 'link' => __( 'Set token', 'stockpack' ),
159 405 'search' => __( 'Search images', 'stockpack' ),
406 + 'generate' => [
407 + 'prompt' => __( 'Describe the image you want', 'stockpack' ),
408 + 'button' => __( 'Generate', 'stockpack' ),
409 + 'clear' => __( 'Clear', 'stockpack' ),
410 + 'working' => __( 'Generating...', 'stockpack' ),
411 + 'timeout' => __( 'The image is taking longer than expected. Check your Magnific account before retrying.', 'stockpack' ),
412 + 'models' => $this->ai_model_labels(),
413 + 'credits' => $this->ai_model_costs(),
414 + 'refine' => [
415 + 'label' => __( 'Refine the selected image', 'stockpack' ),
416 + 'hint' => __( 'Select a generated image first, then refine it with a new prompt.', 'stockpack' ),
417 + 'note' => __( 'Refining sends the selected image along with your prompt. Magnific charges more for a reference image, so expect roughly double.', 'stockpack' ),
418 + 'multiply' => $this->ai_refine_multiplier(),
419 + ],
420 + /* translators: %s: price per image, already formatted */
421 + 'cost' => __( '%s / image', 'stockpack' ),
422 + 'note' => $this->ai_cost_note(),
423 + 'wallet' => $this->ai_wallet_l10n(),
424 + ],
160 425 'close' => __( 'Close', 'stockpack' ),
161 426 'download' => __( 'Download', 'stockpack' ),
162 427 'licenseAction' => __( 'License', 'stockpack' ),
163 428 'alreadyLicensed' => __( 'Licensed', 'stockpack' ),
164 - 'license' => __( 'Your license key is not valid', 'stockpack' ),
429 + 'noFreeDownload' => __( 'This provider has no free tier. Use License to download, it will tell you the cost first.', 'stockpack' ),
430 + 'license' => __( 'Your token is not valid', 'stockpack' ),
165 431 'advanced' => __( 'Advanced search', 'stockpack' ),
166 432 'filters' => [
167 433 'gender' => [
168 434 'label' => __( 'Gender', 'stockpack' ),
@@ -168,8 +434,13 @@
168 434 'label' => __( 'Gender', 'stockpack' ),
169 435 'female' => __( 'Female', 'stockpack' ),
170 436 'male' => __( 'Male', 'stockpack' ),
171 437 ],
438 + 'provider' => [
439 + 'label' => __( 'Provider', 'stockpack' ),
440 + 'default' => __( 'Default', 'stockpack' ),
441 + 'values' => $this->getProviders()
442 + ],
172 443 'orientation' => [
173 444 'label' => __( 'Orientation', 'stockpack' ),
174 445 'horizontal' => __( 'Horizontal', 'stockpack' ),
175 446 'vertical' => __( 'Vertical', 'stockpack' ),
@@ -212,9 +483,8 @@
212 483 'Technology' => __( 'Technology', 'stockpack' ),
213 484 'Transportation' => __( 'Transportation', 'stockpack' ),
214 485 'Vectors' => __( 'Vectors', 'stockpack' ),
215 486 'Vintage' => __( 'Vintage', 'stockpack' ),
216 -
217 487 ]
218 488 ],
219 489 'safe' => [
220 490 'label' => __( 'Safe', 'stockpack' ),
@@ -231,15 +501,30 @@
231 501 'cancel' => __( 'Cancel', 'stockpack' ),
232 502 'adobe_stock' => [
233 503 'title' => __( 'Terms agreement', 'stockpack' ),
234 504 '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' ),
235 - 'link' => 'https://www.adobe.com/legal/terms.html'
505 + 'link' => 'https://stock.adobe.com/license-terms'
236 506 ],
507 + 'getty' => [
508 + 'title' => __( 'Terms agreement', 'stockpack' ),
509 + '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' ),
510 + 'link' => 'https://www.gettyimages.com/eula'
511 + ],
512 + 'istock' => [
513 + 'title' => __( 'Terms agreement', 'stockpack' ),
514 + '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' ),
515 + 'link' => 'https://www.istockphoto.com/legal/license-agreement'
516 + ],
237 517 'pixabay' => [
238 518 'title' => __( 'Terms agreement', 'stockpack' ),
239 519 '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' ),
240 520 'link' => 'https://pixabay.com/service/terms/'
241 521 ],
522 + 'pexels' => [
523 + 'title' => __( 'Terms agreement', 'stockpack' ),
524 + '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' ),
525 + 'link' => 'https://pexels.com/service/terms/'
526 + ],
242 527 'unsplash' => [
243 528 'title' => __( 'Terms agreement', 'stockpack' ),
244 529 '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' ),
245 530 'link' => 'https://unsplash.com/terms'
@@ -248,8 +533,18 @@
248 533 'title' => __( 'Terms agreement', 'stockpack' ),
249 534 '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' ),
250 535 'link' => 'https://depositphotos.com/terms-of-use.html'
251 536 ],
537 + 'freepik' => [
538 + 'title' => __( 'Terms agreement', 'stockpack' ),
539 + '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' ),
540 + 'link' => 'https://www.magnific.com/legal/terms-of-use'
541 + ],
542 + 'magnific' => [
543 + 'title' => __( 'Terms agreement', 'stockpack' ),
544 + 'message' => $this->ai_terms_message(),
545 + 'link' => 'https://www.magnific.com/legal/terms-of-use'
546 + ],
252 547 ],
253 548 'licensePopup' => [
254 549 'proceed' => __( 'Proceed', 'stockpack' ),
255 550 'checkInProgress' => __( 'Cost checking is in progress, please wait', 'stockpack' ),
@@ -260,12 +555,39 @@
260 555 'status' => __( 'Fetching cost...', 'stockpack' ),
261 556 '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' ),
262 557 'directLicenseUrl' => __( 'Adobe License Page', 'stockpack' ),
263 558 ],
559 + 'getty' => [
560 + 'title' => __( 'License and download', 'stockpack' ),
561 + 'message' => __( 'Licensing an image will provide you a non watermarked image from Getty Images.', 'stockpack' ),
562 + 'status' => __( 'Fetching cost...', 'stockpack' ),
563 + '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' ),
564 + 'directLicenseUrl' => __( 'Getty License Page', 'stockpack' ),
565 + ],
566 + 'istock' => [
567 + 'title' => __( 'License and download', 'stockpack' ),
568 + 'message' => __( 'Licensing an image will provide you a non watermarked image from iStock', 'stockpack' ),
569 + 'status' => __( 'Fetching cost...', 'stockpack' ),
570 + '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' ),
571 + 'directLicenseUrl' => __( 'iStock License Page', 'stockpack' ),
572 + ],
573 + 'deposit_photos' => [
574 + 'title' => __( 'License and download', 'stockpack' ),
575 + 'message' => __( 'Licensing an image will provide you a non watermarked image from Deposit Photos.', 'stockpack' ),
576 + 'status' => __( 'Fetching cost...', 'stockpack' ),
577 + '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' ),
578 + 'directLicenseUrl' => __( 'Deposit Photos License Page', 'stockpack' ),
579 + ],
580 + 'freepik' => [
581 + 'title' => __( 'License and download', 'stockpack' ),
582 + 'message' => __( 'Magnific does not offer watermarked previews, so downloading an image gives you the full file straight away.', 'stockpack' ),
583 + 'status' => __( 'Fetching cost...', 'stockpack' ),
584 + 'external' => __( 'You can also download this image directly from the Magnific website with the account you connected.', 'stockpack' ),
585 + 'directLicenseUrl' => __( 'Open on Magnific', 'stockpack' ),
586 + ],
264 587 ],
265 588 'attribution' => [
266 589 'adobe_stock' => [
267 - 'author_info' => __( 'Image info is available in the sidebar', 'stockpack' ),
268 590 'message' => __( 'You are searching images from', 'stockpack' ),
269 591 'link' => 'https://stockpack.co/recommended/adobe_stock',
270 592 'link_title' => 'Adobe Stock'
271 593 ],
@@ -274,35 +596,63 @@
274 596 'message' => __( 'Loading data...', 'stockpack' ),
275 597 'link' => '',
276 598 'link_title' => ''
277 599 ],
600 + 'getty' => [
601 + 'message' => __( 'You are searching images from', 'stockpack' ),
602 + 'link' => 'https://stockpack.co/recommended/getty',
603 + 'link_title' => 'Getty Images',
604 + 'warning' => __( 'Watermarked images from Getty Images are allowed for test only (not publicly available), for up to 30 days following download', 'stockpack' ),
605 + ],
606 + 'istock' => [
607 + 'message' => __( 'You are searching images from', 'stockpack' ),
608 + 'link' => 'https://stockpack.co/recommended/istock',
609 + 'link_title' => 'iStock',
610 + 'warning' => __( 'Watermarked images from iStock are allowed for test only (not publicly available), for up to 30 days following download', 'stockpack' ),
611 + ],
278 612 'pixabay' => [
279 - 'author_info' => __( 'Author info is available in the sidebar', 'stockpack' ),
280 613 'message' => __( 'You are searching images from', 'stockpack' ),
281 614 'link' => 'https://stockpack.co/recommended/pixabay',
282 615 'link_title' => 'Pixabay'
283 616 ],
617 + 'pexels' => [
618 + 'message' => __( 'You are searching images from', 'stockpack' ),
619 + 'link' => 'https://stockpack.co/recommended/pexels',
620 + 'link_title' => 'Pexels'
621 + ],
284 622 'unsplash' => [
285 - 'author_info' => __( 'Author info is available in the sidebar', 'stockpack' ),
286 623 'message' => __( 'You are searching images from', 'stockpack' ),
287 624 'link' => 'https://stockpack.co/recommended/unsplash',
288 625 'link_title' => 'Unsplash'
289 626 ],
290 627 'deposit_photos' => [
291 - 'author_info' => __( 'Author info is available in the sidebar', 'stockpack' ),
292 628 'message' => __( 'You are searching images from', 'stockpack' ),
293 629 'link' => 'https://stockpack.co/recommended/deposit_photos',
294 - 'link_title' => 'Deposit Photos'
630 + 'link_title' => 'Deposit Photos',
631 + 'warning' => __( 'Watermarked images from Deposit Photos are allowed for testing only', 'stockpack' ),
295 632 ],
633 + 'freepik' => [
634 + 'author_info' => __( 'Beta. Runs on the Magnific API key you connect', 'stockpack' ),
635 + 'message' => __( 'You are searching images from', 'stockpack' ),
636 + 'link' => 'https://www.magnific.com',
637 + 'link_title' => 'Freepik',
638 + ],
639 + 'magnific' => [
640 + 'author_info' => $this->ai_attribution(),
641 + /* translators: attribution required by Magnific, shown directly before a link reading "Magnific" */
642 + 'message' => __( 'Powered by', 'stockpack' ),
643 + 'link' => 'https://www.magnific.com',
644 + 'link_title' => 'Magnific',
645 + ],
296 646 ],
297 647 'limit' => [
298 648 'premium' => [
299 649 'title' => __( 'Requests limit reached', 'stockpack' ),
300 - 'message' => __( 'You have reached the limit for the requests. This gets reset, but if you reach this often and need a bigger solution you can contact StockPack support to talk about the options.', 'stockpack' )
650 + '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' )
301 651 ],
302 652 'anonymous' => [
303 653 'title' => __( 'You need an account to continue', 'stockpack' ),
304 - 'message' => __( 'You have reached the limit for the requests without an account. ', 'stockpack' ),
654 + 'message' => __( 'You have used all the requests available without an account.', 'stockpack' ),
305 655 'iframe' => [
306 656 'src' => $dashboard_url . '/register?skim=1',
307 657 'id' => 'stockpack-token-iframe',
308 658 ],
@@ -315,9 +665,9 @@
315 665 ]
316 666 ],
317 667 'free' => [
318 668 'title' => __( 'You need the premium upgrade to continue', 'stockpack' ),
319 - 'message' => __( 'You have reached the limit for the requests with the free account. ', 'stockpack' ),
669 + 'message' => __( 'You have reached the requests limit for the free account.', 'stockpack' ),
320 670 'iframe' => [
321 671 'src' => $dashboard_url . '/login?skim=1&upgrade=1',
322 672 'id' => 'stockpack-upgrade-iframe',
323 673 ],
@@ -330,10 +680,13 @@
330 680 'elsewhere' => __( 'To get back to login you can close this window and open it again, or use the back buttons inside the window', 'stockpack' )
331 681 ]
332 682 ],
333 683 'reset' => __( 'Reset time passed, you can try again', 'stockpack' ),
334 - 'contact' => "Contact",
335 - 'cancel' => "Cancel"
684 + 'contact' => __( 'Contact', 'stockpack' ),
685 + 'cancel' => __( 'Cancel', 'stockpack' )
686 + ],
687 + 'filename' => [
688 + 'placeholder' => __( 'Overwrite filename (No extension)' )
336 689 ]
337 690 );
338 691
339 692 return $strings;
@@ -340,26 +693,248 @@
340 693 }
341 694
342 695 public function settings( $strings, $post ) {
343 696 $strings['stockpack'] = array(
344 - 'terms' => [
697 + 'terms' => [
345 698 'adobe_stock' => get_option( 'terms_accepted_adobe_stock', false ),
699 + 'getty' => get_option( 'terms_accepted_getty', false ),
700 + 'istock' => get_option( 'terms_accepted_istock', false ),
346 701 'pixabay' => get_option( 'terms_accepted_pixabay', false ),
702 + 'pexels' => get_option( 'terms_accepted_pexels', false ),
347 703 'unsplash' => get_option( 'terms_accepted_unsplash', false ),
348 704 'deposit_photos' => get_option( 'terms_accepted_deposit_photos', false ),
705 + 'freepik' => get_option( 'terms_accepted_freepik', false ),
706 + 'magnific' => get_option( 'terms_accepted_magnific', false ),
349 707 ],
350 - 'nonce_terms' => wp_create_nonce( 'stockpack_terms' ),
351 - 'nonce_license_cost' => wp_create_nonce( 'stockpack_license_cost' ),
352 - 'nonce_query' => wp_create_nonce( 'stockpack_query' ),
353 - 'nonce_download' => wp_create_nonce( 'stockpack_download' ),
354 - 'nonce_cache' => wp_create_nonce( 'stockpack_cache' ),
355 - 'nonce_token' => wp_create_nonce( 'stockpack_token' ),
356 - 'nonce_validate' => wp_create_nonce( 'stockpack_validate' ),
357 - 'settings_url' => admin_url( 'options-general.php?page=stockpack' ),
358 - 'contact_url' => 'https://stockpack.co/contact',
708 + 'cache_key' => substr( md5( get_current_blog_id() . '|' . get_current_user_id() ), 0, 12 ),
709 + 'nonce_terms' => wp_create_nonce( 'stockpack_terms' ),
710 + 'nonce_license_cost' => wp_create_nonce( 'stockpack_license_cost' ),
711 + 'nonce_query' => wp_create_nonce( 'stockpack_query' ),
712 + 'nonce_download' => wp_create_nonce( 'stockpack_download' ),
713 + 'nonce_cache' => wp_create_nonce( 'stockpack_cache' ),
714 + 'nonce_generate' => wp_create_nonce( 'stockpack_generate' ),
715 + 'nonce_token' => wp_create_nonce( 'stockpack_token' ),
716 + 'nonce_validate' => wp_create_nonce( 'stockpack_validate' ),
717 + 'settings_url' => admin_url( 'options-general.php?page=stockpack' ),
718 + 'contact_url' => 'https://stockpack.co/contact',
719 + 'filename_change' => $this->settings->get_file_name_change_setting(),
720 + 'premium_provider_caption' => $this->settings->get_premium_providers_caption_setting()
359 721 );
360 722
361 723 return $strings;
724 + }
725 +
726 +
727 +
728 + public function enque_dialog_js() {
729 + wp_enqueue_script( 'jquery-ui-dialog', "/wp-includes/js/jquery/ui/dialog.min.js", array(
730 + 'media-editor',
731 + ), false, 1 );
732 + }
733 +
734 +
735 +
736 + private function sellable_ai_models( $models ) {
737 + if ( 'managed' !== $this->ai_mode() ) {
738 + return $models;
739 + }
740 +
741 + $sellable = array_filter( $models, function ( $model ) {
742 + return isset( $model['wallet_credits'] );
743 + } );
744 +
745 + return $sellable ?: $models;
746 + }
747 +
748 + private function ai_models() {
749 + $prices = StockPack::get_instance()->query->get_ai_prices();
750 +
751 + if ( isset( $prices['models'] ) && is_array( $prices['models'] ) && $prices['models'] ) {
752 + return $this->sellable_ai_models( $prices['models'] );
753 + }
754 +
755 + return array(
756 + 'flux-1' => array( 'label' => 'Flux.1', 'eur' => 0.01, 'default' => true ),
757 + 'mystic-25' => array( 'label' => 'Mystic 2.5', 'eur' => 0.10, 'default' => true ),
758 + );
759 + }
760 +
761 + private function enabled_ai_models() {
762 + $models = $this->ai_models();
763 + $selected = $this->settings->get_selected_ai_models();
764 +
765 + if ( $selected === null ) {
766 + return array_filter( $models, function ( $model ) {
767 + return ! empty( $model['default'] );
768 + } );
769 + }
770 +
771 + $enabled = array_intersect_key( $models, array_flip( $selected ) );
772 +
773 + return $enabled ?: $models;
774 + }
775 +
776 + private function ai_model_labels() {
777 + return array_map( function ( $model ) {
778 + return isset( $model['label'] ) ? $model['label'] : '';
779 + }, $this->enabled_ai_models() );
780 + }
781 +
782 + private function ai_model_costs() {
783 + $managed = 'managed' === $this->ai_mode();
784 +
785 + return array_map( function ( $model ) use ( $managed ) {
786 + if ( $managed ) {
787 + return isset( $model['wallet_credits'] ) ? $this->format_credits( $model['wallet_credits'] ) : '';
788 + }
789 +
790 + if ( ! isset( $model['eur'] ) ) {
791 + return '';
792 + }
793 +
794 + return '€' . rtrim( rtrim( number_format( (float) $model['eur'], 3 ), '0' ), '.' );
795 + }, $this->enabled_ai_models() );
796 + }
797 +
798 + private function ai_wallet() {
799 + return StockPack::get_instance()->query->get_ai_wallet();
800 + }
801 +
802 + private function ai_mode() {
803 + $wallet = $this->ai_wallet();
804 +
805 + return $wallet['mode'];
806 + }
807 +
808 + private function ai_wallet_l10n() {
809 + return $this->ai_wallet() + array(
810 + /* translators: %s: credit balance, already formatted */
811 + 'balance_label' => __( 'Balance: %s credits', 'stockpack' ),
812 + 'top_up' => __( 'Top up', 'stockpack' ),
813 + 'connect' => __( 'Connect Magnific', 'stockpack' ),
814 + 'unavailable' => __( 'Image generation is not set up for this site yet. Connect your own Magnific key on stockpack.co, or buy StockPack credits.', 'stockpack' ),
815 + );
816 + }
817 +
818 + private function ai_cost_note() {
819 + if ( 'managed' === $this->ai_mode() ) {
820 + return __( 'Each image is paid from your StockPack credits at the price shown, and refining costs double. Nothing is charged to a Magnific account.', 'stockpack' );
821 + }
822 +
823 + return __( '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' );
824 + }
825 +
826 + private function ai_terms_message() {
827 + if ( 'managed' === $this->ai_mode() ) {
828 + return __( '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 the StockPack Magnific account and paid from your StockPack credits, and Magnific terms still govern the images you receive. ', 'stockpack' );
829 + }
830 +
831 + return __( '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' );
832 + }
833 +
834 + private function ai_attribution() {
835 + if ( 'managed' === $this->ai_mode() ) {
836 + return __( 'Runs on your StockPack credits. Earlier images are shown while Magnific still hosts them; download the ones you want to keep.', 'stockpack' );
837 + }
838 +
839 + return __( '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' );
840 + }
841 +
842 + private function format_credits( $credits ) {
843 + $credits = (int) $credits;
844 +
845 + return sprintf(
846 + /* translators: %s: number of credits, already formatted */
847 + _n( '%s credit', '%s credits', $credits, 'stockpack' ),
848 + number_format_i18n( $credits )
849 + );
850 + }
851 +
852 + private function upscale_quotes() {
853 + $wallet = $this->ai_wallet();
854 + $prices = StockPack::get_instance()->query->get_ai_prices();
855 + $quotes = array();
856 +
857 + foreach ( array( 2, 4 ) as $factor ) {
858 + $quotes[ $factor ] = $this->upscale_quote( $factor, $wallet, $prices );
859 + }
860 +
861 + return $quotes;
862 + }
863 +
864 + private function upscale_quote( $factor, $wallet, $prices ) {
865 + if ( 'unavailable' === $wallet['mode'] ) {
866 + $strings = $this->ai_wallet_l10n();
867 +
868 + return array( 'refuse' => $strings['unavailable'] );
869 + }
870 +
871 + if ( 'managed' !== $wallet['mode'] ) {
872 + return array();
873 + }
874 +
875 + if ( ! isset( $prices['upscale']['wallet_credits'][ $factor ] ) ) {
876 + return array(
877 + /* translators: %d: upscale factor, 2 or 4 */
878 + 'refuse' => sprintf( __( 'Upscale %dx is not available on StockPack credits yet. Connect your own Magnific key to upscale.', 'stockpack' ), $factor ),
879 + 'link' => false,
880 + );
881 + }
882 +
883 + $credits = (int) $prices['upscale']['wallet_credits'][ $factor ];
884 + $balance = (int) $wallet['balance'];
885 +
886 + if ( $balance < $credits ) {
887 + return array(
888 + 'refuse' => sprintf(
889 + /* translators: 1: upscale factor, 2: credits needed, 3: current balance, both already formatted */
890 + __( 'Upscale %1$dx needs %2$s credits and your balance is %3$s. Top up on stockpack.co first.', 'stockpack' ),
891 + $factor,
892 + number_format_i18n( $credits ),
893 + number_format_i18n( $balance )
894 + ),
895 + );
896 + }
897 +
898 + return array(
899 + 'confirm' => sprintf(
900 + /* translators: 1: upscale factor, 2: credits, already formatted, 3: balance after the upscale, already formatted */
901 + __( 'Upscale %1$dx for %2$s credits? Balance after: %3$s.', 'stockpack' ),
902 + $factor,
903 + number_format_i18n( $credits ),
904 + number_format_i18n( $balance - $credits )
905 + ),
906 + );
907 + }
908 +
909 + private function ai_refine_multiplier() {
910 + $prices = StockPack::get_instance()->query->get_ai_prices();
911 +
912 + return isset( $prices['refine_multiplier'] ) ? (int) $prices['refine_multiplier'] : 2;
913 + }
914 +
915 + private function getProviders()
916 + {
917 + $selected_providers = $this->settings->get_selected_providers_setting();
918 + $providers = array(
919 + 'Adobe Stock' => __('Adobe Stock', 'stockpack'),
920 + 'Deposit Photos' => __('Deposit Photos', 'stockpack'),
921 + 'Freepik' => __('Freepik (Magnific, beta)', 'stockpack'),
922 + 'Magnific AI' => __('Magnific AI (generate, beta)', 'stockpack'),
923 + 'Getty' => __('Getty Images', 'stockpack'),
924 + 'iStock' => __('iStock', 'stockpack'),
925 + 'Pixabay' => __('Pixabay', 'stockpack'),
926 + 'Pexels' => __('Pexels', 'stockpack'),
927 + 'Unsplash' => __('Unsplash', 'stockpack'),
928 + );
929 + foreach ($providers as $key => $value) {
930 + if (!in_array($key, $selected_providers)) {
931 + unset($providers[$key]);
932 + }
933 + }
934 +
935 +
936 + return apply_filters('stockpack_providers', $providers);
362 937 }
363 938
364 939
365 940 }