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