PluginProbe
Pixel Gallery Addons for Elementor – Easy Grid, Creative Gallery, Drag and Drop Grid, Custom Grid Layout, Portfolio Gallery / trunk
Pixel Gallery Addons for Elementor – Easy Grid, Creative Gallery, Drag and Drop Grid, Custom Grid Layout, Portfolio Gallery vtrunk
2.1.14 2.1.13 2.1.12 2.1.11 2.1.10 2.1.9 2.1.8 2.1.7 trunk 1.2.2 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.4.0 1.4.1 1.4.10 1.4.11 1.4.2 1.4.3 1.4.5 1.4.6 All 74 releases
pixel-gallery / includes / helper.php

helper.php in Pixel Gallery Addons for Elementor – Easy Grid, Creative Gallery, Drag and Drop Grid, Custom Grid Layout, Portfolio Gallery trunk, at includes/helper.php

361 lines 11.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly.
4 }
5 //TODO: namespace need. Note: We don't use namespace because use them easily
6 use Elementor\Plugin;
7
8 /**
9 * You can easily add white label branding for for extended license or multi site license.
10 * Don't try for regular license otherwise your license will be invalid.
11 * return white label
12 */
13 define('BDTPG_PNAME', basename(dirname(BDTPG__FILE__)));
14 define('BDTPG_PBNAME', plugin_basename(BDTPG__FILE__));
15 define('BDTPG_PATH', plugin_dir_path(BDTPG__FILE__));
16 define('BDTPG_URL', plugins_url('/', BDTPG__FILE__));
17 define('BDTPG_ADMIN_PATH', BDTPG_PATH . 'admin/');
18 define('BDTPG_ADMIN_URL', BDTPG_URL . 'admin/');
19 define('BDTPG_MODULES_PATH', BDTPG_PATH . 'modules/');
20 define('BDTPG_INC_PATH', BDTPG_PATH . 'includes/');
21 define('BDTPG_ASSETS_URL', BDTPG_URL . 'assets/');
22 define('BDTPG_ASSETS_PATH', BDTPG_PATH . 'assets/');
23 define('BDTPG_MODULES_URL', BDTPG_URL . 'modules/');
24
25 if (!defined('BDTPG')) {
26 define('BDTPG', '');
27 } //Add prefix for all widgets <span class="bdt-widget-badge"></span>
28 if (!defined('BDTPG_CP')) {
29 define('BDTPG_CP', '<span class="pg-widget-badge"></span>');
30 } //Add prefix for all widgets <span class="bdt-widget-badge"></span>
31 if (!defined('BDTPG_NC')) {
32 define('BDTPG_NC', '<span class="pg-new-control"></span>');
33 } // if you have any custom style
34 if (!defined('BDTPG_SLUG')) {
35 define('BDTPG_SLUG', 'pixel-gallery');
36 } // set your own alias
37
38 if (_is_pg_pro_activated()) {
39 if (!defined('BDTPG_PC')) {
40 define('BDTPG_PC', '');
41 } // pro control badge
42 define('BDTPG_IS_PC', '');
43 } else {
44 if (!defined('BDTPG_PC')) {
45 define('BDTPG_PC', '<span class="pg-pro-control"></span>');
46 } // pro control badge
47 define('BDTPG_IS_PC', 'pg-disabled-control');
48 }
49
50 function pixel_gallery_is_edit() {
51 return Plugin::$instance->editor->is_edit_mode();
52 }
53
54 function pixel_gallery_is_preview() {
55 return Plugin::$instance->preview->is_preview_mode();
56 }
57
58
59 /**
60 * default get_option() default value check
61 *
62 * @param string $option settings field name
63 * @param string $section the section name this field belongs to
64 * @param string $default default text if it's not found
65 *
66 * @return mixed
67 */
68 function pixel_gallery_option($option, $section, $default = '') {
69
70 $options = get_option($section);
71
72 if (isset($options[$option])) {
73 return $options[$option];
74 }
75
76 return $default;
77 }
78
79
80 // BDT Blend Type
81 function pixel_gallery_blend_options() {
82 $blend_options = [
83 'multiply' => esc_html__('Multiply', 'pixel-gallery'),
84 'screen' => esc_html__('Screen', 'pixel-gallery'),
85 'overlay' => esc_html__('Overlay', 'pixel-gallery'),
86 'darken' => esc_html__('Darken', 'pixel-gallery'),
87 'lighten' => esc_html__('Lighten', 'pixel-gallery'),
88 'color-dodge' => esc_html__('Color-Dodge', 'pixel-gallery'),
89 'color-burn' => esc_html__('Color-Burn', 'pixel-gallery'),
90 'hard-light' => esc_html__('Hard-Light', 'pixel-gallery'),
91 'soft-light' => esc_html__('Soft-Light', 'pixel-gallery'),
92 'difference' => esc_html__('Difference', 'pixel-gallery'),
93 'exclusion' => esc_html__('Exclusion', 'pixel-gallery'),
94 'hue' => esc_html__('Hue', 'pixel-gallery'),
95 'saturation' => esc_html__('Saturation', 'pixel-gallery'),
96 'color' => esc_html__('Color', 'pixel-gallery'),
97 'luminosity' => esc_html__('Luminosity', 'pixel-gallery'),
98 ];
99
100 return $blend_options;
101 }
102
103
104 // Title Tags
105 function pixel_gallery_title_tags() {
106 $title_tags = [
107 'h1' => 'H1',
108 'h2' => 'H2',
109 'h3' => 'H3',
110 'h4' => 'H4',
111 'h5' => 'H5',
112 'h6' => 'H6',
113 'div' => 'div',
114 'span' => 'span',
115 'p' => 'p',
116 ];
117
118 return $title_tags;
119 }
120
121
122 /**
123 * [pixel_gallery_dashboard_link description]
124 * @param string $suffix [description]
125 * @return [type] [description]
126 */
127 function pixel_gallery_dashboard_link($suffix = '#welcome') {
128 return add_query_arg(['page' => 'pixel_gallery_options' . $suffix], admin_url('admin.php'));
129 }
130
131
132 /**
133 * @param $post_type string any post type that you want to show category
134 * @param $separator string separator for multiple category
135 *
136 * @return string
137 */
138 function pixel_gallery_get_category_list($post_type, $separator = ' ') {
139 switch ($post_type) {
140 case 'campaign':
141 $taxonomy = 'campaign_category';
142 break;
143 case 'lightbox_library':
144 $taxonomy = 'ngg_tag';
145 break;
146 case 'give_forms':
147 $taxonomy = 'give_forms_category';
148 break;
149 case 'tribe_events':
150 $taxonomy = 'tribe_events_cat';
151 break;
152 case 'product':
153 $taxonomy = 'product_cat';
154 break;
155 case 'portfolio':
156 $taxonomy = 'portfolio_filter';
157 break;
158 case 'faq':
159 $taxonomy = 'faq_filter';
160 break;
161 case 'bdthemes-testimonial':
162 $taxonomy = 'testimonial_categories';
163 break;
164 case 'knowledge_base':
165 $taxonomy = 'knowledge-type';
166 break;
167 default:
168 $taxonomy = 'category';
169 break;
170 }
171
172 $categories = get_the_terms(get_the_ID(), $taxonomy);
173 $_categories = [];
174 if ($categories && !is_wp_error($categories)) {
175 foreach ($categories as $category) {
176 // Ensure $category is an object, not an array
177 if (is_object($category) && isset($category->term_id, $category->name, $category->slug)) {
178 $link = '<a href="' . esc_url(get_category_link($category->term_id)) . '">' . esc_html($category->name) . '</a>';
179 $_categories[$category->slug] = $link;
180 }
181 }
182 }
183 return implode(esc_attr($separator), $_categories);
184 }
185
186
187 /**
188 * License Validation
189 */
190 if (!function_exists('pixel_gallery_license_validation')) {
191 function pixel_gallery_license_validation() {
192
193 if (function_exists('pixel_gallery_is_pro_activated') && false === pixel_gallery_is_pro_activated()) {
194 return false;
195 }
196
197 $license_key = trim(get_option('pixel_gallery_license_key'));
198
199 if (isset($license_key) && !empty($license_key)) {
200 return true;
201 } else {
202 return false;
203 }
204 return false;
205 }
206 }
207
208 if (!function_exists('pg_license_validation')) {
209 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Deprecated alias for pixel_gallery_license_validation(); kept for Pixel Gallery Pro back-compat.
210 function pg_license_validation() {
211 return pixel_gallery_license_validation();
212 }
213 }
214
215
216 /**
217 * Mask Shapes
218 */
219
220 function pixel_gallery_mask_shapes() {
221 $shape_name = 'shape';
222 $list = [];
223
224 for ( $i = 1; $i <= 31; $i++ ) {
225 $list[ $shape_name . '-' . $i ] = ucwords( $shape_name . ' ' . $i );
226 }
227
228 return $list;
229 }
230
231 /**
232 * Get Pixel Gallery mask shapes options for VISUAL_CHOICE control
233 *
234 * @return array Options array for VISUAL_CHOICE control
235 */
236 function pixel_gallery_mask_shapes_options() {
237 $options = [];
238 $shape_list = pixel_gallery_mask_shapes();
239
240 foreach ( $shape_list as $shape_key => $shape_name ) {
241 // Skip the first item if it's a placeholder
242 if ( $shape_key === 0 ) {
243 continue;
244 }
245
246 $options[ $shape_key ] = [
247 'title' => $shape_name,
248 'image' => BDTPG_ASSETS_URL . 'images/mask/' . $shape_key . '.svg',
249 ];
250 }
251
252 return $options;
253 }
254
255 function pixel_gallery_post_pagination( $wp_query, $widget_id = '' ) {
256
257 /** Stop execution if there's only 1 page */
258 if ( $wp_query->max_num_pages <= 1 ) {
259 return;
260 }
261
262 // Get current page from multiple sources for reliability
263 $paged_from_query = isset( $wp_query->query_vars['paged'] ) ? $wp_query->query_vars['paged'] : 0;
264 $page_from_query = isset( $wp_query->query_vars['page'] ) ? $wp_query->query_vars['page'] : 0;
265
266 if ( is_front_page() ) {
267 // On front page, WordPress can use either 'page' or 'paged' depending on permalink structure
268 $paged = max( get_query_var( 'page' ), get_query_var( 'paged' ), $paged_from_query, $page_from_query );
269 $paged = $paged ? $paged : 1;
270 $page_var = 'page';
271 } else {
272 $paged = max( get_query_var( 'paged' ), $paged_from_query );
273 $paged = $paged ? $paged : 1;
274 $page_var = 'paged';
275 }
276
277 $max = intval( $wp_query->max_num_pages );
278
279 /** Add current page to the array */
280 if ( $paged >= 1 ) {
281 $links[] = $paged;
282 }
283
284 /** Add the pages around the current page to the array */
285 if ( $paged >= 3 ) {
286 $links[] = $paged - 1;
287 $links[] = $paged - 2;
288 }
289
290 if ( ( $paged + 2 ) <= $max ) {
291 $links[] = $paged + 2;
292 $links[] = $paged + 1;
293 }
294
295 printf( '<ul class="pg-pagination" data-widget-id="%s">' . "\n", esc_attr($widget_id) );
296
297 /** Previous Post Link */
298 if ( $paged > 1 ) {
299 $prev_page = $paged - 1;
300 if ( is_front_page() && $prev_page == 1 ) {
301 $prev_link = home_url( '/' );
302 } else {
303 $prev_link = get_pagenum_link( $prev_page );
304 }
305 printf( '<li class="pg-pagination-previous"><a href="%s" aria-label="' . esc_attr__( 'Previous Page', 'pixel-gallery' ) . '"><span data-pg-pagination-previous><i class="eicon-angle-left" aria-hidden="true"></i></span></a></li>' . "\n", esc_url( $prev_link ) );
306 }
307
308 /** Link to first page, plus ellipses if necessary */
309 if ( ! in_array( 1, $links ) ) {
310 $class = 1 == $paged ? ' class="current"' : '';
311
312 // For page 1, always use home URL on front page, otherwise use get_pagenum_link
313 if ( is_front_page() ) {
314 $page_link = home_url( '/' );
315 } else {
316 $page_link = get_pagenum_link( 1 );
317 }
318
319 printf( '<li%s><a href="%s">%s</a></li>' . "\n", wp_kses_post($class), esc_url( $page_link ), '1' );
320
321 if ( ! in_array( 2, $links ) ) {
322 echo '<li class="pg-pagination-dot-dot"><span>...</span></li>';
323 }
324 }
325
326 /** Link to current page, plus 2 pages in either direction if necessary */
327 sort( $links );
328 foreach ( (array) $links as $link ) {
329 $class = $paged == $link ? ' class="pg-active"' : '';
330
331 // Use appropriate page link for front page vs other pages
332 if ( is_front_page() && $link == 1 ) {
333 $page_link = home_url( '/' );
334 } else {
335 $page_link = get_pagenum_link( $link );
336 }
337
338 printf( '<li%s><a href="%s">%s</a></li>' . "\n", wp_kses_post($class), esc_url( $page_link ), wp_kses_post($link) );
339 }
340
341 /** Link to last page, plus ellipses if necessary */
342 if ( ! in_array( $max, $links ) ) {
343 if ( ! in_array( $max - 1, $links ) ) {
344 echo '<li class="pg-pagination-dot-dot"><span>...</span></li>' . "\n";
345 }
346
347 $class = $paged == $max ? ' class="pg-active"' : '';
348 $page_link = get_pagenum_link( $max );
349
350 printf( '<li%s><a href="%s">%s</a></li>' . "\n", wp_kses_post($class), esc_url( $page_link ), wp_kses_post($max) );
351 }
352
353 /** Next Post Link */
354 if ( $paged < $max ) {
355 $next_page = $paged + 1;
356 $next_link = get_pagenum_link( $next_page );
357 printf( '<li class="pg-pagination-next"><a href="%s" aria-label="' . esc_attr__( 'Next Page', 'pixel-gallery' ) . '"><span data-pg-pagination-next><i class="eicon-angle-right" aria-hidden="true"></i></span></a></li>' . "\n", esc_url( $next_link ) );
358 }
359
360 echo '</ul>' . "\n";
361 }