PluginProbe
Page Builder: Pagelayer – Drag and Drop website builder / 0.9.1
Page Builder: Pagelayer – Drag and Drop website builder v0.9.1
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.1, at init.php

594 lines 15.0 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.1');
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 }
102
103 // This adds the left menu in WordPress Admin page
104 add_action('admin_menu', 'pagelayer_admin_menu');
105
106 // Shows the admin menu of Pagelayer
107 function pagelayer_admin_menu() {
108
109 global $wp_version, $pagelayer;
110
111 $capability = 'activate_plugins';// TODO : Capability for accessing this page
112
113 // Add the menu page
114 add_menu_page(__('PageLayer Editor'), __('PageLayer'), $capability, 'pagelayer', 'pagelayer_page_handler', PAGELAYER_URL.'/images/pagelayer-logo-19.png');
115
116 // Settings Page
117 add_submenu_page('pagelayer', __('PageLayer Editor'), __('Settings'), $capability, 'pagelayer', 'pagelayer_page_handler');
118
119 // Its premium
120 if(defined('PAGELAYER_PREMIUM')){
121
122 // Fonts link
123 add_submenu_page('pagelayer', __('PageLayer Font Settings'), __('PageLayer Font Settings'), $capability, 'pagelayer_fonts', 'pagelayer_page_fonts');
124
125 // Its free
126 }else{
127
128 // Go Pro link
129 add_submenu_page('pagelayer', __('PageLayer Go Pro'), __('Go Pro'), $capability, PAGELAYER_PRO_URL);
130
131 }
132
133 }
134
135 // This function will handle the pages in Pages in PageLayer
136 function pagelayer_page_handler(){
137
138 global $wp_version, $pagelayer;
139
140 include_once(PAGELAYER_DIR.'/main/settings.php');
141
142 // Handle fonts
143 if($pagelayer->action == 'fonts-manager'){
144 include_once(PAGELAYER_DIR.'/main/fonts.php');
145 }
146
147 }
148
149 // Enqueue JS and CSS in Admin Panel for settings
150 add_action( 'admin_enqueue_scripts', 'pagelayer_admin_script' );
151 function pagelayer_admin_script() {
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
156 // Load the Live Body
157 add_action('template_redirect', 'pagelayer_load_live_body', 4);
158
159 function pagelayer_load_live_body(){
160
161 global $post;
162
163 // If its not live editing then stop
164 if(!pagelayer_is_live()){
165 return;
166 }
167
168 // If its the iFRAME then return
169 if(pagelayer_is_live_iframe()){
170 return;
171 }
172
173 // Are you allowed to edit ?
174 if(!pagelayer_user_can_edit()){
175 return;
176 }
177
178 // Load the editor live body
179 include_once(PAGELAYER_DIR.'/main/live-body.php');
180
181 pagelayer_live_body();
182
183 }
184
185 // Add the JS and CSS for Posts and Pages when being viewed ONLY if there is our content called
186 add_action('template_redirect', 'pagelayer_enqueue_frontend', 5);
187
188 function pagelayer_enqueue_frontend($force = false){
189
190 global $post, $pagelayer;
191
192 if(!empty($pagelayer->cache['enqueue_frontend'])){
193 return;
194 }
195
196 if(empty($post->ID)){
197 return;
198 }
199
200 // Enqueue the FRONTEND CSS
201 if(get_post_meta($post->ID , 'pagelayer-data') || $force){
202
203 // We dont need the auto <p> and <br> as they interfere with us
204 remove_filter('the_content', 'wpautop');
205
206 // No need to add curly codes to the content
207 remove_filter('the_content', 'wptexturize');
208
209 pagelayer_load_shortcodes();
210 $pagelayer->cache['enqueue_frontend'] = true;
211
212 // Enqueue our Editor's Frontend JS
213 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);
214 wp_enqueue_script('pagelayer-frontend');
215
216 wp_register_style('pagelayer-frontend', PAGELAYER_CSS.'/givecss.php?give=pagelayer-frontend.css,nivo-lightbox.css,slippry.css,animate.min.css', array(), PAGELAYER_VERSION);
217 wp_enqueue_style('pagelayer-frontend');
218
219 wp_register_style('font-awesome', PAGELAYER_CSS.'/font-awesome.min.css', array(), PAGELAYER_VERSION);
220 wp_enqueue_style('font-awesome');
221
222 // Load the global styles
223 add_action('wp_head', 'pagelayer_global_styles', 5);
224
225 }
226
227 }
228
229 // Load the google fonts
230 add_action('wp_footer', 'pagelayer_enqueue_fonts', 5);
231
232 function pagelayer_enqueue_fonts(){
233 global $pagelayer;
234
235 if(empty($pagelayer->cache['enqueue_frontend'])){
236 return;
237 }
238
239 $url = 'Open Sans:300italic,400italic,600italic,300,400,600&subset=latin,latin-ext';
240 //pagelayer_print($pagelayer->runtime_fonts);die('alpesh');
241
242 foreach($pagelayer->runtime_fonts as $font){
243 $url .= '|'.$font.':100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i';
244 }
245
246 //echo '<link href="https://fonts.googleapis.com/css?family='.$url.'" rel="stylesheet">';
247
248 wp_register_style('pagelayer-google-font', 'https://fonts.googleapis.com/css?family='.rawurlencode($url), array(), PAGELAYER_VERSION);
249 wp_enqueue_style('pagelayer-google-font');
250
251 }
252
253 // We need to handle global styles
254 function pagelayer_global_styles(){
255
256 $styles = '<style id="pagelayer-global-styles" type="text/css">';
257 if(get_option('pagelayer_content_width')){
258 $styles .= '.pagelayer-row-holder{ max-width: '.get_option('pagelayer_content_width').'px;}';
259 }else{
260 $styles .= '.pagelayer-row-holder{ max-width: 1170px;}';
261 }
262 $styles .= '.pagelayer-row-holder{ margin-left: auto; margin-right: auto;}';
263 $styles .= '</style>';
264
265 echo $styles;
266 }
267
268 // Load the live editor if needed
269 add_action('wp_enqueue_scripts', 'pagelayer_load_live', 9999);
270
271 function pagelayer_load_live(){
272
273 global $post;
274
275 // If its not live editing then stop
276 if(!pagelayer_is_live_iframe()){
277 return;
278 }
279
280 // Are you allowed to edit ?
281 if(!pagelayer_user_can_edit()){
282 return;
283 }
284
285 // Load the editor class
286 include_once(PAGELAYER_DIR.'/main/live.php');
287
288 // Call the constructor
289 $pl_editor = new PageLayer_LiveEditor();
290
291 }
292
293 // Show the backend editor options
294 add_action('edit_form_after_title', 'pagelayer_after_title');
295 function pagelayer_after_title(){
296
297 global $post;
298
299 // Get the current screen
300 $current_screen = get_current_screen();
301
302 // For gutenberg
303 if(method_exists($current_screen, 'is_block_editor') && $current_screen->is_block_editor()){
304
305 // Add the code in the footer
306 add_action('admin_footer', 'pagelayer_gutenberg_after_title');
307
308 return;
309 }
310
311 $link = pagelayer_shortlink($post->ID).'&pagelayer-live=1';
312
313 echo '
314 <div id="pagelayer-editor-button-row" style="margin-top:15px">
315 <a id="pagelayer-editor-button" href="'.$link.'" class="button button-primary button-large" style="height:auto; padding:6px; font-size:18px;">
316 <img src="'.PAGELAYER_URL.'/images/pagelayer-logo-40.png" align="top" width="24" /> <span>'.__('Edit with PageLayer').'</span>
317 </a>
318 </div>';
319
320 }
321
322 function pagelayer_gutenberg_after_title(){
323
324 global $post;
325
326 $link = pagelayer_shortlink($post->ID).'&pagelayer-live=1';
327
328 echo '
329 <div id="pagelayer-editor-button-row" style="margin-left:15px; display:none">
330 <a id="pagelayer-editor-button" href="'.$link.'" class="button button-primary button-large" style="height:auto; padding:6px; font-size:18px;">
331 <img src="'.PAGELAYER_URL.'/images/pagelayer-logo-40.png" align="top" width="24" /> <span>'.__('Edit with PageLayer').'</span>
332 </a>
333 </div>
334
335 <script type="text/javascript">
336 jQuery(document).ready(function(){
337
338 var pagelayer_timer;
339 var pagelayer_button = function(){
340 var button = jQuery("#pagelayer-editor-button-row");
341 var g = jQuery(".edit-post-header-toolbar");
342 if(g.length < 1){
343 return;
344 }
345 button.detach();
346 //console.log(button);
347 g.append(button);
348 button.show();
349 clearInterval(pagelayer_timer);
350 }
351 pagelayer_timer = setInterval(pagelayer_button, 100);
352 });
353 </script>';
354
355 }
356
357 add_filter( 'post_row_actions', 'pagelayer_quick_link', 10, 2 );
358 add_filter( 'page_row_actions', 'pagelayer_quick_link', 10, 2 );
359 function pagelayer_quick_link($actions, $post){
360 $link = pagelayer_shortlink($post->ID).'&pagelayer-live=1';
361
362 $actions['pagelayer'] = '<a href="'.esc_url( $link ).'">'.__( 'Edit using PageLayer', 'pagelayer') .'</a>';
363
364 return $actions;
365 }
366
367 // The ajax handler
368 add_action('wp_ajax_pagelayer_wp_widget', 'pagelayer_wp_widget_ajax');
369 function pagelayer_wp_widget_ajax(){
370
371 global $pagelayer;
372
373 // Some AJAX security
374 check_ajax_referer('pagelayer_ajax', 'nonce');
375
376 pagelayer_load_shortcodes();
377
378 header('Content-Type: application/json');
379
380 $ret = [];
381 $tag = @$_POST['tag'];
382 //pagelayer_print($pagelayer->shortcodes[$tag]);
383
384 // No tag ?
385 if(empty($pagelayer->shortcodes[$tag])){
386 $ret['error'][] = 'No Tag';
387 echo json_encode($ret);
388 wp_die();
389 }
390
391 // Include the widgets
392 include_once(ABSPATH . 'wp-admin/includes/widgets.php');
393
394 $class = $pagelayer->shortcodes[$tag]['widget'];
395
396 // Check the widget class exists ?
397 if(empty($class) || !class_exists($class)){
398 $ret['error'][] = 'No Widget Class';
399 echo json_encode($ret);
400 wp_die();
401 }
402
403 $instance = [];
404 $widget = new $class();
405 $widget->_set('pagelayer-widget-1234567890');
406
407 // Is there any existing data ?
408 if(!empty($_POST['widget_data'])){
409 $json = json_decode(stripslashes($_POST['widget_data']), true);
410 //pagelayer_print($json);die();
411 if(!empty($json)){
412 $instance = $json;
413 }
414 }
415
416 // Are there any form values ?
417 if(!empty($_POST['values'])){
418 parse_str(stripslashes($_POST['values']), $data);
419 //pagelayer_print($data);die();
420
421 // Any data ?
422 if(!empty($data)){
423
424 // First key is useless
425 $data = current($data);
426
427 // Do we still have valid data ?
428 if(!empty($data)){
429
430 // 2nd key is useless and just over-ride instance
431 $instance = current($data);
432
433 }
434 }
435 }
436
437 // Get the form
438 ob_start();
439 $widget->form($instance);
440 $ret['form'] = ob_get_contents();
441 ob_end_clean();
442
443 // Get the html
444 ob_start();
445 $widget->widget([], $instance);
446 $ret['html'] = ob_get_contents();
447 ob_end_clean();
448
449 // Widget data to set
450 if(!empty($instance)){
451 $ret['widget_data'] = $instance;
452 }
453
454 echo json_encode($ret);
455 wp_die();
456
457 }
458
459 // Update Post content
460 add_action('wp_ajax_pagelayer_save_content', 'pagelayer_save_content');
461 function pagelayer_save_content(){
462
463 // Some AJAX security
464 check_ajax_referer('pagelayer_ajax', 'nonce');
465
466 $content = $_POST['pagelayer_update_content'];
467
468 $postID = (int) $_GET['postID'];
469
470 if(empty($postID)){
471 $msg['error'] = 'Invalid post ID';
472 }
473
474 // Check if the post exists
475
476 if(!empty($postID) && !empty($content)){
477
478 $post = array(
479 'ID' => $postID,
480 'post_content' => $content,
481 );
482
483 // Update the post into the database
484 wp_update_post($post);
485
486 if (is_wp_error($postID)) {
487 $msg['error'] = 'Unable to update the Post Content for some reason';
488 }else{
489 $msg['success'] = 'Post Content was updated successfully!';
490 }
491
492 }else{
493 $msg['error'] = "Unable to update the Post Content for some reason";
494 }
495
496 echo json_encode($msg);
497 wp_die();
498
499 }
500
501 // Shortcodes Widget Handler
502 add_action('wp_ajax_pagelayer_do_shortcodes', 'pagelayer_do_shortcodes');
503 function pagelayer_do_shortcodes(){
504
505 // Some AJAX security
506 check_ajax_referer('pagelayer_ajax', 'nonce');
507
508 $data = '';
509 if(isset($_REQUEST['shortcode_data'])){
510 $data = stripslashes($_REQUEST['shortcode_data']);
511 }
512
513 echo do_shortcode($data);
514 wp_die();
515
516 }
517
518 // Get the Site Title
519 add_action('wp_ajax_pagelayer_fetch_site_title', 'pagelayer_fetch_site_title');
520 function pagelayer_fetch_site_title(){
521
522 // Some AJAX security
523 check_ajax_referer('pagelayer_ajax', 'nonce');
524
525 echo get_bloginfo('name');
526 wp_die();
527 }
528
529 // Update the Site Title
530 add_action('wp_ajax_pagelayer_update_site_title', 'pagelayer_update_site_title');
531 function pagelayer_update_site_title(){
532 global $wpdb;
533
534 // Some AJAX security
535 check_ajax_referer('pagelayer_ajax', 'nonce');
536
537 $site_title = $_POST['site_title'];
538
539 update_option('blogname', $site_title);
540
541 $wpdb->query("UPDATE `sm_sitemeta`
542 SET meta_value = '".$site_title."'
543 WHERE meta_key = 'site_name'");
544 wp_die();
545 }
546
547 // Show the SideBars
548 add_action('wp_ajax_pagelayer_fetch_sidebar', 'pagelayer_fetch_sidebar');
549 function pagelayer_fetch_sidebar(){
550
551 global $wp_registered_sidebars;
552
553 // Some AJAX security
554 check_ajax_referer('pagelayer_ajax', 'nonce');
555
556 // Create a list
557 $pagelayer_wp_widgets = array();
558
559 foreach($wp_registered_sidebars as $v){
560 $pagelayer_wp_widgets[$v['id']] = $v['name'];
561 }
562
563 $id = @$_REQUEST['sidebar'];
564
565 if(function_exists('dynamic_sidebar') && !empty($pagelayer_wp_widgets[$id])) {
566 ob_start();
567 dynamic_sidebar($id);
568 $result = ob_get_clean();
569 }else{
570 $result = 'No such Widget Area !';
571 }
572
573 echo $result;
574 wp_die();
575
576 }
577
578 // Show the primary menu !
579 add_action('wp_ajax_pagelayer_fetch_primary_menu', 'pagelayer_fetch_primary_menu');
580 function pagelayer_fetch_primary_menu(){
581
582 // Some AJAX security
583 check_ajax_referer('pagelayer_ajax', 'nonce');
584
585 echo wp_nav_menu( array(
586 'menu' => 'primary-menu',
587 'menu_id' => 'pagelayer-header-menu',
588 'theme_location' => 'primary',
589 'menu_class' => 'primary-menu',
590 ) );
591
592 wp_die();
593 }
594