shortcodes[$tag]['func'];
// Create the element array. NOTE : This is similar to the JS el and is temporary
$el = [];
$el['atts'] = $atts;
$el['oAtts'] = $atts;
$el['id'] = pagelayer_RandomString(16);
$el['tmp'] = [];
$el['tag'] = $tag;
$el['content'] = $content;
$el['selector'] = '[pagelayer-id="'.$el['id'].'"]';
$innerHTML = @$pagelayer->shortcodes[$tag]['innerHTML'];
if(!empty($innerHTML) && !empty($content)){
$el['oAtts'][$innerHTML] = $content;
$el['atts'][$innerHTML] = $content;
}
// The default class
$el['classes'][] = $class;
//pagelayer_print($el);
// Lets create the CSS, Classes, Attr. Also clean the dependent atts
foreach($pagelayer->tabs as $tab){
if(empty($pagelayer->shortcodes[$tag][$tab])){
continue;
}
foreach($pagelayer->shortcodes[$tag][$tab] as $section => $Lsection){
$props = empty($pagelayer->shortcodes[$tag][$section]) ? @$pagelayer->styles[$section] : @$pagelayer->shortcodes[$tag][$section];
//echo $tab.' - '.$section.' - ';
if(empty($props)){
continue;
}
foreach($props as $prop => $param){
//echo $tab.' - '.$section.' - '.$prop.' ';
// No value set
if(empty($el['atts'][$prop]) && empty($el['atts'][$prop.'_tablet']) && empty($el['atts'][$prop.'_mobile'])){
continue;
}
// Clean the not required atts
if(!empty($param['req'])){
$set = true;
foreach($param['req'] as $rk => $reqval){
$except = $rk{0} == '!' ? true : false;
$rk = $except ? substr($rk, 1) : $rk;
$val = @$el['atts'][$rk];
//echo $prop.' - '.$rk.' : '.$reqval.' == '.$val.' ';
// The value should not be there
if($except){
if(!is_array($reqval) && $reqval == $val){
$set = false;
break;
}
// Its an array and a value is found, then dont show
if(is_array($reqval) && in_array($val, $reqval)){
$set = false;
break;
}
// The value must be equal
}else{
if(!is_array($reqval) && $reqval != $val){
$set = false;
break;
}
// Its an array and no value is found, then dont show
if(is_array($reqval) && !in_array($val, $reqval)){
$set = false;
break;
}
}
}
// Unset as we dont need
if(empty($set)){
unset($el['atts'][$prop]);
unset($el['atts'][$prop.'_tablet']);
unset($el['atts'][$prop.'_mobile']);
}
}
// We could have unset the value above, so we need to check again if the value is there
if(empty($el['atts'][$prop]) && empty($el['atts'][$prop.'_tablet']) && empty($el['atts'][$prop.'_mobile'])){
continue;
}
// Handle the edit fields
if(!empty($param['edit'])){
$el['edit'][$prop] = $param['edit'];
}
// Load any attachment values
if(in_array($param['type'], ['image', 'video', 'audio', 'media'])){
$attachment = ($param['type'] == 'image') ? pagelayer_image($el['atts'][$prop]) : pagelayer_attachment($el['atts'][$prop]);
if(!empty($attachment)){
foreach($attachment as $k => $v){
$el['tmp'][$prop.'-'.$k] = $v;
}
}
}
// Handle the AddClasses
if(!empty($param['addClass']) && !empty($el['atts'][$prop])){
// Convert to an array
if(!is_array($param['addClass'])){
$param['addClass'] = array($param['addClass']);
}
// Loop through
foreach($param['addClass'] as $k => $v){
$k = str_replace('{{element}}', '', $k);
$el['classes'][] = [trim($k) => str_replace('{{val}}', $el['atts'][$prop], $v)];
}
}
// Handle the AddClasses
if(!empty($param['addAttr']) && !empty($el['atts'][$prop])){
// Convert to an array
if(!is_array($param['addAttr'])){
$param['addAttr'] = array($param['addAttr']);
}
// Loop through
foreach($param['addAttr'] as $k => $v){
$k = str_replace('{{element}}', '', $k);
$el['attr'][] = [trim($k) => $v];
}
}
// Handle the CSS
if(!empty($param['css'])){
//echo $prop.' ';
// Convert to an array
if(!is_array($param['css'])){
$param['css'] = array($param['css']);
}
$modes = [
'desktop' => '',
'tablet' => '_tablet',
'mobile' => '_mobile'
];
// Loop the modes and check for values
foreach($modes as $mk => $mv){
$M_prop = $prop.$mv;
// Any value ?
if(empty($el['atts'][$M_prop])){
continue;
}
// Loop through
foreach($param['css'] as $k => $v){
// Make the selector
$selector = (!is_numeric($k) ? str_replace('{{element}}', $el['selector'], $k) : $el['selector']);
$ender = '';
if($mk == 'tablet'){
$selector = '@media (max-width: 768px) and (min-width: 361px){'.$selector;
$ender = '}';
}
if($mk == 'mobile'){
$selector = '@media (max-width: 360px){'.$selector;
$ender = '}';
}
// Make the CSS
$el['css'][] = $selector.'{'.pagelayer_css_render($v, $el['atts'][$M_prop], @$param['sep']).'}'.$ender;
}
}
}
if($param['type'] == 'typography'){
$val = explode(',', $el['atts'][$prop]);
if(!empty($val[0]) && !in_array($val[0], $pagelayer->runtime_fonts)){
$pagelayer->runtime_fonts[] = $val[0];
//pagelayer_print($pagelayer->runtime_fonts);
}
}
}
}
}
//@pagelayer_print($el['css']);
// Is there a function of the tag ?
if(function_exists($func)){
call_user_func_array($func, array(&$el));
}
// Create the default atts and tmp atts
if(pagelayer_is_live()){
pagelayer_create_sc($el);
}
$div = '
';
$is_group = !empty($pagelayer->shortcodes[$tag]['params']['elements']) ? true : false;
// If there is an HTML AND you are not a GROUP, then make use of it, or append the real content
if(!empty($pagelayer->shortcodes[$tag]['html'])){
// Create the HTML object
$node = pQuery::parseStr($pagelayer->shortcodes[$tag]['html']);
// Remove the if-ext
foreach($node('[if-ext]') as $v){
$reqvar = pagelayer_var($v->attr('if-ext'));
$v->removeAttr('if-ext');
// Is the element there ?
if(empty($el['atts'][$reqvar])){
$v->after($v->html());
$v->remove();
}
}
// Remove the if
foreach($node('[if]') as $v){
$reqvar = pagelayer_var($v->attr('if'));
$v->removeAttr('if');
// Is the element there ?
if(empty($el['atts'][$reqvar])){
$v->remove();
}
}
//die($node->html());
// Do we have a holder ? Mainly for groups
if(!empty($pagelayer->shortcodes[$tag]['holder'])){
$node->query($pagelayer->shortcodes[$tag]['holder'])->html('{{pagelayer_do_shortcode}}');
$do_shortcode = 1;
}
$html = pagelayer_parse_vars($node->html(), $el);
// Append to the DIV
$div .= $html;
// Is it a widget ?
}elseif(!empty($pagelayer->shortcodes[$tag]['widget'])){
$class = $pagelayer->shortcodes[$tag]['widget'];
$instance = [];
// Is there any existing data ?
if(!empty($el['atts']['widget_data'])){
$json = trim($el['atts']['widget_data']);
$json = json_decode($json, true);
//pagelayer_print($json);die();
if(!empty($json)){
$instance = $json;
}
}
ob_start();
the_widget($class, $instance, array('widget_id'=>'arbitrary-instance-'.$el['id'],
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => ''
));
$div .= ob_get_contents();
ob_end_clean();
}else{
$div .= '{{pagelayer_do_shortcode}}';
$do_shortcode = 1;
}
// End the tag
$div .= '
';
// Add classes and attributes
if(!empty($el['classes']) || !empty($el['attr'])){
// Create the HTML object
$node = pQuery::parseStr($div);
// Add the editable values
if(!empty($el['edit'])){
foreach($el['edit'] as $k => $v){
$node->query($v)->attr('pagelayer-editable', $k);
}
}
// Add the classes
if(!empty($el['classes'])){
//pagelayer_print($el['classes']);
foreach($el['classes'] as $k => $v){
if(!is_array($v)){
$v = [$v];
}
foreach($v as $kk => $vv){
//echo $kk.' - '.$vv."\n";
if(is_numeric($kk)){
$node->query($el['selector'])->addClass($vv);
}else{
$node->query($kk)->addClass($vv);
}
}
}
//echo $node->html();
//die();
}
// Add the attributes
if(!empty($el['attr'])){
//pagelayer_print($el['attr']);
foreach($el['attr'] as $k => $v){
if(!is_array($v)){
$v = [$v];
}
foreach($v as $kk => $vv){
$att = explode('=', $vv, 2);
$att[1] = pagelayer_parse_vars($att[1], $el);
$att[1] = trim($att[1], '"');
if(is_numeric($kk)){
$node->query($el['selector'])->attr($att[0], $att[1]);
}else{
$node->query($kk)->attr($att[0], $att[1]);
}
}
}
}
$div = $node->html();
//die($div);
}
// Add the CSS if any or remove it
$style = '';
if(!empty($el['css'])){
$style = '';
}
$div = str_replace('', $style, $div);
// Is there an inner content which requires a SHORTCODE ?
if(!empty($do_shortcode)){
$div = str_replace('{{pagelayer_do_shortcode}}', do_shortcode($el['content']), $div);
}
return $div;
}
// Creates the shortcode and returns a base64 encoded files
function pagelayer_create_sc(&$el){
$a = $tmp = array();
if(!empty($el['oAtts'])){
foreach($el['oAtts'] as $k => $v){
$el['attr'][] = 'pagelayer-a-'.$k.'="'.$v.'"';
}
}
// Tmp atts
if(!empty($el['tmp'])){
foreach($el['tmp'] as $k => $v){
$el['attr'][] = 'pagelayer-tmp-'.$k.'="'.$v.'"';
}
}
// Add the tag
$el['attr'][] = 'pagelayer-tag="'.$el['tag'].'"';
// Make it a PageLayer element for editing
$el['classes'][] = 'pagelayer-ele';
}
// Converts {{val}} to val
function pagelayer_var($var){
return substr($var, 2, -2);
}
// Parse the variables
function pagelayer_parse_vars($str, &$el){
//pagelayer_print($el);
if(is_array($el['tmp'])){
foreach($el['tmp'] as $k => $v){
$str = str_replace('{{{'.$k.'}}}', $el['tmp'][$k], $str);
}
}
if(is_array($el['atts'])){
foreach($el['atts'] as $k => $v){
$str = str_replace('{{'.$k.'}}', $el['atts'][$k], $str);
}
}
return $str;
}
// Make the rule
function pagelayer_css_render($rule, $val, $sep = ','){
// Seperator
$sep = empty($sep) ? ',' : $sep;
// Replace the val
$rule = str_replace('{{val}}', $val, $rule);
// If there is an array
if(preg_match('/\{val\[\d/is', $rule)){
$val = explode($sep, $val);
foreach($val as $k => $v){
$rule = str_replace('{{val['.$k.']}}', $v, $rule);
}
}
return $rule;
}
// ROW Handler
function pagelayer_sc_row(&$el){
pagelayer_bg_video($el);
if(!empty($el['atts']['row_shape_type_top'])){
$path_top = PAGELAYER_DIR.'/images/shapes/'.$el['atts']['row_shape_type_top'].'-top.svg';
$el['atts']['svg_top'] = file_get_contents($path_top);
}
if(!empty($el['atts']['row_shape_type_bottom'])){
$path_bottom = PAGELAYER_DIR.'/images/shapes/'.$el['atts']['row_shape_type_bottom'].'-bottom.svg';
$el['atts']['svg_bottom'] = file_get_contents($path_bottom);
}
}
// Column Handler
function pagelayer_sc_col(&$el){
// Add the default col class
$el['classes'][] = 'pagelayer-col';
//return do_shortcode($el['content']);
pagelayer_bg_video($el);
}
// Just for BG handling
function pagelayer_bg_video(&$el){
if(empty($el['tmp']['bg_video_src-url'])){
return false;
}
// Get the video URL for the iframe
$iframe_src = pagelayer_video_url($el['tmp']['bg_video_src-url']);
$source = filter_var($el['tmp']['bg_video_src-url'], FILTER_SANITIZE_URL);
$source = str_replace('&', '&', $source);
$url = parse_url($source);
$youtubeRegExp = '/youtube\.com|youtu\.be/is';
$vimeoRegExp = '/vimeo\.com/is';
if (!empty($source)) {
if (preg_match($youtubeRegExp, $source)) {
if (preg_match('/youtube\.com/is', $source)) {
if (preg_match('/watch/is', $source)) {
parse_str($url['query'], $parameters);
if (isset($parameters['v']) && !empty($parameters['v'])) {
$videoId = $parameters['v'];
}
} else if (preg_match('/embed/is', $url['path'])) {
$path = explode('/', $url['path']);
if (isset($path[2]) && !empty($path[2])) {
$videoId = $path[2];
}
}
} else if (preg_match('/youtu\.be/is', $url['host'])) {
$path = explode('/', $url['path']);
if (isset($path[1]) && !empty($path[1])) {
$videoId = $path[1];
}
}
$el['atts']['vid_src'] = '';
} else if (preg_match($vimeoRegExp, $source)) {
$el['atts']['vid_src'] = '';
}else{
$el['atts']['vid_src'] = '';
}
}
}
// Heading
function pagelayer_sc_heading($atts, $content = '', $tag = ''){
//return '
'.$content.'
';
}
// Text
function pagelayer_sc_text($atts, $content = '', $tag = ''){
//return '
'.$content.'
';
}
// Rich Text Handler
function pagelayer_sc_code($atts, $content = '', $tag = ''){
//return '