Changeset 32693


Ignore:
Timestamp:
Jan 5, 2022, 6:56:27 PM (2 years ago)
Author:
ddtddt
Message:

[AddUsersNotes] compatybilité piwigo 12

Location:
extensions/AddUsersNotes
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/AddUsersNotes/main.inc.php

    r29854 r32693  
    2828 *   - load language
    2929 */
    30 function usernotes_init()
    31 {
    32   // load plugin language file
     30function usernotes_init(){
    3331  load_language('plugin.lang', USERNOTES_PATH);
     32    global $template;
     33  $template->assign(
     34    array(
     35         'USERNOTES_PATH2'=> get_root_url().USERNOTES_PATH,
     36    )
     37  );
    3438}
    3539
    3640add_event_handler('loc_begin_admin_page', 'usernotes_add_column');
    37 function usernotes_add_column()
    38 {
     41function usernotes_add_column(){
    3942  global $template;
     43        $template->set_prefilter('user_list', 'usernotes_add_column_prefilter');
     44}
     45
     46function usernotes_add_column_prefilter($content){
     47  // add the "Notes" column in the user table
     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       
     54  // add the "Notes" column in the user table
     55  $search = '      <!-- email adress -->
     56      <div class="user-header-col user-header-email not-in-selection-mode">
     57        <span>{\'Email Adress\'|@translate}</span>
     58      </div>';
     59  $content = str_replace($search, $search.'<!-- Notes -->
     60    <div class="user-header-col user-header-notes">
     61       <span>{\'Notes\'|@translate}</th></span>
     62    </div>'
     63        , $content);
     64
     65  // add the "Notes"
     66  $search = '<div class="user-col user-container-registration">';
     67  $replace = '    <div class="user-col user-container-usernotes">
     68      <span><!-- usernotes --></span>
     69    </div>';
     70  $content = str_replace($search, $replace.$search, $content);
     71
     72  // add the "Notes" field in user profile form
     73  $search = '<div class="user-property-group-container">
     74            <p class="user-property-label">{\'Groups\'|@translate}</p>
     75            <div class="user-property-select-container user-property-group">
     76              <select class="user-property-select" data-selectize="groups" placeholder="{\'Select groups or type them\'|translate}"
     77                name="group_id[]" multiple style="box-sizing:border-box;"></select>
     78            </div>
     79          </div>';
     80  $replace = '<p class="user-property-label">{\'Notes\'|@translate}</p>
     81                  <div class="user-property-usernotes">
     82            <span class="usernotes-title"><!-- usernotes --></span>
     83                        <span class="edit-usernotes icon-pencil"></span>
     84          </div>
     85                  <div class="user-property-usernotes-change">
     86            <div class="summary-input-container">
     87              <input class="usernotes-property-input user-property-input-usernotes" value="" placeholder="{\'Notes\'|@translate}" />
     88            </div>
     89            <span class="icon-ok edit-usernotes-validate"></span>
     90            <span class="icon-cancel-circled edit-usernotes-cancel"></span>
     91          </div>
     92                  ';
     93  $content = str_replace($search, $search.$replace, $content);
    4094 
    41         $template->set_prefilter('user_list', 'usernotes_add_column_prefilter');
    42 }
    43 
    44 function usernotes_add_column_prefilter($content, &$smarty)
    45 {
    46   // add the "Notes" column in the user table
    47   $search = '<th>{\'registration date\'|@translate}</th>';
    48   $content = str_replace($search, $search.'<th>{\'Notes\'|@translate}</th>', $content);
    49 
    50   // add the "Notes" field in user profile form
    51   $search = '#</div>\s*<div class="userPropertiesSet userPrefs">#ms';
    52   $replace = '<div class="userProperty"><strong>{\'Notes\'|translate}</strong><br><input type="text" name="usernotes" value="<%- user.usernotes %>" style="width:338px;"></div></div><div class="userPropertiesSet userPrefs">';
    53   $content = preg_replace($search, $replace, $content);
    54 
     95  //css
     96    $search = '</style>';
     97  $replace = '
     98  .user-property-usernotes-change {
     99    justify-content:center;
     100    align-items:center;
     101    display:none;
     102    margin-bottom:25px;
     103  }
     104 
     105  .user-property-usernotes {
     106    margin-bottom:34px;
     107    height:30px;
     108}
     109
     110.edit-usernotes-validate {
     111    display: block;
     112    margin: auto 5px;
     113    cursor: pointer;
     114    background-color: #ffa744;
     115    color: #3c3c3c;
     116    font-size: 17px;
     117    font-weight: 700;
     118    padding: 7px;
     119}
     120
     121.edit-usernotes-validate:hover {
     122    background-color: #f70;
     123    color: #000;
     124    cursor: pointer;
     125}
     126.edit-usernotes {
     127    font-size:1.4em;
     128    cursor:pointer;
     129}
     130.edit-usernotes-cancel {
     131    cursor:pointer;
     132    font-size:22px;
     133    padding-top: 4px;
     134}
     135.usernotes-property-input {
     136    width: 100%;
     137    box-sizing:border-box;
     138    font-size:1.1em;
     139    padding:8px 16px;
     140    border:none;
     141}
     142.edit-usernotes-title {
     143    font-size:1.4em;
     144}
     145.usernotes-property-input.user-property-input-usernotes {
     146    border: solid 2px #ffa744;
     147    padding: 9px;
     148}
     149                  ';
     150  $content = str_replace($search, $replace.$search, $content);
     151   
    55152  return $content;
    56153}
    57154
    58 add_event_handler('user_list_columns', 'usernotes_user_list_columns', EVENT_HANDLER_PRIORITY_NEUTRAL, 1);
    59 function usernotes_user_list_columns($aColumns)
    60 {
    61   $aColumns[] = 'usernotes';
    62  
    63   return $aColumns;
    64 }
    65 
    66155add_event_handler('ws_invoke_allowed', 'usernotes_ws_users_setInfo', EVENT_HANDLER_PRIORITY_NEUTRAL, 3);
    67 function usernotes_ws_users_setInfo($res, $methodName, $params)
    68 {
    69   if ($methodName != 'pwg.users.setInfo')
    70   {
     156function usernotes_ws_users_setInfo($res, $methodName, $params){
     157  if ($methodName != 'pwg.users.setInfo'){
    71158    return $res;
    72159  }
    73 
    74   if (!isset($_POST['usernotes']))
    75   {
     160  if (!isset($_POST['usernotes'])){
    76161    return $res;
    77162  }
    78  
    79   if (count($params['user_id']) == 0)
    80   {
     163  if (count($params['user_id']) == 0){
    81164    return $res;
    82165  }
     
    84167  $updates = array();
    85168
    86   foreach ($params['user_id'] as $user_id)
    87   {
     169  foreach ($params['user_id'] as $user_id){
    88170    $updates[] = array(
    89171      'user_id' => $user_id,
    90172      'usernotes' => $_POST['usernotes'],
    91       );
    92   }
    93  
    94   if (count($updates) > 0)
    95   {
     173    );
     174  }
     175  if (count($updates) > 0){
    96176    mass_updates(
    97177      USER_INFOS_TABLE,
     
    99179        'primary' => array('user_id'),
    100180        'update'  => array('usernotes')
    101         ),
     181      ),
    102182      $updates
    103       );
    104   }
    105  
     183    );
     184  }
    106185  return $res;
    107186}
    108187
    109188add_event_handler('ws_users_getList', 'usernotes_ws_users_getList', EVENT_HANDLER_PRIORITY_NEUTRAL, 1);
    110 function usernotes_ws_users_getList($users)
    111 {
     189function usernotes_ws_users_getList($users){
    112190  $user_ids = array();
    113   foreach ($users as $user_id => $user)
    114   {
     191  foreach ($users as $user_id => $user){
    115192    $user_ids[] = $user_id;
    116193  }
    117 
    118   if (count($user_ids) == 0)
    119   {
     194  if (count($user_ids) == 0){
    120195    return $users;
    121196  }
    122  
    123197  $query = '
    124 SELECT
    125     user_id,
    126     usernotes
    127   FROM '.USER_INFOS_TABLE.'
    128   WHERE user_id IN ('.implode(',', $user_ids).')
    129 ;';
     198    SELECT
     199      user_id,
     200      usernotes
     201    FROM '.USER_INFOS_TABLE.'
     202      WHERE user_id IN ('.implode(',', $user_ids).')
     203  ;';
    130204  $result = pwg_query($query);
    131   while ($row = pwg_db_fetch_assoc($result))
    132   {
     205  while ($row = pwg_db_fetch_assoc($result)){
    133206    $users[$row['user_id']]['usernotes'] = $row['usernotes'];
    134207  }
    135 
    136208  return $users;
    137209}
     210
    138211?>
Note: See TracChangeset for help on using the changeset viewer.