PluginProbe
wp-forecast / 9.6
wp-forecast v9.6
10.0 trunk 1.4 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3..5 3..8 3.0 3.1 3.2 3.3 3.4 3.6 All 86 releases
wp-forecast / class-wpf-widget.php

class-wpf-widget.php in wp-forecast 9.6, at class-wpf-widget.php

125 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class for the widget isntance of wp-forecast
4 *
5 * @package wp-forecast
6 */
7
8 if ( ! class_exists( 'Wpf_Widget' ) ) {
9 /**
10 * Class for the widget instance of wp-forecast
11 */
12 class Wpf_Widget extends WP_Widget {
13 /**
14 * Constructor.
15 */
16 public function __construct() {
17 $widget_ops = array(
18 'classname' => 'wp_forecast_widget',
19 'description' => 'WP Forecast Widget',
20 );
21 $control_ops = array(
22 'width' => 300,
23 'height' => 150,
24 );
25 // $this->WP_Widget('wp-forecast', 'WP Forecast',
26
27 // $widget_ops, $control_ops);
28 parent::__construct( 'wp-forecast', 'WP Forecast', $widget_ops, $control_ops );
29 }
30
31 /**
32 * Wdiget method.
33 *
34 * @param array $args the widget arguments.
35 * @param array $instance the widget instance.
36 */
37 public function widget( $args, $instance ) {
38 // get widget params from instance.
39 $title = $instance['title'];
40 $wpfcid = $instance['wpfcid'];
41
42 if ( trim( $wpfcid ) == '' ) {
43 $wpfcid = 'A';
44 }
45 // pass title to show function.
46 $args['title'] = $title;
47
48 if ( '?' == $wpfcid ) {
49 $wpf_vars = get_wpf_opts( 'A' );
50 } else {
51 $wpf_vars = get_wpf_opts( $wpfcid );
52 }
53
54 if ( ! empty( $language_override ) ) {
55 $wpf_vars['wpf_language'] = $language_override;
56 }
57 show( $wpfcid, $args, $wpf_vars );
58 }
59
60 /**
61 * Update the widget aprams.
62 *
63 * @param array $new_instance the new instance of the widget.
64 * @param array $old_instance the old instance of the widget.
65 */
66 public function update( $new_instance, $old_instance ) {
67 // update semaphor counter for loading wpf ajax script.
68
69 if ( $old_instance['wpfcid'] != $new_instance['wpfcid'] ) {
70 $semnow = get_option( 'wpf_sem_ajaxload' );
71
72 if ( '?' == $new_instance['wpfcid'] ) {
73 update_option( 'wpf_sem_ajaxload', $semnow + 1 );
74 } else {
75 update_option( 'wpf_sem_ajaxload', ( $semnow - 1 < 0 ? 0 : $semnow - 1 ) );
76 }
77 }
78 return $new_instance;
79 }
80
81 /**
82 * Form method to display the form.
83 *
84 * @param array $instance the widget instance.
85 */
86 public function form( $instance ) {
87 $count = wpf_get_option( 'wp-forecast-count' );
88
89 if ( function_exists( 'load_plugin_textdomain' ) ) {
90 load_plugin_textdomain( 'wp-forecast', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
91 }
92 $title = ( isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '' );
93 $wpfcid = ( isset( $instance['wpfcid'] ) ? esc_attr( $instance['wpfcid'] ) : '' );
94 // code for widget title form.
95 $out = '';
96 $out .= '<p><label for="' . $this->get_field_id( 'title' ) . '" >';
97 $out .= __( 'Title:', 'wp-forecast' );
98 $out .= '<input class="widefat" id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" type="text" value="' . $title . '" /></label></p>';
99 // print out widget selector.
100 $out .= '<p><label for ="' . $this->get_field_id( 'wpfcid' ) . '" >';
101 $out .= __( 'Available widgets', 'wp-forecast' );
102 $out .= "<select name='" . $this->get_field_name( 'wpfcid' ) . "' id='" . $this->get_field_id( 'wpfcid' ) . "' size='1' >";
103 // option for choose dialog.
104 $out .= "<option value='?' ";
105
106 if ( '?' == $wpfcid ) {
107 $out .= " selected='selected' ";
108 }
109 $out .= '>?</option>';
110
111 for ( $i = 0;$i < $count;$i++ ) {
112 $id = get_widget_id( $i );
113 $out .= "<option value='" . $id . "' ";
114
115 if ( $wpfcid == $id || ( '' == $wpfcid && 'A' == $id ) ) {
116 $out .= " selected='selected' ";
117 }
118 $out .= '>' . $id . '</option>';
119 }
120 $out .= '</select></label></p>';
121 echo wp_kses( $out, wpf_allowed_tags() );
122 }
123 }
124 }
125