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

Last change on this file since 4078 was 4078, checked in by flop25, 15 years ago

adding admin.php (empty)
adding function get_template (fully functionnal) und set_block_on_index (en cours)

File size: 7.7 KB
Line 
1<?php
2
3
4class Adultcontent
5{
6  var $plugin_name, $plugin_path;
7 
8  function Adultcontent($plugin_name, $plugin_path)
9  {
10    // Args
11    $this->plugin_name = $plugin_name;
12    $this->plugin_path = $plugin_path;
13    // handler
14   // $this->initialize_event_handler();
15  }
16 
17  function get_link_icon($main_link, $action)
18  {
19    $link_url = add_url_params($main_link, array('ad' => $action));
20    return $link_url;
21  }
22 
23  function loading_lang()
24  {
25    global $lang;
26        load_language('plugin.lang', $this->plugin_path);
27  } 
28  function var_template()
29  {
30    global $user;
31    if ($user['template'] == 'flop_pure_design')
32    {
33      $r = 'var_fpd.inc.php';   
34    }
35    else
36    {
37     $r = 'var.inc.php';       
38    }
39   return $r;
40  }
41
42  function register_ac_menubar_blocks($menu_ref_arr) {
43    $menu = & $menu_ref_arr[0];
44    if ($menu->get_id() != 'menubar')
45      return;
46    $menu->register_block(new RegisteredBlock('mbAdultContent', 'Adult Content', 'AC'));
47  }
48  function ac_lien_menu($menu)
49  {
50    array_push($menu, array('NAME' => 'Adult Content',
51            'URL' => get_admin_plugin_menu_link(get_root_url().'plugins/'.$this->plugin_name.'/admin/admin.php')));
52    return $menu;
53  }
54  function get_template($file)
55  {
56    global $user, $template;
57
58    $dir = $this->plugin_path.'template/';
59    $theme_file = $dir.$user['template'].'/'.$user['theme'].'/'.$file;
60    $template_file = $dir.$user['template'].'/'.$file;
61
62    if (file_exists($theme_file))
63    {
64      return $theme_file;
65    }
66    elseif (file_exists($template_file))
67    {
68      return $template_file;
69    }
70    else
71    {
72      return $dir.'yoga/'.$file;
73    }
74  }
75
76  function set_block_on_index ()
77  {
78        global $page, $template;
79
80        if (isset($page['section']) and $page['section'] == 'categories')
81        {
82                $template->set_filename('ac_block', realpath($this->get_template('block.tpl') ) );
83                $begin = 'PLUGIN_INDEX_CONTENT_BEFORE';
84                $end = 'PLUGIN_INDEX_CONTENT_AFTER';
85                $template->concat($begin,       $template->parse('ac_block', true));
86        }
87  }
88  function placer_identification($menu_ref_arr)
89  {
90///////////////////////[début du plug]////////////////////
91    $this->loading_lang();
92    global $user, $conf, $page;
93        global $template;
94
95    $menu = & $menu_ref_arr[0];
96       
97$template->assign(
98  array(
99    'AC_NAME' => AC_NAME
100    ));
101
102
103    //include($this->var_template());
104    if (is_a_guest())
105        {
106       
107///////////////////////[gestion fermer/ouvert]////////////////////
108          if ( !isset( $_GET['ad'] ) )
109          {         
110              if ( !isset( $_COOKIE['pwg_adult_content'] ) or $_COOKIE['pwg_adult_content'] == 'open' )
111              { 
112                        $template->assign(array(  'LINK' => $this->get_link_icon(duplicate_index_url(), 'closed')    ));
113            if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
114               $block->set_title(l10n('ac_title_menu'));
115               $block->template = $this->get_template('opened.tpl');
116            }
117              }
118          elseif ( $_COOKIE['pwg_adult_content'] == 'closed' )
119              {
120            $template->assign(array(  'LINK' => $this->get_link_icon(duplicate_index_url(), 'open')    ));
121                        if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
122               $block->set_title(l10n('ac_title_fermer'));
123               $block->template = $this->get_template('closed.tpl');
124            }
125                       
126              }
127          }
128          elseif (  $_GET['ad'] == 'closed' )
129          {
130        $template->assign(array(  'LINK' => $this->get_link_icon(duplicate_index_url(), 'open')    ));
131                setcookie( 'pwg_adult_content', 'closed', time()+60*60*24*30, cookie_path() );   
132            if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
133               $block->set_title(l10n('ac_title_fermer'));
134               $block->template = $this->get_template('closed.tpl');
135            }
136          }
137          elseif (  $_GET['ad'] == 'open' )
138          {
139            $template->assign(array(  'LINK' => $this->get_link_icon(duplicate_index_url(), 'closed')    ));
140                        if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
141               $block->set_title(l10n('ac_title_menu'));
142               $block->template = $this->get_template('opened.tpl');
143            }
144
145        setcookie( 'pwg_adult_content', 'open', time()+60*60*24*30, cookie_path() );     
146          }
147///////////////////////[FIN fermer/ouvert]////////////////////
148    }//fin if guest
149    elseif ($user['username'] == '18')
150    { 
151                $menu->hide_block('mbIdentification');
152                $template->assign(
153                  array(
154                        'AC_MSG' => l10n('ac_user_text_18')
155                        ));
156                if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
157               $block->set_title(l10n('ac_title_menu'));
158               $block->template = $this->get_template('msg.tpl');
159        }
160         
161          $_SESSION['age']="18"; 
162        setcookie( 'age', '18', time()+60*60*24*30, cookie_path() );     
163
164    }//fin if 18 ans
165    elseif ($user['username'] == '16')
166    {
167                $menu->hide_block('mbIdentification');
168                $template->assign(
169                  array(
170                        'AC_MSG' => l10n('ac_user_text_16')
171                        ));
172                if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
173               $block->set_title(l10n('ac_title_menu'));
174               $block->template = $this->get_template('msg.tpl');
175        }
176
177    }//fin if 16-17 ans
178    elseif (!is_admin())
179    {
180       
181////////////lié à quoi/////     
182         $query = '
183SELECT id FROM '.GROUPS_TABLE.'
184  WHERE name IN (\'+18\')
185;';
186     $data_18 = mysql_fetch_array(pwg_query($query));
187         $query = '
188SELECT id FROM '.GROUPS_TABLE.'
189  WHERE name IN (\'16-17\')
190;';
191     $data_16 = mysql_fetch_array(pwg_query($query));
192         $query = '
193SELECT id FROM '.GROUPS_TABLE.'
194  WHERE name IN (\'nothing\')
195;';
196     $data_no = mysql_fetch_array(pwg_query($query));
197         $n_query = '
198SELECT COUNT(*) AS result FROM '.USER_GROUP_TABLE.'
199  WHERE group_id IN (\''.$data_18['id'].'\',\''.$data_16['id'].'\',\''.$data_no['id'].'\') AND user_id IN (\''.$user['id'].'\')
200;';
201      $data_user = mysql_fetch_array(pwg_query($n_query));
202          $is_grouped = $data_user['result'];   
203
204          if ( $is_grouped == 0 )
205          {
206                $template->assign(
207                  array(
208                        'AC_ETAT' => 'not_defined',
209                        'AC_MSG' => l10n('ac_charte_user_not')
210                        ));
211                $menu = & $menu_ref_arr[0];
212                $block = $menu->get_block( 'mbAdultContent' );
213                $block->set_title(l10n('ac_title_choose'));
214                $block->template = $this->plugin_path.'template/'.$user['template'].'/choose.tpl';
215
216          }
217          else
218          {       
219                        $query = '
220          SELECT group_id FROM '.USER_GROUP_TABLE.'
221                WHERE user_id IN (\''.$user['id'].'\')
222          ;';
223                   $data_group = mysql_fetch_array(pwg_query($query));
224                   $query = '
225          SELECT name FROM '.GROUPS_TABLE.'
226                WHERE id IN (\''.$data_group['group_id'].'\')
227          ;';
228                   $data_group_n = mysql_fetch_array(pwg_query($query));
229                   if ($data_group_n['name'] == '+18')
230                   {
231                   $statut = l10n('ac_user_text_18');
232                   }
233                   if ($data_group_n['name'] == '16-17')
234                   {
235                   $statut = l10n('ac_user_text_16');
236                   }
237                   if ($data_group_n['name'] == 'nothing')
238                   {
239                   $statut = l10n('ac_user_no_s');
240                   }
241                $template->assign(
242                  array(
243                        'AC_ETAT' => 'defined',
244                        'AC_MSG' => $statut.". ".l10n('ac_charte_user_def')
245                        ));
246                $menu = & $menu_ref_arr[0];
247                $block = $menu->get_block( 'mbAdultContent' );
248                $block->set_title(l10n('ac_title_menu_statut'));
249                $block->template = $this->plugin_path.'template/'.$user['template'].'/choose.tpl';
250
251          }
252        }
253
254  }//fin placer_identification
255  function on_register()
256  {
257          include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
258    $user_id = get_userid($_POST['login']);
259    log_user( $user_id, false);
260      redirect(PHPWG_ROOT_PATH.'plugins/adult_content/charte_user.php?etat=not_defined');
261  } 
262}//fin class
263?>
Note: See TracBrowser for help on using the repository browser.