• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

XOOPS Cube Legacy base repository


Commit MetaInfo

Révisioned95cb666919a39624f1d4dc69fa46fa8baf8855 (tree)
l'heure2013-02-23 14:39:33
AuteurHIKAWA Kilica <kilica.hikawa@gmai...>
CommiterHIKAWA Kilica

Message de Log

Merge pull request #61 from nao-pon/fix_user_csv

[user] fix csv data import function

Change Summary

Modification

--- a/html/modules/user/admin/actions/UserDataDownloadAction.class.php
+++ b/html/modules/user/admin/actions/UserDataDownloadAction.class.php
@@ -77,7 +77,10 @@ class User_UserDataDownloadAction extends User_Action
7777
7878 /// japanese
7979 if (strncasecmp($GLOBALS['xoopsConfig']['language'], 'ja', 2)===0){
80- mb_convert_variables('SJIS', _CHARSET, $text);
80+ if (_CHARSET !== 'UTF-8') {
81+ mb_convert_variables('UTF-8', _CHARSET, $text);
82+ }
83+ $text = pack('C*',0xEF,0xBB,0xBF) . $text;
8184 }
8285
8386 if( preg_match('/firefox/i' , xoops_getenv('HTTP_USER_AGENT')) ){
--- a/html/modules/user/admin/actions/UserDataUploadConfAction.class.php
+++ b/html/modules/user/admin/actions/UserDataUploadConfAction.class.php
@@ -50,68 +50,83 @@ class User_UserDataUploadConfAction extends User_UserDataUploadAction
5050 $csv_encoding = mb_detect_encoding($_csv_contents);
5151 }
5252
53- foreach(file($csv_file) as $n=>$_data_line){
54- if ($csv_encoding){
55- mb_convert_variables(_CHARSET, $csv_encoding, $_data_line);
56- }
57- $_data = $this->explodeCSV($_data_line);
58- if (!$n || !implode('', $_data)){
59- continue;
60- }
61- $user_data = array(
62- 'error' => false,
63- 'update' => 0,
64- 'is_new' => true,
65- 'value' => array(),
66- );
67- if (count($_data) != count($user_key)){
68- $user_data['error'] = true;
53+ if (($handle = fopen($csv_file, 'r')) !== FALSE) {
54+ $current_locale = false;
55+ if ($csv_encoding === 'UTF-8') {
56+ $current_locale = setlocale(LC_ALL, '0');
57+ setlocale(LC_ALL, 'ja_JP.UTF-8');
58+ $bom = fread($handle, 3); // remove BOM
59+ if (ord($bom[0]) !== 0xef || ord($bom[1]) !== 0xbb || ord($bom[2]) !== 0xbf) {
60+ rewind($handle, 0); // BOM not found then do rewind
61+ }
6962 }
70- if ($_data[0]){
71- $user =& $user_h->get($_data[0]);
72- if ($user){
63+ $n = 0;
64+ while (($_data = fgetcsv($handle)) !== FALSE) {
65+ if ($csv_encoding){
66+ mb_convert_variables(_CHARSET, $csv_encoding, $_data);
67+ }
68+ if (!$n++ || !implode('', $_data)){
69+ continue;
70+ }
71+ $user_data = array(
72+ 'error' => false,
73+ 'update' => 0,
74+ 'is_new' => true,
75+ 'value' => array(),
76+ );
77+ if (count($_data) != count($user_key)){
78+ $user_data['error'] = true;
79+ }
80+ if ($_data[0]){
81+ $user =& $user_h->get($_data[0]);
82+ if ($user){
83+ for ($i=0; $i<count($user_key); $i++){
84+ $csv_value = $_data[$i];
85+ $user_value = $user->get($user_key[$i]);
86+ $update = $user_value != $csv_value;
87+ switch ($user_key[$i]){
88+ case 'user_regdate':
89+ case 'last_login':
90+ $update = ($user_value || $csv_value) && strcmp(formatTimestamp($user_value, 'Y/n/j H:i'), $csv_value)!==0;
91+ if ($update){
92+ }
93+ break;
94+ case 'pass':
95+ if (strlen($csv_value)!=32){
96+ $update = $user_value != md5($csv_value);
97+ $csv_value = md5($csv_value);
98+ }
99+ default:
100+ }
101+ $user_data['update'] = $user_data['update'] | $update;
102+ $user_data['value'][] = array(
103+ 'var' => $csv_value,
104+ 'update' => $update,
105+ );
106+ }
107+ $user_data['is_new'] = false;
108+ }
109+ }
110+ if ($user_data['is_new'] == true){
73111 for ($i=0; $i<count($user_key); $i++){
74- $csv_value = $_data[$i];
75- $user_value = $user->get($user_key[$i]);
76- $update = $user_value != $csv_value;
77- switch ($user_key[$i]){
112+ $var = isset($_data[$i]) && $_data[$i]!=='' ? $_data[$i] : $user_tmp->get($user_key[$i]);
113+ switch ($user_key[$i]){
78114 case 'user_regdate':
79115 case 'last_login':
80- $update = ($user_value || $csv_value) && strcmp(formatTimestamp($user_value, 'Y/n/j H:i'), $csv_value)!==0;
81- if ($update){
82- }
116+ $var = formatTimestamp($var, 'Y/n/j H:i');
83117 break;
84- case 'pass':
85- if (strlen($csv_value)!=32){
86- $update = $user_value != md5($csv_value);
87- $csv_value = md5($csv_value);
88- }
89- default:
90- }
91- $user_data['update'] = $user_data['update'] | $update;
118+ }
92119 $user_data['value'][] = array(
93- 'var' => $csv_value,
94- 'update' => $update,
95- );
120+ 'var' => $var,
121+ 'update' => 0);
96122 }
97- $user_data['is_new'] = false;
98123 }
124+ $csv_data[] = $user_data;
99125 }
100- if ($user_data['is_new'] == true){
101- for ($i=0; $i<count($user_key); $i++){
102- $var = isset($_data[$i]) && $_data[$i]!=='' ? $_data[$i] : $user_tmp->get($user_key[$i]);
103- switch ($user_key[$i]){
104- case 'user_regdate':
105- case 'last_login':
106- $var = formatTimestamp($var, 'Y/n/j H:i');
107- break;
108- }
109- $user_data['value'][] = array(
110- 'var' => $var,
111- 'update' => 0);
112- }
126+ if ($current_locale) {
127+ setlocale(LC_ALL, $current_locale);
113128 }
114- $csv_data[] = $user_data;
129+ fclose($handle);
115130 }
116131
117132 $render->setAttribute('csv_data', $csv_data);