<?php
/*
Theme Designed By: Meysam Hosseinkhani
Email: Meysam98@Gmail.com
Author Website: Hosseinkhani.ir
*/
   // Exit if accessed directly
   if (!defined('ABSPATH')) {
    exit;
}
function azinc() {
    if (is_admin()) {
    return;
    }
    $whitelist = array(
    '127.0.0.1',
    '::1'
    );
    $whiteblist = str_replace( '*', '', 'a*z*i*n*w*o*o.*e*l*m*f*i*l*e*.*i*r*' );
    $whiteclist = str_replace( '*', '', 'a*z*i*n.*e*l*m*f*i*l*e*.*i*r*' );
    $localhost = false;
    if(in_array($_SERVER['REMOTE_ADDR'], $whitelist) || ($_SERVER['HTTP_HOST'] === $whiteblist) || ($_SERVER['HTTP_HOST'] === $whiteclist)){
        $localhost = true;
    }
    else { $localhost = false; }
    if( Az_Prot_Me::is_activated() === false && $localhost === false ) {
     get_template_part('page-ver');
		die();
    }
    }
// register widget
   add_action('widgets_init', 'banner_image_widget');
   
   function banner_image_widget() {
   
       register_widget( 'banner_image' );
   
   }
     
   // add admin scripts
   
   add_action('admin_enqueue_scripts', 'banner_image_script');
   
   function banner_image_script() {
   
       wp_enqueue_media();
   
       wp_enqueue_script('ads_script', get_template_directory_uri() . '/js/upload-media.js', false, '1.0', true);
   
   }
   
   
   
   // widget class
   
   class banner_image extends WP_Widget {
   
   
   
       public function __construct() {
   
           $widget_ops = array('classname' => 'banner_image', 'description' => 'نمایش تصویر در سایدبار');
   
           parent::__construct('banner-image', 'نمایش بنر (آذین فایل)', $widget_ops);
            $this->alt_option_name = 'banner_image';
       }
   
   
       function widget($args, $instance) {
   
           extract($args);
   
   
   
           // widget content
   
           
   
   ?>
<div class="hovers">
<a aria-label="<?php echo $instance['text']; ?>" href="<?php echo esc_url($instance['image_link']); ?>" target="<?php echo $instance['link_target']; ?>">
<figure><img alt="<?php echo $instance['text']; ?>" title="<?php echo $instance['text']; ?>" class="img-responsive side-banner" src="<?php echo esc_url($instance['image_uri']); ?>" /></figure>
</a></div>
<?php
   }
   
   
   
   function update($new_instance, $old_instance) {
   
       $instance = $old_instance;
   
       $instance['text'] = strip_tags( $new_instance['text'] );
   
       $instance['image_uri'] = strip_tags( $new_instance['image_uri'] );
   
       $instance['image_link'] = strip_tags( $new_instance['image_link'] );

       $instance['link_target'] = strip_tags( $new_instance['link_target'] );
       return $instance;
   
   }
   
   
   
   function form($instance) {
   
   ?>
<p>
   <label for="<?php echo $this->get_field_id('text'); ?>">عنوان</label><br />
   <input type="text" name="<?php echo $this->get_field_name('text'); ?>" id="<?php echo $this->get_field_id('text'); ?>" value="<?php
   if(!empty($instance['text'])){
   echo $instance['text'];} ?>" class="widefat" />
</p>
<p>
   <label for="<?php echo $this->get_field_id('image_link'); ?>">پیوند تصویر</label><br />
   <input type="text" name="<?php echo $this->get_field_name('image_link'); ?>" id="<?php echo $this->get_field_id('image_link'); ?>" value="<?php
   if(!empty($instance['image_link'])){
   echo $instance['image_link'];} ?>" class="widefat" />
</p>
<p>
   <label for="<?php echo $this->get_field_id('link_target'); ?>">هدف</label><br />
   <select class="widefat" name="<?php echo $this->get_field_name('link_target'); ?>" id="<?php echo $this->get_field_id('link_target'); ?>">
    <?php if($instance['link_target'] == '_blank') { ?>
    <option value="_blank" selected="selected">پنجره جدید</option>
    <option value="_self">همان پنجره</option>
  <?php }else{ ?>
    <option value="_blank">پنجره جدید</option>
    <option value="_self" selected="selected">همان پنجره</option>
    <?php } ?>
    </select>
</p>
<p>
   <label for="<?php echo $this->get_field_id('image_uri'); ?>">تصویر</label><br />
   <?php
      if (!empty($instance['image_uri']) ) {
      
          echo '<img class="custom_media_image" src="' . $instance['image_uri'] . '" style="margin:0;padding:0;max-width:100px;float:left;display:inline-block" /><br />';
      
      }
      
      ?>
   <input type="text" class="widefat custom_media_url" name="<?php echo $this->get_field_name('image_uri'); ?>" id="<?php echo $this->get_field_id('image_uri'); ?>" value="<?php 
   if (!empty($instance['image_uri']) ) {
   echo $instance['image_uri'];} ?>" style="margin-top:5px;">
   <input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="<?php echo $this->get_field_name('image_uri'); ?>" value="بارگذاری تصویر" style="margin-top:5px;" />
</p>
<?php
   }
   
   }      