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