This repository has been archived by the owner on Nov 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nowplaying.php
198 lines (155 loc) · 6 KB
/
nowplaying.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
/*
Plugin Name: Now Playing
Plugin URI: http://github.com/jaredmoody/wp_now_playing
Description: Show the music you're playhing in wordpress
Version: 0.1
Author: Jared Moody
Author URI: http://jaredmoody.com
Copyright 2009 Jared Moody (email : [email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
$now_playing_version = "0.1";
function now_playing_install()
{
global $wpdb;
global $now_playing_version;
$table_name = $wpdb->prefix . "songs";
if($wpdb->get_var("show tables like '$table_name'") != $table_name)
{
$sql = "CREATE TABLE " . $table_name . " (
`id` int(11) NOT NULL auto_increment,
`img` varchar(100) default NULL,
`title` varchar(75) default NULL,
`album` varchar(50) default NULL,
`artist` varchar(50) default NULL,
`url` varchar(255) default NULL,
`user_id` int(11) default NULL,
PRIMARY KEY (`id`)
);";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
add_option("now_playing_version", $now_playing_version);
}
}
// shows the current album
function now_playing($username)
{
global $wpdb;
$users_table = $wpdb->prefix . "users";
$songs_table = $wpdb->prefix . "songs";
$result = $wpdb->get_results("SELECT $songs_table.* FROM $songs_table INNER JOIN $users_table ON $songs_table.user_id = $users_table.id WHERE user_login = '$username' ORDER BY $songs_table.id DESC LIMIT 1");
return $result[0];
}
function now_playing_config_page()
{
//add_menu_page("Now Playing", "Now Playing", "Author", __FILE__, "now_playing_admin_menu");
// Add a new submenu under Options:
//add_options_page('Test Options', 'Test Options', 8, 'testoptions', 'mt_options_page');
// Add a new submenu under Manage:
//add_management_page('Test Manage', 'Test Manage', 8, 'testmanage', 'mt_manage_page');
// Add a new top-level menu (ill-advised):
//add_menu_page("Now Playing", "Now Playing", 8, __FILE__, 'now_playing_admin_menu');
// Add a submenu to the custom top-level menu:
add_submenu_page('options-general.php', 'Now Playing', 'Now Playing', 8, "now_playing_configuration", "now_playing_configuration" );
//add_submenu_page(parent, page_title, menu_title, access_level/capability, file, [function]);
// Add a second submenu to the custom top-level menu:
//add_submenu_page(__FILE__, 'Test Sublevel 2', 'Test Sublevel 2', 8, 'sub-page2', 'mt_sublevel_page2');
}
function now_playing_admin_menu()
{
global $wpdb;
$users_table = $wpdb->prefix . "users";
$users = $wpdb->get_results("SELECT display_name FROM $users_table");
print_r($users);
echo "<div class='wrap'>";
echo "<h2>Now Playing</h2> Update now playing for: <select>";
foreach($users as $user)
{
echo("<option>".$user->display_name."<option>");
}
echo "</select>";
}
function now_playing_configuration()
{
global $wpdb;
$users_table = $wpdb->prefix . "users";
?>
<div class="wrap">
<h2>Now Playing Configuration</h2>
<form method="post" action="options.php">
<table class="form-table">
<tr>
<td colspan="2">
<h3>Amazon API Keys</h3>
The Now Playing plugin uses the Amazon API to retrieve album art. You will need an amazon web services account
which you can get at <a href="http://aws.amazon.com/">http://aws.amazon.com/</a>
</td>
</tr>
<tr valign="top">
<th scope="row">Amazon API Public Key</th>
<td><input type="text" name="now_playing_amzn_public" value="<?php echo get_option('now_playing_amzn_public'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Amazon API Private Key</th>
<td><input type="text" name="now_playing_amzn_private" value="<?php echo get_option('now_playing_amzn_private'); ?>" /></td>
</tr>
<tr>
<td colspan="2">
<h3>Amazon Associates Tag</h3>
If you have an amazon affiliate account, you can enter the tag below. This will be used in the links to the album on amazon and any purchases made will credit to your affiliates account.
You can support this plugin by leaving this field blank, which defaults to a tag of the author.
You can sign up for an amazon affiliate account at <a href="http://affiliate-program.amazon.com/">http://affiliate-program.amazon.com/</a>
</td>
</tr>
<tr valign="top">
<th scope="row">Amazon Associates Tag (optional)</th>
<td><input type="text" name="now_playing_amzn_tag" value="<?php echo get_option('now_playing_amzn_tag'); ?>" /></td>
</tr>
<tr valign="top">
<td><h3>Script API Keys</h3></td>
</tr>
<?php
$result = $wpdb->get_results("SELECT display_name, user_pass FROM $users_table");
foreach($result as $user )
{
?>
<tr valign="top">
<th scope="row"><?php echo $user->display_name ?></th>
<td><?php echo md5($user->user_pass); ?></td>
</tr>
<?php
}
?>
</table>
<?php settings_fields( 'now_playing' ); ?>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
</p>
</form>
</div>
<?php
}
function register_settings()
{
register_setting( 'now_playing', 'now_playing_amzn_public' );
register_setting( 'now_playing', 'now_playing_amzn_private' );
register_setting( 'now_playing', 'now_playing_amzn_tag' );
}
//
// HOOKS
//
register_activation_hook(__FILE__,'now_playing_install');
add_action('admin_menu', 'now_playing_config_page');
add_action('admin_init', 'register_settings' );
?>