<?php
/*
Plugin Name: RM Oxy kits
Author: Right Mind
Author URI: https://rightminddev.com
Description: Oxygen kits.
Version: 1.3
*/
include plugin_dir_path(__FILE__) . "more-functions.php";

// sync meta between translations
include plugin_dir_path(__FILE__) . "trans-sync-meta.php";

include plugin_dir_path(__FILE__) . "trans-get-data.php";

include plugin_dir_path(__FILE__) . "trans-more-funcs.php";


add_action('plugins_loaded', 'rm_oxygen_elements_kits_init');
function rm_oxygen_elements_kits_init(){
    if (!class_exists('OxygenElement')) {
        return;
    }
    
    
	// Update plugin core
// 	if( is_admin() && class_exists('rmPluginsUpdateChecker') ) {
// 	    $plugin_slug    = plugin_basename( __DIR__ );
// 	    $plugin_path    = plugin_basename( __FILE__ );
// 	    $version        = '1.2'; 
// 	    $cache_key      = 'rmOxykits_upd';
// 	    $cache_allowed  = false;
// 	    $website_id     = (defined('DS1Init_settings')) ? DS1Init_settings["ds1_dev_info"]['website_id'] : '';
// 	    $hub_link       = "https://r-m.dev/wp-sources/plugins-hub/rm-oxykits/info.php?version=$version&website_id=$website_id";
	    
// 	    $vvvv = new rmPluginsUpdateChecker($plugin_path, $plugin_slug, $version, $cache_key, $cache_allowed, $hub_link);			    
// 	}
	
		
    include plugin_dir_path(__FILE__) . "elements/rm.picture.element.php";
    include plugin_dir_path(__FILE__) . "elements/rm.video.element.php";
    include plugin_dir_path(__FILE__) . "elements/rm.features.element.php";
    // include plugin_dir_path(__FILE__) . "elements/rm.slider.element.php";
    include plugin_dir_path(__FILE__) . "elements/rm.social.element.php";
    include plugin_dir_path(__FILE__) . "elements/rm.social.share.element.php";
    include plugin_dir_path(__FILE__) . "elements/rm.cf7.element.php";
    include plugin_dir_path(__FILE__) . "elements/rm.maps.element.php";
    include plugin_dir_path(__FILE__) . "elements/rm.multilangtext.element.php";

    /*    foreach ( glob(plugin_dir_path(__FILE__) . "elements/*.php" ) as $filename)
        {
            include $filename;
        }
    */
}

if(! function_exists("rm_file_with_data")) {
  function rm_file_with_data($target="", $type='content', $name=""){
        $type = ($type == 'image') ? "dynamicShortcodesImageMode" : "dynamicShortcodesContentMode";
        $btns = "";
        if($name) {
            $btns .= '<div class="oxygen-file-input-browse" data-mediatitle="Select" data-mediabutton="Select" data-mediaproperty="'. $name .'" data-mediatype="mediaUrl" data-returnvalue="url" style="background-color:var(--oxy-dark-transparent);border-radius:var(--oxy-border-radius);padding-inline:6px;color:#fff;height:21px;margin-right:6px;font-size:var(--oxy-small-text-size);display:flex;align-items:center;cursor:pointer;">browse</div>';
        }
        if($target) {
            $btns .= '<div class="oxygen-dynamic-data-browse" ctdynamicdata data="iframeScope.'. $type .'" callback="iframeScope.'. $target .'">data</div>';
        }
        return $btns;
    }  
}
if(! function_exists("fetchDynamicData") ){
    function rm_oxy_fetchDynamicData( $field ) {
		if( strstr( $field, 'oudata_') ) {
			$field = base64_decode( str_replace( 'oudata_', '', $field ) );
			$shortcode = ougssig( $this->El, $field );
			$field = do_shortcode( $shortcode );
		} elseif( strstr( $field, '[oxygen') ) {
			$shortcode = ct_sign_oxy_dynamic_shortcode(array($field));
			$field = do_shortcode($shortcode);
		}

		return $field;
	}
}

// Iframe Scripts
add_action( 'oxygen_enqueue_iframe_scripts', 'rm_oxygen_iframe_scripts' );
function rm_oxygen_iframe_scripts() {
    wp_enqueue_script( 'rm_oxygen-iframe', plugin_dir_url( __FILE__ ) . 'elements/assets/iframe.js', array(), '1.0.0' );
}