[6768] | 1 | <?php |
---|
| 2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 3 | |
---|
[6782] | 4 | // Racourcis un texte et ajoute une ellipse |
---|
[9200] | 5 | function CR_cut_string($string, $limit) { |
---|
[6782] | 6 | include_once(CR_PATH . 'include/cutstring.class.php'); |
---|
[9200] | 7 | if (strlen(str_replace("\r\n", "\n", strip_tags($string))) > $limit) { |
---|
[6782] | 8 | $output = new HtmlCutString($string, $limit); |
---|
| 9 | return ($output->cut()).'...'; |
---|
[9200] | 10 | } else { |
---|
[6782] | 11 | return $string; |
---|
[6768] | 12 | } |
---|
| 13 | } |
---|
| 14 | |
---|
[9975] | 15 | // Recupère le nom d'un coucours à partir de l'id |
---|
[9200] | 16 | function get_contest_name($id) { |
---|
| 17 | $contest = pwg_query("SELECT name FROM " . CR_TABLE_1 . " WHERE id = " . $id . ";"); |
---|
| 18 | if (pwg_db_num_rows($contest)) { |
---|
| 19 | $contest = pwg_db_fetch_assoc($contest); |
---|
| 20 | return $contest['name']; |
---|
| 21 | } else { |
---|
[9745] | 22 | return false; |
---|
[6768] | 23 | } |
---|
| 24 | } |
---|
[9572] | 25 | |
---|
| 26 | // Nombre de jours entre deux dates |
---|
[9745] | 27 | function date_diff($date2, $date1) { |
---|
[9572] | 28 | return ceil((strtotime($date2)-strtotime($date1))/(3600*24)); |
---|
| 29 | } |
---|
| 30 | |
---|
[9975] | 31 | // Date passée |
---|
[9572] | 32 | function is_date_passed($date) { |
---|
| 33 | if (time() > strtotime($date)) { |
---|
| 34 | return true; |
---|
| 35 | } else { |
---|
| 36 | return false; |
---|
| 37 | } |
---|
| 38 | } |
---|
[9745] | 39 | |
---|
| 40 | // Calcul le status d'un concours |
---|
| 41 | function get_contest_status($date_begin, $date_end) { |
---|
| 42 | if (!is_date_passed($date_begin)) { |
---|
| 43 | $contest['status'] = 'pending'; |
---|
| 44 | $contest['days'] = l10n_dec('CR_%d_days_to_begin', 'CR_%d_days_to_begin', date_diff($date_begin,date('Y-m-d'))); |
---|
| 45 | } else if (is_date_passed($date_end)) { |
---|
| 46 | $contest['status'] = 'finished'; |
---|
| 47 | $contest['days'] = l10n('CR_finished'); |
---|
| 48 | } else { |
---|
| 49 | $contest['status'] = 'running'; |
---|
| 50 | $contest['days'] = l10n_dec('CR_%d_days_to_end', 'CR_%d_days_to_end', date_diff($date_end,date('Y-m-d'))); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | return $contest; |
---|
| 54 | } |
---|
[6768] | 55 | ?> |
---|