| 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.8'); |
| 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 |
// Its premium |
| 114 |
if(defined('PAGELAYER_PREMIUM')){ |
| 115 |
include_once(PAGELAYER_DIR.'/main/template-builder.php'); |
| 116 |
} |
| 117 |
|
| 118 |
} |
| 119 |
|
| 120 |
// This adds the left menu in WordPress Admin page |
| 121 |
add_action('admin_menu', 'pagelayer_admin_menu', 5); |
| 122 |
|
| 123 |
// Shows the admin menu of Pagelayer |
| 124 |
function pagelayer_admin_menu() { |
| 125 |
|
| 126 |
global $wp_version, $pagelayer; |
| 127 |
|
| 128 |
$capability = 'activate_plugins';// TODO : Capability for accessing this page |
| 129 |
|
| 130 |
// Add the menu page |
| 131 |
add_menu_page(__('PageLayer Editor'), __('Pagelayer'), $capability, 'pagelayer', 'pagelayer_page_handler', PAGELAYER_URL.'/images/pagelayer-logo-19.png'); |
| 132 |
|
| 133 |
// Settings Page |
| 134 |
add_submenu_page('pagelayer', __('PageLayer Editor'), __('Settings'), $capability, 'pagelayer', 'pagelayer_page_handler'); |
| 135 |
|
| 136 |
// Its premium |
| 137 |
if(defined('PAGELAYER_PREMIUM')){ |
| 138 |
|
| 139 |
// Fonts link |
| 140 |
add_submenu_page('pagelayer', __('Font Settings'), __('Font Settings'), $capability, 'pagelayer_fonts', 'pagelayer_page_fonts'); |
| 141 |
|
| 142 |
// Add new template |
| 143 |
add_submenu_page('pagelayer', __('Theme Builder'), __('Theme Builder'), $capability, 'edit.php?post_type=pagelayer-template'); |
| 144 |
|
| 145 |
// Add new template Link |
| 146 |
//add_submenu_page('pagelayer', __('Add New Template'), __('Add New Template'), $capability, 'edit.php?post_type=pagelayer-template#new'); |
| 147 |
|
| 148 |
// Add new template |
| 149 |
add_submenu_page('pagelayer', __('Add New Template'), __('Add New Template'), $capability, 'pagelayer_template_wizard', 'pagelayer_builder_template_wizard'); |
| 150 |
|
| 151 |
// Its free |
| 152 |
}else{ |
| 153 |
|
| 154 |
// Go Pro link |
| 155 |
add_submenu_page('pagelayer', __('PageLayer Go Pro'), __('Go Pro'), $capability, PAGELAYER_PRO_URL); |
| 156 |
|
| 157 |
} |
| 158 |
|
| 159 |
} |
| 160 |
|
| 161 |
// This function will handle the pages in Pages in PageLayer |
| 162 |
function pagelayer_page_handler(){ |
| 163 |
|
| 164 |
global $wp_version, $pagelayer; |
| 165 |
|
| 166 |
wp_enqueue_script( 'pagelayer-admin', PAGELAYER_JS.'/pagelayer-admin.js', array('jquery'), PAGELAYER_VERSION); |
| 167 |
wp_enqueue_style( 'pagelayer-admin', PAGELAYER_CSS.'/pagelayer-admin.css', array(), PAGELAYER_VERSION); |
| 168 |
|
| 169 |
include_once(PAGELAYER_DIR.'/main/settings.php'); |
| 170 |
|
| 171 |
// Handle fonts |
| 172 |
if($pagelayer->action == 'fonts-manager'){ |
| 173 |
include_once(PAGELAYER_DIR.'/main/fonts.php'); |
| 174 |
} |
| 175 |
|
| 176 |
} |
| 177 |
|
| 178 |
// Load the Live Body |
| 179 |
add_action('template_redirect', 'pagelayer_load_live_body', 4); |
| 180 |
|
| 181 |
function pagelayer_load_live_body(){ |
| 182 |
|
| 183 |
global $post; |
| 184 |
|
| 185 |
// If its not live editing then stop |
| 186 |
if(!pagelayer_is_live()){ |
| 187 |
return; |
| 188 |
} |
| 189 |
|
| 190 |
// If its the iFRAME then return |
| 191 |
if(pagelayer_is_live_iframe()){ |
| 192 |
return; |
| 193 |
} |
| 194 |
|
| 195 |
// Are you allowed to edit ? |
| 196 |
if(!pagelayer_user_can_edit()){ |
| 197 |
return; |
| 198 |
} |
| 199 |
|
| 200 |
// Load the editor live body |
| 201 |
include_once(PAGELAYER_DIR.'/main/live-body.php'); |
| 202 |
|
| 203 |
pagelayer_live_body(); |
| 204 |
|
| 205 |
} |
| 206 |
|
| 207 |
// Add the JS and CSS for Posts and Pages when being viewed ONLY if there is our content called |
| 208 |
add_action('template_redirect', 'pagelayer_enqueue_frontend', 5); |
| 209 |
|
| 210 |
function pagelayer_enqueue_frontend($force = false){ |
| 211 |
|
| 212 |
global $post, $pagelayer; |
| 213 |
|
| 214 |
if(!empty($pagelayer->cache['enqueue_frontend'])){ |
| 215 |
return; |
| 216 |
} |
| 217 |
|
| 218 |
if(empty($post->ID)){ |
| 219 |
return; |
| 220 |
} |
| 221 |
|
| 222 |
// Enqueue the FRONTEND CSS |
| 223 |
if(get_post_meta($post->ID , 'pagelayer-data') || $force){ |
| 224 |
|
| 225 |
// We dont need the auto <p> and <br> as they interfere with us |
| 226 |
remove_filter('the_content', 'wpautop'); |
| 227 |
|
| 228 |
// No need to add curly codes to the content |
| 229 |
remove_filter('the_content', 'wptexturize'); |
| 230 |
|
| 231 |
pagelayer_load_shortcodes(); |
| 232 |
$pagelayer->cache['enqueue_frontend'] = true; |
| 233 |
|
| 234 |
// Load the global styles |
| 235 |
add_action('wp_head', 'pagelayer_global_js', 2); |
| 236 |
|
| 237 |
$premium_js = ''; |
| 238 |
if(defined('PAGELAYER_PREMIUM')){ |
| 239 |
$premium_js = ',chart.min.js,slick.min.js,premium-frontend.js'; |
| 240 |
$premium_css = ',slick.css,slick-theme.css,premium-frontend.css'; |
| 241 |
// Load this For audio widget |
| 242 |
wp_enqueue_script('wp-mediaelement'); |
| 243 |
wp_enqueue_style( 'wp-mediaelement' ); |
| 244 |
} |
| 245 |
|
| 246 |
// Enqueue our Editor's Frontend JS |
| 247 |
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); |
| 248 |
wp_enqueue_script('pagelayer-frontend'); |
| 249 |
|
| 250 |
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); |
| 251 |
wp_enqueue_style('pagelayer-frontend'); |
| 252 |
|
| 253 |
wp_register_style('font-awesome', PAGELAYER_CSS.'/font-awesome.min.css', array(), PAGELAYER_VERSION); |
| 254 |
wp_enqueue_style('font-awesome'); |
| 255 |
|
| 256 |
// Load the global styles |
| 257 |
add_action('wp_head', 'pagelayer_global_styles', 5); |
| 258 |
|
| 259 |
// Load custom widgets |
| 260 |
do_action('pagelayer_custom_frontend_enqueue'); |
| 261 |
|
| 262 |
} |
| 263 |
|
| 264 |
} |
| 265 |
|
| 266 |
// Load the google fonts |
| 267 |
add_action('wp_footer', 'pagelayer_enqueue_fonts', 5); |
| 268 |
|
| 269 |
function pagelayer_enqueue_fonts(){ |
| 270 |
global $pagelayer; |
| 271 |
|
| 272 |
if(empty($pagelayer->cache['enqueue_frontend'])){ |
| 273 |
return; |
| 274 |
} |
| 275 |
|
| 276 |
$url = 'Open Sans:300italic,400italic,600italic,300,400,600&subset=latin,latin-ext'; |
| 277 |
//pagelayer_print($pagelayer->runtime_fonts);die('alpesh'); |
| 278 |
|
| 279 |
foreach($pagelayer->runtime_fonts as $font){ |
| 280 |
$url .= '|'.$font.':100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i'; |
| 281 |
} |
| 282 |
|
| 283 |
//echo '<link href="https://fonts.googleapis.com/css?family='.$url.'" rel="stylesheet">'; |
| 284 |
|
| 285 |
wp_register_style('pagelayer-google-font', 'https://fonts.googleapis.com/css?family='.rawurlencode($url), array(), PAGELAYER_VERSION); |
| 286 |
wp_enqueue_style('pagelayer-google-font'); |
| 287 |
|
| 288 |
} |
| 289 |
|
| 290 |
// Load any header we have |
| 291 |
function pagelayer_global_js(){ |
| 292 |
|
| 293 |
echo '<script> |
| 294 |
var pagelayer_ajaxurl = "'.admin_url( 'admin-ajax.php' ).'?"; |
| 295 |
var pagelayer_ajax_nonce = "'.wp_create_nonce('pagelayer_ajax').'"; |
| 296 |
var pagelayer_server_time = '.time().'; |
| 297 |
var pagelayer_facebook_id = "'.get_option('pagelayer-fbapp-id').'"; |
| 298 |
</script>'; |
| 299 |
|
| 300 |
} |
| 301 |
|
| 302 |
// We need to handle global styles |
| 303 |
function pagelayer_global_styles(){ |
| 304 |
|
| 305 |
$styles = '<style id="pagelayer-global-styles" type="text/css">'; |
| 306 |
|
| 307 |
$width = get_option('pagelayer_content_width', '1170'); |
| 308 |
|
| 309 |
$styles .= '.pagelayer-row-stretch-auto .pagelayer-row-holder{ max-width: '.$width.'px; margin-left: auto; margin-right: auto;}'; |
| 310 |
|
| 311 |
$styles .= '</style>'; |
| 312 |
|
| 313 |
echo $styles; |
| 314 |
} |
| 315 |
|
| 316 |
// Load the live editor if needed |
| 317 |
add_action('wp_enqueue_scripts', 'pagelayer_load_live', 9999); |
| 318 |
|
| 319 |
function pagelayer_load_live(){ |
| 320 |
|
| 321 |
global $post; |
| 322 |
|
| 323 |
// If its not live editing then stop |
| 324 |
if(!pagelayer_is_live_iframe()){ |
| 325 |
return; |
| 326 |
} |
| 327 |
|
| 328 |
// Are you allowed to edit ? |
| 329 |
if(!pagelayer_user_can_edit()){ |
| 330 |
return; |
| 331 |
} |
| 332 |
|
| 333 |
// Load the editor class |
| 334 |
include_once(PAGELAYER_DIR.'/main/live.php'); |
| 335 |
|
| 336 |
// Call the constructor |
| 337 |
$pl_editor = new PageLayer_LiveEditor(); |
| 338 |
|
| 339 |
} |
| 340 |
|
| 341 |
// If we are doing ajax and its a pagelayer ajax |
| 342 |
if(wp_doing_ajax()){ |
| 343 |
include_once(PAGELAYER_DIR.'/main/ajax.php'); |
| 344 |
} |
| 345 |
|
| 346 |
// Show the backend editor options |
| 347 |
add_action('edit_form_after_title', 'pagelayer_after_title', 10); |
| 348 |
function pagelayer_after_title(){ |
| 349 |
|
| 350 |
global $post; |
| 351 |
|
| 352 |
// Get the current screen |
| 353 |
$current_screen = get_current_screen(); |
| 354 |
|
| 355 |
// For gutenberg |
| 356 |
if(method_exists($current_screen, 'is_block_editor') && $current_screen->is_block_editor()){ |
| 357 |
|
| 358 |
// Add the code in the footer |
| 359 |
add_action('admin_footer', 'pagelayer_gutenberg_after_title'); |
| 360 |
|
| 361 |
return; |
| 362 |
} |
| 363 |
|
| 364 |
$link = pagelayer_shortlink($post->ID).'&pagelayer-live=1'; |
| 365 |
|
| 366 |
echo ' |
| 367 |
<div id="pagelayer-editor-button-row" style="margin-top:15px; display:inline-block;"> |
| 368 |
<a id="pagelayer-editor-button" href="'.$link.'" class="button button-primary button-large" style="height:auto; padding:6px; font-size:18px;"> |
| 369 |
<img src="'.PAGELAYER_URL.'/images/pagelayer-logo-40.png" align="top" width="24" /> <span>'.__('Edit with PageLayer').'</span> |
| 370 |
</a> |
| 371 |
</div>'; |
| 372 |
|
| 373 |
} |
| 374 |
|
| 375 |
function pagelayer_gutenberg_after_title(){ |
| 376 |
|
| 377 |
global $post; |
| 378 |
|
| 379 |
$link = pagelayer_shortlink($post->ID).'&pagelayer-live=1'; |
| 380 |
|
| 381 |
echo ' |
| 382 |
<div id="pagelayer-editor-button-row" style="margin-left:15px; display:none"> |
| 383 |
<a id="pagelayer-editor-button" href="'.$link.'" class="button button-primary button-large" style="height:auto; padding:6px; font-size:18px;"> |
| 384 |
<img src="'.PAGELAYER_URL.'/images/pagelayer-logo-40.png" align="top" width="24" /> <span>'.__('Edit with PageLayer').'</span> |
| 385 |
</a> |
| 386 |
</div> |
| 387 |
|
| 388 |
<script type="text/javascript"> |
| 389 |
jQuery(document).ready(function(){ |
| 390 |
|
| 391 |
var pagelayer_timer; |
| 392 |
var pagelayer_button = function(){ |
| 393 |
var button = jQuery("#pagelayer-editor-button-row"); |
| 394 |
var g = jQuery(".edit-post-header-toolbar"); |
| 395 |
if(g.length < 1){ |
| 396 |
return; |
| 397 |
} |
| 398 |
button.detach(); |
| 399 |
//console.log(button); |
| 400 |
g.append(button); |
| 401 |
button.show(); |
| 402 |
clearInterval(pagelayer_timer); |
| 403 |
} |
| 404 |
pagelayer_timer = setInterval(pagelayer_button, 100); |
| 405 |
}); |
| 406 |
</script>'; |
| 407 |
|
| 408 |
} |
| 409 |
|
| 410 |
add_filter( 'post_row_actions', 'pagelayer_quick_link', 10, 2 ); |
| 411 |
add_filter( 'page_row_actions', 'pagelayer_quick_link', 10, 2 ); |
| 412 |
function pagelayer_quick_link($actions, $post){ |
| 413 |
$link = pagelayer_shortlink($post->ID).'&pagelayer-live=1'; |
| 414 |
|
| 415 |
$actions['pagelayer'] = '<a href="'.esc_url( $link ).'">'.__( 'Edit using PageLayer', 'pagelayer') .'</a>'; |
| 416 |
|
| 417 |
return $actions; |
| 418 |
} |
| 419 |
|
| 420 |
// Pagelayer Template Loading Mechanism |
| 421 |
include_once(PAGELAYER_DIR.'/main/template.php'); |