source: extensions/ContestResults/include/cr_menubar.php

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