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

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

first commit

File size: 8.0 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    //include(get_language_filepath('plugin.lang.php', $this->plugin_path));
27        load_language('plugin.lang', $this->plugin_path);
28  } 
29  /*
30  function remove_code($tlp_handle, $str_begin, $str_end)
31  {
32      global $template;
33 
34      $template->loadfile($tlp_handle);
35 
36      $p_beg = strpos($template->uncompiled_code[$tlp_handle], $str_begin);
37      $p_end = strpos($template->uncompiled_code[$tlp_handle], $str_end) + strlen($str_end);
38      $s = substr($template->uncompiled_code[$tlp_handle], $p_beg, $p_end - $p_beg);
39 
40      $template->uncompiled_code[$tlp_handle] =
41      substr_replace($template->uncompiled_code[$tlp_handle], '', $p_beg, $p_end - $p_beg);
42 
43      return $s;
44  }
45 
46  function add_before_code($tlp_handle, $insert_before, $code)
47  {
48      global $template;
49 
50      $template->loadfile($tlp_handle);
51      $template->uncompiled_code[$tlp_handle] = str_replace($insert_before, $code.$insert_before, $template->uncompiled_code[$tlp_handle]);
52  }
53  function add_after_code($tlp_handle, $insert_after, $code)
54  {
55    global $template;
56 
57    $template->loadfile($tlp_handle);
58    $template->uncompiled_code[$tlp_handle] = str_replace($insert_after, $insert_after.$code, $template->uncompiled_code[$tlp_handle]);
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  function link_charte_user($etat)
74  {
75  global $user, $lang;
76  include($this->var_template());
77  if ($etat == 'not_defined')
78  {
79      /*$s = $this->remove_code('menubar',$begin_ident ,$end_ident);
80      $this->add_before_code('menubar','<!-- BEGIN links -->',$s);       
81      $this->add_after_code('menubar','<!-- END hello -->
82    <ul>','<a href="'.get_root_url().'plugins/'.$this->plugin_name.'/charte_user.php?etat='.$etat.'">{lang:ac_charte_user_not}</a>');*/
83  }
84  elseif ($etat == 'defined')
85  {
86      $query = '
87SELECT group_id FROM '.USER_GROUP_TABLE.'
88  WHERE user_id IN (\''.$user['id'].'\')
89;';
90     $data_group = mysql_fetch_array(pwg_query($query));
91         $query = '
92SELECT name FROM '.GROUPS_TABLE.'
93  WHERE id IN (\''.$data_group['group_id'].'\')
94;';
95     $data_group_n = mysql_fetch_array(pwg_query($query));
96         if ($data_group_n['name'] == '+18')
97         {
98         $statut = $lang['ac_user_text_18'];
99         }
100         if ($data_group_n['name'] == '16-17')
101         {
102         $statut = $lang['ac_user_text_16'];
103         }
104         if ($data_group_n['name'] == 'nothing')
105         {
106         $statut = $lang['ac_user_no_s'];
107         }
108
109          /*$this->add_after_code('menubar','<!-- END hello -->
110    <ul>',''.$statut.' <a href="'.get_root_url().'plugins/'.$this->plugin_name.'/charte_user.php?etat='.$etat.'">{lang:ac_logout}</a>');*/
111  }
112     
113
114  }
115
116  function register_ac_menubar_blocks($menu_ref_arr) {
117    $menu = & $menu_ref_arr[0];
118    if ($menu->get_id() != 'menubar')
119      return;
120    $menu->register_block(new RegisteredBlock('mbAdultContent', 'Adult Content', 'AC'));
121  }
122
123  function placer_identification($menu_ref_arr)
124  {
125///////////////////////[début du plug]////////////////////
126    $this->loading_lang();
127    global $user, $conf, $page;
128        global $template;
129
130    $menu = & $menu_ref_arr[0];
131       
132$template->assign(
133  array(
134    'AC_NAME' => AC_NAME
135    ));
136
137
138    //include($this->var_template());
139    if (is_a_guest())
140        {
141       
142///////////////////////[gestion fermer/ouvert]////////////////////
143          if ( !isset( $_GET['ad'] ) )
144          {         
145              if ( !isset( $_COOKIE['pwg_adult_content'] ) or $_COOKIE['pwg_adult_content'] == 'open' )
146              { 
147                //$this->add_before_code('menubar','<!-- BEGIN links -->', $msg_opened);
148                        $template->assign(array(  'LINK' => $this->get_link_icon(duplicate_index_url(), 'closed')    ));
149            if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
150               $block->set_title(l10n('ac_title_menu'));
151               $block->template = $this->plugin_path.'template/'.$user['template'].'/opened.tpl';
152            }
153              }
154          elseif ( $_COOKIE['pwg_adult_content'] == 'closed' )
155              {
156                //$this->add_before_code('menubar','<!-- BEGIN links -->', $msg_closed);
157            $template->assign(array(  'LINK' => $this->get_link_icon(duplicate_index_url(), 'open')    ));
158                        if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
159               $block->set_title(l10n('ac_title_fermer'));
160               $block->template = $this->plugin_path.'template/'.$user['template'].'/closed.tpl';
161            }
162                       
163              }
164          }
165          elseif (  $_GET['ad'] == 'closed' )
166          {
167            //$this->add_before_code('menubar','<!-- BEGIN links -->', $msg_closed);
168        $template->assign(array(  'LINK' => $this->get_link_icon(duplicate_index_url(), 'open')    ));
169                setcookie( 'pwg_adult_content', 'closed', time()+60*60*24*30, cookie_path() );   
170            if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
171               $block->set_title(l10n('ac_title_fermer'));
172               $block->template = $this->plugin_path.'template/'.$user['template'].'/closed.tpl';
173            }
174          }
175          elseif (  $_GET['ad'] == 'open' )
176          {
177            //$this->add_before_code('menubar','<!-- BEGIN links -->', $msg_opened);
178            $template->assign(array(  'LINK' => $this->get_link_icon(duplicate_index_url(), 'closed')    ));
179                        if (($block = $menu->get_block( 'mbAdultContent' )) != null) {
180               $block->set_title(l10n('ac_title_menu'));
181               $block->template = $this->plugin_path.'template/'.$user['template'].'/opened.tpl';
182            }
183
184        setcookie( 'pwg_adult_content', 'open', time()+60*60*24*30, cookie_path() );     
185          }
186///////////////////////[FIN fermer/ouvert]////////////////////
187    }//fin if guest
188    elseif ($user['username'] == '18')
189    { 
190      $this->remove_code('menubar', '<dl id="mbIdentification">', '<!-- END quickconnect -->
191
192  </dd>
193</dl>');
194 
195      $this->add_before_code('menubar','<!-- BEGIN tags -->',$msg_18);
196         
197          $_SESSION['age']="18"; 
198        setcookie( 'age', '18', time()+60*60*24*30, cookie_path() );     
199
200    }//fin if 18 ans
201    elseif ($user['username'] == '16')
202    {
203      $this->remove_code('menubar', '<dl id="mbIdentification">', '<!-- END quickconnect -->
204
205  </dd>
206</dl>');
207 
208      $this->add_before_code('menubar','<!-- BEGIN tags -->',$msg_16);
209
210    }//fin if 16-17 ans
211    elseif (!is_admin())
212    {
213       
214////////////lié à quoi/////     
215         $query = '
216SELECT id FROM '.GROUPS_TABLE.'
217  WHERE name IN (\'+18\')
218;';
219     $data_18 = mysql_fetch_array(pwg_query($query));
220         $query = '
221SELECT id FROM '.GROUPS_TABLE.'
222  WHERE name IN (\'16-17\')
223;';
224     $data_16 = mysql_fetch_array(pwg_query($query));
225         $query = '
226SELECT id FROM '.GROUPS_TABLE.'
227  WHERE name IN (\'nothing\')
228;';
229     $data_no = mysql_fetch_array(pwg_query($query));
230         $n_query = '
231SELECT COUNT(*) AS result FROM '.USER_GROUP_TABLE.'
232  WHERE group_id IN (\''.$data_18['id'].'\',\''.$data_16['id'].'\',\''.$data_no['id'].'\') AND user_id IN (\''.$user['id'].'\')
233;';
234      $data_user = mysql_fetch_array(pwg_query($n_query));
235          $is_grouped = $data_user['result'];   
236
237          if ( $is_grouped == 0 )
238          {
239          $this->link_charte_user('not_defined');
240          }
241          else
242          {       
243          $this->link_charte_user('defined');
244          }
245        }
246
247  }//fin placer_identification
248  function on_register()
249  {
250          include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
251    $user_id = get_userid($_POST['login']);
252    log_user( $user_id, false);
253      redirect(PHPWG_ROOT_PATH.'plugins/adult_content/charte_user.php?etat=not_defined');
254  } 
255}//fin class
256?>
Note: See TracBrowser for help on using the repository browser.