| 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 | return; |
|---|
| 78 | $menu->register_block(new RegisteredBlock('mbAdultContent', 'Adult Content', 'AC')); |
|---|
| 79 | } |
|---|
| 80 | function ac_lien_menu($menu) |
|---|
| 81 | { |
|---|
| 82 | array_push($menu, array('NAME' => 'Adult Content', |
|---|
| 83 | 'URL' => get_admin_plugin_menu_link(get_root_url().'plugins/'.$this->plugin_name.'/admin/admin.php'))); |
|---|
| 84 | return $menu; |
|---|
| 85 | } |
|---|
| 86 | function get_template($file) |
|---|
| 87 | { |
|---|
| 88 | global $user, $template; |
|---|
| 89 | $r_theme_file=array(); |
|---|
| 90 | $dir = $this->plugin_path.'template/'; |
|---|
| 91 | $r_theme_file=($template->smarty->template_dir); |
|---|
| 92 | foreach( $r_theme_file as $style) |
|---|
| 93 | { |
|---|
| 94 | $theme_file = explode("/", $style); |
|---|
| 95 | $pos = count($theme_file) - 2 ; |
|---|
| 96 | $theme_file = $dir.$theme_file[$pos].'/'.$file; |
|---|
| 97 | if (file_exists($theme_file)) |
|---|
| 98 | { |
|---|
| 99 | return $theme_file; |
|---|
| 100 | } |
|---|
| 101 | else |
|---|
| 102 | { |
|---|
| 103 | $theme_file=NULL; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | } |
|---|
| 108 | if (empty($theme_file)) |
|---|
| 109 | { |
|---|
| 110 | return $dir.'default/'.$file; |
|---|
| 111 | } |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | function set_block_on_index () |
|---|
| 115 | { |
|---|
| 116 | $this->loading_lang(); |
|---|
| 117 | global $page, $template, $user, $conf; |
|---|
| 118 | |
|---|
| 119 | if (isset($page['section']) and $page['section'] == 'categories') |
|---|
| 120 | |
|---|
| 121 | { |
|---|
| 122 | ////////////lié à quoi///// |
|---|
| 123 | $query = ' |
|---|
| 124 | SELECT id FROM '.GROUPS_TABLE.' |
|---|
| 125 | WHERE name IN (\'+18\') |
|---|
| 126 | ;'; |
|---|
| 127 | $data_18 = mysql_fetch_array(pwg_query($query)); |
|---|
| 128 | $query = ' |
|---|
| 129 | SELECT id FROM '.GROUPS_TABLE.' |
|---|
| 130 | WHERE name IN (\'16-17\') |
|---|
| 131 | ;'; |
|---|
| 132 | $data_16 = mysql_fetch_array(pwg_query($query)); |
|---|
| 133 | $query = ' |
|---|
| 134 | SELECT id FROM '.GROUPS_TABLE.' |
|---|
| 135 | WHERE name IN (\'nothing\') |
|---|
| 136 | ;'; |
|---|
| 137 | $data_no = mysql_fetch_array(pwg_query($query)); |
|---|
| 138 | $n_query = ' |
|---|
| 139 | SELECT COUNT(*) AS result FROM '.USER_GROUP_TABLE.' |
|---|
| 140 | WHERE group_id IN (\''.$data_18['id'].'\',\''.$data_16['id'].'\',\''.$data_no['id'].'\') AND user_id IN (\''.$user['id'].'\') |
|---|
| 141 | ;'; |
|---|
| 142 | $data_user = mysql_fetch_array(pwg_query($n_query)); |
|---|
| 143 | $is_grouped = $data_user['result']; |
|---|
| 144 | |
|---|
| 145 | if ( $is_grouped == 0 and $user['username'] !== '16' and $user['username'] !== '18') |
|---|
| 146 | { |
|---|
| 147 | $template->set_filename('ac_block', realpath($this->get_template('block.tpl') ) ); |
|---|
| 148 | $begin = 'PLUGIN_INDEX_CONTENT_BEFORE'; |
|---|
| 149 | $end = 'PLUGIN_INDEX_CONTENT_AFTER'; |
|---|
| 150 | $template->concat($begin, $template->parse('ac_block', true)); |
|---|
| 151 | } |
|---|
| 152 | } |
|---|
| 153 | } |
|---|
| 154 | function placer_identification($menu_ref_arr) |
|---|
| 155 | { |
|---|
| 156 | ///////////////////////[début du plug]//////////////////// |
|---|
| 157 | $this->loading_lang(); |
|---|
| 158 | global $user, $conf, $page, $template; |
|---|
| 159 | $menu = & $menu_ref_arr[0]; |
|---|
| 160 | $conf_plugin = explode("," , $conf['ad_c_plugin']); |
|---|
| 161 | $template->assign( |
|---|
| 162 | array( |
|---|
| 163 | 'AC_NAME' => AC_NAME |
|---|
| 164 | )); |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | //include($this->var_template()); |
|---|
| 168 | if (is_a_guest() and $conf_plugin[0]=='true') |
|---|
| 169 | { |
|---|
| 170 | |
|---|
| 171 | ///////////////////////[gestion fermer/ouvert]//////////////////// |
|---|
| 172 | if ( !isset( $_GET['ad'] ) ) |
|---|
| 173 | { |
|---|
| 174 | if ( !isset( $_COOKIE['pwg_adult_content'] ) or $_COOKIE['pwg_adult_content'] == 'open' ) |
|---|
| 175 | { |
|---|
| 176 | $template->assign(array( 'LINK' => $this->get_link_icon(duplicate_index_url(), 'closed') )); |
|---|
| 177 | if (($block = $menu->get_block( 'mbAdultContent' )) != null) { |
|---|
| 178 | $block->set_title(l10n('ac_title_menu')); |
|---|
| 179 | $block->template = $this->get_template('opened.tpl'); |
|---|
| 180 | } |
|---|
| 181 | } |
|---|
| 182 | elseif ( $_COOKIE['pwg_adult_content'] == 'closed' ) |
|---|
| 183 | { |
|---|
| 184 | $template->assign(array( 'LINK' => $this->get_link_icon(duplicate_index_url(), 'open') )); |
|---|
| 185 | if (($block = $menu->get_block( 'mbAdultContent' )) != null) { |
|---|
| 186 | $block->set_title(l10n('ac_title_fermer')); |
|---|
| 187 | $block->template = $this->get_template('closed.tpl'); |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | } |
|---|
| 191 | } |
|---|
| 192 | elseif ( $_GET['ad'] == 'closed' ) |
|---|
| 193 | { |
|---|
| 194 | $template->assign(array( 'LINK' => $this->get_link_icon(duplicate_index_url(), 'open') )); |
|---|
| 195 | setcookie( 'pwg_adult_content', 'closed', time()+60*60*24*30, cookie_path() ); |
|---|
| 196 | if (($block = $menu->get_block( 'mbAdultContent' )) != null) { |
|---|
| 197 | $block->set_title(l10n('ac_title_fermer')); |
|---|
| 198 | $block->template = $this->get_template('closed.tpl'); |
|---|
| 199 | } |
|---|
| 200 | } |
|---|
| 201 | elseif ( $_GET['ad'] == 'open' ) |
|---|
| 202 | { |
|---|
| 203 | $template->assign(array( 'LINK' => $this->get_link_icon(duplicate_index_url(), 'closed') )); |
|---|
| 204 | if (($block = $menu->get_block( 'mbAdultContent' )) != null) { |
|---|
| 205 | $block->set_title(l10n('ac_title_menu')); |
|---|
| 206 | $block->template = $this->get_template('opened.tpl'); |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | setcookie( 'pwg_adult_content', 'open', time()+60*60*24*30, cookie_path() ); |
|---|
| 210 | } |
|---|
| 211 | ///////////////////////[FIN fermer/ouvert]//////////////////// |
|---|
| 212 | }//fin if guest |
|---|
| 213 | elseif (is_a_guest() and $conf_plugin[0]!='true') |
|---|
| 214 | { |
|---|
| 215 | $menu->hide_block('mbAdultContent'); |
|---|
| 216 | } |
|---|
| 217 | elseif ($user['username'] == '18') |
|---|
| 218 | { |
|---|
| 219 | $menu->hide_block('mbIdentification'); |
|---|
| 220 | $template->assign( |
|---|
| 221 | array( |
|---|
| 222 | 'AC_MSG' => l10n('ac_user_text_18') |
|---|
| 223 | )); |
|---|
| 224 | if (($block = $menu->get_block( 'mbAdultContent' )) != null) { |
|---|
| 225 | $block->set_title(l10n('ac_title_menu')); |
|---|
| 226 | $block->template = $this->get_template('msg.tpl'); |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | $_SESSION['age']="18"; |
|---|
| 230 | setcookie( 'age', '18', time()+60*60*24*30, cookie_path() ); |
|---|
| 231 | |
|---|
| 232 | }//fin if 18 ans |
|---|
| 233 | elseif ($user['username'] == '16') |
|---|
| 234 | { |
|---|
| 235 | $menu->hide_block('mbIdentification'); |
|---|
| 236 | $template->assign( |
|---|
| 237 | array( |
|---|
| 238 | 'AC_MSG' => l10n('ac_user_text_16') |
|---|
| 239 | )); |
|---|
| 240 | if (($block = $menu->get_block( 'mbAdultContent' )) != null) { |
|---|
| 241 | $block->set_title(l10n('ac_title_menu')); |
|---|
| 242 | $block->template = $this->get_template('msg.tpl'); |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | }//fin if 16-17 ans |
|---|
| 246 | elseif (!is_admin()) |
|---|
| 247 | { |
|---|
| 248 | ////////////lié à quoi///// |
|---|
| 249 | $this->fill_idgroups_user(); |
|---|
| 250 | $this->fill_idgroups_ad_c(); |
|---|
| 251 | |
|---|
| 252 | if ( !$this->is_in_ad_c_group() ) |
|---|
| 253 | { |
|---|
| 254 | $template->assign( |
|---|
| 255 | array( |
|---|
| 256 | 'AC_MSG' => l10n('ac_charte_user_not') |
|---|
| 257 | )); |
|---|
| 258 | $menu = & $menu_ref_arr[0]; |
|---|
| 259 | if (($block = $menu->get_block( 'mbAdultContent' )) != null) { |
|---|
| 260 | $block->set_title(l10n('ac_title_choose')); |
|---|
| 261 | $block->template = $this->get_template('choose.tpl'); |
|---|
| 262 | } |
|---|
| 263 | } |
|---|
| 264 | else |
|---|
| 265 | { |
|---|
| 266 | $link=$this->is_in_ad_c_group(); |
|---|
| 267 | if ($link == $this->idgroups_ad_c[0]) |
|---|
| 268 | { |
|---|
| 269 | $statut = l10n('ac_user_text_18'); |
|---|
| 270 | } |
|---|
| 271 | if ($link == $this->idgroups_ad_c[1]) |
|---|
| 272 | { |
|---|
| 273 | $statut = l10n('ac_user_text_16'); |
|---|
| 274 | } |
|---|
| 275 | if ($link == $this->idgroups_ad_c[2]) |
|---|
| 276 | { |
|---|
| 277 | $statut = l10n('ac_user_no_s'); |
|---|
| 278 | } |
|---|
| 279 | $template->assign( |
|---|
| 280 | array( |
|---|
| 281 | 'AC_MSG' => $statut.". ".l10n('ac_charte_user_def') |
|---|
| 282 | )); |
|---|
| 283 | $menu = & $menu_ref_arr[0]; |
|---|
| 284 | if (($block = $menu->get_block( 'mbAdultContent' )) != null) { |
|---|
| 285 | $block->set_title(l10n('ac_title_menu_statut')); |
|---|
| 286 | $block->template = $this->get_template('choose.tpl'); |
|---|
| 287 | } |
|---|
| 288 | |
|---|
| 289 | } |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| 292 | }//fin placer_identification |
|---|
| 293 | function on_register() |
|---|
| 294 | { |
|---|
| 295 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
|---|
| 296 | $user_id = get_userid($_POST['login']); |
|---|
| 297 | log_user( $user_id, false); |
|---|
| 298 | redirect(PHPWG_ROOT_PATH.'plugins/adult_content/charte_user.php'); |
|---|
| 299 | } |
|---|
| 300 | }//fin class |
|---|
| 301 | ?> |
|---|