Changeset 10549


Ignore:
Timestamp:
Apr 21, 2011, 11:09:53 PM (14 years ago)
Author:
LucMorizur
Message:

Code cleaning

Location:
extensions/LCAS/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/LCAS/trunk/admin/LCAS_admin.php

    r10270 r10549  
    99check_status(ACCESS_ADMINISTRATOR);
    1010
    11 if (!defined('LCAS_PATH')) define('LCAS_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
    12 if (!defined('LCAS_PATH_ABS')) define('LCAS_PATH_ABS' ,  dirname(__FILE__).'/');
     11if (!defined('LCAS_PATH'))
     12 define('LCAS_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
     13if (!defined('LCAS_PATH_ABS'))
     14 define('LCAS_PATH_ABS' ,  dirname(__FILE__).'/');
    1315
    1416//ini_set('error_reporting', E_ALL);
     
    3032$version = $plugin['version'];
    3133
    32         if (isset($_POST['submit']) and isset($_POST['LCAS_Option']) and isset($_POST['LCAS_Mail']))
     34if (isset($_POST['submit'])
     35 and isset($_POST['LCAS_Option'])
     36 and isset($_POST['LCAS_Mail']))
     37{
     38
     39/* General configuration settings */
     40  $_POST['LCAS_MailText'] = str_replace('\"', '"', str_replace("\'", "'",
     41   str_replace("\\\\", "\\", $_POST['LCAS_MailText'])));
     42 
     43  $newconf_LCAS= array(
     44    $_POST['LCAS_Option'],
     45    $_POST['LCAS_Mail'],
     46    $_POST['LCAS_MailText']);
     47
     48  $conf['LoginCaseAccentsSensitivity'] = serialize($newconf_LCAS);
     49
     50  $query = '
     51    UPDATE '.CONFIG_TABLE.'
     52    SET value="'.addslashes($conf['LoginCaseAccentsSensitivity']).'"
     53    WHERE param="LoginCaseAccentsSensitivity"
     54    LIMIT 1
     55    ;';
     56 
     57  pwg_query($query);
     58
     59  array_push($page['infos'], l10n('LCAS_save_config'));
     60}
     61
     62$conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
     63
     64if (isset($conf_LCAS[0]))
     65{
     66  $case_ins = ($conf_LCAS[0] == '1' or $conf_LCAS[0] == '3');
     67  $acc_ins = ($conf_LCAS[0] == '2' or $conf_LCAS[0] == '3');
     68
     69  if ($case_ins or $acc_ins)
    3370  {
    3471
    35 /* General configuration settings */
    36                 $_POST['LCAS_MailText'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['LCAS_MailText'])));
    37    
    38     $newconf_LCAS= array(
    39       $_POST['LCAS_Option'],
    40       $_POST['LCAS_Mail'],
    41       $_POST['LCAS_MailText']);
    42 
    43     $conf['LoginCaseAccentsSensitivity'] = serialize($newconf_LCAS);
    44 
    45                 $query = '
    46                 UPDATE '.CONFIG_TABLE.'
    47                 SET value="'.addslashes($conf['LoginCaseAccentsSensitivity']).'"
    48                 WHERE param="LoginCaseAccentsSensitivity"
    49                 LIMIT 1
    50                 ;';
    51                
    52                 pwg_query($query);
    53 
    54     array_push($page['infos'], l10n('LCAS_save_config'));
    55   }
    56 
    57         $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
    58  
    59   if (isset($conf_LCAS[0]))
    60   {
    61     $case_ins = ($conf_LCAS[0] == '1' or $conf_LCAS[0] == '3');
    62     $acc_ins = ($conf_LCAS[0] == '2' or $conf_LCAS[0] == '3');
    63 
    64     if ($case_ins or $acc_ins)
     72// +-----------------------------------------------------------------------+
     73// |                               user list                               |
     74// +-----------------------------------------------------------------------+
     75
     76    $page['all_users'] = LCAS_get_user_list($conf_LCAS[0]);
     77
     78// +-----------------------------------------------------------------------+
     79// |                           initialization                              |
     80// +-----------------------------------------------------------------------+
     81
     82    $lcas_UserToUpdate = -1;
     83    if ((isset($_POST['UserToUpdate'])) && ($_POST['UserToUpdate'] != -1)) {
     84      $lcas_UserToUpdate = $_POST['UserToUpdate'];
     85     
     86      if ((isset($_POST['user-'.$lcas_UserToUpdate])) &&
     87       ($_POST['user-'.$lcas_UserToUpdate] != '')) {
     88
     89        // Check if username already exists
     90        $lcas_previous_compare_user =
     91         LCAS_change_case($_POST['user-'.$lcas_UserToUpdate], $conf_LCAS[0]);
     92
     93        $LCAS_users = array();
     94
     95        // This is a dirty request - Works fine for small number of users
     96        // but could be unoptimized for large number of users
     97        $query = '
     98          SELECT '.$conf['user_fields']['username'].' AS username
     99          FROM '.USERS_TABLE.';';
     100       
     101        $res = pwg_query($query);
     102        while ($r = pwg_db_fetch_assoc($res))
     103        {
     104          $LCAS_users[$r['username']] =
     105           LCAS_change_case($r['username'], $conf_LCAS[0]);
     106        }
     107         
     108        $users_found = array_keys($LCAS_users, $lcas_previous_compare_user);
     109
     110        if (count($users_found) < 1)
     111        {
     112          // Get old username before update -
     113          // Useful for user notification if is set
     114          $query ='
     115            SELECT username
     116            FROM '.USERS_TABLE.'
     117            WHERE id = '.$lcas_UserToUpdate.'
     118          ;';
     119
     120          $data = pwg_db_fetch_assoc(pwg_query($query));
     121
     122          // Username update
     123          $query = '
     124            UPDATE '.USERS_TABLE.'
     125            SET username="'.addslashes($_POST['user-'.$lcas_UserToUpdate]).'"
     126            WHERE id='.$lcas_UserToUpdate.'
     127            LIMIT 1
     128            ;';
     129
     130          pwg_query($query);
     131
     132          if (isset($conf_LCAS[1]) and $conf_LCAS[1] == 'true')
     133          {
     134            LCAS_SendMail($lcas_UserToUpdate, $data['username'],
     135             $_POST['user-'.$lcas_UserToUpdate]);
     136          }
     137
     138          // Reloading conflict table content
     139          $page['all_users'] = LCAS_get_user_list($conf_LCAS[0]);
     140          array_push($page['infos'],
     141           l10n('LCAS_Info_userlist_username_renamed'));
     142        }
     143        else
     144        {
     145          // Username already exists
     146          array_push(
     147            $page['errors'],
     148            l10n('LCAS_Err_Userlist_New_Username_Exists').
     149             '<br>"'.$lcas_previous_compare_user.'"'
     150          );
     151        }
     152      }
     153      else {
     154        // Username is empty
     155        array_push($page['errors'],
     156         l10n('LCAS_Err_Userlist_Empty_New_Username'));
     157      }
     158    }
     159
     160// +-----------------------------------------------------------------------+
     161// |                               user list                               |
     162// +-----------------------------------------------------------------------+
     163
     164    $lcas_previous_compare_user = '';
     165    $visible_user_list          = array();
     166    foreach ($page['all_users'] as $local_user)
    65167    {
    66 
    67 // +-----------------------------------------------------------------------+
    68 // |                               user list                               |
    69 // +-----------------------------------------------------------------------+
    70 
    71       $page['all_users'] = LCAS_get_user_list($conf_LCAS[0]);
    72 
    73 // +-----------------------------------------------------------------------+
    74 // |                           initialization                              |
    75 // +-----------------------------------------------------------------------+
    76 
    77       $lcas_UserToUpdate = -1;
    78       if ((isset($_POST['UserToUpdate'])) && ($_POST['UserToUpdate'] != -1)) {
    79         $lcas_UserToUpdate = $_POST['UserToUpdate'];
    80        
    81         if ((isset($_POST['user-'.$lcas_UserToUpdate])) && ($_POST['user-'.$lcas_UserToUpdate] != '')) {
    82 
    83           // Check if username already exists
    84                 $lcas_previous_compare_user = LCAS_change_case($_POST['user-'.$lcas_UserToUpdate], $conf_LCAS[0]);
    85 
    86           $LCAS_users = array();
    87 
    88           // This is a dirty request - Works fine for small number of users but could be unoptimized for large number of users
    89           $query = '
    90             SELECT '.$conf['user_fields']['username'].' AS username
    91             FROM '.USERS_TABLE.';';
    92          
    93           $res = pwg_query($query);
    94           while ($r = pwg_db_fetch_assoc($res))
    95           {
    96             $LCAS_users[$r['username']] = LCAS_change_case($r['username'], $conf_LCAS[0]);
    97           }
    98            
    99           $users_found = array_keys($LCAS_users, $lcas_previous_compare_user);
    100 
    101           if (count($users_found) < 1)
    102           {
    103             // Get old username before update - Usefull for user notification if is set
    104             $query ='
    105               SELECT username
    106               FROM '.USERS_TABLE.'
    107               WHERE id = '.$lcas_UserToUpdate.'
    108             ;';
    109 
    110             $data = pwg_db_fetch_assoc(pwg_query($query));
    111  
    112             // Username update
    113             $query = '
    114               UPDATE '.USERS_TABLE.'
    115               SET username="'.addslashes($_POST['user-'.$lcas_UserToUpdate]).'"
    116               WHERE id='.$lcas_UserToUpdate.'
    117               LIMIT 1
    118               ;';
    119 
    120             pwg_query($query);
    121 
    122             if (isset($conf_LCAS[1]) and $conf_LCAS[1] == 'true')
    123             {
    124               LCAS_SendMail($lcas_UserToUpdate, $data['username'], $_POST['user-'.$lcas_UserToUpdate]);
    125             }
    126 
    127             // Reloading conflict table content
    128             $page['all_users'] = LCAS_get_user_list($conf_LCAS[0]);
    129             array_push($page['infos'], l10n('LCAS_Info_userlist_username_renamed'));
    130           }
    131           else
    132           {
    133             // Username already exists
    134             array_push($page['errors'], l10n('LCAS_Err_Userlist_New_Username_Exists').'<br>"'.$lcas_previous_compare_user.'"');
    135           }
    136         }
    137         else {
    138           // Username is empty
    139           array_push($page['errors'], l10n('LCAS_Err_Userlist_Empty_New_Username'));
    140         }
    141       }
    142 
    143 // +-----------------------------------------------------------------------+
    144 // |                               user list                               |
    145 // +-----------------------------------------------------------------------+
    146 
    147       $lcas_previous_compare_user = '';
    148       $visible_user_list          = array();
    149       foreach ($page['all_users'] as $local_user)
    150       {
    151         if ($lcas_previous_compare_user != $local_user['transformed']) {
    152           $display = 'orange';
    153           $lcas_previous_compare_user = $local_user['transformed'];
    154         }
    155         else {
    156           $display = '';
    157         }
    158 
    159         $template->append(
    160           'users',
    161           array(
    162             'ID'          => $local_user['id'],
    163             'USERNAME'    => stripslashes($local_user['username']),
    164             'COMPARE'     => stripslashes($local_user['transformed']),
    165             'EMAIL'       => get_email_address_as_display_text($local_user['email']),
    166             'DISPLAY'     => $display,
    167           )
    168         );
    169       }
    170      
     168      if ($lcas_previous_compare_user != $local_user['transformed']) {
     169        $display = 'orange';
     170        $lcas_previous_compare_user = $local_user['transformed'];
     171      }
     172      else {
     173        $display = '';
     174      }
     175
     176      $template->append(
     177        'users',
     178        array(
     179          'ID'          => $local_user['id'],
     180          'USERNAME'    => stripslashes($local_user['username']),
     181          'COMPARE'     => stripslashes($local_user['transformed']),
     182          'EMAIL'       =>
     183           get_email_address_as_display_text($local_user['email']),
     184          'DISPLAY'     => $display,
     185        )
     186      );
    171187    }
    172188  }
     189}
    173190
    174191
     
    176193// |                           templates init                              |
    177194// +-----------------------------------------------------------------------+
    178   $template->assign(
    179     array(
    180     'LCAS_VERSION'                  => $version,
    181     'LCAS_PATH'                     => LCAS_PATH,
    182     'PHPWG_VERSION'                 => PHPWG_VERSION,
    183     'LCAS_PATH_ABS'                 => LCAS_PATH_ABS,
    184                 'LCAS_Option'                   => $conf_LCAS[0],
    185                 'LCAS_MAIL_TRUE'                => $conf_LCAS[1] == 'true'  ? 'checked = "checked"' : '' ,
    186                 'LCAS_MAIL_FALSE'              => $conf_LCAS[1] == 'false' ? 'checked = "checked"' : '' ,
    187     'LCAS_MAILTEXT'                 => $conf_LCAS[2]
    188     )
    189   );
     195$template->assign(
     196  array(
     197  'LCAS_VERSION'    => $version,
     198  'LCAS_PATH'       => LCAS_PATH,
     199  'PHPWG_VERSION'   => PHPWG_VERSION,
     200  'LCAS_PATH_ABS'   => LCAS_PATH_ABS,
     201  'LCAS_Option'     => $conf_LCAS[0],
     202  'LCAS_MAIL_TRUE'  => $conf_LCAS[1] == 'true'  ? 'checked = "checked"' : '' ,
     203  'LCAS_MAIL_FALSE' => $conf_LCAS[1] == 'false' ? 'checked = "checked"' : '' ,
     204  'LCAS_MAILTEXT'   => $conf_LCAS[2]
     205  )
     206);
    190207
    191208
     
    193210// |                             errors display                            |
    194211// +-----------------------------------------------------------------------+
    195   if (isset ($errors) and count($errors) != 0)
     212if (isset ($errors) and count($errors) != 0)
     213{
     214  $template->assign('errors',array());
     215  foreach ($errors as $error)
    196216  {
    197           $template->assign('errors',array());
    198           foreach ($errors as $error)
    199           {
    200                   array_push($page['errors'], $error);
    201                 }
    202         } 
     217    array_push($page['errors'], $error);
     218  }
     219
    203220
    204221// +-----------------------------------------------------------------------+
    205222// |                           templates display                           |
    206223// +-----------------------------------------------------------------------+
    207   $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/global.tpl');
    208   $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
     224$template->set_filename('plugin_admin_content',
     225 dirname(__FILE__) . '/template/global.tpl');
     226$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
    209227
    210228?>
  • extensions/LCAS/trunk/include/admin_search.inc.php

    r10116 r10549  
    11<?php
    2 // Keeps file coded in UTF-8 without BOM: é
     2// Keep file coded in UTF-8 without BOM: é
    33
    44if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     
    3737  $filter = array();
    3838
    39     // Build a PHP regex both complying to user's request, and to LCAS current
    40     // rule
     39    // Build a PHP regex both complying to user's request,
     40    // and to LCAS current rule
    4141    $username=  preg_replace(array('/^\*/', '/\*$/'), '%', $_GET['username']);
    4242    if (preg_match('/%$/', $username))
     
    233233// allow plugins to fill template var plugin_user_list_column_titles and
    234234// plugin_columns/plugin_actions for each user in the list
    235 $visible_user_list = trigger_event('loc_visible_user_list', $visible_user_list);
     235$visible_user_list =
     236 trigger_event('loc_visible_user_list', $visible_user_list);
    236237
    237238foreach ($visible_user_list as $local_user)
     
    262263    $properties[] = l10n( sprintf('Level %d', $local_user['level']) );
    263264  }
    264   $properties[] =
    265     (isset($local_user['enabled_high']) and ($local_user['enabled_high'] == 'true'))
    266         ? l10n('High definition') : l10n('');
     265  $properties[] = (
     266    isset($local_user['enabled_high']) and
     267    ($local_user['enabled_high'] == 'true')
     268  ) ? l10n('High definition') : l10n('');
    267269
    268270  $template->append(
     
    282284      'GROUPS' => $groups_string,
    283285      'PROPERTIES' => implode( ', ', $properties),
    284       'plugin_columns' => isset($local_user['plugin_columns']) ? $local_user['plugin_columns'] : array(),
    285       'plugin_actions' => isset($local_user['plugin_actions']) ? $local_user['plugin_actions'] : array(),
     286      'plugin_columns' => isset($local_user['plugin_columns']) ?
     287       $local_user['plugin_columns'] : array(),
     288      'plugin_actions' => isset($local_user['plugin_actions']) ?
     289       $local_user['plugin_actions'] : array(),
    286290      )
    287291    );
  • extensions/LCAS/trunk/include/functions.inc.php

    r9499 r10549  
    11<?php
    22          // Keeps file coded in UTF-8 without BOM : é
     3
    34include_once (LCAS_PATH.'include/constants.php');
    45load_language('plugin.lang', LCAS_PATH);
     
    2021
    2122/**
    22  * Changes the characters of the given string as stated by values of
     23 * Change the characters of the given string as stated by values of
    2324 * $conf['insensitive_case_logon'] and $conf['LCAS_replacement_set'].
    2425 *
     
    6970}
    7071
    71 
    72 
    73 
    74 
    75 
    76 
    77 
    78 
    79 
    80 
    81 
    8272/* Function called from LCAS_admin.php to send notification email */
    8373function LCAS_SendMail($id, $oldusername, $username)
     
    9787  $data = pwg_db_fetch_assoc(pwg_query($query));
    9888
    99 /* Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language */
     89  // Check if user is already registered (profile changing) -
     90  // If not (new registration), language is set to current gallery language
    10091  if (empty($data))
    10192  {
    102 /* And switch gallery to this language before using personalized and multilangual contents */
     93    // And switch gallery to this language before using personalized
     94    // and multilangual contents
    10395    $language = pwg_get_session_var( 'lang_switch', $user['language'] );
    10496    switch_lang_to($language);
     
    10698  else
    10799  {
    108 /* And switch gallery to this language before using personalized and multilangual contents */
     100    // And switch gallery to this language before using personalized
     101    // and multilangual contents
    109102    switch_lang_to($data['language']);
    110103    load_language('plugin.lang', LCAS_PATH);
    111104  }
    112105
    113   $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Username_updated_for_%s', stripslashes($oldusername)));
     106  $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args(
     107   'Username_updated_for_%s', stripslashes($oldusername)));
    114108
    115109  if (isset($conf_LCAS[2]) and $conf_LCAS[2] <> '')
     
    143137    'content' => ($customtxt."\n\n").(l10n_args($info)),
    144138  ));
    145 
    146 /* Switching back to default language */
    147 switch_lang_back();
    148 }
    149 
    150 
    151 /* Function called from LCAS_admin.php and main.inc.php to get the plugin version and name */
     139 
     140  /* Switching back to default language */
     141  switch_lang_back();
     142}
     143
     144
     145// Function called from LCAS_admin.php and main.inc.php
     146// to get the plugin version and name
    152147function LCAS_PluginInfos($dir)
    153148{
     
    167162    $plugin['uri'] = trim($val[1]);
    168163  }
    169   if ($desc = load_language('description.txt', $path.'/', array('return' => true)))
     164  if ($desc =
     165   load_language('description.txt', $path.'/', array('return' => true)))
    170166  {
    171167    $plugin['description'] = trim($desc);
     
    183179    $plugin['author uri'] = trim($val[1]);
    184180  }
    185   if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid='))
     181  if (!empty($plugin['uri']) and
     182   strpos($plugin['uri'] , 'extension_view.php?eid='))
    186183  {
    187184    list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']);
     
    326323}
    327324
    328 
    329 /*
    330  * str_from_var3($var)
    331  * returns a string easing array var informations displaying in Piwigo :
    332  *   _ the string return value starts with"<p style = "text-align:left;">" ;
    333  *   _ all "TAB" characters (chr(10)) are replaced by "<br>" ;
    334  *   _ all spaces are replaced by "&nbsp;".
    335  *
    336  * @param
    337  *   $var : variable to display
    338  * @return
    339  *   string easy to display in Piwigo
    340  */
    341 function str_from_var3($var) {
    342   return
    343    '<p style = "text-align:left;">'.
    344    str_replace(
    345     chr(10),'<br>',
    346     str_replace(' ','&nbsp;', print_r /* var_dump */ ($var,true))
    347    ).
    348    '</p>';
    349 }
    350 
    351 
    352 // DebugLog function
    353 function DebugLog($var1, $var2, $var3, $var4, $var5)
    354 {
    355    $fo=fopen (LCAS_PATH.'admin/debuglog.txt','a') ;
    356    fwrite($fo,"======================\n") ;
    357    fwrite($fo,'le ' . date('D, d M Y H:i:s') . "\r\n");
    358    fwrite($fo, "\n" . $var1 . "\r\n") ;
    359    fwrite($fo, "\n" . $var2 . "\r\n") ;
    360    fwrite($fo, "\n" . $var3 . "\r\n") ;
    361    fwrite($fo, "\n" . $var4 . "\r\n") ;
    362    fwrite($fo, "\n" . $var5 . "\r\n") ;
    363    fclose($fo) ;
    364 }
    365325?>
Note: See TracChangeset for help on using the changeset viewer.