-
Notifications
You must be signed in to change notification settings - Fork 0
/
last_track_widget.php
122 lines (101 loc) · 4.95 KB
/
last_track_widget.php
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
require_once "last_track_plugin.php";
require_once "last_track_request.php";
require_once "elements-library.php";
class LastTrackWidget {
public static function init() {
wp_register_sidebar_widget(LastTrackPlugin::PREFIX, __('Shoutcast last tracks',
LastTrackPlugin::domain()), array(__CLASS__, 'draw'));
wp_register_widget_control(LastTrackPlugin::PREFIX, __('Shoutcast last tracks',
LastTrackPlugin::domain()), array(__CLASS__, 'settings'));
add_action('wp_ajax_nopriv_' . LastTrackPlugin::PREFIX, array(__CLASS__, 'ajax'));
add_action('wp_ajax_' . LastTrackPlugin::PREFIX, array(__CLASS__, 'ajax'));
}
private static function echo_template() {
$connect_options = array(
'url' => LastTrackPlugin::get_option('url'),
'require_auth' => (LastTrackPlugin::get_option('require_auth') != ''),
'login' => LastTrackPlugin::get_option('login'),
'password' => LastTrackPlugin::get_option('password'),
'connect_timeout' => LastTrackPlugin::get_option('connect_timeout'),
'timeout' => LastTrackPlugin::get_option('timeout'),
'exclude' => LastTrackPlugin::get_option('exclude'),
'parse_format' => LastTrackPlugin::get_option('parse_format'));
$information = LastTrackPlugin::get_option('information');
$information_message = LastTrackPlugin::get_option('information_message');
$current_song = LastTrackPlugin::get_option('current_song');
$last_songs = LastTrackPlugin::get_option('last_songs');
$count_songs = LastTrackPlugin::get_option('count_songs');
$href = LastTrackPlugin::get_option('href');
$lt_request = new LastTrackRequest($connect_options);
$songs = $lt_request->get_last_songs($count_songs);
include 'templates/widget_page.php';
}
private static function get_template() {
ob_start();
LastTrackWidget::echo_template();
$html = ob_get_contents();
ob_end_clean();
return $html;
}
public static function draw($args) {
extract($args);
echo $before_widget;
echo $before_title;
echo LastTrackPlugin::get_option('title');
echo $after_title;
LastTrackWidget::echo_template();
wp_enqueue_script("jquery");
wp_enqueue_script(LastTrackPlugin::get_name_with_prefix('widget_js'),
plugins_url('templates/js/widget.js', __FILE__), array('jquery'));
wp_enqueue_style(LastTrackPlugin::get_name_with_prefix('widget_css'),
plugins_url('templates/stylesheets/widget.css', __FILE__));
echo $after_widget;
}
public static function settings() {
$post_options = array(LastTrackPlugin::get_name_with_prefix('information'),
LastTrackPlugin::get_name_with_prefix('information_message'),
LastTrackPlugin::get_name_with_prefix('title'),
LastTrackPlugin::get_name_with_prefix('current_song'),
LastTrackPlugin::get_name_with_prefix('last_songs'),
LastTrackPlugin::get_name_with_prefix('count_songs'),
LastTrackPlugin::get_name_with_prefix('href'));
foreach($post_options as $option) {
if (!empty($_REQUEST[$option])) {
update_option($option, $_REQUEST[$option]);
}
}
$options = array(
LastTrackPlugin::INFORMATION_NONE => __('None', LastTrackPlugin::domain()),
LastTrackPlugin::INFORMATION_MESSAGE => __('Specified message',
LastTrackPlugin::domain()),
LastTrackPlugin::INFORMATION_FULL => __('Full', LastTrackPlugin::domain()));
echo ElementsLibrary::draw_label(__('Error notification', LastTrackPlugin::domain()));
echo ElementsLibrary::draw_select(LastTrackPlugin::get_name_with_prefix('information'),
$options, LastTrackPlugin::get_option('information'));
echo ElementsLibrary::draw_label(__('Error message', LastTrackPlugin::domain()));
echo ElementsLibrary::draw_text(LastTrackPlugin::get_name_with_prefix('information_message'),
LastTrackPlugin::get_option('information_message'));
echo ElementsLibrary::draw_label(__('Title', LastTrackPlugin::domain()));
echo ElementsLibrary::draw_text(LastTrackPlugin::get_name_with_prefix('title'),
LastTrackPlugin::get_option('title'));
echo ElementsLibrary::draw_label(__('Current track title', LastTrackPlugin::domain()));
echo ElementsLibrary::draw_text(LastTrackPlugin::get_name_with_prefix('current_song'),
LastTrackPlugin::get_option('current_song'));
echo ElementsLibrary::draw_label(__('Last tracks title', LastTrackPlugin::domain()));
echo ElementsLibrary::draw_text(LastTrackPlugin::get_name_with_prefix('last_songs'),
LastTrackPlugin::get_option('last_songs'));
echo ElementsLibrary::draw_label(__('Count last songs', LastTrackPlugin::domain()));
echo ElementsLibrary::draw_text(LastTrackPlugin::get_name_with_prefix('count_songs'),
LastTrackPlugin::get_option('count_songs'));
echo ElementsLibrary::draw_label(__('Link to radio', LastTrackPlugin::domain()));
echo ElementsLibrary::draw_text(LastTrackPlugin::get_name_with_prefix('href'),
LastTrackPlugin::get_option('href'));
}
public static function ajax() {
$ajax = array(
'title' => LastTrackPlugin::get_option('title'),
'content' => LastTrackWidget::get_template());
exit(json_encode($ajax));
}
}