<?php
    function cloudslider($id) {
        global $wpdb, $objCloudSlider;
        echo do_shortcode("[cloudslider id='".$id."']");
    }

    function cs_directory_install()
    {
        global $wpdb;
        if (!get_option('cs_googlefonts')) {
            update_option('cs_googlefonts', 'Open+Sans:300|Oswald:300,regular,700|Playball|Lato:300,400,700|Oxygen:400,700');
        }
        require_once (ABSPATH . "wp-admin/includes/upgrade.php");

        $tableName = $wpdb->prefix . "cloudslider";
        $checkSQL = "show tables like '$tableName'";

        if (!empty($wpdb->dbh_connections)) { // Multi DB
            foreach($wpdb->dbh_connections as $dbh_connection) {
                $db_name = $dbh_connection['name'];
                $create_table = "CREATE TABLE IF NOT EXISTS  $db_name.$tableName(
                id INT NOT NULL AUTO_INCREMENT,name VARCHAR(100),data longtext,author_id int(11),created timestamp default CURRENT_TIMESTAMP,
                modified datetime default NULL,type VARCHAR(10), PRIMARY KEY (id));";
                dbDelta($create_table);
            }
        } else {
            $create_table = "CREATE TABLE IF NOT EXISTS  $tableName(
            id INT NOT NULL AUTO_INCREMENT,name VARCHAR(100),data longtext,author_id int(11),created timestamp default CURRENT_TIMESTAMP,
            modified datetime default NULL,type VARCHAR(10), PRIMARY KEY (id));";
            dbDelta($create_table);
        }
    }

    function _cs_script()
    {
        $googlefonts = get_option('cs_googlefonts');
        if ($googlefonts != '') {
            wp_register_style('cs-googlefonts', 'http://fonts.googleapis.com/css?family=' . $googlefonts);
            wp_enqueue_style('cs-googlefonts');
        }
        wp_register_style('cs-cloud', plugins_url('library/css/cloudslider.css', dirname(__FILE__)));
        wp_enqueue_style('cs-cloud');
        $footer = get_option('cs_include_script_footer', false) ? true : false;
        if (get_option('cs_cdn_jquery', false)) {
            wp_deregister_script('jquery');
            wp_enqueue_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js', array() , '1.8.3');
        }
        wp_register_script('cs-cloudjs', plugins_url('library/js/cloudslider.jquery.min.js', dirname(__FILE__)) , array('jquery') , CS_PLUGIN_VERSION, $footer);
        if (!$footer && get_option('cs_script_load', true) == false && get_option('cs_include_js_to_body', true) == false) {
            wp_enqueue_script('cs-cloudjs');
            $GLOBALS['library_loaded'] = true;
        }
    }

    function _cs_admin_script() {
    }

    function register_cs_menu_page()
    {
        $capability = get_option('cs_capability', 'manage_options');
        add_menu_page('Cloud Slider', 'Cloud Slider', $capability, 'cloud-slider-list', '_cloud_slider_list', plugins_url('cloudslider/images/icon.png'));
        add_submenu_page('cloud-slider-list', 'Add New', 'Add New', $capability, 'cloud-slider', '_cloud_slider_template');
    }

    function _cs_page_admin_script()
    {
        if (function_exists('wp_enqueue_media')) {
            wp_enqueue_media();
        }
        else {
            wp_enqueue_style('thickbox');
            wp_enqueue_script('media-upload');
            wp_enqueue_script('thickbox');
        }
        wp_register_style('cs-awesome', plugins_url('css/font-awesome/css/font-awesome.min.css', dirname(__FILE__)));
        wp_enqueue_style('cs-awesome');
        wp_register_style('cs-jquery-ui', plugins_url('css/jquery-ui.css', dirname(__FILE__)));
        wp_enqueue_style('cs-jquery-ui');
        wp_register_style('cs-jquery.checkbox', plugins_url('css/jquery.checkbox.css', dirname(__FILE__)));
        wp_enqueue_style('cs-jquery.checkbox');
        $googlefonts = get_option('cs_googlefonts');
        if ($googlefonts != '') {
            wp_register_style('cs-googlefonts', 'http://fonts.googleapis.com/css?family=' . $googlefonts);
            wp_enqueue_style('cs-googlefonts');
        }
        wp_register_style('cs-minicolors', plugins_url('css/jquery.minicolors.css', dirname(__FILE__)));
        wp_enqueue_style('cs-minicolors');
        wp_register_style('cs-style', plugins_url('css/style_admin.css', dirname(__FILE__)));
        wp_enqueue_style('cs-style');
        wp_register_style('cs-cloud-admin', plugins_url('library/css/cloudslider.css', dirname(__FILE__)));
        wp_enqueue_style('cs-cloud-admin');
        wp_register_style('cs-style-codemirror', plugins_url('js/codemirror/codemirror.css', dirname(__FILE__)));
        wp_enqueue_style('cs-style-codemirror');
        wp_register_style('cs-style-codemirror-fold', plugins_url('js/codemirror/foldgutter.css', dirname(__FILE__)));
        wp_enqueue_style('cs-style-codemirror-fold');
        wp_register_script('cs-fix-clone', plugins_url('js/jquery.fix.clone.js', dirname(__FILE__)));
        wp_enqueue_script('cs-fix-clone');
        wp_register_script('cs-checkbox', plugins_url('js/jquery.checkbox.js', dirname(__FILE__)));
        wp_enqueue_script('cs-checkbox');
        wp_register_script('cs-minicolors', plugins_url('js/jquery.minicolors.min.js', dirname(__FILE__)));
        wp_enqueue_script('cs-minicolors');
        wp_register_script('cs-serializejson', plugins_url('js/jquery.serializejson.min.js', dirname(__FILE__)));
        wp_enqueue_script('cs-serializejson');
        wp_register_script('cs-cloudjs', plugins_url('library/js/cloudslider.jquery.min.js', dirname(__FILE__)), array('jquery'));
        wp_enqueue_script('cs-cloudjs');
        wp_register_script('cs-script-codemirror', plugins_url('js/codemirror/codemirror.js', dirname(__FILE__)));
        wp_enqueue_script('cs-script-codemirror');
        wp_register_script('cs-script-codemirror-foldcode', plugins_url('js/codemirror/foldcode.js', dirname(__FILE__)));
        wp_enqueue_script('cs-script-codemirror-foldcode');
        wp_register_script('cs-script-codemirror-gutter', plugins_url('js/codemirror/foldgutter.js', dirname(__FILE__)));
        wp_enqueue_script('cs-script-codemirror-gutter');
        wp_register_script('cs-script-codemirror-bracefold', plugins_url('js/codemirror/brace-fold.js', dirname(__FILE__)));
        wp_enqueue_script('cs-script-codemirror-bracefold');
        wp_register_script('cs-script-codemirror-commentfold', plugins_url('js/codemirror/comment-fold.js', dirname(__FILE__)));
        wp_enqueue_script('cs-script-codemirror-commentfold');
        wp_register_script('cs-script-codemirror-mode', plugins_url('js/codemirror/javascript.js', dirname(__FILE__)));
        wp_enqueue_script('cs-script-codemirror-mode');
        wp_register_script('cs-script-ui', plugins_url('js/jquery-ui.js', dirname(__FILE__)));
        wp_enqueue_script('cs-script-ui');        
        wp_register_script('cs-admin-script', plugins_url('js/jQuery.cloudslider.js', dirname(__FILE__)));
        wp_enqueue_script('cs-admin-script');
    }

    function _cloud_slider_template()
    {
        global $objCloudSlider;
        $objCloudSlider->fnCloudSliderTemplate($_GET);
    }
    function _cs_admin_print_script()
    {        
    ?>
    <script type="text/javascript">var CS_ROOT_URL = '<?php echo CS_ROOT_URL; ?>/';</script>
    <?php
    }
    function get_templates_callback()
    {
        global $objCloudSlider;
        $objCloudSlider->fnGetTemplateCallback($_POST);
        exit;
    }
    function save_slider_callback()
    {
        global $objCloudSlider;
        if (isset($_POST['hdnPreview']) && $_POST['hdnPreview'] == 'preview'){ 
            $objCloudSlider->fnSavePreviewCallback($_POST);
        }else{            
            $objCloudSlider->fnSaveSliderCallback($_POST);
        }
    }
    function preview_slider_callback()
    {
        global $wpdb, $objCloudSlider;
        echo do_shortcode("[cloudslider id='".$_POST["id"]."' type='preview']");
        exit;
    }
    function delete_preview_callback()
    {
        if (isset($_POST['hidden_action']) && $_POST['hidden_action'] == 'delete_preview_file') {
            global $objCloudSlider;
            $objCloudSlider->fnDeletePreviewSlider($_POST);
            exit;
        }
    }
    function _cloud_slider_list()
    {
        global $objCloudSlider;
        $objCloudSlider->fnGetCloudSliderList($_REQUEST);
        if (isset($_GET['cs_action']) && $_GET['cs_action'] === 'upgrade_cs_plugin') {
            updateCloudSlider();
        }
        include_once (CS_DIR . '/include/list.php');

    }
    function updateCloudSlider()
    {
        global $objCloudSlider;
        $objCloudSlider->fnUpdateCloudSlider();
    }
    function cloudslider_callback($atts)
    {
        $optionArray=array();
        $atts = shortcode_atts(array(
        'id' => 0,
        'type' => 'live'
        ) , $atts);
        $slider_id = $atts['id'];
        $output = '';
        $slider='';
        global $wpdb,$objCloudSlider;
        if($atts['type'] == 'preview'){            
            $jsonData=$_POST["allData"];
            $jsonArray = json_decode(stripcslashes($jsonData), true);
            $slider = $jsonArray['slides'];            
        }
        else{
            $tableName = $wpdb->prefix . 'cloudslider';
            $slider = $wpdb->get_row('SELECT * FROM ' . $tableName . ' WHERE id=' . $slider_id, ARRAY_A);
            $slider = base64_decode($slider['data']);
            $slider = unserialize($slider);   
        }

        $slider_layer = $slider['layers'];
        $slider_settings = $slider['settings'];
        $slider_callback = $slider['callbacks'];
        $slider_css= "margin:0 auto;";
        $defaultSkin=$objCloudSlider->arrSkins[$slider_settings['skin']];

        // $slider_css.= $slider_settings['slider-width'] ? "width:" . $slider_settings['slider-width'] . "px;" : 'width:1000px;';
        //  $slider_css.= $slider_settings['slider-height'] ? "height:" . $slider_settings['slider-height'] . "px;" : 'height:500px;';
        // $slider_css.= $slider_settings['container-color'] ? 'background-color:' . $slider_settings['container-color'] . ';' : '';
        // $slider_css.= $slider_settings['container-border'] ? 'padding:' . $slider_settings['container-border'] . ";" : '';
        //$slider_css.= $slider_settings['container-box-shadow'] ? 'box-shadow:' . $slider_settings['container-box-shadow'] . ";" : '';
        // $slider_css.= $slider_settings['container-box-shadow'] ? '-moz-box-shadow:' . $slider_settings['container-box-shadow'] . ";" : '';
        // $slider_css.= $slider_settings['container-box-shadow'] ? '-webkit-box-shadow:' . $slider_settings['container-box-shadow'] . ";" : '';

        if (floatval($slider_settings['slider-width']) > 0 && floatval($slider_settings['slider-width'])!=1000) {                       
            $optionArray['genaral'][]= "\t\t\twidth: " . floatval($slider_settings['slider-width']);
            $slider_css.="width:" . $slider_settings['slider-width'] . "px;";
        }
        else {                        
            $optionArray['genaral'][]= "\t\t\twidth: 1000";
            $slider_css.="width: 1000px;";
        }
        if (floatval($slider_settings['slider-height']) > 0 && floatval($slider_settings['slider-height'])!=500) {                        
            $optionArray['genaral'][]= "\t\t\theight: " . floatval($slider_settings['slider-height']);
            $slider_css.="height:" . $slider_settings['slider-height'] . "px;";
        }
        else {                        
            $optionArray['genaral'][]= "\t\t\theight: 500";
            $slider_css.="height: 500px;";
        }
        if (isset($slider_settings['container-color']) && $slider_settings['container-color']!=''){
            $slider_css.='background-color:' . $slider_settings['container-color'] . ';';           
        }
        if(isset($slider_settings['container-border']) && $slider_settings['container-border']!=''){
            $slider_css.='padding:' . $slider_settings['container-border'] . ";";
        }
        if (isset($slider_settings['container-box-shadow']) && $slider_settings['container-box-shadow'] != '0px 2px 30px 0px #000') {                        
            $slider_css.='box-shadow:' . $slider_settings['container-box-shadow'] . ";";
            $slider_css.='-moz-box-shadow:' . $slider_settings['container-box-shadow'] . ";";
            $slider_css.='-webkit-box-shadow:' . $slider_settings['container-box-shadow'] . ";";
        }
        if (!isset($slider_settings['responsive']) || isset($slider_settings['responsive']) && $slider_settings['responsive'] != 'on') {
            $optionArray['genaral'][]= "\t\t\tresponsive: false";
        }
        if (isset($slider_settings['full-width']) && $slider_settings['full-width'] == 'on') {
            $optionArray['genaral'][]= "\t\t\tfullWidth: true";
        }
        if (isset($slider_settings['full-size']) && $slider_settings['full-size'] == 'on') {
            $optionArray['genaral'][]= "\t\t\tfullSize: true";
        }
        if (!isset($slider_settings['start-slide-show']) || isset($slider_settings['start-slide-show']) &&  $slider_settings['start-slide-show'] != 'on') {                        
            $optionArray['genaral'][]= "\t\t\tautoSlide: false";
        }
        if (isset($slider_settings['auto-slide-carousel']) && $slider_settings['auto-slide-carousel'] !== 'slide' && $slider_settings['auto-slide-carousel']!='') {                        
            $optionArray['genaral'][]= "\t\t\tautoSlideCarousel: '" . $slider_settings['auto-slide-carousel'] . "'";
        }                
        if (!isset($slider_settings['pause-on-hover']) || isset($slider_settings['pause-on-hover']) && $slider_settings['pause-on-hover'] != 'on') {                        
            $optionArray['genaral'][]= "\t\t\tonHoverPause: false";
        }                
        if (isset($slider_settings['start-with-slide']) && intval($slider_settings['start-with-slide']) > 1) {                        
            $optionArray['genaral'][]= "\t\t\tstartSlideNo: " . intval($slider_settings['start-with-slide']);
        }
        if (isset($slider_settings['shuffle-mode']) && $slider_settings['shuffle-mode'] == 'on') {                        
            $optionArray['genaral'][]= "\t\t\tshuffleMode: true";
        }               
        if (isset($slider_settings['proress-bar-pos']) && $slider_settings['proress-bar-pos'] !== $defaultSkin['progressBarPosition'] && $slider_settings['proress-bar-pos']!='') {                        
            $optionArray['genaral'][]= "\t\t\tprogressBarPosition: '" . $slider_settings['proress-bar-pos'] . "'";
        }                
        if (isset($slider_settings['progress-bar-color']) && $slider_settings['progress-bar-color'] != '' && $slider_settings['progress-bar-color']!=$defaultSkin['progressBarColor']) {                        
            $optionArray['genaral'][]= "\t\t\tprogressBarColor: '" . $slider_settings['progress-bar-color'] . "'";
        }
        if (isset($slider_settings['progress-bar-thick']) && $slider_settings['progress-bar-thick'] != '' && trim($slider_settings['progress-bar-thick']).'px'!= $defaultSkin['progressBarThick']) {                        
            $optionArray['genaral'][]= "\t\t\tprogressBarThick: '" . $slider_settings['progress-bar-thick'] . "px'";
        }                
        if (isset($slider_settings['img-loader']) && $slider_settings['img-loader'] != '' && ($slider_settings['img-loader']!=$defaultSkin['imgLoader'] || !$objCloudSlider->fnIsDefaultImage($slider_settings['img-loader']))) {                        
            $optionArray['genaral'][]= "\t\t\timgLoader: '" . $slider_settings['img-loader'] . "'";
        }
        if (!isset($slider_settings['image-lazyload']) || isset($slider_settings['image-lazyload']) && $slider_settings['image-lazyload'] != 'on') {                        
            $optionArray['genaral'][]=  "\t\t\tlazyImageLoad: false";
        }               
        if (!isset($slider_settings['keyboard-navigation']) || isset($slider_settings['keyboard-navigation']) && $slider_settings['keyboard-navigation'] != 'on') {                        
            $optionArray['genaral'][]=  "\t\t\tkeyNavigation: false";
        }                
        if (isset($slider_settings['navigation-type']) && $slider_settings['navigation-type'] != 'bullet' && $slider_settings['navigation-type']!='') {                        
            $optionArray['genaral'][] ="\t\t\tnavType: '" . $slider_settings['navigation-type'] . "'";
        }               
        if (isset($slider_settings['skin']) && $slider_settings['skin'] != '' && $slider_settings['skin'] != 'default') {                        
            $optionArray['genaral'][] = "\t\t\tskin: '" . $slider_settings['skin'] . "'";
        }
        if (isset($slider_settings['arrow-visibility']) && $slider_settings['arrow-visibility'] != 'hover' && $slider_settings['arrow-visibility']!='') {          
            $optionArray['arrow'][]= "\t\t\t\tvisibility: '" . $slider_settings['arrow-visibility'] . "'";                        
        }
        if (isset($slider_settings['arrow-pos']) && $slider_settings['arrow-pos'] != '' && $slider_settings['arrow-pos']!=$defaultSkin['arrow']['positionOffset']){                        
            $optionArray['arrow'][]= "\t\t\t\tpositionOffset: '" . $slider_settings['arrow-pos'] . "'";
        }               
        if (isset($slider_settings['left-arrow-img']) && $slider_settings['left-arrow-img'] != '' && ($slider_settings['left-arrow-img']!=$defaultSkin['arrow']['imgPrev'] || !$objCloudSlider->fnIsDefaultImage($slider_settings['left-arrow-img']))) {                        
            $optionArray['arrow'][]= "\t\t\t\timgPrev: '" . $slider_settings['left-arrow-img'] . "'";
        }
        if (isset($slider_settings['right-arrow-img']) && $slider_settings['right-arrow-img'] != '' && ($slider_settings['right-arrow-img']!=$defaultSkin['arrow']['imgNext'] || !$objCloudSlider->fnIsDefaultImage($slider_settings['right-arrow-img']))) {                        
            $optionArray['arrow'][]= "\t\t\t\timgNext: '" . $slider_settings['right-arrow-img'] . "'";
        }
        if (isset($slider_settings['left-hover-arrow-img']) && $slider_settings['left-hover-arrow-img'] != '' && ($slider_settings['left-hover-arrow-img']!=$defaultSkin['arrow']['imgPrevActivated'] || !$objCloudSlider->fnIsDefaultImage($slider_settings['left-hover-arrow-img']))) {                    
            $optionArray['arrow'][]= "\t\t\t\timgPrevActivated: '" . $slider_settings['left-hover-arrow-img'] . "'";
        }
        if (isset($slider_settings['right-hover-arrow-img']) && $slider_settings['right-hover-arrow-img'] != '' && ($slider_settings['right-hover-arrow-img']!=$defaultSkin['arrow']['imgNextActivated'] || !$objCloudSlider->fnIsDefaultImage($slider_settings['right-hover-arrow-img']))) {
            $optionArray['arrow'][]= "\t\t\t\timgNextActivated: '" . $slider_settings['right-hover-arrow-img'] . "'";
        }
        if (isset($slider_settings['arrow-responsive-level']) && floatval($slider_settings['arrow-responsive-level']) > 0 && floatval($slider_settings['arrow-responsive-level'])!=$defaultSkin['arrow']['responsiveLevel']) {
            $optionArray['arrow'][]= "\t\t\t\tresponsiveLevel: " . floatval($slider_settings['arrow-responsive-level']);
        }                    

        if (isset($slider_settings['navigation-type']) && $slider_settings['navigation-type'] == "bullet") {
            if (isset($slider_settings['']) && $slider_settings['bullet-visibility']!='' && $slider_settings['bullet-visibility'] != 'show') {
                $optionArray['bullet'][]= "\t\t\t\tvisibility: 'hover'";
            }                        
            if (isset($slider_settings['bullet-pos']) && $slider_settings['bullet-pos'] !== '' && $slider_settings['bullet-pos'] !== $defaultSkin['bullet']['position']) {
                $optionArray['bullet'][]= "\t\t\t\tposition: '" . $slider_settings['bullet-pos'] . "'";
            }
            if (isset($slider_settings['horizontal-offset']) && floatval($slider_settings['horizontal-offset']) != $defaultSkin['bullet']['horizontalOffset']) {
                $optionArray['bullet'][]= "\t\t\t\thorizontalOffset: " . floatval($slider_settings['horizontal-offset']);
            }
            if (isset($slider_settings['vertical-offset']) && floatval($slider_settings['vertical-offset']) != 0 && floatval($slider_settings['vertical-offset']) != $defaultSkin['bullet']['verticalOffset']) {
                $optionArray['bullet'][]= "\t\t\t\tverticalOffset: " . floatval($slider_settings['vertical-offset']);
            }
            if (isset($slider_settings['bullet-opacity']) && floatval($slider_settings['bullet-opacity']) < 1 && floatval($slider_settings['bullet-opacity']) >0 && floatval($slider_settings['bullet-opacity']) != $defaultSkin['bullet']['itemOpacity']) {
                $optionArray['bullet'][]= "\t\t\t\titemOpacity: " . floatval($slider_settings['bullet-opacity']);
            }
            if (isset($slider_settings['active-bullet-opacity']) && floatval($slider_settings['active-bullet-opacity']) < 1 && floatval($slider_settings['active-bullet-opacity']) >0 && floatval($slider_settings['active-bullet-opacity']) != $defaultSkin['bullet']['activatedOpacity']) {                
                $optionArray['bullet'][]="\t\t\t\tactivatedOpacity: " . floatval($slider_settings['active-bullet-opacity']);
            }
            if (isset($slider_settings['bullet-img']) && $slider_settings['bullet-img'] != '' && ($slider_settings['bullet-img']!=$defaultSkin['bullet']['imgItem'] || !$objCloudSlider->fnIsDefaultImage($slider_settings['bullet-img']))) {
                $optionArray['bullet'][]= "\t\t\t\timgItem: '" . $slider_settings['bullet-img'] . "'";
            }
            if (isset($slider_settings['active-bullet-img']) && $slider_settings['active-bullet-img'] != '' && ($slider_settings['active-bullet-img']!=$defaultSkin['bullet']['imgItemActivated'] || !$objCloudSlider->fnIsDefaultImage($slider_settings['active-bullet-img']))) {                      
                $optionArray['bullet'][]= "\t\t\t\timgItemActivated: '" . $slider_settings['active-bullet-img'] . "'";
            }
            if (isset($slider_settings['bullet-left-container-img']) && $slider_settings['bullet-left-container-img'] != '' && ($slider_settings['bullet-left-container-img']!=$defaultSkin['bullet']['imgContainerLeft'] || !$objCloudSlider->fnIsDefaultImage($slider_settings['bullet-left-container-img']))) {
                $optionArray['bullet'][]= "\t\t\t\timgContainerLeft: '" . $slider_settings['bullet-left-container-img'] . "'";
            }
            if (isset($slider_settings['bullet-right-container-img']) && $slider_settings['bullet-right-container-img'] != ''  && ($slider_settings['bullet-right-container-img']!=$defaultSkin['bullet']['imgContainerRight'] || !$objCloudSlider->fnIsDefaultImage($slider_settings['bullet-right-container-img']))) {
                $optionArray['bullet'][]= "\t\t\t\timgContainerRight: '" . $slider_settings['bullet-right-container-img'] . "'";
            }
            if (isset($slider_settings['bullet-margin']) && $slider_settings['bullet-margin'] != '' && $slider_settings['bullet-margin'] != $defaultSkin['bullet']['itemMargin']) {
                $optionArray['bullet'][]= "\t\t\t\titemMargin: '" . $slider_settings['bullet-margin'] . "'";
            }
            if (isset($slider_settings['bullet-responsive-level']) && floatval($slider_settings['bullet-responsive-level']) > 0 && floatval($slider_settings['bullet-responsive-level'])!=$defaultSkin['bullet']['responsiveLevel']) {                         
                $optionArray['bullet'][]= "\t\t\t\tresponsiveLevel: " . floatval($slider_settings['bullet-responsive-level']);
            }                        
        }

        else if (isset($slider_settings['navigation-type']) && $slider_settings['navigation-type'] == "thumb") {
                $thumbString='';                           
                if (isset($slider_settings['thumb-visibility']) && $slider_settings['thumb-visibility'] !='' && $slider_settings['thumb-visibility'] == 'show' ) {    
                    $optionArray['thumb'][]= "\t\t\t\tvisibility: 'show'";
                }
                if (isset($slider_settings['thumb-position-offset']) && $slider_settings['thumb-position-offset'] != '' && $slider_settings['thumb-position-offset']!=$defaultSkin['thumb']['positionOffset']) {
                $optionArray['thumb'][]= "\t\t\t\tpositionOffset: '" . $slider_settings['thumb-position-offset'] . "'";
            }
            if (isset($slider_settings['thumb-container-width']) && $slider_settings['thumb-container-width'] != '' && $slider_settings['thumb-container-width']!='auto') {
                $optionArray['thumb'][]= "\t\t\t\tcontainerWidth: '" . $slider_settings['thumb-container-width'] . "'";
            }
            if (isset($slider_settings['thumb-container-padding']) && $slider_settings['thumb-container-padding'] != '' && $slider_settings['thumb-container-padding']!=$defaultSkin['thumb']['containerPadding']) {                           
                $optionArray['thumb'][]= "\t\t\t\tcontainerPadding: '" . $slider_settings['thumb-container-padding'] . "'";
            }
            if (isset($slider_settings['thumb-opacity']) && floatval($slider_settings['thumb-opacity']) <= 1 && floatval($slider_settings['thumb-opacity']) >= 0 && floatval($slider_settings['thumb-opacity']) != $defaultSkin['thumb']['itemOpacity']) {
                $optionArray['thumb'][]="\t\t\t\titemOpacity: " . floatval($slider_settings['thumb-opacity']) . "";
            }
            if (isset($slider_settings['active-thumb-opacity']) && floatval($slider_settings['active-thumb-opacity']) <= 1 && floatval($slider_settings['active-thumb-opacity']) >= 0 && floatval($slider_settings['active-thumb-opacity'])!=$defaultSkin['thumb']['activatedOpacity']) {
                $optionArray['thumb'][]="\t\t\t\tactivatedOpacity: " . floatval($slider_settings['active-thumb-opacity']);
            }                
            if (isset($slider_settings['no-thumb-img']) && $slider_settings['no-thumb-img'] != '' && ($slider_settings['no-thumb-img']!=$defaultSkin['thumb']['imgNoThumb'] || !$objCloudSlider->fnIsDefaultImage($slider_settings['no-thumb-img']))) {
                $optionArray['thumb'][]= "\t\t\t\timgNoThumb: '" . $slider_settings['no-thumb-img'] . "'";
            }
            if (isset($slider_settings['thumb-width']) && floatval($slider_settings['thumb-width']) > 0 && floatval($slider_settings['thumb-height']) > 0) {
                $optionArray['thumb'][]= "\t\t\t\titemSize: {width: " . $slider_settings['thumb-width'] . ", height: " . $slider_settings['thumb-height'] . "}";
            }
            else if (isset($slider_settings['thumb-width']) && floatval($slider_settings['thumb-width']) > 0) {
                    $optionArray['thumb'][]= "\t\t\t\titemSize: {width: " . $slider_settings['thumb-width'] . "}";
                }
                else if (isset($slider_settings['thumb-height']) && floatval($slider_settings['thumb-height']) > 0) {
                        $optionArray['thumb'][]= "\t\t\t\titemSize: {height: " . $slider_settings['thumb-height'] . "}";
                    }
                    if (isset($slider_settings['thumb-margin']) && $slider_settings['thumb-margin'] != '' && $slider_settings['thumb-margin']!=$defaultSkin['thumb']['itemMargin']) {
                $optionArray['thumb'][]= "\t\t\t\titemMargin: '" . $slider_settings['thumb-margin'] . "'";
            }
            if (isset($slider_settings['thumb-bg-color']) && $slider_settings['thumb-bg-color'] != '' && $slider_settings['thumb-bg-color'] != $defaultSkin['thumb']['containerBgColor']) {
                $optionArray['thumb'][]= "\t\t\t\tcontainerBgColor: '" . $slider_settings['thumb-bg-color'] . "'";
            }                        
            if (isset($slider_settings['thumb-border-width']) && floatval($slider_settings['thumb-border-width']) >= 0 && floatval($slider_settings['thumb-border-width'])!=$defaultSkin['thumb']['itemBorderWidth']) {
                $optionArray['thumb'][]= "\t\t\t\titemBorderWidth: '" . floatval($slider_settings['thumb-border-width']) . "px'";
            }
            if (isset($slider_settings['thumb-border-color']) && $slider_settings['thumb-border-color'] != '' && $slider_settings['thumb-border-color'] != $defaultSkin['thumb']['itemBorderColor']) {
                $optionArray['thumb'][]= "\t\t\t\titemBorderColor: '" . $slider_settings['thumb-border-color'] . "'";
            }
            if (isset($slider_settings['active-thumb-border-color']) && $slider_settings['active-thumb-border-color'] != '' && $slider_settings['active-thumb-border-color'] !=  $defaultSkin['thumb']['activatedBorderColor']) {
                $optionArray['thumb'][]= "\t\t\t\tactivatedBorderColor: '" . $slider_settings['active-thumb-border-color'] . "'";
            }                        
            if (isset($slider_settings['thumb-responsive-level']) && floatval($slider_settings['thumb-responsive-level']) > 0 && floatval($slider_settings['thumb-responsive-level'])!=$defaultSkin['thumb']['responsiveLevel']) {                         
                $optionArray['thumb'][]= "\t\t\t\tresponsiveLevel: " . floatval($slider_settings['thumb-responsive-level']);
            }   
        }                    
        if (isset($slider_callback['callback-onInit']) && trim($slider_callback['callback-onInit']) != '') {                        
            $optionArray['callback'][]="\t\t\tonInit: function() {\n\t\t\t".stripcslashes($slider_callback['callback-onInit']) . "\n\t\t\t}";
        }
        if (isset($slider_callback['callback-onResume']) && trim($slider_callback['callback-onResume']) != '') {
            $optionArray['callback'][]="\t\t\tonResume: function() {\n\t\t\t".stripcslashes($slider_callback['callback-onResume']) . "\n\t\t\t}";
        }
        if (isset($slider_callback['callback-onPause']) && trim($slider_callback['callback-onPause']) != '') {
            $optionArray['callback'][]="\t\t\tonPause: function() {\n\t\t\t".stripcslashes($slider_callback['callback-onPause']) . "\n\t\t\t}";
        }
        if (isset($slider_callback['callback-onPrev']) && trim($slider_callback['callback-onPrev']) != '') {
            $optionArray['callback'][]="\t\t\tonPrev: function() {\n\t\t\t".stripcslashes($slider_callback['callback-onPrev']) . "\n\t\t\t}";
        }
        if (isset($slider_callback['callback-onNext']) && trim($slider_callback['callback-onNext']) != '') {
            $optionArray['callback'][]="\t\t\tonNext: function() {\n\t\t\t".stripcslashes($slider_callback['callback-onNext']) . "\n\t\t\t}";
        }
        if (isset($slider_callback['callback-onSlideTo']) && trim($slider_callback['callback-onSlideTo']) != '') {
            $optionArray['callback'][]="\t\t\tonSlideTo: function() {\n\t\t\t".stripcslashes($slider_callback['callback-onSlideTo']) . "\n\t\t\t}";
        }
        if (isset($slider_callback['callback-onSlidingStart']) && trim($slider_callback['callback-onSlidingStart']) != '') {
            $optionArray['callback'][]="\t\t\tonSlidingStart: function() {\n\t\t\t".stripcslashes($slider_callback['callback-onSlidingStart']) . "\n\t\t\t}";
        }
        if (isset($slider_callback['callback-onSlidingComplete']) && trim($slider_callback['callback-onSlidingComplete']) != '') {
            $optionArray['callback'][]="\t\t\tonSlidingComplete: function() {\n\t\t\t".stripcslashes($slider_callback['callback-onSlidingComplete']) . "\n\t\t\t}";
        }
        if (isset($slider_callback['callback-onCarouselTo']) && trim($slider_callback['callback-onCarouselTo']) != '') {
            $optionArray['callback'][]="\t\t\tonCarouselTo: function() {\n\t\t\t".stripcslashes($slider_callback['callback-onCarouselTo']) . "\n\t\t\t}";
        }
        if (isset($slider_callback['callback-onCloudClick']) && trim($slider_callback['callback-onCloudClick']) != '') {                        
            $optionArray['callback'][]="\t\t\tonCloudClick: function(target) {\n\t\t\t".stripcslashes($slider_callback['callback-onCloudClick']) . "\n\t\t\t}";
        }
        if (isset($slider_callback['callback-onCloudHover']) && trim($slider_callback['callback-onCloudHover']) != '') {                        
            $optionArray['callback'][]="\t\t\tonCloudHover: function(target, isOver) {\n\t\t\t".stripcslashes($slider_callback['callback-onCloudHover']) . "\n\t\t\t}";
        }
        if (isset($slider_settings['auto-play']) && $slider_settings['auto-play'] == 'on') {                        
            $optionArray['video'][]= "\t\t\t\tautoPlay: true";
        }
        if (!isset($slider_settings['pause-when-playing']) || isset($slider_settings['pause-when-playing']) && $slider_settings['pause-when-playing'] != 'on') {                        
            $optionArray['video'][]= "\t\t\t\tpauseWhilePlaying: false";
        } 

        ob_start();
    ?>
    <?php 
        if (isset($slider_settings['custom-styles']) && $slider_settings['custom-styles'] != '') {
            echo '<style type="text/css">';
            echo $slider_settings['custom-styles'];
            echo '</style>';
        }

        if ((get_option('cs_script_load', true) == true || get_option('cs_include_js_to_body', true) == true) && !isset($GLOBALS['library_loaded'])) { ?>

            <script type="text/javascript" src="<?php echo plugins_url('library/js/cloudslider.jquery.min.js', dirname(__FILE__)); ?>"></script>
            <?php
            $GLOBALS['library_loaded'] = true;
        }
    ?>
    <div id="cloudslider<?php echo $slider_id;?>" class="cloud-container" style="<?php echo $slider_css; ?>">
        <?php
            $carousel_jq = "";

            for ($i = 0; $i < count($slider_layer); $i++) {
                $data_dur = "";
                $data_transition = "";
                $data_ken = "";
                $slide = $slider_layer[$i];
                $twoD='';
                $threeD='';
                if (isset($slide['properties']['2d_transitions_id']) && ($slide['properties']['2d_transitions_id'] != "" && $slide['properties']['2d_transitions_id'] != "1,2")) {
                    $toDArray=explode(',',$slide['properties']['2d_transitions_id']);

                    if(count($toDArray)==32) {
                        $twoD = '2d';
                    } else {
                        $twoD = $slide['properties']['2d_transitions_id'];
                    }
                }
                if (isset($slide['properties']['3d_transitions_id']) && $slide['properties']['3d_transitions_id'] != "") {
                    $threeDArray=explode(',',$slide['properties']['3d_transitions_id']);

                    if(count($threeDArray)==18){
                        $threeD = '3d';
                    }else{
                        $threeD = $slide['properties']['3d_transitions_id'];
                    }                   
                }
                if($twoD=='2d' && $threeD=='3d'){
                    $data_transition='data-transition="all"';
                }else if($twoD!='' && $threeD!=''){
                        $data_transition='data-transition="'.$twoD.','.$threeD.'"';
                    }else if($twoD==''  && $threeD!=''){
                            $data_transition='data-transition="'.$threeD.'"';
                        }else if($threeD=='' && $twoD!=''){
                                $data_transition='data-transition="'.$twoD.'"';
                            }


                            if (isset($slide['properties']['slidedelay']) && ($slide['properties']['slidedelay'] != "" && $slide['properties']['slidedelay'] != "6000")) {
                    $data_dur = "data-duration='" . $slide['properties']['slidedelay'] . "' ";
                }
                if (isset($slide['properties']['kenburn']) && $slide['properties']['kenburn'] != "") {
                    $kendata = "";
                    $kendata = "scalefrom:" . $slide['properties']['scale-from'] . ";";
                    if (isset($slide['properties']['position-from']) && $slide['properties']['position-from'] == "top_left_per") {
                        $top = $slide['properties']['position-from-top'];
                        $left = $slide['properties']['position-from-left'];
                        $posfrm = $top . "," . $left;
                    }
                    else {
                        $posfrm = $slide['properties']['position-from'];
                    }

                    $kendata.= " positionfrom:" . $posfrm . ";";
                    $kendata.= " scaleto:" . $slide['properties']['scale-to'] . ";";
                    if (isset($slide['properties']['position-to']) && $slide['properties']['position-to'] == "top_left_per") {
                        $top_to = $slide['properties']['position-to-top'];
                        $left_to = $slide['properties']['position-to-left'];
                        $posto = $top_to . "," . $left_to;
                    }
                    else {
                        $posto = $slide['properties']['position-to'];
                    }

                    $kendata.= " positionto:" . $posto . ";";
                    $kendata.= " easing:" . $slide['properties']['kenburn-easing'] . ";";
                    $kendata.= " duration:" . $slide['properties']['kenburn-duration'] . ";";

                    if($kendata!=''){
                        $data_ken = "data-ken='" . $kendata . "' ";
                    }
                }
                $data_thumb = "";
                if (isset($slide['properties']['thumbnail']) && $slide['properties']['thumbnail'] != "") {
                    $data_thumb = " data-thumb='" . $slide['properties']['thumbnail'] . "'";
                }
                $data_carousel = "";
                $optionArray['carousel']['carousel_'.$i]['available']=0;
                if (isset($slide['properties']['carousel']) && $slide['properties']['carousel'] != "") {
                    $data_carousel = " data-carousel='carousel_" . $i . "'";                    
                    if (isset($slide['properties']['carousel-pos']) && $slide['properties']['carousel-pos']!='center') {
                        if (isset($slide['properties']['carousel-pos']) && $slide['properties']['carousel-pos'] == "px_or_per") {
                            if (isset($slide['properties']['carousel-pos-px-per'])) {    
                                $optionArray['carousel']['carousel_'.$i]['genaral'][]= "\t\t\t\tposition : '" . $slide['properties']['carousel-pos-px-per'] . "'";
                            }
                        }
                        else {
                            $optionArray['carousel']['carousel_'.$i]['genaral'][]= "\t\t\t\tposition : '" . $slide['properties']['carousel-pos'] . "'";
                        }
                    }
                    $c_size = "";
                    if ((isset($slide['properties']['carousel-width']) && floatval($slide['properties']['carousel-width']) > 0) && (isset($slide['properties']['carousel-height']) && floatval($slide['properties']['carousel-height']) > 0)) {
                        $optionArray['carousel']['carousel_'.$i]['genaral'][]= "\t\t\t\titemSize : {width: " . floatval($slide['properties']['carousel-width']) . ", height: " . floatval($slide['properties']['carousel-height']) . "}";
                    }
                    else if (isset($slide['properties']['carousel-width']) && floatval($slide['properties']['carousel-width']) > 0) {
                            $optionArray['carousel']['carousel_'.$i]['genaral'][]= "\t\t\t\titemSize : {width: " . floatval($slide['properties']['carousel-width']) . "}";
                        }
                        else if (isset($slide['properties']['carousel-height']) && floatval($slide['properties']['carousel-height']) > 0) {    
                                $optionArray['carousel']['carousel_'.$i]['genaral'][]= "\t\t\t\titemSize : {height: " . floatval($slide['properties']['carousel-height']) . "}";
                            }

                            if (isset($slide['properties']['carousel-fisrt-show']) && ($slide['properties']['carousel-fisrt-show']!='' && $slide['properties']['carousel-fisrt-show']!='1')) {                        
                        $optionArray['carousel']['carousel_'.$i]['genaral'][]= "\t\t\t\tfirstShow : '" . $slide['properties']['carousel-fisrt-show'] . "'";
                    }

                    if (isset($slide['properties']['carousel-overlay']) && ($slide['properties']['carousel-overlay']!='' && $slide['properties']['carousel-overlay']!='20%')) {                        
                        $optionArray['carousel']['carousel_'.$i]['genaral'][]= "\t\t\t\toverlay : '" . $slide['properties']['carousel-overlay'] . "'";
                    }
                    if (isset($slide['properties']['carousel-easing']) && ($slide['properties']['carousel-easing']!='' && $slide['properties']['carousel-easing']!='easeOutSine')) {                        
                        $optionArray['carousel']['carousel_'.$i]['genaral'][]= "\t\t\t\teasing : '" . $slide['properties']['carousel-easing'] . "'";
                    }

                    if (isset($slide['properties']['carousel-perspective']) && ($slide['properties']['carousel-perspective']!='' && $slide['properties']['carousel-perspective']!='1000')) {

                        $optionArray['carousel']['carousel_'.$i]['genaral'][]= "\t\t\t\tperspective : '" . $slide['properties']['carousel-perspective'] . "'";
                    }

                    if (isset($slide['properties']['carousel-duration']) && ($slide['properties']['carousel-duration']!='' && $slide['properties']['carousel-duration']!='700')) {                        
                        $optionArray['carousel']['carousel_'.$i]['genaral'][]= "\t\t\t\tduration : '" . $slide['properties']['carousel-duration'] . "'";
                    }
                    if (isset($slide['properties']['carousel-delay']) && ($slide['properties']['carousel-delay']!='' && $slide['properties']['carousel-delay']!='6000')) {                        
                        $optionArray['carousel']['carousel_'.$i]['genaral'][]= "\t\t\t\tdelay : '" . $slide['properties']['carousel-delay'] . "'";
                    }
                    if (isset($slide['properties']['carousel-direction']) && ($slide['properties']['carousel-direction']!='' && $slide['properties']['carousel-direction']!='right')) {                        
                        $optionArray['carousel']['carousel_'.$i]['genaral'][]= "\t\t\t\tdirection : '" . $slide['properties']['carousel-direction'] . "'";
                    }    
                    if (isset($slide['properties']['carousel-arrow-visibility']) && ($slide['properties']['carousel-arrow-visibility']!='' && $slide['properties']['carousel-arrow-visibility']!='hover')) {                        
                        $optionArray['carousel']['carousel_'.$i]['arrow'][]= "\t\t\t\t\tvisibility : '" . $slide['properties']['carousel-arrow-visibility'] . "'";
                    }                    
                    if (isset($slide['properties']['carousel-arrow-pos']) && ($slide['properties']['carousel-arrow-pos']!='' && $slide['properties']['carousel-arrow-pos']!='auto')) {                        
                        $optionArray['carousel']['carousel_'.$i]['arrow'][]=  "\t\t\t\t\tposition : '" . $slide['properties']['carousel-arrow-pos'] . "'";
                    }                    
                    if (isset($slide['properties']['carousel-left-arrow-img']) && ($slide['properties']['carousel-left-arrow-img']!='' && !$objCloudSlider->fnIsDefaultImage($slide['properties']['carousel-left-arrow-img']))) {
                        $optionArray['carousel']['carousel_'.$i]['arrow'][]=  "\t\t\t\t\timgPrev : '" . $slide['properties']['carousel-left-arrow-img'] . "'";
                    }
                    if (isset($slide['properties']['carousel-right-arrow-img']) && ($slide['properties']['carousel-right-arrow-img']!='' && !$objCloudSlider->fnIsDefaultImage($slide['properties']['carousel-right-arrow-img']))) {     
                        $optionArray['carousel']['carousel_'.$i]['arrow'][]=  "\t\t\t\t\timgNext : '" . $slide['properties']['carousel-right-arrow-img'] . "'";
                    }
                    if (isset($slide['properties']['carousel-responsive-level']) && ($slide['properties']['carousel-responsive-level']!='' && $slide['properties']['carousel-responsive-level']!='2')) {                        
                        $optionArray['carousel']['carousel_'.$i]['arrow'][]= "\t\t\t\t\tresponsiveLevel : '" . $slide['properties']['carousel-responsive-level'] . "'";
                    }


                    if (isset($slide['properties']['carousel-level'])) {                    
                        $carousel_layer = $slide['properties']['carousel-level'];
                        for ($c = 1; $c <= sizeof($slide['properties']['carousel-level']); $c++) {
                            $carouselSubLayer='';
                            if (isset($carousel_layer[$c]['carousel-opacity']) && $carousel_layer[$c]['carousel-opacity'] !=''  ) {    
                                $optionArray['carousel']['carousel_'.$i]['level'][$c-1][]= "\t\t\t\t\t\topacity : " . $carousel_layer[$c]['carousel-opacity'];
                            }
                            if (isset($carousel_layer[$c]['carousel-scale']) && $carousel_layer[$c]['carousel-scale']!='' ) {    
                                $optionArray['carousel']['carousel_'.$i]['level'][$c-1][]="\t\t\t\t\t\tscale : " . $carousel_layer[$c]['carousel-scale'];
                            }
                            if (isset($carousel_layer[$c]['carousel-rotation-x']) && $carousel_layer[$c]['carousel-rotation-x']!='' ) {    
                                $optionArray['carousel']['carousel_'.$i]['level'][$c-1][]= "\t\t\t\t\t\trotationX : " . $carousel_layer[$c]['carousel-rotation-x'] ;
                            }
                            if (isset($carousel_layer[$c]['carousel-rotation-y']) && $carousel_layer[$c]['carousel-rotation-y']!='' ) {    
                                $optionArray['carousel']['carousel_'.$i]['level'][$c-1][]= "\t\t\t\t\t\trotationY : " . $carousel_layer[$c]['carousel-rotation-y'];
                            }
                            if (isset($carousel_layer[$c]['carousel-rotation-z']) && $carousel_layer[$c]['carousel-rotation-z']!='' ) {    
                                $optionArray['carousel']['carousel_'.$i]['level'][$c-1][]= "\t\t\t\t\t\trotationZ : " . $carousel_layer[$c]['carousel-rotation-z'];
                            }
                        }
                    }
                    else {                        
                        $optionArray['carousel']['carousel_'.$i]['level'][0][]= array("\t\t\t\t\t\topacity : 1","\t\t\t\t\t\tscale : 0.8","\t\t\t\t\t\trotationX : 1","\t\t\t\t\t\trotationY : 1","\t\t\t\t\t\trotationZ : 1");
                        $optionArray['carousel']['carousel_'.$i]['level'][1][]= array("\t\t\t\t\t\topacity : 1","\t\t\t\t\t\tscale : 0.6","\t\t\t\t\t\trotationX : 0","\t\t\t\t\t\trotationY : 0","\t\t\t\t\t\trotationZ : 0");
                        $optionArray['carousel']['carousel_'.$i]['level'][2][]= array("\t\t\t\t\t\topacity : 1","\t\t\t\t\t\tscale : 0.4","\t\t\t\t\t\trotationX : 1","\t\t\t\t\t\trotationY : 1","\t\t\t\t\t\trotationZ : 1");
                    }                   
                }                
                $all_carousel_layer = array();
                if (isset($slide['properties']['carousel_layer_ids']) && $slide['properties']['carousel_layer_ids'] != "") {
                    $all_carousel_layer = explode(",", $slide['properties']['carousel_layer_ids']);
                }

                if (!isset($slide['properties']["hidden"]) || (isset($slide['properties']["hidden"]) && $slide['properties']["hidden"]!=1)) {
                    $attr_div = "";
                    $common_arr = array();
                    $layer = array();
                    $layerHTML='';
                    for ($j = 0; $j < count($slide['sub_layer']); $j++) {
                        $tran_in = "";
                        $tran_out = "";
                        $style_elements = "";
                        $attr_elements = "";
                        $layer = $slide['sub_layer'][$j]['properties'];
                        $layer_data = "";
                        $style_elements = 'z-index:' . ($j + 2) . ';';
                        if (isset($layer['pos_width'])){
                            if($layer['pos_width'] !== "" && $layer['pos_width'] != "auto") {
                                if(strpos($layer['pos_width'],"%")!==false || strpos($layer['pos_width'],"px")!==false){
                                    $style_elements.= 'width:' . $layer['pos_width'] . ';';
                                }
                                else {
                                    $style_elements.= 'width:' . $layer['pos_width'] . 'px;';
                                }    
                            }
                        }
                        /*else
                        $style_elements .= 'width:auto;';*/
                        if (isset($layer['pos_height'])){
                            if($layer['pos_height'] != "" && $layer['pos_height'] != "auto") {
                                if(strpos($layer['pos_height'],"%")!==false  || strpos($layer['pos_height'],"px")!==false){
                                    $style_elements.= 'height:' . $layer['pos_height'] . ';';
                                }
                                else
                                {
                                    $style_elements.= 'height:' . $layer['pos_height'] . 'px;';
                                }        
                            }
                        }
                        /*else
                        $style_elements .= 'height:auto';*/
                        if (isset($layer['pos_top']) && $layer['pos_top'] != "" && $layer['pos_top'] != 0) $style_elements.= 'top:' . $layer['pos_top'] . $layer['pos_top_type'] . ';';
                        if (isset($layer['pos_left']) && $layer['pos_left'] != "" && $layer['pos_left'] != 0) $style_elements.= 'left:' . $layer['pos_left'] . $layer['pos_left_type'] . ';';
                        if (isset($layer['padding_top']) && $layer['padding_top'] != "" && $layer['padding_top'] != "0") $style_elements.= 'padding-top:' . $layer['padding_top'] . 'px;';
                        if (isset($layer['padding_right']) && $layer['padding_right'] != "" && $layer['padding_right'] != "0") $style_elements.= 'padding-right:' . $layer['padding_right'] . 'px;';
                        if (isset($layer['padding_bottom']) && $layer['padding_bottom'] != "" && $layer['padding_bottom'] != "0") $style_elements.= 'padding-bottom:' . $layer['padding_bottom'] . 'px;';
                        if (isset($layer['padding_left']) && $layer['padding_left'] != "" && $layer['padding_left'] != "0") $style_elements.= 'padding-left:' . $layer['padding_left'] . 'px;';
                        if (isset($layer['font_family']) && $layer['font_family'] != "" && $layer['font_family'] != "Arial, Helvetica, sans-serif") $style_elements.= 'font-family:' . str_replace('"',"'",stripslashes($layer['font_family'])) . ';';
                        if (isset($layer['font_size']) && $layer['font_size'] != "" && $layer['font_size'] != "15") $style_elements.= 'font-size:' . $layer['font_size'] . 'px;';
                        if (isset($layer['line_height']) && $layer['line_height'] != "" && $layer['line_height'] != "Normal") $style_elements.= 'line-height:' . $layer['line_height'] . 'px;';
                        $link_style = "";
                        if (isset($layer['font_color']) && $layer['font_color'] != "" && $layer['font_color'] != "#000000") {
                            $style_elements.= 'color:' . $layer['font_color'] . ';';
                            $link_style = ' style="color:' . $layer['font_color'] . ';"';
                        }
                        if (isset($layer['radius']) && $layer['radius'] != "" && $layer['radius'] != "0") $style_elements.= 'border-radius:' . $layer['radius'] . 'px;';
                        if (isset($layer['font_background']) && $layer['font_background'] != "") $style_elements.= 'background-color:' . $layer['font_background'] . ';';
                        // $style_elements .= $layer['wordwrap'] ? 'white-space:normal':'white-space:nowrap'.';';
                        if (isset($layer['custom_style']) && $layer['custom_style']!='') $style_elements.= $layer['custom_style'];
                        if ((isset($layer['hide']) && $layer['hide'] == 1) || (isset($layer['hidden']) && $layer['hidden'])) $style_elements.= "display:none !important;";
                        $attr_elements = $layer['id'] ? ' id="' . $layer['id'] . '" ' : '';
                        $attr_elements.= $layer['title'] ? ' title="' . $layer['title'] . '" ' : '';
                        $attr_elements.= $layer['alt'] ? ' alt="' . $layer['alt'] . '" ' : '';
                        $attr_elements.= $layer['rel'] ? ' rel="' . $layer['rel'] . '" ' : '';

                        if (isset($layer['ti-offsetx']) && $layer['ti-offsetx'] != "" &&  $layer['ti-offsetx'] != "0") $tran_in.= "offsetx:" . $layer['ti-offsetx'] . ";";
                        if (isset($layer['ti-offsety']) && $layer['ti-offsety'] != "" && $layer['ti-offsety'] != "0") $tran_in.= "offsety:" . $layer['ti-offsety'] . ";";
                        if (isset($layer['ti-rotate']) && $layer['ti-rotate'] != "" && $layer['ti-rotate'] != "0") $tran_in.= "rotate:" . $layer['ti-rotate'] . ";";
                        if (isset($layer['ti-rotatex']) && $layer['ti-rotatex'] != "" && $layer['ti-rotatex'] != "0") $tran_in.= "rotatex:" . $layer['ti-rotatex'] . ";";
                        if (isset($layer['ti-rotatey']) && $layer['ti-rotatey'] != "" && $layer['ti-rotatey'] != "0") $tran_in.= "rotatey:" . $layer['ti-rotatey'] . ";";
                        if (isset($layer['ti-scalex']) && $layer['ti-scalex'] != "" && $layer['ti-scalex'] != "1") $tran_in.= "scalex:" . $layer['ti-scalex'] . ";";
                        if (isset($layer['ti-scaley']) && $layer['ti-scaley'] != "" && $layer['ti-scaley'] != "1") $tran_in.= "scaley:" . $layer['ti-scaley'] . ";";
                        if (isset($layer['ti-skewx']) && $layer['ti-skewx'] != "" && $layer['ti-skewx'] != "0") $tran_in.= "skewx:" . $layer['ti-skewx'] . ";";
                        if (isset($layer['ti-skewy']) && $layer['ti-skewy'] != "" && $layer['ti-skewy'] != "0") $tran_in.= "skewy:" . $layer['ti-skewy'] . "; ";
                        if (isset($layer['ti-delay']) && $layer['ti-delay'] != "" && $layer['ti-delay'] != "0") $tran_in.= "delay:" . $layer['ti-delay'] . ";";
                        if (isset($layer['ti-duration']) && $layer['ti-duration'] != "" && $layer['ti-duration'] != "800") {$tran_in.= "duration:" . $layer['ti-duration'] . ";";}
                        if (isset($layer['ti-easing']) && $layer['ti-easing'] != ""  && $layer['ti-easing'] != "easeInOutExpo") {$tran_in.= "easing:" . $layer['ti-easing'] . ";";}
                        if (isset($layer['ti-perspective']) && $layer['ti-perspective'] != "" && $layer['ti-perspective'] != "400"){ $tran_in.= "perspective:" . $layer['ti-perspective'] . ";";}
                        if (isset($layer['ti-origin']) && $layer['ti-origin'] != "" &&  $layer['ti-origin'] != "50% 50% 0") {$tran_in.= "transformorigin:" . $layer['ti-origin'] . ";";}

                        if (isset($layer['ti-fade']) && $layer['ti-fade'] == "on") {}else{$tran_in.= "fade:false;";}

                        if($tran_in!=''){
                            $tran_in="data-transitionin='".$tran_in."'";
                        }

                        if (isset($layer['to-offsetx']) && $layer['to-offsetx'] != "" && $layer['to-offsetx'] != "0") $tran_out.= "offsetx:" . $layer['to-offsetx'] . ";";
                        if (isset($layer['to-offsety']) && $layer['to-offsety'] != ""  && $layer['to-offsety'] != "0") $tran_out.= "offsety:" . $layer['to-offsety'] . ";";
                        if (isset($layer['to-rotate']) && $layer['to-rotate'] != ""  && $layer['to-rotate'] != "0") $tran_out.= "rotate:" . $layer['to-rotate'] . ";";
                        if (isset($layer['to-rotatex']) && $layer['to-rotatex'] != "" && $layer['to-rotatex'] != "0") $tran_out.= "rotatex:" . $layer['to-rotatex'] . ";";
                        if (isset($layer['to-rotatey']) && $layer['to-rotatey'] != "" && $layer['to-rotatey'] != "0") $tran_out.= "rotatey:" . $layer['to-rotatey'] . ";";
                        if (isset($layer['to-scalex']) && $layer['to-scalex'] != ""  && $layer['to-scalex'] != "1") $tran_out.= "scalex:" . $layer['to-scalex'] . ";";
                        if (isset($layer['to-scaley']) && $layer['to-scaley'] != ""  && $layer['to-scaley'] != "1") $tran_out.= "scaley:" . $layer['to-scaley'] . ";";
                        if (isset($layer['to-skewx']) && $layer['to-skewx'] != ""  && $layer['to-skewx'] != "0") $tran_out.= "skewx:" . $layer['to-skewx'] . ";";
                        if (isset($layer['to-skewy']) && $layer['to-skewy'] != ""  && $layer['to-skewy'] != "0") $tran_out.= "skewy:" . $layer['to-skewy'] . ";";
                        if (isset($layer['to-delay']) && $layer['to-delay'] != "" && $layer['to-delay'] != "0") $tran_out.= "delay:" . $layer['to-delay'] . ";";
                        if (isset($layer['to-duration']) && $layer['to-duration'] != "" && $layer['to-duration'] != "400") $tran_out.= "duration:" . $layer['to-duration'] . ";";
                        if (isset($layer['to-easing']) && $layer['to-easing'] != "" && $layer['to-easing'] != "easeInOutExpo") $tran_out.= "easing:" . $layer['to-easing'] . ";";
                        if (isset($layer['to-perspective']) && $layer['to-perspective'] != "" && $layer['to-perspective'] != "400") $tran_out.= "perspective:" . $layer['to-perspective'] . ";";
                        if (isset($layer['to-origin']) && $layer['to-origin'] != "" && $layer['to-origin'] != "50% 50% 0") $tran_out.= "transformorigin:" . $layer['to-origin'] . ";";
                        if (isset($layer['to-fade']) && $layer['to-fade'] == "on"){} else {$tran_out.= "fade:false;";}

                        if($tran_out!=''){
                            $tran_out="data-transitionout='".$tran_out."'";
                        }                        

                        $cls = "";
                        $link = "";
                        $l_style = "";
                        if ($layer['url'] && $layer['url'] != "") {
                            $link = " href='" . $layer['url'] . "' target='" . $layer['target'] . "'";
                            $cls.= " cloud-link";
                            $l_style = ' style="color:' . $layer['font_color'] . ';"';
                        }
                        if ($layer['classes'] != "") $cls.= " " . $layer['classes'];
                        $attr = "";
                        if (isset($layer['carousel-layer']) && $layer['carousel-layer']) { 
                            $optionArray['carousel']['carousel_'.$i]['available']=1;
                            $cls.= " kr-carousel";
                            if (count($layer['carousel_attr']) > 0) {
                                for ($a = 0; $a < sizeof($layer['carousel_attr']); $a++) {
                                    $carousel = $layer['carousel_attr'][$a];
                                    $val = "";
                                    if ($carousel['attach_layer'] != "" && $carousel['attach_layer']!='Please Select') {
                                        $val = $carousel['attach_layer_value'];
                                        $val = str_replace("'", "&quot;", $val);
                                        /*$attr .= "data-attr".$carousel['attach_layer']."='".$val."' ";*/
                                        $attr.= "data-attr" . $carousel['attach_layer'] . "='" . str_replace("\&quot;", '"', stripslashes(str_replace("\'", "&quot;", $val))) . "' ";
                                    }           
                                }
                            }
                        }

                        if (!empty($all_carousel_layer) && in_array($layer['layer_id'], $all_carousel_layer)) {
                            $cls.= ' kr-carousel-cloud-attr' . $layer['layer_id'];
                        }
                        // if(!in_array($layer['layer_id'],$all_carousel_layer))
                        // {
                        $dataTitle=$layer['subtitle']!=''?'data-title="'.$layer['subtitle'].'"':'';
                        switch ($layer['type']) {
                            case 'image':
                                if ($layer['image']) {
                                    if ($layer['url'] && $layer['url'] != "") $layer_data = '<a ' . $link . 'class="kr-cloud' . $cls . '" style="' . $style_elements . '" ' . $tran_in . ' ' . $tran_out . ' ' . $dataTitle . ' ' . $attr . $attr_elements . '><img src="' . $layer['image'] . '"/></a>';
                                    else $layer_data = '<img ' . $attr . $attr_elements . ' src="' . $layer['image'] . '" class="kr-cloud' . $cls . '" style="' . $style_elements . '" ' . $tran_in . ' ' . $tran_out . ' ' . $dataTitle . ' '. $link . '/>';
                                }
                                break;

                            case 'html':
                                if ($layer['html']) {
                                    if ($layer['url'] && $layer['url'] != "") $layer_data = '<div ' . $attr . $attr_elements . ' class="kr-cloud' . $cls . '" style="' . $style_elements . '" ' . $tran_in . ' ' . $tran_out . ' ' . $dataTitle . ' ' . $link . '><a ' . $link . $l_style . '>' . stripcslashes($layer['html']) . '</a></div>';
                                    else $layer_data = '<div ' . $attr . $attr_elements . ' class="kr-cloud' . $cls . '" style="' . $style_elements . '" ' . $tran_in . ' ' . $tran_out . ' ' . $dataTitle . ' ' . $link . '>' . stripcslashes($layer['html']) . '</div>';
                                }
                                break;

                            case 'dynamic_text':

                                if ($layer["hidden_post_id"] != "") {
                                    get_post($layer["hidden_post_id"]);
                                    $post = get_post($layer['hidden_post_id']);
                                    if ($layer['url'] && $layer['url'] != "") $layer_data = '<div ' . $attr . $attr_elements . ' class="kr-cloud' . $cls . '" style="' . $style_elements . '" ' . $tran_in . ' ' . $tran_out . ' ' . $dataTitle . ' '. $link . '><a ' . $link . '>' . cs_get_content_with_format(stripcslashes($layer['dynamic_text']) , $layer['text-limit'], $post, "str") . '</a></div>';
                                    else $layer_data = '<div ' . $attr . $attr_elements . ' class="kr-cloud' . $cls . '" style="' . $style_elements . '" ' . $tran_in . ' ' . $tran_out . ' ' . $dataTitle . ' ' . $link . '>' . cs_get_content_with_format(stripcslashes($layer['dynamic_text']) , $layer['text-limit'], $post, "str") . '</div>';
                                }
                                else {
                                    if ($layer['url'] && $layer['url'] != "") $layer_data = '<div ' . $attr . $attr_elements . ' class="kr-cloud' . $cls . '" style="' . $style_elements . '" ' . $tran_in . ' ' . $tran_out . ' ' . $dataTitle . ' ' . $link . '><a ' . $link . $l_style . '>' . stripcslashes($layer['dynamic_text']) . '</a></div>';
                                    else $layer_data = '<div ' . $attr . $attr_elements . ' class="kr-cloud' . $cls . '" style="' . $style_elements . '" ' . $tran_in . ' ' . $tran_out . ' ' . $dataTitle . ' ' . $link . '>' . stripcslashes($layer['dynamic_text']) . '</div>';
                                }

                                break;

                            default:
                                if ($layer['type'] && $layer['text']) {
                                    if ($layer['url'] && $layer['url'] != "") $layer_data = '<' . $layer['type'] . ' ' . $attr . $attr_elements . ' class="kr-cloud' . $cls . '" style="' . $style_elements . '" ' . $tran_in . ' ' . $tran_out . ' ' . $dataTitle . ' ' . $link . '><a ' . $link . $l_style . '>' . stripcslashes($layer['text']) . '</a></' . $layer['type'] . '>';
                                    else $layer_data = '<' . $layer['type'] . ' ' . $attr . $attr_elements . ' class="kr-cloud' . $cls . '"  style="' . $style_elements . '" ' . $tran_in . ' ' . $tran_out . ' ' . $dataTitle . ' ' . $link . '>' . stripcslashes($layer['text']) . '</' . $layer['type'] . '>';
                                }
                                break;
                        }
                        $layerHTML.= $layer_data;
                        // }
                    }
                    if (!isset($slide['properties']['hidden']) OR (isset($slide['properties']['hidden']) && $slide['properties']['hidden'] != 'on')) {
                    ?>
                    <div class="kr-sky" <?php
                            echo $data_dur;
                            echo $data_transition;
                            echo $data_ken;                        
                            echo $data_thumb;                        
                            echo $optionArray['carousel']['carousel_'.$i]['available']==1?$data_carousel:''; ?>  >
                        <?php
                            if ($slide['properties']['background'] != "") {
                                if ($slide['properties']['background'] != "") {
                                    $backsize=$slide['properties']['backsize']=='contain'?"data-size='contain'":'';
                                    if ($slide['properties']['layer_link'] != "") {
                                        echo "<a href='" . $slide['properties']['layer_link'] . "' target='" . $slide['properties']['layer_link_target'] . "' style='z-index:99999;'><img src='" . $slide['properties']['background'] . "' class='sky-background' ".$backsize." /></a>";
                                    }
                                    else {
                                        echo "<img src='" . $slide['properties']['background'] . "' class='sky-background' ".$backsize."/>";
                                    }
                                }
                            }
                            echo $layerHTML.$attr_div;
                        ?>

                    </div>
                    <?php
                    }
                }
            }
        ?>
    </div>
    <?php
        $js=array();

        foreach($optionArray as $pKey=>$options)
        {
            switch($pKey)
            {
                case 'genaral':
                case 'callback':
                    $js[]=implode(",\n",$optionArray[$pKey]);
                    break;
                case 'carousel':
                    if(isset($optionArray['carousel']) && count($optionArray['carousel'])>0)
                    {    
                        foreach($optionArray['carousel'] as $key=>$car)
                        {
                            $jsCarousel=array();
                            if($car['available']==1) {
                                if(isset($car['genaral']) && count($car['genaral'])>0)
                                {
                                    $jsCarousel[]=implode(",\n",$car['genaral']);
                                }
                                if(isset($car['arrow']) && count($car['arrow'])>0)
                                {
                                    $jsCarousel[]="\t\t\tarrow: {\n".implode(",\n",$car['arrow'])."\n\t\t\t}";
                                }
                                if(isset($car['level']) && count($car['level'])>0)
                                {
                                    $levelArray=array();
                                    foreach($car['level'] as $level)
                                    {
                                        $levelArray[]="\t\t\t\t\t{\n".implode(",\n",$level)."\n\t\t\t\t\t}";
                                    }
                                    if(count($levelArray)>0)
                                    {
                                        $jsCarousel[]="\t\t\t\tlevel: [\n".implode(",\n",$levelArray)."\n\t\t\t\t]";
                                    }
                                }
                                if(count($jsCarousel)>0)
                                {
                                    $js[]="\t\t\t$key: {\n".implode(",\n",$jsCarousel)."\n\t\t\t}";
                                }
                            }
                        }
                    }
                    break;
                default:
                    $js[]="\t\t\t".$pKey.": {\n".implode(",\n",$optionArray[$pKey])."\n\t\t\t}";
                    break;

            }
        }
        
        $footer = get_option('cs_include_script_footer', false) ? true : false;
        if (!isset($GLOBALS['library_loaded'])) {
            
            wp_register_script('cs-cloudjs', plugins_url('library/js/cloudslider.jquery.min.js', dirname(__FILE__)) , array('jquery') , CS_PLUGIN_VERSION, $footer);
            wp_enqueue_script('cs-cloudjs');

        }
        
    ?>
            <script type="text/javascript">
                
                (function ($) {
    <?php 
                if ($footer) {
    ?>
                    $(document).ready(function() {
    <?php } ?>
                        $('#cloudslider<?php echo $slider_id;?>').cloudSlider({
                            <?php 
                                if(count($js)>0)
                                {
                                    echo implode(",\n",$js);
                                }
                            ?>
                        });
    <?php 
                if ($footer) {
    ?>
                    });
    <?php } ?>
                })(jQuery);
                
            </script>

    <?php
        
    $output = ob_get_contents();
    ob_end_clean();
    if (get_option('cs_concatenate_output', true)) {
        $output = trim(preg_replace('/(?:(?:\r\n|\r|\n)\s*){2}/s', "\n", $output));
    }
    return $output;
}

function cloud_id_callback()
{
    global $objCloudSlider;
    echo $objCloudSlider->fnGetAutoIncrement();
    exit;
}
function cs_update_callback()
{
    global $objCloudSlider;
    $objCloudSlider->fnUpdateCallback($_POST);
    exit;
}
function _save_cloude_advanced_settings()
{
    global $objCloudSlider;
    $objCloudSlider->fnSaveAdvanceCloudSettings($_POST);
}
add_action('init', 'do_output_buffer');
function do_output_buffer()
{
    global $objCloudSlider;
    $objCloudSlider->fnDoOutputBuffer($_REQUEST);
}
function cs_get_post_types()
{
    $post_types = get_post_types();
    if (isset($post_types['revision'])) {
        unset($post_types['revision']);
    }
    if (isset($post_types['nav_menu_item'])) {
        unset($post_types['nav_menu_item']);
    }
    foreach($post_types as $key => $val) {
        if (!empty($val)) {
            $post_types[$key] = array();
            $post_types[$key]['slug'] = $val;
            $post_types[$key]['obj'] = get_post_type_object($val);
            $post_types[$key]['name'] = $post_types[$key]['obj']->labels->name;
        }
    }
    return $post_types;
}
function cs_get_category_list($post = null)
{
    if (!empty($post)) {
        $post = get_post($post->ID);
    }
    if (has_category(false, $post->ID)) {
        $cat_list = wp_get_post_categories($post->ID);
        foreach($cat_list as $cat) {
            $cat_data = get_category($cat);
            $categories[] = '<a href="/category/' . $cat_data->slug . '/">' . $cat_data->name . '</a>';
        }
        return '<div>' . implode(', ', $categories) . '</div>';
    }
    else {
        return '';
    }
}
function cs_get_tag_list($post = null)
{
    if (!empty($post)) {
        $post = get_post($post->ID);
    }
    if (has_tag(false, $post->ID)) {
        $tag_list = wp_get_post_tags($post->ID);
        foreach($tag_list as $tag) {
            $tags[] = '<a href="/tag/' . $val->slug . '/">' . $tag->name . '</a>';
        }
        return '<div>' . implode(', ', $tags) . '</div>';
    }
    else {
        return '';
    }
}
function cs_get_post_data($args)
{
    $post_data = get_posts($args);
    $arr=array();
    foreach($post_data as $key => $val) {
        $arr[$key]['post-id'] = $val->ID;
        $arr[$key]['post-slug'] = $val->post_name;
        $arr[$key]['title'] = $val->post_title;
        $arr[$key]['content'] = wp_strip_all_tags($val->post_content);
        $arr[$key]['excerpt'] = !empty($val->post_excerpt) ? $val->post_excerpt : '';
        $arr[$key]['author'] = get_userdata($val->post_author)->user_nicename;
        $arr[$key]['author-id'] = $val->post_author;
        $arr[$key]['post-url'] = get_permalink($val->ID);
        $arr[$key]['date-published'] = date(get_option('date_format') , strtotime($val->post_date));
        $arr[$key]['date-modified'] = date(get_option('date_format') , strtotime($val->post_modified));
        $thumb = "";
        if (function_exists('get_post_thumbnail_id') && function_exists('wp_get_attachment_url')) {
            $thumb = wp_get_attachment_url(get_post_thumbnail_id($val->ID));
        }
        $arr[$key]['thumbnail'] = $thumb;
        $arr[$key]['thumbnail'] = !empty($arr[$key]['thumbnail']) ? $arr[$key]['thumbnail'] : CS_ROOT_URL . '/images/blank.gif';
        $arr[$key]['image'] = '<img src="' . $arr[$key]['thumbnail'] . '" alt="">';
        $arr[$key]['image-url'] = $arr[$key]['thumbnail'];
        $arr[$key]['categories'] = cs_get_category_list($val);
        $arr[$key]['tags'] = cs_get_tag_list($val);
        $arr[$key]['comments'] = $val->comment_count;
    }
    return $arr;
}
function cloud_post_data_callback()
{
    global $current_user;
    get_currentuserinfo();
    $args = array(
    'post_status' => 'publish',
    'limit' => 20,
    'posts_per_page' => 20,
    'post_type' => $_POST['cs_post_type'],
    'author' => $current_user->ID
    );

    if (!empty($_POST['cs_order_by'])) {
        $args['orderby'] = $_POST['cs_order_by'];
    }
    if (!empty($_POST['cs_order'])) {
        $args['order'] = $_POST['cs_order'];
    }
    if (!empty($_POST['cs_post_cat'][0])) {
        $args['category__in'] = $_POST['cs_post_cat'];
    }
    if (!empty($_POST['cs_post_tags'][0])) {
        $args['tag__in'] = $_POST['cs_post_tags'];
    }
    $posts = cs_get_post_data($args);
    die(json_encode($posts));
}
function cloud_short_code_callback()
{
    $post = get_post($_POST["postid"]);
    $content = $_POST["content"];
    $len = $_POST["text_length"];
    echo cs_get_content_with_format($content, $len, $post, "");
    exit;
}
function cs_get_content_with_format($text, $textlen = 0, $post, $type = "")
{
    if (!is_object($post)) {
        return $text;
    }
    $arr = array();
    if (stripos($text, '[post-id]') !== false) {
        $text = str_replace('[post-id]', $post->ID, $text);
        $arr['post-id'] = $post->ID;
    }
    if (stripos($text, '[post-slug]') !== false) {
        $text = str_replace('[post-slug]', $post->post_name, $text);
        $arr['post-slug'] = $post->post_name;
    }
    if (stripos($text, '[title]') !== false) {
        if (!empty($textlen)) {
            $text = str_replace('[title]', substr(get_the_title($post->ID) , 0, $textlen) , $text);
            $arr['title'] = substr(get_the_title($post->ID) , 0, $textlen);
        }
        else {
            $text = str_replace('[title]', get_the_title($post->ID) , $text);
            $arr['title'] = get_the_title($post->ID);
        }
    }
    if (stripos($text, '[content]') !== false) {
        if (empty($textlen)) $content = wp_strip_all_tags($post->post_content);
        else $content = substr(wp_strip_all_tags($post->post_content) , 0, $textlen);
        $text = str_replace('[content]', $content, $text);
        $arr['content'] = $content;
    }
    if (stripos($text, '[excerpt]') !== false) {
        if (!empty($textlen)) {
            if (empty($post->post_excerpt)) {
                $text = str_replace('[excerpt]', '[excerpt]', $text);
                $arr['excerpt'] = '[excerpt]';
            }
            else {
                $text = str_replace('[excerpt]', substr($post->post_excerpt, 0, $textlen) , $text);
                $arr['excerpt'] = substr($post->post_excerpt, 0, $textlen);
            }
        }
        else {
            if (empty($post->post_excerpt)) {
                $text = str_replace('[excerpt]', '[excerpt]', $text);
                $arr['excerpt'] = '[excerpt]';
            }
            else {
                $text = str_replace('[excerpt]', $post->post_excerpt, $text);
                $arr['excerpt'] = $post->post_excerpt;
            }
        }
    }
    if (stripos($text, '[author]') !== false) {
        $post_author = get_userdata($post->post_author)->user_nicename;
        $text = str_replace('[author]', $post_author, $text);
        $arr['author'] = $post_author;
    }
    if (stripos($text, '[author-id]') !== false) {
        $text = str_replace('[author-id]', $post->post_author, $text);
        $arr['author-id'] = $post->post_author;
    }
    if (stripos($text, '[post-url]') !== false) {
        $text = str_replace('[post-url]', get_permalink($post->ID) , $text);
        $arr['post-url'] = get_permalink($post->ID);
    }
    if (stripos($text, '[date-published]') !== false) {
        $text = str_replace('[date-published]', date(get_option('date_format') , strtotime($post->post_date)) , $text);
        $arr['date-published'] = date(get_option('date_format') , strtotime($post->post_date));
    }
    if (stripos($text, '[date-modified]') !== false) {
        $text = str_replace('[date-modified]', date(get_option('date_format') , strtotime($post->post_modified)) , $text);
        $arr['date-modified'] = date(get_option('date_format') , strtotime($post->post_modified));
    }
    if (stripos($text, '[image]') !== false) {
        if (has_post_thumbnail($post->ID)) {
            $src = "";
            if (function_exists('get_post_thumbnail_id') && function_exists('wp_get_attachment_url')) {
                $src = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
            }
            if (!empty($src)) {
                $text = str_replace('[image]', '<img src="' . $src . '" />', $text);
                $arr['image'] = '<img src="' . $src . '" />';
            }
        }
    }
    if (stripos($text, '[image-url]') !== false) {
        if (has_post_thumbnail($post->ID)) {
            $src = "";
            if (function_exists('get_post_thumbnail_id') && function_exists('wp_get_attachment_url')) {
                $src = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
            }
            if (!empty($src)) {
                $text = str_replace('[image-url]', $src, $text);
                $arr['image-url'] = $src;
            }
        }
    }
    if (stripos($text, '[categories]') !== false) {
        $text = str_replace('[categories]', cs_get_category_list($post) , $text);
        $arr['categories'] = cs_get_category_list($post);
    }
    if (stripos($text, '[tags]') !== false) {
        $text = str_replace('[tags]', cs_get_tag_list($post) , $text);
        $arr['tags'] = cs_get_tag_list($post);
    }
    if (stripos($text, '[comments]') !== false) {
        $text = str_replace('[comments]', $post->comment_count, $text);
        $arr['comments'] = $post->comment_count;
    }
    if ($type == "str") return trim($text);
    else return json_encode($arr);
}
function display_time($time_ago)
{
    $cur_time = time();
    $time_elapsed = $cur_time - $time_ago;
    $seconds = $time_elapsed;
    $minutes = round($time_elapsed / 60);
    $hours = round($time_elapsed / 3600);
    $days = round($time_elapsed / 86400);
    $weeks = round($time_elapsed / 604800);
    $months = round($time_elapsed / 2600640);
    $years = round($time_elapsed / 31207680);
    // Seconds
    if ($seconds <= 60) {
        echo "$seconds seconds ago";
    }
    // Minutes
    else if ($minutes <= 60) {
            if ($minutes == 1) {
                echo "one minute ago";
            }
            else {
                echo "$minutes minutes ago";
            }
        }
        // Hours
        else if ($hours <= 24) {
                if ($hours == 1) {
                    echo "an hour ago";
                }
                else {
                    echo "$hours hours ago";
                }
            }
            // Days
            else if ($days <= 7) {
                    if ($days == 1) {
                        echo "yesterday";
                    }
                    else {
                        echo "$days days ago";
                    }
                }
                // Weeks
                else if ($weeks <= 4.3) {
                        if ($weeks == 1) {
                            echo "a week ago";
                        }
                        else {
                            echo "$weeks weeks ago";
                        }
                    }
                    // Months
                    else if ($months <= 12) {
                            if ($months == 1) {
                                echo "a month ago";
                            }
                            else {
                                echo "$months months ago";
                            }
                        }
                        // Years
                        else {
                            if ($years == 1) {
                                echo "one year ago";
                            }
                            else {
                                echo "$years years ago";
                            }
    }
}
add_filter('ajax_query_attachments_args', "user_restrict_media_library");
function user_restrict_media_library($query)
{
    if (current_user_can("manage_options")) {
        $blogusers = get_users(array(
        'role' => 'administrator',
        "fields" => "ID",
        "exclude" => get_current_user_id()
        ));
        $query['author__not_in'] = $blogusers;
        return $query;
    }
    else {
        global $current_user;
        $query['author'] = $current_user->id;
        return $query;
    }
}
function my_files_only($wp_query)
{
    if (strpos($_SERVER['REQUEST_URI'], '/wp-admin/upload.php') !== false) {
        if (current_user_can("manage_options")) {
            $blogusers = get_users(array(
            'role' => 'administrator',
            "fields" => "ID",
            "exclude" => get_current_user_id()
            ));
            $wp_query->set('author__not_in', $blogusers);
        }
        else {
            global $current_user;
            $wp_query->set('author', $current_user->id);
        }
    }
}
add_filter('parse_query', 'my_files_only');
function add_theme_caps()
{
    $role = get_role('contributor');
    $role->add_cap('upload_files');
    $role1 = get_role('subscriber');
    $role1->add_cap('upload_files');
}
add_action('admin_init', 'add_theme_caps');
