25
25
26
26
class plgSystemCfi extends CMSPlugin
27
27
{
28
+ const BOM = "\xEF" . "\xBB" . "\xBF" ; // UTF BOM signature
29
+
28
30
private $ _app ;
29
31
private $ _doc ;
30
32
private $ _user ;
@@ -115,10 +117,10 @@ public function onAfterRender()
115
117
116
118
$ db = Factory::getDbo ();
117
119
$ query = $ db ->getQuery (true )
118
- ->select ('`id`, ` title` ' )
119
- ->from ('` #__categories` ' )
120
- ->where ('` extension` = "com_content" ' )
121
- ->order ('` title` ' );
120
+ ->select ('id, title ' )
121
+ ->from ('#__categories ' )
122
+ ->where ('extension = "com_content" ' )
123
+ ->order ('title ' );
122
124
$ db ->setQuery ($ query );
123
125
try {
124
126
$ categories = $ db ->loadObjectList ();
@@ -147,17 +149,17 @@ public function onAfterRender()
147
149
148
150
public function onAjaxCfi ()
149
151
{
150
- Log::addLogger (['text_file ' => 'cfi.php ' , 'text_entry_format ' => "{DATETIME} \t{PRIORITY} \t{MESSAGE} " ], Log::ALL );
152
+ Log::addLogger (['textfile ' => 'cfi.php ' , 'text_entry_format ' => "{DATETIME} \t{PRIORITY} \t{MESSAGE} " ], Log::ALL );
151
153
152
154
$ state = $ this ->_app ->input ->get ('cfistate ' , '' );
153
155
154
156
if (!Session::checkToken ($ state == 'download ' ? 'get ' : 'post ' )) {
155
157
$ data = [
156
158
'result ' => Text::_ ('JINVALID_TOKEN ' ),
157
159
'user ' => $ this ->_user ,
158
- 'file ' => $ _FILES ,
159
- 'get ' => $ _GET ,
160
- 'post ' => $ _POST
160
+ 'file ' => $ this -> _app -> input -> files -> getArray () ,
161
+ 'get ' => $ this -> _app -> input -> get -> getArray () ,
162
+ 'post ' => $ this -> _app -> input -> post -> getArray ()
161
163
];
162
164
Log::add (json_encode ($ data ), Log::ERROR );
163
165
$ this ->_printJson ($ data ['result ' ]);
@@ -175,7 +177,7 @@ public function onAjaxCfi()
175
177
if ($ state == 'download ' ) {
176
178
$ this ->_file = $ this ->_app ->input ->get ('f ' , '' );
177
179
if ($ this ->_file ) {
178
- $ this ->_file = base64_decode ( $ this ->_file );
180
+ $ this ->_file = Path:: clean (Factory:: getConfig ()-> get ( ' tmp_path ' ) . ' / ' . urldecode ( $ this ->_file ) );
179
181
$ this ->_fileDownload ($ this ->_file );
180
182
@unlink ($ this ->_file );
181
183
}
@@ -201,34 +203,34 @@ private function _checkFile($file)
201
203
if (is_array ($ file ) && count ($ file )) {
202
204
203
205
if ($ file ['error ' ] != 0 ) {
204
- $ data ['result ' ] = Text::_ ('PLG_CFI_FILE_ERROR ' );
206
+ $ data ['result ' ] = Text::_ ('PLG_CFIfile_ERROR ' );
205
207
Log::add (json_encode ($ data ), Log::ERROR );
206
208
$ this ->_printJson ($ data ['result ' ]);
207
209
}
208
210
209
211
if (!$ file ['size ' ]) {
210
- $ data ['result ' ] = Text::_ ('PLG_CFI_FILE_SIZE ' );
212
+ $ data ['result ' ] = Text::_ ('PLG_CFIfile_SIZE ' );
211
213
Log::add (json_encode ($ data ), Log::ERROR );
212
214
$ this ->_printJson ($ data ['result ' ]);
213
215
}
214
216
215
217
if (pathinfo ($ file ['name ' ], PATHINFO_EXTENSION ) !== 'csv ' ) {
216
- $ data ['result ' ] = Text::_ ('PLG_CFI_FILE_TYPE ' );
218
+ $ data ['result ' ] = Text::_ ('PLG_CFIfile_TYPE ' );
217
219
Log::add (json_encode ($ data ), Log::ERROR );
218
220
$ this ->_printJson ($ data ['result ' ]);
219
221
}
220
222
221
223
$ this ->_file = Path::clean (Factory::getConfig ()->get ('tmp_path ' ) . '/cfi_ ' . date ('Y-m-d-H-i-s ' ) . '.csv ' );
222
224
if (!@move_uploaded_file ($ file ['tmp_name ' ], $ this ->_file )) {
223
- $ data ['result ' ] = Text::_ ('PLG_CFI_FILE_MOVE ' );
225
+ $ data ['result ' ] = Text::_ ('PLG_CFIfile_MOVE ' );
224
226
Log::add (json_encode ($ data ), Log::ERROR );
225
227
$ this ->_printJson ($ data ['result ' ]);
226
228
}
227
229
228
230
return true ;
229
231
}
230
232
231
- $ data ['result ' ] = Text::_ ('PLG_CFI_FILE_NOTHING ' );
233
+ $ data ['result ' ] = Text::_ ('PLG_CFIfile_NOTHING ' );
232
234
Log::add (json_encode ($ data ), Log::ERROR );
233
235
$ this ->_printJson ($ data ['result ' ]);
234
236
}
@@ -259,7 +261,7 @@ private function _importData()
259
261
}
260
262
261
263
// unset utf-8 bom
262
- $ content = str_replace ("\xEF\xBB\xBF" , '' , $ content );
264
+ $ content = str_replace ($ this -> BOM , '' , $ content );
263
265
264
266
// line separator definition
265
267
$ rowDelimiter = "\r\n" ;
@@ -425,10 +427,10 @@ private function _getCategories()
425
427
{
426
428
$ db = Factory::getDbo ();
427
429
$ query = $ db ->getQuery (true )
428
- ->select ('`id` ' )
429
- ->from ('` #__categories` ' )
430
- ->where ('` extension` = "com_content" ' )
431
- ->order ('`id` ' );
430
+ ->select ('id ' )
431
+ ->from ('#__categories ' )
432
+ ->where ('extension = "com_content" ' )
433
+ ->order ('id ' );
432
434
$ db ->setQuery ($ query );
433
435
try {
434
436
return $ db ->loadColumn ();
@@ -456,11 +458,11 @@ private function _exportData()
456
458
// get articles
457
459
$ db = Factory::getDbo ();
458
460
$ query = $ db ->getQuery (true )
459
- ->select ('`id`, ` title`, ` language`, ` introtext`, ` fulltext` ' )
460
- ->from ('` #__content` ' )
461
- ->where ('` state` >= 0 ' )
462
- ->where ('` catid` = ' . $ catid )
463
- ->order ('`id` ' );
461
+ ->select ('id, title, language, introtext, \' fulltext \' ' )
462
+ ->from ('#__content ' )
463
+ ->where ('state >= 0 ' )
464
+ ->where ('catid = ' . ( int ) $ catid )
465
+ ->order ('id ' );
464
466
$ db ->setQuery ($ query );
465
467
try {
466
468
$ articles = $ db ->loadObjectList ();
@@ -479,7 +481,7 @@ private function _exportData()
479
481
// file handler
480
482
$ this ->_file = Path::clean (Factory::getConfig ()->get ('tmp_path ' ) . '/cfi_export_ ' . date ('Y-m-d-H-i-s ' ) . '.csv ' );
481
483
if (($ fileHandle = fopen ($ this ->_file , 'w ' )) === false ) {
482
- $ data ['result ' ] = Text::_ ('PLG_CFI_EXPORT_FILE_CREATE ' );
484
+ $ data ['result ' ] = Text::_ ('PLG_CFI_EXPORTfile_CREATE ' );
483
485
Log::add (json_encode ($ data ), Log::ERROR );
484
486
$ this ->_printJson ($ data ['result ' ]);
485
487
}
@@ -555,7 +557,7 @@ private function _exportData()
555
557
$ data ['result ' ] = Text::_ ('PLG_CFI_EXPORT_SUCCESS ' );
556
558
$ date ['file ' ] = $ this ->_file ;
557
559
Log::add (json_encode ($ data ), Log::INFO );
558
- $ this ->_printJson ($ data ['result ' ], true , ['f ' => base64_encode ( $ this ->_file )]);
560
+ $ this ->_printJson ($ data ['result ' ], true , ['f ' => urlencode ( pathinfo ( $ this ->_file , PATHINFO_BASENAME ) )]);
559
561
560
562
exit ;
561
563
}
0 commit comments