PluginProbe
Page Builder: Pagelayer – Drag and Drop website builder / 2.2.0
Page Builder: Pagelayer – Drag and Drop website builder v2.2.0
2.2.1 2.2.0 2.1.9 2.1.8 2.1.7 2.1.6 2.1.5 2.1.4 2.1.3 trunk 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5 0.9.6 0.9.7 0.9.8 0.9.9 1.0.0 1.0.2 1.0.3 1.0.4 1.0.5 All 129 releases
pagelayer / main / import.php

import.php in Page Builder: Pagelayer – Drag and Drop website builder 2.2.0, at main/import.php

1,752 lines 59.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 //////////////////////////////////////////////////////////////
4 //===========================================================
5 // template_import.php
6 //===========================================================
7 // PAGELAYER
8 // Inspired by the DESIRE to be the BEST OF ALL
9 // ----------------------------------------------------------
10 // Started by: Pulkit Gupta
11 // Date: 23rd Jan 2017
12 // Time: 23:00 hrs
13 // Site: http://pagelayer.com/wordpress (PAGELAYER)
14 // ----------------------------------------------------------
15 // Please Read the Terms of use at http://pagelayer.com/tos
16 // ----------------------------------------------------------
17 //===========================================================
18 // (c)Pagelayer Team
19 //===========================================================
20 //////////////////////////////////////////////////////////////
21
22 // Are we being accessed directly ?
23 if(!defined('PAGELAYER_VERSION')) {
24 exit('Hacking Attempt !');
25 }
26
27 include_once(PAGELAYER_DIR.'/main/settings.php');
28
29 function pagelayer_import(){
30
31 global $pagelayer, $pagelayer_theme, $pagelayer_theme_url, $pagelayer_theme_path, $pagelayer_pages, $pl_error;
32
33 $pagelayer_theme = wp_get_theme();
34 $pagelayer_theme_url = get_stylesheet_directory_uri();
35 $pagelayer_theme_path = get_stylesheet_directory();
36
37 // Get the pages
38 $pagelayer_templates = @json_decode(file_get_contents($pagelayer_theme_path.'/pagelayer.conf'), true);
39 $pagelayer_pages = @json_decode(file_get_contents($pagelayer_theme_path.'/pagelayer-data.conf'), true);
40
41 if(isset($_POST['theme'])){
42 check_admin_referer('pagelayer-import');
43 $GLOBALS['pl_saved'] = pagelayer_import_theme($pagelayer_theme->template);
44 }
45
46 // Have we already imported ?
47 $imported = get_option('pagelayer_theme_'.get_template().'_imported');
48 if(!empty($imported)){
49 $GLOBALS['pl_warn'] = __('You have already imported the content of this theme. You can re-import the same by either choosing to over-write existing pages / pagelayer templates OR creating duplicate content !', 'pagelayer');
50 }
51
52 // Call the theme
53 pagelayer_import_T();
54
55 }
56
57 function pagelayer_import_T(){
58
59 global $pagelayer, $pagelayer_theme, $pagelayer_theme_url, $pagelayer_theme_path, $pagelayer_pages, $pl_error;
60
61 pagelayer_page_header('Pagelayer - Import Template');
62
63 // Any errors ?
64 if(!empty($pl_error)){
65 pagelayer_report_error($pl_error);echo '<br />';
66 }
67
68 // Saved ?
69 if(!empty($GLOBALS['pl_saved'])){
70 echo '<div class="notice notice-success"><p>'. __('The theme content was successfully imported', 'pagelayer'). '</p></div>';
71
72 // Warn ?
73 }elseif(!empty($GLOBALS['pl_warn'])){
74 echo '<div class="notice notice-warning"><p>'.$GLOBALS['pl_warn'].'</p></div>';
75 }
76
77 // Is it a pagelayer theme ?
78 if(!file_exists($pagelayer_theme_path.'/pagelayer.conf')){
79 echo'<div class="pagelayer-premium-alert pagelayer-alert-warning">
80 <span class="pagelayer-alert-icon dashicons dashicons-warning"></span>
81 <div class="pagelayer-alert-content">
82 ' . __('This utility is for importing content of the current active theme if its a Pagelayer Theme. Your current theme is <strong>not</strong> a Pagelayer exported theme ! If you want to export your content and make it into a distributable theme, please refer to the guide <a href="">here</a>.', 'pagelayer') . '
83 </div>
84 </div>';
85 //return;
86 die();
87 }
88
89 // Home screenshot
90 $screenshot = $pagelayer_theme_url.'/screenshots/home.jpg';
91 if(!file_exists($pagelayer_theme_path.'/screenshots/home.jpg')){
92 $screenshot = PAGELAYER_URL.'/images/no_screenshot.png';
93 }
94
95 echo '
96 <style>
97 .pagelayer_img_screen{
98 width: 120px;
99 margin: 0px 15px 10px 15px;
100 display: inline-block;
101 border: 1px solid transparent;
102 border-radius: 3px;
103 }
104
105 .pagelayer_img_selected{
106 border: 1px solid #1A9CDB;
107 }
108
109 .pagelayer_img_div{
110 overflow: hidden;
111 height: 160px;
112 }
113
114 .pagelayer_img_name{
115 text-align: center;
116 background: #fff;
117 padding: 5px 10px;
118 border-top: 1px solid #ccc;
119 }
120
121 /* The Modal (background) */
122 .pagelayer-modal {
123 display: none;
124 position: fixed;
125 z-index: 10000;
126 left: 0;
127 top: 0;
128 width: 100%;
129 height: 100%;
130 overflow: auto;
131 background-color: rgb(0,0,0);
132 background-color: rgba(0,0,0,0.4);
133 }
134
135 /* Modal Content/Box */
136 .pagelayer-modal-holder {
137 background-color: #fefefe;
138 margin: 15% auto; /* 15% from the top and centered */
139 border: 1px solid #888;
140 width: 50%;
141 min-height: 200px;
142 position: relative;
143 }
144
145 /* The Close Button */
146 .pagelayer-modal-close {
147 color: #aaa;
148 float: right;
149 font-size: 28px;
150 font-weight: bold;
151 }
152
153 .pagelayer-modal-close:hover,
154 .pagelayer-modal-close:focus {
155 color: black;
156 text-decoration: none;
157 cursor: pointer;
158 }
159
160 .pagelayer-modal-header{
161 max-height: 80px;
162 top: 0px;
163 border-bottom: 1px solid #ccc;
164 }
165
166 .pagelayer-modal-footer{
167 max-height: 80px;
168 bottom: 0px;
169 border-top: 1px solid #ccc;
170 text-align: right;
171 }
172
173 .pagelayer-modal-header,
174 .pagelayer-modal-content,
175 .pagelayer-modal-footer{
176 padding: 15px;
177 width: 100%;
178 box-sizing: border-box;
179 }
180
181 #pagelayer-import-form>div{
182 padding: 4px;
183 font-weight: 600;
184 }
185
186 </style>
187
188 <!-- The Modal -->
189 <div id="pagelayerModal" class="pagelayer-modal">
190
191 <!-- Modal holder -->
192 <div class="pagelayer-modal-holder">
193
194 <!-- Modal header -->
195 <div class="pagelayer-modal-header">
196 <b>Import Theme Contents</b> <span class="pagelayer-modal-close">&times;</span>
197 </div>
198
199 <!-- Modal content -->
200 <div class="pagelayer-modal-content">
201 <form id="pagelayer-import-form" method="post" enctype="multipart/form-data">';
202 wp_nonce_field('pagelayer-import');
203 echo '<input name="theme" value="'.get_template().'" type="hidden" />
204 <div><input type="checkbox" name="no_header_menu" /> Do not create Header Menu</div>
205 <div><input type="checkbox" name="delete_old_import" id="delete_old_import" /> Delete Previously Imported Content</div>
206 <div><input type="checkbox" name="overwrite" /> Overwrite existing Pages with same name</div>
207 <div><input type="checkbox" name="set_home_page" checked /> Set the Home Page as per the content</div>
208 <div class="pagelayer-image-copyright">
209 <h2 class="pagelayer-sub-head">Image Copyright</h2>
210 <p>We try our best to use images that are free from legal perspectives. However, we do not take any responsibility for the same. Do you want to use the demo images with this theme ?</p>
211 <ul class="pagelayer-content">
212 <li><input type="checkbox" name="download_imgs" value="1"/> If you click here, then the images will be downloaded from their respective sources.<br/></li>
213 <li>By default it will use placeholder images which are distributed with this theme and can be replaced easily.</li>
214 </ul>
215 </div>
216 </form>
217 </div>
218
219 <!-- Modal footer -->
220 <div class="pagelayer-modal-footer">
221 <button class="button button-primary" onclick="jQuery(\'#pagelayer-import-form\').submit()">Import</button> &nbsp;
222 <button class="button pagelayer-cancel">Cancel</button>
223 </div>
224 </div>
225
226 </div>
227
228 <script>
229
230 function pagelayer_modal(sel){
231
232 var modal = jQuery(sel);
233
234 modal.show();
235
236 // Get the <span> element that closes the modal
237 var span = modal.find(".pagelayer-modal-close, .pagelayer-cancel");
238
239 // When the user clicks on <span> (x), close the modal
240 span.on("click", function() {
241 modal.hide();
242 });
243
244 // When the user clicks anywhere outside of the modal, close it
245 window.onclick = function(event) {
246 if(event.target == modal[0]){
247 modal.hide();
248 }
249 }
250 }
251
252 jQuery(document).ready(function(){
253 var $ = jQuery;
254
255 var choose_image = function(jEle){
256 if(!jEle || !jEle.length){
257 return;
258 }
259 var img_src = jEle.find("img").attr("src");
260 if(typeof img_src === "undefined"){
261 return;
262 }
263 $("#pagelayer_display_image").attr("src", img_src);
264
265 $(".pagelayer_img_screen").removeClass("pagelayer_img_selected");
266 jEle.addClass("pagelayer_img_selected");
267 }
268
269 var first = $(".pagelayer_img_screen:first");
270 var home = $(".pagelayer_img_screen[page=home]");
271
272 if(home.length > 0){
273 first = home;
274 }
275
276 if(first.length > 0){
277 choose_image(first);
278 }
279
280 $(".pagelayer_img_screen").on("click", function(){
281 choose_image($(this));
282 });
283
284 $("#pagelayer-import-form").on("submit", function(){
285
286 if(!jQuery("#delete_old_import").is(":checked")){
287 return true;
288 }
289
290 if(confirm("This will delete any pages / pagelayer templates imported earlier. Should we proceed ?")){
291 return true;
292 }else{
293 return false;
294 }
295
296 });
297
298 });
299 </script>
300
301 <div><h1 style="margin-bottom: 10px; padding-top: 0px;">'.$pagelayer_theme->name.'</h1></div>
302 <div style="margin: 0px -10px; vertical-align: top;">
303 <div style="width: 52%; display: inline-block; text-align: center;">
304 <div style="width: 100%; max-height: 400px; overflow: auto; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);">
305 <img id="pagelayer_display_image" src="'.$screenshot.'" width="100%">
306 </div>
307 </div>
308 <div style="width: 45%; display: inline-block; padding: 0px 10px; vertical-align: top;">';
309 $pages = (array) @$pagelayer_pages['page'];
310 foreach( $pages as $k => $v){
311
312 $screenshot = $pagelayer_theme_url.'/screenshots/'.$k.'.jpg';
313
314 if(!file_exists($pagelayer_theme_path.'/screenshots/'.$k.'.jpg')){
315 $screenshot = PAGELAYER_URL.'/images/no_screenshot.png';
316 }
317
318 echo '<div class="pagelayer_img_screen" page="'.$k.'">
319 <div class="pagelayer_img_div"><img src="'.$screenshot.'" width="100%" /></div>
320 <div class="pagelayer_img_name">'.$v['post_title'].'</div>
321 </div>';
322 }
323
324 echo '</div>
325 </div>
326
327 <div style="position:fixed; bottom: 30px; right: 30px;">
328 <input name="import_theme" class="button button-pagelayer" value="Import Theme Content" type="button" onclick="pagelayer_modal(\'#pagelayerModal\')" />
329 </div>';
330
331 add_filter('pagelayer_right_bar_promos', '__return_false');
332
333 pagelayer_page_footer(1);
334
335 }
336
337 // Imports the required conf
338 function pagelayer_import_conf(&$conf){
339
340 foreach($conf as $k => $v){
341
342 if(in_array($k, ['page_for_posts'])){
343 continue;
344 }
345
346 update_option($k, $v);
347 }
348
349 }
350
351 // The actual function to get page content to import the theme
352 function pagelayer_file_get_import_contents($path){
353
354 $pre_content = apply_filters('pagelayer_pre_get_import_contents', null, $path);
355
356 if(!empty($pre_content)){
357 return $pre_content;
358 }
359
360 $content = file_get_contents($path);
361
362 $content = apply_filters('pagelayer_get_import_contents', $content, $path);
363
364 return $content;
365 }
366
367 // The actual function to import the theme
368 function pagelayer_import_single($template_name, $items, $pagelayer_theme_path = ''){
369
370 global $wpdb, $wp_rewrite;
371 global $pagelayer, $pl_error;
372
373 if(empty($pagelayer_theme_path)){
374 $pagelayer_theme_path = get_stylesheet_directory();
375 }
376
377 if(empty($items)){
378 $pl_error[] = 'Items were not submitted';
379 return false;
380 }
381
382 /////////////////////////
383 // Handle the PAGES Data
384 /////////////////////////
385
386 // Load the new themes pages array
387 $data = file_get_contents($pagelayer_theme_path.'/pagelayer-data.conf');
388 $data = @json_decode($data, true);
389 //r_print($data);die();
390
391 if(empty($data['page'])){
392 $pl_error[] = 'Pages list not found. This is not a proper template !';
393 return false;
394 }
395
396 // Check the theme files
397 foreach($data['page'] as $k => $v){
398
399 $path = pagelayer_cleanpath($pagelayer_theme_path.'/data/page/'.$k);
400
401 // Does it have the title and slug ?
402 if(empty($v['post_title']) || empty($v['post_name'])){
403 $pl_error[] = 'Something is fishy with this theme as there is no title or slug for '.$k;
404 return false;
405 }
406
407 // Does the page exist ?
408 if(!file_exists($path) || pagelayer_cleanpath(realpath($path)) != $path){
409 $pl_error[] = 'Something is fishy with this theme';
410 return false;
411 }
412
413 }
414
415 $status = empty($_POST['save_as_draft']) ? 'publish' : 'draft';
416
417 // Now check the pages if it exist in this installation ?
418 foreach($data['page'] as $k => $v){
419
420 if(!in_array($k, $items['page'])){
421 continue;
422 }
423
424 $path = pagelayer_cleanpath($pagelayer_theme_path.'/data/page/'.$k);
425
426 // Is the page there ?
427 $page = get_page_by_path($v['post_name'], OBJECT, array('page'));
428 //r_print($page);
429
430 $new_post = array();
431
432 // It does exist so save the revision IF its the header and footer
433 if(!empty($page) && isset($_POST['overwrite'])){
434
435 $rev = wp_save_post_revision($page->ID);
436
437 $new_post['ID'] = $page->ID;
438
439 }
440
441 // Make an array
442 $new_post['post_content'] = pagelayer_file_get_import_contents($path);
443 $new_post['post_title'] = $v['post_title'];
444 $new_post['post_name'] = $v['post_name'];
445 $new_post['post_type'] = 'page';
446 $new_post['post_status'] = $status;
447 //r_print($new_post);die();
448
449 // Now insert / update the post
450 $ret = pagelayer_insert_content($new_post, $err);
451
452 // Did we save the post ?
453 if(empty($ret)){
454 $pl_error[] = 'Could not update the page '.$v['post_name'];
455 return false;
456 }
457
458 update_post_meta($ret, 'pagelayer_imported_content', $template_name);
459
460 }
461
462 //To import typography and breakpoint
463 if(!empty($data['conf'])){
464 pagelayer_import_conf($data['conf']);
465 }
466
467 return true;
468
469 }
470
471 // The actual function to import the theme
472 function pagelayer_import_theme($template_name, $pagelayer_theme_path = '', $to_import = array()){
473
474 global $wpdb, $wp_rewrite;
475 global $pagelayer, $pl_error, $sitepad;
476
477 if(empty($pagelayer_theme_path)){
478 $pagelayer_theme_path = get_stylesheet_directory();
479 }
480 //die($pagelayer_theme_path);
481
482 // Delete Old Data ?
483 if(isset($_POST['delete_old_import'])){
484 $args = array(
485 'post_type' => ['page', 'post', $pagelayer->builder['name']],
486 'meta_query' => array(
487 array(
488 'key' => 'pagelayer_imported_content',
489 'compare' => 'EXISTS'
490 )
491 )
492 );
493 $query = new WP_Query($args);
494
495 foreach ( $query->posts as $p ) {
496 //echo $p->ID.'<br>';
497 wp_delete_post($p->ID);
498 }
499 }
500
501 $pagelayer->import_links = [];
502
503 /////////////////////////
504 // Handle PAGELAYER DATA
505 /////////////////////////
506
507 // Load the PGL conf
508 $pgl = file_get_contents($pagelayer_theme_path.'/pagelayer.conf');
509 $pgl = @json_decode($pgl, true);
510
511 if(empty($pgl['header'])){
512 $pl_error[] = 'Header list not found. Report to Website Builder Team';
513 return false;
514 }
515
516 // Load the new themes pages array
517 $data = file_get_contents($pagelayer_theme_path.'/pagelayer-data.conf');
518 $data = @json_decode($data, true);
519 //r_print($data);die();
520
521 // Prepare template data
522 $data = apply_filters('pagelayer_prepare_template_import_data', $data, $template_name );
523
524 if(empty($data['page'])){
525 $pl_error[] = 'Pages list not found. This is not a proper template !';
526 return false;
527 }
528
529 // Check the theme files
530 foreach($pgl as $k => $v){
531
532 $path = pagelayer_cleanpath($pagelayer_theme_path.'/'.$k.'.pgl');
533 //print_r($path);
534
535 // Does the page exist ?
536 if(!file_exists($path) || (empty($GLOBALS['sitepad']['dev']) && pagelayer_cleanpath(realpath($path)) != $path)){
537 $pl_error[] = 'Something is fishy with this theme as the template - '.$k.' - of type - '.$v['type'].' - was not found';
538 return false;
539 }
540
541 }
542
543 // Are we to add default templates ?
544 if(empty($_POST['no_blog_templates'])){
545 add_filter('pagelayer_importing_templates', 'pagelayer_blog_templates', 10, 1);
546 }
547
548 ///////////////////////////
549 // Lets import all MEDIA
550 ///////////////////////////
551
552 // Now lets download the templates
553 if(!function_exists( 'list_files' ) ) {
554 require_once ABSPATH . PAGELAYER_CMS_DIR_PREFIX.'-admin/includes/file.php';
555 }
556
557 $_media = list_files($pagelayer_theme_path.'/images', 1);
558 $imgs_json = array();
559 //pagelayer_print($_media);die();
560
561 if(file_exists($pagelayer_theme_path.'/images.json')){
562 $imgs_json = @json_decode(file_get_contents($pagelayer_theme_path.'/images.json'), true);
563 }
564
565 // Download images
566 if(!empty($_REQUEST['download_imgs'])){
567
568 /* foreach($imgs_json as $k => $v){
569
570 if(empty($v['download_url'])){
571 continue;
572 }
573
574 $dest_dir = $pagelayer_theme_path.'/images';
575 $dest_file = $dest_dir.'/'.$k;
576 $image_file = $v['download_url'];
577
578 // Compare image md5
579 if($v['md5'] != md5_file($image_file)){
580 continue;
581 }
582
583 if(file_exists($dest_file)){
584 $imagesize = getimagesize($dest_file);
585
586 // Download and resize image
587 $resize_file = pagelayer_resizeImage($v['download_url'], $imagesize[0], $imagesize[1]);
588 if(!empty($resize_file)){
589 $image_file = $resize_file;
590 }
591 }
592
593 // Put image in file
594 file_put_contents($dest_file, $image_file);
595
596 } */
597
598 // Update option to set no
599 update_option('pagelayer_import_images_'.$template_name, 'yes');
600
601 }elseif(empty($_REQUEST['download_imgs'])){ // && !file_exists($pagelayer_theme_path.'/images.json')
602 foreach($_media as $k => $v){
603 $imagesize = getimagesize($v);
604 $mime = !empty($imagesize['mime']) ? $imagesize['mime'] : '';
605
606 // Create blank image
607 if(strpos($mime, "image/" ) !== false) {
608 $blank_image = pagelayer_create_blank_image($imagesize[0], $imagesize[1]);
609 file_put_contents($v, $blank_image);
610 }
611 }
612
613 // Update option to set no
614 update_option('pagelayer_import_images_'.$template_name, 'no');
615 }
616
617 foreach($_media as $k => $v){
618 $file_name = basename($v);
619
620 // We are going to create a loop to find the image
621 for($i = 1; $i <= 3; $i++){
622
623 // Upload the image
624 $ret = pagelayer_upload_media($file_name, file_get_contents($v));
625
626 // Lets check the file exists ?
627 if(!empty($ret)){
628
629 // Lets check if the file exists
630 $tmp_image_path = pagelayer_cleanpath(get_attached_file($ret));
631
632 // If the file does not exist, simply delete the old upload as well
633 if(!file_exists($tmp_image_path)){
634 wp_delete_attachment($ret, true);
635 $ret = false;
636
637 // The image does exist and we can continue
638 }else{
639 break;
640 }
641
642 }
643
644 }
645
646 if(!empty($ret)){
647 $pagelayer->import_media['{{theme_url}}/images/'.$file_name] = $ret;
648
649 if(isset($imgs_json[$file_name])){
650 $fields = array('sitepad_img_source', 'sitepad_download_url', 'sitepad_img_lic');
651
652 foreach($fields as $field){
653 $_field = str_replace('sitepad_', '', $field);
654
655 if(!empty($imgs_json[$file_name][$_field])){
656 update_post_meta($ret, $field, $imgs_json[$file_name][$_field]);
657 }
658 }
659 }
660 }
661 }
662 //r_print($pagelayer->import_media);die();
663
664 // If we are to import default templates
665 $pgl = apply_filters('pagelayer_importing_templates', $pgl);
666
667 //////////////////////
668 // Create Menus
669 //////////////////////
670
671 // Create the menu
672 if(empty($_POST['no_header_menu'])){
673
674 // Is there any MENU in this theme ?
675 if(empty($data['menus'])){
676 $menu_id = pagelayer_import_create_menu($template_name.' Header Menu');
677 }else{
678
679 foreach($data['menus'] as $k => $v){
680 $new_id = pagelayer_import_create_menu($v['name']);
681 $pagelayer->imported_menus[$v['term_id']] = $new_id;
682 $pagelayer->imported_menus_slug[$new_id] = $k;
683 }
684
685 //r_print($pagelayer->imported_menus);die();
686
687 $menu_id = current($pagelayer->imported_menus);
688
689 }
690
691 }else{
692
693 // Get the first menu that has items if we still can't find a menu.
694 $menus = wp_get_nav_menus();
695 foreach ( $menus as $menu_maybe ) {
696 $menu_items = wp_get_nav_menu_items( $menu_maybe->term_id, array( 'update_post_term_cache' => false ) );
697 if ( $menu_items ) {
698 $menu_id = $menu_maybe->term_id;
699 break;
700 }
701 }
702
703 }
704
705 // Make a array of OLD IDs => NEW IDs for replace
706 $pagelayer->imported_menus_preg = [];
707
708 // If we have menus !
709 if(!empty($pagelayer->imported_menus)){
710
711 foreach($pagelayer->imported_menus as $k => $v){
712 $pagelayer->imported_menus_preg['('.$k.')'] = $v;
713 }
714
715 // Theme didnt import menus, so lets replace with 0
716 }else{
717 $pagelayer->imported_menus_preg['(\d*)'] = $menu_id;
718 }
719
720 //////////////////////
721 // Start import
722 //////////////////////
723
724 // Import the Pagelayer Templates files
725 foreach($pgl as $k => $v){
726
727 $path = pagelayer_cleanpath($pagelayer_theme_path.'/'.$k.'.pgl');
728
729 $new_post = array();
730
731 // Is the page there ?
732 $template = get_page_by_path($k, OBJECT, array($pagelayer->builder['name']));
733
734 // It does exist so save the revision IF its the header and footer
735 if(!empty($template)){
736
737 $rev = wp_save_post_revision($template->ID);
738
739 // Did we save the rev ?
740 if(empty($rev)){
741 // TODO : Throw error
742 }
743
744 $new_post['ID'] = $template->ID;
745
746 }
747
748 // Make an array
749 $new_post['post_content'] = empty($v['post_content']) ? pagelayer_file_get_import_contents($path) : $v['post_content'];
750 $new_post['post_title'] = $v['title'];
751 $new_post['post_name'] = $k;
752 $new_post['post_type'] = $pagelayer->builder['name'];
753 $new_post['post_status'] = 'publish';
754 $new_post['comment_status'] = 'closed';
755 $new_post['ping_status'] = 'closed';
756 //pagelayer_print($new_post);die();
757
758 // Handle Menu data
759 $new_post['post_content'] = pagelayer_import_handle_replaces($new_post['post_content']);
760
761 //pagelayer_print($new_post);die();
762
763 // Now insert / update the post
764 $ret = pagelayer_insert_content($new_post, $err);
765 $post_id = $ret;
766 $pagelayer->import_map[$k] = $ret;
767 $pagelayer->imported_ids[$new_post['post_type']][$new_post['post_name']] = $ret;
768
769 // Did we save the rev ?
770 if(empty($ret)){
771 $pl_error[] = 'Could not update the Pagelayer Template '.$k;
772 return false;
773 }
774
775 // Save our template type
776 update_post_meta($post_id, 'pagelayer_template_type', $v['type']);
777 update_post_meta($post_id, 'pagelayer_template_conditions', $v['conditions']);
778 update_post_meta($post_id, 'pagelayer_imported_content', $template_name);
779
780 // Any conditions having Page IDs that need to be updated ?
781 if(!empty($v['conditions'])){
782
783 foreach($v['conditions'] as $ck => $cv){
784 if(!empty($cv['id'])){
785 $conditions[$post_id][$ck] = $cv['id'];
786 }
787 }
788
789 }
790
791 }
792
793 /////////////////////////
794 // Handle the PAGES Data
795 /////////////////////////
796
797 //pagelayer_print($data);
798
799 // Import taxonomies
800 $taxonomy_ids = array();
801 if(!empty($data['taxonomies'])){
802 $taxonomy_ids = pagelayer_import_taxonomies($data['taxonomies']);
803 }
804
805 foreach($data as $data_type => $data_v){
806
807 $pagelayer->imported[$data_type] = 1;
808
809 // To import theme related settings
810 if($data_type == 'conf'){
811 pagelayer_import_conf($data['conf']);
812 continue;
813 }
814
815 if($data_type == 'menus' || $data_type == 'taxonomies'){
816 continue;
817 }
818
819 // Check the theme files
820 foreach($data[$data_type] as $k => $v){
821
822 $path = pagelayer_cleanpath($pagelayer_theme_path.'/data/'.$data_type.'/'.$k);
823
824 // Does it have the title and slug ?
825 if(empty($v['post_title']) || empty($v['post_name'])){
826 $pl_error[] = 'Something is fishy with this theme as there is no title or slug for '.$k;
827 return false;
828 }
829
830 // Does the file exist ?
831 if(!file_exists($path) || (empty($GLOBALS['sitepad']['dev']) && pagelayer_cleanpath(realpath($path)) != $path)){
832 $pl_error[] = 'Something is fishy with this theme';
833 return false;
834 }
835
836 }
837
838 $menu_pages = [];
839
840 // Now check the pages if it exist in this installation ?
841 foreach($data[$data_type] as $k => $v){
842
843 // Do we have to import selected pages ?
844 if(!empty($to_import[$data_type]) && !in_array($k, $to_import[$data_type])){
845 continue;
846 }
847
848 do_action('pagelayer_start_importing_page', $k);
849
850 $path = pagelayer_cleanpath($pagelayer_theme_path.'/data/'.$data_type.'/'.$k);
851
852 $args = ['post_type' => $data_type,
853 'name' => $v['post_name'],
854 'post_status' => $v['post_status'],
855 'posts_per_page' => -1
856 ];
857
858 $type_query = new WP_Query($args);
859
860 // Is the page there ?
861 $page = @current($type_query->posts);
862 //r_print($page);
863
864 $new_post = array();
865 $insert_meta = 1;
866
867 // It does exist so save the revision IF its the header and footer
868 if(!empty($page)){
869
870 $insert_meta = 0;
871
872 if(isset($_POST['overwrite'])){
873 $rev = wp_save_post_revision($page->ID);
874 $new_post['ID'] = $page->ID;
875 $insert_meta = 1;
876 }
877
878 }
879
880 // Make an array
881 $new_post['post_content'] = pagelayer_file_get_import_contents($path);
882 $new_post['post_excerpt'] = $v['post_excerpt'];
883 $new_post['post_title'] = $v['post_title'];
884 $new_post['post_name'] = $v['post_name'];
885 $new_post['post_type'] = $data_type;
886 $new_post['post_status'] = 'publish';
887
888 if(isset($_POST['maintain_ids']) && empty($new_post['ID'])){
889 $new_post['import_id'] = $v['ID'];
890 }
891
892 // Category register
893 if(!empty($v['taxonomies'])){
894
895 foreach($v['taxonomies'] as $tax => $tax_ids){
896
897 if(!empty($tax_ids)){
898
899 // Need to replace ids with new ids
900 $tax_ids = explode(',', $tax_ids);
901
902 foreach($tax_ids as $key => $id){
903 $tax_ids[$key] = (int) $taxonomy_ids[$id];
904 }
905
906 switch ($tax) {
907 case 'category':
908 $new_post['post_category'] = $tax_ids;
909 break;
910 case 'post_tag':
911 $new_post['tags_input'] = $tax_ids;
912 break;
913 default:
914 $new_post['tax_input'][$tax] = $tax_ids;
915 }
916 }
917
918 }
919
920 }
921
922 // Meta file path
923 $meta_path = pagelayer_cleanpath($pagelayer_theme_path.'/data/'.$data_type.'/'.$k.'.meta');
924
925 if($insert_meta && file_exists($meta_path)){
926 $meta_path = pagelayer_cleanpath($pagelayer_theme_path.'/data/'.$data_type.'/'.$k.'.meta');
927 $new_post['meta_input'] = file_get_contents($meta_path);
928 $new_post['meta_input'] = json_decode($new_post['meta_input']);
929 }
930
931 //r_print($new_post);die();
932
933 // Handle Menu data
934 $new_post['post_content'] = pagelayer_import_handle_replaces($new_post['post_content']);
935
936 // Now insert / update the post
937 $ret = pagelayer_insert_content($new_post, $err);
938
939 // Did we save the post ?
940 if(empty($ret)){
941 $pl_error[] = 'Could not update the '.$data_type.' '.$v['post_name'];
942 return false;
943 }
944
945 update_post_meta($ret, 'pagelayer_imported_content', $template_name);
946
947 $pagelayer->import_map[$v['ID']] = $ret;
948 $pagelayer->imported_ids[$new_post['post_type']][$new_post['post_name']] = $ret;
949
950 // Skip Header, Footer and Home pages
951 if($data_type == 'page' && preg_match('/^home/is', $new_post['post_name'])){
952 $home_page = $ret;
953 }
954
955 if(defined('SITEPAD')){
956
957 // Does the screenshot exist ?
958 $screenshot_file = $pagelayer_theme_path.'/screenshots/'.$v['post_name'].'.jpg';
959 if(file_exists($screenshot_file)){
960 @mkdir($sitepad['screenshots_path'], 0755, true);
961 @copy($screenshot_file, $sitepad['screenshots_path'].'/'.$v['post_name'].'.jpg');
962 }
963
964 }
965
966 }
967
968 }
969
970 // Update Post for import
971 if(!empty($conditions)){
972
973 foreach($conditions as $post_ID => $v){
974
975 $cond = get_post_meta($post_ID, 'pagelayer_template_conditions', 1);
976
977 foreach($v as $ck => $cv){
978
979 if(!empty($pagelayer->import_map[$cv])){
980 $cond[$ck]['id'] = $pagelayer->import_map[$cv];
981 }
982
983 }
984
985 update_post_meta($post_id, 'pagelayer_template_conditions', $cond);
986
987 }
988
989 }
990
991 // Call a function for the theme if they want to execute something like create more templates, etc
992 $ret = apply_filters('pagelayer_theme_imported', $template_name);
993
994 if(isset($_POST['set_home_page']) || isset($_POST['create_blog_page'])){
995
996 // Get the home page ID
997 $blog = get_page_by_path('blog', OBJECT, array('page'));
998
999 // Insert the blog page
1000 if(empty($blog)){
1001
1002 $new_post['post_content'] = '';
1003 $new_post['post_title'] = 'Blog';
1004 $new_post['post_name'] = 'blog';
1005 $new_post['post_type'] = 'page';
1006 $new_post['post_status'] = 'publish';
1007
1008 // Now insert / update the post
1009 $blog_id = wp_insert_post($new_post);
1010
1011 }else{
1012 $blog_id = $blog->ID;
1013 }
1014
1015 // Set the blog page
1016 update_option('page_for_posts', $blog_id);
1017
1018 }
1019
1020 if(!empty($data['conf']['page_for_posts'])){
1021 $pagelayer->import_map[$data['conf']['page_for_posts']] = $blog_id;
1022 $pagelayer->imported_ids['page']['blog'] = $blog_id;
1023 }
1024
1025 // Update any links that are to be updated
1026 if(!empty($pagelayer->import_links)){
1027
1028 foreach($pagelayer->import_links as $post_type => $v){
1029 foreach($v as $slug => $link_maps){
1030
1031 // Lets get the post
1032 $tmp_post = get_post($pagelayer->imported_ids[$post_type][$slug]);
1033
1034 foreach($link_maps as $old_link_type => $old_link_slugs){
1035
1036 //pagelayer_print($old_link_slugs);die();
1037
1038 foreach($old_link_slugs as $old_link_slug){
1039
1040 // Did we have such a link ?
1041 $new_link_id = @$pagelayer->imported_ids[$old_link_type][$old_link_slug];
1042
1043 // If not found, lets try to find a similar post
1044 if(empty($new_link_id)){
1045
1046 $args = ['name' => $old_link_slug,
1047 'post_type' => $old_link_type];
1048
1049 // Make query
1050 $query = new WP_Query($args);
1051
1052 // Get post
1053 if(!empty($query->posts)){
1054 $link_post = current($query->posts);
1055 //echo $old_link_slug.' - ';pagelayer_print($link_post->post_name);die();
1056
1057 $new_link_id = @$link_post->ID;
1058 }
1059
1060 }
1061
1062 if(empty($new_link_id)){
1063 continue;
1064 }
1065
1066 $tmp_post->post_content = str_replace('||link_id|'.$old_link_type.'|'.$old_link_slug.'||', $new_link_id, $tmp_post->post_content);
1067 }
1068 }
1069
1070 //pagelayer_print($tmp_post);
1071 wp_update_post($tmp_post);
1072 }
1073 }
1074
1075 }
1076
1077 if(isset($_POST['set_home_page'])){
1078
1079 // Set the blog page
1080 update_option('show_on_front', 'page');
1081
1082 // Set home page as the default page
1083 if(!empty($home_page)){
1084 update_option('page_on_front', $home_page);
1085 }
1086
1087 }
1088
1089 // Update the menu
1090 if(empty($_POST['no_header_menu'])){
1091
1092 // Are we importing from the theme ?
1093 if(!empty($pagelayer->imported_menus)){
1094
1095 foreach($pagelayer->imported_menus as $k => $v){
1096 pagelayer_import_update_menus($v, $pagelayer_theme_path);
1097 }
1098
1099 // We created the menu, lets update it
1100 }else{
1101 pagelayer_update_header_menu($menu_id, $pagelayer->import_map);
1102 }
1103 }
1104
1105 // Save that we have imported the theme
1106 update_option('pagelayer_theme_'.$template_name.'_imported', time(), true);
1107
1108 // Blank woocommerce fix
1109 update_option('pagelayer_template_product_fix', 0);
1110
1111 return true;
1112
1113 }
1114
1115 // Import Taxonomies Handler
1116 function pagelayer_import_taxonomies($taxonomy){
1117
1118 $new_ids = array();
1119
1120 foreach($taxonomy as $term_id => $term){
1121
1122 $parent_id = null;
1123 $term_par = 0;
1124
1125 // If tern has parent
1126 if(!empty($term['parent']) && empty($new_ids[$term['parent']])){
1127
1128 // Get parent taxonomy
1129 $par_terms = get_terms( array(
1130 'taxonomy' => $term['taxonomy'],
1131 'hide_empty' => false,
1132 'meta_key' => 'pagelayer_imported_id',
1133 'meta_value' => $term['parent']
1134 ) );
1135
1136 $par_terms_len = count($par_terms) - 1;
1137
1138 // If not exists
1139 if(is_wp_error($par_terms) || empty($par_terms)){
1140 $par_ids = pagelayer_import_taxonomies(array($term['parent'] => $taxonomy[$term['parent']]));
1141 $term_par = $parent_id = $par_ids[$term['parent']];
1142 $new_ids[$term['parent']] = $parent_id;
1143 }elseif($par_terms_len > -1){
1144 $term_par = $parent_id = $par_terms[$par_terms_len]->term_id;
1145 }
1146
1147 }elseif(!empty($new_ids[$term['parent']])){
1148 $term_par = $parent_id = $new_ids[$term['parent']];
1149 }
1150
1151 $exist_term = term_exists($term['name'], $term['taxonomy'], $parent_id );
1152
1153 if($exist_term === null){
1154 $tax_details = wp_insert_term($term['name'], $term['taxonomy'] ,array('description' => $term['description'],'parent' => $term_par, 'slug' => $term['slug']));
1155 if(!(is_wp_error( $tax_details ))){
1156 $new_id = $tax_details['term_id'];
1157 }
1158 }elseif(is_array($exist_term)){
1159 $new_id = $exist_term['term_id'];
1160 }else{
1161 $new_id = $exist_term;
1162 }
1163
1164 // ID is empty?
1165 if(empty($new_id)){
1166 continue;
1167 }
1168
1169 update_term_meta( $new_id, 'pagelayer_imported_id', $term_id);
1170 $new_ids[$term_id] = $new_id;
1171 }
1172
1173 return $new_ids;
1174 }
1175
1176 add_filter('pagelayer_start_insert_content', 'pagelayer_import_start_insert_content');
1177 function pagelayer_import_start_insert_content($post){
1178
1179 global $pagelayer;
1180
1181 $_post = json_encode($post);
1182
1183 // Does it have links ?
1184 if(preg_match_all('/(\|\|link_id\|([\w-]*)\|([\w-]*)\|\|)/', $_post, $matches)){
1185 foreach($matches[3] as $kk => $link){
1186 $pagelayer->import_links[$post['post_type']][$post['post_name']][$matches[2][$kk]][] = $link;
1187 }
1188 //pagelayer_print($matches);pagelayer_print($pagelayer->import_links);die();
1189 }
1190
1191 if(preg_match('/theme_url/is', $_post)){
1192 $do = 1;
1193 }
1194
1195 // Lets replace the images
1196 foreach($pagelayer->import_media as $k => $v){
1197 $_post = str_replace($k, $v, $_post);
1198 $k = str_replace('/', '\/', $k);// Handle JSON
1199 $_post = str_replace($k, $v, $_post);
1200 $k = str_replace('/', '\/', addslashes($k));// Handle Doubled JSON
1201 $_post = str_replace($k, $v, $_post);
1202 }
1203
1204 $post = json_decode($_post, true);
1205
1206 if(!empty($do)){
1207 //echo $_post;
1208 //pagelayer_print($post);die();
1209 }
1210
1211 return $post;
1212 }
1213
1214 // Create the menu
1215 function pagelayer_import_create_menu($name){
1216
1217 // Create the menu if not exists
1218 $menu_name = (empty($name) ? 'Pagelayer Menu' : $name);
1219 $menu_exists = wp_get_nav_menu_object($menu_name);
1220
1221 // If there is no menu we will need to add it
1222 if(!empty($menu_exists)){
1223 wp_delete_nav_menu($menu_exists);
1224 }
1225
1226 // Insert the Menu
1227 $menu_id = wp_create_nav_menu($menu_name);
1228
1229 //r_print($menu_exists);r_print($menu_name);r_print($menu_id);die();
1230
1231 if(!is_int($menu_id)){
1232 return false;
1233 }
1234
1235 // We need to DISABLE auto add TEMPORARILY
1236 $options = (array) get_option('nav_menu_options');
1237
1238 if (isset($options['auto_add'])){
1239 $key = array_search($menu_id, $options['auto_add']);
1240
1241 if(!empty($key)){
1242 unset($options['auto_add'][$key]);
1243 update_option('nav_menu_options', $options);
1244 }
1245 }
1246
1247 return $menu_id;
1248
1249 }
1250
1251 // Callback for menu replacement
1252 function pagelayer_import_handle_replaces($content){
1253 global $pagelayer;
1254
1255 // Replace the old ID structure
1256 $content = preg_replace_callback('/pagelayer-id="(\w{16})"/s', 'pagelayer_handle_id_sc', $content);
1257 $content = preg_replace_callback('/"pagelayer-id"\:"(\w{16})"/s', 'pagelayer_handle_id', $content);
1258
1259 foreach($pagelayer->imported_menus_preg as $k => $v){
1260 $content = preg_replace('/\[pl_wp_menu ([^\]]*)nav_list="'.$k.'"([^\]]*)\]/is', '[pl_wp_menu ${1}nav_list="'.$v.'"${3}]', $content);
1261 }
1262
1263 // Also for block format
1264 $content = preg_replace_callback('/<!--\s+(?P<closer>\/)?sp:pagelayer\/pl_wp_menu\s+(?P<attrs>{(?:(?:[^}]+|}+(?=})|(?!}\s+\/?-->).)*+)?}\s+)?(?P<void>\/)?-->/s', 'pagelayer_handle_wp_menu', $content);
1265
1266 // Lets replace the variables for social icons
1267 $content = preg_replace_callback('/\[pl_social ([^\]]*)\]/is', 'pagelayer_handle_social_urls', $content);
1268
1269 $content = preg_replace_callback('/<!--\s+(?P<closer>\/)?sp:pagelayer\/pl_social\s+(?P<attrs>{(?:(?:[^}]+|}+(?=})|(?!}\s+\/?-->).)*+)?}\s+)?(?P<void>\/)?-->/s', 'pagelayer_handle_social_urls_blocks', $content);
1270
1271 // Remove comment_atts attribute
1272 if(!PAGELAYER_DEV && stripos( $content, 'comment_atts') !== false){
1273 $content = pagelayer_clear_comment_atts($content);
1274 }
1275
1276 return $content;
1277 }
1278
1279 // Remove comment_atts attribute
1280 function pagelayer_clear_comment_atts($content){
1281
1282 if(defined('PAGELAYER_BLOCK_PREFIX') && PAGELAYER_BLOCK_PREFIX == 'wp'){
1283 $content = str_replace('<!-- sp:pagelayer', '<!-- wp:pagelayer', $content);
1284 $content = str_replace('<!-- /sp:pagelayer', '<!-- /wp:pagelayer', $content);
1285 }
1286
1287 if( ! defined('DB_CHARSET') || strpos(DB_CHARSET, 'utf8mb4') === false ){
1288 $content = pagelayer_remove_broken_utf16( $content );
1289 }
1290
1291 $blocks = parse_blocks( $content );
1292 $output = '';
1293
1294 foreach($blocks as $block){
1295 $block_name = $block['blockName'];
1296
1297 // Is pagelayer block
1298 if ( is_string( $block_name ) && 0 === strpos( $block_name, 'pagelayer/' ) ) {
1299 $_block = pagelayer_clear_block_comment_atts($block);
1300 $output .= serialize_block($_block);
1301 continue;
1302 }
1303
1304 $output .= serialize_block($block);
1305 }
1306
1307 return $output;
1308 }
1309
1310 // Helper function for remove comment_atts attribute
1311 function pagelayer_clear_block_comment_atts($block){
1312
1313 if(isset($block['attrs']['comment_atts'])){
1314 unset($block['attrs']['comment_atts']); // cleanup
1315 }
1316
1317 // This have innerBlocks
1318 if(!empty($block['innerBlocks']) && is_array($block['innerBlocks'])){
1319 foreach($block['innerBlocks'] as $key => $inner_block){
1320 $block['innerBlocks'][$key] = pagelayer_clear_block_comment_atts($inner_block);
1321 }
1322 }
1323
1324 return $block;
1325 }
1326
1327 function pagelayer_remove_broken_utf16($string) {
1328 // Remove UTF-16 surrogate pairs (\uD800–\uDFFF)
1329 return preg_replace('/\\\\u(d[89ab][0-9a-fA-F]{2})/i', '', $string);
1330 }
1331
1332 // Update the header menu
1333 function pagelayer_update_header_menu($menu_id, $pages){
1334
1335 $menu_pages = [];
1336
1337 $home = get_option('page_on_front');
1338 if(!empty($home)){
1339 $menu_pages[] = $home;
1340 }
1341
1342 $blog = get_option('page_for_posts');
1343 if(!empty($blog)){
1344 $menu_pages[] = $blog;
1345 }
1346
1347 // The other links
1348 foreach($pages as $pk => $pv){
1349
1350 $tmp = get_post($pv);
1351
1352 if(is_wp_error($tmp) || $tmp->post_type !== 'page'){
1353 continue;
1354 }
1355
1356 // Skip Header, Footer and Home pages
1357 if(in_array($pv, $menu_pages)){
1358 continue;
1359 }
1360
1361 $menu_pages[] = $pv;
1362
1363 }
1364
1365 // Get the pages
1366 foreach($menu_pages as $pk => $page_id){
1367 $menu_pages[$pk] = get_post($page_id);
1368 }
1369
1370 // The other links
1371 foreach($menu_pages as $pk => $pv){
1372
1373 wp_update_nav_menu_item($menu_id, 0, array(
1374 'menu-item-title' => $pv->post_title,
1375 'menu-item-url' => home_url( '/'.$pv->post_name.'/' ),
1376 'menu-item-status' => 'publish',
1377 'menu-item-type' => 'post_type',
1378 'menu-item-object' => 'page',
1379 'menu-item-object-id' => $pv->ID));
1380
1381 }
1382
1383 // We need to enable auto add new pages
1384 $options = (array) get_option('nav_menu_options');
1385
1386 if (!isset($options['auto_add'])){
1387 $options['auto_add'] = array();
1388 }
1389
1390 $options['auto_add'][] = $menu_id;
1391 update_option('nav_menu_options', $options);
1392
1393 }
1394
1395 // For import of our exported menus
1396 function pagelayer_import_update_menus($menu_id, $pagelayer_theme_path = ''){
1397
1398 global $pagelayer;
1399
1400 $old_id = array_search($menu_id, $pagelayer->imported_menus);
1401 $slug = $pagelayer->imported_menus_slug[$menu_id];
1402
1403 $data = file_get_contents($pagelayer_theme_path.'/data/menus/'.$slug);
1404 $data = @json_decode($data, true);
1405
1406 $ids = [];
1407
1408 // Insert the links
1409 foreach($data as $k => $v){
1410
1411 $r = [];
1412 $r['menu-item-title'] = $v['post']['title'];
1413 $r['menu-item-status'] = $v['post']['post_status'];
1414 $r['menu-item-type'] = $v['post']['type'];
1415 $r['menu-item-object'] = $v['post']['object'];
1416 $r['menu-item-classes'] = implode(' ', $v['post']['classes']);
1417
1418 // Any parent ?
1419 if(!empty($v['post']['menu_item_parent'])){
1420
1421 $parent = $ids[$v['post']['menu_item_parent']];
1422
1423 if(!empty($parent)){
1424 $r['menu-item-parent-id'] = $parent;
1425 }
1426
1427 }
1428
1429 // Regular Data Object
1430 if($r['menu-item-type'] !== 'custom'){
1431
1432 $r['menu-item-object-id'] = $pagelayer->import_map[$v['post']['object_id']];
1433
1434 if(empty($r['menu-item-object-id'])){
1435 continue;
1436 }
1437
1438 $r['menu-item-url'] = get_permalink($r['menu-item-object-id']);
1439
1440 // Custom URL
1441 }else{
1442 $r['menu-item-url'] = $v['post']['url'];
1443 }
1444
1445 //r_print($r);
1446
1447 $updated_nav = wp_update_nav_menu_item($menu_id, 0, $r);
1448 $ids[$v['post']['db_id']] = $updated_nav;
1449
1450 if(isset($v['post_metas']['_pagelayer_content'])){
1451 $mdata = pagelayer_import_handle_replaces($v['post_metas']['_pagelayer_content']);
1452 $mdata = pagelayer_sanitize_content($mdata);
1453 update_post_meta($updated_nav, '_pagelayer_content', $mdata);
1454 }
1455 }
1456
1457 // We need to enable auto add new pages
1458 $options = (array) get_option('nav_menu_options');
1459
1460 if (!isset($options['auto_add'])){
1461 $options['auto_add'] = array();
1462 }
1463
1464 $options['auto_add'][] = $menu_id;
1465 update_option('nav_menu_options', $options);
1466
1467 }
1468
1469 // Callback for menu replacement
1470 function pagelayer_handle_wp_menu($matches){
1471 global $pagelayer;
1472
1473 foreach($pagelayer->imported_menus_preg as $k => $v){
1474 $matches[0] = preg_replace('/nav_list"\s*:\s*"'.$k.'"/is', 'nav_list":"'.$v.'"', $matches[0]);
1475 }
1476
1477 return $matches[0];
1478
1479 }
1480
1481 // Change the old style ID to the new style
1482 function pagelayer_handle_id($matches){
1483 //r_print($matches);die();
1484 $str = '"pagelayer-id":"'.pagelayer_create_id().'"';
1485 return $str;
1486 }
1487
1488 // Change the old style ID to the new style
1489 function pagelayer_handle_id_sc($matches){
1490 //r_print($matches);die();
1491 $str = 'pagelayer-id="'.pagelayer_create_id().'"';
1492 return $str;
1493 }
1494
1495 // Replace Social URLs with the one given in setup
1496 function pagelayer_handle_social_urls($matches){
1497 //r_print($matches);die();
1498
1499 // Get the icon
1500 preg_match('/icon=(\'|")([^\'"]*)(\'|")/is', $matches[0], $icon);
1501 $icon = $icon[2];
1502
1503 $urls = pagelayer_get_social_urls();
1504
1505 foreach($urls as $k => $v){
1506 if(preg_match('/'.preg_quote($k, '/').'/is', $icon)){
1507 $social_url = $v;
1508 break;
1509 }
1510 }
1511
1512 if(!empty($social_url)){
1513
1514 // Is the social_url param there ?
1515 if(!preg_match('/social_url=/is', $matches[0])){
1516 $matches[0] = substr($matches[0], 0, -1).'social_url="#"]';
1517 }
1518
1519 $matches[0] = preg_replace('/social_url=(\'|")([^\'"]*)(\'|")/is', 'social_url="'.$social_url.'"', $matches[0]);
1520 }
1521
1522 //r_print($matches);die();
1523
1524 return $matches[0];
1525
1526 }
1527
1528 // Replace Social URLs with the one given in setup
1529 function pagelayer_handle_social_urls_blocks($matches){
1530
1531 // Get the icon
1532 preg_match('/icon":"([^"]*)"/is', $matches[0], $icon);
1533 $icon = $icon[1];
1534
1535 $urls = pagelayer_get_social_urls();
1536
1537 foreach($urls as $k => $v){
1538 if(preg_match('/'.preg_quote($k, '/').'/is', $icon)){
1539 $social_url = $v;
1540 break;
1541 }
1542 }
1543
1544 if(!empty($social_url)){
1545
1546 // Is the social_url param there ?
1547 if(!preg_match('/"social_url"/is', $matches[0])){
1548 $matches[0] = preg_replace('/("icon"\s*:\s*"([^"]*)")/is', '"icon":"'.$icon.'","social_url":"#"', $matches[0]);
1549 }
1550
1551 $matches[0] = preg_replace('/social_url"\s*:\s*"([^"]*)"/is', 'social_url":"'.$social_url.'"', $matches[0]);
1552 }
1553
1554 return $matches[0];
1555
1556 }
1557
1558 // Add the blog templates
1559 function pagelayer_blog_templates($pgl){
1560
1561 $conf = '{
1562 "single-template": {
1563 "type": "single",
1564 "title": "Single Template",
1565 "conditions": [
1566 {
1567 "type": "include",
1568 "template": "singular",
1569 "sub_template": "post",
1570 "id": ""
1571 },
1572 {
1573 "type": "include",
1574 "template": "singular",
1575 "sub_template": "attachment",
1576 "id": ""
1577 }
1578 ]
1579 },
1580 "blog-template": {
1581 "type": "archive",
1582 "title": "Blog Template",
1583 "conditions": [
1584 {
1585 "type": "include",
1586 "template": "archives",
1587 "sub_template": "",
1588 "id": ""
1589 }
1590 ]
1591 },
1592 "404": {
1593 "type": "single",
1594 "title": "404",
1595 "conditions": [
1596 {
1597 "type": "include",
1598 "template": "singular",
1599 "sub_template": "404",
1600 "id": ""
1601 }
1602 ]
1603 }
1604 }';
1605
1606 $conf = json_decode($conf, true);
1607
1608 // Do we have the blog template ?
1609 if(empty($pgl['blog-template'])){
1610
1611 $conf['blog-template']['post_content'] = '<!-- sp:pagelayer/pl_row {"stretch":"auto","col_gap":"0","width_content":"auto","row_height":"default","overlay_hover_delay":"400","row_shape_top_color":"#227bc3","row_shape_top_width":"100","row_shape_top_height":"100","row_shape_bottom_color":"#e44993","row_shape_bottom_width":"100","row_shape_bottom_height":"100","ele_padding_tablet":"0px,0px,0px,0px","ele_padding_mobile":"0px,0px,0px,0px","ele_margin":"80px,0px,40px,0px","ele_padding":"0px,0px,0px,0px","pagelayer-id":"m4k2309"} -->
1612 <!-- sp:pagelayer/pl_col {"overlay_hover_delay":"400","widget_space":"0","col_width":"100","col_width_mobile":"100","ele_padding_mobile":"10px,10px,10px,10px","col_width_tablet":"100","ele_padding_tablet":"10px,10px,10px,10px","pagelayer-id":"8yo2717"} -->
1613 <!-- sp:pagelayer/pl_archive_posts {"type":"default","columns":"3","columns_mobile":"1","col_gap":"30","row_gap":"30","data_padding":"10,10,10,10","bg_color":"#ffffff","show_thumb":"true","show_title":"true","meta":"date","meta_sep":"","show_content":"excerpt","content_color":"#adb5bdff","content_align":"left","pagination":"number_prev_next","thumb_size":"medium_large","ratio":"0.7","title_color":"#495057ff","title_typo":",20,,bold,,,,,,,","exc_length":"10","pagi_prev_text":"Previous","pagi_next_text":"Next","pagi_end_size":"1","pagi_mid_size":"2","pagi_align":"center","box_shadow":"0,1,5,#00000026,0,","title_spacing":"0,0","meta_color":"#666666ff","meta_align":"left","meta_typo":"Roboto,12,,600,,,,,Uppercase,,","content_padding":"10,0,10,0","pagi_colors":"active","pagi_color":"#495057ff","pagi_hover_color":"#000000ff","pagi_current_color":"#000000ff","pagi_typo":",,,,,,,,,,","meta_tag_pos":"absolute","meta_width":"50%","meta_vposition":"bottom","meta_hposition":"left","meta_vposition_offset":"8px","meta_hposition_offset":"8px","show_more":"true","more":"Read More","align":"right","icon_position":"pagelayer-btn-icon-right","more_typo":"Roboto,12,,bold,,,,,Capitalize,,","btn_type":"pagelayer-btn-custom","size":"pagelayer-btn-custom","icon":"fas fa-angle-right","icon_spacing":"5","btn_bg_color":"#00000000","more_color":"#adb5bdff","btn_hover":"hover","btn_custom_size":"0,0","pagi_padding":"50,0,0,0","columns_tablet":"1","pagelayer-id":"mue2352"} /-->
1614 <!-- /sp:pagelayer/pl_col -->
1615 <!-- /sp:pagelayer/pl_row -->';
1616
1617 $pgl['blog-template'] = $conf['blog-template'];
1618
1619 }
1620
1621 // Do we have the blog template ?
1622 if(empty($pgl['404'])){
1623
1624 $conf['404']['post_content'] = '<!-- sp:pagelayer/pl_row {"stretch":"auto","col_gap":"10","width_content":"auto","row_height":"default","overlay_hover_delay":"400","row_shape_top_color":"#227bc3","row_shape_top_width":"100","row_shape_top_height":"100","row_shape_bottom_color":"#e44993","row_shape_bottom_width":"100","row_shape_bottom_height":"100","ele_margin":"120px,0px,120px,0px","ele_padding":"0px,0px,0px,0px","pagelayer-id":"rxs3267"} -->
1625 <!-- sp:pagelayer/pl_col {"widget_space":"15","overlay_hover_delay":"400","col_width":"50","col_width_mobile":"40","col_width_tablet":"40","pagelayer-id":"iyr6907"} -->
1626 <!-- sp:pagelayer/pl_image {"id":"{{pl_plugin_url}}/images/404image.jpg","id-size":"full","align":"right","img_hover":"normal","img_hover_delay":"400","caption_color":"#0986c0","max-width":"36","custom_size":"400x400","max-width_mobile":"100","max-width_tablet":"100","pagelayer-id":"tem415"} /-->
1627 <!-- /sp:pagelayer/pl_col -->
1628 <!-- sp:pagelayer/pl_col {"widget_space":"15","overlay_hover_delay":"400","content_pos":"center","col_width":"50","col_width_mobile":"55","col_width_tablet":"55","pagelayer-id":"wnp3287"} -->
1629 <!-- sp:pagelayer/pl_heading {"text":"\u003cp\u003eThe page you requested was not found we suggest you to go back to HomePage\u003c\/p\u003e","heading_state":"normal","align":"left","color":"#495057ff","heading_typo":",,,,,,,,,,","heading_text_shadow":",,,","ele_custom_pos":"true","ele_align":"margin","ele_height":"auto","ele_custom_width":"80%","ele_custom_width_mobile":"100%","ele_custom_width_tablet":"100%","pagelayer-id":"a8q1058"} --><p>The page you requested was not found we suggest you to go back to HomePage</p><!-- /sp:pagelayer/pl_heading -->
1630 <!-- sp:pagelayer/pl_btn {"text":"Back To HomePage","align":"left","type":"pagelayer-btn-custom","size":"pagelayer-btn-custom","btn_hover_delay":"400","icon_position":"pagelayer-btn-icon-left","icon_spacing":"5","link":"||link_id|page|home||","btn_typo":"Roboto,15,Normal,500,Normal,None,,1,Uppercase,1,1","btn_bg_color":"#ff8474ff","btn_color":"#ffffff","btn_custom_size":"25","btn_hover":"hover","btn_bg_color_hover":"#583d72ff","btn_color_hover":"#ffffffff","btn_shadow":"1,1,1,#000000ff,1,","btn_typo_mobile":",14,,,,,,,,,","btn_typo_tablet":",14,,,,,,,,,","pagelayer-id":"znu8912"} /-->
1631 <!-- /sp:pagelayer/pl_col -->
1632 <!-- /sp:pagelayer/pl_row -->';
1633
1634 $pgl['404'] = $conf['404'];
1635
1636 }
1637
1638
1639 // Do we have the blog template ?
1640 if(empty($pgl['single-template'])){
1641
1642 $conf['single-template']['post_content'] = '<!-- sp:pagelayer/pl_row {"stretch":"auto","col_gap":"0","width_content":"fixed","row_height":"default","overlay_hover_delay":"400","row_shape_top_color":"#227bc3","row_shape_top_width":"100","row_shape_top_height":"100","row_shape_bottom_color":"#e44993","row_shape_bottom_width":"100","row_shape_bottom_height":"100","ele_margin":"80px,0px,80px,0px","ele_padding":"0px,0px,0px,0px","fixed_width":"75%","fixed_width_mobile":"100%","fixed_width_tablet":"100%","pagelayer-id":"bdr9414"} -->
1643 <!-- sp:pagelayer/pl_col {"widget_space":"15","overlay_hover_delay":"400","ele_padding":"10px,10px,10px,10px","content_pos":"center","col_width":"100","pagelayer-id":"yfr4566"} -->
1644 <!-- sp:pagelayer/pl_post_title {"title_color":"#495057ff","typo":",35,,bold,,,,1.3,,,","shadow":"0,0,1,#000000ff","align":"left","typo_mobile":",30,,,,,,,,,","typo_tablet":",30,,,,,,,,,","pagelayer-id":"v7n9444"} /-->
1645 <!-- sp:pagelayer/pl_post_excerpt {"align":"left","pe_margin":"0px,0px,0px,0px","color":"#adb5bdff","typo":",15,Italic,500,,,,1.5,,,","ele_margin":"0px,0px,0px,0px","ele_padding":"0px,0px,0px,0px","pagelayer-id":"kgd1425"} /-->
1646 <!-- sp:pagelayer/pl_featured_img {"size":"full","img_filter":"0,100,100,0,0,100,100","caption_color":"#0986c0","img_hover_delay":"400","align":"center","img_shadow":"0,24,36,#0000001a,0,","custom_size":"80%,60%","pagelayer-id":"4wb1030"} /-->
1647 <!-- sp:pagelayer/pl_inner_row {"stretch":"auto","col_gap":"10","width_content":"auto","row_height":"default","overlay_hover_delay":"400","row_shape_top_color":"#227bc3","row_shape_top_width":"100","row_shape_top_height":"100","row_shape_bottom_color":"#e44993","row_shape_bottom_width":"100","row_shape_bottom_height":"100","pagelayer-id":"f8n3612"} -->
1648 <!-- sp:pagelayer/pl_inner_col {"widget_space":"15","overlay_hover_delay":"400","content_pos":"center","col":"4","pagelayer-id":"i795860"} -->
1649 <!-- sp:pagelayer/pl_post_info {"layout":"vertical","space_between":"25","align":"left","icon_colors":"normal","text_colors":"hover","icon_color_normal":"#495057ff","text_color_normal":"#495057ff","text_color_hover":"#000000ff","input_typo":"Roboto,14,,500,,,,1.6,,,","ele_align":"margin","ele_height":"auto","ele_width":"initial","icon_size":"120%","pagelayer-id":"qip3968"} -->
1650 <!-- sp:pagelayer/pl_post_info_list {"type":"author","info_link":"true","info_icon_on":"true","info_icon":"fas fa-user-circle","info_avatar":"true","info_avatar_size":"22","pagelayer-id":"l1i4146"} /-->
1651 <!-- sp:pagelayer/pl_post_info_list {"type":"date","info_link":"true","info_icon_on":"true","info_icon":"far fa-clock","date_format":"default","pagelayer-id":"xj43574"} /-->
1652 <!-- /sp:pagelayer/pl_post_info -->
1653 <!-- /sp:pagelayer/pl_inner_col -->
1654 <!-- sp:pagelayer/pl_inner_col {"widget_space":"15","overlay_hover_delay":"400","content_pos":"center","col":"7","pagelayer-id":"t2j1983"} -->
1655 <!-- sp:pagelayer/pl_post_info {"layout":"vertical","space_between":"0","align":"right","icon_colors":"normal","text_colors":"normal","icon_color_normal":"#495057ff","text_color_normal":"#0072ffff","text_color_hover":"","input_typo":"Roboto,14,,500,,,,1.6,,,","ele_align":"margin","ele_height":"auto","ele_width":"initial","icon_size":"120%","ele_position":"","ele_hposition":"left","ele_hposition_offset":"100%","ele_bg_type":"","ele_bg_color":"#66aaff26","ele_padding":"0px,0px,0px,0px","align_mobile":"left","align_tablet":"left","anchor_text_colors":"normal","anchor_text_color_normal":"#f48989ff","anchor_background_color_normal":"#4bd34bff","anchor_text_padding":"5,10,5,10","anchor_text_margin":"10,10,10,10","terms_text_colors":"normal","terms_background_color_normal":"#66aaff26","terms_text_color_normal":"#0072ffff","terms_text_padding":"5,10,5,10","terms_text_margin":"0,5,0,5","terms_border_radius":"4,4,4,4","pagelayer-id":"dbq3916"} -->
1656 <!-- sp:pagelayer/pl_post_info_list {"type":"terms","info_link":"true","info_icon_on":"","info_icon":"fas fa-user-circle","taxonomy":"category","pagelayer-id":"wpv7212"} /-->
1657 <!-- /sp:pagelayer/pl_post_info -->
1658 <!-- /sp:pagelayer/pl_inner_col -->
1659 <!-- /sp:pagelayer/pl_inner_row -->
1660 <!-- sp:pagelayer/pl_inner_row {"stretch":"auto","col_gap":"10","width_content":"auto","row_height":"default","overlay_hover_delay":"400","row_shape_top_color":"#227bc3","row_shape_top_width":"100","row_shape_top_height":"100","row_shape_bottom_color":"#e44993","row_shape_bottom_width":"100","row_shape_bottom_height":"100","pagelayer-id":"trw3096"} -->
1661 <!-- sp:pagelayer/pl_inner_col {"widget_space":"15","overlay_hover_delay":"400","content_pos":"center","col":"2","pagelayer-id":"wwu6541"} -->
1662 <!-- sp:pagelayer/pl_post_content {"align":"left","pagelayer-id":"ccj4284"} /-->
1663 <!-- /sp:pagelayer/pl_inner_col -->
1664 <!-- /sp:pagelayer/pl_inner_row -->
1665 <!-- sp:pagelayer/pl_inner_row {"stretch":"auto","col_gap":"10","width_content":"auto","row_height":"default","overlay_hover_delay":"400","row_shape_top_color":"#227bc3","row_shape_top_width":"100","row_shape_top_height":"100","row_shape_bottom_color":"#e44993","row_shape_bottom_width":"100","row_shape_bottom_height":"100","pagelayer-id":"wl6689"} -->
1666 <!-- sp:pagelayer/pl_inner_col {"widget_space":"15","overlay_hover_delay":"400","content_pos":"center","col":"6","pagelayer-id":"fja274"} -->
1667 <!-- sp:pagelayer/pl_post_info {"layout":"vertical","space_between":"0","align":"left","icon_colors":"normal","text_colors":"normal","icon_color_normal":"#495057ff","text_color_normal":"#0072ffff","text_color_hover":"","input_typo":"Roboto,13,,500,,,,1.6,Uppercase,,","ele_align":"margin","ele_height":"auto","ele_width":"initial","icon_size":"120%","ele_position":"","ele_hposition":"left","ele_hposition_offset":"100%","ele_bg_type":"","ele_bg_color":"#66aaff26","ele_padding":"0px,0px,0px,0px","align_mobile":"left","align_tablet":"left","anchor_text_colors":"normal","anchor_text_color_normal":"#f48989ff","anchor_background_color_normal":"#4bd34bff","anchor_text_padding":"5,10,5,10","anchor_text_margin":"10,10,10,10","terms_text_colors":"normal","terms_background_color_normal":"#66aaff26","terms_text_color_normal":"#0072ffff","terms_text_padding":"5,10,5,10","terms_text_margin":"0,5,0,5","terms_border_radius":"4,4,4,4","pagelayer-id":"dcl5111"} -->
1668 <!-- sp:pagelayer/pl_post_info_list {"type":"terms","info_link":"true","info_icon_on":"","info_icon":"fas fa-user-circle","taxonomy":"post_tag","info_before":"\ud83d\udd16Tags:","pagelayer-id":"7401458"} /-->
1669 <!-- /sp:pagelayer/pl_post_info -->
1670 <!-- /sp:pagelayer/pl_inner_col -->
1671 <!-- sp:pagelayer/pl_inner_col {"widget_space":"15","overlay_hover_delay":"400","content_pos":"center","col":"6","pagelayer-id":"jzl6522"} -->
1672 <!-- sp:pagelayer/pl_share_grp {"type":"icon-label","bg_shape":"pagelayer-social-bg-none","align":"right","vspace":"0","hspace":"0","height":"35","icon_size":"27","icon_space":"0","color_scheme":"pagelayer-scheme-official","icon_color":"#adb5bdff","social_hover_delay":"400","name_typo":"Roboto,15,,500,,,,,,,","count":"","icon_bg_color":"#00000000","social_hover":"","icon_color_hover":"#000000ff","icon_bg_color_hover":"#00000000","vspace_mobile":"10","hspace_mobile":"10","height_mobile":"NaN","icon_size_mobile":"20","name_typo_mobile":",13,,,,,,,,,","align_mobile":"left","align_tablet":"left","vspace_tablet":"10","hspace_tablet":"10","icon_size_tablet":"20","name_typo_tablet":",13,,,,,,,,,","pagelayer-id":"xsb5673"} -->
1673 <!-- sp:pagelayer/pl_share {"icon":"fab fa-facebook-square","target":"true","text":"Share on Facebook","pagelayer-id":"9mh2934"} /-->
1674 <!-- sp:pagelayer/pl_share {"icon":"fab fa-twitter-square","text":"Share on Twitter","target":"true","pagelayer-id":"rai4926"} /-->
1675 <!-- /sp:pagelayer/pl_share_grp -->
1676 <!-- /sp:pagelayer/pl_inner_col -->
1677 <!-- /sp:pagelayer/pl_inner_row -->
1678 <!-- sp:pagelayer/pl_inner_row {"stretch":"auto","col_gap":"10","width_content":"auto","row_height":"default","overlay_hover_delay":"400","row_shape_top_color":"#227bc3","row_shape_top_width":"100","row_shape_top_height":"100","row_shape_bottom_color":"#e44993","row_shape_bottom_width":"100","row_shape_bottom_height":"100","pagelayer-id":"zqp4850"} -->
1679 <!-- sp:pagelayer/pl_inner_col {"widget_space":"15","overlay_hover_delay":"400","content_pos":"center","col":"2","pagelayer-id":"q725202"} -->
1680 <!-- sp:pagelayer/pl_post_nav {"lables":"true","post_title":"true","arrows":"true","sep_color":"#adb5bdff","sep_rotate":"20","sep_width":"1","prev_label":"Previous","next_label":"Next","label_colors":"hover","title_colors":"normal","arrows_list":"chevron","icon_colors":"hover","label_color":"#adb5bdff","label_hover_color":"","label_typo":",15,,,,,,,,,","title_color":"#000000ff","title_typo":"Roboto,18,,bold,,,,,,,","icon_color":"#adb5bdff","icon_hover_color":"","icon_size":"30","disable_sep":"true","taxonomies":"category","pagelayer-id":"55r4448"} /-->
1681 <!-- /sp:pagelayer/pl_inner_col -->
1682 <!-- /sp:pagelayer/pl_inner_row -->
1683 <!-- /sp:pagelayer/pl_col -->
1684 <!-- /sp:pagelayer/pl_row -->
1685 <!-- sp:pagelayer/pl_row {"stretch":"auto","col_gap":"0","width_content":"fixed","row_height":"default","overlay_hover_delay":"400","row_shape_top_color":"#227bc3","row_shape_top_width":"100","row_shape_top_height":"100","row_shape_bottom_color":"#e44993","row_shape_bottom_width":"100","row_shape_bottom_height":"100","ele_margin":"0px,0px,0px,0px","ele_padding":"0px,0px,0px,0px","fixed_width":"75%","fixed_width_mobile":"100%","ele_margin_mobile":"0px,0px,0px,0px","ele_padding_mobile":"0px,0px,0px,0px","fixed_width_tablet":"100%","pagelayer-id":"kf35301"} -->
1686 <!-- sp:pagelayer/pl_col {"widget_space":"15","overlay_hover_delay":"400","ele_padding":"10px,10px,10px,10px","content_pos":"center","col_width":"100","pagelayer-id":"d539589"} -->
1687 <!-- sp:pagelayer/pl_post_comment {"comment_skin":"theme_comment","post_type":"current","pagelayer-id":"1oh7228"} /-->
1688 <!-- /sp:pagelayer/pl_col -->
1689 <!-- /sp:pagelayer/pl_row -->';
1690
1691 $pgl['single-template'] = $conf['single-template'];
1692
1693 }
1694
1695 return $pgl;
1696
1697 }
1698
1699 // Resize Image
1700 function pagelayer_resizeImage($filename, $newwidth, $newheight){
1701
1702 $imagesize = getimagesize($filename);
1703 $width = $imagesize[0];
1704 $height = $imagesize[1];
1705
1706 // Calculate the Height and width
1707 if($width <= $newwidth || $height <= $newheight){
1708 return false;
1709 }
1710
1711 $thumb = imagecreatetruecolor($newwidth, $newheight);
1712
1713 switch($imagesize['mime']) {
1714 case 'image/jpg':
1715 case 'image/jpeg':
1716 $source = imagecreatefromjpeg($filename);
1717 break;
1718 case 'image/gif':
1719 $source = imagecreatefromgif($filename);
1720 break;
1721 case 'image/png':
1722 $source = imagecreatefrompng($filename);
1723 break;
1724 }
1725
1726 if(empty($source)){
1727 return false;
1728 }
1729
1730 imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
1731 imagedestroy($source);
1732 ob_start();
1733
1734 switch($imagesize['mime']) {
1735 case 'image/jpg':
1736 case 'image/jpeg':
1737 imagejpeg($thumb);
1738 break;
1739 case 'image/gif':
1740 imagegif($thumb);
1741 break;
1742 case 'image/png':
1743 imagepng($thumb);
1744 break;
1745 }
1746
1747 $image = ob_get_clean();
1748 imagedestroy($thumb);
1749
1750 return $image;
1751 }
1752