PluginProbe
Templateberg – Gutenberg Templates, WordPress Themes Template Kits & WordPress Templates / 1.1.0
Templateberg – Gutenberg Templates, WordPress Themes Template Kits & WordPress Templates v1.1.0
1.2.0 2.0.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9
templateberg / includes / functions.php

functions.php in Templateberg – Gutenberg Templates, WordPress Themes Template Kits & WordPress Templates 1.1.0, at includes/functions.php

747 lines 27.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (! function_exists('templateberg_is_edit_page')) {
3 function templateberg_is_edit_page()
4 {
5 //make sure we are on the backend
6 if (! is_admin()) {
7 return false;
8 }
9 global $pagenow;
10 return in_array($pagenow, array( 'post.php', 'post-new.php' ));
11 }
12 }
13
14 if (! function_exists('templateberg_get_payment_info_html')) {
15 function templateberg_get_payment_info_html()
16 {
17 $payment_info = templateberg_connect()->get_purchase();
18 if (is_array($payment_info) && !empty($payment_info)) {
19 ?>
20 <div class="tb-purchase__wrap">
21 <div class="tb-purchase__id">
22 <span class="tb-purchase__title"><?php echo esc_html__('ID', 'templateberg'); ?></span>
23 </div>
24 <div class="tb-purchase__type">
25 <span class="tb-purchase__title"><?php echo esc_html__('Type', 'templateberg'); ?></span>
26 </div>
27 <div class="tb-purchase__type">
28 <span class="tb-purchase__title"><?php echo esc_html__('Name', 'templateberg'); ?></span>
29 </div>
30 <div class="tb-purchase__date">
31 <span class="tb-purchase__title"><?php echo esc_html__('Date', 'templateberg'); ?></span>
32 </div>
33 <div class="tb-purchase__amount">
34 <span class="tb-purchase__title"><?php echo esc_html__('Amount', 'templateberg'); ?></span>
35 </div>
36 <div class="tb-purchase__limit">
37 <span class="tb-purchase__title"><?php echo esc_html__('Limit', 'templateberg'); ?></span>
38 </div>
39 <div class="tb-purchase__plan">
40 <span class="tb-purchase__title"><?php echo esc_html__('Plan', 'templateberg'); ?></span>
41 </div>
42 <div class="tb-purchase__link">
43 <span class="tb-purchase__title"><?php echo esc_html__('Details', 'templateberg'); ?></span>
44 </div>
45 </div>
46 <?php
47 foreach ($payment_info as $pi) {
48 ?>
49 <div class="tb-purchase__wrap">
50 <div class="tb-purchase__id">
51 <span class="tb-purchase__desc">
52 <?php echo isset($pi['id'])?esc_html($pi['id']):'';?>
53 </span>
54 </div>
55 <div class="tb-purchase__type">
56 <span class="tb-purchase__desc">
57 <?php echo isset($pi['type'])?esc_html($pi['type']):'';?>
58 </span>
59 </div>
60 <div class="tb-purchase__type">
61 <span class="tb-purchase__desc">
62 <?php echo isset($pi['title'])?wp_kses_post($pi['title']):'';?>
63 </span>
64 </div>
65 <div class="tb-purchase__date">
66 <span class="tb-purchase__desc">
67 <?php echo isset($pi['date'])?esc_html($pi['date']):'';?>
68 </span>
69 </div>
70 <div class="tb-purchase__amount">
71 <span class="tb-purchase__desc">
72 <?php echo isset($pi['amount'])?esc_html($pi['amount']):'';?>
73 </span>
74 </div>
75 <div class="tb-purchase__limit">
76 <span class="tb-purchase__desc">
77 <?php echo isset($pi['limit'])?esc_html($pi['limit']):'';?>
78 </span>
79 </div>
80 <div class="tb-purchase__plan">
81 <span class="tb-purchase__desc">
82 <?php echo isset($pi['plan'])?esc_html($pi['plan']):'';?>
83 </span>
84 </div>
85
86 <div class="tb-purchase__plan">
87 <span class="tb-purchase__desc">
88 <?php echo wp_kses_post($pi['details'])?>
89 </span>
90 </div>
91 </div>
92 <?php
93 }
94 } else {
95 ?>
96 <div class="tb-info__box">
97 <?php echo esc_html__('No payment information found', 'templateberg'); ?>
98 </div>
99 <?php
100 }
101 }
102 }
103
104 if (! function_exists('templateberg_get_free_templates_html')) {
105 function templateberg_get_free_templates_html()
106 {
107 $free_templates = templateberg_connect()->get_free_templates();
108 if (is_array($free_templates) && !empty($free_templates)) {
109 echo '<div class="tb-row">';
110 foreach ($free_templates as $ft) {
111 ?>
112 <div class="tb-col-3">
113 <img src="<?php echo esc_url($ft['screenshot_url'])?>" alt="<?php echo esc_attr($ft['title'])?>"/>
114 </div>
115 <?php
116 }
117 echo '</div>';
118 } else {
119 ?>
120 <div class="tb-info__box">
121 <?php echo esc_html__('No template information found', 'templateberg'); ?>
122 </div>
123 <?php
124 }
125 }
126 }
127
128 /**
129 * check if Gutentor activated
130 */
131 if (! function_exists('templateburg_is_gutentor_active')) {
132
133 function templateburg_is_gutentor_active()
134 {
135 return class_exists('Gutentor') ? true : false;
136 }
137 }
138
139
140 /**
141 * check if Gutentor activated
142 */
143 if (! function_exists('templateburg_is_advanced_import_active')) {
144
145 function templateburg_is_advanced_import_active()
146 {
147 return class_exists('Advanced_Import') ? true : false;
148 }
149 }
150
151
152 /**
153 * Get Transients by prefix
154 *
155 * @param $prefix string Prefix of Transients
156 * without _transient_
157 *
158 * @return array|boolean Array of Transients or false if no Transients
159 */
160 if (!function_exists('templateberg_get_transients_by_prefix')) {
161 function templateberg_get_transients_by_prefix($prefix)
162 {
163
164 global $wpdb;
165
166 /*Add Prefix*/
167 $prefix = $wpdb->esc_like('_transient_' . $prefix);
168
169 /*SQL*/
170 $sql = "SELECT `option_name` FROM $wpdb->options WHERE `option_name` LIKE '%s'";
171
172 /*Get transients*/
173 $transients = $wpdb->get_results(
174 $wpdb->prepare(
175 $sql,
176 $prefix . '%'
177 ),
178 ARRAY_A
179 );
180
181 /*Return*/
182 if ($transients && ! is_wp_error($transients)) {
183 return $transients;
184 }
185
186 /*No transients, return false*/
187 return false;
188 }
189 }
190
191 /**
192 * Delete Transients by prefix
193 *
194 * @param $prefix string Prefix of Transients
195 * without _transient_
196 *
197 * @return array|boolean Array of found Transients and deleted Transients options name
198 * or false if no Transients
199 */
200 if (!function_exists('templateberg_delete_transients_by_prefix')) {
201
202 function templateberg_delete_transients_by_prefix($prefix)
203 {
204
205 $transients = templateberg_get_transients_by_prefix($prefix);
206 if (! $transients) {
207 return false;
208 }
209
210 $deleted = array();
211
212 /*Loop through found transients*/
213 foreach ($transients as $transient) {
214 $deleted[] = $transient['option_name'];
215 delete_transient(str_replace('_transient_', '', $transient['option_name']));
216 }
217
218 /*Return an array of total transients
219 and deleted transients option_name*/
220 return array(
221 'found' => count($transients),
222 'deleted' => $deleted,
223 );
224 }
225 }
226
227 /**
228 * Function create pagination
229 *
230 * @param [array] $attr
231 * @return String
232 */
233 if (!function_exists('templateberg_pagination')) {
234 function templateberg_pagination($paged = false, $max_num_pages = false)
235 {
236 $da_link = get_post_type_archive_link('download');
237 $nextDisabled = ($paged+1) > $max_num_pages?'tb-list__page-disabled':'';
238 $prevDisabled = ($paged-1) < 1 ?'tb-list__page-disabled':'';
239 $prevPage = ($paged-1) < 1?1:$paged-1;
240 $nextPage = ($paged+1) > $max_num_pages?$max_num_pages:$paged+1;
241
242 $phtml = '';
243 $phtml .= '<div class="tb-list__navigation"><nav aria-label="Page navigation"><ul class="tb-list__pagination">';
244 $phtml .= '<li class="tb-list__page-item '.$prevDisabled.'"><a class="tb-list__page-link" href="'.esc_url($da_link).'page/'.$prevPage.'" data-gpage="'.esc_html($prevPage).'">'.esc_html__('Previous', 'templateberg').'</a></li>';
245
246 if (! $paged) {
247 $paged = get_query_var('paged') ? get_query_var('paged') : 1;
248 }
249 if (! $max_num_pages) {
250 global $wp_query;
251 $max_num_pages = $wp_query->max_num_pages;
252 if (! $max_num_pages) {
253 $max_num_pages = 1;
254 }
255 }
256 $mid_pages = $paged >= 3 ? array( $paged - 1, $paged, $paged + 1 ) : array( 1, 2, 3 );
257 if ($max_num_pages > 1) {
258 if (! in_array(1, $mid_pages)) {
259 $is_active = $paged == 1 ? ' tb-list__page-active' : '';
260 $phtml .= '<li class="tb-list__page-item ' . $is_active . '">
261 <a class="tb-list__page-link" href="'.esc_url($da_link).'page/1" data-gpage="1">' . __('1', 'templateberg') . '</a>
262 </li>';
263 }
264 if ($paged > 3) {
265 $phtml .= '<li class="tb-list__page-item tb-list__pagination-dots"><a class="tb-list__page-link" href="#">...</a></li>';
266 }
267 foreach ($mid_pages as $i) {
268 if ($max_num_pages >= $i) {
269 $is_active = $paged == $i ? ' tb-list__page-active' : '';
270 $phtml .= '<li class="tb-list__page-item' . $is_active . '">
271 <a class="tb-list__page-link" href="'.esc_url($da_link).'page/'.$i.'" data-gpage="' . $i . '">' . __($i, 'templateberg') . '</a>
272 </li>';
273 }
274 }
275 if ($max_num_pages > $paged + 1) {
276 if ($max_num_pages > 3) {
277 $phtml .= '<li class="tb-list__page-item tb-list__pagination-dots"><a class="tb-list__page-link" href="#">...</a></li>';
278 }
279 if ($max_num_pages > 3) {
280 $is_active = $paged == $max_num_pages ? ' tb-list__page-active' : '';
281 $phtml .= '<li class="tb-list__page-item ' . $is_active . '">
282 <a class="tb-list__page-link" href="'.esc_url($da_link).'page/'.$max_num_pages.'" data-gpage="' . $max_num_pages . '">' . __($max_num_pages, 'templateberg') . '</a>
283 </li>';
284 }
285 }
286 }
287 $phtml .= ' <li class="tb-list__page-item '.$nextDisabled.'"><a class="tb-list__page-link" href="'.esc_url($da_link).'page/'.$nextPage.'" data-gpage="'.esc_html($nextPage).'">'.esc_html__('Next', 'templateberg').'</a></li>';
288 $phtml .= '</ul></nav></div>';
289 return $phtml;
290 }
291
292 }
293
294 /**
295 * Function to get Current Theme Info
296 *
297 * @param [array] $attr
298 * @return array
299 */
300 if (!function_exists('templateberg_get_current_theme_info')) {
301 function templateberg_get_current_theme_info()
302 {
303 return array(
304 'template'=>get_template(),
305 'stylesheet'=>get_stylesheet(),
306 'author'=>wp_get_theme()->get('Author'),
307 );
308 }
309
310 }
311
312 /**
313 * Function to get Current Theme Button
314 *
315 * @param [array] $attr
316 * @return boolean
317 */
318 if (!function_exists('templateberg_is_current_theme_template_available')) {
319 function templateberg_is_current_theme_template_available($item)
320 {
321 $is_available = false;
322 if (!isset($item['is_pro']) || !$item['is_pro']) {
323 $is_available= true;
324 } elseif (empty(templateberg_connect()->get_current_theme_purchase_templates_id())) {
325 $is_available = false;
326 } elseif (in_array($item['id'], templateberg_connect()->get_current_theme_purchase_templates_id())) {
327 $is_available = true;
328 }
329 return $is_available;
330 }
331 }
332
333 /**
334 * Function check if templates has set up
335 *
336 * @param [array] $attr
337 * @return boolean
338 */
339 if (!function_exists('templateberg_has_templates')) {
340 function templateberg_has_templates($type, $theme_slug = '')
341 {
342 $is_available = false;
343
344 switch ($type) {
345 case 'current-theme':
346 $paged = get_query_var('paged')?get_query_var('paged'):1;
347 if ($theme_slug) {
348 $theme = $theme_slug;
349 } else {
350 $theme = get_stylesheet();
351 }
352 $themes_list = templateberg_get_current_theme_templates($paged, $theme);
353 if ($themes_list && 'nothing' !== $themes_list) {
354 $is_available = true;
355 }
356 break;
357
358 case 'available-themes':
359 $paged = get_query_var('paged')?get_query_var('paged'):1;
360 $themes_list = templateberg_get_theme_templates($paged);
361 if ($themes_list) {
362 $is_available = true;
363 }
364 break;
365
366 default:
367 $paged = get_query_var('paged')?get_query_var('paged'):1;
368 $templates_list = templateberg_get_gutenberg_templates($paged);
369 if ($templates_list) {
370 $is_available = true;
371 }
372 break;
373 }
374
375 return $is_available;
376 }
377 }
378
379 /**
380 * Function set gutenberg templates
381 *
382 * @param [array] $attr
383 * @return boolean
384 */
385 if (!function_exists('templateberg_set_gutenberg_templates')) {
386 function templateberg_set_gutenberg_templates($templates_list, $paged = 1)
387 {
388 $is_set = false;
389 $message = array();
390 if (set_transient('templateberg_gt_'.$paged, $templates_list, WEEK_IN_SECONDS) !== true) {
391 global $wp_filesystem;
392 if (! $wp_filesystem) {
393 require_once ABSPATH . 'wp-admin' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'file.php';
394 }
395 $upload_dir = wp_upload_dir();
396 $dir = trailingslashit($upload_dir['basedir']) . 'templateberg' . DIRECTORY_SEPARATOR;
397
398 WP_Filesystem();
399 if (! $wp_filesystem->is_dir($dir)) {
400 $message[] = $dir . __(' not exists', 'templateberg');
401 if ($wp_filesystem->mkdir($dir)) {
402 $message[] = $dir . __(' created', 'templateberg');
403 } else {
404 $message[] = $dir . __(' create permission issue', 'templateberg');
405 }
406 } else {
407 $message[] = $dir . __(' exists', 'templateberg');
408 }
409 $templates_list = json_encode($templates_list);
410 if ($wp_filesystem->put_contents($dir . 'gt-'.$paged.'.json', $templates_list, 0644)) {
411 $is_set = true;
412 $message[] = __('Successfully created file ', 'templateberg') . 'gt-'.$paged.'.json';
413 } else {
414 $message[] = __('Permission denied to create file ', 'templateberg') . 'gt-'.$paged.'.json';
415 }
416 } else {
417 $is_set = true;
418 }
419 return $is_set;
420 }
421 }
422
423 /**
424 * Function get gutenberg templates
425 *
426 * @param [array] $attr
427 * @return boolean
428 */
429 if (!function_exists('templateberg_get_gutenberg_templates')) {
430 function templateberg_get_gutenberg_templates($paged = 1)
431 {
432 $templates_list = get_transient('templateberg_gt_'.$paged);
433 if (!$templates_list) {
434 $upload_dir = wp_upload_dir();
435 $file_dir = $upload_dir['basedir'] . '/templateberg/'.'gt-'.$paged.'.json';
436 if (file_exists($file_dir)) {
437 $file_url = $upload_dir['baseurl'] . '/templateberg/'.'gt-'.$paged.'.json';
438 $body_args = array(
439 /*API version*/
440 'api_version' => TEMPLATEBERG_VERSION,
441 /*lang*/
442 'site_lang' => get_bloginfo('language'),
443 );
444 $raw_json = wp_safe_remote_get(
445 $file_url,
446 array(
447 'timeout' => 100,
448 'body' => $body_args,
449 )
450 );
451 if (! is_wp_error($raw_json)) {
452 $templates_list = json_decode(wp_remote_retrieve_body($raw_json), true);
453 } else {
454 $templates_list = false;
455 }
456 }
457 }
458 return $templates_list;
459 }
460 }
461
462 /**
463 * Function set editor templates
464 *
465 * @param [array] $templates_list
466 * @param [int] $paged
467 * @return boolean
468 */
469 if (!function_exists('templateberg_set_editor_templates')) {
470 function templateberg_set_editor_templates($templates_list, $paged = 1)
471 {
472 $is_set = false;
473 $message = array();
474 ob_start();
475 $is_transient_saved = set_transient('templateberg_edt_'.$paged, $templates_list, WEEK_IN_SECONDS);
476 ob_clean();
477 if ($is_transient_saved !== true) {
478 global $wp_filesystem;
479 if (! $wp_filesystem) {
480 require_once ABSPATH . 'wp-admin' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'file.php';
481 }
482 $upload_dir = wp_upload_dir();
483 $dir = trailingslashit($upload_dir['basedir']) . 'templateberg' . DIRECTORY_SEPARATOR;
484
485 WP_Filesystem();
486 if (! $wp_filesystem->is_dir($dir)) {
487 $message[] = $dir . __(' not exists', 'templateberg');
488 if ($wp_filesystem->mkdir($dir)) {
489 $message[] = $dir . __(' created', 'templateberg');
490 } else {
491 $message[] = $dir . __(' create permission issue', 'templateberg');
492 }
493 } else {
494 $message[] = $dir . __(' exists', 'templateberg');
495 }
496 $templates_list = json_encode($templates_list);
497 if ($wp_filesystem->put_contents($dir . 'edt-'.$paged.'.json', $templates_list, 0644)) {
498 $is_set = true;
499 $message[] = __('Successfully created file ', 'templateberg') . 'edt-'.$paged.'.json';
500 } else {
501 $message[] = __('Permission denied to create file ', 'templateberg') . 'edt-'.$paged.'.json';
502 }
503 } else {
504 $is_set = true;
505 }
506 return $is_set;
507 }
508 }
509
510 /**
511 * Function get editor templates
512 *
513 * @param [int] $paged
514 * @return array
515 */
516 if (!function_exists('templateberg_get_editor_templates')) {
517 function templateberg_get_editor_templates($paged = 1)
518 {
519 $templates_list = get_transient('templateberg_edt_'.$paged);
520 if (!$templates_list) {
521 $upload_dir = wp_upload_dir();
522 $file_dir = $upload_dir['basedir'] . '/templateberg/'.'edt-'.$paged.'.json';
523 if (file_exists($file_dir)) {
524 $file_url = $upload_dir['baseurl'] . '/templateberg/'.'edt-'.$paged.'.json';
525 $body_args = array(
526 /*API version*/
527 'api_version' => TEMPLATEBERG_VERSION,
528 /*lang*/
529 'site_lang' => get_bloginfo('language'),
530 );
531 $raw_json = wp_safe_remote_get(
532 $file_url,
533 array(
534 'timeout' => 100,
535 'body' => $body_args,
536 )
537 );
538 if (! is_wp_error($raw_json)) {
539 $templates_list = json_decode(wp_remote_retrieve_body($raw_json), true);
540 } else {
541 $templates_list = false;
542 }
543 }
544 }
545 return $templates_list;
546 }
547 }
548
549 /**
550 * Function set theme templates
551 *
552 * @param [array] $templates_list
553 * @param [int] $paged
554 * @return boolean
555 */
556 if (!function_exists('templateberg_set_theme_templates')) {
557 function templateberg_set_theme_templates($templates_list, $paged = 1)
558 {
559 $is_set = false;
560 $message = array();
561 if (set_transient('templateberg_tt_'.$paged, $templates_list, 'WEEK_IN_SECONDS') !== true) {
562 global $wp_filesystem;
563 if (! $wp_filesystem) {
564 require_once ABSPATH . 'wp-admin' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'file.php';
565 }
566 $upload_dir = wp_upload_dir();
567 $dir = trailingslashit($upload_dir['basedir']) . 'templateberg' . DIRECTORY_SEPARATOR;
568
569 WP_Filesystem();
570 if (! $wp_filesystem->is_dir($dir)) {
571 $message[] = $dir . __(' not exists', 'templateberg');
572 if ($wp_filesystem->mkdir($dir)) {
573 $message[] = $dir . __(' created', 'templateberg');
574 } else {
575 $message[] = $dir . __(' create permission issue', 'templateberg');
576 }
577 } else {
578 $message[] = $dir . __(' exists', 'templateberg');
579 }
580 $templates_list = json_encode($templates_list);
581 if ($wp_filesystem->put_contents($dir . 'tt-'.$paged.'.json', $templates_list, 0644)) {
582 $is_set = true;
583 $message[] = __('Successfully created file ', 'templateberg') . 'tt-'.$paged.'.json';
584 } else {
585 $message[] = __('Permission denied to create file ', 'templateberg') . 'tt-'.$paged.'.json';
586 }
587 } else {
588 $is_set = true;
589 }
590 return $is_set;
591 }
592 }
593
594 /**
595 * Function get editor templates
596 *
597 * @param [int] $paged
598 * @return array
599 */
600 if (!function_exists('templateberg_get_theme_templates')) {
601 function templateberg_get_theme_templates($paged = 1)
602 {
603 $templates_list = get_transient('templateberg_tt_'.$paged);
604 if (!$templates_list) {
605 $upload_dir = wp_upload_dir();
606 $file_dir = $upload_dir['basedir'] . '/templateberg/'.'tt-'.$paged.'.json';
607 if (file_exists($file_dir)) {
608 $file_url = $upload_dir['baseurl'] . '/templateberg/'.'tt-'.$paged.'.json';
609 $body_args = array(
610 /*API version*/
611 'api_version' => TEMPLATEBERG_VERSION,
612 /*lang*/
613 'site_lang' => get_bloginfo('language'),
614 );
615 $raw_json = wp_safe_remote_get(
616 $file_url,
617 array(
618 'timeout' => 100,
619 'body' => $body_args,
620 )
621 );
622 if (! is_wp_error($raw_json)) {
623 $templates_list = json_decode(wp_remote_retrieve_body($raw_json), true);
624 } else {
625 $templates_list = false;
626 }
627 }
628 }
629 return $templates_list;
630 }
631 }
632
633 /**
634 * Function set current theme templates
635 *
636 * @param [array] $templates_list
637 * @param [int] $paged
638 * @return boolean
639 */
640 if (!function_exists('templateberg_set_current_theme_templates')) {
641 function templateberg_set_current_theme_templates($templates_list, $paged = 1, $theme_slug = '')
642 {
643 $is_set = false;
644 $message = array();
645 if ($theme_slug) {
646 $theme = $theme_slug;
647 } else {
648 $theme = get_stylesheet();
649 }
650 if (set_transient('templateberg_ct_'.$theme.'_templates_'.$paged, $templates_list, 'WEEK_IN_SECONDS') !== true) {
651 global $wp_filesystem;
652 if (! $wp_filesystem) {
653 require_once ABSPATH . 'wp-admin' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'file.php';
654 }
655 $upload_dir = wp_upload_dir();
656 $dir = trailingslashit($upload_dir['basedir']) . 'templateberg' . DIRECTORY_SEPARATOR;
657
658 WP_Filesystem();
659 if (! $wp_filesystem->is_dir($dir)) {
660 $message[] = $dir . __(' not exists', 'templateberg');
661 if ($wp_filesystem->mkdir($dir)) {
662 $message[] = $dir . __(' created', 'templateberg');
663 } else {
664 $message[] = $dir . __(' create permission issue', 'templateberg');
665 }
666 } else {
667 $message[] = $dir . __(' exists', 'templateberg');
668 }
669 $templates_list = json_encode($templates_list);
670 if ($wp_filesystem->put_contents($dir . 'ct-'.$theme.'-'.$paged.'.json', $templates_list, 0644)) {
671 $is_set = true;
672 $message[] = __('Successfully created file ', 'templateberg') . 'ct-'.$theme.'-'.$paged.'.json';
673 } else {
674 $message[] = __('Permission denied to create file ', 'templateberg') . 'ct-'.$theme.'-'.$paged.'.json';
675 }
676 } else {
677 $is_set = true;
678 }
679 return $is_set;
680 }
681 }
682
683 /**
684 * Function get current theme templates
685 *
686 * @param [int] $paged
687 * @return array
688 */
689 if (!function_exists('templateberg_get_current_theme_templates')) {
690 function templateberg_get_current_theme_templates($paged = 1, $theme_slug = '')
691 {
692 if ($theme_slug) {
693 $theme = $theme_slug;
694 } else {
695 $theme = get_stylesheet();
696 }
697
698 $templates_list = get_transient('templateberg_ct_'.$theme.'_templates_' . $paged);
699 if (!$templates_list) {
700 $upload_dir = wp_upload_dir();
701 $file_dir = $upload_dir['basedir'] . '/templateberg/'.'ct-'.$theme.'-'.$paged.'.json';
702 if (file_exists($file_dir)) {
703 $file_url = $upload_dir['baseurl'] . '/templateberg/'.'ct-'.$theme.'-'.$paged.'.json';
704 $body_args = array(
705 /*API version*/
706 'api_version' => TEMPLATEBERG_VERSION,
707 /*lang*/
708 'site_lang' => get_bloginfo('language'),
709 );
710 $raw_json = wp_safe_remote_get(
711 $file_url,
712 array(
713 'timeout' => 100,
714 'body' => $body_args,
715 )
716 );
717 if (! is_wp_error($raw_json)) {
718 $templates_list = json_decode(wp_remote_retrieve_body($raw_json), true);
719 } else {
720 $templates_list = false;
721 }
722 }
723 }
724 return $templates_list;
725 }
726 }
727
728 /**
729 * Function check if templates has set up
730 *
731 * @param [array] $attr
732 * @return boolean
733 */
734 if (!function_exists('templateberg_current_theme_is_nothing')) {
735 function templateberg_current_theme_is_nothing()
736 {
737 $is_available = false;
738 $paged = get_query_var('paged')?get_query_var('paged'):1;
739 $theme = get_stylesheet();
740 $themes_list = templateberg_get_current_theme_templates($paged, $theme);
741 if ('nothing' === $themes_list) {
742 $is_available = true;
743 }
744 return $is_available;
745 }
746 }
747