1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
<?php
namespace hji\geofarms\widgets;
use \hji\geofarms\GeoFarms;
use \hji\common\utils\Views;
class Map extends \WP_Widget {
private $view;
function __construct()
{
parent::__construct
(
'gf_display_map_widget',
'HJI ' . GeoFarms::NAME . ' Map',
array('description' => 'Easily display your ' . GeoFarms::NAME . ' map anywhere on your site!',)
);
$this->view = new Views(GeoFarms::$views);
}
function widget($args, $instance)
{
foreach($instance as $k => $v)
{
$instance[$k] = esc_attr($v);
}
echo $args['before_widget'];
if(!empty($instance['title']))
{
echo $args['before_title'] . apply_filters('widget_title', $instance['title']). $args['after_title'];
}
echo hjigf_display_map($instance['parent_display_only'], $instance['id']);
echo $args['after_widget'];
}
function form($instance)
{
$fields = array_merge(
$this->addField('title', $instance),
$this->addField('parent_display_only', $instance),
$this->addField('id', $instance)
);
$vars['field'] = $fields;
$vars['instance'] = $instance;
echo $this->view->render('widget-display-map-admin', $vars);
}
function addField($fieldName, $instance)
{
$field[$fieldName]['id'] = $this->get_field_id($fieldName);
$field[$fieldName]['name'] = $this->get_field_name($fieldName);
$field[$fieldName]['value'] = (isset($instance[$fieldName])) ? $instance[$fieldName] : false;
return $field;
}
function update($new, $old)
{
$values = array();
$values['title'] = $new['title'];
$values['parent_display_only'] = $new['parent_display_only'];
$values['id'] = $new['id'];
return $values;
}
}