| 1 |
<?php |
| 2 |
|
| 3 |
////////////////////////////////////////////////////////////// |
| 4 |
//=========================================================== |
| 5 |
// class.php |
| 6 |
//=========================================================== |
| 7 |
// PAGELAYER |
| 8 |
// Inspired by the DESIRE to be the BEST OF ALL |
| 9 |
// ---------------------------------------------------------- |
| 10 |
// Started by: Pulkit Gupta |
| 11 |
// Date: 23rd Jan 2017 |
| 12 |
// Time: 23:00 hrs |
| 13 |
// Site: http://pagelayer.com/wordpress (PAGELAYER) |
| 14 |
// ---------------------------------------------------------- |
| 15 |
// Please Read the Terms of use at http://pagelayer.com/tos |
| 16 |
// ---------------------------------------------------------- |
| 17 |
//=========================================================== |
| 18 |
// (c)Pagelayer Team |
| 19 |
//=========================================================== |
| 20 |
////////////////////////////////////////////////////////////// |
| 21 |
|
| 22 |
// Are we being accessed directly ? |
| 23 |
if(!defined('PAGELAYER_VERSION')) { |
| 24 |
exit('Hacking Attempt !'); |
| 25 |
} |
| 26 |
|
| 27 |
// Get the client IP |
| 28 |
function _pagelayer_getip(){ |
| 29 |
if(isset($_SERVER["REMOTE_ADDR"])){ |
| 30 |
return $_SERVER["REMOTE_ADDR"]; |
| 31 |
}elseif(isset($_SERVER["HTTP_X_FORWARDED_FOR"])){ |
| 32 |
return $_SERVER["HTTP_X_FORWARDED_FOR"]; |
| 33 |
}elseif(isset($_SERVER["HTTP_CLIENT_IP"])){ |
| 34 |
return $_SERVER["HTTP_CLIENT_IP"]; |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
// Get the client IP |
| 39 |
function pagelayer_getip(){ |
| 40 |
|
| 41 |
global $pagelayer; |
| 42 |
|
| 43 |
// Just so that we have something |
| 44 |
$ip = _pagelayer_getip(); |
| 45 |
|
| 46 |
$pagelayer['ip_method'] = (int) @$pagelayer['ip_method']; |
| 47 |
|
| 48 |
if(isset($_SERVER["REMOTE_ADDR"])){ |
| 49 |
$ip = $_SERVER["REMOTE_ADDR"]; |
| 50 |
} |
| 51 |
|
| 52 |
if(isset($_SERVER["HTTP_X_FORWARDED_FOR"]) && @$pagelayer['ip_method'] == 1){ |
| 53 |
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; |
| 54 |
} |
| 55 |
|
| 56 |
if(isset($_SERVER["HTTP_CLIENT_IP"]) && @$pagelayer['ip_method'] == 2){ |
| 57 |
$ip = $_SERVER["HTTP_CLIENT_IP"]; |
| 58 |
} |
| 59 |
|
| 60 |
// Hacking fix for X-Forwarded-For |
| 61 |
if(!pagelayer_valid_ip($ip)){ |
| 62 |
return ''; |
| 63 |
} |
| 64 |
|
| 65 |
return $ip; |
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
// Execute a select query and return an array |
| 70 |
function pagelayer_selectquery($query, $array = 0){ |
| 71 |
global $wpdb; |
| 72 |
|
| 73 |
$result = $wpdb->get_results($query, 'ARRAY_A'); |
| 74 |
|
| 75 |
if(empty($array)){ |
| 76 |
return current($result); |
| 77 |
}else{ |
| 78 |
return $result; |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
// Check if an IP is valid |
| 83 |
function pagelayer_valid_ip($ip){ |
| 84 |
|
| 85 |
// IPv6 |
| 86 |
if(pagelayer_valid_ipv6($ip)){ |
| 87 |
return true; |
| 88 |
} |
| 89 |
|
| 90 |
// IPv4 |
| 91 |
if(!ip2long($ip)){ |
| 92 |
return false; |
| 93 |
} |
| 94 |
|
| 95 |
return true; |
| 96 |
} |
| 97 |
|
| 98 |
function pagelayer_valid_ipv6($ip){ |
| 99 |
|
| 100 |
$pattern = '/^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/'; |
| 101 |
|
| 102 |
if(!preg_match($pattern, $ip)){ |
| 103 |
return false; |
| 104 |
} |
| 105 |
|
| 106 |
return true; |
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
// Check if a field is posted via POST else return default value |
| 111 |
function pagelayer_optpost($name, $default = ''){ |
| 112 |
|
| 113 |
if(!empty($_POST[$name])){ |
| 114 |
return pagelayer_inputsec(pagelayer_htmlizer(trim($_POST[$name]))); |
| 115 |
} |
| 116 |
|
| 117 |
return $default; |
| 118 |
} |
| 119 |
|
| 120 |
// Check if a field is posted via GET else return default value |
| 121 |
function pagelayer_optget($name, $default = ''){ |
| 122 |
|
| 123 |
if(!empty($_GET[$name])){ |
| 124 |
return pagelayer_inputsec(pagelayer_htmlizer(trim($_GET[$name]))); |
| 125 |
} |
| 126 |
|
| 127 |
return $default; |
| 128 |
} |
| 129 |
|
| 130 |
// Check if a field is posted via GET or POST else return default value |
| 131 |
function pagelayer_optreq($name, $default = ''){ |
| 132 |
|
| 133 |
if(!empty($_REQUEST[$name])){ |
| 134 |
return pagelayer_inputsec(pagelayer_htmlizer(trim($_REQUEST[$name]))); |
| 135 |
} |
| 136 |
|
| 137 |
return $default; |
| 138 |
} |
| 139 |
|
| 140 |
// For filling in posted values |
| 141 |
function pagelayer_POSTval($name, $default = ''){ |
| 142 |
|
| 143 |
return (!empty($_POST) ? (!isset($_POST[$name]) ? '' : $_POST[$name]) : $default); |
| 144 |
|
| 145 |
} |
| 146 |
|
| 147 |
function pagelayer_POSTchecked($name, $default = false){ |
| 148 |
|
| 149 |
return (!empty($_POST) ? (isset($_POST[$name]) ? 'checked="checked"' : '') : (!empty($default) ? 'checked="checked"' : '')); |
| 150 |
|
| 151 |
} |
| 152 |
|
| 153 |
function pagelayer_POSTselect($name, $value, $default = false){ |
| 154 |
|
| 155 |
if(empty($_POST)){ |
| 156 |
if(!empty($default)){ |
| 157 |
return 'selected="selected"'; |
| 158 |
} |
| 159 |
}else{ |
| 160 |
if(isset($_POST[$name])){ |
| 161 |
if(trim($_POST[$name]) == $value){ |
| 162 |
return 'selected="selected"'; |
| 163 |
} |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
} |
| 168 |
|
| 169 |
function pagelayer_inputsec($string){ |
| 170 |
|
| 171 |
if(!get_magic_quotes_gpc()){ |
| 172 |
|
| 173 |
$string = addslashes($string); |
| 174 |
|
| 175 |
}else{ |
| 176 |
|
| 177 |
$string = stripslashes($string); |
| 178 |
$string = addslashes($string); |
| 179 |
|
| 180 |
} |
| 181 |
|
| 182 |
// This is to replace ` which can cause the command to be executed in exec() |
| 183 |
$string = str_replace('`', '\`', $string); |
| 184 |
|
| 185 |
return $string; |
| 186 |
|
| 187 |
} |
| 188 |
|
| 189 |
function pagelayer_htmlizer($string){ |
| 190 |
|
| 191 |
$string = htmlentities($string, ENT_QUOTES, 'UTF-8'); |
| 192 |
|
| 193 |
preg_match_all('/(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)/', $string, $matches);//r_print($matches); |
| 194 |
|
| 195 |
foreach($matches[1] as $mk => $mv){ |
| 196 |
$tmp_m = pagelayer_entity_check($matches[2][$mk]); |
| 197 |
$string = str_replace($matches[1][$mk], $tmp_m, $string); |
| 198 |
} |
| 199 |
|
| 200 |
return $string; |
| 201 |
|
| 202 |
} |
| 203 |
|
| 204 |
function pagelayer_entity_check($string){ |
| 205 |
|
| 206 |
//Convert Hexadecimal to Decimal |
| 207 |
$num = ((substr($string, 0, 1) === 'x') ? hexdec(substr($string, 1)) : (int) $string); |
| 208 |
|
| 209 |
//Squares and Spaces - return nothing |
| 210 |
$string = (($num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num < 0x20) ? '' : '&#'.$num.';'); |
| 211 |
|
| 212 |
return $string; |
| 213 |
|
| 214 |
} |
| 215 |
|
| 216 |
// Check if a checkbox is selected |
| 217 |
function pagelayer_is_checked($post){ |
| 218 |
|
| 219 |
if(!empty($_POST[$post])){ |
| 220 |
return true; |
| 221 |
} |
| 222 |
return false; |
| 223 |
} |
| 224 |
|
| 225 |
// Reoort an error |
| 226 |
function pagelayer_report_error($error = array()){ |
| 227 |
|
| 228 |
if(empty($error)){ |
| 229 |
return true; |
| 230 |
} |
| 231 |
|
| 232 |
$error_string = '<b>Please fix the below error(s) :</b> <br />'; |
| 233 |
|
| 234 |
foreach($error as $ek => $ev){ |
| 235 |
$error_string .= '* '.$ev.'<br />'; |
| 236 |
} |
| 237 |
|
| 238 |
echo '<div id="message" class="error"><p>' |
| 239 |
. __pl($error_string) |
| 240 |
. '</p></div>'; |
| 241 |
} |
| 242 |
|
| 243 |
// Report a notice |
| 244 |
function pagelayer_report_notice($notice = array()){ |
| 245 |
|
| 246 |
global $wp_version; |
| 247 |
|
| 248 |
if(empty($notice)){ |
| 249 |
return true; |
| 250 |
} |
| 251 |
|
| 252 |
// Which class do we have to use ? |
| 253 |
if(version_compare($wp_version, '3.8', '<')){ |
| 254 |
$notice_class = 'updated'; |
| 255 |
}else{ |
| 256 |
$notice_class = 'updated'; |
| 257 |
} |
| 258 |
|
| 259 |
$notice_string = '<b>Please check the below notice(s) :</b> <br />'; |
| 260 |
|
| 261 |
foreach($notice as $ek => $ev){ |
| 262 |
$notice_string .= '* '.$ev.'<br />'; |
| 263 |
} |
| 264 |
|
| 265 |
echo '<div id="message" class="'.$notice_class.'"><p>' |
| 266 |
. __pl($notice_string) |
| 267 |
. '</p></div>'; |
| 268 |
} |
| 269 |
|
| 270 |
// Convert an objext to array |
| 271 |
function pagelayer_objectToArray($d){ |
| 272 |
|
| 273 |
if(is_object($d)){ |
| 274 |
$d = get_object_vars($d); |
| 275 |
} |
| 276 |
|
| 277 |
if(is_array($d)){ |
| 278 |
return array_map(__FUNCTION__, $d); // recursive |
| 279 |
}elseif(is_object($d)){ |
| 280 |
return pagelayer_objectToArray($d); |
| 281 |
}else{ |
| 282 |
return $d; |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
// Sanitize variables |
| 287 |
function pagelayer_sanitize_variables($variables = array()){ |
| 288 |
|
| 289 |
if(is_array($variables)){ |
| 290 |
foreach($variables as $k => $v){ |
| 291 |
$variables[$k] = trim($v); |
| 292 |
$variables[$k] = escapeshellcmd($v); |
| 293 |
} |
| 294 |
}else{ |
| 295 |
$variables = escapeshellcmd(trim($variables)); |
| 296 |
} |
| 297 |
|
| 298 |
return $variables; |
| 299 |
} |
| 300 |
|
| 301 |
// Is multisite ? |
| 302 |
function pagelayer_is_multisite() { |
| 303 |
|
| 304 |
if(function_exists('get_site_option') && function_exists('is_multisite') && is_multisite()){ |
| 305 |
return true; |
| 306 |
} |
| 307 |
|
| 308 |
return false; |
| 309 |
} |
| 310 |
|
| 311 |
// Generate a random string |
| 312 |
function pagelayer_RandomString($length = 10){ |
| 313 |
$characters = '0123456789abcdefghijklmnopqrstuvwxyz'; |
| 314 |
$charactersLength = strlen($characters); |
| 315 |
$randomString = ''; |
| 316 |
for($i = 0; $i < $length; $i++){ |
| 317 |
$randomString .= $characters[rand(0, $charactersLength - 1)]; |
| 318 |
} |
| 319 |
return $randomString; |
| 320 |
} |
| 321 |
|
| 322 |
function pagelayer_print($array){ |
| 323 |
|
| 324 |
echo '<pre>'; |
| 325 |
print_r($array); |
| 326 |
echo '</pre>'; |
| 327 |
|
| 328 |
} |
| 329 |
|
| 330 |
function pagelayer_cleanpath($path){ |
| 331 |
$path = str_replace('\\\\', '/', $path); |
| 332 |
$path = str_replace('\\', '/', $path); |
| 333 |
$path = str_replace('//', '/', $path); |
| 334 |
return rtrim($path, '/'); |
| 335 |
} |
| 336 |
|
| 337 |
// Returns the Numeric Value of results Per Page |
| 338 |
function pagelayer_get_page($get = 'page', $resperpage = 50){ |
| 339 |
|
| 340 |
$resperpage = (!empty($_REQUEST['reslen']) && is_numeric($_REQUEST['reslen']) ? (int) pagelayer_optreq('reslen') : $resperpage); |
| 341 |
|
| 342 |
if(pagelayer_optget($get)){ |
| 343 |
$pg = (int) pagelayer_optget($get); |
| 344 |
$pg = $pg - 1; |
| 345 |
$page = ($pg * $resperpage); |
| 346 |
$page = ($page <= 0 ? 0 : $page); |
| 347 |
}else{ |
| 348 |
$page = 0; |
| 349 |
} |
| 350 |
return $page; |
| 351 |
} |
| 352 |
|
| 353 |
// Are we editing from the Admin panel ? |
| 354 |
function pagelayer_is_editing($force = false){ |
| 355 |
|
| 356 |
global $post, $pagelayer; |
| 357 |
|
| 358 |
if(!empty($force)){ |
| 359 |
return true; |
| 360 |
} |
| 361 |
|
| 362 |
if(!is_admin()){ |
| 363 |
return false; |
| 364 |
} |
| 365 |
|
| 366 |
$current_file = basename($_SERVER['PHP_SELF']); |
| 367 |
|
| 368 |
$type = get_post_type(); |
| 369 |
//echo $type;return false; |
| 370 |
//$page = pagelayer_optreq('page'); |
| 371 |
|
| 372 |
// Are we in the live editor mode OR is this a post which is supported |
| 373 |
if((pagelayer_supported_type($type) && in_array($current_file, array('post.php', 'post-new.php'))) || pagelayer_is_live()){ |
| 374 |
return true; |
| 375 |
}else{ |
| 376 |
return false; |
| 377 |
} |
| 378 |
|
| 379 |
} |
| 380 |
|
| 381 |
// Is the given post type editable by us ? |
| 382 |
function pagelayer_supported_type($type){ |
| 383 |
|
| 384 |
global $pagelayer; |
| 385 |
|
| 386 |
$type = trim($type); |
| 387 |
|
| 388 |
if(in_array($type, $pagelayer->settings['post_types'])){ |
| 389 |
return true; |
| 390 |
} |
| 391 |
|
| 392 |
return false; |
| 393 |
|
| 394 |
} |
| 395 |
|
| 396 |
function pagelayer_shortlink($id){ |
| 397 |
$link = wp_get_shortlink($id); |
| 398 |
$link .= substr_count($link, '?') > 0 ? '' : '?'; |
| 399 |
return $link; |
| 400 |
} |
| 401 |
|
| 402 |
// Pagelayer live link |
| 403 |
function pagelayer_livelink($id){ |
| 404 |
return pagelayer_shortlink($id).'&pagelayer-live=1'; |
| 405 |
} |
| 406 |
|
| 407 |
// Are we in live mode ? |
| 408 |
function pagelayer_is_live(){ |
| 409 |
|
| 410 |
global $post; |
| 411 |
|
| 412 |
// Are we seeing the post ? |
| 413 |
if(!isset($post) || !isset($post->ID) || empty($post->ID)){ |
| 414 |
return false; |
| 415 |
} |
| 416 |
|
| 417 |
// Is it the live mode ? |
| 418 |
if(pagelayer_optreq('pagelayer-live')){ |
| 419 |
return true; |
| 420 |
} |
| 421 |
|
| 422 |
return false; |
| 423 |
|
| 424 |
} |
| 425 |
|
| 426 |
// Are we in live IFRAME mode ? |
| 427 |
function pagelayer_is_live_iframe(){ |
| 428 |
|
| 429 |
// Are we seeing the post ? |
| 430 |
if(!pagelayer_is_live()){ |
| 431 |
return false; |
| 432 |
} |
| 433 |
|
| 434 |
// Is it the live mode ? |
| 435 |
if(pagelayer_optreq('pagelayer-iframe')){ |
| 436 |
return true; |
| 437 |
} |
| 438 |
|
| 439 |
return false; |
| 440 |
|
| 441 |
} |
| 442 |
|
| 443 |
// Can the current user edit the post ? |
| 444 |
function pagelayer_user_can_edit($post = NULL){ |
| 445 |
|
| 446 |
global $wp_the_query, $current_user; |
| 447 |
|
| 448 |
if(!isset($post) || empty($post) || $post === NULL){ |
| 449 |
global $post; |
| 450 |
} |
| 451 |
|
| 452 |
wp_get_current_user(); |
| 453 |
|
| 454 |
if(isset($post) && is_object($post) && isset($post->ID) && isset($post->post_author) && isset($current_user) && is_object($current_user) && isset($current_user->ID) && (current_user_can('edit_others_posts', $post->ID) || ($post->post_author == $current_user->ID))){ |
| 455 |
return true; |
| 456 |
} |
| 457 |
|
| 458 |
return false; |
| 459 |
|
| 460 |
} |
| 461 |
|
| 462 |
// Language sting function |
| 463 |
function __pl($key){ |
| 464 |
|
| 465 |
global $pagelayer; |
| 466 |
|
| 467 |
if(!empty($pagelayer->l[$key])){ |
| 468 |
return $pagelayer->l[$key]; |
| 469 |
} |
| 470 |
|
| 471 |
return $key; |
| 472 |
|
| 473 |
} |
| 474 |
|
| 475 |
// Give the list of icon sources |
| 476 |
function pagelayer_icon_sources(){ |
| 477 |
return array(); |
| 478 |
} |
| 479 |
|
| 480 |
// Loads the shortcodes |
| 481 |
function pagelayer_load_shortcodes(){ |
| 482 |
|
| 483 |
include_once(PAGELAYER_DIR.'/main/shortcode_functions.php'); |
| 484 |
if(defined('PAGELAYER_PREMIUM')){ |
| 485 |
include_once(PAGELAYER_DIR.'/main/premium_functions.php'); |
| 486 |
} |
| 487 |
include_once(PAGELAYER_DIR.'/main/shortcodes.php'); |
| 488 |
|
| 489 |
// pQuery |
| 490 |
include_once(PAGELAYER_DIR.'/lib/pquery/IQuery.php'); |
| 491 |
include_once(PAGELAYER_DIR.'/lib/pquery/gan_formatter.php'); |
| 492 |
include_once(PAGELAYER_DIR.'/lib/pquery/gan_node_html.php'); |
| 493 |
include_once(PAGELAYER_DIR.'/lib/pquery/gan_tokenizer.php'); |
| 494 |
include_once(PAGELAYER_DIR.'/lib/pquery/gan_parser_html.php'); |
| 495 |
include_once(PAGELAYER_DIR.'/lib/pquery/gan_selector_html.php'); |
| 496 |
include_once(PAGELAYER_DIR.'/lib/pquery/gan_xml2array.php'); |
| 497 |
include_once(PAGELAYER_DIR.'/lib/pquery/pQuery.php'); |
| 498 |
|
| 499 |
// Apply filter to load custom widgets |
| 500 |
do_action('pagelayer_load_custom_widgets'); |
| 501 |
|
| 502 |
} |
| 503 |
|
| 504 |
// Add the shortcodes to the pagelayer list |
| 505 |
function pagelayer_add_shortcode($tag, $params = array()){ |
| 506 |
|
| 507 |
global $pagelayer; |
| 508 |
|
| 509 |
// Is there a handler function ? |
| 510 |
if(!empty($params['func'])){ |
| 511 |
|
| 512 |
if($tag == 'pl_row'){ |
| 513 |
$inner_tag = 'pl_inner_row'; |
| 514 |
add_shortcode($inner_tag, 'pagelayer_render_shortcode'); |
| 515 |
} |
| 516 |
|
| 517 |
if($tag == 'pl_col'){ |
| 518 |
$inner_tag = 'pl_inner_col'; |
| 519 |
add_shortcode($inner_tag, 'pagelayer_render_shortcode'); |
| 520 |
} |
| 521 |
|
| 522 |
add_shortcode($tag, 'pagelayer_render_shortcode');//$params['func']); |
| 523 |
//unset($params['func']); |
| 524 |
} |
| 525 |
|
| 526 |
// Is there a group ? |
| 527 |
if(empty($params['group'])){ |
| 528 |
$params['group'] = 'misc'; |
| 529 |
} |
| 530 |
|
| 531 |
// Add the advanced styling group |
| 532 |
$params['options'] = [ |
| 533 |
'ele_bg_styles' => __pl('ele_bg_styles'), |
| 534 |
'ele_styles' => __pl('ele_styles'), |
| 535 |
'border_styles' => __pl('border_styles'), |
| 536 |
'position_styles' => __pl('position_styles'), |
| 537 |
'animation_styles' => __pl('animation_styles'), |
| 538 |
'responsive_styles' => __pl('responsive_styles'), |
| 539 |
'custom_styles' => __pl('custom_styles'), |
| 540 |
]; |
| 541 |
|
| 542 |
if(!empty($params['skip_props_cat'])){ |
| 543 |
foreach($params['skip_props_cat'] as $k => $v){ |
| 544 |
unset($params['options'][$v]); |
| 545 |
} |
| 546 |
} |
| 547 |
|
| 548 |
// Are the settings there which hold the params ? |
| 549 |
if(empty($params['settings'])){ |
| 550 |
$params['settings'] = [ |
| 551 |
'params' => $params['name'], |
| 552 |
]; |
| 553 |
} |
| 554 |
|
| 555 |
// Disable the style options |
| 556 |
if(!empty($params['styles'])){ |
| 557 |
$params['settings'] = array_merge($params['settings'], $params['styles']); |
| 558 |
unset($params['styles']); |
| 559 |
} |
| 560 |
|
| 561 |
/*// The following is for testing only |
| 562 |
$r = []; |
| 563 |
foreach($pagelayer->styles as $k => $v){ |
| 564 |
foreach($v as $kk => $vv){ |
| 565 |
$r[$kk] = $kk; |
| 566 |
} |
| 567 |
} |
| 568 |
//print_r($r);die(); |
| 569 |
|
| 570 |
foreach($params['settings'] as $k => $v){ |
| 571 |
if(empty($params[$k])) continue; |
| 572 |
foreach($params[$k] as $kk => $vv){ |
| 573 |
if(!empty($r[$kk])){ |
| 574 |
echo 'Duplicate KEY '.$kk.' in Shortcode '.$tag."<br>"; |
| 575 |
} |
| 576 |
} |
| 577 |
} |
| 578 |
//die();*/ |
| 579 |
|
| 580 |
// Insert the shortcode |
| 581 |
$pagelayer->shortcodes[$tag] = $params; |
| 582 |
$pagelayer->groups[$params['group']][] = $tag; |
| 583 |
|
| 584 |
} |
| 585 |
|
| 586 |
// Returns the Image values |
| 587 |
function pagelayer_image($id){ |
| 588 |
|
| 589 |
global $pagelayer; |
| 590 |
|
| 591 |
$ret = []; |
| 592 |
|
| 593 |
// External image ? |
| 594 |
if(pagelayer_is_external_img($id)){ |
| 595 |
|
| 596 |
$ret['url'] = $id; |
| 597 |
|
| 598 |
// Attachment |
| 599 |
}elseif(!empty($id)){ |
| 600 |
|
| 601 |
$id = (int) @$id; |
| 602 |
|
| 603 |
$image = get_post($id); |
| 604 |
|
| 605 |
// Is there an attachment which is an image ? |
| 606 |
if(!empty($image) && $image->post_type == 'attachment' && wp_attachment_is_image($id)){ |
| 607 |
|
| 608 |
// Need to export necessary media |
| 609 |
if(!empty($pagelayer->export_mode)){ |
| 610 |
$pagelayer->media_to_export[] = $id; |
| 611 |
} |
| 612 |
|
| 613 |
$sizes = get_intermediate_image_sizes(); |
| 614 |
array_unshift($sizes, 'full'); |
| 615 |
|
| 616 |
foreach($sizes as $size){ |
| 617 |
$src = wp_get_attachment_image_src($id, $size); |
| 618 |
$ret[$size.'-url'] = $src[0]; |
| 619 |
} |
| 620 |
|
| 621 |
// Title and Alt |
| 622 |
$title = esc_attr($image->post_title); |
| 623 |
$alt = get_post_meta($id, '_wp_attachment_image_alt', true); |
| 624 |
$alt = empty($alt) ? $image->post_excerpt : $alt; |
| 625 |
$alt = empty($alt) ? $image->post_title : $alt; |
| 626 |
$alt = empty($alt) ? '' : trim(strip_tags($alt)); |
| 627 |
$link = get_attachment_link($id); |
| 628 |
$caption = wp_get_attachment_caption($id); |
| 629 |
$caption = !empty($caption) ? $caption : ''; |
| 630 |
|
| 631 |
$ret['alt'] = $alt; |
| 632 |
$ret['title'] = $title; |
| 633 |
$ret['link'] = $link; |
| 634 |
$ret['caption'] = $caption; |
| 635 |
|
| 636 |
} |
| 637 |
|
| 638 |
} |
| 639 |
|
| 640 |
// First preference to full url |
| 641 |
if(!empty($ret['full-url'])){ |
| 642 |
$ret['url'] = $ret['full-url']; |
| 643 |
} |
| 644 |
|
| 645 |
// No image |
| 646 |
if(empty($ret['url'])){ |
| 647 |
$ret['url'] = PAGELAYER_URL.'/images/default-image.png'; |
| 648 |
} |
| 649 |
|
| 650 |
$ret = apply_filters('pagelayer_image', $ret); |
| 651 |
|
| 652 |
return $ret; |
| 653 |
|
| 654 |
} |
| 655 |
|
| 656 |
// Checks if the given parameter is an external link or a wp attachment id |
| 657 |
function pagelayer_is_external_img($img = ''){ |
| 658 |
|
| 659 |
if(empty($img)){ |
| 660 |
return false; |
| 661 |
} |
| 662 |
|
| 663 |
if(preg_match('#http://#is', $img) || preg_match('#https://#is', $img) || preg_match('#^{{#is', $img)){ |
| 664 |
return true; |
| 665 |
} |
| 666 |
|
| 667 |
return false; |
| 668 |
|
| 669 |
} |
| 670 |
|
| 671 |
// Returns the attachment url |
| 672 |
function pagelayer_attachment($id){ |
| 673 |
|
| 674 |
$ret = []; |
| 675 |
|
| 676 |
// External url ? |
| 677 |
if(pagelayer_is_external_img($id)){ |
| 678 |
|
| 679 |
$ret['url'] = $id; |
| 680 |
|
| 681 |
// Attachment |
| 682 |
}elseif(!empty($id)){ |
| 683 |
|
| 684 |
// Need to export necessary media |
| 685 |
if(!empty($pagelayer->export_mode)){ |
| 686 |
$pagelayer->media_to_export[] = $id; |
| 687 |
} |
| 688 |
|
| 689 |
$ret['url'] = wp_get_attachment_url($id); |
| 690 |
|
| 691 |
} |
| 692 |
|
| 693 |
$ret = apply_filters('pagelayer_attachment', $ret); |
| 694 |
|
| 695 |
return $ret; |
| 696 |
|
| 697 |
} |
| 698 |
|
| 699 |
// Convert the regular URL of a Video to a Embed URL |
| 700 |
// Todo : Check |
| 701 |
function pagelayer_video_url($source){ |
| 702 |
|
| 703 |
if (!empty($source)) { |
| 704 |
|
| 705 |
$source = esc_url( $source ); |
| 706 |
$source = str_replace('&', '&', $source); |
| 707 |
$url = parse_url($source); |
| 708 |
$videoSite =''; |
| 709 |
|
| 710 |
$youtubeRegExp = '/youtube\.com|youtu\.be/is'; |
| 711 |
$vimeoRegExp = '/vimeo\.com/is'; |
| 712 |
|
| 713 |
if (preg_match($youtubeRegExp, $source)) { |
| 714 |
$videoSite = 'youtube'; |
| 715 |
} else if (preg_match($vimeoRegExp, $source)) { |
| 716 |
$videoSite = 'vimeo'; |
| 717 |
} |
| 718 |
|
| 719 |
switch ($videoSite) { |
| 720 |
case 'youtube': |
| 721 |
|
| 722 |
if (preg_match('/youtube\.com/is', $source)) { |
| 723 |
|
| 724 |
if (preg_match('/watch/is', $source)) { |
| 725 |
parse_str($url['query'], $parameters); |
| 726 |
|
| 727 |
if (isset($parameters['v']) && !empty($parameters['v'])) { |
| 728 |
$videoId = $parameters['v']; |
| 729 |
} |
| 730 |
|
| 731 |
} else if (preg_match('/embed/is', $url['path'])) { |
| 732 |
$path = explode('/', $url['path']); |
| 733 |
if (isset($path[2]) && !empty($path[2])) { |
| 734 |
$videoId = $path[2]; |
| 735 |
} |
| 736 |
} |
| 737 |
|
| 738 |
} else if (preg_match('/youtu\.be/is', $url['host'])) { |
| 739 |
$path = explode('/', $url['path']); |
| 740 |
|
| 741 |
if (isset($path[1]) && !empty($path[1])) { |
| 742 |
$videoId = $path[1]; |
| 743 |
} |
| 744 |
|
| 745 |
} |
| 746 |
|
| 747 |
return '//youtube.com/embed/'.$videoId; |
| 748 |
|
| 749 |
break; |
| 750 |
case 'vimeo': |
| 751 |
|
| 752 |
if (preg_match('/player\.vimeo\.com/is', $url['host']) && preg_match('/video/is', $url['path'])) { |
| 753 |
$path = explode('/', $url['path']); |
| 754 |
|
| 755 |
if (isset($path[2]) && !empty($path[2])) { |
| 756 |
$videoId = $path[2]; |
| 757 |
} |
| 758 |
|
| 759 |
} else if (preg_match('/vimeo\.com/is', $url['host'])) { |
| 760 |
$path = explode('/', $url['path']); |
| 761 |
|
| 762 |
if (isset($path[1]) && !empty($path[1])) { |
| 763 |
$videoId = $path[1]; |
| 764 |
} |
| 765 |
|
| 766 |
} |
| 767 |
|
| 768 |
return '//player.vimeo.com/video/'.$videoId; |
| 769 |
|
| 770 |
break; |
| 771 |
default: |
| 772 |
|
| 773 |
return $source; |
| 774 |
|
| 775 |
} |
| 776 |
|
| 777 |
} |
| 778 |
} |
| 779 |
|
| 780 |
|
| 781 |
// As per the JS specification |
| 782 |
function pagelayer_escapeHTML($str){ |
| 783 |
|
| 784 |
$replace = [ |
| 785 |
']' => ']', |
| 786 |
'[' => '[', |
| 787 |
//'=' => '=', |
| 788 |
'<' => '<', |
| 789 |
'>' => '>', |
| 790 |
'"' => '"', |
| 791 |
//'&' => '&', |
| 792 |
'\'' => ''' |
| 793 |
]; |
| 794 |
|
| 795 |
$str = str_replace(array_keys($replace), array_values($replace), $str); |
| 796 |
|
| 797 |
return $str; |
| 798 |
} |
| 799 |
|
| 800 |
// As per the JS specification |
| 801 |
function pagelayer_unescapeHTML($str){ |
| 802 |
$replace = [ |
| 803 |
'#93' => ']', |
| 804 |
'#91' => '[', |
| 805 |
//'#61' => '=', |
| 806 |
'lt' => '<', |
| 807 |
'gt' => '>', |
| 808 |
'quot' => '"', |
| 809 |
//'amp' => '&', |
| 810 |
'#39' => '\'' |
| 811 |
]; |
| 812 |
|
| 813 |
foreach($replace as $k => $v){ |
| 814 |
$str = str_replace('&'.$k.';', $v, $str); |
| 815 |
} |
| 816 |
return $str; |
| 817 |
} |
| 818 |
|
| 819 |
// Show promo notice on dashboard |
| 820 |
function pagelayer_show_promo(){ |
| 821 |
|
| 822 |
global $pagelayer_promo_opts; |
| 823 |
$opts = $pagelayer_promo_opts; |
| 824 |
|
| 825 |
echo '<style> |
| 826 |
.pagelayer_promo_button { |
| 827 |
background-color: #4CAF50; /* Green */ |
| 828 |
border: none; |
| 829 |
color: white; |
| 830 |
padding: 6px 10px; |
| 831 |
text-align: center; |
| 832 |
text-decoration: none; |
| 833 |
display: inline-block; |
| 834 |
font-size: 13px; |
| 835 |
margin: 4px 2px; |
| 836 |
-webkit-transition-duration: 0.4s; /* Safari */ |
| 837 |
transition-duration: 0.4s; |
| 838 |
cursor: pointer; |
| 839 |
} |
| 840 |
.pagelayer_promo_button:focus, |
| 841 |
.pagelayer_promo_button:hover{ |
| 842 |
border: none; |
| 843 |
color: white; |
| 844 |
box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19); |
| 845 |
color: white; |
| 846 |
} |
| 847 |
.pagelayer_promo_buy { |
| 848 |
color: white; |
| 849 |
padding: 8px 12px; |
| 850 |
font-size: 14px; |
| 851 |
} |
| 852 |
.pagelayer_promo_button1 { |
| 853 |
color: white; |
| 854 |
background-color: #4CAF50; |
| 855 |
border:3px solid #4CAF50; |
| 856 |
} |
| 857 |
.pagelayer_promo_button1:hover { |
| 858 |
border:3px solid #4CAF50; |
| 859 |
} |
| 860 |
.pagelayer_promo_button2 { |
| 861 |
color: white; |
| 862 |
background-color: #0085ba; |
| 863 |
} |
| 864 |
.pagelayer_promo_button3 { |
| 865 |
color: white; |
| 866 |
background-color: #365899; |
| 867 |
} |
| 868 |
.pagelayer_promo_button4 { |
| 869 |
color: white; |
| 870 |
background-color: rgb(66, 184, 221); |
| 871 |
} |
| 872 |
.pagelayer_promo-close{ |
| 873 |
float:right; |
| 874 |
text-decoration:none; |
| 875 |
margin: 5px 10px 0px 0px; |
| 876 |
} |
| 877 |
.pagelayer_promo-close:hover{ |
| 878 |
color: red; |
| 879 |
} |
| 880 |
</style> |
| 881 |
<script type="application/javascript"> |
| 882 |
jQuery(document).ready(function(){ |
| 883 |
jQuery("#pagelayer_promo .pagelayer_promo-close").click(function(){ |
| 884 |
var data; |
| 885 |
jQuery("#pagelayer_promo").hide(); |
| 886 |
// Save this preference |
| 887 |
jQuery.post("'.admin_url('?pagelayer_promo=0').'", data, function(response) { |
| 888 |
//alert(response); |
| 889 |
}); |
| 890 |
}); |
| 891 |
}); |
| 892 |
</script> |
| 893 |
|
| 894 |
<div class="notice notice-success" id="pagelayer_promo" style="min-height:90px"> |
| 895 |
<a class="pagelayer_promo-close" href="javascript:" aria-label="Dismiss this Notice"> |
| 896 |
<span class="dashicons dashicons-dismiss"></span> Dismiss |
| 897 |
</a>'; |
| 898 |
|
| 899 |
if(!empty($opts['image'])){ |
| 900 |
echo '<a href="'.$opts['website'].'"><img src="'.$opts['image'].'" style="float:left; margin:10px 20px 10px 10px" width="67" /></a>'; |
| 901 |
} |
| 902 |
|
| 903 |
echo ' |
| 904 |
<p style="font-size:13px">We are glad you like <a href="'.$opts['website'].'"><b>Pagelayer</b></a> and have been using it since the past few days. It is time to take the next step !</p> |
| 905 |
<p> |
| 906 |
'.(empty($opts['pro_url']) ? '' : '<a class="pagelayer_promo_button pagelayer_promo_buy" target="_blank" href="'.$opts['pro_url'].'">Buy Pagelayer Pro</a>').' |
| 907 |
'.(empty($opts['rating']) ? '' : '<a class="pagelayer_promo_button pagelayer_promo_button2" target="_blank" href="'.$opts['rating'].'">Rate it 5� |
| 908 |
\'s</a>').' |
| 909 |
'.(empty($opts['facebook']) ? '' : '<a class="pagelayer_promo_button pagelayer_promo_button3" target="_blank" href="'.$opts['facebook'].'"><span class="dashicons dashicons-thumbs-up"></span> Facebook</a>').' |
| 910 |
'.(empty($opts['twitter']) ? '' : '<a class="pagelayer_promo_button pagelayer_promo_button4" target="_blank" href="'.$opts['twitter'].'"><span class="dashicons dashicons-twitter"></span> Tweet</a>').' |
| 911 |
'.(empty($opts['website']) ? '' : '<a class="pagelayer_promo_button pagelayer_promo_button4" target="_blank" href="'.$opts['website'].'">Visit our website</a>').' |
| 912 |
</p> |
| 913 |
<p style="font-size:13px"><a href="'.$opts['pro_url'].'"><b>Pagelayer Pro</b></a> has many more features like 60+ widgets, 400+ sections, Theme Builder, WooCommerce Builder, Theme Creator and Exporter, Form Builder, Popup Builder, etc.'; |
| 914 |
|
| 915 |
if(date('Ymd') <= 20200331){ |
| 916 |
echo '<br><span style="font-size: 14px"><b>Promotional Offer</b></span> : If you buy <a href="'.$opts['pro_url'].'"><b>Pagelayer Pro</b></a> before <b>31st March, 2020</b> then you will get an additional year free and your license will expire on <b>31st March, 2022</b>.'; |
| 917 |
} |
| 918 |
|
| 919 |
echo '</p></div>'; |
| 920 |
|
| 921 |
} |
| 922 |
|
| 923 |
// Are we to show a promo ? |
| 924 |
function pagelayer_maybe_promo($opts){ |
| 925 |
|
| 926 |
global $pagelayer_promo_opts; |
| 927 |
|
| 928 |
// There must be an interval |
| 929 |
if(empty($opts['interval'])){ |
| 930 |
return false; |
| 931 |
} |
| 932 |
|
| 933 |
// Are we to show a promo |
| 934 |
$opt_name = 'pagelayer_promo_time'; |
| 935 |
$promo_time = get_option($opt_name); |
| 936 |
|
| 937 |
// First time access |
| 938 |
if(empty($promo_time)){ |
| 939 |
update_option($opt_name, time() + (!empty($opts['after']) ? $opts['after'] * 86400 : 0)); |
| 940 |
$promo_time = get_option($opt_name); |
| 941 |
} |
| 942 |
|
| 943 |
// Is there interval elapsed |
| 944 |
if(time() > $promo_time){ |
| 945 |
$pagelayer_promo_opts = $opts; |
| 946 |
add_action('admin_notices', 'pagelayer_show_promo'); |
| 947 |
} |
| 948 |
|
| 949 |
// Are we to disable the promo |
| 950 |
if(isset($_GET['pagelayer_promo']) && (int)$_GET['pagelayer_promo'] == 0){ |
| 951 |
update_option($opt_name, time() + ($opts['interval'] * 86400)); |
| 952 |
die('DONE'); |
| 953 |
} |
| 954 |
|
| 955 |
} |
| 956 |
|
| 957 |
// Bread Crumbs with links |
| 958 |
function pagelayer_get_breadcrumb(){ |
| 959 |
|
| 960 |
// Home page |
| 961 |
$ret = '<a href="'.home_url().'" rel="nofollow">{{home}}</a>'; |
| 962 |
|
| 963 |
// Is Front page |
| 964 |
if(is_front_page()){ |
| 965 |
return $ret; |
| 966 |
|
| 967 |
// Is search query |
| 968 |
}elseif(is_search()){ |
| 969 |
$ret .= '<b class="pagelayer-breadcrumb-sep" if="{{separator}}">{{separator}}</b><b class="pagelayer-breadcrumb-prefix" if="{{search_prefix}}">{{search_prefix}}</b>'; |
| 970 |
$ret .= '<em>'; |
| 971 |
$ret .= get_search_query(); |
| 972 |
$ret .= '</em>'; |
| 973 |
|
| 974 |
//Is category or single post |
| 975 |
}elseif(is_category() || is_single()){ |
| 976 |
|
| 977 |
$ret .= '<b class="pagelayer-breadcrumb-sep" if="{{separator}}">{{separator}}</b>'; |
| 978 |
$categories = get_the_category(); |
| 979 |
$separator = ' '; |
| 980 |
$output = ''; |
| 981 |
if(!empty($categories)){ |
| 982 |
$ret .= get_category_parents($categories[0], true, ' <b class="pagelayer-breadcrumb-sep" if="{{separator}}">{{separator}}</b> '); |
| 983 |
} |
| 984 |
if(is_single()) { |
| 985 |
/* if (empty($categories)){ |
| 986 |
$ret .= ' <b class="pagelayer-breadcrumb-sep" if="{{separator}}">{{separator}}</b> '; |
| 987 |
} */ |
| 988 |
$ret .= get_the_title(); |
| 989 |
} |
| 990 |
|
| 991 |
// Is page |
| 992 |
}elseif(is_page()){ |
| 993 |
$ret .= '<b class="pagelayer-breadcrumb-sep" if="{{separator}}">{{separator}}</b>'; |
| 994 |
$ret .= get_the_title(); |
| 995 |
}else{ |
| 996 |
$ret .= '<b class="pagelayer-breadcrumb-sep" if="{{separator}}">{{separator}}</b>'; |
| 997 |
$ret .= wp_title('', false ); |
| 998 |
} |
| 999 |
|
| 1000 |
// wooCommerce Integration left |
| 1001 |
|
| 1002 |
return $ret; |
| 1003 |
} |
| 1004 |
|
| 1005 |
// Portfolio Posts |
| 1006 |
function pagelayer_widget_posts($args){ |
| 1007 |
|
| 1008 |
$r = new \WP_Query($args); |
| 1009 |
|
| 1010 |
$ret = ''; |
| 1011 |
if ( $r->have_posts() ){ |
| 1012 |
|
| 1013 |
if($args['filter_by'] != 'none' && $args['post_type'] == 'post'){ |
| 1014 |
$ret .= '<div class="pagelayer-postfolio-filter">'; |
| 1015 |
|
| 1016 |
$data_filter = ( $args['filter_by'] == 'category' ? get_categories() : get_tags() ); |
| 1017 |
|
| 1018 |
if(!empty($data_filter)){ |
| 1019 |
|
| 1020 |
$ret .= '<div class="pagelayer-postfolio-btn" data-filter="all">'.__pl('All').'</div>'; |
| 1021 |
|
| 1022 |
foreach($data_filter as $filter) { |
| 1023 |
$ret .= '<div class="pagelayer-postfolio-btn" data-filter="'.$filter->name.'">' . $filter->name . '</div>'; |
| 1024 |
} |
| 1025 |
|
| 1026 |
} |
| 1027 |
|
| 1028 |
$ret .= '</div>'; |
| 1029 |
} |
| 1030 |
|
| 1031 |
$ret .= '<div class="pagelayer-postfolio-container">'; |
| 1032 |
|
| 1033 |
while ( $r->have_posts() ) : $r->the_post(); |
| 1034 |
$post_meta = ( $args['filter_by'] == 'category' ? get_the_category() : get_the_tags() ); |
| 1035 |
$meta_attr = ''; |
| 1036 |
if($post_meta){ |
| 1037 |
|
| 1038 |
$meta_array = array(); |
| 1039 |
foreach( $post_meta as $meta ){ |
| 1040 |
$meta_array[] = $meta->name; |
| 1041 |
} |
| 1042 |
$meta_attr .= ' data-category="'.implode(' ', $meta_array).'"'; |
| 1043 |
} |
| 1044 |
|
| 1045 |
$ret .= '<div class="pagelayer-postfolio-thumb"'.(has_post_thumbnail() ? ' style="background:url('.get_the_post_thumbnail_url().')"' : ''). $meta_attr .'>'; |
| 1046 |
$ret .= '<a href="'.esc_url( get_permalink() ).'" rel="bookmark">'; |
| 1047 |
$ret .= '<div class="pagelayer-postfolio-content">'; |
| 1048 |
$ret .= '<h4 class="pagelayer-entry-title">'.get_the_title().'</h4>'; |
| 1049 |
$ret .= '</div></a></div>'; |
| 1050 |
|
| 1051 |
endwhile; |
| 1052 |
|
| 1053 |
$ret .= '</div>'; |
| 1054 |
|
| 1055 |
} |
| 1056 |
|
| 1057 |
return $ret; |
| 1058 |
} |
| 1059 |
|
| 1060 |
// List all available sizes of images registered on WordPress |
| 1061 |
function pagelayer_image_sizes(){ |
| 1062 |
|
| 1063 |
$sizes = array(); |
| 1064 |
$sizes = get_intermediate_image_sizes(); |
| 1065 |
$ret = array(); |
| 1066 |
foreach($sizes as $size){ |
| 1067 |
$ret[$size] = __pl($size); |
| 1068 |
} |
| 1069 |
|
| 1070 |
return $ret; |
| 1071 |
} |
| 1072 |
|
| 1073 |
function pagelayer_remove_excerpt_more($more){ |
| 1074 |
return ''; |
| 1075 |
} |
| 1076 |
|
| 1077 |
function pagelayer_posts($params, $args = []){ |
| 1078 |
|
| 1079 |
// If args is empty |
| 1080 |
if(empty($args)){ |
| 1081 |
$args = array( |
| 1082 |
'post_type' => $params['post_type'], |
| 1083 |
'posts_per_page' => $params['posts_per_page'], |
| 1084 |
'order' => $params['order'] |
| 1085 |
); |
| 1086 |
|
| 1087 |
if($params['exc_length']){ |
| 1088 |
$exc_length = (int) $params['exc_length']; |
| 1089 |
add_filter( 'excerpt_length', function($length) use($exc_length){ |
| 1090 |
return $exc_length; |
| 1091 |
}, 999 ); |
| 1092 |
} |
| 1093 |
|
| 1094 |
add_filter('excerpt_more', 'pagelayer_remove_excerpt_more', 999); |
| 1095 |
|
| 1096 |
if($params['term']){ |
| 1097 |
|
| 1098 |
$term = explode(':', $params['term']); |
| 1099 |
//pagelayer_print($term); |
| 1100 |
if($term[0] == 'category'){ |
| 1101 |
$args['category_name'] = $term[1]; |
| 1102 |
} |
| 1103 |
if($term[0] == 'post_tag'){ |
| 1104 |
$args['tag'] = $term[1]; |
| 1105 |
} |
| 1106 |
} |
| 1107 |
|
| 1108 |
if($params['exc_term']){ |
| 1109 |
|
| 1110 |
$term = explode(':', $params['exc_term']); |
| 1111 |
//pagelayer_print($term); |
| 1112 |
if($term[0] == 'category'){ |
| 1113 |
$args['category__not_in'] = $term[2]; |
| 1114 |
} |
| 1115 |
if($term[0] == 'post_tag'){ |
| 1116 |
$args['tag__not_in'] = $term[2]; |
| 1117 |
} |
| 1118 |
} |
| 1119 |
|
| 1120 |
if($params['author_name']){ |
| 1121 |
$author_name = explode(':', $params['author_name']); |
| 1122 |
$args['author_name'] = $author_name[0]; |
| 1123 |
} |
| 1124 |
|
| 1125 |
if($params['exc_author']){ |
| 1126 |
$exc_author = explode(':', $params['exc_author']); |
| 1127 |
$args['author'] = '-'.$exc_author[1]; |
| 1128 |
} |
| 1129 |
|
| 1130 |
if(!empty($params['offset'])){ |
| 1131 |
$args['offset'] = $params['offset']; |
| 1132 |
} |
| 1133 |
|
| 1134 |
if(!empty($params['ignore_sticky'])){ |
| 1135 |
$args['ignore_sticky_posts'] = $params['ignore_sticky']; |
| 1136 |
} |
| 1137 |
|
| 1138 |
if(!empty($params['orderby'])){ |
| 1139 |
$args['orderby'] = $params['orderby']; |
| 1140 |
} |
| 1141 |
|
| 1142 |
if($params['by_period']){ |
| 1143 |
$date_arg = array(); |
| 1144 |
switch($params['by_period']){ |
| 1145 |
case 'last_day': |
| 1146 |
$date_arg['day'] = date('j')-1; |
| 1147 |
break; |
| 1148 |
case 'last_week': |
| 1149 |
$date_arg['week'] = date('W')-1; |
| 1150 |
break; |
| 1151 |
case 'last_month': |
| 1152 |
$date_arg['month'] = date('n')-1; |
| 1153 |
break; |
| 1154 |
case 'last_year': |
| 1155 |
$date_arg['year'] = date('Y')-1; |
| 1156 |
break; |
| 1157 |
case 'custom': |
| 1158 |
$date_arg['before'] = $params['before_date']; |
| 1159 |
$date_arg['after'] = $params['after_date']; |
| 1160 |
break; |
| 1161 |
} |
| 1162 |
$args['date_query'] = array( |
| 1163 |
$date_arg |
| 1164 |
); |
| 1165 |
} |
| 1166 |
} |
| 1167 |
//pagelayer_print($args); |
| 1168 |
|
| 1169 |
$postsquery = new WP_Query($args); |
| 1170 |
$data = ''; |
| 1171 |
|
| 1172 |
if(!$postsquery->have_posts()){ |
| 1173 |
return '<h3>Something went wrong, Please give proper inputs!</h3>'; |
| 1174 |
} |
| 1175 |
|
| 1176 |
while($postsquery->have_posts()) : $postsquery->the_post(); |
| 1177 |
$data .= '<div class="pagelayer-wposts-col"> |
| 1178 |
<div class="pagelayer-wposts-post"> |
| 1179 |
<div class="pagelayer-wposts-featured">'; |
| 1180 |
$data .= '<a href="'. get_the_permalink() .'">'; |
| 1181 |
|
| 1182 |
if(isset($params['show_thumb']) && has_post_thumbnail( $postsquery->ID )){ |
| 1183 |
$data .= '<div class="pagelayer-wposts-thumb"'.(has_post_thumbnail() ? ' style="background:url('.get_the_post_thumbnail_url($postsquery->ID,$params['thumb_size']).')"' : '').'></div>'; |
| 1184 |
} |
| 1185 |
/* if($params['show_thumb'] && has_post_thumbnail( $postsquery->ID )){ |
| 1186 |
$data .= get_the_post_thumbnail_url($postsquery->ID,$params['thumb_size']); |
| 1187 |
} */ |
| 1188 |
$data .= '</a></div> |
| 1189 |
<div class="pagelayer-wposts-content">'; |
| 1190 |
|
| 1191 |
if(isset($params['show_title'])){ |
| 1192 |
$data .= '<a href="'.esc_url( get_permalink() ).'" rel="bookmark"><div class="pagelayer-wposts-title">'. get_the_title().'</div></a>'; |
| 1193 |
} |
| 1194 |
|
| 1195 |
$data .= '<div class="pagelayer-wposts-meta">'; |
| 1196 |
$sep = ''; |
| 1197 |
if(isset($params['meta_sep'])){ |
| 1198 |
$sep = '<b class="pagelayer-wposts-sep">'.$params['meta_sep'].'</b>'; |
| 1199 |
} |
| 1200 |
if(isset($params['author'])){ |
| 1201 |
$data .= '<span class="pagelayer-wposts-author">By <a class="pagelayer-wposts-author-url" href="'.esc_url(get_author_posts_url(get_the_author_meta('ID'))).'">'.esc_html(get_the_author()).'</a></span>'.$sep; |
| 1202 |
} |
| 1203 |
if(isset($params['date'])){ |
| 1204 |
$data .= '<span class="pagelayer-wposts-date"><time class="pagelayer-wposts-entry-date published updated" datetime="'.get_the_date('c').'"><span class="date-d">'.get_the_date('j').'</span><span class="date-my">'.get_the_date('M, y').'</span></time></span>'.$sep; |
| 1205 |
} |
| 1206 |
if(isset($params['category'])){ |
| 1207 |
$category = get_the_category(); |
| 1208 |
$singlecategory = ''; |
| 1209 |
foreach( $category as $cat ){ |
| 1210 |
$singlecategory .= '<a href="' . get_tag_link( $cat->term_id ) . '">'. $cat->name .'</a>'; |
| 1211 |
} |
| 1212 |
$data .= '<span class="pagelayer-wposts-category">' . $singlecategory . '</span>'.$sep; |
| 1213 |
} |
| 1214 |
if(isset($params['tags'])){ |
| 1215 |
$tags = get_the_tags(); |
| 1216 |
$singletag = ''; |
| 1217 |
if(!empty($tags)){ |
| 1218 |
foreach( $tags as $tag ){ |
| 1219 |
$singletag .= '<a href="' . get_tag_link( $tag->term_id ) . '">'. $tag->name .'</a>'; |
| 1220 |
} |
| 1221 |
if(!empty($singletag)){ |
| 1222 |
$data .= '<span class="pagelayer-wposts-tags">'.$singletag.'</span>'.$sep; |
| 1223 |
} |
| 1224 |
} |
| 1225 |
|
| 1226 |
} |
| 1227 |
if(isset($params['comments'])){ |
| 1228 |
$data .= '<span class="pagelayer-wposts-comments"><i class="far fa-comment"></i><a href="' . esc_url( get_permalink() ) . '">' . esc_html(get_comments_number()) . '</a></span>'.$sep; |
| 1229 |
} |
| 1230 |
|
| 1231 |
$data .= '</div>'; |
| 1232 |
|
| 1233 |
if(isset($params['show_content'])){ |
| 1234 |
$data .= '<div class="pagelayer-wposts-excerpt">'; |
| 1235 |
if($params['show_content'] == 'excerpt'){ |
| 1236 |
$data .= do_shortcode(get_the_excerpt()); |
| 1237 |
}elseif($params['show_content'] == 'full'){ |
| 1238 |
$data .= do_shortcode(get_the_content()); |
| 1239 |
} |
| 1240 |
$data .= '</div>'; |
| 1241 |
} |
| 1242 |
|
| 1243 |
if(isset($params['show_more'])){ |
| 1244 |
$data .= '<div class="pagelayer-wposts-mdiv"><a class="pagelayer-wposts-more pagelayer-btn-holder pagelayer-ele-link '.$params['btn_type'].' '.$params['size'].' '.$params['icon_position'].'" href="'. get_the_permalink().'">'; |
| 1245 |
|
| 1246 |
if($params['icon']){ |
| 1247 |
$data .= '<i class="'.$params['icon'].' pagelayer-btn-icon"></i>'; |
| 1248 |
} |
| 1249 |
|
| 1250 |
if($params['more']){ |
| 1251 |
$data .= '<span class="pagelayer-btn-text">'.$params['more'].'</span>'; |
| 1252 |
} |
| 1253 |
|
| 1254 |
if($params['icon']){ |
| 1255 |
$data .= '<i class="'.$params['icon'].' pagelayer-btn-icon"></i>'; |
| 1256 |
} |
| 1257 |
|
| 1258 |
$data .= '</a></div>'; |
| 1259 |
|
| 1260 |
//$data .= '<a class="pagelayer-wposts-more" href="'. get_the_permalink().'">'.$params['more'].'</a>'; |
| 1261 |
} |
| 1262 |
|
| 1263 |
//$data .= '<div class="pagelayer-wposts-date"><p>'.get_the_date().'</p></div>'; |
| 1264 |
$data .= '</div></div></div>'; |
| 1265 |
endwhile; |
| 1266 |
|
| 1267 |
return $data; |
| 1268 |
} |
| 1269 |
|
| 1270 |
// Get Post Revision |
| 1271 |
function pagelayer_get_post_revision_by_id($postID){ |
| 1272 |
|
| 1273 |
// Insert the post revision into the database |
| 1274 |
$post_revisions = array(); |
| 1275 |
$reviews = wp_get_post_revisions($postID); |
| 1276 |
|
| 1277 |
foreach($reviews as $values){ |
| 1278 |
|
| 1279 |
$date_format = date_i18n('j-M @ H:i', strtotime( $values->post_modified ) ); |
| 1280 |
$user_meta = get_userdata($values->post_author); |
| 1281 |
|
| 1282 |
if ( false !== strpos( $values->post_name, 'autosave' ) ) { |
| 1283 |
$type = 'autosave'; |
| 1284 |
} else { |
| 1285 |
$type = 'revision'; |
| 1286 |
} |
| 1287 |
|
| 1288 |
$post_tmp_data = array( |
| 1289 |
'ID' => $values->ID, |
| 1290 |
'post_author_name' => $user_meta->data->display_name, |
| 1291 |
'post_author_url' => get_avatar_url($values->post_author), |
| 1292 |
'post_date' => $date_format, |
| 1293 |
'post_date_ago' => human_time_diff(strtotime($values->post_modified), current_time( 'timestamp' )) . ' ago ', |
| 1294 |
'post_type' => $type, |
| 1295 |
); |
| 1296 |
|
| 1297 |
$post_revisions[] = $post_tmp_data; |
| 1298 |
} |
| 1299 |
|
| 1300 |
return $post_revisions; |
| 1301 |
} |
| 1302 |
|
| 1303 |
// Gets author data |
| 1304 |
function pagelayer_author_data($postID){ |
| 1305 |
|
| 1306 |
$authorID = get_post_field('post_author', $postID); |
| 1307 |
$data['display_name'] = get_the_author_meta( 'display_name' , $authorID ); |
| 1308 |
$data['description'] = get_the_author_meta( 'description' , $authorID ); |
| 1309 |
$data['user_url'] = get_author_posts_url( $authorID , '' ); |
| 1310 |
$data['avatar'] = get_avatar_url( $authorID ); |
| 1311 |
|
| 1312 |
return $data; |
| 1313 |
} |
| 1314 |
|
| 1315 |
// Posts Slider |
| 1316 |
function pagelayer_posts_slider($params){ |
| 1317 |
|
| 1318 |
$args = array(); |
| 1319 |
|
| 1320 |
if(isset($params['post']['post_type'])){ |
| 1321 |
$args['post_type'] = $params['post']['post_type']; |
| 1322 |
} |
| 1323 |
|
| 1324 |
if(isset($params['post']['category'])){ |
| 1325 |
$args['category_name'] = $params['post']['category']; |
| 1326 |
} |
| 1327 |
|
| 1328 |
if(isset($params['post']['tags'])){ |
| 1329 |
$args['tag'] = $params['post']['tags']; |
| 1330 |
} |
| 1331 |
|
| 1332 |
if(isset($params['post']['order_by'])){ |
| 1333 |
$args['orderby'] = $params['post']['order_by']; |
| 1334 |
} |
| 1335 |
|
| 1336 |
if(isset($params['post']['sort_order'])){ |
| 1337 |
$args['order'] = $params['post']['sort_order']; |
| 1338 |
} |
| 1339 |
|
| 1340 |
if(isset($params['post']['post_count'])){ |
| 1341 |
$args['posts_per_page'] = $params['post']['post_count']; |
| 1342 |
} |
| 1343 |
|
| 1344 |
$data = ''; |
| 1345 |
$postsquery = new WP_Query($args); |
| 1346 |
if ( $postsquery->have_posts() ){ |
| 1347 |
while ( $postsquery->have_posts() ) : $postsquery->the_post(); |
| 1348 |
$data .= '<li class="pagelayer-posts-slider-col"> |
| 1349 |
<div class="pagelayer-posts-slider-post"> |
| 1350 |
<div class="pagelayer-posts-slider-featured-img">'; |
| 1351 |
$data .= '<a href="'. get_the_permalink() .'">'; |
| 1352 |
if(has_post_thumbnail( $postsquery->ID ) ){ |
| 1353 |
if($params['post']['image_size'] == "full" || $params['post']['image_size'] == "custom" ){ |
| 1354 |
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $postsquery->ID ), 'single-post-thumbnail' ); |
| 1355 |
$data .= '<img class="pagelayer-img" src="'.$image[0].'" class="pagelayer-posts-slider-img">'; |
| 1356 |
}else if($params['post']['image_size'] == "thumbnail"){ |
| 1357 |
$data .= get_the_post_thumbnail(); |
| 1358 |
} |
| 1359 |
} |
| 1360 |
$data .= '</a></div> |
| 1361 |
<div class="pagelayer-posts-slider-content">'; |
| 1362 |
$data .= '<p class="pagelayer-posts-slider-title">'. get_the_title().'</p>'; |
| 1363 |
$data .= '<div class="pagelayer-posts-slider-excerpt">'; |
| 1364 |
if($params['post']['show_excerpt'] == "true"){ |
| 1365 |
if(has_excerpt()){ |
| 1366 |
$excerpt = get_the_excerpt(); |
| 1367 |
$data .= do_shortcode($excerpt); |
| 1368 |
} |
| 1369 |
} |
| 1370 |
$data .= '</div>'; |
| 1371 |
$data .= '<a class="pagelayer-posts-slider-link" href="'. get_the_permalink().'">Read More</a>'; |
| 1372 |
$data .= '<div class="pagelayer-post-slider-date"><p>'.get_the_date().'</p></div>'; |
| 1373 |
$data .= '</div></div></li>'; |
| 1374 |
endwhile; |
| 1375 |
} |
| 1376 |
return $data; |
| 1377 |
} |
| 1378 |
|
| 1379 |
// Gets the site logo URLs |
| 1380 |
function pagelayer_site_logo(){ |
| 1381 |
|
| 1382 |
if(get_theme_mod('custom_logo')){ |
| 1383 |
$logo_id = get_theme_mod('custom_logo'); |
| 1384 |
return pagelayer_image($logo_id); |
| 1385 |
} |
| 1386 |
|
| 1387 |
return NULL; |
| 1388 |
} |
| 1389 |
|
| 1390 |
// Create select options |
| 1391 |
function pagelayer_create_sel_options( $opt_array , $selected = ''){ |
| 1392 |
$options = ''; |
| 1393 |
foreach($opt_array as $x => $val){ |
| 1394 |
|
| 1395 |
// Single item |
| 1396 |
if(is_string($opt_array[$x])){ |
| 1397 |
$options .= pagelayer_sel_option($x, $val, $selected); |
| 1398 |
|
| 1399 |
// Groups |
| 1400 |
}else{ |
| 1401 |
|
| 1402 |
// If Label is there, then its a normal option |
| 1403 |
if(array_key_exists('label', $opt_array[$x])){ |
| 1404 |
$options .= pagelayer_sel_option($x, $opt_array[$x]['label'], $selected); |
| 1405 |
|
| 1406 |
// Optgroups |
| 1407 |
} else{ |
| 1408 |
$options .= '<optgroup label="'. $x .'">'; |
| 1409 |
$options .= pagelayer_create_sel_options($opt_array[$x], $selected); |
| 1410 |
$options .= '</optgroup>'; |
| 1411 |
} |
| 1412 |
} |
| 1413 |
} |
| 1414 |
|
| 1415 |
return $options; |
| 1416 |
} |
| 1417 |
|
| 1418 |
// Create option HTML |
| 1419 |
function pagelayer_sel_option($val, $lang, $selected){ |
| 1420 |
return '<option value="'. $val .'" '. (($val != $selected) ? '' : 'selected="selected"') .' >'. $lang .'</option>'; |
| 1421 |
} |
| 1422 |
|
| 1423 |
// Get values from multi-dimensional array by key |
| 1424 |
function pagelayer_multi_array_search(&$array, $key){ |
| 1425 |
|
| 1426 |
if(!is_array($array)){ |
| 1427 |
return false; |
| 1428 |
} |
| 1429 |
|
| 1430 |
foreach ($array as $k => $v) { |
| 1431 |
|
| 1432 |
if($k == $key){ |
| 1433 |
return $v; |
| 1434 |
} |
| 1435 |
|
| 1436 |
if (is_array($v)) { |
| 1437 |
$found = pagelayer_multi_array_search($v, $key); |
| 1438 |
if(!empty($found)){ |
| 1439 |
return $found; |
| 1440 |
} |
| 1441 |
} |
| 1442 |
} |
| 1443 |
|
| 1444 |
return false; |
| 1445 |
} |
| 1446 |
|
| 1447 |
function pagelayer_get_post_term(){ |
| 1448 |
|
| 1449 |
$args = [ |
| 1450 |
'taxonomy' => array('category','post_tag'), |
| 1451 |
'hide_empty' => false, |
| 1452 |
]; |
| 1453 |
|
| 1454 |
$terms = get_terms( $args ); |
| 1455 |
|
| 1456 |
$ret = array(); |
| 1457 |
foreach ( $terms as $term ) { |
| 1458 |
$ret[$term->taxonomy.':'.$term->slug.':'.$term->term_taxonomy_id] = $term->taxonomy .': '. $term->name; |
| 1459 |
} |
| 1460 |
//pagelayer_print($terms);die(); |
| 1461 |
return $ret; |
| 1462 |
} |
| 1463 |
|
| 1464 |
function pagelayer_get_post_author(){ |
| 1465 |
|
| 1466 |
$args = [ |
| 1467 |
'who' => 'authors', |
| 1468 |
'fields' => [ |
| 1469 |
'ID', |
| 1470 |
'display_name', |
| 1471 |
'user_nicename', |
| 1472 |
] |
| 1473 |
]; |
| 1474 |
|
| 1475 |
$authors = new \WP_User_Query( $args ); |
| 1476 |
|
| 1477 |
$ret = array(); |
| 1478 |
foreach ( $authors->get_results() as $author ) { |
| 1479 |
$ret[$author->user_nicename.':'.$author->ID] = $author->display_name; |
| 1480 |
} |
| 1481 |
//pagelayer_print($authors->get_results());die(); |
| 1482 |
return $ret; |
| 1483 |
} |
| 1484 |
|
| 1485 |
// Gets the registered post types |
| 1486 |
function pagelayer_get_public_post_types( $args = [] ) { |
| 1487 |
|
| 1488 |
global $pagelayer; |
| 1489 |
|
| 1490 |
$post_type_args = [ |
| 1491 |
'public' => true, |
| 1492 |
]; |
| 1493 |
|
| 1494 |
$post_type_args = wp_parse_args( $post_type_args, $args ); |
| 1495 |
|
| 1496 |
$_post_types = get_post_types( $post_type_args, 'objects' ); |
| 1497 |
|
| 1498 |
$post_types = array(); |
| 1499 |
|
| 1500 |
foreach ( $_post_types as $post_type => $object ) { |
| 1501 |
|
| 1502 |
if($post_type == $pagelayer->builder['name']){ |
| 1503 |
continue; |
| 1504 |
} |
| 1505 |
|
| 1506 |
$post_types[ $post_type ] = $object->label; |
| 1507 |
} |
| 1508 |
//print_r($post_types); |
| 1509 |
|
| 1510 |
return $post_types; |
| 1511 |
} |
| 1512 |
|
| 1513 |
// Simply echo and dir |
| 1514 |
function pagelayer_json_output(&$done){ |
| 1515 |
|
| 1516 |
echo json_encode($done); |
| 1517 |
wp_die(); |
| 1518 |
|
| 1519 |
} |
| 1520 |
|
| 1521 |
// Get the current query for render the product |
| 1522 |
function pagelayer_shortcode_current_query($query_args, $atts, $type){ |
| 1523 |
global $wp_query; |
| 1524 |
|
| 1525 |
if($type == 'pagelayer_current_query'){ |
| 1526 |
|
| 1527 |
if ( ! is_page( wc_get_page_id( 'shop' ) ) ) { |
| 1528 |
$query_args = $wp_query->query_vars; |
| 1529 |
} |
| 1530 |
|
| 1531 |
add_action( "woocommerce_shortcode_before_{$type}_loop", function () { |
| 1532 |
wc_set_loop_prop( 'is_shortcode', false ); |
| 1533 |
} ); |
| 1534 |
|
| 1535 |
if(!empty($atts['paginate'])){ |
| 1536 |
$page = get_query_var( 'paged', 1 ); |
| 1537 |
|
| 1538 |
if( 1 < $page ) { |
| 1539 |
$query_args['paged'] = $page; |
| 1540 |
} |
| 1541 |
} |
| 1542 |
|
| 1543 |
// Always query only IDs |
| 1544 |
$query_args['fields'] = 'ids'; |
| 1545 |
|
| 1546 |
} |
| 1547 |
|
| 1548 |
return $query_args; |
| 1549 |
} |
| 1550 |
|
| 1551 |
function pagelayer_export_content($content){ |
| 1552 |
|
| 1553 |
// Just call do_shortcode so we can get list of media files to export |
| 1554 |
//do_shortcode($content); |
| 1555 |
|
| 1556 |
$theme_url = preg_replace('/http(s?):\/\//is', '', get_stylesheet_directory_uri()); |
| 1557 |
|
| 1558 |
$content = preg_replace('/http(s?):\/\/'.preg_quote($theme_url, '/').'/is', '{{theme_url}}', $content); |
| 1559 |
|
| 1560 |
// Apply a filter |
| 1561 |
$content = apply_filters('pagelayer_export_content', $content); |
| 1562 |
|
| 1563 |
return $content; |
| 1564 |
|
| 1565 |
} |
| 1566 |
|
| 1567 |
// Insert a post which is a Pagelayer Post |
| 1568 |
function pagelayer_insert_content($post, &$ret){ |
| 1569 |
|
| 1570 |
// Replace Vars |
| 1571 |
$template_vars = pagelayer_template_vars(); |
| 1572 |
|
| 1573 |
foreach($template_vars as $key => $val){ |
| 1574 |
$post['post_content'] = str_replace($key, $val, $post['post_content']); |
| 1575 |
} |
| 1576 |
|
| 1577 |
//pagelayer_print($post);die(); |
| 1578 |
|
| 1579 |
// Add slashes for safe insert |
| 1580 |
$post['post_content'] = wp_slash($post['post_content']); |
| 1581 |
|
| 1582 |
// Now insert / update the post |
| 1583 |
$ret = wp_insert_post($post); |
| 1584 |
|
| 1585 |
// Did we save the post ? |
| 1586 |
if(empty($ret) || is_wp_error($ret)){ |
| 1587 |
return false; |
| 1588 |
} |
| 1589 |
|
| 1590 |
// Convert to pagelayer accessed post |
| 1591 |
if(!add_post_meta($ret, 'pagelayer-data', time(), true)){ |
| 1592 |
update_post_meta($ret, 'pagelayer-data', time()); |
| 1593 |
} |
| 1594 |
|
| 1595 |
return $ret; |
| 1596 |
|
| 1597 |
} |
| 1598 |
|
| 1599 |
// Gets the list of enabled fonts |
| 1600 |
function pagelayer_enabled_icons(){ |
| 1601 |
|
| 1602 |
$stored_icons = get_option('pagelayer_icons_set'); |
| 1603 |
if(empty($stored_icons)){ |
| 1604 |
update_option('pagelayer_icons_set', ['font-awesome5']); |
| 1605 |
$stored_icons = get_option('pagelayer_icons_set'); |
| 1606 |
} |
| 1607 |
|
| 1608 |
return $stored_icons; |
| 1609 |
|
| 1610 |
} |
| 1611 |
|
| 1612 |
// Install the Pro version |
| 1613 |
function pagelayer_install_pro(){ |
| 1614 |
|
| 1615 |
global $pagelayer; |
| 1616 |
|
| 1617 |
// Include the necessary stuff |
| 1618 |
include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); |
| 1619 |
|
| 1620 |
// Includes necessary for Plugin_Upgrader and Plugin_Installer_Skin |
| 1621 |
include_once( ABSPATH . 'wp-admin/includes/file.php' ); |
| 1622 |
include_once( ABSPATH . 'wp-admin/includes/misc.php' ); |
| 1623 |
include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); |
| 1624 |
|
| 1625 |
// Filter to prevent the activate text |
| 1626 |
add_filter('install_plugin_complete_actions', 'pagelayer_install_plugin_complete_actions', 10, 3); |
| 1627 |
|
| 1628 |
$upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( ) ); |
| 1629 |
$installed = $upgrader->install(PAGELAYER_API.'download.php?version=latest&license='.$pagelayer->license['license']); |
| 1630 |
|
| 1631 |
if ( !is_wp_error( $installed ) && $installed ) { |
| 1632 |
echo 'Activating Pagelayer Pro !'; |
| 1633 |
$activate = activate_plugin(PAGELAYER_PRO_BASE); |
| 1634 |
|
| 1635 |
if ( is_null($activate) ) { |
| 1636 |
echo '<div id="message" class="updated"><p>'. __('Done! Pagelayer Pro is now installed and activated.', 'pagelayer'). '</p></div><br />'; |
| 1637 |
echo '<br><br><b>Done! Pagelayer Pro is now installed and activated.</b>'; |
| 1638 |
} |
| 1639 |
} |
| 1640 |
|
| 1641 |
return $installed; |
| 1642 |
|
| 1643 |
} |
| 1644 |
|
| 1645 |
// Prevent pro activate text for installer |
| 1646 |
function pagelayer_install_plugin_complete_actions($install_actions, $api, $plugin_file){ |
| 1647 |
|
| 1648 |
if($plugin_file == PAGELAYER_PRO_BASE){ |
| 1649 |
return array(); |
| 1650 |
} |
| 1651 |
|
| 1652 |
return $install_actions; |
| 1653 |
} |
| 1654 |
|
| 1655 |
// Load license data |
| 1656 |
function pagelayer_load_license(){ |
| 1657 |
|
| 1658 |
global $pagelayer; |
| 1659 |
|
| 1660 |
// Load license |
| 1661 |
$pagelayer->license = get_option('pagelayer_license'); |
| 1662 |
|
| 1663 |
// Update license details as well |
| 1664 |
if(!empty($pagelayer->license) && (time() - @$pagelayer->license['last_update']) >= 86400){ |
| 1665 |
|
| 1666 |
$resp = wp_remote_get(PAGELAYER_API.'license.php?license='.$pagelayer->license['license']); |
| 1667 |
|
| 1668 |
// Did we get a response ? |
| 1669 |
if(is_array($resp)){ |
| 1670 |
|
| 1671 |
$tosave = json_decode($resp['body'], true); |
| 1672 |
|
| 1673 |
// Is it the license ? |
| 1674 |
if(!empty($tosave['license'])){ |
| 1675 |
$tosave['last_update'] = time(); |
| 1676 |
update_option('pagelayer_license', $tosave); |
| 1677 |
} |
| 1678 |
|
| 1679 |
} |
| 1680 |
|
| 1681 |
} |
| 1682 |
|
| 1683 |
} |
| 1684 |
|
| 1685 |
// Handle hexa to rgba and also remove alpha which is ff |
| 1686 |
function pagelayer_hex8_to_rgba($val){ |
| 1687 |
|
| 1688 |
// If opacity is ff then discard ff |
| 1689 |
if(preg_match('/^#([a-f0-9]{6})ff$/is', $val)){ |
| 1690 |
return substr($val, 0, 7); |
| 1691 |
} |
| 1692 |
|
| 1693 |
// Lets handle the RGB+opacity |
| 1694 |
if(preg_match('/#([a-f0-9]{8})$/is', $val)){ |
| 1695 |
$val = pagelayer_hex2rgba($val); |
| 1696 |
} |
| 1697 |
|
| 1698 |
return $val; |
| 1699 |
|
| 1700 |
} |
| 1701 |
|
| 1702 |
// Convert to RGBA from HEX |
| 1703 |
function pagelayer_hex2rgba($color){ |
| 1704 |
|
| 1705 |
//Return if no color provided |
| 1706 |
if(empty($color)){ |
| 1707 |
return; |
| 1708 |
} |
| 1709 |
|
| 1710 |
//Sanitize $color if "#" is provided |
| 1711 |
if ($color[0] == '#'){ |
| 1712 |
$color = substr( $color, 1 ); |
| 1713 |
} |
| 1714 |
|
| 1715 |
//Check if color has 6 or 3 characters and get values |
| 1716 |
if (strlen($color) == 8) { |
| 1717 |
$hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ); |
| 1718 |
$alpha = $color[6] . $color[7]; |
| 1719 |
//$alpha = ''; |
| 1720 |
} elseif (strlen($color) == 6) { |
| 1721 |
$hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ); |
| 1722 |
} elseif ( strlen( $color ) == 3 ) { |
| 1723 |
$hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ); |
| 1724 |
} else { |
| 1725 |
return; |
| 1726 |
} |
| 1727 |
|
| 1728 |
//Convert hexadec to rgb |
| 1729 |
$rgb = array_map('hexdec', $hex); |
| 1730 |
|
| 1731 |
//Check if opacity is set(rgba or rgb) |
| 1732 |
if($alpha){ |
| 1733 |
|
| 1734 |
$alpha = number_format((float)hexdec($alpha) / 255, 2, '.', ''); |
| 1735 |
//print_r($alpha); |
| 1736 |
if(abs($alpha) > 1){ |
| 1737 |
$alpha = 1.0; |
| 1738 |
} |
| 1739 |
$output = 'rgba('.implode(",",$rgb).','.$alpha.')'; |
| 1740 |
} else { |
| 1741 |
$output = 'rgb('.implode(",",$rgb).')'; |
| 1742 |
} |
| 1743 |
|
| 1744 |
//Return rgb(a) color string |
| 1745 |
return $output; |
| 1746 |
} |
| 1747 |
|
| 1748 |
// Get social URLs |
| 1749 |
function pagelayer_get_social_urls(){ |
| 1750 |
|
| 1751 |
$urls = array(); |
| 1752 |
|
| 1753 |
$urls['facebook'] = get_option('pagelayer-facebook-url'); |
| 1754 |
$urls['twitter'] = get_option('pagelayer-twitter-url'); |
| 1755 |
$urls['instagram'] = get_option('pagelayer-instagram-url'); |
| 1756 |
$urls['linkedin'] = get_option('pagelayer-linkedin-url'); |
| 1757 |
$urls['youtube'] = get_option('pagelayer-youtube-url'); |
| 1758 |
$urls['google'] = get_option('pagelayer-gplus-url'); |
| 1759 |
|
| 1760 |
foreach($urls as $k => $v){ |
| 1761 |
if(empty($v)) unset($urls[$k]); |
| 1762 |
} |
| 1763 |
|
| 1764 |
return $urls; |
| 1765 |
} |
| 1766 |
|
| 1767 |
function pagelayer_get_option($opt){ |
| 1768 |
$ret = get_option($opt); |
| 1769 |
|
| 1770 |
$opts = array('pagelayer-address' => '1, My Address, My Street, New York City, NY, USA', |
| 1771 |
'pagelayer-phone' => '+1234567890', |
| 1772 |
'pagelayer-copyright' => '© '.date('Y').' '.get_option('blogname'), |
| 1773 |
'pagelayer_cf_to_email' => 'contact@domain.com'); |
| 1774 |
|
| 1775 |
if(empty($ret)){ |
| 1776 |
return $opts[$opt]; |
| 1777 |
} |
| 1778 |
|
| 1779 |
return $ret; |
| 1780 |
} |