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

386 lines 10.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(__FILE__));
7 define('PAGELAYER_FILE', __FILE__);
8 define('PAGELAYER_VERSION', '0.9.5');
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 $premium_js = '';
221 if(defined('PAGELAYER_PREMIUM')){
222 $premium_js = ',chartist.min.js';
223 }
224
225 // Enqueue our Editor's Frontend JS
226 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'.$premium_js, array('jquery'), PAGELAYER_VERSION);
227 wp_enqueue_script('pagelayer-frontend');
228
229 wp_register_style('pagelayer-frontend', PAGELAYER_CSS.'/givecss.php?give=pagelayer-frontend.css,nivo-lightbox.css,slippry.css,animate.min.css', array(), PAGELAYER_VERSION);
230 wp_enqueue_style('pagelayer-frontend');
231
232 wp_register_style('font-awesome', PAGELAYER_CSS.'/font-awesome.min.css', array(), PAGELAYER_VERSION);
233 wp_enqueue_style('font-awesome');
234
235 // Load the global styles
236 add_action('wp_head', 'pagelayer_global_styles', 5);
237
238 // Load custom widgets
239 do_action('pagelayer_custom_frontend_enqueue');
240
241 }
242
243 }
244
245 // Load the google fonts
246 add_action('wp_footer', 'pagelayer_enqueue_fonts', 5);
247
248 function pagelayer_enqueue_fonts(){
249 global $pagelayer;
250
251 if(empty($pagelayer->cache['enqueue_frontend'])){
252 return;
253 }
254
255 $url = 'Open Sans:300italic,400italic,600italic,300,400,600&subset=latin,latin-ext';
256 //pagelayer_print($pagelayer->runtime_fonts);die('alpesh');
257
258 foreach($pagelayer->runtime_fonts as $font){
259 $url .= '|'.$font.':100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i';
260 }
261
262 //echo '<link href="https://fonts.googleapis.com/css?family='.$url.'" rel="stylesheet">';
263
264 wp_register_style('pagelayer-google-font', 'https://fonts.googleapis.com/css?family='.rawurlencode($url), array(), PAGELAYER_VERSION);
265 wp_enqueue_style('pagelayer-google-font');
266
267 }
268
269 // We need to handle global styles
270 function pagelayer_global_styles(){
271
272 $styles = '<style id="pagelayer-global-styles" type="text/css">';
273
274 $width = get_option('pagelayer_content_width', '1170');
275
276 $styles .= '.pagelayer-row-stretch-auto .pagelayer-row-holder{ max-width: '.$width.'px; margin-left: auto; margin-right: auto;}';
277
278 $styles .= '</style>';
279
280 echo $styles;
281 }
282
283 // Load the live editor if needed
284 add_action('wp_enqueue_scripts', 'pagelayer_load_live', 9999);
285
286 function pagelayer_load_live(){
287
288 global $post;
289
290 // If its not live editing then stop
291 if(!pagelayer_is_live_iframe()){
292 return;
293 }
294
295 // Are you allowed to edit ?
296 if(!pagelayer_user_can_edit()){
297 return;
298 }
299
300 // Load the editor class
301 include_once(PAGELAYER_DIR.'/main/live.php');
302
303 // Call the constructor
304 $pl_editor = new PageLayer_LiveEditor();
305
306 }
307
308 // If we are doing ajax and its a pagelayer ajax
309 if(wp_doing_ajax()){
310 include_once(PAGELAYER_DIR.'/main/ajax.php');
311 }
312
313 // Show the backend editor options
314 add_action('edit_form_after_title', 'pagelayer_after_title');
315 function pagelayer_after_title(){
316
317 global $post;
318
319 // Get the current screen
320 $current_screen = get_current_screen();
321
322 // For gutenberg
323 if(method_exists($current_screen, 'is_block_editor') && $current_screen->is_block_editor()){
324
325 // Add the code in the footer
326 add_action('admin_footer', 'pagelayer_gutenberg_after_title');
327
328 return;
329 }
330
331 $link = pagelayer_shortlink($post->ID).'&pagelayer-live=1';
332
333 echo '
334 <div id="pagelayer-editor-button-row" style="margin-top:15px">
335 <a id="pagelayer-editor-button" href="'.$link.'" class="button button-primary button-large" style="height:auto; padding:6px; font-size:18px;">
336 <img src="'.PAGELAYER_URL.'/images/pagelayer-logo-40.png" align="top" width="24" /> <span>'.__('Edit with PageLayer').'</span>
337 </a>
338 </div>';
339
340 }
341
342 function pagelayer_gutenberg_after_title(){
343
344 global $post;
345
346 $link = pagelayer_shortlink($post->ID).'&pagelayer-live=1';
347
348 echo '
349 <div id="pagelayer-editor-button-row" style="margin-left:15px; display:none">
350 <a id="pagelayer-editor-button" href="'.$link.'" class="button button-primary button-large" style="height:auto; padding:6px; font-size:18px;">
351 <img src="'.PAGELAYER_URL.'/images/pagelayer-logo-40.png" align="top" width="24" /> <span>'.__('Edit with PageLayer').'</span>
352 </a>
353 </div>
354
355 <script type="text/javascript">
356 jQuery(document).ready(function(){
357
358 var pagelayer_timer;
359 var pagelayer_button = function(){
360 var button = jQuery("#pagelayer-editor-button-row");
361 var g = jQuery(".edit-post-header-toolbar");
362 if(g.length < 1){
363 return;
364 }
365 button.detach();
366 //console.log(button);
367 g.append(button);
368 button.show();
369 clearInterval(pagelayer_timer);
370 }
371 pagelayer_timer = setInterval(pagelayer_button, 100);
372 });
373 </script>';
374
375 }
376
377 add_filter( 'post_row_actions', 'pagelayer_quick_link', 10, 2 );
378 add_filter( 'page_row_actions', 'pagelayer_quick_link', 10, 2 );
379 function pagelayer_quick_link($actions, $post){
380 $link = pagelayer_shortlink($post->ID).'&pagelayer-live=1';
381
382 $actions['pagelayer'] = '<a href="'.esc_url( $link ).'">'.__( 'Edit using PageLayer', 'pagelayer') .'</a>';
383
384 return $actions;
385 }
386