1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // Triggers |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | $config = unserialize($conf['ContestResults']); |
---|
8 | if ($config['menubar_mode']['block']) { |
---|
9 | add_event_handler('blockmanager_register_blocks', 'CR_register_menubar_blocks'); |
---|
10 | } |
---|
11 | add_event_handler('blockmanager_apply', 'CR_menubar_apply'); |
---|
12 | |
---|
13 | // +-----------------------------------------------------------------------+ |
---|
14 | // Ajouter un block |
---|
15 | // +-----------------------------------------------------------------------+ |
---|
16 | function CR_register_menubar_blocks($menu_ref_arr) { |
---|
17 | $menu = &$menu_ref_arr[0]; |
---|
18 | if ($menu->get_id() != 'menubar') { return; } |
---|
19 | $menu->register_block(new RegisteredBlock('mbContestResults', l10n('Contests'), 'ContestResults')); |
---|
20 | } |
---|
21 | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | // Remplis les block |
---|
24 | // +-----------------------------------------------------------------------+ |
---|
25 | function CR_menubar_apply($menu_ref_arr) { |
---|
26 | global $template, $conf; |
---|
27 | $config = unserialize($conf['ContestResults']); |
---|
28 | $menu = &$menu_ref_arr[0]; |
---|
29 | |
---|
30 | // Block Contest - un nouveau bloc dans le menu |
---|
31 | if (($block = $menu->get_block('mbContestResults')) != null) { |
---|
32 | $data = array(); |
---|
33 | |
---|
34 | // on récupère les concours |
---|
35 | $contests = pwg_query("SELECT |
---|
36 | id, |
---|
37 | name, |
---|
38 | visible, |
---|
39 | date_begin, |
---|
40 | date_end |
---|
41 | FROM " . CR_TABLE_1 . " |
---|
42 | ORDER BY date_begin DESC;"); |
---|
43 | |
---|
44 | $m = 0; // compteur pour limiter le nombre de concours affichés |
---|
45 | while($contest = pwg_db_fetch_assoc($contests)){ |
---|
46 | if (($contest['visible'] OR is_admin()) AND $m < $config['menubar_block']['number']) { |
---|
47 | array_push($data, array( |
---|
48 | 'URL' => CR_PUBLIC . $contest['id'] . '-' . str2url(trigger_event('render_CR_content', $contest['name'])), |
---|
49 | 'LABEL' => trigger_event('render_CR_content', $contest['name']), |
---|
50 | 'DATE' => format_date($contest['date_begin']) . ' - ' . format_date($contest['date_end']), |
---|
51 | 'VISIBLE' => $contest['visible'], |
---|
52 | 'FINISHED' => is_date_passed($contest['date_end']), |
---|
53 | 'DAYS' => DateDiff($contest['date_end'],date('Y-m-d')), |
---|
54 | )); |
---|
55 | } |
---|
56 | $m++; |
---|
57 | } |
---|
58 | |
---|
59 | // Finalement on rempli le bloc avec les concours |
---|
60 | if (!empty($data)) { |
---|
61 | $template->set_template_dir(CR_PATH . 'template/'); |
---|
62 | $block->set_title('<a href="' . CR_PUBLIC . '">' . l10n('Contests') . '</a>'); |
---|
63 | $block->template = 'cr_menubar.tpl'; |
---|
64 | $block->data = $data; |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | // Block Menu - ajout d'un lien dans le bloc Menu |
---|
69 | if ($config['menubar_mode']['link'] AND $config['menubar_link']['menu'] AND ($block = $menu->get_block('mbMenu')) != null) { |
---|
70 | array_push($block->data, array( |
---|
71 | 'URL' => CR_PUBLIC, |
---|
72 | 'TITLE' => l10n('Contests'), |
---|
73 | 'NAME' => l10n('Contests') |
---|
74 | )); |
---|
75 | } |
---|
76 | |
---|
77 | // Block Specials - ajout d'un lien dans le bloc Specials |
---|
78 | if($config['menubar_mode']['link'] AND $config['menubar_link']['specials'] AND ($block = $menu->get_block('mbSpecials')) != null){ |
---|
79 | array_push($block->data, array( |
---|
80 | 'URL' => CR_PUBLIC, |
---|
81 | 'TITLE' => l10n('Contests'), |
---|
82 | 'NAME' => l10n('Contests') |
---|
83 | )); |
---|
84 | } |
---|
85 | } |
---|
86 | ?> |
---|