1 | <?php |
---|
2 | |
---|
3 | |
---|
4 | class Adultcontent |
---|
5 | { |
---|
6 | var $plugin_name, $plugin_path; |
---|
7 | var $idgroups_user = array(); |
---|
8 | var $idgroups_ad_c = array();// 0=+18 1=16 2=nothing |
---|
9 | function Adultcontent($plugin_name, $plugin_path) |
---|
10 | { |
---|
11 | // Args |
---|
12 | $this->plugin_name = $plugin_name; |
---|
13 | $this->plugin_path = $plugin_path; |
---|
14 | } |
---|
15 | function fill_idgroups_user() |
---|
16 | { |
---|
17 | global $user; |
---|
18 | |
---|
19 | $query = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id = ' . $user['id'] . ';'; |
---|
20 | $result = pwg_query($query); |
---|
21 | while ($row = mysql_fetch_assoc($result)) |
---|
22 | { |
---|
23 | array_push($this->idgroups_user, $row['group_id']); |
---|
24 | } |
---|
25 | } |
---|
26 | function fill_idgroups_ad_c() |
---|
27 | { |
---|
28 | global $user; |
---|
29 | |
---|
30 | $query = 'SELECT id FROM ' . GROUPS_TABLE . ' WHERE name IN (\'+18\', \'16-17\', \'nothing\') ORDER BY id'; |
---|
31 | $result = pwg_query($query); |
---|
32 | while ($row = mysql_fetch_assoc($result)) |
---|
33 | { |
---|
34 | array_push($this->idgroups_ad_c, $row['id']); |
---|
35 | } |
---|
36 | } |
---|
37 | function is_in_ad_c_group() |
---|
38 | { |
---|
39 | foreach( $this->idgroups_ad_c as $id ) |
---|
40 | { |
---|
41 | if ( in_array($id, $this->idgroups_user)) |
---|
42 | { |
---|
43 | return $id; |
---|
44 | exit; |
---|
45 | } |
---|
46 | } |
---|
47 | return false; |
---|
48 | } |
---|
49 | function get_link_icon($main_link, $action) |
---|
50 | { |
---|
51 | $link_url = add_url_params($main_link, array('ad' => $action)); |
---|
52 | return $link_url; |
---|
53 | } |
---|
54 | |
---|
55 | function loading_lang() |
---|
56 | { |
---|
57 | global $lang; |
---|
58 | load_language('plugin.lang', $this->plugin_path); |
---|
59 | } |
---|
60 | function var_template() |
---|
61 | { |
---|
62 | global $user; |
---|
63 | if ($user['template'] == 'flop_pure_design') |
---|
64 | { |
---|
65 | $r = 'var_fpd.inc.php'; |
---|
66 | } |
---|
67 | else |
---|
68 | { |
---|
69 | $r = 'var.inc.php'; |
---|
70 | } |
---|
71 | return $r; |
---|
72 | } |
---|
73 | |
---|
74 | function register_ac_menubar_blocks($menu_ref_arr) { |
---|
75 | $menu = & $menu_ref_arr[0]; |
---|
76 | if ($menu->get_id() != 'menubar') |
---|
77 | { |
---|
78 | return; |
---|
79 | } |
---|
80 | $menu->register_block(new RegisteredBlock('mbAdultContent', 'Adult Content', 'AC')); |
---|
81 | } |
---|
82 | function ac_lien_menu($menu) |
---|
83 | { |
---|
84 | array_push( |
---|
85 | $menu, |
---|
86 | array('NAME' => 'Adult Content', |
---|
87 | 'URL' => get_admin_plugin_menu_link(get_root_url().'plugins/'.$this->plugin_name.'/admin/admin.php') |
---|
88 | ) |
---|
89 | ); |
---|
90 | return $menu; |
---|
91 | } |
---|
92 | function get_template($file) |
---|
93 | { |
---|
94 | global $user, $template; |
---|
95 | $r_theme_file=array(); |
---|
96 | $dir = $this->plugin_path.'template/'; |
---|
97 | $r_theme_file=($template->smarty->template_dir); |
---|
98 | foreach( $r_theme_file as $style) |
---|
99 | { |
---|
100 | $theme_file = explode("/", $style); |
---|
101 | $pos = count($theme_file) - 2 ; |
---|
102 | $theme_file = $dir.$theme_file[$pos].'/'.$file; |
---|
103 | if (file_exists($theme_file)) |
---|
104 | { |
---|
105 | return $theme_file; |
---|
106 | } |
---|
107 | else |
---|
108 | { |
---|
109 | $theme_file=NULL; |
---|
110 | } |
---|
111 | |
---|
112 | |
---|
113 | } |
---|
114 | if (empty($theme_file)) |
---|
115 | { |
---|
116 | return $dir.'default/'.$file; |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | function set_block_on_index () |
---|
121 | { |
---|
122 | $this->loading_lang(); |
---|
123 | global $page, $template, $user, $conf; |
---|
124 | |
---|
125 | if (isset($page['section']) and $page['section'] == 'categories') |
---|
126 | |
---|
127 | { |
---|
128 | ////////////lié à quoi///// |
---|
129 | $query = ' |
---|
130 | SELECT id FROM '.GROUPS_TABLE.' |
---|
131 | WHERE name IN (\'+18\') |
---|
132 | ;'; |
---|
133 | $data_18 = mysql_fetch_array(pwg_query($query)); |
---|
134 | $query = ' |
---|
135 | SELECT id FROM '.GROUPS_TABLE.' |
---|
136 | WHERE name IN (\'16-17\') |
---|
137 | ;'; |
---|
138 | $data_16 = mysql_fetch_array(pwg_query($query)); |
---|
139 | $query = ' |
---|
140 | SELECT id FROM '.GROUPS_TABLE.' |
---|
141 | WHERE name IN (\'nothing\') |
---|
142 | ;'; |
---|
143 | $data_no = mysql_fetch_array(pwg_query($query)); |
---|
144 | $n_query = ' |
---|
145 | SELECT COUNT(*) AS result FROM '.USER_GROUP_TABLE.' |
---|
146 | WHERE group_id IN (\''.$data_18['id'].'\',\''.$data_16['id'].'\',\''.$data_no['id'].'\') AND user_id IN (\''.$user['id'].'\') |
---|
147 | ;'; |
---|
148 | $data_user = mysql_fetch_array(pwg_query($n_query)); |
---|
149 | $is_grouped = $data_user['result']; |
---|
150 | |
---|
151 | if ( $is_grouped == 0 and $user['username'] !== '16' and $user['username'] !== '18') |
---|
152 | { |
---|
153 | $template->set_filename('ac_block', realpath($this->get_template('block.tpl') ) ); |
---|
154 | $begin = 'PLUGIN_INDEX_CONTENT_BEFORE'; |
---|
155 | $end = 'PLUGIN_INDEX_CONTENT_AFTER'; |
---|
156 | $template->concat($begin, $template->parse('ac_block', true)); |
---|
157 | } |
---|
158 | } |
---|
159 | } |
---|
160 | function placer_identification($menu_ref_arr) |
---|
161 | { |
---|
162 | ///////////////////////[début du plug]//////////////////// |
---|
163 | $this->loading_lang(); |
---|
164 | global $user, $conf, $page, $template; |
---|
165 | $menu = & $menu_ref_arr[0]; |
---|
166 | $conf_plugin = explode("," , $conf['ad_c_plugin']); |
---|
167 | $template->assign( |
---|
168 | array( |
---|
169 | 'AC_NAME' => AC_NAME |
---|
170 | )); |
---|
171 | |
---|
172 | |
---|
173 | //include($this->var_template()); |
---|
174 | if (is_a_guest() and $conf_plugin[0]=='true') |
---|
175 | { |
---|
176 | |
---|
177 | ///////////////////////[gestion fermer/ouvert]//////////////////// |
---|
178 | if ( !isset( $_GET['ad'] ) ) |
---|
179 | { |
---|
180 | if ( !isset( $_COOKIE['pwg_adult_content'] ) or $_COOKIE['pwg_adult_content'] == 'open' ) |
---|
181 | { |
---|
182 | $template->assign(array( 'LINK' => $this->get_link_icon(duplicate_index_url(), 'closed') )); |
---|
183 | if (($block = $menu->get_block( 'mbAdultContent' )) != null) { |
---|
184 | $block->set_title(l10n('ac_title_menu')); |
---|
185 | $block->template = $this->get_template('opened.tpl'); |
---|
186 | } |
---|
187 | } |
---|
188 | elseif ( $_COOKIE['pwg_adult_content'] == 'closed' ) |
---|
189 | { |
---|
190 | $template->assign(array( 'LINK' => $this->get_link_icon(duplicate_index_url(), 'open') )); |
---|
191 | if (($block = $menu->get_block( 'mbAdultContent' )) != null) { |
---|
192 | $block->set_title(l10n('ac_title_fermer')); |
---|
193 | $block->template = $this->get_template('closed.tpl'); |
---|
194 | } |
---|
195 | |
---|
196 | } |
---|
197 | } |
---|
198 | elseif ( $_GET['ad'] == 'closed' ) |
---|
199 | { |
---|
200 | $template->assign(array( 'LINK' => $this->get_link_icon(duplicate_index_url(), 'open') )); |
---|
201 | setcookie( 'pwg_adult_content', 'closed', time()+60*60*24*30, cookie_path() ); |
---|
202 | if (($block = $menu->get_block( 'mbAdultContent' )) != null) { |
---|
203 | $block->set_title(l10n('ac_title_fermer')); |
---|
204 | $block->template = $this->get_template('closed.tpl'); |
---|
205 | } |
---|
206 | } |
---|
207 | elseif ( $_GET['ad'] == 'open' ) |
---|
208 | { |
---|
209 | $template->assign(array( 'LINK' => $this->get_link_icon(duplicate_index_url(), 'closed') )); |
---|
210 | if (($block = $menu->get_block( 'mbAdultContent' )) != null) { |
---|
211 | $block->set_title(l10n('ac_title_menu')); |
---|
212 | $block->template = $this->get_template('opened.tpl'); |
---|
213 | } |
---|
214 | |
---|
215 | setcookie( 'pwg_adult_content', 'open', time()+60*60*24*30, cookie_path() ); |
---|
216 | } |
---|
217 | ///////////////////////[FIN fermer/ouvert]//////////////////// |
---|
218 | }//fin if guest |
---|
219 | elseif (is_a_guest() and $conf_plugin[0]!='true') |
---|
220 | { |
---|
221 | $menu->hide_block('mbAdultContent'); |
---|
222 | } |
---|
223 | elseif ($user['username'] == '18') |
---|
224 | { |
---|
225 | $menu->hide_block('mbIdentification'); |
---|
226 | $template->assign( |
---|
227 | array( |
---|
228 | 'AC_MSG' => l10n('ac_user_text_18') |
---|
229 | )); |
---|
230 | if (($block = $menu->get_block( 'mbAdultContent' )) != null) { |
---|
231 | $block->set_title(l10n('ac_title_menu')); |
---|
232 | $block->template = $this->get_template('msg.tpl'); |
---|
233 | } |
---|
234 | |
---|
235 | $_SESSION['age']="18"; |
---|
236 | setcookie( 'age', '18', time()+60*60*24*30, cookie_path() ); |
---|
237 | |
---|
238 | }//fin if 18 ans |
---|
239 | elseif ($user['username'] == '16') |
---|
240 | { |
---|
241 | $menu->hide_block('mbIdentification'); |
---|
242 | $template->assign( |
---|
243 | array( |
---|
244 | 'AC_MSG' => l10n('ac_user_text_16') |
---|
245 | )); |
---|
246 | if (($block = $menu->get_block( 'mbAdultContent' )) != null) { |
---|
247 | $block->set_title(l10n('ac_title_menu')); |
---|
248 | $block->template = $this->get_template('msg.tpl'); |
---|
249 | } |
---|
250 | |
---|
251 | }//fin if 16-17 ans |
---|
252 | elseif (!is_admin() and $user['status']!="generic") |
---|
253 | { |
---|
254 | ////////////lié à quoi///// |
---|
255 | $this->fill_idgroups_user(); |
---|
256 | $this->fill_idgroups_ad_c(); |
---|
257 | |
---|
258 | if ( !$this->is_in_ad_c_group() )// lié à rien |
---|
259 | { |
---|
260 | $template->assign( |
---|
261 | array( |
---|
262 | 'AC_MSG' => l10n('ac_charte_user_not') |
---|
263 | )); |
---|
264 | $menu = & $menu_ref_arr[0]; |
---|
265 | if (($block = $menu->get_block( 'mbAdultContent' )) != null) { |
---|
266 | //$block->set_title(l10n('ac_title_choose')); |
---|
267 | $block->template = $this->get_template('choose.tpl'); |
---|
268 | } |
---|
269 | $query = 'SELECT id FROM ' . GROUPS_TABLE . ' WHERE name IN (\'+18\', \'16-17\', \'nothing\') ORDER BY id'; |
---|
270 | $result = pwg_query($query); |
---|
271 | if ( isset($conf['UserAdvManager']) ) |
---|
272 | { |
---|
273 | $conf_UAM_2 = unserialize($conf['UserAdvManager']); |
---|
274 | if ( in_array($conf_UAM_2[2], $this->idgroups_user))/// $conf_UAM_2[2] est le groupe des user en attente de modération |
---|
275 | { |
---|
276 | $menu->hide_block('mbAdultContent'); |
---|
277 | } |
---|
278 | } |
---|
279 | |
---|
280 | } |
---|
281 | else |
---|
282 | { |
---|
283 | $link=$this->is_in_ad_c_group(); |
---|
284 | if ($link == $this->idgroups_ad_c[0]) |
---|
285 | { |
---|
286 | $statut = l10n('ac_user_text_18'); |
---|
287 | } |
---|
288 | if ($link == $this->idgroups_ad_c[1]) |
---|
289 | { |
---|
290 | $statut = l10n('ac_user_text_16'); |
---|
291 | } |
---|
292 | if ($link == $this->idgroups_ad_c[2]) |
---|
293 | { |
---|
294 | $statut = l10n('ac_user_no_s'); |
---|
295 | } |
---|
296 | $template->assign( |
---|
297 | array( |
---|
298 | 'AC_MSG' => $statut.". ".l10n('ac_charte_user_def') |
---|
299 | )); |
---|
300 | $menu = & $menu_ref_arr[0]; |
---|
301 | if (($block = $menu->get_block( 'mbAdultContent' )) != null) { |
---|
302 | $block->set_title(l10n('ac_title_menu_statut')); |
---|
303 | $block->template = $this->get_template('choose.tpl'); |
---|
304 | } |
---|
305 | |
---|
306 | } |
---|
307 | } |
---|
308 | |
---|
309 | }//fin placer_identification |
---|
310 | function on_register() |
---|
311 | { |
---|
312 | if ( !function_exists('UAM_admin_menu')) |
---|
313 | { |
---|
314 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
315 | $user_id = get_userid($_POST['login']); |
---|
316 | log_user( $user_id, false); |
---|
317 | redirect(PHPWG_ROOT_PATH.'plugins/adult_content/charte_user.php'); |
---|
318 | } |
---|
319 | } |
---|
320 | }//fin class |
---|
321 | ?> |
---|