source: extensions/user_custom_fields/initprofile.php

Last change on this file was 32909, checked in by ddtddt, 16 months ago

[user_custom_fields] compatibility php8

File size: 3.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | User Custom Fields plugin for Piwigo by TEMMII                        |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2016-2022 ddtddt               http://temmii.com/piwigo/ |
6// +-----------------------------------------------------------------------+
7// | This program is free software; you can redistribute it and/or modify  |
8// | it under the terms of the GNU General Public License as published by  |
9// | the Free Software Foundation                                          |
10// |                                                                       |
11// | This program is distributed in the hope that it will be useful, but   |
12// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
13// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
14// | General Public License for more details.                              |
15// |                                                                       |
16// | You should have received a copy of the GNU General Public License     |
17// | along with this program; if not, write to the Free Software           |
18// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
19// | USA.                                                                  |
20// +-----------------------------------------------------------------------+
21
22//add prefiter
23add_event_handler('loc_begin_profile', 'ucfPI', 95 );
24
25function ucfPI(){
26  global $template;
27  $template->set_prefilter('profile_content', 'ucfPT');
28  $template->set_filename('ucf_profile_add', realpath(UCF_PATH.'ucf_profile_add.tpl'));
29  $template->assign_var_from_handle('UCF_PROFILE_ADD', 'ucf_profile_add');
30}
31
32function ucfPT($content){
33  $search = '/(<legend>{\'Registration).*({if \$ALLOW_USER_CUSTOMIZATION}
34  <fieldset>)/is';
35  return preg_replace($search, '{$UCF_PROFILE_ADD}'."\n".'{if $ALLOW_USER_CUSTOMIZATION}
36  <fieldset>', $content);
37 }
38
39add_event_handler('loc_begin_profile', 'ucfinitprofil');
40function ucfinitprofil(){
41  global $template, $userdata, $pwg_loaded_plugins, $conf;
42 if (isset($userdata['id'])){ 
43        if (isset($pwg_loaded_plugins['ExtendedDescription'])){
44                add_event_handler('AP_render_content', 'get_user_language_desc');
45    }
46  $tab_user_register=tab_user_custom_fields_register();
47 
48  $template->assign('UCF_USERNAME',$userdata['username']);
49  $template->assign('UCF_EMAIL',$userdata['email']);
50  $special_user = in_array($userdata['id'], array($conf['guest_id'], $conf['default_user_id']));
51  $template->assign('SPECIAL_USER', $special_user);
52  while ($info_users = pwg_db_fetch_assoc($tab_user_register)) {
53        $d=data_info_user($userdata['id'],$info_users['id_ucf']);
54        $row = pwg_db_fetch_assoc($d);
55        $items['UCFID'] = $info_users['id_ucf'];
56        $items['UCFWORDING'] = trigger_change('AP_render_content', $info_users['wording']);
57        $items['UCFOBLIGATORY'] = $info_users['obligatory'];
58        $items['UCFDATA'] = $row['data'] ?? '';
59
60        $template->append('edit_users_profil', $items);
61  }
62 }
63}
64
65 
66add_event_handler('save_profile_from_post', 'ucfPT2');
67function ucfPT2(){
68  global $prefixeTable,$userdata;
69  $profil_base_url = PHPWG_ROOT_PATH . '/profile.php';
70  foreach ($_POST['data'] AS $id_ucf => $data) {
71        $q = 'SELECT 1 FROM ' . UCFD_TABLE . ' WHERE id_user=' . $userdata['id'] . ' AND id_ucf=' . $id_ucf;
72        $test = pwg_query($q);
73        $row = pwg_db_fetch_assoc($test);
74        if (!empty($row)){
75          if ($data != ''){
76                $query = 'UPDATE ' . UCFD_TABLE . ' SET data="' . $data . '" WHERE id_user=' . $userdata['id'] . ' AND id_ucf=' . $id_ucf;
77                pwg_query($query);
78          }else{
79                $query = 'DELETE FROM ' . UCFD_TABLE . ' WHERE id_user=' . $userdata['id'] . ' AND id_ucf=' . $id_ucf;
80                pwg_query($query);
81          }
82        }else if ($data != ''){
83                $query = 'INSERT ' . UCFD_TABLE . '(id_user,id_ucf,data) VALUES (' . $userdata['id'] . ',' . $id_ucf . ',"' . $data . '");';
84                pwg_query($query);
85        }
86  }
87  redirect($profil_base_url); 
88}
89
90?>
Note: See TracBrowser for help on using the repository browser.