1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // Trigger |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | global $conf; |
---|
8 | $config = unserialize($conf['ContestResults']); |
---|
9 | if($config['menubar_mode']['block']) |
---|
10 | add_event_handler('blockmanager_register_blocks', 'CR_register_menubar_blocks'); |
---|
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 |
---|
31 | if(($block = $menu->get_block('mbContestResults')) != null){ |
---|
32 | $data = array(); |
---|
33 | |
---|
34 | $query = "SELECT id, name, visible, status, date_begin, date_end |
---|
35 | FROM " . CR_TABLE_1 . " |
---|
36 | ORDER BY date_begin DESC |
---|
37 | LIMIT " . $config['menubar_block']['number'] . " OFFSET 0;"; |
---|
38 | $result = pwg_query($query); |
---|
39 | |
---|
40 | while($contest = pwg_db_fetch_assoc($result)){ |
---|
41 | if($contest['visible'] OR is_admin()){ |
---|
42 | array_push($data, array( |
---|
43 | 'URL' => CR_PUBLIC . $contest['id'] . '-' . str2url(trigger_event('render_CR_content', $contest['name'])), |
---|
44 | 'LABEL' => trigger_event('render_CR_content', $contest['name']), |
---|
45 | 'DATE' => format_date($contest['date_begin']) . ' - ' . format_date($contest['date_end']), |
---|
46 | 'STATUS' => $contest['status'] |
---|
47 | )); |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | if(!empty($data)){ |
---|
52 | $template->set_template_dir(CR_PATH . 'template/'); |
---|
53 | $block->set_title('<a href="' . CR_PUBLIC . '">' . l10n('Contests') . '</a>'); |
---|
54 | $block->template = 'cr_menubar.tpl'; |
---|
55 | $block->data = $data; |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | // Block Menu |
---|
60 | if($config['menubar_mode']['link'] AND $config['menubar_link']['menu'] AND ($block = $menu->get_block('mbMenu')) != null){ |
---|
61 | array_push($block->data, array( |
---|
62 | 'URL' => CR_PUBLIC, |
---|
63 | 'TITLE' => l10n('Contests'), |
---|
64 | 'NAME' => l10n('Contests') |
---|
65 | )); |
---|
66 | } |
---|
67 | |
---|
68 | // Block Specials |
---|
69 | if($config['menubar_mode']['link'] AND $config['menubar_link']['specials'] AND ($block = $menu->get_block('mbSpecials')) != null){ |
---|
70 | array_push($block->data, array( |
---|
71 | 'URL' => CR_PUBLIC, |
---|
72 | 'TITLE' => l10n('Contests'), |
---|
73 | 'NAME' => l10n('Contests') |
---|
74 | )); |
---|
75 | } |
---|
76 | } |
---|
77 | ?> |
---|