2 namespace wcf\system\bulk\processing\user;
3 use wcf\data\user\UserAction;
4 use wcf\data\user\UserList;
5 use wcf\data\DatabaseObjectList;
7 use wcf\util\StringUtil;
10 * Bulk processing action implementation for exporting mail addresses of users.
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
20 class ExportMailAddressUserBulkProcessingAction extends AbstractUserBulkProcessingAction {
22 * type of the file the email addresses will be saved in (csv or xml)
25 public $fileType = 'csv';
28 * separates the exported email addresses
31 public $separator = ',';
34 * encloses the exported email addresses
37 public $textSeparator = '"';
40 * @see \wcf\system\bulk\processing\IBulkProcessingAction::executeAction()
42 public function executeAction(DatabaseObjectList $objectList) {
43 if (!($objectList instanceof UserList)) return;
46 header('Content-Type: text/'.$this->fileType.'; charset=UTF-8');
47 header('Content-Disposition: attachment; filename="export.'.$this->fileType.'"');
49 if ($this->fileType == 'xml') {
50 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<addresses>\n";
53 $userCount = count($objectList);
55 foreach ($objectList as $user) {
56 if ($this->fileType == 'xml') {
57 echo "<address><![CDATA[".StringUtil::escapeCDATA($user->email)."]]></address>\n";
60 echo $this->textSeparator.$user->email.$this->textSeparator.($i < $userCount ? $this->separator : '');
66 if ($this->fileType == 'xml') {
72 * @see \wcf\system\bulk\processing\IBulkProcessingAction::getHTML()
74 public function getHTML() {
75 return WCF::getTPL()->fetch('exportMailAddressUserBulkProcessing', 'wcf', [
76 'fileType' => $this->fileType,
77 'separator' => $this->separator,
78 'textSeparator' => $this->textSeparator
83 * @see \wcf\system\bulk\processing\IBulkProcessingAction::getObjectList()
85 public function getObjectList() {
86 $userList = parent::getObjectList();
88 $userList->sqlOrderBy = 'user_table.email';
94 * @see \wcf\system\bulk\processing\IBulkProcessingAction::readFormParameters()
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'];
103 * @see \wcf\system\bulk\processing\IBulkProcessingAction::reset()
105 public function reset() {