1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Add Users Notes |
---|
4 | Version: auto |
---|
5 | Description: Adds admin notes to users profiles |
---|
6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=580 |
---|
7 | Author: ddtddt |
---|
8 | Author URI: |
---|
9 | */ |
---|
10 | |
---|
11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
12 | |
---|
13 | global $prefixeTable; |
---|
14 | |
---|
15 | // +-----------------------------------------------------------------------+ |
---|
16 | // | Define plugin constants | |
---|
17 | // +-----------------------------------------------------------------------+ |
---|
18 | |
---|
19 | define('USERNOTES_ID', basename(dirname(__FILE__))); |
---|
20 | define('USERNOTES_PATH', PHPWG_PLUGINS_PATH.USERNOTES_ID.'/'); |
---|
21 | |
---|
22 | // init the plugin |
---|
23 | add_event_handler('init', 'usernotes_init'); |
---|
24 | |
---|
25 | /** |
---|
26 | * plugin initialization |
---|
27 | * - check for upgrades |
---|
28 | * - load language |
---|
29 | */ |
---|
30 | function 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 | |
---|
40 | add_event_handler('loc_begin_admin_page', 'usernotes_add_column'); |
---|
41 | function usernotes_add_column(){ |
---|
42 | global $template; |
---|
43 | $template->set_prefilter('user_list', 'usernotes_add_column_prefilter'); |
---|
44 | } |
---|
45 | |
---|
46 | function 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-help-circled 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 = '<div id="UserList" class="UserListPopIn"> |
---|
82 | |
---|
83 | <div class="UserListPopInContainer"> |
---|
84 | |
---|
85 | <a class="icon-cancel CloseUserList"></a> |
---|
86 | <div class="summary-properties-update-container"> |
---|
87 | <div class="summary-properties-container"> |
---|
88 | <div class="summary-container"> |
---|
89 | <div class="user-property-initials"> |
---|
90 | <div> |
---|
91 | <span class="icon-blue"><!-- Initials (JP) --></span> |
---|
92 | </div> |
---|
93 | </div> |
---|
94 | <div class="user-property-username"> |
---|
95 | <span class="edit-username-title"><!-- Name (Jessy Pinkman) --></span> |
---|
96 | <span class="edit-username-specifier"><!-- You specifire (you) --></span> |
---|
97 | <span class="edit-username icon-pencil"></span> |
---|
98 | </div> |
---|
99 | <div class="user-property-username-change"> |
---|
100 | <div class="summary-input-container"> |
---|
101 | <input class="user-property-input user-property-input-username" value="" placeholder="{\'Username\'|@translate}" /> |
---|
102 | </div> |
---|
103 | <span class="icon-ok edit-username-validate"></span> |
---|
104 | <span class="icon-cancel-circled edit-username-cancel"></span> |
---|
105 | </div> |
---|
106 | <div class="user-property-password-container"> |
---|
107 | <div class="user-property-password edit-password"> |
---|
108 | <p class="user-property-button"><span class="icon-key user-edit-icon"> </span>{\'Change Password\'|@translate}</p> |
---|
109 | </div> |
---|
110 | <div class="user-property-password-change"> |
---|
111 | <div class="summary-input-container"> |
---|
112 | <input class="user-property-input user-property-input-password" value="" placeholder="{\'Password\'|@translate}" /> |
---|
113 | </div> |
---|
114 | <span class="icon-ok edit-password-validate"></span> |
---|
115 | <span class="icon-cancel-circled edit-password-cancel"></span> |
---|
116 | </div> |
---|
117 | <div class="user-property-permissions"> |
---|
118 | <p class="user-property-button"> <span class="icon-lock user-edit-icon"> </span><a href="#" >{\'Permissions\'|@translate}</a></p> |
---|
119 | </div> |
---|
120 | </div> |
---|
121 | <div class="user-property-register-visit"> |
---|
122 | <span class="user-property-register"><!-- Registered date XX/XX/XXXX --></span> |
---|
123 | <span class="icon-calendar"></span> |
---|
124 | <span class="user-property-last-visit"><!-- Last Visit date XX/XX/XXXX --></span> |
---|
125 | </div>'; |
---|
126 | $replace = '<p class="user-property-label usernotes-label-edit">{\'Notes\'|@translate}<span class="edit-usernotes icon-pencil"></span></p> |
---|
127 | <div class="user-property-usernotes"> |
---|
128 | <span class="usernotes-title"><!-- usernotes --></span> |
---|
129 | </div> |
---|
130 | <div class="user-property-usernotes-change"> |
---|
131 | <div class="summary-input-container"> |
---|
132 | <input class="usernotes-property-input user-property-input-usernotes" value="" placeholder="{\'Notes\'|@translate}" /> |
---|
133 | </div> |
---|
134 | <span class="icon-ok edit-usernotes-validate"></span> |
---|
135 | <span class="icon-cancel-circled edit-usernotes-cancel"></span> |
---|
136 | </div> |
---|
137 | '; |
---|
138 | $content = str_replace($search, $search.$replace, $content); |
---|
139 | |
---|
140 | //css |
---|
141 | $search = '</style>'; |
---|
142 | $replace = ' |
---|
143 | .user-property-usernotes-change { |
---|
144 | justify-content:center; |
---|
145 | align-items:center; |
---|
146 | display:none; |
---|
147 | margin-bottom:25px; |
---|
148 | } |
---|
149 | |
---|
150 | .user-property-usernotes { |
---|
151 | margin-bottom:34px; |
---|
152 | height:30px; |
---|
153 | width: 100%; |
---|
154 | padding: 8px; |
---|
155 | background-color: #F3F3F3; |
---|
156 | padding-bottom: 16px; |
---|
157 | } |
---|
158 | |
---|
159 | .edit-usernotes-validate { |
---|
160 | display: block; |
---|
161 | margin: auto 5px; |
---|
162 | cursor: pointer; |
---|
163 | background-color: #ffa744; |
---|
164 | color: #3c3c3c; |
---|
165 | font-size: 17px; |
---|
166 | font-weight: 700; |
---|
167 | padding: 7px; |
---|
168 | } |
---|
169 | |
---|
170 | .edit-usernotes-validate:hover { |
---|
171 | background-color: #f70; |
---|
172 | color: #000; |
---|
173 | cursor: pointer; |
---|
174 | } |
---|
175 | .edit-usernotes { |
---|
176 | font-size:1.4em; |
---|
177 | cursor:pointer; |
---|
178 | color: #A4A4A4 !important; |
---|
179 | } |
---|
180 | .edit-usernotes-cancel { |
---|
181 | cursor:pointer; |
---|
182 | font-size:22px; |
---|
183 | padding-top: 4px; |
---|
184 | } |
---|
185 | .usernotes-property-input { |
---|
186 | width: 100%; |
---|
187 | box-sizing:border-box; |
---|
188 | font-size:1.1em; |
---|
189 | padding:8px 16px; |
---|
190 | border:none; |
---|
191 | } |
---|
192 | .edit-usernotes-title { |
---|
193 | font-size:1.4em; |
---|
194 | } |
---|
195 | .usernotes-title { |
---|
196 | color: #353535; |
---|
197 | display: flex; |
---|
198 | justify-content: left; |
---|
199 | |
---|
200 | --line-height: 1.4; |
---|
201 | --num-lines: 2; |
---|
202 | line-height: var(--line-height); |
---|
203 | display: block; |
---|
204 | height: calc(1em * var(--line-height) * var(--num-lines)); |
---|
205 | display: -webkit-box; |
---|
206 | -webkit-line-clamp: var(--num-lines); |
---|
207 | -webkit-box-orient: vertical; |
---|
208 | overflow: hidden; |
---|
209 | text-overflow: ellipsis; |
---|
210 | margin-bottom: 5px; |
---|
211 | } |
---|
212 | .usernotes-property-input.user-property-input-usernotes { |
---|
213 | border: solid 2px #ffa744; |
---|
214 | padding: 9px; |
---|
215 | } |
---|
216 | |
---|
217 | .user-header-usernotes{ |
---|
218 | width: 20%; |
---|
219 | max-width: 195px; |
---|
220 | } |
---|
221 | .user-container-usernotes { |
---|
222 | width: 20%; |
---|
223 | max-width: 195px; |
---|
224 | white-space: nowrap; |
---|
225 | overflow: hidden; |
---|
226 | text-overflow: ellipsis; |
---|
227 | } |
---|
228 | .user-container-usernotes span { |
---|
229 | max-width: 100%; |
---|
230 | |
---|
231 | overflow: hidden; |
---|
232 | text-overflow: ellipsis; |
---|
233 | } |
---|
234 | .usernotes-label-edit { |
---|
235 | align-self: flex-start; |
---|
236 | } |
---|
237 | |
---|
238 | .user-property-register-visit { |
---|
239 | margin-top: -15px; |
---|
240 | } |
---|
241 | '; |
---|
242 | $content = str_replace($search, $replace.$search, $content); |
---|
243 | |
---|
244 | return $content; |
---|
245 | } |
---|
246 | |
---|
247 | add_event_handler('ws_invoke_allowed', 'usernotes_ws_users_setInfo', EVENT_HANDLER_PRIORITY_NEUTRAL, 3); |
---|
248 | function usernotes_ws_users_setInfo($res, $methodName, $params){ |
---|
249 | if ($methodName != 'pwg.users.setInfo'){ |
---|
250 | return $res; |
---|
251 | } |
---|
252 | if (!isset($_POST['usernotes'])){ |
---|
253 | return $res; |
---|
254 | } |
---|
255 | if (count($params['user_id']) == 0){ |
---|
256 | return $res; |
---|
257 | } |
---|
258 | |
---|
259 | $updates = array(); |
---|
260 | |
---|
261 | foreach ($params['user_id'] as $user_id){ |
---|
262 | $updates[] = array( |
---|
263 | 'user_id' => $user_id, |
---|
264 | 'usernotes' => $_POST['usernotes'], |
---|
265 | ); |
---|
266 | } |
---|
267 | if (count($updates) > 0){ |
---|
268 | mass_updates( |
---|
269 | USER_INFOS_TABLE, |
---|
270 | array( |
---|
271 | 'primary' => array('user_id'), |
---|
272 | 'update' => array('usernotes') |
---|
273 | ), |
---|
274 | $updates |
---|
275 | ); |
---|
276 | } |
---|
277 | return $res; |
---|
278 | } |
---|
279 | |
---|
280 | add_event_handler('ws_users_getList', 'usernotes_ws_users_getList', EVENT_HANDLER_PRIORITY_NEUTRAL, 1); |
---|
281 | function usernotes_ws_users_getList($users){ |
---|
282 | $user_ids = array(); |
---|
283 | foreach ($users as $user_id => $user){ |
---|
284 | $user_ids[] = $user_id; |
---|
285 | } |
---|
286 | if (count($user_ids) == 0){ |
---|
287 | return $users; |
---|
288 | } |
---|
289 | $query = ' |
---|
290 | SELECT |
---|
291 | user_id, |
---|
292 | usernotes |
---|
293 | FROM '.USER_INFOS_TABLE.' |
---|
294 | WHERE user_id IN ('.implode(',', $user_ids).') |
---|
295 | ;'; |
---|
296 | $result = pwg_query($query); |
---|
297 | while ($row = pwg_db_fetch_assoc($result)){ |
---|
298 | $users[$row['user_id']]['usernotes'] = $row['usernotes']; |
---|
299 | } |
---|
300 | return $users; |
---|
301 | } |
---|
302 | |
---|
303 | ?> |
---|