<?php
/**
 * Callback for Social Links  
 */
function ellolite_social_cb() {
    $facebook  = get_theme_mod('ellolite_facebook', 'https://www.facebook.com/pixelonetry');
    $twitter   = get_theme_mod('ellolite_twitter', '#');
    $pinterest = get_theme_mod('ellolite_pinterest', 'https://www.pinterest.com/pixelonetry');
    $linkedin    = get_theme_mod( 'ellolite_linkedin' );
    $instagram = get_theme_mod('ellolite_instagram', 'https://www.instagram.com/pixelonetry_llc');
    $youtube     = get_theme_mod( 'ellolite_youtube' );
    $tiktok      = get_theme_mod( 'ellolite_tiktok' );

    if ( $facebook || $twitter || $pinterest || $linkedin || $instagram || $youtube || $tiktok ) { ?>
        <div class="social">
            <?php 
                if ( $facebook ) echo '<a class="facebook" href="' . esc_url( $facebook ) . '" target="_blank" title="' . esc_attr__( 'Facebook', 'ello-lite-photography' ) . '"><i class="fa fa-facebook"></i></a>';
                if ( $twitter ) echo '<a class="twitter" href="' . esc_url( $twitter ) . '" target="_blank" title="' . esc_attr__( 'Twitter', 'ello-lite-photography' ) . '"><i class="fa fa-twitter"></i></a>'; 
                if ( $pinterest ) echo '<a class="pinterest" href="' . esc_url( $pinterest ) . '" target="_blank" title="' . esc_attr__( 'Pinterest', 'ello-lite-photography' ) . '"><i class="fa fa-pinterest-p"></i></a>';
                if ( $linkedin ) echo '<a class="linkedin" href="' . esc_url( $linkedin ) . '" target="_blank" title="' . esc_attr__( 'LinkedIn', 'ello-lite-photography' ) . '"><i class="fa fa-linkedin"></i></a>';
                if ( $instagram ) echo '<a class="instagram" href="' . esc_url( $instagram ) . '" target="_blank" title="' . esc_attr__( 'Instagram', 'ello-lite-photography' ) . '"><i class="fa fa-instagram"></i></a>';
                if ( $youtube ) echo '<a class="youtube" href="' . esc_url( $youtube ) . '" target="_blank" title="' . esc_attr__( 'YouTube', 'ello-lite-photography' ) . '"><i class="fa fa-youtube"></i></a>';
                if ( $tiktok ) echo '<a class="tiktok" href="' . esc_url( $tiktok ) . '" target="_blank" title="' . esc_attr__( 'TikTok', 'ello-lite-photography' ) . '"><i class="fab fa-tiktok"></i></a>';
            ?>
        </div>
    <?php }
}
add_action( 'ellolite_social', 'ellolite_social_cb' );
?>

<?php

function ellolite_header_social_cb() {
    $facebook    = get_theme_mod( 'ellolite_facebook' );
    $twitter     = get_theme_mod( 'ellolite_twitter' );
    $pinterest   = get_theme_mod( 'ellolite_pinterest' );
    $linkedin    = get_theme_mod( 'ellolite_linkedin' );
    $instagram   = get_theme_mod( 'ellolite_instagram' );
    $youtube     = get_theme_mod( 'ellolite_youtube' );
    $tiktok      = get_theme_mod( 'ellolite_tiktok' );

    if ( $facebook || $twitter || $pinterest || $linkedin || $instagram || $youtube || $tiktok ) { ?>
        <ul>
            <?php 
                if ( $facebook ) echo '<li><a class="fa-social-hover" href="' . esc_url( $facebook ) . '" target="_blank" title="' . esc_attr__( 'Facebook', 'ello-lite-photography' ) . '"><i class="fa fa-facebook"></i></a></li>';
                if ( $twitter ) echo '<li><a class="fa-social-hover" href="' . esc_url( $twitter ) . '" target="_blank" title="' . esc_attr__( 'Twitter', 'ello-lite-photography' ) . '"><i class="fa fa-twitter"></i></a></li>'; 
                if ( $pinterest ) echo '<li><a class="fa-social-hover" href="' . esc_url( $pinterest ) . '" target="_blank" title="' . esc_attr__( 'Pinterest', 'ello-lite-photography' ) . '"><i class="fa fa-pinterest-p"></i></a></li>';
                if ( $linkedin ) echo '<li><a class="fa-social-hover" href="' . esc_url( $linkedin ) . '" target="_blank" title="' . esc_attr__( 'LinkedIn', 'ello-lite-photography' ) . '"><i class="fa fa-linkedin"></i></a></li>';
                if ( $instagram ) echo '<li><a class="fa-social-hover" href="' . esc_url( $instagram ) . '" target="_blank" title="' . esc_attr__( 'Instagram', 'ello-lite-photography' ) . '"><i class="fa fa-instagram"></i></a></li>';
                if ( $youtube ) echo '<li><a class="fa-social-hover" href="' . esc_url( $youtube ) . '" target="_blank" title="' . esc_attr__( 'YouTube', 'ello-lite-photography' ) . '"><i class="fa fa-youtube"></i></a></li>';
                if ( $tiktok ) echo '<li><a class="fa-social-hover" href="' . esc_url( $tiktok ) . '" target="_blank" title="' . esc_attr__( 'TikTok', 'ello-lite-photography' ) . '"><i class="fab fa-tiktok"></i></a></li>';
            ?>
        </ul>
    <?php }
}
add_action( 'ellolite_header_social', 'ellolite_header_social_cb' );

/*******************************************************************************/
/*  Get Started Notice                                                         */
/*******************************************************************************/
add_action( 'wp_ajax_ello_lite_photography_dismissed_notice_handler', 'ello_lite_photography_ajax_notice_handler' );

 /**
  * AJAX handler to store the state of dismissible notices.
  */
 function ello_lite_photography_ajax_notice_handler() {
     if ( isset( $_POST['type'] ) ) {
         // Pick up the notice "type" - passed via jQuery (the "data-notice" attribute on the notice)
         $type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
         // Store it in the options table
         update_option( 'dismissed-' . $type, TRUE );
     }
 }
 
 function ello_lite_photography_deprecated_hook_admin_notice() {
         // Check if it's been dismissed...
         if ( ! get_option('dismissed-get_started', FALSE ) ) {
             // Added the class "notice-get-started-class" so jQuery pick it up and pass via AJAX,
             // and added "data-notice" attribute in order to track multiple / different notices
             // multiple dismissible notice states ?>
             <div class="updated notice notice-get-started-class is-dismissible" data-notice="get_started">
                 <div class="ello-lite-photography-getting-started-notice clearfix">
                     <div class="ello-lite-photography-theme-screenshot">
                         <img src="<?php echo esc_url( get_stylesheet_directory_uri() ); ?>/screenshot.png" class="screenshot" alt="<?php esc_attr_e( 'Theme Screenshot', 'ello-lite-photography' ); ?>" />
                     </div><!-- /.ello-lite-photography-theme-screenshot -->
                     <div class="ello-lite-photography-theme-notice-content">
                         <h2 class="ello-lite-photography-notice-h2">
                             <?php
                         printf(
                         /* translators: 1: welcome page link starting html tag, 2: welcome page link ending html tag. */
                             esc_html__( 'Welcome! Thank you for choosing %1$s!', 'ello-lite-photography' ), '<strong>'. wp_get_theme()->get('Name'). '</strong>' );
                         ?>
                         </h2>
 
                         <p class="plugin-install-notice"><?php echo sprintf(__('Install and activate <strong>Pixelonetry Companion</strong> plugin for taking full advantage of all the features this theme has to offer.', 'ello-lite-photography')) ?></p>
 
                         <a class="ello-lite-photography-btn-get-started button button-primary button-hero ello-lite-photography-button-padding" href="#" data-name="" data-slug=""><?php esc_html_e( 'Get started with Ello', 'ello-lite-photography' ) ?></a><span class="ello-lite-photography-push-down">
                         <?php
                             /* translators: %1$s: Anchor link start %2$s: Anchor link end */
                             printf(
                                 'or %1$sCustomize theme%2$s</a></span>',
                                 '<a target="_blank" href="' . esc_url( admin_url( 'customize.php' ) ) . '">',
                                 '</a>'
                             );
                         ?>
                     </div><!-- /.ello-lite-photography-theme-notice-content -->
                 </div>
             </div>
         <?php }
 }
 
 add_action( 'admin_notices', 'ello_lite_photography_deprecated_hook_admin_notice' );

/*******************************************************************************/
/*  Plugin Installer                                                           */
/*******************************************************************************/


 add_action( 'wp_ajax_install_act_plugin', 'ello_lite_photography_admin_install_plugin' );
 
 function ello_lite_photography_admin_install_plugin() {
     /**
      * Install Plugin.
      */
     include_once ABSPATH . '/wp-admin/includes/file.php';
     include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
 
     if ( ! file_exists( WP_PLUGIN_DIR . '/pixelonetry-companion' ) ) {
         $api = plugins_api( 'plugin_information', array(
             'slug'   => sanitize_key( wp_unslash( 'pixelonetry-companion' ) ),
             'fields' => array(
                 'sections' => false,
             ),
         ) );
 
         $skin     = new WP_Ajax_Upgrader_Skin();
         $upgrader = new Plugin_Upgrader( $skin );
         $result   = $upgrader->install( $api->download_link );
     }
 
     // Activate plugin.
     if ( current_user_can( 'activate_plugin' ) ) {
         $result = activate_plugin( 'pixelonetry-companion/pixelonetry-companion.php' );
     }
 }	
 
 ?>