PluginProbe
Page Builder: Pagelayer – Drag and Drop website builder / 1.0.4
Page Builder: Pagelayer – Drag and Drop website builder v1.0.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 1.0.4, at init.php

537 lines 15.8 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(PAGELAYER_FILE));
7 define('PAGELAYER_PRO_BASE', 'pagelayer-pro/pagelayer-pro.php');
8 define('PAGELAYER_VERSION', '1.0.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/pricing?from=plugin');
15 define('PAGELAYER_WWW_URL', 'https://pagelayer.com/');
16 define('PAGELAYER_DOCS', 'https://pagelayer.com/docs/');
17 define('PAGELAYER_API', 'https://api.pagelayer.com/');
18 define('PAGELAYER_SC_PREFIX', 'pl');
19 define('PAGELAYER_YOUTUBE_BG', 'https://www.youtube.com/watch?v=Csa6rvCWmLU');
20 @define('PAGELAYER_BRAND_TEXT', 'Pagelayer');
21 @define('PAGELAYER_LOGO', PAGELAYER_URL.'/images/pagelayer-logo-40.png');
22
23 include_once(PAGELAYER_DIR.'/main/functions.php');
24 include_once(PAGELAYER_DIR.'/main/class.php');
25
26 // Ok so we are now ready to go
27 register_activation_hook(PAGELAYER_FILE, 'pagelayer_activation');
28
29 // Is called when the ADMIN enables the plugin
30 function pagelayer_activation(){
31
32 global $wpdb;
33
34 $sql = array();
35
36 /*$sql[] = "DROP TABLE IF EXISTS `".$wpdb->prefix."pagelayer_logs`";
37
38 foreach($sql as $sk => $sv){
39 $wpdb->query($sv);
40 }*/
41
42 add_option('pagelayer_version', PAGELAYER_VERSION);
43 add_option('pagelayer_options', array());
44
45 }
46
47 // Checks if we are to update ?
48 function pagelayer_update_check(){
49
50 global $wpdb;
51
52 $sql = array();
53 $current_version = get_option('pagelayer_version');
54 $version = (int) str_replace('.', '', $current_version);
55
56 // No update required
57 if($current_version == PAGELAYER_VERSION){
58 return true;
59 }
60
61 // Is it first run ?
62 if(empty($current_version)){
63
64 // Reinstall
65 pagelayer_activation();
66
67 // Trick the following if conditions to not run
68 $version = (int) str_replace('.', '', PAGELAYER_VERSION);
69
70 }
71
72 // Save the new Version
73 update_option('pagelayer_version', PAGELAYER_VERSION);
74
75 }
76
77 // Add the action to load the plugin
78 add_action('plugins_loaded', 'pagelayer_load_plugin');
79
80 // The function that will be called when the plugin is loaded
81 function pagelayer_load_plugin(){
82
83 global $pagelayer;
84
85 // Check if the installed version is outdated
86 pagelayer_update_check();
87
88 // Set the array
89 $pagelayer = new PageLayer();
90
91 // Load license
92 pagelayer_load_license();
93
94 // Is there any ACTION set ?
95 $pagelayer->action = pagelayer_optreq('pagelayer-action');
96
97 // Load settings
98 $options = get_option('pagelayer_options');
99 $pagelayer->settings['post_types'] = empty($options['post_types']) ? array('post', 'page') : $options['post_types'];
100 $pagelayer->settings['css_code'] = empty($options['css_code']) ? '' : $options['css_code'];
101 $pagelayer->settings['animate'] = empty($options['animate']) ? '' : $options['animate'];
102 $pagelayer->settings['max_width'] = empty($options['max_width']) ? 1170 : $options['max_width'];
103
104 // Load the language
105 load_plugin_textdomain('pagelayer', false, PAGELAYER_SLUG.'/languages/');
106
107 // Show the promo
108 pagelayer_maybe_promo([
109 'after' => 1,// In days
110 'interval' => 30,// In days
111 'pro_url' => PAGELAYER_PRO_URL,
112 'rating' => 'https://wordpress.org/plugins/pagelayer/#reviews',
113 'twitter' => 'https://twitter.com/pagelayer?status='.rawurlencode('I love #Pagelayer Site Builder by @pagelayer team for my #WordPress site - '.home_url()),
114 'facebook' => 'https://www.facebook.com/pagelayer',
115 'website' => PAGELAYER_WWW_URL,
116 'image' => PAGELAYER_URL.'/images/pagelayer-logo-256.png'
117 ]);
118
119 // Its premium
120 if(defined('PAGELAYER_PREMIUM')){
121
122 // Check for updates
123 include_once(PAGELAYER_DIR.'/main/plugin-update-checker.php');
124 $pagelayer_updater = Pagelayer_PucFactory::buildUpdateChecker(PAGELAYER_API.'updates.php?version='.PAGELAYER_VERSION, PAGELAYER_FILE);
125
126 // Add the license key to query arguments
127 $pagelayer_updater->addQueryArgFilter('pagelayer_updater_filter_args');
128
129 // Show the text to install the license key
130 add_filter('puc_manual_final_check_link-pagelayer-pro', 'pagelayer_updater_check_link', 10, 1);
131
132 // Load the template builder
133 include_once(PAGELAYER_DIR.'/main/template-builder.php');
134 }
135
136 }
137
138 // Add our license key if ANY
139 function pagelayer_updater_filter_args($queryArgs) {
140
141 global $pagelayer;
142
143 if ( !empty($pagelayer->license['license']) ) {
144 $queryArgs['license'] = $pagelayer->license['license'];
145 }
146
147 return $queryArgs;
148 }
149
150 // Handle the Check for update link and ask to install license key
151 function pagelayer_updater_check_link($final_link){
152
153 global $pagelayer;
154
155 if(empty($pagelayer->license['license'])){
156 return '<a href="'.admin_url('admin.php?page=pagelayer_license').'">Install Pagelayer Pro License Key</a>';
157 }
158
159 return $final_link;
160 }
161
162 // This adds the left menu in WordPress Admin page
163 add_action('admin_menu', 'pagelayer_admin_menu', 5);
164
165 // Shows the admin menu of Pagelayer
166 function pagelayer_admin_menu() {
167
168 global $wp_version, $pagelayer;
169
170 $capability = 'activate_plugins';// TODO : Capability for accessing this page
171
172 // Add the menu page
173 add_menu_page(__('Pagelayer Editor'), __('Pagelayer'), $capability, 'pagelayer', 'pagelayer_page_handler', PAGELAYER_URL.'/images/pagelayer-logo-19.png');
174
175 // Settings Page
176 add_submenu_page('pagelayer', __('Pagelayer Editor'), __('Settings'), $capability, 'pagelayer', 'pagelayer_page_handler');
177
178 // Its premium
179 if(defined('PAGELAYER_PREMIUM')){
180
181 // Fonts link
182 add_submenu_page('pagelayer', __('Font Settings'), __('Font Settings'), $capability, 'admin.php?page=pagelayer#settings');
183
184 // Add new template
185 add_submenu_page('pagelayer', __('Theme Templates'), __('Theme Templates'), $capability, 'edit.php?post_type=pagelayer-template');
186
187 // Add new template Link
188 //add_submenu_page('pagelayer', __('Add New Template'), __('Add New Template'), $capability, 'edit.php?post_type=pagelayer-template#new');
189
190 // Add new template
191 add_submenu_page('pagelayer', __('Add New Template'), __('Add New Template'), $capability, 'pagelayer_template_wizard', 'pagelayer_builder_template_wizard');
192
193 // Export Template Wizard
194 add_submenu_page('pagelayer', __('Export Templates into a Theme'), __('Export Templates'), $capability, 'pagelayer_template_export', 'pagelayer_builder_export');
195
196 // Its free
197 }else{
198
199 // Go Pro link
200 add_submenu_page('pagelayer', __('Pagelayer Go Pro'), __('Go Pro'), $capability, PAGELAYER_PRO_URL);
201
202 }
203
204 // License Page
205 add_submenu_page('pagelayer', __('Pagelayer Editor'), __('License'), $capability, 'pagelayer_license', 'pagelayer_license_page');
206
207 }
208
209 // This function will handle the Settings Pages in PageLayer
210 function pagelayer_page_handler(){
211
212 global $wp_version, $pagelayer;
213
214 wp_enqueue_script( 'pagelayer-admin', PAGELAYER_JS.'/pagelayer-admin.js', array('jquery'), PAGELAYER_VERSION);
215 wp_enqueue_style( 'pagelayer-admin', PAGELAYER_CSS.'/pagelayer-admin.css', array(), PAGELAYER_VERSION);
216
217 include_once(PAGELAYER_DIR.'/main/settings.php');
218
219 pagelayer_settings_page();
220
221 }
222
223 // This function will handle the Settings Pages in PageLayer
224 function pagelayer_license_page(){
225
226 global $wp_version, $pagelayer;
227
228 include_once(PAGELAYER_DIR.'/main/license.php');
229
230 pagelayer_license();
231
232 }
233
234 // Load the Live Body
235 add_action('template_redirect', 'pagelayer_load_live_body', 4);
236
237 function pagelayer_load_live_body(){
238
239 global $post;
240
241 // If its not live editing then stop
242 if(!pagelayer_is_live()){
243 return;
244 }
245
246 // If its the iFRAME then return
247 if(pagelayer_is_live_iframe()){
248 return;
249 }
250
251 // Are you allowed to edit ?
252 if(!pagelayer_user_can_edit()){
253 return;
254 }
255
256 // Load the editor live body
257 include_once(PAGELAYER_DIR.'/main/live-body.php');
258
259 pagelayer_live_body();
260
261 }
262
263 // Add the JS and CSS for Posts and Pages when being viewed ONLY if there is our content called
264 add_action('template_redirect', 'pagelayer_enqueue_frontend', 5);
265
266 function pagelayer_enqueue_frontend($force = false){
267
268 global $post, $pagelayer;
269
270 if(!empty($pagelayer->cache['enqueue_frontend'])){
271 return;
272 }
273
274 if(empty($post->ID) && empty($force)){
275 return;
276 }
277
278 $is_pagelayer = false;
279 $is_audio = false;
280
281 // This IF is for Archives mainly as $post->ID is only the first post in the archive
282 // and we need to make sure that other posts are pagelayer or not
283 if(!empty($GLOBALS['wp_query']->posts) && is_array($GLOBALS['wp_query']->posts)){
284 foreach($GLOBALS['wp_query']->posts as $v){
285 if(get_post_meta($v->ID , 'pagelayer-data')){
286 $is_pagelayer = true;
287 }
288
289 if(preg_match('/\[pl_audio/is', $v->post_content)){
290 $is_audio = true;
291 }
292 }
293 }
294
295 // Enqueue the FRONTEND CSS
296 if(get_post_meta($post->ID , 'pagelayer-data') || $is_pagelayer || $force){
297
298 // We dont need the auto <p> and <br> as they interfere with us
299 remove_filter('the_content', 'wpautop');
300
301 // No need to add curly codes to the content
302 remove_filter('the_content', 'wptexturize');
303
304 pagelayer_load_shortcodes();
305 $pagelayer->cache['enqueue_frontend'] = true;
306
307 // Load the global styles
308 add_action('wp_head', 'pagelayer_global_js', 2);
309
310 $premium_js = '';
311 $premium_css = '';
312 if(defined('PAGELAYER_PREMIUM')){
313 $premium_js = ',chart.min.js,slick.min.js,premium-frontend.js';
314 $premium_css = ',slick.css,slick-theme.css,premium-frontend.css';
315
316 // Load this For audio widget
317 if($is_audio || pagelayer_is_live_iframe()){
318 wp_enqueue_script('wp-mediaelement');
319 wp_enqueue_style( 'wp-mediaelement' );
320 }
321 }
322
323 // Enqueue our Editor's Frontend JS
324 wp_register_script('pagelayer-frontend', PAGELAYER_JS.'/givejs.php?give=pagelayer-frontend.js,nivo-lightbox.min.js,wow.min.js,jquery-numerator.js,simpleParallax.min.js,owl.carousel.min.js'.$premium_js, array('jquery'), PAGELAYER_VERSION);
325 wp_enqueue_script('pagelayer-frontend');
326
327 wp_register_style('pagelayer-frontend', PAGELAYER_CSS.'/givecss.php?give=pagelayer-frontend.css,nivo-lightbox.css,animate.min.css,owl.carousel.min.css,owl.theme.default.min.css'.$premium_css, array(), PAGELAYER_VERSION);
328 wp_enqueue_style('pagelayer-frontend');
329
330 // Get list of enabled icons
331 $icons = pagelayer_enabled_icons();
332 foreach($icons as $icon){
333 wp_register_style($icon, PAGELAYER_CSS.'/givecss.php?give='.$icon.'.min.css', array(), PAGELAYER_VERSION);
334 wp_enqueue_style($icon);
335 }
336
337 // Load the global styles
338 add_action('wp_head', 'pagelayer_global_styles', 5);
339
340 // Load custom widgets
341 do_action('pagelayer_custom_frontend_enqueue');
342
343 }
344
345 }
346
347 // Load the google fonts
348 add_action('wp_footer', 'pagelayer_enqueue_fonts', 5);
349
350 function pagelayer_enqueue_fonts(){
351 global $pagelayer;
352
353 if(empty($pagelayer->cache['enqueue_frontend'])){
354 return;
355 }
356
357 $url = 'Open Sans:300italic,400italic,600italic,300,400,600&subset=latin,latin-ext';
358 //pagelayer_print($pagelayer->runtime_fonts);die('alpesh');
359
360 foreach($pagelayer->runtime_fonts as $font){
361 $url .= '|'.$font.':100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i';
362 }
363
364 // Fetch body font if given
365 if(get_option('pagelayer_body_font')){
366 $url .= '|'.get_option('pagelayer_body_font').':100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i';
367 }
368
369 //echo '<link href="https://fonts.googleapis.com/css?family='.$url.'" rel="stylesheet">';
370
371 wp_register_style('pagelayer-google-font', 'https://fonts.googleapis.com/css?family='.rawurlencode($url), array(), PAGELAYER_VERSION);
372 wp_enqueue_style('pagelayer-google-font');
373
374 }
375
376 // Load any header we have
377 function pagelayer_global_js(){
378
379 echo '<script>
380 var pagelayer_ajaxurl = "'.admin_url( 'admin-ajax.php' ).'?";
381 var pagelayer_ajax_nonce = "'.wp_create_nonce('pagelayer_ajax').'";
382 var pagelayer_server_time = '.time().';
383 var pagelayer_facebook_id = "'.get_option('pagelayer-fbapp-id').'";
384 </script>';
385
386 }
387
388 // We need to handle global styles
389 function pagelayer_global_styles(){
390
391 $styles = '<style id="pagelayer-global-styles" type="text/css">';
392
393 $width = get_option('pagelayer_content_width', '1170');
394
395 // Style for only child row holder
396 $styles .= '.pagelayer-row-stretch-auto > .pagelayer-row-holder, .pagelayer-row-stretch-full > .pagelayer-row-holder.pagelayer-width-auto{ max-width: '.$width.'px; margin-left: auto; margin-right: auto;}';
397
398 if(get_option('pagelayer_body_font')){
399 $styles .= 'body *{font-family:'.get_option("pagelayer_body_font").';}';
400 }
401
402 $styles .= '</style>';
403
404 echo $styles;
405 }
406
407 // Load the live editor if needed
408 add_action('wp_enqueue_scripts', 'pagelayer_load_live', 9999);
409
410 function pagelayer_load_live(){
411
412 global $post;
413
414 // If its not live editing then stop
415 if(!pagelayer_is_live_iframe()){
416 return;
417 }
418
419 // Are you allowed to edit ?
420 if(!pagelayer_user_can_edit()){
421 return;
422 }
423
424 // Load the editor class
425 include_once(PAGELAYER_DIR.'/main/live.php');
426
427 // Call the constructor
428 $pl_editor = new PageLayer_LiveEditor();
429
430 }
431
432 // If we are doing ajax and its a pagelayer ajax
433 if(wp_doing_ajax()){
434 include_once(PAGELAYER_DIR.'/main/ajax.php');
435 }
436
437 // Show the backend editor options
438 add_action('edit_form_after_title', 'pagelayer_after_title', 10);
439 function pagelayer_after_title(){
440
441 global $post;
442
443 // Get the current screen
444 $current_screen = get_current_screen();
445
446 // For gutenberg
447 if(method_exists($current_screen, 'is_block_editor') && $current_screen->is_block_editor()){
448
449 // Add the code in the footer
450 add_action('admin_footer', 'pagelayer_gutenberg_after_title');
451
452 return;
453 }
454
455 $link = pagelayer_shortlink($post->ID).'&pagelayer-live=1';
456
457 echo '
458 <div id="pagelayer-editor-button-row" style="margin-top:15px; display:inline-block;">
459 <a id="pagelayer-editor-button" href="'.$link.'" class="button button-primary button-large" style="height:auto; padding:6px; font-size:18px;">
460 <img src="'.PAGELAYER_URL.'/images/pagelayer-logo-40.png" align="top" width="24" /> <span>'.__('Edit with Pagelayer').'</span>
461 </a>
462 </div>';
463
464 }
465
466 function pagelayer_gutenberg_after_title(){
467
468 global $post;
469
470 $link = pagelayer_shortlink($post->ID).'&pagelayer-live=1';
471
472 echo '
473 <div id="pagelayer-editor-button-row" style="margin-left:15px; display:none">
474 <a id="pagelayer-editor-button" href="'.$link.'" class="button button-primary button-large" style="height:auto; padding:6px; font-size:18px;">
475 <img src="'.PAGELAYER_URL.'/images/pagelayer-logo-40.png" align="top" width="24" /> <span>'.__('Edit with Pagelayer').'</span>
476 </a>
477 </div>
478
479 <script type="text/javascript">
480 jQuery(document).ready(function(){
481
482 var pagelayer_timer;
483 var pagelayer_button = function(){
484 var button = jQuery("#pagelayer-editor-button-row");
485 var g = jQuery(".edit-post-header-toolbar");
486 if(g.length < 1){
487 return;
488 }
489 button.detach();
490 //console.log(button);
491 g.append(button);
492 button.show();
493 clearInterval(pagelayer_timer);
494 }
495 pagelayer_timer = setInterval(pagelayer_button, 100);
496 });
497 </script>';
498
499 }
500
501 // Handle Old Slug URL redirect for live link
502 add_filter( 'old_slug_redirect_url', 'pagelayer_old_slug_redirect', 10, 1);
503 function pagelayer_old_slug_redirect($link){
504
505 if(pagelayer_optreq('pagelayer-live')){
506 $link = add_query_arg('pagelayer-live', '1', $link);
507 }
508
509 return $link;
510 }
511
512 add_filter( 'post_row_actions', 'pagelayer_quick_link', 10, 2 );
513 add_filter( 'page_row_actions', 'pagelayer_quick_link', 10, 2 );
514 function pagelayer_quick_link($actions, $post){
515 $link = pagelayer_shortlink($post->ID).'&pagelayer-live=1';
516
517 $actions['pagelayer'] = '<a href="'.esc_url( $link ).'">'.__( 'Edit using Pagelayer', 'pagelayer') .'</a>';
518
519 return $actions;
520 }
521
522 // Add settings link on plugin page
523 add_filter('plugin_action_links_pagelayer/pagelayer.php', 'pagelayer_plugin_action_links');
524 function pagelayer_plugin_action_links($links){
525
526 if(!defined('PAGELAYER_PREMIUM')){
527 $links[] = '<a href="'.PAGELAYER_PRO_URL.'" style="color:#3db634;" target="_blank">'._x('Go Pro', 'Upgrade to Pagelayer Pro for many more features', 'pagelayer').'</a>';
528 }
529
530 $settings_link = '<a href="admin.php?page=pagelayer">Settings</a>';
531 array_unshift($links, $settings_link);
532
533 return $links;
534 }
535
536 // Pagelayer Template Loading Mechanism
537 include_once(PAGELAYER_DIR.'/main/template.php');