source: extensions/AddUsersNotes/main.inc.php @ 32984

Last change on this file since 32984 was 32888, checked in by plg, 22 months ago

change icon to info (instead of help) + simplify search pattern in prefilter (compatibility 13.3.0)

File size: 6.7 KB
Line 
1<?php
2/*
3Plugin Name: Add Users Notes
4Version: auto
5Description: Adds admin notes to users profiles
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=580
7Author: ddtddt
8Author URI:
9*/
10
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12
13global $prefixeTable;
14
15// +-----------------------------------------------------------------------+
16// | Define plugin constants                                               |
17// +-----------------------------------------------------------------------+
18
19define('USERNOTES_ID', basename(dirname(__FILE__)));
20define('USERNOTES_PATH', PHPWG_PLUGINS_PATH.USERNOTES_ID.'/');
21
22// init the plugin
23add_event_handler('init', 'usernotes_init');
24
25/**
26 * plugin initialization
27 *   - check for upgrades
28 *   - load language
29 */
30function usernotes_init(){
31  load_language('plugin.lang', USERNOTES_PATH);
32  global $template;
33  $template->assign(
34    array(
35         'USERNOTES_PATH2'=> get_root_url().USERNOTES_PATH,
36    )
37  );
38}
39
40add_event_handler('loc_begin_admin_page', 'usernotes_add_column');
41function usernotes_add_column(){
42  global $template;
43        $template->set_prefilter('user_list', 'usernotes_add_column_prefilter');
44}
45
46function usernotes_add_column_prefilter($content){
47  // add js link
48  $search = '<div class="selection-mode-group-manager" style="right:30px">';
49  $replace = '{combine_script id="jquery.usersnotes" load=\'footer\' path="$USERNOTES_PATH2/js/usersnotes.js"}';
50  $content = str_replace($search, $replace.$search, $content);
51       
52       
53        // add "?" next to username for usernotes
54  $search = '<span><!-- name --></span>';
55
56  $replace = '<i class="user-notes-icon icon-info-circled-1 tiptip"> </i>';
57
58  $content = str_replace($search, $search.$replace, $content);
59
60  // add the "Notes" column in the user table
61  // $search = '<!-- groups -->
62  //      <div class="user-header-col user-header-groups">
63  //      <span>{\'Groups\'|@translate}</span>
64  //    </div>';
65  // $content = str_replace($search, $search.'<!-- Notes -->
66  //   <div class="user-header-col user-header-usernotes">
67  //      <span>{\'Notes\'|@translate}</th></span>
68  //   </div>'
69        // , $content);
70
71  // add the "Notes"
72  // $search = '<div class="user-col user-container-groups">
73  //     <!-- groups -->
74  //   </div>';
75  // $replace = '    <div class="user-col user-container-usernotes">
76  //     <span><!-- usernotes --></span>
77  //   </div>';
78  // $content = str_replace($search, $search.$replace, $content);
79
80  // add the "Notes" field in user profile form
81  $search = '<span class="user-property-register"><!-- Registered date XX/XX/XXXX --></span>
82            <span class="icon-calendar"></span>
83            <span class="user-property-last-visit"><!-- Last Visit date XX/XX/XXXX --></span>
84          </div>';
85  $replace = '<p class="user-property-label usernotes-label-edit">{\'Notes\'|@translate}<span class="edit-usernotes icon-pencil"></span></p>
86                  <div class="user-property-usernotes">
87            <span class="usernotes-title"><!-- usernotes --></span>
88          </div>
89                  <div class="user-property-usernotes-change">
90            <div class="summary-input-container">
91              <input class="usernotes-property-input user-property-input-usernotes" value="" placeholder="{\'Notes\'|@translate}" />
92            </div>
93            <span class="icon-ok edit-usernotes-validate"></span>
94            <span class="icon-cancel-circled edit-usernotes-cancel"></span>
95          </div>
96                  ';
97  $content = str_replace($search, $search.$replace, $content);
98 
99  //css
100    $search = '</style>';
101  $replace = '
102  .user-property-usernotes-change {
103    justify-content:center;
104    align-items:center;
105    display:none;
106    margin-bottom:25px;
107  }
108 
109  .user-property-usernotes {
110    margin-bottom:34px;
111    height:30px;
112    width: 100%;
113    padding: 8px;
114    background-color: #F3F3F3;
115    padding-bottom: 16px;
116}
117
118.edit-usernotes-validate {
119    display: block;
120    margin: auto 5px;
121    cursor: pointer;
122    background-color: #ffa744;
123    color: #3c3c3c;
124    font-size: 17px;
125    font-weight: 700;
126    padding: 7px;
127}
128
129.edit-usernotes-validate:hover {
130    background-color: #f70;
131    color: #000;
132    cursor: pointer;
133}
134.edit-usernotes {
135    font-size:1.4em;
136    cursor:pointer;
137    color: #A4A4A4 !important;
138}
139.edit-usernotes-cancel {
140    cursor:pointer;
141    font-size:22px;
142    padding-top: 4px;
143}
144.usernotes-property-input {
145    width: 100%;
146    box-sizing:border-box;
147    font-size:1.1em;
148    padding:8px 16px;
149    border:none;
150}
151.edit-usernotes-title {
152    font-size:1.4em;
153}
154.usernotes-title {
155  color: #353535;
156  display: flex;
157  justify-content: left;
158
159  --line-height: 1.4;
160  --num-lines: 2;
161  line-height: var(--line-height);
162  display: block;
163  height: calc(1em * var(--line-height) * var(--num-lines));
164  display: -webkit-box;
165  -webkit-line-clamp: var(--num-lines);
166  -webkit-box-orient: vertical;
167  overflow: hidden;
168  text-overflow: ellipsis;
169  margin-bottom: 5px;
170}
171.usernotes-property-input.user-property-input-usernotes {
172    border: solid 2px #ffa744;
173    padding: 9px;
174}
175
176.user-header-usernotes{
177  width: 20%;
178  max-width: 195px;
179}
180.user-container-usernotes {
181  width: 20%;
182  max-width: 195px;
183  white-space: nowrap;
184  overflow: hidden;
185  text-overflow: ellipsis;
186}
187.user-container-usernotes span {
188  max-width: 100%;
189
190  overflow: hidden;
191  text-overflow: ellipsis;
192}
193.usernotes-label-edit {
194  align-self: flex-start;
195}
196
197.user-property-register-visit {
198  margin-top: -15px;
199}
200                  ';
201  $content = str_replace($search, $replace.$search, $content);
202   
203  return $content;
204}
205
206add_event_handler('ws_invoke_allowed', 'usernotes_ws_users_setInfo', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
207function usernotes_ws_users_setInfo($res, $methodName, $params){
208  if ($methodName != 'pwg.users.setInfo'){
209    return $res;
210  }
211  if (!isset($_POST['usernotes'])){
212    return $res;
213  }
214  if (count($params['user_id']) == 0){
215    return $res;
216  }
217 
218  $updates = array();
219
220  foreach ($params['user_id'] as $user_id){
221    $updates[] = array(
222      'user_id' => $user_id,
223      'usernotes' => $_POST['usernotes'],
224    );
225  }
226  if (count($updates) > 0){
227    mass_updates(
228      USER_INFOS_TABLE,
229      array(
230        'primary' => array('user_id'),
231        'update'  => array('usernotes')
232      ),
233      $updates
234    );
235  }
236  return $res;
237}
238
239add_event_handler('ws_users_getList', 'usernotes_ws_users_getList', EVENT_HANDLER_PRIORITY_NEUTRAL, 1);
240function usernotes_ws_users_getList($users){
241  $user_ids = array();
242  foreach ($users as $user_id => $user){
243    $user_ids[] = $user_id;
244  }
245  if (count($user_ids) == 0){
246    return $users;
247  }
248  $query = '
249    SELECT
250      user_id,
251      usernotes
252    FROM '.USER_INFOS_TABLE.'
253      WHERE user_id IN ('.implode(',', $user_ids).')
254  ;';
255  $result = pwg_query($query);
256  while ($row = pwg_db_fetch_assoc($result)){
257    $users[$row['user_id']]['usernotes'] = $row['usernotes'];
258  }
259  return $users;
260}
261
262?>
Note: See TracBrowser for help on using the repository browser.