/** * Export Action for CSV Files * * @return void */ public function exportCsvAction() { $this->view->assignMultiple(array('mails' => $this->mailRepository->findAllInPid($this->id, $this->settings, $this->piVars), 'fieldUids' => GeneralUtility::trimExplode(',', StringUtility::conditionalVariable($this->piVars['export']['fields'], ''), true))); $fileName = StringUtility::conditionalVariable($this->settings['export']['filenameCsv'], 'export.csv'); header('Content-Type: text/x-csv'); header('Content-Disposition: attachment; filename="' . $fileName . '"'); header('Pragma: no-cache'); }
/** * Trim outer and inner HTML for CSV files * * @return string */ public function render() { $string = $this->renderChildren(); $string = $this->removeDuplicatedWhitespace($string); $string = StringUtility::br2nl($string); $string = $this->removeWhiteSpaceForEveryLine($string); $string = $this->removeCsvWhitespace($string); return $string; }
/** * Function makePlain() removes html tags and add linebreaks * Easy generate a plain email bodytext from a html bodytext * * @param string $content HTML Mail bodytext * @return string $content */ protected function makePlain($content) { $tags2LineBreaks = ['</p>', '</tr>', '<ul>', '</li>', '</h1>', '</h2>', '</h3>', '</h4>', '</h5>', '</h6>', '</div>', '</legend>', '</fieldset>', '</dd>', '</dt>']; // 1. remove complete head element $content = preg_replace('/<head>(.*?)<\\/head>/i', '', $content); // 2. remove linebreaks, tabs $content = trim(str_replace(["\n", "\r", "\t"], '', $content)); // 3. add linebreaks on some parts (</p> => </p><br />) $content = str_replace($tags2LineBreaks, '</p><br />', $content); // 4. insert space for table cells $content = str_replace(['</td>', '</th>'], '</td> ', $content); // 5. replace links <a href="xyz">LINK</a> -> LINK [xyz] $content = preg_replace('/<a[^>]+href\\s*=\\s*["\']([^"\']+)["\'][^>]*>(.*?)<\\/a>/misu', '$2 [$1]', $content); // 6. remove all tags (<b>bla</b><br /> => bla<br />) $content = strip_tags($content, '<br><address>'); // 7. <br /> to \n $content = StringUtility::br2nl($content); return trim($content); }
/** * Mail Generation for Receiver * * @param Mail $mail * @param string $hash * @return void */ protected function sendReceiverMail(Mail $mail, $hash = null) { $receiverString = TemplateUtility::fluidParseString($this->settings['receiver']['email'], $this->mailRepository->getVariablesWithMarkersFromMail($mail)); TypoScriptUtility::overwriteValueFromTypoScript($receiverString, $this->conf['receiver.']['overwrite.'], 'email'); $receivers = StringUtility::getReceiverEmails($receiverString, $this->settings['receiver']['fe_group']); $mail->setReceiverMail(implode(PHP_EOL, $receivers)); TypoScriptUtility::overwriteValueFromTypoScript($defaultSenderEmail, $this->conf['receiver.']['default.'], 'senderEmail'); TypoScriptUtility::overwriteValueFromTypoScript($defaultSenderName, $this->conf['receiver.']['default.'], 'senderName'); foreach ($receivers as $receiver) { $email = ['template' => 'Mail/ReceiverMail', 'receiverEmail' => $receiver, 'receiverName' => !empty($this->settings['receiver']['name']) ? $this->settings['receiver']['name'] : 'Powermail', 'senderEmail' => $this->mailRepository->getSenderMailFromArguments($mail, $defaultSenderEmail), 'senderName' => $this->mailRepository->getSenderNameFromArguments($mail, $defaultSenderName), 'subject' => $this->settings['receiver']['subject'], 'rteBody' => $this->settings['receiver']['body'], 'format' => $this->settings['receiver']['mailformat'], 'variables' => ['hash' => $hash]]; TypoScriptUtility::overwriteValueFromTypoScript($email['receiverName'], $this->conf['receiver.']['overwrite.'], 'name'); TypoScriptUtility::overwriteValueFromTypoScript($email['senderName'], $this->conf['receiver.']['overwrite.'], 'senderName'); TypoScriptUtility::overwriteValueFromTypoScript($email['senderEmail'], $this->conf['receiver.']['overwrite.'], 'senderEmail'); $sent = $this->sendMailService->sendEmailPreflight($email, $mail, $this->settings, 'receiver'); if (!$sent) { $this->addFlashMessage(LocalizationUtility::translate('error_mail_not_created'), '', AbstractMessage::ERROR); $this->messageClass = 'error'; } } }
/** * Test if stringlength is in range * * @param string $value * @param string $configuration e.g. "1,6" or "6" * @return bool */ protected function validateLength($value, $configuration) { $values = GeneralUtility::trimExplode(',', $configuration, true); if ((int) $values[0] <= 0) { return true; } if (!isset($values[1])) { $values[1] = $values[0]; $values[0] = 1; } return StringUtility::getStringLength($value) >= $values[0] && StringUtility::getStringLength($value) <= $values[1]; }
/** * cleanFileNameReturnBool Test * * @param string $content * @param string $expectedResult * @dataProvider br2nlReturnStringDataProvider * @return void * @test */ public function br2nlReturnString($content, $expectedResult) { $this->assertSame($expectedResult, StringUtility::br2nl($content)); }
/** * View helper check if given value is empty * * @param mixed $val String or Number * @return boolean */ public function render($val) { return StringUtility::isNotEmpty($val); }
/** * Create a random filename * * @return void */ protected function createRandomFileName() { /** * Note: * GeneralUtility::writeFileToTypo3tempDir() * allows only filenames which are max 59 characters long */ $fileName = StringUtility::getRandomString(55); $fileName .= '.'; $fileName .= $this->getFormat(); $this->fileName = $fileName; }
/** * Get path and filename * * @param bool $absolute * @param bool $addHash * @return string */ public function getPathAndFilename($absolute = false, $addHash = false) { $pathAndFilename = $this->pathAndFilename; if ($absolute) { $pathAndFilename = GeneralUtility::getFileAbsFileName($pathAndFilename); } if ($addHash) { $pathAndFilename .= '?hash=' . StringUtility::getRandomString(8); } return $pathAndFilename; }
/** * getStringLength Test * * @param string $string * @param int $expectedResult * @dataProvider getStringLengthReturnIntDataProvider * @return void * @test */ public function getStringLengthReturnInt($string, $expectedResult) { $this->assertSame($expectedResult, StringUtility::getStringLength($string)); }
/** * Initially fill the marker field from title * * @param string $status mode of change * @param string $table the table which gets changed * @param string $uid uid of the record * @param array $fieldArray the updateArray * @return void */ public function processDatamap_postProcessFieldArray($status, $table, $uid, &$fieldArray) { if ($table !== 'tx_powermail_domain_model_fields') { return; } $markers = array_merge((array) $this->existingMarkers, (array) $this->marker); $this->makeUniqueValueInArray($markers); // set marker for new field if (isset($this->data['tx_powermail_domain_model_fields'][$uid]['marker']) || stristr($uid, 'NEW')) { if (isset($fieldArray['marker']) && empty($fieldArray['marker'])) { $fieldArray['marker'] = 'marker_' . StringUtility::getRandomString(8, false); } if (!empty($markers['_' . $uid])) { $fieldArray['marker'] = $markers['_' . $uid]; } } // revise marker if related to a new page and not allowed if (!empty($markers['_' . $uid]) && $markers['_' . $uid] !== $this->marker['_' . $uid]) { $fieldArray['marker'] = $markers['_' . $uid]; } // marker should be empty on localized fields if (!empty($fieldArray['sys_language_uid']) && $fieldArray['sys_language_uid'] > 0) { unset($fieldArray['marker']); } }
/** * Call methods in finisher class * * @param AbstractFinisher $finisher * @return void */ protected function callFinisherMethods(AbstractFinisher $finisher) { foreach (get_class_methods($finisher) as $method) { if (!StringUtility::endsWith($method, 'Finisher') || strpos($method, 'initialize') === 0) { continue; } $this->callInitializeFinisherMethod($finisher, $method); $finisher->{$method}(); } }
/** * Should this key skipped because it starts with _ or ends with . * * @param string $key * @return bool */ protected function isSkippedKey($key) { return StringUtility::startsWith($key, '_') || StringUtility::endsWith($key, '.'); }
/** * removeLastDot Test * * @param string $string * @param string $expectedResult * @dataProvider removeLastDotReturnsStringDataProvider * @return void * @test */ public function removeLastDotReturnsString($string, $expectedResult) { $this->assertSame($expectedResult, StringUtility::removeLastDot($string)); }
/** * @param string $filename * @return string */ protected static function randomizeFileName($filename) { $fileInfo = pathinfo($filename); return StringUtility::getRandomString(8) . '.' . $fileInfo['extension']; }
/** * return sorting array and respect * settings and piVars * return array( * 'property' => 'asc' * ) * * @param string $sortby * @param string $order * @param array $piVars * @return array */ protected function getSorting($sortby, $order, $piVars = array()) { $sorting = array($this->cleanStringForQuery(StringUtility::conditionalVariable($sortby, 'crdate')) => $this->getSortOrderByString($order)); if (!empty($piVars['sorting'])) { $sorting = array(); foreach ((array) array_reverse($piVars['sorting']) as $property => $sortOrderName) { $sorting[$this->cleanStringForQuery($property)] = $this->getSortOrderByString($sortOrderName); } } return $sorting; }
/** * Mandatory Check * * @param mixed $value * @return bool */ protected function validateMandatory($value) { return StringUtility::isNotEmpty($value); }