function wppa_allow_user_uploads() { global $wpdb; // Get the limits $limits = wppa_get_user_upload_limits(); $temp = explode('/', $limits); $limit_max = isset($temp[0]) ? $temp[0] : '0'; $limit_time = isset($temp[1]) ? $temp[1] : '0'; if (!$limit_max) { return '-1'; } // Unlimited max $user = wppa_get_user('login'); if (!$limit_time) { // For ever $curcount = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_PHOTOS . "` WHERE `owner` = %s", $user)); wppa_dbg_q('Q326'); } else { // Time criterium in place $timnow = time(); $timthen = $timnow - $limit_time; $curcount = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_PHOTOS . "` WHERE `owner` = %s AND `timestamp` > %s", $user, $timthen)); wppa_dbg_q('Q327'); } if ($curcount >= $limit_max) { $result = '0'; } else { $result = $limit_max - $curcount; } return $result; }
function wppa_time_to_wait_html($album, $user = false) { global $wpdb; if (!$album && !$user) { return '0'; } if ($user) { $limits = wppa_get_user_upload_limits(); } else { $limits = $wpdb->get_var($wpdb->prepare("SELECT `upload_limit` FROM `" . WPPA_ALBUMS . "` WHERE `id` = %s", $album)); } wppa_dbg_q('Q62'); $temp = explode('/', $limits); $limit_max = isset($temp[0]) ? $temp[0] : '0'; $limit_time = isset($temp[1]) ? $temp[1] : '0'; $result = ''; if (!$limit_max || !$limit_time) { return $result; } if ($user) { $owner = wppa_get_user('login'); $last_upload_time = $wpdb->get_var($wpdb->prepare("SELECT `timestamp` FROM `" . WPPA_PHOTOS . "` WHERE `owner` = %s ORDER BY `timestamp` DESC LIMIT 1", $owner)); } else { $last_upload_time = $wpdb->get_var($wpdb->prepare("SELECT `timestamp` FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s ORDER BY `timestamp` DESC LIMIT 1", $album)); } wppa_dbg_q('Q63'); $timnow = time(); // For simplicity: a year is 364 days = 52 weeks, we skip the months $seconds = array('min' => '60', 'hour' => '3600', 'day' => '86400', 'week' => '604800', 'month' => '2592000', 'year' => '31449600'); $deltatim = $last_upload_time + $limit_time - $timnow; $temp = $deltatim; // $months = floor( $temp / $seconds['month'] ); // $temp = $temp % $seconds['month']; $weeks = floor($temp / $seconds['week']); $temp = $temp % $seconds['week']; $days = floor($temp / $seconds['day']); $temp = $temp % $seconds['day']; $hours = floor($temp / $seconds['hour']); $temp = $temp % $seconds['hour']; $mins = floor($temp / $seconds['min']); $secs = $temp % $seconds['min']; $switch = false; $string = __('You can upload after', 'wp-photo-album-plus') . ' '; // if ( $months ) { $string .= $months.' '.'months'.', '; $switch = true; } if ($weeks || $switch) { $string .= $weeks . ' ' . __('weeks', 'wp-photo-album-plus') . ', '; $switch = true; } if ($days || $switch) { $string .= $days . ' ' . __('days', 'wp-photo-album-plus') . ', '; $switch = true; } if ($hours || $switch) { $string .= $hours . ' ' . __('hours', 'wp-photo-album-plus') . ', '; $switch = true; } if ($mins || $switch) { $string .= $mins . ' ' . __('minutes', 'wp-photo-album-plus') . ' ' . __('and', 'wp-photo-album-plus') . ' '; $switch = true; } if ($switch) { $string .= $secs . ' ' . __('seconds', 'wp-photo-album-plus'); } $string .= '.'; $result = '<span style="font-size:9px;"> ' . $string . '</span>'; return $result; }