Cambiar periodo actualización PHP lista musical
Publicado por Hugo (5 intervenciones) el 07/02/2019 01:00:06
Buenas, he encontrado el código PHP que adjunto aquí debajo, y me gustaría saber si se podría cambiar para que la actualización de la lista fuera semanal, y como tendría que hacerlo.
Además si se pudiera que las votaciones de la lista se cerrarán en un momento determinado que sería el Domingo a las 00h estaría súper guay.
Si hiciera falta algún otro archivo, lo busco y lo adjunto sin problema.
¡Muchísimas gracias de antemano!
Además si se pudiera que las votaciones de la lista se cerrarán en un momento determinado que sería el Domingo a las 00h estaría súper guay.
Si hiciera falta algún otro archivo, lo busco y lo adjunto sin problema.
¡Muchísimas gracias de antemano!
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
<?php
include dirname(__FILE__) . '/widget.php';
add_action('wp_head', 'pluginname_ajaxurl');
function topcharts_init() {
global $wpdb;
$wpdb->query("CREATE TABLE IF NOT EXISTS `wp_topcharts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`post_id` int(11) NOT NULL,
`vote` tinyint(4) NOT NULL DEFAULT '1',
`datetime` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;");
}
add_action('init', 'topcharts_init');
function pluginname_ajaxurl() {
?>
<script type="text/javascript">
var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
</script>
<?php
}
/**
*
*/
function topcharts_wp_enqueue_scripts() {
wp_register_style('topcharts', plugins_url('/css/topcharts.css', __FILE__));
wp_enqueue_style('topcharts');
wp_enqueue_script('topcharts', plugins_url('/js/topcharts.js', __FILE__), array('jquery'));
}
add_action('wp_enqueue_scripts', 'topcharts_wp_enqueue_scripts');
// returns the content of $GLOBALS['post']
// if the page is called 'debug'
function topcharts_the_content($content) {
// global $post;
// otherwise returns the database content
// $vote_button = '<a href="">Vote</a>';
return $content; // . is_user_logged_in();
}
add_filter('the_content', 'topcharts_the_content');
function DisplayVotes($postID = null) {
if (is_user_logged_in()) {
$user_id = get_current_user_id();
print '<a href="javascript:void(0);" class="tc-vote-btn '.(VotesCountOfUser($postID, $user_id) > 0 ? 'voted' : '').'" data-postid="' . $postID . '"><img src="http://www.unsignedtopcharts.com/wp-content/uploads/2014/11/vot-icon.png" /></a>';
} else {
print '<a href="' . wp_login_url() . '"><img src="http://www.unsignedtopcharts.com/wp-content/uploads/2014/11/vot-icon.png" /></a>';
}
}
function VotesCount($postID = null) {
global $wpdb;
$datetime_from = date('Y-m-01 00:00:00');
$datetime_to = date('Y-m-d h:i:s');
return $wpdb->get_var("
SELECT COUNT(*) as total FROM wp_topcharts
WHERE `datetime` >= '{$datetime_from}' AND `datetime` <= '{$datetime_to}'
AND post_id = '{$postID}'");
}
function VotesCountOfUser($postID = null, $userID) {
global $wpdb;
$datetime_from = date('Y-m-01 00:00:00');
$datetime_to = date('Y-m-d h:i:s');
return $wpdb->get_var("
SELECT COUNT(*) as total FROM wp_topcharts
WHERE `datetime` >= '{$datetime_from}' AND `datetime` <= '{$datetime_to}'
AND post_id = '{$postID}' AND user_id = '{$userID}'");
}
function topcharts_top10($lastmonth = false) {
global $wpdb;
$datetime_from = date('Y-m-01 00:00:00');
$datetime_to = date('Y-m-d h:i:s');
// last month
if ($lastmonth) {
$datetime_to = date("Y-m-d 23:59:59", strtotime('last day of last month'));
$datetime_from = date("Y-m-d 00:00:00", strtotime('first day of last month'));
}
return $wpdb->get_results("
SELECT *, COUNT(*) FROM wp_topcharts tc
LEFT JOIN wp_posts p ON tc.`post_id` = p.`ID`
WHERE `datetime` >= '{$datetime_from}' AND `datetime` <= '{$datetime_to}'
GROUP BY post_id
ORDER BY COUNT(*) DESC
LIMIT 10");
}
function topcharts_vote_cast_ajax() {
global $wpdb;
$user_id = get_current_user_id();
$post_id = $_POST['postID'];
// check if user has already voted for this post in this month
if(VotesCountOfUser($post_id, $user_id) > 0) {
$response = array(
'success' => false,
'message' => 'You already voted for this'
);
}
else {
$data = array(
'user_id' => get_current_user_id(),
'post_id' => $_POST['postID'],
'vote' => 1,
'datetime' => date('Y-m-d h:i:s'),
);
$vote_id = $wpdb->insert('wp_topcharts', $data);
$response = array(
'success' => true,
'vote_id' => $vote_id,
'message' => 'Thank you for your vote.'
);
}
die(json_encode($response));
}
add_action('wp_ajax_topcharts_vote_cast', 'topcharts_vote_cast_ajax');
add_action('wp_ajax_nopriv_topcharts_vote_cast', 'topcharts_vote_cast_ajax');
function topcharts_this_months_top_10($atts) {
$top_posts = topcharts_top10();
$html = '';
foreach ($top_posts as $index => $top_post) {
$the_permalink = get_permalink($top_post->ID);
$html .= '
<div class="topcharts-item" data-url="' . $the_permalink . '">
<div class="topcharts-item-number">' . ($index + 1) . '</div>
<div class="topcharts-item-thumbnail">' . get_the_post_thumbnail($top_post->ID, 'post-thumbnail', '') . '</div>
<div class="topcharts-item-author-title">
<div class="topcharts-item-title">' . $top_post->post_title . '</div>
<div class="topcharts-item-author">' . get_the_author_meta('display_name', $top_post->post_author) . '</div>
</div>
<div style="clear: both"></div>
</div>';
}
the_post_thumbnail($html);
return $html;
}
add_shortcode('this_months_top_10', 'topcharts_this_months_top_10');
function topcharts_last_months_top_10($atts) {
$top_posts = topcharts_top10(true);
$html = '';
foreach ($top_posts as $index => $top_post) {
$the_permalink = get_permalink($top_post->ID);
$html .= '
<div class="topcharts-item" data-url="' . $the_permalink . '">
<div class="topcharts-item-number">' . ($index + 1) . '</div>
<div class="topcharts-item-thumbnail">' . get_the_post_thumbnail($top_post->ID, 'post-thumbnail', '') . '</div>
<div class="topcharts-item-author-title">
<div class="topcharts-item-title">' . $top_post->post_title . '</div>
<div class="topcharts-item-author">' . get_the_author_meta('display_name', $top_post->post_author) . '</div>
</div>
<div style="clear: both"></div>
</div>';
}
the_post_thumbnail($html);
return $html;
}
add_shortcode('last_months_top_10', 'topcharts_last_months_top_10');
Valora esta pregunta


0