1 | <?php |
---|
2 | |
---|
3 | /* ----------------------------------------------------------------------------- |
---|
4 | class name: public_integration |
---|
5 | class version: 1.0 |
---|
6 | date: 2007-10-31 |
---|
7 | ------------------------------------------------------------------------------ |
---|
8 | author: grum at grum.dnsalias.com |
---|
9 | << May the Little SpaceFrog be with you >> |
---|
10 | ------------------------------------------------------------------------------ |
---|
11 | |
---|
12 | this class provides base functions to manage an integration into main index |
---|
13 | page |
---|
14 | the class use plugin MenuBarManager function if installed |
---|
15 | |
---|
16 | - constructor public_integration($section) |
---|
17 | - (public) function init_events() |
---|
18 | - (public) function set_callback_page_function($value) |
---|
19 | - (public) function set_callback_init_menu_function($value) |
---|
20 | - (public) function set_menu_tpl($tpl_code) |
---|
21 | - (public) function set_menu_list($list) |
---|
22 | - (public) function set_menu_title($title) |
---|
23 | - (public) function set_lnk_admin_add($text, $link) |
---|
24 | - (public) function set_lnk_admin_edit($text, $link) |
---|
25 | - (private) function update_menubar() |
---|
26 | - (private) function init_section() |
---|
27 | - (private) function call_page() |
---|
28 | |
---|
29 | use init_events() function to initialize needed triggers for updating menubar |
---|
30 | use set_menu_tpl() function to initialize the template of menu |
---|
31 | use set_menu_title() function to initialize the title of menu |
---|
32 | use set_menu_list() function to initialize the elements of menu (see function for use) |
---|
33 | use set_lnk_admin_add() and set_lnk_admin_edit() functions for displaying specific admin links |
---|
34 | |
---|
35 | the "callback_page_function" is called everytime a specific page is displayed |
---|
36 | the "callback_init_menu_function" is called everytime the menu is made (allows |
---|
37 | for example to prepare menu's title and list using user's language) |
---|
38 | |
---|
39 | ----------------------------------------------------------------------------- */ |
---|
40 | |
---|
41 | class public_integration |
---|
42 | { |
---|
43 | var $menu_tpl; //template definition for the menu |
---|
44 | var $menu_list; //an array of arrays array(array('text' => '', 'id' => '', 'link' => ''), array... ) |
---|
45 | var $menu_title; //menu's title |
---|
46 | var $lnk_admin_add; //if set array('text'=>'', 'link'=>''), add a link "add" to the menu |
---|
47 | var $lnk_admin_edit; //if set array('text'=>'', 'link'=>''), add a link "edit" to the menu's elements |
---|
48 | var $section; //section applied to the page viewed |
---|
49 | var $callback_page_function; //called function to display page |
---|
50 | var $callback_init_menu_function; //called function to initialize menu |
---|
51 | |
---|
52 | function public_integration($section) |
---|
53 | { |
---|
54 | $this->menu_tpl=""; |
---|
55 | $this->menu_list=array(); |
---|
56 | $this->menu_title=""; |
---|
57 | $this->lnk_admin_add=array(); |
---|
58 | $this->lnk_admin_edit=array(); |
---|
59 | $this->section=$section; |
---|
60 | $this->callback_page_function=''; |
---|
61 | $this->callback_init_menu_function=''; |
---|
62 | } |
---|
63 | |
---|
64 | //initialize events to manage menu & page integration |
---|
65 | function init_events() |
---|
66 | { |
---|
67 | add_event_handler('loc_begin_menubar', array(&$this, 'init_smarty')); |
---|
68 | add_event_handler('loc_end_menubar', array(&$this, 'update_menubar')); |
---|
69 | add_event_handler('loc_end_section_init', array(&$this, 'init_section')); |
---|
70 | add_event_handler('loc_end_index', array(&$this, 'call_page')); |
---|
71 | } |
---|
72 | |
---|
73 | function set_callback_page_function($value) |
---|
74 | { |
---|
75 | $this->callback_page_function=$value; |
---|
76 | } |
---|
77 | |
---|
78 | function set_callback_init_menu_function($value) |
---|
79 | { |
---|
80 | $this->callback_init_menu_function=$value; |
---|
81 | } |
---|
82 | |
---|
83 | // set template definition for menu |
---|
84 | function set_menu_tpl($tpl_code) |
---|
85 | { |
---|
86 | $this->menu_tpl = $tpl_code; |
---|
87 | } |
---|
88 | |
---|
89 | //set menu list |
---|
90 | function set_menu_list($list) |
---|
91 | { |
---|
92 | $this->menu_list = $list; |
---|
93 | } |
---|
94 | |
---|
95 | //set menu title |
---|
96 | function set_menu_title($title) |
---|
97 | { |
---|
98 | $this->menu_title = $title; |
---|
99 | } |
---|
100 | |
---|
101 | //set 'add' link to menu |
---|
102 | function set_lnk_admin_add($text, $link) |
---|
103 | { |
---|
104 | $this->lnk_admin_add = array('text' => $text, 'link' => $link); |
---|
105 | } |
---|
106 | |
---|
107 | //set 'edit' link to menu |
---|
108 | function set_lnk_admin_edit($text, $link) |
---|
109 | { |
---|
110 | $this->lnk_admin_edit = array('text' => $text, 'link' => $link); |
---|
111 | } |
---|
112 | |
---|
113 | function init_smarty() |
---|
114 | { |
---|
115 | global $template; |
---|
116 | |
---|
117 | $template->smarty->register_prefilter(array(&$this, 'modify_tpl')); |
---|
118 | } |
---|
119 | |
---|
120 | function modify_tpl($tpl_source, &$smarty) |
---|
121 | { |
---|
122 | return(str_replace('<div id="menubar">', '<div id="menubar">(test3)'.$this->menu_tpl, $tpl_source)); |
---|
123 | } |
---|
124 | |
---|
125 | /* |
---|
126 | Update PWG menubar |
---|
127 | - add a MyPolls block |
---|
128 | - add a MyPolls menu inside |
---|
129 | */ |
---|
130 | function update_menubar() |
---|
131 | { |
---|
132 | global $template; |
---|
133 | |
---|
134 | @call_user_func($this->callback_init_menu_function); |
---|
135 | |
---|
136 | //echo "update_menubar****".$this->menu_tpl."****".$this->menu_title."****".count($this->menu_list)."****"; |
---|
137 | //do not do nothing because nothing to do |
---|
138 | if((($this->menu_tpl=="") || |
---|
139 | (count($this->menu_list)==0) || |
---|
140 | ($this->menu_title=="") |
---|
141 | ) and !is_admin()) |
---|
142 | { |
---|
143 | return(false); |
---|
144 | } |
---|
145 | |
---|
146 | $template_datas=array(); |
---|
147 | $template_datas['links']=array(); |
---|
148 | $template_datas['TITLE']='toto'.$this->menu_title; |
---|
149 | |
---|
150 | if(is_admin() && (count($this->lnk_admin_add)>0)) |
---|
151 | { |
---|
152 | $template_datas['links'][]=array( |
---|
153 | 'LABEL' => "<i>".$this->lnk_admin_add['text']."</i>", |
---|
154 | 'URL' => $this->lnk_admin_add['link'] |
---|
155 | ); |
---|
156 | } |
---|
157 | |
---|
158 | foreach($this->menu_list as $key => $val) |
---|
159 | { |
---|
160 | if(is_admin() && (count($this->lnk_admin_edit)>0)) |
---|
161 | { $lnk_edit = "</a> --- <a href='".$this->lnk_admin_edit['link']. |
---|
162 | $val['id']."'>[".$this->lnk_admin_edit['text']."]"; } |
---|
163 | else |
---|
164 | { $lnk_edit = ''; } |
---|
165 | |
---|
166 | $template_datas['links'][]=array( |
---|
167 | 'LABEL' => $val['text'].$lnk_edit, |
---|
168 | 'URL' => $val['link'] |
---|
169 | ); |
---|
170 | } |
---|
171 | |
---|
172 | $template->assign("datas", $template_datas); |
---|
173 | } |
---|
174 | |
---|
175 | /* |
---|
176 | init section |
---|
177 | */ |
---|
178 | function init_section() |
---|
179 | { |
---|
180 | global $tokens, $page; |
---|
181 | |
---|
182 | if ($tokens[0] == $this->section) |
---|
183 | { $page['section'] = $this->section; } |
---|
184 | } |
---|
185 | |
---|
186 | /* |
---|
187 | loads a page |
---|
188 | */ |
---|
189 | function call_page() |
---|
190 | { |
---|
191 | global $page, $user; |
---|
192 | |
---|
193 | if($page['section'] == $this->section) |
---|
194 | { |
---|
195 | @call_user_func($this->callback_page_function); |
---|
196 | } |
---|
197 | } |
---|
198 | |
---|
199 | } //class public_integration |
---|
200 | |
---|
201 | |
---|
202 | ?> |
---|