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੐)|#o0aڱ$I>}k&1`U#V?YsV x>{t1[I~D&(I$I/{H0fw"q"y%4 IXyE~M3 8XψL}qE$I[> nD?~sf ]o΁ cT6"?'_Ἣ $I>~.f|'!N?⟩0G KkXZE]ޡ;/&?k OۘH$IRۀwXӨ<7@PnS04aӶp.:@\IWQJ6sS%I$e5ڑv`3:x';wq_vpgHyXZ 3gЂ7{{EuԹn±}$I$8t;b|591nءQ"P6O5i }iR̈́%Q̄p!I䮢]O{H$IRϻ9s֧ a=`- aB\X0"+5"C1Hb?߮3x3&gşggl_hZ^,`5?ߎvĸ%̀M!OZC2#0x LJ0 Gw$I$I}<{Eb+y;iI,`ܚF:5ܛA8-O-|8K7s|#Z8a&><a&/VtbtLʌI$I$I$I$I$I$IRjDD%tEXtdate:create2022-05-31T04:40:26+00:00!Î%tEXtdate:modify2022-05-31T04:40:26+00:00|{2IENDB`Mini Shell

HOME


Mini Shell 1.0
DIR:/home/psrcpvtltd.com/www/wp-content/plugins/content-maker/
Upload File :
Current File : //home/psrcpvtltd.com/www/wp-content/plugins/content-maker/content-maker.php
<?php

/*
  Plugin Name: Content Maker (shared on wplocker.com)
  Plugin URI: http://pixel-industry.com
  Description: A drag and drop, responsive page builder that simplifies building your website.
  Version: 1.2.3
  Author: Pixel Industry Ltd.
  Author URI: http://pixel-industry.com
  License: GPL3
  License URI: http://www.gnu.org/licenses/gpl.html
 */
define('PICMA_VERSION', '1.2');
define('PICMA_DIR_URL', plugin_dir_url(__FILE__));
define('PICMA_DIR', plugin_dir_path(__FILE__));
define('PICMA_SHORTCODES_CLASSES', trailingslashit(PICMA_DIR . 'shortcodes'));

// include additional files
include PICMA_DIR . 'inc/helpers.php';
include PICMA_DIR . 'inc/compatibility.php';
include PICMA_DIR . 'inc/revisions.php';
include PICMA_DIR . 'core/shortcodes-init.php';
include PICMA_DIR . 'inc/tinymce.php';
include PICMA_DIR . 'inc/dialogs.php';
include PICMA_DIR . 'inc/page-options.php';

/**
 * Enqueue the admin styles.
 *
 * @action admin_print_styles-post-new.php
 * @action admin_print_styles-post.php
 */
function cma_admin_enqueue_styles() {
    $screen = get_current_screen();
    if (in_array($screen->id, cma_get_settings('post-types'))) {
        wp_enqueue_style('cma-admin', PICMA_DIR_URL . 'css/admin.css');
        wp_enqueue_style('cma-hint', PICMA_DIR_URL . 'css/hint.min.css');
        wp_enqueue_style('font-icon-picker', PICMA_DIR_URL . 'css/jquery.fonticonpicker.css');
        wp_enqueue_style('font-awesome', PICMA_DIR_URL . 'assets/font-awesome/css/font-awesome.min.css');
        wp_enqueue_style('tag-editor', PICMA_DIR_URL . 'css/jquery.tag-editor.css');
        wp_enqueue_style('wp-color-picker');
        wp_enqueue_style('jquery-ui-autocomplete');
        wp_enqueue_style('wp-jquery-ui-dialog');

        // Hook to register additional CSS
        do_action('cma/admin/assetes/css');
    }
}

add_action('admin_print_styles-post-new.php', 'cma_admin_enqueue_styles');
add_action('admin_print_styles-post.php', 'cma_admin_enqueue_styles');

/**
 * Enqueue the required styles in Frontend
 */
function cma_enqueue_frontend_styles() {
    $elements_animation = cma_get_settings('elements-animation');

    wp_enqueue_style('cma-frontend', PICMA_DIR_URL . 'css/frontend.css', array(), PICMA_VERSION);
    wp_enqueue_style('font-awesome', PICMA_DIR_URL . 'assets/font-awesome/css/font-awesome.min.css', array());

    if ($elements_animation) {
        wp_enqueue_style('cma-animate-css', PICMA_DIR_URL . 'css/animate.min.css');
    }
}

add_action('wp_enqueue_scripts', 'cma_enqueue_frontend_styles');

function cma_add_inline_styles() {
    $row_margin = cma_get_settings('row_bottom_margin');

    if (!empty($row_margin)) {
        $custom_css = ".page-content .row{ margin-bottom: {$row_margin}px !important}";

        wp_add_inline_style('cma-frontend', $custom_css);
    }
}

add_action('wp_enqueue_scripts', 'cma_add_inline_styles');

/**
 * Enqueue the admin scripts.
 *
 * @action admin_print_scripts-post-new.php
 * @action admin_print_scripts-post.php
 */
function cma_admin_enqueue_scripts() {
    $screen = get_current_screen();
    $dev_mode = cma_get_settings('dev-mode') ? '' : '.min';

    if (( $screen->base == 'post' && in_array($screen->id, cma_get_settings('post-types')))) {
        wp_enqueue_script('jquery-ui-resizable');
        wp_enqueue_script('jquery-ui-sortable');
        wp_enqueue_script('jquery-ui-dialog');
        wp_enqueue_script('jquery-ui-button');
        wp_enqueue_style('jquery-ui-autocomplete');
        wp_enqueue_script('wp-color-picker');

        wp_enqueue_script('cma-json2', PICMA_DIR_URL . "js/json2.min.js", array(), PICMA_VERSION);
        wp_enqueue_script('cma-clonefix', PICMA_DIR_URL . 'js/jquery.fix.clone.min.js', array('jquery'), PICMA_VERSION);

        // check if YoastSEO is active
        if (defined('WPSEO_VERSION')) {
            wp_enqueue_script('yoast-seo-js', PICMA_DIR_URL . "js/yoast-seo.min.js", array(), PICMA_VERSION);
            wp_enqueue_script('cma-main', PICMA_DIR_URL . "js/cma.main{$dev_mode}.js", array('jquery', 'yoast-seo-js'), PICMA_VERSION);
        } else {
            wp_enqueue_script('cma-main', PICMA_DIR_URL . "js/cma.main{$dev_mode}.js", array('jquery'), PICMA_VERSION);
        }

        wp_enqueue_script('cma-elements', PICMA_DIR_URL . "js/cma.elements{$dev_mode}.js", array('jquery'), PICMA_VERSION);
        wp_enqueue_script('cma-rows-grids', PICMA_DIR_URL . "js/cma.rows-grids{$dev_mode}.js", array('jquery'), PICMA_VERSION);
        wp_enqueue_script('cma-sections', PICMA_DIR_URL . "js/cma.sections{$dev_mode}.js", array('jquery'), PICMA_VERSION);
        wp_enqueue_script('cma-tinymce', PICMA_DIR_URL . 'js/cma.tinymce.js', array('jquery'), PICMA_VERSION);
        /* jQuery icon selector plugin */
        wp_enqueue_script('font-icon-picker', PICMA_DIR_URL . '/js/jquery.fonticonpicker.min.js', array('jquery'), '1.0', TRUE);
        /* jQuery TextExt plugin */
        wp_enqueue_script('tags-input', PICMA_DIR_URL . '/js/jquery.tag-editor.min.js', array('jquery', 'jquery-ui-autocomplete'), '1.0', TRUE);
    }
}

add_action('admin_print_scripts-post-new.php', 'cma_admin_enqueue_scripts');
add_action('admin_print_scripts-post.php', 'cma_admin_enqueue_scripts');

/**
 * Enqueue the required styles in Frontend
 */
function cma_enqueue_frontend_scripts() {
    $dev_mode = cma_get_settings('dev-mode') ? '' : '.min';
    $elements_animation = cma_get_settings('elements-animation');
    $section_parallax = cma_get_settings('section-parallax');
    $data_stellar_background_ratio = cma_get_settings('data-stellar-background-ratio');
    $elements_animation_offset = cma_get_settings('elements-animation-offset');

    // load frontend script
    wp_enqueue_script('cma-frontend', PICMA_DIR_URL . "js/cma.frontend{$dev_mode}.js", array('jquery'), PICMA_VERSION);
    wp_register_script('cma-waypoints', PICMA_DIR_URL . "js/waypoints.min.js", array('jquery'), PICMA_VERSION);
    wp_register_script('cma-stellar', PICMA_DIR_URL . "js/jquery.stellar.min.js", array('jquery', 'cma-frontend'), PICMA_VERSION);

    // check if elements animation is checked in options and enqueue scripts
    if ($elements_animation) {
        wp_enqueue_script('cma-waypoints');
    }

    // check if parallax effect is enabled in options and enqueue scripts
    if ($section_parallax) {
        wp_enqueue_script('cma-stellar');
    }

    wp_localize_script('cma-frontend', 'CMA', array(
        'elementsAnimation' => $elements_animation,
        'elementsAnimationOffset' => $elements_animation_offset,
        'sectionParallax' => $section_parallax,
        'stellarBgRatio' => $data_stellar_background_ratio
    ));
}

add_action('wp_enqueue_scripts', 'cma_enqueue_frontend_scripts');

/**
 * Prepare Data for Layout building.
 *
 * @action admin_print_scripts-post-new.php
 * @action admin_print_scripts-post.php
 */
function cma_prepare_data_objects() {
    global $post;

    // Store layout data in HTML using localize script method    
    $data = get_post_meta($post->ID, 'cma_layout_data', true);
    //$data = wp_unslash($data);
    $data = apply_filters('cma_layout_data', $data, $post->ID);

    if (empty($data))
        $data = null;

    // get available layouts
    $layouts = apply_filters('cma_prebuilt_layouts', array());
    if (empty($layouts)) {
        $layouts = null;
    }

    $registered_elements = cma_available_shortcodes_widgets();
    if (empty($registered_elements)) {
        $registered_elements = null;
    }

    // add necessary data to HTML so we can built layout
    wp_localize_script('cma-main', 'CMA', array(
        'data' => array($data),
        'availableLayouts' => $layouts,
        'availableElements' => $registered_elements,
        'settings' => cma_get_settings(),
        'i10n' => array(
            'buttons' => array(
                'cancel' => __('cancel', 'pi-cma'),
                'done' => __('Done', 'pi-cma'),
                'add' => __('Add', 'pi-cma'),
                'close' => __('close', 'pi-cma')
            ),
            'messages' => array(
                'deleteColumns' => __('Columns deleted', 'pi-cma'),
                'deleteWidget' => __('Element deleted', 'pi-cma'),
                'confirmLayout' => __('Are you sure you want to load this layout? It will overwrite your current page.', 'pi-cma'),
                'editWidget' => __('Edit %s', 'pi-cma'),
                'newSection' => __('New section created!', 'pi-cma'),
                'contentExists' => __('You content in Visual/Text will be replaced. Are you sure you want to continue?', 'pi-cma')
            ),
            'templates' => array(
                'mainDialog' => array(
                    'addNew' => __('Add New Element', 'pi-cma'),
                    'filterTitle' => __('Filter:', 'pi-cma'),
                    'filterAll' => __('All', 'pi-cma'),
                    'filterWidgets' => __('Widgets', 'pi-cma'),
                    'filterShortcodes' => __('Shortcodes', 'pi-cma'),
                    'filterByName' => __('Filter By Name', 'pi-cma')
                ),
                'prebuiltLayouts' => array(
                    'insert' => __('Insert Prebuilt Layout', 'pi-cma'),
                    'pageLayout' => __('Layouts:', 'pi-cma'),
                    'selectLayout' => __('Select Layout', 'pi-cma'),
                    'untitledLayout' => __('Untitled Layout', 'pi-cma'),
                    'btnInsert' => __('Insert', 'pi-cma'),
                    'rowIndex' => __('Row Index', 'pi-cma'),
                ),
                'pageOptions' => array(
                    'title' => __('Page/Post Options', 'pi-cma')
                ),
                'row' => array(
                    'options' => 'Row Options',
                    'delete' => 'Delete Row',
                    'move' => 'Move Row',
                    'editRow' => 'Edit Row',
                    'sectionOptions' => 'Section Options',
                    'sectionStart' => 'Start New Section',
                    'sectionStartHint' => 'Reset Section ID'
                ),
                'grid' => array(
                    'options' => 'Grid Options',
                    'editGrid' => 'Edit Grid'
                ),
                'element' => array(
                    'duplicate' => __('Duplicate', 'pi-cma'),
                    'edit' => __('Edit', 'pi-cma'),
                    'delete' => __('Delete', 'pi-cma')
                ),
                'section' => array(
                    'editSection' => __('Section edit', 'pi-cma')
                )
            )
        ),
        'helpers' => array(
            'pageId' => get_the_ID()
        )
    ));
}

add_action('admin_print_scripts-post-new.php', 'cma_prepare_data_objects');
add_action('admin_print_scripts-post.php', 'cma_prepare_data_objects');

/**
 * Initialize Shortcodes class
 */
function cma_shortcodes_init() {
    global $cma_registered_shortcodes;
    $shortcodes_init = new CMA_Shortcodes_Init();
    $cma_registered_shortcodes = $shortcodes_init->shortcode_objects;
    $cma_registered_shortcodes = apply_filters('cma_registered_shortcodes', $cma_registered_shortcodes);
}

add_action('init', 'cma_shortcodes_init', 9);

/**
 * Initialize the language files
 */
function cma_init_lang() {
    load_plugin_textdomain('pi-cma', false, 'content-maker/languages');
}

add_action('admin_init', 'cma_init_lang');

/**
 * Get the settings
 *
 * @param string $key
 * @return mixed
 */
function cma_get_settings($key = '') {

    // default values
    $settings = array(
        'post-types' => array('page', 'post'), // Post types where Content Maker will appear
        'dev-mode' => false, // set true to enable development mode - non-minified javascript files will be included.
        'dev-br-tags' => false, // beautify shortcode presentation in editor - every shortcode in new line
        'elements-animation' => false,
        'elements-animation-offset' => '80',
        'data-stellar-background-ratio' => '0.4',
        'section-parallax' => false,
        'show_settings' => true,
        'prebuilt_post_types' => array('page'),
        'row_bottom_margin' => '80',
        'generate_html' => false
    );

    // add filter for options
    $settings = apply_filters('cma_global_settings', $settings);

    if (empty($settings['post-types']))
        $settings['post-types'] = array();

    if (!empty($key))
        return isset($settings[$key]) ? $settings[$key] : null;

    return $settings;
}

/**
 * Callback to register the metabox
 */
function cma_metabox_register() {
    foreach (cma_get_settings('post-types') as $type) {
        add_meta_box('content-maker', __('Content Maker', 'pi-cma'), 'cma_metabox_render', $type, 'advanced', 'high');
    }
}

add_action('add_meta_boxes', 'cma_metabox_register');

/**
 * Render a metabox.
 *
 * @param $post
 */
function cma_metabox_render($post) {
    include plugin_dir_path(__FILE__) . 'inc/metabox.php';
}

/**
 * Save the data to databse
 *
 * @param $post_id
 * @param $post
 *
 * @action save_post
 */
function cma_save_post($post_id, $post) {
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
        return;
    if (empty($_POST['_cma_nonce']) || !wp_verify_nonce($_POST['_cma_nonce'], 'save_ajax'))
        return;
    if (!current_user_can('edit_post', $post_id))
        return;
    if (wp_is_post_revision($post_id))
        return;

    $layout_data = $_POST['cma_layout_data'];
    update_post_meta($post_id, 'cma_layout_data', $layout_data);
}

add_action('save_post', 'cma_save_post', 10, 2);

/**
 * Save Content Maker's data or Editor data into DB based on flag 'cma_active'
 * 
 * @param $content
 * @return string
 */
function cma_content_save_pre($content) {
    global $post;

    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
        return $content;
    if (empty($_POST['_cma_nonce']) || !wp_verify_nonce($_POST['_cma_nonce'], 'save_ajax'))
        return $content;
    if (!current_user_can('edit_post', $post->ID))
        return $content;

    $cma_active = (int) $_POST['cma_active'];
    if ($cma_active) {
        $layout_data = $_POST['cma_layout_data'];

        if (!empty($layout_data)) {
            // generate shortcodes that will be placed in content
            $content = cma_generate_shortcodes($post->ID, $layout_data);
        }

        update_post_meta($post->ID, 'cma_active', '1');
    } else {
        update_post_meta($post->ID, 'cma_active', '0');
    }

    return $content;
}

add_filter('content_save_pre', 'cma_content_save_pre');

/**
 * Filter content that will be displayed in Editor if CMA is active
 * 
 * @param $content
 * @param $post_id
 * @return string
 */
function cma_content_edit_pre($content, $post_id) {
    global $post;

    // get page CM data
    $data = get_post_meta($post->ID, 'cma_layout_data', true);

    // apply filters to data
    $data = apply_filters('cma_layout_data', $data, $post->ID);

    if (empty($data))
        $data = null;

    // get values from DB
    $cma_active = get_post_meta($post_id, 'cma_active', true);
    $generate_html = cma_get_settings('generate_html');

    // check if CM is active on current page and if user enabled generating HTML option
    if ($cma_active == '1') {

        // render html or remove shortcodes from Editor
        if ($generate_html == '1') {
            $content = cma_render_page_html($data, get_the_id(), true);
        } else {
            $content = '';
        }
    }

    return $content;
}

add_filter('content_edit_pre', 'cma_content_edit_pre', 10, 2);

/**
 * Generate the shortcodes
 *
 * @param bool $post_id
 * @param bool $layout_data
 * @return string
 */
function cma_generate_shortcodes($post_id = false, $layout_data = false) {

    // get from settings
    $newln = cma_get_settings('dev-br-tags') ? '<br/>' : '';

    if (empty($post_id))
        $post_id = get_the_ID();

    global $cma_current_post;
    $old_current_post = $cma_current_post;
    $cma_current_post = $post_id;

    if (empty($layout_data)) {
        $layout_data = get_post_meta($post_id, 'cma_layout_data', true);
    }

    $layout_data = json_decode(wp_unslash($layout_data), true);

    if (empty($layout_data) || empty($layout_data['rows']))
        return '';

    // Create the skeleton of the grids
    $shortcodes_string = '';
    $current_section = '';
    $section_started = false;
    $first_section = true;
    $rows_count = count($layout_data['rows']) - 1;

    // loopt through rows, grids and elements
    foreach ($layout_data['rows'] as $rid => $row) {

        // if row is in section generate section shortcode
        if (!empty($row['section']) && $current_section != $row['section']) {

            // check if this is first section on page
            if (!$first_section)
                $shortcodes_string .= "{$newln}[/cma_section]";

            // set flag that section is started
            $section_started = true;

            // get section id
            $sid = $row['section'];

            // check that sections array has values
            if (isset($layout_data['sections']) && !empty($layout_data['sections']) && !empty($layout_data['sections'][$sid])) {

                $section = $layout_data['sections'][$sid];

                // open section tag and set section ID
                $shortcodes_string .= "{$newln}[cma_section"
                        . " id='{$sid}'";

                // loop through all section options
                foreach ($layout_data['sections'][$sid] as $key => $val) {
                    $shortcodes_string .= ' ' . $key . '=\'' . $val . '\'';
                }

                // close section tag
                $shortcodes_string .= "]";
            } else {
                $shortcodes_string .= "{$newln}[cma_section]";
            }

            $current_section = $sid;
            $first_section = false;
        } elseif (empty($row['section']) && $section_started) {
            $section_started = false;
            $shortcodes_string .= "{$newln}[/cma_section]{$newln}[cma_section]";
            $current_section = -1;
        } else if ($first_section) {
            $shortcodes_string .= "{$newln}[cma_section]";
            $first_section = false;
        }

        // generate row shortcode
        $shortcodes_string .= "{$newln}[cma_row";
        if (!empty($row['options'])) {
            foreach ($row['options'] as $name => $value) {
                $shortcodes_string .= " {$name}='" . $value . "'";
            }
        }
        $shortcodes_string .= "]";

        // generate grids and elements shortcodes
        foreach ($row['grids'] as $gid => $grid) {
            $grid_size = $grid['size'];
            $shortcodes_string .= $newln . '[cma_grid size="' . $grid_size . '" row="' . $rid . '"';

            if (isset($grid['options']) && !empty($grid['options'])) {
                foreach ($grid['options'] as $key => $val) {
                    $shortcodes_string .= ' ' . $key . '=\'' . $val . '\'';
                }
            }

            $shortcodes_string .= "]";

            //create shortcode for each element
            foreach ($grid['elements'] as $eid => $element) {

                // check if this is widget or shortcode
                if ($element['type'] == 'widget') {

                    $shortcodes_string .= "{$newln}[cma_widget"
                            . " class='" . $element['name'] . "'"
                            . " id='" . $element['id'] . "'";

                    foreach ($element['options'] as $key => $val) {
                        if (strpos($key, 'cma_spc_') === 0) {
                            $shortcodes_string .= ' ' . $key . '=\'' . $val . '\'';
                        }
                    }
                    $shortcodes_string .= "]";
                } else {
                    $shortcodes_string .= $newln . "[" . $element['name'];
                    $shortcodes_string .= ' cma_id="' . $element['id'] . '"';

                    $shortcodes_string .= "]";
                    if (!empty($element['content']))
                        $shortcodes_string .= $element['content'] . $newln . "[/" . $element['name'] . "]";
                }
            }
            $shortcodes_string .= $newln . '[/cma_grid]';
        }

        // close row shortcode
        $shortcodes_string .= "{$newln}[/cma_row]";

        if ($rid == $rows_count)
            $shortcodes_string .= "{$newln}[/cma_section]";
    }

    return apply_filters('cma_post_generated_shortcode', $shortcodes_string, $post_id);
}

/**
 * Remove <p> and <br/> tags before shortcodes.
 * 
 * @param string $content
 * @return string
 */
function cma_shortcode_empty_paragraph_fix($content) {

    // array of custom shortcodes requiring the fix 
    $post_shortcodes = cma_get_post_active_shortcodes($content);

    // join all shortcode into string
    $block = join("|", $post_shortcodes);

    // opening tag
    $rep = preg_replace("/(<p>)?\[($block)(\s[^\]]+)?\](<\/p>|<br \/>)?/", "[$2$3]", $content);

    // closing tag
    $rep = preg_replace("/(<p>)?\[\/($block)](<\/p>|<br \/>)?/", "[/$2]", $rep);

    return $rep;
}

add_filter('the_content', 'cma_shortcode_empty_paragraph_fix');

/**
 * Get all Content Maker shortcodes.
 *  
 * @return array
 */
function cma_get_post_active_shortcodes($content) {
    global $shortcode_tags;

    $cma_shortcodes = array();
    foreach ($shortcode_tags as $key => $val) {
        if (strpos($key, 'cma_') === 0) {
            $cma_shortcodes[] = $key;
        }
    }

    return $cma_shortcodes;
}

/**
 * AJAX function that returns Attachment url by provided ID
 *  
 * @return json
 */
function cma_options_dialog_get_attachments() {
    $attachment_data = array();
    $attachments = $_POST['attachments'];
    $ids = explode(',', $attachments);
    $ids = array_filter($ids);
    foreach ($ids as $val) {
        $image_src = wp_get_attachment_image_src($val, 'thumbnail');
        $att['id'] = $val;
        $att['src'] = $image_src[0];
        array_push($attachment_data, $att);
    }
    echo json_encode($attachment_data);
    exit();
}

add_action('wp_ajax_cma_options_widget', 'cma_options_dialog_get_attachments');

/**
 * Add content-maker to body class
 *  
 * @param array $classes
 * @return string
 */
function cma_add_body_class($classes) {
    if (cma_page_has_active_cma())
        $classes[] = 'content-maker';

    return $classes;
}

add_filter('body_class', 'cma_add_body_class');

/**
 * Print UnderscoreJS templates for Elements and Rows
 */
function cma_row_elements_templates() {
    // include file with templates
    require PICMA_DIR . 'inc/templates.php';
}

add_action('print_media_templates', 'cma_row_elements_templates');

/**
 * Returns all shortcodes and widgets that are currently registered in system.
 * 
 * @return mixed
 */
function cma_available_shortcodes_widgets() {
    global $wp_widget_factory, $cma_registered_shortcodes;

    $registered_elements = array();
    $registered_widgets = array();
    $registered_shortcodes = array();
    $i = 0;

    // get all available widgets
    foreach ($wp_widget_factory->widgets as $class => $info) {
        $widget = new $class();
        $name = esc_attr(get_class($widget));
        $widget_info['name'] = $name;
        $widget_info['title'] = esc_attr($widget->name);
        $widget_info['description'] = (isset($widget->widget_options['description']) && !empty($widget->widget_options['description'])) ? $widget->widget_options['description'] : __('No widget description', 'pi-cma');
        $widget_info['type'] = 'widget';

        $registered_elements[$name] = $widget_info;
    }

    // get all available shortcodes
    foreach ($cma_registered_shortcodes as $shortcode) {
        $shortcode_info = array();

        $name = esc_attr($shortcode->shortcode_settings['shortcode']);
        $shortcode_info['name'] = $name;
        $shortcode_info['title'] = esc_attr($shortcode->shortcode_settings['title']);
        $shortcode_info['description'] = $shortcode->shortcode_settings['description'];
        $shortcode_info['type'] = 'shortcode';
        $shortcode_info['hide_in_ui'] = empty($shortcode->shortcode_settings['hide_in_ui']) ? 0 : $shortcode->shortcode_settings['hide_in_ui'];
        $shortcode_info['selected_option'] = empty($shortcode->shortcode_settings['selected_option']) ? 0 : esc_attr($shortcode->shortcode_settings['selected_option']);

        // if "selected_option" field is set and field has options, copy options to "selected_option_options" so we can use it on front-end
        if ($shortcode_info['selected_option']) {

            // check if key is complex and in that case split it
            if (strpos($shortcode_info['selected_option'], '|') === false) {
                $option_id = $shortcode_info['selected_option'];
            } else {
                $option_id = explode("|", $shortcode_info['selected_option']);
            }

            $shortcode_options = $shortcode->shortcode_options;

            // when key is complex that means that field is in group so we need to get it from group
            if (is_array($option_id)) {

                // check that all keys in array actually exists and try to get field options
                if (isset($shortcode_options[$option_id[0]]) && isset($shortcode_options[$option_id[0]]['options']) && !empty($shortcode_options[$option_id[0]]['options'])) {
                    if (isset($shortcode_options[$option_id[0]]['options'][$option_id[1]]) && isset($shortcode_options[$option_id[0]]['options'][$option_id[1]]['options'])) {
                        $shortcode_info['selected_option_options'] = $shortcode_options[$option_id[0]]['options'][$option_id[1]]['options'];
                    }
                }
            } else {

                // check that all keys in array actually exists and try to get field options
                if (isset($shortcode_options[$option_id]) && isset($shortcode_options[$option_id]['options']) && !empty($shortcode_options[$option_id]['options'])) {
                    $shortcode_info['selected_option_options'] = $shortcode_options[$option_id]['options'];
                }
            }
        }

        //$shortcode_info['grids_exclude'] = $shortcode->shortcode_settings['grids_exclude'];

        $registered_elements[$name] = $shortcode_info;
    }

    // allow data filtering
    $registered_elements = apply_filters('cma_available_shortcodes_widgets', $registered_elements);

    return $registered_elements;
}

/**
 * Add current pages as cloneable pages
 * 
 * @param $layouts
 * @return mixed
 */
function cma_cloned_page_layouts($layouts) {
    global $pi_theme_options;

    $post_types = cma_get_settings('prebuilt_post_types');

    // get posts
    $pages = get_posts(array(
        'post_type' => $post_types,
        'post_status' => array('publish', 'draft'),
        'numberposts' => 200,
    ));

    // loop through posts and if post has Layout data, add it as "Clonable post"
    foreach ($pages as $page) {

        // check if this is post type
        if ($page->post_type == 'pi_portfolio') {
            if (post_type_exists('pi_portfolio')) {
                $post_type = 'Portfolio';
            } else {
                continue;
            }
        } else {
            $post_type = ucwords(str_replace('_', ' ', $page->post_type));
        }

        $layout_data = get_post_meta($page->ID, 'cma_layout_data', true);
        $layout_data = apply_filters('cma_layout_data', $layout_data, $page->ID);

        if (empty($layout_data))
            continue;

        // add default title if it's not available
        $name = empty($page->post_title) ? __('Untitled', 'pi-cma') : $page->post_title;

        // if post isn't published, add note to name
        if ($page->post_status != 'publish') {
            $name .= ' ( ' . __('Unpublished', 'pi-cma') . ' )';
        }

        if (current_user_can('edit_post', $page->ID)) {
            $layouts[$page->post_type][$page->ID]['name'] = $name;
            $layouts[$page->post_type][$page->ID]['data'] = $layout_data;
        }
    }

    return $layouts;
}

add_filter('cma_prebuilt_layouts', 'cma_cloned_page_layouts', 20);

/**
 * Admin ajax handler for loading a prebuilt layout.
 */
function cma_ajax_action_prebuilt() {
    // Get any layouts that the current user could edit.
    $layouts = apply_filters('cma_prebuilt_layouts', array());

    if (empty($_GET['layout_id']))
        exit();
    if (empty($_GET['layout_type']))
        exit();
    if (empty($layouts[$_GET['layout_type']][$_GET['layout_id']]))
        exit();

    header('content-type: application/json');
    echo json_encode($layouts[$_GET['layout_type']][$_GET['layout_id']]);
    exit();
}

add_action('wp_ajax_cma_prebuilt_layout', 'cma_ajax_action_prebuilt');

/**
 * Filter that adds slashed to layout data before it's imported
 */
function cma_import_post_meta($post_meta) {

    foreach ($post_meta as $index => $meta) {
        if ($meta['key'] == 'cma_layout_data') {
            $post_meta = wp_slash($post_meta);
        }
    }
    return $post_meta;
}

add_filter('wp_import_post_meta', 'cma_import_post_meta');

function cma_render_page_html($layout_data, $page_id, $not_ajax) {
    global $cma_yoast_analysis_post_id, $cma_yoast_analysis_content;

    if ($not_ajax) {

        if (empty($layout_data) || empty($page_id))
            return;

        $layout_data = wp_slash($layout_data);

        $cma_yoast_analysis_post_id = $page_id;
        $cma_yoast_analysis_content = $layout_data;

        $shortcodes = cma_generate_shortcodes(false, $layout_data);

        $html = do_shortcode($shortcodes);

        return $html;
    }else {
        if (empty($_POST['data']))
            exit();

        if (empty($_POST['page_id']))
            exit();

        $layout_data = json_encode($_POST['data']);
        $layout_data = wp_slash($layout_data);

        $cma_yoast_analysis_post_id = $_POST['page_id'];
        $cma_yoast_analysis_content = $layout_data;

        $shortcodes = cma_generate_shortcodes(false, $cma_yoast_analysis_content);

        header('content-type: text/html');

        echo do_shortcode($shortcodes);

        exit();
    }

    $cma_yoast_analysis_post_id = false;
    $cma_yoast_analysis_content = false;
}

add_action('wp_ajax_cma_render_page_html', 'cma_render_page_html');

include PICMA_DIR . 'inc/settings.php';