source: extensions/adult_content/class.inc.php @ 21057

Last change on this file since 21057 was 21057, checked in by flop25, 11 years ago

removed the option for PWG stuffs
added an explicative texte
added new lang key for the PWG Stuff module

File size: 8.1 KB
Line 
1<?php
2
3
4class 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 = pwg_db_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 = pwg_db_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 placer_identification($menu_ref_arr)
121  {
122///////////////////////[début du plug]////////////////////
123    $this->loading_lang();
124    global $user, $conf, $page, $template;
125    $menu = & $menu_ref_arr[0];
126                $conf_plugin = unserialize($conf['ad_c_plugin']);
127                $template->assign(
128                        array(
129                                'AC_NAME' => AC_NAME
130                                ));
131
132
133    //include($this->var_template());
134    if (is_a_guest() and $conf_plugin['menublock_for_guest']=='true')
135        {
136       
137///////////////////////[gestion fermer/ouvert]////////////////////
138          if ( !isset( $_GET['ad'] ) )
139          {         
140              if ( !isset( $_COOKIE['pwg_adult_content'] ) or $_COOKIE['pwg_adult_content'] == 'open' )
141              { 
142                        $template->assign(array(  'LINK' => $this->get_link_icon(duplicate_index_url(), 'closed')    ));
143            if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
144               $block->set_title(l10n('ac_title_menu'));
145               $block->template = $this->get_template('opened.tpl');
146            }
147              }
148          elseif ( $_COOKIE['pwg_adult_content'] == 'closed' )
149              {
150            $template->assign(array(  'LINK' => $this->get_link_icon(duplicate_index_url(), 'open')    ));
151                        if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
152               $block->set_title(l10n('ac_title_fermer'));
153               $block->template = $this->get_template('closed.tpl');
154            }
155                       
156              }
157          }
158          elseif (  $_GET['ad'] == 'closed' )
159          {
160        $template->assign(array(  'LINK' => $this->get_link_icon(duplicate_index_url(), 'open')    ));
161                setcookie( 'pwg_adult_content', 'closed', time()+60*60*24*30, cookie_path() );   
162            if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
163               $block->set_title(l10n('ac_title_fermer'));
164               $block->template = $this->get_template('closed.tpl');
165            }
166          }
167          elseif (  $_GET['ad'] == 'open' )
168          {
169            $template->assign(array(  'LINK' => $this->get_link_icon(duplicate_index_url(), 'closed')    ));
170                        if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
171               $block->set_title(l10n('ac_title_menu'));
172               $block->template = $this->get_template('opened.tpl');
173            }
174
175        setcookie( 'pwg_adult_content', 'open', time()+60*60*24*30, cookie_path() );     
176          }
177///////////////////////[FIN fermer/ouvert]////////////////////
178    }//fin if guest
179    elseif (is_a_guest() and $conf_plugin['menublock_for_guest']!='true')
180    { 
181                  $menu->hide_block('mbAdultContent');
182    }
183    elseif ($user['username'] == '18')
184    { 
185                $menu->hide_block('mbIdentification');
186                $template->assign(
187                  array(
188                        'AC_MSG' => l10n('ac_user_text_18')
189                        ));
190                if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
191               $block->set_title(l10n('ac_title_menu'));
192               $block->template = $this->get_template('msg.tpl');
193        }
194         
195          $_SESSION['age']="18"; 
196        setcookie( 'age', '18', time()+60*60*24*30, cookie_path() );     
197
198    }//fin if 18 ans
199    elseif ($user['username'] == '16')
200    {
201                $menu->hide_block('mbIdentification');
202                $template->assign(
203                  array(
204                        'AC_MSG' => l10n('ac_user_text_16')
205                        ));
206                if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
207               $block->set_title(l10n('ac_title_menu'));
208               $block->template = $this->get_template('msg.tpl');
209        }
210
211    }//fin if 16-17 ans
212    elseif (!is_admin() and $user['status']!="generic")
213    {
214////////////lié à quoi/////     
215                        $this->fill_idgroups_user();
216                        $this->fill_idgroups_ad_c();   
217
218                        if ( !$this->is_in_ad_c_group() )// lié à rien
219                        {
220                                $template->assign(
221                                        array(
222                                        'AC_MSG' => l10n('ac_charte_user_not')
223                                        ));
224                                $menu = & $menu_ref_arr[0];
225                                if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
226                                        //$block->set_title(l10n('ac_title_choose'));
227                                        $block->template = $this->get_template('choose.tpl');
228                                }
229                                $query = 'SELECT id FROM ' . GROUPS_TABLE . ' WHERE name IN (\'+18\', \'16-17\', \'nothing\') ORDER BY id';
230                                $result = pwg_query($query);
231                                if ( isset($conf['UserAdvManager']) )
232                                {
233                                        $conf_UAM_2 = unserialize($conf['UserAdvManager']);
234                                        if ( in_array($conf_UAM_2[2], $this->idgroups_user))/// $conf_UAM_2[2] est le groupe des user en attente de modération
235                                        {
236                                                $menu->hide_block('mbAdultContent');
237                                        }
238                                }
239
240                        }
241                        else
242                        {         
243                                $link=$this->is_in_ad_c_group();
244                                if ($link == $this->idgroups_ad_c[0])
245                                {
246                                        $statut = l10n('ac_user_text_18');
247                                }
248                                if ($link ==  $this->idgroups_ad_c[1])
249                                {
250                                        $statut = l10n('ac_user_text_16');
251                                }
252                                if ($link ==  $this->idgroups_ad_c[2])
253                                {
254                                        $statut = l10n('ac_user_no_s');
255                                }
256                                $template->assign(
257                                array(
258                                'AC_MSG' => $statut.". ".l10n('ac_charte_user_def')
259                                ));
260                                $menu = & $menu_ref_arr[0];
261                                if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
262                                        $block->set_title(l10n('ac_title_menu_statut'));
263                                        $block->template = $this->get_template('choose.tpl');
264                                }
265
266          }
267        }
268
269  }//fin placer_identification
270  function on_register()
271  {
272          if ( !function_exists('UAM_admin_menu'))
273                {
274                        include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
275                        $user_id = get_userid($_POST['login']);
276                        log_user( $user_id, false);
277      redirect(PHPWG_ROOT_PATH.'plugins/adult_content/charte_user.php');
278                }
279  }
280  function ac_stuffs_module($modules)
281  {
282    load_language('plugin.lang', $this->plugin_path);
283    array_push($modules, array(
284      'path' => PHPWG_PLUGINS_PATH . AC_NAME . '/stuffs_module/',
285      'name' => l10n('ac_text'),
286      'description' => l10n('Disclaimer for the guest, with the ability to choose its age'),
287      )
288    );
289    return $modules;
290  }
291
292}//fin class
293?>
Note: See TracBrowser for help on using the repository browser.