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

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

575 lines 14.4 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.0');
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
223 }
224
225 // Load the google fonts
226 add_action('wp_footer', 'pagelayer_enqueue_fonts', 5);
227
228 function pagelayer_enqueue_fonts(){
229 global $pagelayer;
230
231 if(empty($pagelayer->cache['enqueue_frontend'])){
232 return;
233 }
234
235 $url = 'Open Sans:300italic,400italic,600italic,300,400,600&subset=latin,latin-ext';
236 //pagelayer_print($pagelayer->runtime_fonts);die('alpesh');
237
238 foreach($pagelayer->runtime_fonts as $font){
239 $url .= '|'.$font.':100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i';
240 }
241
242 //echo '<link href="https://fonts.googleapis.com/css?family='.$url.'" rel="stylesheet">';
243
244 wp_register_style('pagelayer-google-font', 'https://fonts.googleapis.com/css?family='.rawurlencode($url), array(), PAGELAYER_VERSION);
245 wp_enqueue_style('pagelayer-google-font');
246
247 }
248
249 // Load the live editor if needed
250 add_action('wp_enqueue_scripts', 'pagelayer_load_live', 9999);
251
252 function pagelayer_load_live(){
253
254 global $post;
255
256 // If its not live editing then stop
257 if(!pagelayer_is_live_iframe()){
258 return;
259 }
260
261 // Are you allowed to edit ?
262 if(!pagelayer_user_can_edit()){
263 return;
264 }
265
266 // Load the editor class
267 include_once(PAGELAYER_DIR.'/main/live.php');
268
269 // Call the constructor
270 $pl_editor = new PageLayer_LiveEditor();
271
272 }
273
274 // Show the backend editor options
275 add_action('edit_form_after_title', 'pagelayer_after_title');
276 function pagelayer_after_title(){
277
278 global $post;
279
280 // Get the current screen
281 $current_screen = get_current_screen();
282
283 // For gutenberg
284 if(method_exists($current_screen, 'is_block_editor') && $current_screen->is_block_editor()){
285
286 // Add the code in the footer
287 add_action('admin_footer', 'pagelayer_gutenberg_after_title');
288
289 return;
290 }
291
292 $link = pagelayer_shortlink($post->ID).'&pagelayer-live=1';
293
294 echo '
295 <div id="pagelayer-editor-button-row" style="margin-top:15px">
296 <a id="pagelayer-editor-button" href="'.$link.'" class="button button-primary button-large" style="height:auto; padding:6px; font-size:18px;">
297 <img src="'.PAGELAYER_URL.'/images/pagelayer-logo-40.png" align="top" width="24" /> <span>'.__('Edit with PageLayer').'</span>
298 </a>
299 </div>';
300
301 }
302
303 function pagelayer_gutenberg_after_title(){
304
305 global $post;
306
307 $link = pagelayer_shortlink($post->ID).'&pagelayer-live=1';
308
309 echo '
310 <div id="pagelayer-editor-button-row" style="margin-left:15px; display:none">
311 <a id="pagelayer-editor-button" href="'.$link.'" class="button button-primary button-large" style="height:auto; padding:6px; font-size:18px;">
312 <img src="'.PAGELAYER_URL.'/images/pagelayer-logo-40.png" align="top" width="24" /> <span>'.__('Edit with PageLayer').'</span>
313 </a>
314 </div>
315
316 <script type="text/javascript">
317 jQuery(document).ready(function(){
318
319 var pagelayer_timer;
320 var pagelayer_button = function(){
321 var button = jQuery("#pagelayer-editor-button-row");
322 var g = jQuery(".edit-post-header-toolbar");
323 if(g.length < 1){
324 return;
325 }
326 button.detach();
327 //console.log(button);
328 g.append(button);
329 button.show();
330 clearInterval(pagelayer_timer);
331 }
332 pagelayer_timer = setInterval(pagelayer_button, 100);
333 });
334 </script>';
335
336 }
337
338 add_filter( 'post_row_actions', 'pagelayer_quick_link', 10, 2 );
339 add_filter( 'page_row_actions', 'pagelayer_quick_link', 10, 2 );
340 function pagelayer_quick_link($actions, $post){
341 $link = pagelayer_shortlink($post->ID).'&pagelayer-live=1';
342
343 $actions['pagelayer'] = '<a href="'.esc_url( $link ).'">'.__( 'Edit using PageLayer', 'pagelayer') .'</a>';
344
345 return $actions;
346 }
347
348 // The ajax handler
349 add_action('wp_ajax_pagelayer_wp_widget', 'pagelayer_wp_widget_ajax');
350 function pagelayer_wp_widget_ajax(){
351
352 global $pagelayer;
353
354 // Some AJAX security
355 check_ajax_referer('pagelayer_ajax', 'nonce');
356
357 pagelayer_load_shortcodes();
358
359 header('Content-Type: application/json');
360
361 $ret = [];
362 $tag = @$_POST['tag'];
363 //pagelayer_print($pagelayer->shortcodes[$tag]);
364
365 // No tag ?
366 if(empty($pagelayer->shortcodes[$tag])){
367 $ret['error'][] = 'No Tag';
368 echo json_encode($ret);
369 wp_die();
370 }
371
372 // Include the widgets
373 include_once(ABSPATH . 'wp-admin/includes/widgets.php');
374
375 $class = $pagelayer->shortcodes[$tag]['widget'];
376
377 // Check the widget class exists ?
378 if(empty($class) || !class_exists($class)){
379 $ret['error'][] = 'No Widget Class';
380 echo json_encode($ret);
381 wp_die();
382 }
383
384 $instance = [];
385 $widget = new $class();
386 $widget->_set('pagelayer-widget-1234567890');
387
388 // Is there any existing data ?
389 if(!empty($_POST['widget_data'])){
390 $json = json_decode(stripslashes($_POST['widget_data']), true);
391 //pagelayer_print($json);die();
392 if(!empty($json)){
393 $instance = $json;
394 }
395 }
396
397 // Are there any form values ?
398 if(!empty($_POST['values'])){
399 parse_str(stripslashes($_POST['values']), $data);
400 //pagelayer_print($data);die();
401
402 // Any data ?
403 if(!empty($data)){
404
405 // First key is useless
406 $data = current($data);
407
408 // Do we still have valid data ?
409 if(!empty($data)){
410
411 // 2nd key is useless and just over-ride instance
412 $instance = current($data);
413
414 }
415 }
416 }
417
418 // Get the form
419 ob_start();
420 $widget->form($instance);
421 $ret['form'] = ob_get_contents();
422 ob_end_clean();
423
424 // Get the html
425 ob_start();
426 $widget->widget([], $instance);
427 $ret['html'] = ob_get_contents();
428 ob_end_clean();
429
430 // Widget data to set
431 if(!empty($instance)){
432 $ret['widget_data'] = $instance;
433 }
434
435 echo json_encode($ret);
436 wp_die();
437
438 }
439
440 // Update Post content
441 add_action('wp_ajax_pagelayer_save_content', 'pagelayer_save_content');
442 function pagelayer_save_content(){
443
444 // Some AJAX security
445 check_ajax_referer('pagelayer_ajax', 'nonce');
446
447 $content = $_POST['pagelayer_update_content'];
448
449 $postID = (int) $_GET['postID'];
450
451 if(empty($postID)){
452 $msg['error'] = 'Invalid post ID';
453 }
454
455 // Check if the post exists
456
457 if(!empty($postID) && !empty($content)){
458
459 $post = array(
460 'ID' => $postID,
461 'post_content' => $content,
462 );
463
464 // Update the post into the database
465 wp_update_post($post);
466
467 if (is_wp_error($postID)) {
468 $msg['error'] = 'Unable to update the Post Content for some reason';
469 }else{
470 $msg['success'] = 'Post Content was updated successfully!';
471 }
472
473 }else{
474 $msg['error'] = "Unable to update the Post Content for some reason";
475 }
476
477 echo json_encode($msg);
478 wp_die();
479
480 }
481
482 // Shortcodes Widget Handler
483 add_action('wp_ajax_pagelayer_do_shortcodes', 'pagelayer_do_shortcodes');
484 function pagelayer_do_shortcodes(){
485
486 // Some AJAX security
487 check_ajax_referer('pagelayer_ajax', 'nonce');
488
489 $data = '';
490 if(isset($_REQUEST['shortcode_data'])){
491 $data = stripslashes($_REQUEST['shortcode_data']);
492 }
493
494 echo do_shortcode($data);
495 wp_die();
496
497 }
498
499 // Get the Site Title
500 add_action('wp_ajax_pagelayer_fetch_site_title', 'pagelayer_fetch_site_title');
501 function pagelayer_fetch_site_title(){
502
503 // Some AJAX security
504 check_ajax_referer('pagelayer_ajax', 'nonce');
505
506 echo get_bloginfo('name');
507 wp_die();
508 }
509
510 // Update the Site Title
511 add_action('wp_ajax_pagelayer_update_site_title', 'pagelayer_update_site_title');
512 function pagelayer_update_site_title(){
513 global $wpdb;
514
515 // Some AJAX security
516 check_ajax_referer('pagelayer_ajax', 'nonce');
517
518 $site_title = $_POST['site_title'];
519
520 update_option('blogname', $site_title);
521
522 $wpdb->query("UPDATE `sm_sitemeta`
523 SET meta_value = '".$site_title."'
524 WHERE meta_key = 'site_name'");
525 wp_die();
526 }
527
528 // Show the SideBars
529 add_action('wp_ajax_pagelayer_fetch_sidebar', 'pagelayer_fetch_sidebar');
530 function pagelayer_fetch_sidebar(){
531
532 global $wp_registered_sidebars;
533
534 // Some AJAX security
535 check_ajax_referer('pagelayer_ajax', 'nonce');
536
537 // Create a list
538 $pagelayer_wp_widgets = array();
539
540 foreach($wp_registered_sidebars as $v){
541 $pagelayer_wp_widgets[$v['id']] = $v['name'];
542 }
543
544 $id = @$_REQUEST['sidebar'];
545
546 if(function_exists('dynamic_sidebar') && !empty($pagelayer_wp_widgets[$id])) {
547 ob_start();
548 dynamic_sidebar($id);
549 $result = ob_get_clean();
550 }else{
551 $result = 'No such Widget Area !';
552 }
553
554 echo $result;
555 wp_die();
556
557 }
558
559 // Show the primary menu !
560 add_action('wp_ajax_pagelayer_fetch_primary_menu', 'pagelayer_fetch_primary_menu');
561 function pagelayer_fetch_primary_menu(){
562
563 // Some AJAX security
564 check_ajax_referer('pagelayer_ajax', 'nonce');
565
566 echo wp_nav_menu( array(
567 'menu' => 'primary-menu',
568 'menu_id' => 'pagelayer-header-menu',
569 'theme_location' => 'primary',
570 'menu_class' => 'primary-menu',
571 ) );
572
573 wp_die();
574 }
575