| 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 |
// Is there a tag ? |
| 28 |
function pagelayer_render_shortcode($atts, $content = '', $tag = ''){ |
| 29 |
|
| 30 |
global $pagelayer; |
| 31 |
|
| 32 |
$_tag = $class = $tag; |
| 33 |
$final_tag = $tag; |
| 34 |
|
| 35 |
// Check if the tag is inner row and col then change it to row and col tag |
| 36 |
if($tag == 'pl_inner_row'){ |
| 37 |
$tag = 'pl_row'; |
| 38 |
}elseif($tag == 'pl_inner_col'){ |
| 39 |
$tag = 'pl_col'; |
| 40 |
$final_tag = $tag; |
| 41 |
} |
| 42 |
|
| 43 |
// Clear the pagelayer tags |
| 44 |
if(substr($tag, 0, 3) == 'pl_'){ |
| 45 |
$_tag = str_replace('pl_', '', $final_tag); |
| 46 |
$class = 'pagelayer-'.$_tag; |
| 47 |
} |
| 48 |
|
| 49 |
// Is there any function ? |
| 50 |
$func = @$pagelayer->shortcodes[$tag]['func']; |
| 51 |
$atts = (array) $atts; |
| 52 |
// Create the element array. NOTE : This is similar to the JS el and is temporary |
| 53 |
$el = []; |
| 54 |
$el['atts'] = $atts; |
| 55 |
$el['oAtts'] = $atts; |
| 56 |
$el['id'] = pagelayer_RandomString(16); |
| 57 |
$el['tmp'] = []; |
| 58 |
$el['tag'] = $final_tag; |
| 59 |
$el['content'] = $content; |
| 60 |
$el['selector'] = '[pagelayer-id="'.$el['id'].'"]'; |
| 61 |
$el['wrap'] = '[pagelayer-wrap-id="'.$el['id'].'"]'; |
| 62 |
|
| 63 |
$innerHTML = @$pagelayer->shortcodes[$tag]['innerHTML']; |
| 64 |
if(!empty($innerHTML) && !empty($content)){ |
| 65 |
$el['oAtts'][$innerHTML] = $content; |
| 66 |
$el['atts'][$innerHTML] = $content; |
| 67 |
} |
| 68 |
|
| 69 |
// The default class |
| 70 |
$el['classes'][] = $class; |
| 71 |
|
| 72 |
//pagelayer_print($el); |
| 73 |
|
| 74 |
// Lets create the CSS, Classes, Attr. Also clean the dependent atts |
| 75 |
foreach($pagelayer->tabs as $tab){ |
| 76 |
|
| 77 |
if(empty($pagelayer->shortcodes[$tag][$tab])){ |
| 78 |
continue; |
| 79 |
} |
| 80 |
|
| 81 |
foreach($pagelayer->shortcodes[$tag][$tab] as $section => $Lsection){ |
| 82 |
|
| 83 |
$props = empty($pagelayer->shortcodes[$tag][$section]) ? @$pagelayer->styles[$section] : @$pagelayer->shortcodes[$tag][$section]; |
| 84 |
|
| 85 |
//echo $tab.' - '.$section.' - <br>'; |
| 86 |
|
| 87 |
if(empty($props)){ |
| 88 |
continue; |
| 89 |
} |
| 90 |
|
| 91 |
foreach($props as $prop => $param){ |
| 92 |
|
| 93 |
//echo $tab.' - '.$section.' - '.$prop.'<br>'; |
| 94 |
|
| 95 |
// No value set |
| 96 |
if(empty($el['atts'][$prop]) && empty($el['atts'][$prop.'_tablet']) && empty($el['atts'][$prop.'_mobile'])){ |
| 97 |
continue; |
| 98 |
} |
| 99 |
|
| 100 |
// Clean the not required atts |
| 101 |
if(!empty($param['req'])){ |
| 102 |
|
| 103 |
$set = true; |
| 104 |
|
| 105 |
foreach($param['req'] as $rk => $reqval){ |
| 106 |
$except = $rk{0} == '!' ? true : false; |
| 107 |
$rk = $except ? substr($rk, 1) : $rk; |
| 108 |
$val = @$el['atts'][$rk]; |
| 109 |
|
| 110 |
//echo $prop.' - '.$rk.' : '.$reqval.' == '.$val.'<br>'; |
| 111 |
|
| 112 |
// The value should not be there |
| 113 |
if($except){ |
| 114 |
|
| 115 |
if(!is_array($reqval) && $reqval == $val){ |
| 116 |
$set = false; |
| 117 |
break; |
| 118 |
} |
| 119 |
|
| 120 |
// Its an array and a value is found, then dont show |
| 121 |
if(is_array($reqval) && in_array($val, $reqval)){ |
| 122 |
$set = false; |
| 123 |
break; |
| 124 |
} |
| 125 |
|
| 126 |
// The value must be equal |
| 127 |
}else{ |
| 128 |
|
| 129 |
if(!is_array($reqval) && $reqval != $val){ |
| 130 |
$set = false; |
| 131 |
break; |
| 132 |
} |
| 133 |
|
| 134 |
// Its an array and no value is found, then dont show |
| 135 |
if(is_array($reqval) && !in_array($val, $reqval)){ |
| 136 |
$set = false; |
| 137 |
break; |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
} |
| 142 |
|
| 143 |
// Unset as we dont need |
| 144 |
if(empty($set)){ |
| 145 |
unset($el['atts'][$prop]); |
| 146 |
unset($el['atts'][$prop.'_tablet']); |
| 147 |
unset($el['atts'][$prop.'_mobile']); |
| 148 |
} |
| 149 |
|
| 150 |
} |
| 151 |
|
| 152 |
// We could have unset the value above, so we need to check again if the value is there |
| 153 |
if(empty($el['atts'][$prop]) && empty($el['atts'][$prop.'_tablet']) && empty($el['atts'][$prop.'_mobile'])){ |
| 154 |
continue; |
| 155 |
} |
| 156 |
|
| 157 |
// Handle the edit fields |
| 158 |
if(!empty($param['edit'])){ |
| 159 |
$el['edit'][$prop] = $param['edit']; |
| 160 |
} |
| 161 |
|
| 162 |
// Backward compatibility of Icons |
| 163 |
if($param['type'] == 'icon' && !empty($el['atts'][$prop]) && !preg_match('/\s/', $el['atts'][$prop])){ |
| 164 |
$el['atts'][$prop] = $el['oAtts'][$prop] = 'fa fa-'.$el['atts'][$prop]; |
| 165 |
} |
| 166 |
|
| 167 |
// Backward compatibility of Box Shadow |
| 168 |
if($param['type'] == 'box_shadow' && !empty($el['atts'][$prop]) && substr_count($el['atts'][$prop], ',') == 3){ |
| 169 |
$el['atts'][$prop] = $el['oAtts'][$prop] = $el['atts'][$prop].',0,'; |
| 170 |
} |
| 171 |
|
| 172 |
// Load any attachment values |
| 173 |
if(in_array($param['type'], ['image', 'video', 'audio', 'media'])){ |
| 174 |
|
| 175 |
$attachment = ($param['type'] == 'image') ? pagelayer_image($el['atts'][$prop]) : pagelayer_attachment($el['atts'][$prop]); |
| 176 |
|
| 177 |
if(!empty($attachment)){ |
| 178 |
foreach($attachment as $k => $v){ |
| 179 |
$el['tmp'][$prop.'-'.$k] = $v; |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
} |
| 184 |
|
| 185 |
// Handle the AddClasses |
| 186 |
if(!empty($param['addClass']) && !empty($el['atts'][$prop])){ |
| 187 |
|
| 188 |
// Convert to an array |
| 189 |
if(!is_array($param['addClass'])){ |
| 190 |
$param['addClass'] = array($param['addClass']); |
| 191 |
} |
| 192 |
|
| 193 |
// Loop through |
| 194 |
foreach($param['addClass'] as $k => $v){ |
| 195 |
$k = str_replace('{{element}}', '', $k); |
| 196 |
$el['classes'][] = [trim($k) => str_replace('{{val}}', $el['atts'][$prop], $v)]; |
| 197 |
} |
| 198 |
|
| 199 |
} |
| 200 |
|
| 201 |
// Handle the AddClasses |
| 202 |
if(!empty($param['addAttr']) && !empty($el['atts'][$prop])){ |
| 203 |
|
| 204 |
// Convert to an array |
| 205 |
if(!is_array($param['addAttr'])){ |
| 206 |
$param['addAttr'] = array($param['addAttr']); |
| 207 |
} |
| 208 |
|
| 209 |
// Loop through |
| 210 |
foreach($param['addAttr'] as $k => $v){ |
| 211 |
$k = str_replace('{{element}}', '', $k); |
| 212 |
$el['attr'][] = [trim($k) => $v]; |
| 213 |
} |
| 214 |
|
| 215 |
} |
| 216 |
|
| 217 |
// Handle the CSS |
| 218 |
if(!empty($param['css'])){ |
| 219 |
//echo $prop.'<br>'; |
| 220 |
// Convert to an array |
| 221 |
if(!is_array($param['css'])){ |
| 222 |
$param['css'] = array($param['css']); |
| 223 |
} |
| 224 |
|
| 225 |
$modes = [ |
| 226 |
'desktop' => '', |
| 227 |
'tablet' => '_tablet', |
| 228 |
'mobile' => '_mobile' |
| 229 |
]; |
| 230 |
|
| 231 |
// Loop the modes and check for values |
| 232 |
foreach($modes as $mk => $mv){ |
| 233 |
|
| 234 |
$M_prop = $prop.$mv; |
| 235 |
|
| 236 |
// Any value ? |
| 237 |
if(empty($el['atts'][$M_prop])){ |
| 238 |
continue; |
| 239 |
} |
| 240 |
|
| 241 |
// Loop through |
| 242 |
foreach($param['css'] as $k => $v){ |
| 243 |
|
| 244 |
// Make the selector |
| 245 |
$selector = (!is_numeric($k) ? $k : $el['selector']); |
| 246 |
$selector = pagelayer_parse_el_vars($selector, $el); |
| 247 |
|
| 248 |
$ender = ''; |
| 249 |
|
| 250 |
if($mk == 'tablet'){ |
| 251 |
$selector = '@media (max-width: 768px) and (min-width: 361px){'.$selector; |
| 252 |
$ender = '}'; |
| 253 |
} |
| 254 |
|
| 255 |
if($mk == 'mobile'){ |
| 256 |
$selector = '@media (max-width: 360px){'.$selector; |
| 257 |
$ender = '}'; |
| 258 |
} |
| 259 |
|
| 260 |
if(!empty($selector)){ |
| 261 |
// Make the CSS |
| 262 |
$el['css'][] = $selector.'{'.pagelayer_css_render($v, $el['atts'][$M_prop], @$param['sep']).'}'.$ender; |
| 263 |
}else{ |
| 264 |
$el['css'][] = pagelayer_parse_el_vars($el['atts'][$M_prop],$el); |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
} |
| 269 |
|
| 270 |
} |
| 271 |
|
| 272 |
if($param['type'] == 'typography'){ |
| 273 |
$val = explode(',', $el['atts'][$prop]); |
| 274 |
|
| 275 |
if(!empty($val[0]) && !in_array($val[0], $pagelayer->runtime_fonts)){ |
| 276 |
$pagelayer->runtime_fonts[] = $val[0]; |
| 277 |
//pagelayer_print($pagelayer->runtime_fonts); |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
} |
| 282 |
|
| 283 |
} |
| 284 |
|
| 285 |
} |
| 286 |
|
| 287 |
//@pagelayer_print($el['css']); |
| 288 |
|
| 289 |
// Is there a function of the tag ? |
| 290 |
if(function_exists($func)){ |
| 291 |
call_user_func_array($func, array(&$el)); |
| 292 |
} |
| 293 |
|
| 294 |
// Create the default atts and tmp atts |
| 295 |
if(pagelayer_is_live()){ |
| 296 |
pagelayer_create_sc($el); |
| 297 |
} |
| 298 |
|
| 299 |
$div = '<div pagelayer-id="'.$el['id'].'"> |
| 300 |
<style pagelayer-style-id="'.$el['id'].'"></style>'; |
| 301 |
|
| 302 |
$is_group = !empty($pagelayer->shortcodes[$tag]['params']['elements']) ? true : false; |
| 303 |
|
| 304 |
// If there is an HTML AND you are not a GROUP, then make use of it, or append the real content |
| 305 |
if(!empty($pagelayer->shortcodes[$tag]['html'])){ |
| 306 |
|
| 307 |
// Create the HTML object |
| 308 |
$node = pQuery::parseStr($pagelayer->shortcodes[$tag]['html']); |
| 309 |
|
| 310 |
// Remove the if-ext |
| 311 |
foreach($node('[if-ext]') as $v){ |
| 312 |
$reqvar = pagelayer_var($v->attr('if-ext')); |
| 313 |
$v->removeAttr('if-ext'); |
| 314 |
|
| 315 |
// Is the element there ? |
| 316 |
if(empty($el['atts'][$reqvar])){ |
| 317 |
$v->after($v->html()); |
| 318 |
$v->remove(); |
| 319 |
} |
| 320 |
} |
| 321 |
|
| 322 |
// Remove the if |
| 323 |
foreach($node('[if]') as $v){ |
| 324 |
$reqvar = pagelayer_var($v->attr('if')); |
| 325 |
$v->removeAttr('if'); |
| 326 |
|
| 327 |
// Is the element there ? |
| 328 |
if(empty($el['atts'][$reqvar])){ |
| 329 |
$v->remove(); |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
//die($node->html()); |
| 334 |
|
| 335 |
// Do we have a holder ? Mainly for groups |
| 336 |
if(!empty($pagelayer->shortcodes[$tag]['holder'])){ |
| 337 |
$node->query($pagelayer->shortcodes[$tag]['holder'])->html('{{pagelayer_do_shortcode}}'); |
| 338 |
$do_shortcode = 1; |
| 339 |
} |
| 340 |
|
| 341 |
$html = pagelayer_parse_vars($node->html(), $el); |
| 342 |
|
| 343 |
// Append to the DIV |
| 344 |
$div .= $html; |
| 345 |
|
| 346 |
// Is it a widget ? |
| 347 |
}elseif(!empty($pagelayer->shortcodes[$tag]['widget'])){ |
| 348 |
|
| 349 |
$class = $pagelayer->shortcodes[$tag]['widget']; |
| 350 |
$instance = []; |
| 351 |
|
| 352 |
// Is there any existing data ? |
| 353 |
if(!empty($el['atts']['widget_data'])){ |
| 354 |
$json = trim($el['atts']['widget_data']); |
| 355 |
$json = json_decode($json, true); |
| 356 |
//pagelayer_print($json);die(); |
| 357 |
if(!empty($json)){ |
| 358 |
$instance = $json; |
| 359 |
} |
| 360 |
} |
| 361 |
|
| 362 |
ob_start(); |
| 363 |
the_widget($class, $instance, array('widget_id'=>'arbitrary-instance-'.$el['id'], |
| 364 |
'before_widget' => '', |
| 365 |
'after_widget' => '', |
| 366 |
'before_title' => '', |
| 367 |
'after_title' => '' |
| 368 |
)); |
| 369 |
|
| 370 |
$div .= ob_get_contents(); |
| 371 |
ob_end_clean(); |
| 372 |
|
| 373 |
}else{ |
| 374 |
$div .= '{{pagelayer_do_shortcode}}'; |
| 375 |
$do_shortcode = 1; |
| 376 |
} |
| 377 |
|
| 378 |
// End the tag |
| 379 |
$div .= '</div>'; |
| 380 |
|
| 381 |
// Add classes and attributes |
| 382 |
if(!empty($el['classes']) || !empty($el['attr'])){ |
| 383 |
|
| 384 |
// Create the HTML object |
| 385 |
$node = pQuery::parseStr($div); |
| 386 |
|
| 387 |
// Add the editable values |
| 388 |
if(!empty($el['edit'])){ |
| 389 |
|
| 390 |
foreach($el['edit'] as $k => $v){ |
| 391 |
$node->query($v)->attr('pagelayer-editable', $k); |
| 392 |
} |
| 393 |
|
| 394 |
} |
| 395 |
|
| 396 |
// Add the classes |
| 397 |
if(!empty($el['classes'])){ |
| 398 |
|
| 399 |
//pagelayer_print($el['classes']); |
| 400 |
|
| 401 |
foreach($el['classes'] as $k => $v){ |
| 402 |
|
| 403 |
if(!is_array($v)){ |
| 404 |
$v = [$v]; |
| 405 |
} |
| 406 |
|
| 407 |
foreach($v as $kk => $vv){ |
| 408 |
//echo $kk.' - '.$vv."\n"; |
| 409 |
if(is_numeric($kk)){ |
| 410 |
$node->query($el['selector'])->addClass($vv); |
| 411 |
}else{ |
| 412 |
$node->query($kk)->addClass($vv); |
| 413 |
} |
| 414 |
|
| 415 |
} |
| 416 |
|
| 417 |
} |
| 418 |
|
| 419 |
//echo $node->html(); |
| 420 |
//die(); |
| 421 |
|
| 422 |
} |
| 423 |
|
| 424 |
// Add the attributes |
| 425 |
if(!empty($el['attr'])){ |
| 426 |
|
| 427 |
//pagelayer_print($el['attr']); |
| 428 |
|
| 429 |
foreach($el['attr'] as $k => $v){ |
| 430 |
|
| 431 |
if(!is_array($v)){ |
| 432 |
$v = [$v]; |
| 433 |
} |
| 434 |
|
| 435 |
foreach($v as $kk => $vv){ |
| 436 |
|
| 437 |
$att = explode('=', $vv, 2); |
| 438 |
$att[1] = pagelayer_parse_vars($att[1], $el); |
| 439 |
$att[1] = trim($att[1], '"'); |
| 440 |
|
| 441 |
if(is_numeric($kk)){ |
| 442 |
$node->query($el['selector'])->attr($att[0], $att[1]); |
| 443 |
}else{ |
| 444 |
$node->query($kk)->attr($att[0], $att[1]); |
| 445 |
} |
| 446 |
|
| 447 |
} |
| 448 |
|
| 449 |
} |
| 450 |
|
| 451 |
} |
| 452 |
|
| 453 |
$div = $node->html(); |
| 454 |
//die($div); |
| 455 |
|
| 456 |
} |
| 457 |
|
| 458 |
// Add the CSS if any or remove it |
| 459 |
$style = ''; |
| 460 |
if(!empty($el['css'])){ |
| 461 |
|
| 462 |
$style = '<style pagelayer-style-id="'.$el['id'].'"> |
| 463 |
'.implode("\n", pagelayer_parse_vars($el['css'], $el)).' |
| 464 |
</style>'; |
| 465 |
|
| 466 |
if(!empty($pagelayer->shortcodes[$tag]['overide_css_selector'])){ |
| 467 |
$style = str_replace($el['selector'], $pagelayer->shortcodes[$tag]['overide_css_selector'], $style); |
| 468 |
$style = str_replace($el['wrap'], $pagelayer->shortcodes[$tag]['overide_css_selector'], $style); |
| 469 |
} |
| 470 |
|
| 471 |
} |
| 472 |
|
| 473 |
$div = str_replace('<style pagelayer-style-id="'.$el['id'].'"></style>', $style, $div); |
| 474 |
|
| 475 |
// Is there an inner content which requires a SHORTCODE ? |
| 476 |
if(!empty($do_shortcode)){ |
| 477 |
$div = str_replace('{{pagelayer_do_shortcode}}', do_shortcode($el['content']), $div); |
| 478 |
} |
| 479 |
|
| 480 |
return $div; |
| 481 |
|
| 482 |
} |
| 483 |
|
| 484 |
// Creates the shortcode and returns a base64 encoded files |
| 485 |
function pagelayer_create_sc(&$el){ |
| 486 |
|
| 487 |
$a = $tmp = array(); |
| 488 |
|
| 489 |
if(!empty($el['oAtts'])){ |
| 490 |
|
| 491 |
foreach($el['oAtts'] as $k => $v){ |
| 492 |
$el['attr'][] = 'pagelayer-a-'.$k.'="'.$v.'"'; |
| 493 |
} |
| 494 |
|
| 495 |
} |
| 496 |
|
| 497 |
// Tmp atts |
| 498 |
if(!empty($el['tmp'])){ |
| 499 |
|
| 500 |
foreach($el['tmp'] as $k => $v){ |
| 501 |
$el['attr'][] = 'pagelayer-tmp-'.$k.'="'.$v.'"'; |
| 502 |
} |
| 503 |
|
| 504 |
} |
| 505 |
|
| 506 |
// Add the tag |
| 507 |
$el['attr'][] = 'pagelayer-tag="'.$el['tag'].'"'; |
| 508 |
|
| 509 |
// Make it a PageLayer element for editing |
| 510 |
$el['classes'][] = 'pagelayer-ele'; |
| 511 |
|
| 512 |
} |
| 513 |
|
| 514 |
// Converts {{val}} to val |
| 515 |
function pagelayer_var($var){ |
| 516 |
return substr($var, 2, -2); |
| 517 |
} |
| 518 |
|
| 519 |
// Replace the variables |
| 520 |
function pagelayer_parse_el_vars($str, &$el){ |
| 521 |
|
| 522 |
$str = str_replace('{{element}}', $el['selector'], $str); |
| 523 |
$is_live = pagelayer_is_live(); |
| 524 |
if(!empty($is_live)){ |
| 525 |
$str = str_replace('{{wrap}}', $el['wrap'], $str); |
| 526 |
}else{ |
| 527 |
$str = str_replace('{{wrap}}', $el['selector'], $str); |
| 528 |
} |
| 529 |
$str = str_replace('{{ele_id}}', $el['id'], $str); |
| 530 |
|
| 531 |
return $str; |
| 532 |
|
| 533 |
} |
| 534 |
|
| 535 |
// Parse the variables |
| 536 |
function pagelayer_parse_vars($str, &$el){ |
| 537 |
|
| 538 |
//pagelayer_print($el); |
| 539 |
if(is_array($el['tmp'])){ |
| 540 |
foreach($el['tmp'] as $k => $v){ |
| 541 |
$str = str_replace('{{{'.$k.'}}}', $el['tmp'][$k], $str); |
| 542 |
} |
| 543 |
} |
| 544 |
|
| 545 |
if(is_array($el['atts'])){ |
| 546 |
foreach($el['atts'] as $k => $v){ |
| 547 |
$str = str_replace('{{'.$k.'}}', $el['atts'][$k], $str); |
| 548 |
} |
| 549 |
} |
| 550 |
|
| 551 |
return $str; |
| 552 |
} |
| 553 |
|
| 554 |
// Make the rule |
| 555 |
function pagelayer_css_render($rule, $val, $sep = ','){ |
| 556 |
|
| 557 |
// Seperator |
| 558 |
$sep = empty($sep) ? ',' : $sep; |
| 559 |
|
| 560 |
// Replace the val |
| 561 |
$rule = str_replace('{{val}}', $val, $rule); |
| 562 |
|
| 563 |
// If there is an array |
| 564 |
if(preg_match('/\{val\[\d/is', $rule)){ |
| 565 |
$val = explode($sep, $val); |
| 566 |
foreach($val as $k => $v){ |
| 567 |
$rule = str_replace('{{val['.$k.']}}', $v, $rule); |
| 568 |
} |
| 569 |
} |
| 570 |
|
| 571 |
return $rule; |
| 572 |
|
| 573 |
} |
| 574 |
|
| 575 |
// Post Property Handler |
| 576 |
function pagelayer_sc_body(&$el){ |
| 577 |
|
| 578 |
global $post; |
| 579 |
|
| 580 |
$el['oAtts']['post_title'] = $post->post_title; |
| 581 |
$el['oAtts']['post_name'] = $post->post_name; |
| 582 |
$el['oAtts']['post_excerpt'] = $post->post_excerpt; |
| 583 |
$el['oAtts']['post_status'] = $post->post_status; |
| 584 |
$el['oAtts']['featured_image'] = get_post_thumbnail_id($post); |
| 585 |
|
| 586 |
// Load featured image details |
| 587 |
if(!empty($el['oAtts']['featured_image'])){ |
| 588 |
|
| 589 |
$attachment = pagelayer_image($el['oAtts']['featured_image']); |
| 590 |
|
| 591 |
if(!empty($attachment)){ |
| 592 |
foreach($attachment as $k => $v){ |
| 593 |
$el['tmp']['featured_image-'.$k] = $v; |
| 594 |
} |
| 595 |
} |
| 596 |
|
| 597 |
} |
| 598 |
|
| 599 |
} |
| 600 |
|
| 601 |
// ROW Handler |
| 602 |
function pagelayer_sc_row(&$el){ |
| 603 |
|
| 604 |
pagelayer_bg_video($el); |
| 605 |
|
| 606 |
if(!empty($el['atts']['row_shape_type_top'])){ |
| 607 |
$path_top = PAGELAYER_DIR.'/images/shapes/'.$el['atts']['row_shape_type_top'].'-top.svg'; |
| 608 |
$el['atts']['svg_top'] = file_get_contents($path_top); |
| 609 |
} |
| 610 |
|
| 611 |
if(!empty($el['atts']['row_shape_type_bottom'])){ |
| 612 |
$path_bottom = PAGELAYER_DIR.'/images/shapes/'.$el['atts']['row_shape_type_bottom'].'-bottom.svg'; |
| 613 |
$el['atts']['svg_bottom'] = file_get_contents($path_bottom); |
| 614 |
} |
| 615 |
|
| 616 |
// Row background slider |
| 617 |
if(!empty($el['atts']['bg_slider'])){ |
| 618 |
$ids = explode(',', $el['atts']['bg_slider']); |
| 619 |
$urls = []; |
| 620 |
$el['atts']['slider'] = ''; |
| 621 |
|
| 622 |
// Make the image URL |
| 623 |
foreach($ids as $k => $v){ |
| 624 |
|
| 625 |
$image = pagelayer_image($v); |
| 626 |
$urls['i'.$v] = @$image['full-url']; |
| 627 |
|
| 628 |
$el['atts']['slider'] .= '<div class="pagelayer-bgimg-slide" style="background-image:url(\''.$image['full-url'].'\')"></div>'; |
| 629 |
|
| 630 |
} |
| 631 |
|
| 632 |
if(!empty($urls)){ |
| 633 |
$el['tmp']['bg_slider-urls'] = json_encode($urls); |
| 634 |
} |
| 635 |
|
| 636 |
} |
| 637 |
} |
| 638 |
|
| 639 |
// Column Handler |
| 640 |
function pagelayer_sc_col(&$el){ |
| 641 |
|
| 642 |
// Add the default col class |
| 643 |
$el['classes'][] = 'pagelayer-col'; |
| 644 |
|
| 645 |
//return do_shortcode($el['content']); |
| 646 |
|
| 647 |
pagelayer_bg_video($el); |
| 648 |
|
| 649 |
} |
| 650 |
|
| 651 |
// Just for BG handling |
| 652 |
function pagelayer_bg_video(&$el){ |
| 653 |
|
| 654 |
if(empty($el['tmp']['bg_video_src-url'])){ |
| 655 |
return false; |
| 656 |
} |
| 657 |
|
| 658 |
// Get the video URL for the iframe |
| 659 |
$iframe_src = pagelayer_video_url($el['tmp']['bg_video_src-url']); |
| 660 |
|
| 661 |
$source = filter_var($el['tmp']['bg_video_src-url'], FILTER_SANITIZE_URL); |
| 662 |
$source = str_replace('&', '&', $source); |
| 663 |
$url = parse_url($source); |
| 664 |
|
| 665 |
$youtubeRegExp = '/youtube\.com|youtu\.be/is'; |
| 666 |
$vimeoRegExp = '/vimeo\.com/is'; |
| 667 |
|
| 668 |
if (!empty($source)) { |
| 669 |
|
| 670 |
if (preg_match($youtubeRegExp, $source)) { |
| 671 |
if (preg_match('/youtube\.com/is', $source)) { |
| 672 |
|
| 673 |
if (preg_match('/watch/is', $source)) { |
| 674 |
parse_str($url['query'], $parameters); |
| 675 |
|
| 676 |
if (isset($parameters['v']) && !empty($parameters['v'])) { |
| 677 |
$videoId = $parameters['v']; |
| 678 |
} |
| 679 |
|
| 680 |
} else if (preg_match('/embed/is', $url['path'])) { |
| 681 |
$path = explode('/', $url['path']); |
| 682 |
if (isset($path[2]) && !empty($path[2])) { |
| 683 |
$videoId = $path[2]; |
| 684 |
} |
| 685 |
} |
| 686 |
|
| 687 |
} else if (preg_match('/youtu\.be/is', $url['host'])) { |
| 688 |
$path = explode('/', $url['path']); |
| 689 |
|
| 690 |
if (isset($path[1]) && !empty($path[1])) { |
| 691 |
$videoId = $path[1]; |
| 692 |
} |
| 693 |
|
| 694 |
} |
| 695 |
|
| 696 |
$el['atts']['vid_src'] = '<iframe src="'.$iframe_src.'?autoplay=1&controls=0&showinfo=0&rel=0&loop=1&autohide=1&playlist='.$videoId.'" allowfullscreen="1" webkitallowfullscreen="1" mozallowfullscreen="1" frameborder="0"></iframe>'; |
| 697 |
|
| 698 |
} else if (preg_match($vimeoRegExp, $source)) { |
| 699 |
|
| 700 |
$el['atts']['vid_src'] = '<iframe src="'.$iframe_src.'?background=1&autoplay=1&loop=1&byline=0&title=0" allowfullscreen="1" webkitallowfullscreen="1" mozallowfullscreen="1" frameborder="0"></iframe>'; |
| 701 |
|
| 702 |
}else{ |
| 703 |
|
| 704 |
$el['atts']['vid_src'] = '<video autoplay loop>'. |
| 705 |
'<source src="'.$iframe_src.'" type="video/mp4">'. |
| 706 |
'</video>'; |
| 707 |
|
| 708 |
} |
| 709 |
} |
| 710 |
} |
| 711 |
|
| 712 |
// Image Handler |
| 713 |
function pagelayer_sc_social(&$el){ |
| 714 |
$icon = explode(' fa-', $el['atts']['icon']); |
| 715 |
$el['classes'][] = ['.pagelayer-icon-holder' => 'pagelayer-'.$icon[1]]; |
| 716 |
} |
| 717 |
|
| 718 |
// Image Handler |
| 719 |
function pagelayer_sc_image(&$el){ |
| 720 |
|
| 721 |
// Decide the image URL |
| 722 |
$el['atts']['func_id'] = @$el['tmp']['id-'.$el['atts']['id-size'].'-url']; |
| 723 |
$el['atts']['func_id'] = empty($el['atts']['func_id']) ? @$el['tmp']['id-full-url'] : $el['atts']['func_id']; |
| 724 |
|
| 725 |
// What is the link ? |
| 726 |
if(!empty($el['atts']['link_type'])){ |
| 727 |
|
| 728 |
// Custom url |
| 729 |
if($el['atts']['link_type'] == 'custom_url'){ |
| 730 |
$el['atts']['func_link'] = $el['atts']['link']; |
| 731 |
} |
| 732 |
|
| 733 |
// Link to the media file itself |
| 734 |
if($el['atts']['link_type'] == 'media_file'){ |
| 735 |
$el['atts']['func_link'] = $el['atts']['func_id']; |
| 736 |
} |
| 737 |
|
| 738 |
// Lightbox |
| 739 |
if($el['atts']['link_type'] == 'lightbox'){ |
| 740 |
$el['atts']['func_link'] = $el['atts']['func_id']; |
| 741 |
} |
| 742 |
|
| 743 |
} |
| 744 |
|
| 745 |
//pagelayer_print($el); |
| 746 |
|
| 747 |
} |
| 748 |
|
| 749 |
// Image Slider Handler |
| 750 |
function pagelayer_sc_image_slider(&$el){ |
| 751 |
|
| 752 |
$ids = explode(',', $el['atts']['ids']); |
| 753 |
$urls = []; |
| 754 |
$all_urls = []; |
| 755 |
$final_urls = []; |
| 756 |
$ul = []; |
| 757 |
$size = $el['atts']['size']; |
| 758 |
|
| 759 |
// Make the image URL |
| 760 |
foreach($ids as $k => $v){ |
| 761 |
|
| 762 |
$image = pagelayer_image($v); |
| 763 |
|
| 764 |
$final_urls[$v] = empty($image[$size.'-url']) ? @$image['full-url'] : $image[$size.'-url']; |
| 765 |
|
| 766 |
$urls['i'.$v] = @$image['full-url']; |
| 767 |
|
| 768 |
foreach($image as $kk => $vv){ |
| 769 |
$si = strstr($kk, '-url', true); |
| 770 |
if(!empty($si)){ |
| 771 |
$all_urls['i'.$v][$si] = $vv; |
| 772 |
} |
| 773 |
} |
| 774 |
|
| 775 |
$li = '<li class="pagelayer-slider-item">'; |
| 776 |
|
| 777 |
// Any Link ? |
| 778 |
if(!empty($el['atts']['link_type'])){ |
| 779 |
$link = ($el['atts']['link_type'] == 'media_file' ? $final_urls[$v] : @$el['atts']['link']); |
| 780 |
$li .= '<a href="'.$link.'">'; |
| 781 |
} |
| 782 |
|
| 783 |
// The Image |
| 784 |
$li .= '<img class="pagelayer-img" src="'.$final_urls[$v].'">'; |
| 785 |
|
| 786 |
if(!empty($el['atts']['link_type'])){ |
| 787 |
$li .= '</a>'; |
| 788 |
} |
| 789 |
|
| 790 |
$li .= '</li>'; |
| 791 |
|
| 792 |
$ul[] = $li; |
| 793 |
|
| 794 |
} |
| 795 |
|
| 796 |
//pagelayer_print($urls); |
| 797 |
//pagelayer_print($final_urls); |
| 798 |
//pagelayer_print($all_urls); |
| 799 |
|
| 800 |
// Make the TMP vars |
| 801 |
if(!empty($urls)){ |
| 802 |
$el['tmp']['ids-urls'] = json_encode($urls); |
| 803 |
$el['tmp']['ids-all-urls'] = json_encode($all_urls); |
| 804 |
$el['atts']['ul'] = implode('', $ul); |
| 805 |
|
| 806 |
// Which arrows to show |
| 807 |
if(in_array(@$el['atts']['controls'], ['arrows', 'none'])){ |
| 808 |
$el['attr'][] = ['.pagelayer-image-slider-ul' => 'data-pager="false"']; |
| 809 |
} |
| 810 |
|
| 811 |
if(in_array(@$el['atts']['controls'], ['pager', 'none'])){ |
| 812 |
$el['attr'][] = ['.pagelayer-image-slider-ul' => 'data-controls="false"']; |
| 813 |
} |
| 814 |
} |
| 815 |
|
| 816 |
}; |
| 817 |
|
| 818 |
//Grid Gallery Handler |
| 819 |
function pagelayer_sc_grid_gallery(&$el){ |
| 820 |
|
| 821 |
$ids = explode(',', $el['atts']['ids']); |
| 822 |
$urls = []; |
| 823 |
$all_urls = []; |
| 824 |
$final_urls = []; |
| 825 |
$ul = []; |
| 826 |
$size = $el['atts']['size']; |
| 827 |
$i = 0; |
| 828 |
$col = $el['atts']['columns']; |
| 829 |
$gallery_rand = 'gallery-id-'.floor((rand() * 100) + 1); |
| 830 |
|
| 831 |
$ul[] = '<ul class="pagelayer-grid-gallery-ul">'; |
| 832 |
// Make the image URL |
| 833 |
foreach($ids as $k => $v){ |
| 834 |
|
| 835 |
$image = pagelayer_image($v); |
| 836 |
|
| 837 |
$final_urls[$v] = empty($image[$size.'-url']) ? @$image['full-url'] : $image[$size.'-url']; |
| 838 |
|
| 839 |
$urls['i'.$v] = @$image['full-url']; |
| 840 |
$links['i'.$v] = @$image['link']; |
| 841 |
$titles['i'.$v] = @$image['title']; |
| 842 |
$captions['i'.$v] = @$image['caption']; |
| 843 |
|
| 844 |
foreach($image as $kk => $vv){ |
| 845 |
$si = strstr($kk, '-url', true); |
| 846 |
if(!empty($si)){ |
| 847 |
$all_urls['i'.$v][$si] = $vv; |
| 848 |
} |
| 849 |
} |
| 850 |
|
| 851 |
/* if(($i % $col) == 0 && $i != 0 ){ |
| 852 |
$ul[] = '</ul><ul class="pagelayer-grid-gallery-ul">'; |
| 853 |
} */ |
| 854 |
|
| 855 |
$li = '<li class="pagelayer-gallery-item" >'; |
| 856 |
|
| 857 |
if(empty($el['atts']['link_to'])){ |
| 858 |
$li .= '<div>'; |
| 859 |
} |
| 860 |
|
| 861 |
// Any Link ? |
| 862 |
if(!empty($el['atts']['link_to']) && $el['atts']['link_to'] == 'media_file'){ |
| 863 |
$link = ($el['atts']['link_to'] == 'media_file' ? $final_urls[$v] : @$el['atts']['link']); |
| 864 |
$li .= '<a href="'.$link.'" class="pagelayer-ele-link">'; |
| 865 |
} |
| 866 |
|
| 867 |
// Any Link ? |
| 868 |
if(!empty($el['atts']['link_to']) && $el['atts']['link_to'] == 'attachment' ){ |
| 869 |
$link = $image['link']; |
| 870 |
$li .= '<a href="'.$link.'" class="pagelayer-ele-link">'; |
| 871 |
} |
| 872 |
|
| 873 |
if(!empty($el['atts']['link_to']) && $el['atts']['link_to'] == 'lightbox'){ |
| 874 |
$li .= '<a href="'.$image['full-url'].'" data-lightbox-gallery="'.$gallery_rand.'" alt="'.$image['alt'].'" class="pagelayer-ele-link" pagelayer-grid-gallery-type="'.$el['atts']['link_to'].'">'; |
| 875 |
} |
| 876 |
// The Image |
| 877 |
$li .= '<img class="pagelayer-img" src="'.$final_urls[$v].'" title="'.$image['title'].'" alt="'.$image['alt'].'">'; |
| 878 |
|
| 879 |
if(!empty($el['atts']['caption'])){ |
| 880 |
$li .= '<span class="pagelayer-grid-gallery-caption">'.$image['caption'].'</span>'; |
| 881 |
} |
| 882 |
|
| 883 |
if(!empty($el['atts']['link_to'])){ |
| 884 |
$li .= '</a>'; |
| 885 |
} |
| 886 |
|
| 887 |
if(empty($el['atts']['link_to'])){ |
| 888 |
$li .= '</div>'; |
| 889 |
} |
| 890 |
|
| 891 |
$li .= '</li>'; |
| 892 |
|
| 893 |
$ul[] = $li; |
| 894 |
$i++; |
| 895 |
} |
| 896 |
|
| 897 |
$ul[] = '</ul>'; |
| 898 |
|
| 899 |
//pagelayer_print($urls); |
| 900 |
//pagelayer_print($final_urls); |
| 901 |
//pagelayer_print($all_urls); |
| 902 |
|
| 903 |
// Make the TMP vars |
| 904 |
if(!empty($urls)){ |
| 905 |
$el['tmp']['ids-urls'] = json_encode($urls); |
| 906 |
$el['tmp']['ids-all-urls'] = json_encode($all_urls); |
| 907 |
$el['tmp']['ids-all-links'] = json_encode($links); |
| 908 |
$el['tmp']['ids-all-titles'] = json_encode($titles); |
| 909 |
$el['tmp']['ids-all-captions'] = json_encode($captions); |
| 910 |
$el['atts']['ul'] = implode('', $ul); |
| 911 |
$el['tmp']['gallery-random-id'] = $gallery_rand; |
| 912 |
|
| 913 |
} |
| 914 |
} |
| 915 |
|
| 916 |
// Testimonial Handler |
| 917 |
function pagelayer_sc_testimonial(&$el){ |
| 918 |
|
| 919 |
$el['atts']['func_image'] = @$el['tmp']['avatar-'.$el['atts']['custom_size'].'-url']; |
| 920 |
$el['atts']['func_image'] = empty($el['atts']['func_image']) ? @$el['tmp']['avatar-full-url'] : $el['atts']['func_image']; |
| 921 |
|
| 922 |
if(!empty($image)){ |
| 923 |
foreach($image as $k => $v){ |
| 924 |
$el['tmp']['avatar-'.$k] = $v; |
| 925 |
} |
| 926 |
} |
| 927 |
|
| 928 |
} |
| 929 |
|
| 930 |
// Video Handler |
| 931 |
function pagelayer_sc_video(&$el){ |
| 932 |
|
| 933 |
$el['atts']['video_overlay_image-url'] = empty($el['tmp']['video_overlay_image-'.$el['atts']['custom_size'].'-url']) ? $el['tmp']['video_overlay_image-url'] : $el['tmp']['video_overlay_image-'.$el['atts']['custom_size'].'-url']; |
| 934 |
$el['atts']['video_overlay_image-url'] = empty($el['atts']['video_overlay_image-url']) ? $el['atts']['video_overlay_image'] : $el['atts']['video_overlay_image-url']; |
| 935 |
|
| 936 |
// Get the video URL for the iframe |
| 937 |
$el['atts']['vid_src'] = pagelayer_video_url($el['tmp']['src-url']); |
| 938 |
|
| 939 |
if($el['atts']['autoplay'] == "true"){ |
| 940 |
$el['atts']['vid_src'] .="?&autoplay=1"; |
| 941 |
}else{ |
| 942 |
$el['atts']['vid_src'] .="?&autoplay=0"; |
| 943 |
} |
| 944 |
|
| 945 |
if($el['atts']['mute'] == "true"){ |
| 946 |
$el['atts']['vid_src'] .="&mute=1"; |
| 947 |
}else{ |
| 948 |
$el['atts']['vid_src'] .="&mute=0"; |
| 949 |
} |
| 950 |
|
| 951 |
if($el['atts']['loop'] == "true"){ |
| 952 |
$el['atts']['vid_src'] .="&loop=1"; |
| 953 |
}else{ |
| 954 |
$el['atts']['vid_src'] .="&loop=0"; |
| 955 |
} |
| 956 |
|
| 957 |
$el['tmp']['ele_id'] = $el['id']; |
| 958 |
|
| 959 |
} |
| 960 |
|
| 961 |
|
| 962 |
// Shortcodes Handler |
| 963 |
function pagelayer_sc_shortcodes(&$el){ |
| 964 |
$el['tmp']['shortcode'] = do_shortcode($el['atts']['data']); |
| 965 |
} |
| 966 |
|
| 967 |
// Shortcodes Handler |
| 968 |
function pagelayer_sc_wp_widgets(&$el){ |
| 969 |
|
| 970 |
global $wp_registered_sidebars; |
| 971 |
|
| 972 |
$data = ''; |
| 973 |
foreach($wp_registered_sidebars as $v){ |
| 974 |
if($el['atts']['sidebar'] == $v['id']){ |
| 975 |
ob_start(); |
| 976 |
dynamic_sidebar($v['id']); |
| 977 |
$data = ob_get_clean(); |
| 978 |
} |
| 979 |
} |
| 980 |
|
| 981 |
$el['tmp']['data'] = $data; |
| 982 |
} |
| 983 |
|
| 984 |
|
| 985 |
// Service Handler |
| 986 |
function pagelayer_sc_service(&$el){ |
| 987 |
|
| 988 |
if(!empty($el['atts']['service_image'])){ |
| 989 |
$el['atts']['func_image'] = @$el['tmp']['service_image-'.$el['atts']['service_image_size'].'-url']; |
| 990 |
$el['atts']['func_image'] = empty($el['atts']['func_image']) ? @$el['tmp']['service_image-full-url'] : $el['atts']['func_image']; |
| 991 |
} |
| 992 |
} |
| 993 |
|
| 994 |
|
| 995 |
/*pagelayer_print($atts); |
| 996 |
pagelayer_print($content); |
| 997 |
die();*/ |
| 998 |
|
| 999 |
///////////////////////////////////// |
| 1000 |
// Miscellaneous Shortcode Functions |
| 1001 |
///////////////////////////////////// |
| 1002 |
|
| 1003 |
// The font family list |
| 1004 |
function pagelayer_font_family(){ |
| 1005 |
return array( |
| 1006 |
'arial' => 'Arial', |
| 1007 |
'terminal' => 'Terminal' |
| 1008 |
); |
| 1009 |
} |
| 1010 |
|
| 1011 |
// Supported Icons |
| 1012 |
function pagelayer_icon_class_list(){ |
| 1013 |
return array(); |
| 1014 |
} |
| 1015 |
|