45356fb5d4990ec70dcddb4b05adb668904daac1
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\bulk\processing\user;
3 use wcf\data\user\UserList;
4 use wcf\data\DatabaseObjectList;
5 use wcf\system\WCF;
6 use wcf\util\StringUtil;
7
8 /**
9 * Bulk processing action implementation for exporting mail addresses of users.
10 *
11 * @author Matthias Schmidt
12 * @copyright 2001-2015 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package com.woltlab.wcf
15 * @subpackage system.bulk.processing.user
16 * @category Community Framework
17 * @since 2.2
18 */
19 class ExportMailAddressUserBulkProcessingAction extends AbstractUserBulkProcessingAction {
20 /**
21 * type of the file the email addresses will be saved in (csv or xml)
22 * @var string
23 */
24 public $fileType = 'csv';
25
26 /**
27 * separates the exported email addresses
28 * @var string
29 */
30 public $separator = ',';
31
32 /**
33 * encloses the exported email addresses
34 * @var string
35 */
36 public $textSeparator = '"';
37
38 /**
39 * @see \wcf\system\bulk\processing\IBulkProcessingAction::executeAction()
40 */
41 public function executeAction(DatabaseObjectList $objectList) {
42 if (!($objectList instanceof UserList)) return;
43
44 // send content type
45 header('Content-Type: text/'.$this->fileType.'; charset=UTF-8');
46 header('Content-Disposition: attachment; filename="export.'.$this->fileType.'"');
47
48 if ($this->fileType == 'xml') {
49 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<addresses>\n";
50 }
51
52 $userCount = count($objectList);
53 $i = 0;
54 foreach ($objectList as $user) {
55 if ($this->fileType == 'xml') {
56 echo "<address><![CDATA[".StringUtil::escapeCDATA($user->email)."]]></address>\n";
57 }
58 else {
59 echo $this->textSeparator.$user->email.$this->textSeparator.($i < $userCount ? $this->separator : '');
60 }
61
62 $i++;
63 }
64
65 if ($this->fileType == 'xml') {
66 echo "</addresses>";
67 }
68 }
69
70 /**
71 * @see \wcf\system\bulk\processing\IBulkProcessingAction::getHTML()
72 */
73 public function getHTML() {
74 return WCF::getTPL()->fetch('exportMailAddressUserBulkProcessing', 'wcf', [
75 'fileType' => $this->fileType,
76 'separator' => $this->separator,
77 'textSeparator' => $this->textSeparator
78 ]);
79 }
80
81 /**
82 * @see \wcf\system\bulk\processing\IBulkProcessingAction::getObjectList()
83 */
84 public function getObjectList() {
85 $userList = parent::getObjectList();
86
87 $userList->sqlOrderBy = 'user_table.email';
88
89 return $userList;
90 }
91
92 /**
93 * @see \wcf\system\bulk\processing\IBulkProcessingAction::readFormParameters()
94 */
95 public function readFormParameters() {
96 if (isset($_POST['fileType']) && $_POST['fileType'] == 'xml') $this->fileType = $_POST['fileType'];
97 if (isset($_POST['separator'])) $this->separator = $_POST['separator'];
98 if (isset($_POST['textSeparator'])) $this->textSeparator = $_POST['textSeparator'];
99 }
100
101 /**
102 * @see \wcf\system\bulk\processing\IBulkProcessingAction::reset()
103 */
104 public function reset() {
105 exit;
106 }
107 }