<?php
/* 
Plugin Name: Luzuk - Multi Slider
Plugin URI: 
Description: Luzuk - Multi Slider is a simple and user-friendly slider plugin.
Version: 0.0.5
Requires PHP: 7.0
Requires at least: 5.0
Author: Luzuk
Author URI: https://www.luzuk.com
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

// Define constants
define( 'LMSLIDER_DIR_PATH', plugin_dir_path( __FILE__ ) );
define( 'LMSLIDER_DIR_URL', plugin_dir_url( __FILE__ ) );

$lsmp_options="";
$lsmp_options = get_option('lsmp_options');


// Plugin activation and deactivation
register_activation_hook(__FILE__, 'lmslider_activation');
function lmslider_activation() {}

register_deactivation_hook(__FILE__, 'lmslider_deactivation');
function lmslider_deactivation() {}


// Added styes admin
add_action('admin_enqueue_scripts', 'lmslider_admin_styles');
function lmslider_admin_styles() {
    
    // Define version (static or dynamic using filemtime())
    $plugin_version = '0.0.5'; 

    wp_register_style('lmslider_style', plugins_url('assets/css/style.css', __FILE__), array(), $plugin_version);
    wp_enqueue_style('lmslider_style');

    wp_register_style('bootstrap-css', plugins_url('assets/css/bootstrap.css', __FILE__), array(), $plugin_version);
    wp_enqueue_style('bootstrap-css');

    wp_register_style('bootstrap-js', plugins_url('assets/js/bootstrap.js', __FILE__),array('jquery'),'5.3.0',true);
    wp_enqueue_style('bootstrap-js');

    wp_register_style('lmslider_fontawesome_style', plugins_url('assets/css/font-awesome.css', __FILE__), array(), $plugin_version);
    wp_enqueue_style('lmslider_fontawesome_style');

    wp_register_style('lmslider_fontawesomeall_style', plugins_url('assets/css/fontawesome-all.css', __FILE__), array(), $plugin_version);
    wp_enqueue_style('lmslider_fontawesomeall_style');

}

// Adding Custom Post Type
function lmslider_createcustomtypesslider() {
    // slider
    register_post_type('lmslider_our_slider', array(
        'labels' => array(
            'name' => esc_html__('Luzuk Multi Slider', 'luzuk-multi-slider'),
            'singular_name' => esc_html__('Slider', 'luzuk-multi-slider'),
        ),
        'public' => true,
        'has_archive' => true,
        'menu_icon' => 'dashicons-images-alt',
        'supports' => array('title', 'thumbnail', 'editor', 'page-attributes'),
        'rewrite' => array('slug' => 'luzuk-slider'),
        'show_in_rest' => true, // Enables Gutenberg support
    ));    
}
// Post type initialize
add_action('init', 'lmslider_createcustomtypesslider');


/**
  * Custom Post Type add Subpage to Custom Post Menu
  * @description- Luzuk - Multi Slider Custom Post Type Submenu Example
  * 
  *
  */
 
// Hook   
 
add_action('admin_menu', 'lmslider_submenu');
 
//admin_menu callback function
 
function lmslider_submenu(){
 
    add_submenu_page(
        'edit.php?post_type=lmslider_our_slider',
        'Slider',
        'Dashboard',
        'manage_options',
        'tutorial_subpage_example',
        'lmslider_optionspage'
    );
     
}

        
function lmslider_optionspage() {
?>

<div class="lspluginsetting">
    <div class="header row">
        <div class="col-lg-4 col-md-4 dashb"> 
            <h3><i class="fa-solid fa-house"></i><?php echo esc_html(' Dashboard'); ?></h3>
        </div>
        <div class="col-lg-4 col-md-4 logo">
            <h3><?php echo esc_html('Luzuk - Multi Slider'); ?></h3>
        </div>
        <div class="col-lg-4 col-md-4 sett">
            <h3>
                <a href="<?php echo esc_url('https://www.luzuk.com/contact-us/'); ?>" target="_blank">
                    <?php echo esc_html__('Help', 'luzuk-multi-slider'); ?>
                </a>
            </h3>
        </div>
    </div>
    <div class="lsheadinginfo">
        <div class="head">
            <h3><?php echo esc_html('How To Publish'); ?></h3>
        </div>
        <div class="infobox row">
            <div class="col-lg-6 col-md-6 lsheading-content box1">
                <h4><?php echo esc_html('Shortcode'); ?></h4>
                <p><?php echo esc_html('Copy and paste this shortcode into your posts or pages:'); ?></p>
                <h3><?php echo esc_html('[lms_building_construction_company]'); ?></h3>
            </div>
            <div class="col-lg-6 col-md-6 lsheading-content box2">
                <h4><?php echo esc_html('PHP code'); ?></h4>
                <p><?php echo esc_html('Paste the PHP code into your theme\'s file:'); ?></p>
                <h3><?php echo esc_html('<?php echo do_shortcode(\'[lms_building_construction_company]\'); ?>'); ?></h3>
            </div>
        </div>
    </div>
    <div class="lsdesigns">
        <div class="lsdesignhead">
            <h3><?php echo esc_html('Designs'); ?></h3>
        </div>
        <div class="lsdesigncontent">
            <div class="row">
                <div class="col-lg-4 col-md-4 designs">
                    <img src="<?php echo esc_url(plugins_url('assets/images/slider1img.png', __FILE__)); ?>" alt="Slider 1 Image">
                    <h4><?php echo esc_html('Shortcode'); ?></h4>
                    <h3><?php echo esc_html('[lms_building_construction_company]'); ?></h3>
                </div>
                <div class="col-lg-4 col-md-4 designs">
                    <img src="<?php echo esc_url(plugins_url('assets/images/slider2img.png', __FILE__)); ?>" alt="Slider 2 Image">
                    <h4><?php echo esc_html('Shortcode'); ?></h4>
                    <h3><?php echo esc_html('[lms_expert_teacher]'); ?></h3>
                </div>
                <div class="col-lg-4 col-md-4 designs">
                    <img src="<?php echo esc_url(plugins_url('assets/images/slider3img.jpg', __FILE__)); ?>" alt="Slider 3 Image">
                    <h4><?php echo esc_html('Shortcode'); ?></h4>
                    <h3><?php echo esc_html('[lms_social_ngo]'); ?></h3>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-4 col-md-4 designs">
                    <img src="<?php echo esc_url(plugins_url('assets/images/slider4img.png', __FILE__)); ?>" alt="Slider 4 Image">
                    <h4><?php echo esc_html('Shortcode'); ?></h4>
                    <h3><?php echo esc_html('[lms_movers_and_packers]'); ?></h3>
                </div>
            </div>
        </div>
    </div>
</div>

<?php }


/***** Start Add custome fields for slider luzuk section *****/
/**
 * @author Luzuk <support@luzuk.com>
 **/

/**
 * When the post is saved, saves our custom data 
 * @author Luzuk <support@luzuk.com>
 **/
function lmslider_custombutton(){
    global $post;
    // Get the saved values 
    $buttonlabel = get_post_meta($post->ID, 'buttonlabel', false);
    $buttonlabel = !empty($buttonlabel[0])?$buttonlabel[0]:'';

    $buttonlink = get_post_meta($post->ID, 'buttonlink', false);
    $buttonlinkvalue = !empty($buttonlink[0])?$buttonlink[0]:'';

    $buttonlabel1 = get_post_meta($post->ID, 'buttonlabel1', false);
    $buttonlabel1 = !empty($buttonlabel1[0])?$buttonlabel1[0]:'';

    $buttonlink1 = get_post_meta($post->ID, 'buttonlink1', false);
    $buttonlinkvalue1 = !empty($buttonlink1[0])?$buttonlink1[0]:''; 

    // Use nonce for verification
    lmslider_noncefield(); // Add nonce field for security 

    // Display the input fields
    echo '<table width="100%">';
    echo '<tr> 
        <th width="10%">1. Button label :</th>
        <td width="10%"><input type="text" name="buttonlabel" value="' . esc_attr($buttonlabel) . '" /></td>
        <th width="10%">Button link :</th>
        <td><input type="text" name="buttonlink" value="' . esc_attr($buttonlinkvalue) . '" /></td>
    </tr>';
    echo '<tr> 
        <th width="10%">2. Button label :</th>
        <td width="10%"><input type="text" name="buttonlabel1" value="' . esc_attr($buttonlabel1) . '" /></td>
        <th width="10%">Button link :</th>
        <td><input type="text" name="buttonlink1" value="' . esc_attr($buttonlinkvalue1) . '" /></td>
    </tr>';
    echo '</table>';
}

function lmslider_posthook(){
    add_meta_box('sliderluzuk-text', __('Add Button', 'luzuk-multi-slider'), 'lmslider_custombutton', 'lmslider_our_slider', 'normal', 'high');
}

add_action('add_meta_boxes', 'lmslider_posthook');


function lmslider_custombutton_data($post_id) {
    // Check if this is an autosave. If it is, our form has not been submitted, so return.
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }

    // Verify the nonce for security.
    if (
        isset($_POST['sliderluzuk_nonce']) && 
        !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['sliderluzuk_nonce'])), 'lmslider_save_data')
    ) {
        return;
    }

    // Check if the user has the permission to edit the post.
    if (!current_user_can('edit_post', $post_id)) {
        return;
    }

    // Process and save the form data only if it exists.
    if (
        isset($_POST['buttonlink']) || 
        isset($_POST['buttonlabel']) || 
        isset($_POST['buttonlink1']) || 
        isset($_POST['buttonlabel1'])
    ) {
        // Sanitize and save data.
        if (!empty($_POST['buttonlink'])) {
            $buttonlink = sanitize_text_field(wp_unslash($_POST['buttonlink']));
            update_post_meta($post_id, 'buttonlink', $buttonlink);
        }

        if (!empty($_POST['buttonlabel'])) {
            $buttonlabel = sanitize_text_field(wp_unslash($_POST['buttonlabel']));
            update_post_meta($post_id, 'buttonlabel', $buttonlabel);
        }

        if (!empty($_POST['buttonlink1'])) {
            $buttonlink1 = sanitize_text_field(wp_unslash($_POST['buttonlink1']));
            update_post_meta($post_id, 'buttonlink1', $buttonlink1);
        }

        if (!empty($_POST['buttonlabel1'])) {
            $buttonlabel1 = sanitize_text_field(wp_unslash($_POST['buttonlabel1']));
            update_post_meta($post_id, 'buttonlabel1', $buttonlabel1);
        }
    }
}

// Add nonce field to your form
function lmslider_noncefield() {
    wp_nonce_field('lmslider_save_data', 'sliderluzuk_nonce');
}

// Hook to save post data
add_action('save_post', 'lmslider_custombutton_data');

// /***** End Add custome fields for slider section *****/

// calling sliders files

// If the slider1.php file is in a subdirectory, e.g., 'includes':
require_once plugin_dir_path(__FILE__) . 'includes/slider1.php';

// If the slider2.php file is in a subdirectory, e.g., 'includes':
require_once plugin_dir_path(__FILE__) . 'includes/slider2.php';

// If the slider2.php file is in a subdirectory, e.g., 'includes':
require_once plugin_dir_path(__FILE__) . 'includes/slider3.php';

// If the slider4.php file is in a subdirectory, e.g., 'includes':
require_once plugin_dir_path(__FILE__) . 'includes/slider4.php';

