| 1 |
<?php |
| 2 |
/* |
| 3 |
* Virtue Image Widget for compatiblity |
| 4 |
*/ |
| 5 |
|
| 6 |
if ( ! class_exists( 'Simple_About_With_Image' ) ) { |
| 7 |
class Simple_About_With_Image extends WP_Widget { |
| 8 |
|
| 9 |
private static $instance = 0; |
| 10 |
public function __construct() { |
| 11 |
$widget_ops = array( 'classname' => 'virtue_about_with_image', 'description' => __( 'This allows for an image and a simple about text.', 'virtue-toolkit' ) ); |
| 12 |
parent::__construct( 'virtue_about_with_image', __( 'Virtue: Image', 'virtue-toolkit' ), $widget_ops); |
| 13 |
} |
| 14 |
|
| 15 |
public function widget( $args, $instance ){ |
| 16 |
extract( $args ); |
| 17 |
if ( ! empty( $instance['image_link_open'] ) && 'none' == $instance['image_link_open'] ) { |
| 18 |
$uselink = false; |
| 19 |
$link = ''; |
| 20 |
$linktype = ''; |
| 21 |
} else if( empty( $instance['image_link_open'] ) || "lightbox" == $instance['image_link_open'] ) { |
| 22 |
$uselink = true; |
| 23 |
$link = esc_url($instance['image_uri']); |
| 24 |
$linktype = 'rel="lightbox"'; |
| 25 |
} else if( $instance['image_link_open'] == "_blank" ) { |
| 26 |
$uselink = true; |
| 27 |
if( ! empty($instance['image_link'])) { |
| 28 |
$link = $instance['image_link']; |
| 29 |
} else { |
| 30 |
$link = esc_url( $instance['image_uri'] ); |
| 31 |
} |
| 32 |
$linktype = 'target="_blank"'; |
| 33 |
} else if( $instance['image_link_open'] == "_self" ) { |
| 34 |
$uselink = true; |
| 35 |
if( ! empty($instance['image_link'] ) ) { |
| 36 |
$link = $instance['image_link']; |
| 37 |
} else { |
| 38 |
$link = esc_url( $instance['image_uri'] ); |
| 39 |
} |
| 40 |
$linktype = 'target="_self"'; |
| 41 |
} |
| 42 |
|
| 43 |
echo $before_widget; |
| 44 |
?> |
| 45 |
<div class="kad_img_upload_widget"> |
| 46 |
<?php if($uselink == true) {echo '<a href="'.$link.'" '.$linktype.'>';} ?> |
| 47 |
<img src="<?php echo esc_url($instance['image_uri']); ?>" /> |
| 48 |
<?php if($uselink == true) {echo '</a>'; }?> |
| 49 |
<?php if(!empty($instance['text'])) { ?> <div class="virtue_image_widget_caption"><?php echo $instance['text']; ?></div><?php }?> |
| 50 |
</div> |
| 51 |
|
| 52 |
<?php |
| 53 |
echo $after_widget; |
| 54 |
} |
| 55 |
|
| 56 |
public function update( $new_instance, $old_instance ) { |
| 57 |
$instance = $old_instance; |
| 58 |
$instance['text'] = $new_instance['text']; |
| 59 |
$instance['image_uri'] = strip_tags( $new_instance['image_uri'] ); |
| 60 |
$instance['image_link'] = $new_instance['image_link']; |
| 61 |
$instance['image_link_open'] = $new_instance['image_link_open']; |
| 62 |
return $instance; |
| 63 |
} |
| 64 |
|
| 65 |
public function form( $instance ){ |
| 66 |
$image_uri = isset($instance['image_uri']) ? esc_attr($instance['image_uri']) : ''; |
| 67 |
$image_link = isset($instance['image_link']) ? esc_attr($instance['image_link']) : ''; |
| 68 |
if (isset($instance['image_link_open'])) { $image_link_open = esc_attr($instance['image_link_open']); } else {$image_link_open = 'lightbox';} |
| 69 |
$link_options = array(); |
| 70 |
$link_options_array = array(); |
| 71 |
$link_options[] = array("slug" => "lightbox", "name" => __('Lightbox', 'virtue-toolkit')); |
| 72 |
$link_options[] = array("slug" => "_blank", "name" => __('New Window', 'virtue-toolkit')); |
| 73 |
$link_options[] = array("slug" => "_self", "name" => __('Same Window', 'virtue-toolkit')); |
| 74 |
$link_options[] = array("slug" => "none", "name" => __('No Link', 'virtue-toolkit')); |
| 75 |
|
| 76 |
foreach ($link_options as $link_option) { |
| 77 |
if ($image_link_open == $link_option['slug']) {$selected=' selected="selected"';} else { $selected=""; } |
| 78 |
$link_options_array[] = '<option value="' . $link_option['slug'] .'"' . $selected . '>' . $link_option['name'] . '</option>'; |
| 79 |
} |
| 80 |
?> |
| 81 |
<div class="kad_img_upload_widget"> |
| 82 |
<p> |
| 83 |
<img class="kad_custom_media_image" src="<?php if(!empty($instance['image_uri'])){echo $instance['image_uri'];} ?>" style="margin:0;padding:0;max-width:100px;display:block" /> |
| 84 |
</p> |
| 85 |
<p> |
| 86 |
<label for="<?php echo $this->get_field_id('image_uri'); ?>"><?php _e('Image URL', 'virtue-toolkit'); ?></label><br /> |
| 87 |
<input type="text" class="widefat kad_custom_media_url" name="<?php echo $this->get_field_name('image_uri'); ?>" id="<?php echo $this->get_field_id('image_uri'); ?>" value="<?php echo $image_uri; ?>"> |
| 88 |
<input type="button" value="<?php _e('Upload', 'virtue-toolkit'); ?>" class="button kad_custom_media_upload" id="kad_custom_image_uploader" /> |
| 89 |
</p> |
| 90 |
<p> |
| 91 |
<label for="<?php echo $this->get_field_id('image_link_open'); ?>"><?php _e('Image opens in', 'virtue-toolkit'); ?></label><br /> |
| 92 |
<select id="<?php echo $this->get_field_id('image_link_open'); ?>" name="<?php echo $this->get_field_name('image_link_open'); ?>"><?php echo implode('', $link_options_array);?></select> |
| 93 |
</p> |
| 94 |
<p> |
| 95 |
<label for="<?php echo $this->get_field_id('image_link'); ?>"><?php _e('Image Link (optional)', 'virtue-toolkit'); ?></label><br /> |
| 96 |
<input type="text" class="widefat kad_img_widget_link" name="<?php echo $this->get_field_name('image_link'); ?>" id="<?php echo $this->get_field_id('image_link'); ?>" value="<?php echo $image_link; ?>"> |
| 97 |
</p> |
| 98 |
<p> |
| 99 |
<label for="<?php echo $this->get_field_id('text'); ?>"><?php _e('Text/Caption (optional)', 'virtue-toolkit'); ?></label><br /> |
| 100 |
<textarea name="<?php echo $this->get_field_name('text'); ?>" id="<?php echo $this->get_field_id('text'); ?>" class="widefat" ><?php if(!empty($instance['text'])) echo $instance['text']; ?></textarea> |
| 101 |
</p> |
| 102 |
</div> |
| 103 |
<?php |
| 104 |
} |
| 105 |
} |
| 106 |
} |