PluginProbe
Page Builder: Pagelayer – Drag and Drop website builder / 0.9.4
Page Builder: Pagelayer – Drag and Drop website builder v0.9.4
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 / init.php

init.php in Page Builder: Pagelayer – Drag and Drop website builder 0.9.4, at init.php

604 lines 15.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // We need the ABSPATH
4 if (!defined('ABSPATH')) exit;
5
6 define('PAGELAYER_BASE', plugin_basename(__FILE__));
7 define('PAGELAYER_FILE', __FILE__);
8 define('PAGELAYER_VERSION', '0.9.4');
9 define('PAGELAYER_DIR', WP_PLUGIN_DIR.'/'.basename(dirname(PAGELAYER_FILE)));
10 define('PAGELAYER_SLUG', 'pagelayer');
11 define('PAGELAYER_URL', plugins_url('', PAGELAYER_FILE));
12 define('PAGELAYER_CSS', PAGELAYER_URL.'/css');
13 define('PAGELAYER_JS', PAGELAYER_URL.'/js');
14 define('PAGELAYER_PRO_URL', 'https://pagelayer.com/features#compare');
15 define('PAGELAYER_DOCS', 'https://pagelayer.com/docs/');
16 define('PAGELAYER_API', 'https://api.pagelayer.com/');
17 define('PAGELAYER_SC_PREFIX', 'pl');
18 define('PAGELAYER_YOUTUBE_BG', 'https://www.youtube.com/watch?v=Csa6rvCWmLU');
19
20 include_once(PAGELAYER_DIR.'/main/functions.php');
21 include_once(PAGELAYER_DIR.'/main/class.php');
22
23 // Ok so we are now ready to go
24 register_activation_hook(PAGELAYER_FILE, 'pagelayer_activation');
25
26 // Is called when the ADMIN enables the plugin
27 function pagelayer_activation(){
28
29 global $wpdb;
30
31 $sql = array();
32
33 /*$sql[] = "DROP TABLE IF EXISTS `".$wpdb->prefix."pagelayer_logs`";
34
35 foreach($sql as $sk => $sv){
36 $wpdb->query($sv);
37 }*/
38
39 add_option('pagelayer_version', PAGELAYER_VERSION);
40 add_option('pagelayer_options', array());
41
42 }
43
44 // Checks if we are to update ?
45 function pagelayer_update_check(){
46
47 global $wpdb;
48
49 $sql = array();
50 $current_version = get_option('pagelayer_version');
51 $version = (int) str_replace('.', '', $current_version);
52
53 // No update required
54 if($current_version == PAGELAYER_VERSION){
55 return true;
56 }
57
58 // Is it first run ?
59 if(empty($current_version)){
60
61 // Reinstall
62 pagelayer_activation();
63
64 // Trick the following if conditions to not run
65 $version = (int) str_replace('.', '', PAGELAYER_VERSION);
66
67 }
68
69 // Save the new Version
70 update_option('pagelayer_version', PAGELAYER_VERSION);
71
72 }
73
74 // Add the action to load the plugin
75 add_action('plugins_loaded', 'pagelayer_load_plugin');
76
77 // The function that will be called when the plugin is loaded
78 function pagelayer_load_plugin(){
79
80 global $pagelayer;
81
82 // Check if the installed version is outdated
83 pagelayer_update_check();
84
85 // Set the array
86 $pagelayer = new PageLayer();
87
88 // Is there any ACTION set ?
89 $pagelayer->action = pagelayer_optreq('pagelayer-action');
90
91 // Load settings
92 $options = get_option('pagelayer_options');
93 $pagelayer->settings['post_types'] = empty($options['post_types']) ? array('post', 'page') : $options['post_types'];
94 $pagelayer->settings['css_code'] = empty($options['css_code']) ? '' : $options['css_code'];
95 $pagelayer->settings['animate'] = empty($options['animate']) ? '' : $options['animate'];
96 $pagelayer->settings['max_width'] = empty($options['max_width']) ? 1170 : $options['max_width'];
97
98 // Load the language
99 load_plugin_textdomain('pagelayer', false, PAGELAYER_SLUG.'/languages/');
100
101 // Show the promo
102 pagelayer_maybe_promo([
103 'after' => 1,// In days
104 'interval' => 30,// In days
105 //'pro_url' => 'https://pagelayer.com/themes/wordpress/corporate/Bizworx_Pro',
106 'rating' => 'https://wordpress.org/plugins/pagelayer/#reviews',
107 'twitter' => 'https://twitter.com/pagelayer?status='.rawurlencode('I love #PageLayer Site Builder by @pagelayer team for my #WordPress site - '.home_url()),
108 'facebook' => 'https://www.facebook.com/pagelayer',
109 'website' => '//pagelayer.com',
110 'image' => PAGELAYER_URL.'/images/pagelayer-logo-256.png'
111 ]);
112
113 }
114
115 // This adds the left menu in WordPress Admin page
116 add_action('admin_menu', 'pagelayer_admin_menu');
117
118 // Shows the admin menu of Pagelayer
119 function pagelayer_admin_menu() {
120
121 global $wp_version, $pagelayer;
122
123 $capability = 'activate_plugins';// TODO : Capability for accessing this page
124
125 // Add the menu page
126 add_menu_page(__('PageLayer Editor'), __('PageLayer'), $capability, 'pagelayer', 'pagelayer_page_handler', PAGELAYER_URL.'/images/pagelayer-logo-19.png');
127
128 // Settings Page
129 add_submenu_page('pagelayer', __('PageLayer Editor'), __('Settings'), $capability, 'pagelayer', 'pagelayer_page_handler');
130
131 // Its premium
132 if(defined('PAGELAYER_PREMIUM')){
133
134 // Fonts link
135 add_submenu_page('pagelayer', __('PageLayer Font Settings'), __('PageLayer Font Settings'), $capability, 'pagelayer_fonts', 'pagelayer_page_fonts');
136
137 // Its free
138 }else{
139
140 // Go Pro link
141 add_submenu_page('pagelayer', __('PageLayer Go Pro'), __('Go Pro'), $capability, PAGELAYER_PRO_URL);
142
143 }
144
145 }
146
147 // This function will handle the pages in Pages in PageLayer
148 function pagelayer_page_handler(){
149
150 global $wp_version, $pagelayer;
151
152 wp_enqueue_script( 'pagelayer-admin', PAGELAYER_JS.'/pagelayer-admin.js', array('jquery'), PAGELAYER_VERSION);
153 wp_enqueue_style( 'pagelayer-admin', PAGELAYER_CSS.'/pagelayer-admin.css', array(), PAGELAYER_VERSION);
154
155 include_once(PAGELAYER_DIR.'/main/settings.php');
156
157 // Handle fonts
158 if($pagelayer->action == 'fonts-manager'){
159 include_once(PAGELAYER_DIR.'/main/fonts.php');
160 }
161
162 }
163
164 // Load the Live Body
165 add_action('template_redirect', 'pagelayer_load_live_body', 4);
166
167 function pagelayer_load_live_body(){
168
169 global $post;
170
171 // If its not live editing then stop
172 if(!pagelayer_is_live()){
173 return;
174 }
175
176 // If its the iFRAME then return
177 if(pagelayer_is_live_iframe()){
178 return;
179 }
180
181 // Are you allowed to edit ?
182 if(!pagelayer_user_can_edit()){
183 return;
184 }
185
186 // Load the editor live body
187 include_once(PAGELAYER_DIR.'/main/live-body.php');
188
189 pagelayer_live_body();
190
191 }
192
193 // Add the JS and CSS for Posts and Pages when being viewed ONLY if there is our content called
194 add_action('template_redirect', 'pagelayer_enqueue_frontend', 5);
195
196 function pagelayer_enqueue_frontend($force = false){
197
198 global $post, $pagelayer;
199
200 if(!empty($pagelayer->cache['enqueue_frontend'])){
201 return;
202 }
203
204 if(empty($post->ID)){
205 return;
206 }
207
208 // Enqueue the FRONTEND CSS
209 if(get_post_meta($post->ID , 'pagelayer-data') || $force){
210
211 // We dont need the auto <p> and <br> as they interfere with us
212 remove_filter('the_content', 'wpautop');
213
214 // No need to add curly codes to the content
215 remove_filter('the_content', 'wptexturize');
216
217 pagelayer_load_shortcodes();
218 $pagelayer->cache['enqueue_frontend'] = true;
219
220 // Enqueue our Editor's Frontend JS
221 wp_register_script('pagelayer-frontend', PAGELAYER_JS.'/givejs.php?give=pagelayer-frontend.js,nivo-lightbox.min.js,slippry.min.js,wow.min.js,jquery-numerator.js,simpleParallax.min.js', array('jquery'), PAGELAYER_VERSION);
222 wp_enqueue_script('pagelayer-frontend');
223
224 wp_register_style('pagelayer-frontend', PAGELAYER_CSS.'/givecss.php?give=pagelayer-frontend.css,nivo-lightbox.css,slippry.css,animate.min.css', array(), PAGELAYER_VERSION);
225 wp_enqueue_style('pagelayer-frontend');
226
227 wp_register_style('font-awesome', PAGELAYER_CSS.'/font-awesome.min.css', array(), PAGELAYER_VERSION);
228 wp_enqueue_style('font-awesome');
229
230 // Load the global styles
231 add_action('wp_head', 'pagelayer_global_styles', 5);
232
233 // Load custom widgets
234 do_action('pagelayer_custom_frontend_enqueue');
235
236 }
237
238 }
239
240 // Load the google fonts
241 add_action('wp_footer', 'pagelayer_enqueue_fonts', 5);
242
243 function pagelayer_enqueue_fonts(){
244 global $pagelayer;
245
246 if(empty($pagelayer->cache['enqueue_frontend'])){
247 return;
248 }
249
250 $url = 'Open Sans:300italic,400italic,600italic,300,400,600&subset=latin,latin-ext';
251 //pagelayer_print($pagelayer->runtime_fonts);die('alpesh');
252
253 foreach($pagelayer->runtime_fonts as $font){
254 $url .= '|'.$font.':100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i';
255 }
256
257 //echo '<link href="https://fonts.googleapis.com/css?family='.$url.'" rel="stylesheet">';
258
259 wp_register_style('pagelayer-google-font', 'https://fonts.googleapis.com/css?family='.rawurlencode($url), array(), PAGELAYER_VERSION);
260 wp_enqueue_style('pagelayer-google-font');
261
262 }
263
264 // We need to handle global styles
265 function pagelayer_global_styles(){
266
267 $styles = '<style id="pagelayer-global-styles" type="text/css">';
268
269 $width = get_option('pagelayer_content_width', '1170');
270
271 $styles .= '.pagelayer-row-stretch-auto .pagelayer-row-holder{ max-width: '.$width.'px; margin-left: auto; margin-right: auto;}';
272
273 $styles .= '</style>';
274
275 echo $styles;
276 }
277
278 // Load the live editor if needed
279 add_action('wp_enqueue_scripts', 'pagelayer_load_live', 9999);
280
281 function pagelayer_load_live(){
282
283 global $post;
284
285 // If its not live editing then stop
286 if(!pagelayer_is_live_iframe()){
287 return;
288 }
289
290 // Are you allowed to edit ?
291 if(!pagelayer_user_can_edit()){
292 return;
293 }
294
295 // Load the editor class
296 include_once(PAGELAYER_DIR.'/main/live.php');
297
298 // Call the constructor
299 $pl_editor = new PageLayer_LiveEditor();
300
301 }
302
303 // Show the backend editor options
304 add_action('edit_form_after_title', 'pagelayer_after_title');
305 function pagelayer_after_title(){
306
307 global $post;
308
309 // Get the current screen
310 $current_screen = get_current_screen();
311
312 // For gutenberg
313 if(method_exists($current_screen, 'is_block_editor') && $current_screen->is_block_editor()){
314
315 // Add the code in the footer
316 add_action('admin_footer', 'pagelayer_gutenberg_after_title');
317
318 return;
319 }
320
321 $link = pagelayer_shortlink($post->ID).'&pagelayer-live=1';
322
323 echo '
324 <div id="pagelayer-editor-button-row" style="margin-top:15px">
325 <a id="pagelayer-editor-button" href="'.$link.'" class="button button-primary button-large" style="height:auto; padding:6px; font-size:18px;">
326 <img src="'.PAGELAYER_URL.'/images/pagelayer-logo-40.png" align="top" width="24" /> <span>'.__('Edit with PageLayer').'</span>
327 </a>
328 </div>';
329
330 }
331
332 function pagelayer_gutenberg_after_title(){
333
334 global $post;
335
336 $link = pagelayer_shortlink($post->ID).'&pagelayer-live=1';
337
338 echo '
339 <div id="pagelayer-editor-button-row" style="margin-left:15px; display:none">
340 <a id="pagelayer-editor-button" href="'.$link.'" class="button button-primary button-large" style="height:auto; padding:6px; font-size:18px;">
341 <img src="'.PAGELAYER_URL.'/images/pagelayer-logo-40.png" align="top" width="24" /> <span>'.__('Edit with PageLayer').'</span>
342 </a>
343 </div>
344
345 <script type="text/javascript">
346 jQuery(document).ready(function(){
347
348 var pagelayer_timer;
349 var pagelayer_button = function(){
350 var button = jQuery("#pagelayer-editor-button-row");
351 var g = jQuery(".edit-post-header-toolbar");
352 if(g.length < 1){
353 return;
354 }
355 button.detach();
356 //console.log(button);
357 g.append(button);
358 button.show();
359 clearInterval(pagelayer_timer);
360 }
361 pagelayer_timer = setInterval(pagelayer_button, 100);
362 });
363 </script>';
364
365 }
366
367 add_filter( 'post_row_actions', 'pagelayer_quick_link', 10, 2 );
368 add_filter( 'page_row_actions', 'pagelayer_quick_link', 10, 2 );
369 function pagelayer_quick_link($actions, $post){
370 $link = pagelayer_shortlink($post->ID).'&pagelayer-live=1';
371
372 $actions['pagelayer'] = '<a href="'.esc_url( $link ).'">'.__( 'Edit using PageLayer', 'pagelayer') .'</a>';
373
374 return $actions;
375 }
376
377 // The ajax handler
378 add_action('wp_ajax_pagelayer_wp_widget', 'pagelayer_wp_widget_ajax');
379 function pagelayer_wp_widget_ajax(){
380
381 global $pagelayer;
382
383 // Some AJAX security
384 check_ajax_referer('pagelayer_ajax', 'nonce');
385
386 pagelayer_load_shortcodes();
387
388 header('Content-Type: application/json');
389
390 $ret = [];
391 $tag = @$_POST['tag'];
392 //pagelayer_print($pagelayer->shortcodes[$tag]);
393
394 // No tag ?
395 if(empty($pagelayer->shortcodes[$tag])){
396 $ret['error'][] = 'No Tag';
397 echo json_encode($ret);
398 wp_die();
399 }
400
401 // Include the widgets
402 include_once(ABSPATH . 'wp-admin/includes/widgets.php');
403
404 $class = $pagelayer->shortcodes[$tag]['widget'];
405
406 // Check the widget class exists ?
407 if(empty($class) || !class_exists($class)){
408 $ret['error'][] = 'No Widget Class';
409 echo json_encode($ret);
410 wp_die();
411 }
412
413 $instance = [];
414 $widget = new $class();
415 $widget->_set('pagelayer-widget-1234567890');
416
417 // Is there any existing data ?
418 if(!empty($_POST['widget_data'])){
419 $json = json_decode(stripslashes($_POST['widget_data']), true);
420 //pagelayer_print($json);die();
421 if(!empty($json)){
422 $instance = $json;
423 }
424 }
425
426 // Are there any form values ?
427 if(!empty($_POST['values'])){
428 parse_str(stripslashes($_POST['values']), $data);
429 //pagelayer_print($data);die();
430
431 // Any data ?
432 if(!empty($data)){
433
434 // First key is useless
435 $data = current($data);
436
437 // Do we still have valid data ?
438 if(!empty($data)){
439
440 // 2nd key is useless and just over-ride instance
441 $instance = current($data);
442
443 }
444 }
445 }
446
447 // Get the form
448 ob_start();
449 $widget->form($instance);
450 $ret['form'] = ob_get_contents();
451 ob_end_clean();
452
453 // Get the html
454 ob_start();
455 $widget->widget([], $instance);
456 $ret['html'] = ob_get_contents();
457 ob_end_clean();
458
459 // Widget data to set
460 if(!empty($instance)){
461 $ret['widget_data'] = $instance;
462 }
463
464 echo json_encode($ret);
465 wp_die();
466
467 }
468
469 // Update Post content
470 add_action('wp_ajax_pagelayer_save_content', 'pagelayer_save_content');
471 function pagelayer_save_content(){
472
473 // Some AJAX security
474 check_ajax_referer('pagelayer_ajax', 'nonce');
475
476 $content = $_POST['pagelayer_update_content'];
477
478 $postID = (int) $_GET['postID'];
479
480 if(empty($postID)){
481 $msg['error'] = 'Invalid post ID';
482 }
483
484 // Check if the post exists
485
486 if(!empty($postID) && !empty($content)){
487
488 $post = array(
489 'ID' => $postID,
490 'post_content' => $content,
491 );
492
493 // Update the post into the database
494 wp_update_post($post);
495
496 if (is_wp_error($postID)) {
497 $msg['error'] = 'Unable to update the Post Content for some reason';
498 }else{
499 $msg['success'] = 'Post Content was updated successfully!';
500 }
501
502 }else{
503 $msg['error'] = "Unable to update the Post Content for some reason";
504 }
505
506 echo json_encode($msg);
507 wp_die();
508
509 }
510
511 // Shortcodes Widget Handler
512 add_action('wp_ajax_pagelayer_do_shortcodes', 'pagelayer_do_shortcodes');
513 function pagelayer_do_shortcodes(){
514
515 // Some AJAX security
516 check_ajax_referer('pagelayer_ajax', 'nonce');
517
518 $data = '';
519 if(isset($_REQUEST['shortcode_data'])){
520 $data = stripslashes($_REQUEST['shortcode_data']);
521 }
522
523 echo do_shortcode($data);
524 wp_die();
525
526 }
527
528 // Get the Site Title
529 add_action('wp_ajax_pagelayer_fetch_site_title', 'pagelayer_fetch_site_title');
530 function pagelayer_fetch_site_title(){
531
532 // Some AJAX security
533 check_ajax_referer('pagelayer_ajax', 'nonce');
534
535 echo get_bloginfo('name');
536 wp_die();
537 }
538
539 // Update the Site Title
540 add_action('wp_ajax_pagelayer_update_site_title', 'pagelayer_update_site_title');
541 function pagelayer_update_site_title(){
542 global $wpdb;
543
544 // Some AJAX security
545 check_ajax_referer('pagelayer_ajax', 'nonce');
546
547 $site_title = $_POST['site_title'];
548
549 update_option('blogname', $site_title);
550
551 $wpdb->query("UPDATE `sm_sitemeta`
552 SET meta_value = '".$site_title."'
553 WHERE meta_key = 'site_name'");
554 wp_die();
555 }
556
557 // Show the SideBars
558 add_action('wp_ajax_pagelayer_fetch_sidebar', 'pagelayer_fetch_sidebar');
559 function pagelayer_fetch_sidebar(){
560
561 global $wp_registered_sidebars;
562
563 // Some AJAX security
564 check_ajax_referer('pagelayer_ajax', 'nonce');
565
566 // Create a list
567 $pagelayer_wp_widgets = array();
568
569 foreach($wp_registered_sidebars as $v){
570 $pagelayer_wp_widgets[$v['id']] = $v['name'];
571 }
572
573 $id = @$_REQUEST['sidebar'];
574
575 if(function_exists('dynamic_sidebar') && !empty($pagelayer_wp_widgets[$id])) {
576 ob_start();
577 dynamic_sidebar($id);
578 $result = ob_get_clean();
579 }else{
580 $result = 'No such Widget Area !';
581 }
582
583 echo $result;
584 wp_die();
585
586 }
587
588 // Show the primary menu !
589 add_action('wp_ajax_pagelayer_fetch_primary_menu', 'pagelayer_fetch_primary_menu');
590 function pagelayer_fetch_primary_menu(){
591
592 // Some AJAX security
593 check_ajax_referer('pagelayer_ajax', 'nonce');
594
595 echo wp_nav_menu( array(
596 'menu' => 'primary-menu',
597 'menu_id' => 'pagelayer-header-menu',
598 'theme_location' => 'primary',
599 'menu_class' => 'primary-menu',
600 ) );
601
602 wp_die();
603 }
604