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

526 lines 15.5 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.3');
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, 'pagelayer_fonts', 'pagelayer_page_fonts');
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 }
220
221 // This function will handle the Settings Pages in PageLayer
222 function pagelayer_license_page(){
223
224 global $wp_version, $pagelayer;
225
226 include_once(PAGELAYER_DIR.'/main/license.php');
227
228 pagelayer_license();
229
230 }
231
232 // Load the Live Body
233 add_action('template_redirect', 'pagelayer_load_live_body', 4);
234
235 function pagelayer_load_live_body(){
236
237 global $post;
238
239 // If its not live editing then stop
240 if(!pagelayer_is_live()){
241 return;
242 }
243
244 // If its the iFRAME then return
245 if(pagelayer_is_live_iframe()){
246 return;
247 }
248
249 // Are you allowed to edit ?
250 if(!pagelayer_user_can_edit()){
251 return;
252 }
253
254 // Load the editor live body
255 include_once(PAGELAYER_DIR.'/main/live-body.php');
256
257 pagelayer_live_body();
258
259 }
260
261 // Add the JS and CSS for Posts and Pages when being viewed ONLY if there is our content called
262 add_action('template_redirect', 'pagelayer_enqueue_frontend', 5);
263
264 function pagelayer_enqueue_frontend($force = false){
265
266 global $post, $pagelayer;
267
268 if(!empty($pagelayer->cache['enqueue_frontend'])){
269 return;
270 }
271
272 if(empty($post->ID) && empty($force)){
273 return;
274 }
275
276 $is_pagelayer = false;
277 $is_audio = false;
278
279 // This IF is for Archives mainly as $post->ID is only the first post in the archive
280 // and we need to make sure that other posts are pagelayer or not
281 if(!empty($GLOBALS['wp_query']->posts) && is_array($GLOBALS['wp_query']->posts)){
282 foreach($GLOBALS['wp_query']->posts as $v){
283 if(get_post_meta($v->ID , 'pagelayer-data')){
284 $is_pagelayer = true;
285 }
286
287 if(preg_match('/\[pl_audio/is', $v->post_content)){
288 $is_audio = true;
289 }
290 }
291 }
292
293 // Enqueue the FRONTEND CSS
294 if(get_post_meta($post->ID , 'pagelayer-data') || $is_pagelayer || $force){
295
296 // We dont need the auto <p> and <br> as they interfere with us
297 remove_filter('the_content', 'wpautop');
298
299 // No need to add curly codes to the content
300 remove_filter('the_content', 'wptexturize');
301
302 pagelayer_load_shortcodes();
303 $pagelayer->cache['enqueue_frontend'] = true;
304
305 // Load the global styles
306 add_action('wp_head', 'pagelayer_global_js', 2);
307
308 $premium_js = '';
309 $premium_css = '';
310 if(defined('PAGELAYER_PREMIUM')){
311 $premium_js = ',chart.min.js,slick.min.js,premium-frontend.js';
312 $premium_css = ',slick.css,slick-theme.css,premium-frontend.css';
313
314 // Load this For audio widget
315 if($is_audio || pagelayer_is_live_iframe()){
316 wp_enqueue_script('wp-mediaelement');
317 wp_enqueue_style( 'wp-mediaelement' );
318 }
319 }
320
321 // Enqueue our Editor's Frontend JS
322 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);
323 wp_enqueue_script('pagelayer-frontend');
324
325 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);
326 wp_enqueue_style('pagelayer-frontend');
327
328 // Get list of enabled icons
329 $icons = pagelayer_enabled_icons();
330 foreach($icons as $icon){
331 wp_register_style($icon, PAGELAYER_CSS.'/givecss.php?give='.$icon.'.min.css', array(), PAGELAYER_VERSION);
332 wp_enqueue_style($icon);
333 }
334
335 // Load the global styles
336 add_action('wp_head', 'pagelayer_global_styles', 5);
337
338 // Load custom widgets
339 do_action('pagelayer_custom_frontend_enqueue');
340
341 }
342
343 }
344
345 // Load the google fonts
346 add_action('wp_footer', 'pagelayer_enqueue_fonts', 5);
347
348 function pagelayer_enqueue_fonts(){
349 global $pagelayer;
350
351 if(empty($pagelayer->cache['enqueue_frontend'])){
352 return;
353 }
354
355 $url = 'Open Sans:300italic,400italic,600italic,300,400,600&subset=latin,latin-ext';
356 //pagelayer_print($pagelayer->runtime_fonts);die('alpesh');
357
358 foreach($pagelayer->runtime_fonts as $font){
359 $url .= '|'.$font.':100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i';
360 }
361
362 //echo '<link href="https://fonts.googleapis.com/css?family='.$url.'" rel="stylesheet">';
363
364 wp_register_style('pagelayer-google-font', 'https://fonts.googleapis.com/css?family='.rawurlencode($url), array(), PAGELAYER_VERSION);
365 wp_enqueue_style('pagelayer-google-font');
366
367 }
368
369 // Load any header we have
370 function pagelayer_global_js(){
371
372 echo '<script>
373 var pagelayer_ajaxurl = "'.admin_url( 'admin-ajax.php' ).'?";
374 var pagelayer_ajax_nonce = "'.wp_create_nonce('pagelayer_ajax').'";
375 var pagelayer_server_time = '.time().';
376 var pagelayer_facebook_id = "'.get_option('pagelayer-fbapp-id').'";
377 </script>';
378
379 }
380
381 // We need to handle global styles
382 function pagelayer_global_styles(){
383
384 $styles = '<style id="pagelayer-global-styles" type="text/css">';
385
386 $width = get_option('pagelayer_content_width', '1170');
387
388 // Style for only child row holder
389 $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;}';
390
391 $styles .= '</style>';
392
393 echo $styles;
394 }
395
396 // Load the live editor if needed
397 add_action('wp_enqueue_scripts', 'pagelayer_load_live', 9999);
398
399 function pagelayer_load_live(){
400
401 global $post;
402
403 // If its not live editing then stop
404 if(!pagelayer_is_live_iframe()){
405 return;
406 }
407
408 // Are you allowed to edit ?
409 if(!pagelayer_user_can_edit()){
410 return;
411 }
412
413 // Load the editor class
414 include_once(PAGELAYER_DIR.'/main/live.php');
415
416 // Call the constructor
417 $pl_editor = new PageLayer_LiveEditor();
418
419 }
420
421 // If we are doing ajax and its a pagelayer ajax
422 if(wp_doing_ajax()){
423 include_once(PAGELAYER_DIR.'/main/ajax.php');
424 }
425
426 // Show the backend editor options
427 add_action('edit_form_after_title', 'pagelayer_after_title', 10);
428 function pagelayer_after_title(){
429
430 global $post;
431
432 // Get the current screen
433 $current_screen = get_current_screen();
434
435 // For gutenberg
436 if(method_exists($current_screen, 'is_block_editor') && $current_screen->is_block_editor()){
437
438 // Add the code in the footer
439 add_action('admin_footer', 'pagelayer_gutenberg_after_title');
440
441 return;
442 }
443
444 $link = pagelayer_shortlink($post->ID).'&pagelayer-live=1';
445
446 echo '
447 <div id="pagelayer-editor-button-row" style="margin-top:15px; display:inline-block;">
448 <a id="pagelayer-editor-button" href="'.$link.'" class="button button-primary button-large" style="height:auto; padding:6px; font-size:18px;">
449 <img src="'.PAGELAYER_URL.'/images/pagelayer-logo-40.png" align="top" width="24" /> <span>'.__('Edit with Pagelayer').'</span>
450 </a>
451 </div>';
452
453 }
454
455 function pagelayer_gutenberg_after_title(){
456
457 global $post;
458
459 $link = pagelayer_shortlink($post->ID).'&pagelayer-live=1';
460
461 echo '
462 <div id="pagelayer-editor-button-row" style="margin-left:15px; display:none">
463 <a id="pagelayer-editor-button" href="'.$link.'" class="button button-primary button-large" style="height:auto; padding:6px; font-size:18px;">
464 <img src="'.PAGELAYER_URL.'/images/pagelayer-logo-40.png" align="top" width="24" /> <span>'.__('Edit with Pagelayer').'</span>
465 </a>
466 </div>
467
468 <script type="text/javascript">
469 jQuery(document).ready(function(){
470
471 var pagelayer_timer;
472 var pagelayer_button = function(){
473 var button = jQuery("#pagelayer-editor-button-row");
474 var g = jQuery(".edit-post-header-toolbar");
475 if(g.length < 1){
476 return;
477 }
478 button.detach();
479 //console.log(button);
480 g.append(button);
481 button.show();
482 clearInterval(pagelayer_timer);
483 }
484 pagelayer_timer = setInterval(pagelayer_button, 100);
485 });
486 </script>';
487
488 }
489
490 // Handle Old Slug URL redirect for live link
491 add_filter( 'old_slug_redirect_url', 'pagelayer_old_slug_redirect', 10, 1);
492 function pagelayer_old_slug_redirect($link){
493
494 if(pagelayer_optreq('pagelayer-live')){
495 $link = add_query_arg('pagelayer-live', '1', $link);
496 }
497
498 return $link;
499 }
500
501 add_filter( 'post_row_actions', 'pagelayer_quick_link', 10, 2 );
502 add_filter( 'page_row_actions', 'pagelayer_quick_link', 10, 2 );
503 function pagelayer_quick_link($actions, $post){
504 $link = pagelayer_shortlink($post->ID).'&pagelayer-live=1';
505
506 $actions['pagelayer'] = '<a href="'.esc_url( $link ).'">'.__( 'Edit using Pagelayer', 'pagelayer') .'</a>';
507
508 return $actions;
509 }
510
511 // Add settings link on plugin page
512 add_filter('plugin_action_links_pagelayer/pagelayer.php', 'pagelayer_plugin_action_links');
513 function pagelayer_plugin_action_links($links){
514
515 if(!defined('PAGELAYER_PREMIUM')){
516 $links[] = '<a href="'.PAGELAYER_PRO_URL.'" style="color:#3db634;" target="_blank">'._x('Go Pro', 'Upgrade to Pagelayer Pro for many more features', 'pagelayer').'</a>';
517 }
518
519 $settings_link = '<a href="admin.php?page=pagelayer">Settings</a>';
520 array_unshift($links, $settings_link);
521
522 return $links;
523 }
524
525 // Pagelayer Template Loading Mechanism
526 include_once(PAGELAYER_DIR.'/main/template.php');