$atts[$currentKey] = shortcode_parse_atts($used[3][$currentKey]);
                    } else {
                        $atts[$currentKey] = array();
                    }
                    $IDs[$currentKey] = $element;
                    $shortcodes[$currentKey] = $options['shortcode'];
                    $cfg = get_option($element);
                }
            }
        }
    }
}
if (!empty($IDs)) {
    foreach ($IDs as $currentKey => $ID) {
        $instance[$currentKey] = msc_getDefaultAtts($ID, $atts[$currentKey]);
        msc_processHeaders($ID, $instance[$currentKey]);
    }
    if (isset($cfg['_defaultContent'])) {
        $content = $cfg['_defaultContent'];
    } else {
        $content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus et feugiat eros. Praesent ac justo orci, quis ornare mi. Quisque dictum eleifend diam, eu congue augue congue ultrices. Proin convallis auctor neque, semper luctus libero pulvinar vel.";
    }
    $outPutCode = msc_doShortcode($instance[0]['atts'], $content, $shortcodes[0]);
    global $wp_scripts;
    $headerscripts = $preheaderscripts . $headerscripts;
}
?>
<!DOCTYPE html>
<html>
    <head>
        <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
Exemple #2
0
function msc_elementDetect()
{
    global $contentPrefilters, $footerOutput, $headerscripts, $phpincludes, $headerContent, $footerContent;
    $elements = get_option('CE_ELEMENTS');
    if (empty($elements)) {
        return $template;
    }
    //return;
    $postID = url_to_postid($_SERVER['REQUEST_URI']);
    if (empty($postID)) {
        $frontPage = get_option('page_on_front');
        if (!empty($frontPage)) {
            $frontPage = get_option('page_on_front');
            $posts[] = get_post($frontPage);
        } else {
            $args = array('numberposts' => get_option('posts_per_page'));
            $posts = get_posts($args);
        }
    } else {
        $posts[] = get_post($postID);
    }
    //    vardump($posts);
    // get always loads
    $AlwaysLoads = get_option('CE_ALWAYSLOAD');
    if (!empty($AlwaysLoads)) {
        foreach ($AlwaysLoads as $ID => $Location) {
            if (!empty($elements[$ID]['state'])) {
                $options = $elements[$ID];
                if (!empty($options['variables'])) {
                    $setAtts = get_option($ID . '_cfg');
                    if (empty($setAtts)) {
                        $setAtts = array();
                    }
                    $atts = array();
                    foreach ($options['variables']['names'] as $varkey => $variable) {
                        if ($options['variables']['type'][$varkey] == 'Dropdown') {
                            $options['variables']['defaults'][$varkey] = trim(strtok($options['variables']['defaults'][$varkey], ','));
                        }
                        if (!empty($options['variables']['multiple'][$varkey])) {
                            $endLoop = true;
                            $loopIndex = 1;
                            while ($endLoop) {
                                if (isset($setAtts[$variable . '_' . $loopIndex])) {
                                    $atts[$variable . '_' . $loopIndex] = $setAtts[$variable . '_' . $loopIndex];
                                    $loopIndex++;
                                } else {
                                    if ($loopIndex === 1) {
                                        $atts[$variable . '_' . $loopIndex] = $options['variables']['defaults'][$varkey];
                                    }
                                    $endLoop = false;
                                }
                            }
                        } else {
                            $atts[$variable] = $options['variables']['defaults'][$varkey];
                        }
                    }
                }
                if (!empty($setAtts) && !empty($atts)) {
                    $shortcodes[$ID][] = shortcode_atts($atts, $setAtts);
                } else {
                    $shortcodes[$ID][] = false;
                }
            }
        }
    }
    foreach ($elements as $key => $el) {
        if (empty($el['state'])) {
            unset($elements[$key]);
        }
    }
    // scan the posts
    if (!empty($posts)) {
        foreach ($posts as $postKey => $post) {
            $content = $post->post_content;
            $used = msc_getUsedShortcodes($content);
            foreach ($elements as $element => $options) {
                if (!empty($options['shortcode'])) {
                    if ($keys = array_keys($used[2], $options['shortcode'])) {
                        foreach ($keys as $key) {
                            if (!empty($used[3][$key])) {
                                $setAtts = shortcode_parse_atts($used[3][$key]);
                            } else {
                                $setAtts = array();
                            }
                            if (!empty($options['variables'])) {
                                $atts = array();
                                foreach ($options['variables']['names'] as $varkey => $variable) {
                                    if (!empty($options['variables']['type'][$varkey])) {
                                        if ($options['variables']['type'][$varkey] == 'Dropdown') {
                                            $options['variables']['defaults'][$varkey] = trim(strtok($options['variables']['defaults'][$varkey], ','));
                                        }
                                    }
                                    if (!empty($options['variables']['multiple'][$varkey])) {
                                        $endLoop = true;
                                        $loopIndex = 1;
                                        while ($endLoop) {
                                            if (isset($setAtts[$variable . '_' . $loopIndex])) {
                                                $atts[$variable . '_' . $loopIndex] = $setAtts[$variable . '_' . $loopIndex];
                                                $loopIndex++;
                                            } else {
                                                if ($loopIndex === 1) {
                                                    $atts[$variable . '_' . $loopIndex] = $options['variables']['defaults'][$varkey];
                                                }
                                                $endLoop = false;
                                            }
                                        }
                                    } else {
                                        $atts[$variable] = $options['variables']['defaults'][$varkey];
                                    }
                                }
                            }
                            if (!empty($options['removelinebreaks'])) {
                                $preContent = $used[5][$key];
                                for ($i = count($used[0]) - 1; $i > $key; $i--) {
                                    $preContent = str_replace($used[0][$i], '[*' . $i . '*]', $preContent);
                                }
                                $preContent = str_replace(array("\r\n", "\r"), "", $preContent);
                                for ($i = count($used[0]) - 1; $i > $key; $i--) {
                                    $preContent = str_replace('[*' . $i . '*]', $used[0][$i], $preContent);
                                }
                                $post->post_content = trim(str_replace($used[5][$key], $preContent, $post->post_content));
                                $contentPrefilters[$post->ID] = $post->post_content;
                            }
                            if (!empty($setAtts) && !empty($atts)) {
                                $shortcodes[$element][] = shortcode_atts($atts, $setAtts);
                            } else {
                                $shortcodes[$element][] = false;
                            }
                        }
                    }
                }
            }
        }
    }
    /* Scan for active widgets*/
    $texts = get_option('widget_ceelements');
    $sidebars = get_option('sidebars_widgets');
    unset($sidebars['wp_inactive_widgets']);
    foreach ($sidebars as $sidebar => $set) {
        if (is_active_sidebar($sidebar)) {
            foreach ($set as $widget) {
                if (substr($widget, 0, 11) == 'ceelements-') {
                    $id = substr($widget, 11);
                    if (!empty($texts[$id])) {
                        $element = $texts[$id]['_element'];
                        if (!empty($elements[$element])) {
                            $options = $elements[$element];
                            unset($texts[$id]['_catagory']);
                            unset($texts[$id]['_element']);
                            $instance = $texts[$id];
                            if (!empty($options['shortcode']) && !empty($options['state']) && ($options['elementType'] == 2 || $options['elementType'] == 3)) {
                                if (!empty($instance)) {
                                    $setAtts = $instance;
                                } else {
                                    $setAtts = array();
                                }
                                $atts = array();
                                if (!empty($options['variables'])) {
                                    foreach ($options['variables']['names'] as $varkey => $variable) {
                                        if ($options['variables']['type'][$varkey] == 'Dropdown') {
                                            $options['variables']['defaults'][$varkey] = trim(strtok($options['variables']['defaults'][$varkey], ','));
                                        }
                                        if (!empty($options['variables']['multiple'][$varkey])) {
                                            $endLoop = true;
                                            $loopIndex = 1;
                                            while ($endLoop) {
                                                if (isset($setAtts[$variable . '_' . $loopIndex])) {
                                                    $atts[$variable . '_' . $loopIndex] = $setAtts[$variable . '_' . $loopIndex];
                                                    $loopIndex++;
                                                } else {
                                                    if ($loopIndex === 1) {
                                                        $atts[$variable . '_' . $loopIndex] = $options['variables']['defaults'][$varkey];
                                                    }
                                                    $endLoop = false;
                                                }
                                            }
                                        } else {
                                            $atts[$variable] = $options['variables']['defaults'][$varkey];
                                        }
                                    }
                                }
                                if (!empty($setAtts) && !empty($atts)) {
                                    $shortcodes[$element][] = shortcode_atts($atts, $setAtts);
                                } else {
                                    $shortcodes[$element][] = false;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (empty($shortcodes)) {
        return;
    }
    //dump($shortcodes);
    foreach ($shortcodes as $ID => $Instances) {
        foreach ($Instances as $no => $atts) {
            $atts = msc_getDefaultAtts($ID, $atts);
            msc_processHeaders($ID, $atts);
        }
    }
    return;
}