Example #1
0
 /**
  * Generate the content element
  */
 protected function compile()
 {
     $rows = deserialize($this->tableitems);
     $this->Template->id = 'table_' . $this->id;
     $this->Template->summary = specialchars($this->summary);
     $this->Template->useHeader = $this->thead ? true : false;
     $this->Template->useFooter = $this->tfoot ? true : false;
     $this->Template->useLeftTh = $this->tleft ? true : false;
     $this->Template->sortable = $this->sortable ? true : false;
     $arrHeader = array();
     $arrBody = array();
     $arrFooter = array();
     // Table header
     if ($this->thead) {
         foreach ($rows[0] as $i => $v) {
             // Set table sort cookie
             if ($this->sortable && $i == $this->sortIndex) {
                 $co = 'TS_TABLE_' . $this->id;
                 $so = $this->sortOrder == 'descending' ? 'desc' : 'asc';
                 if (\Input::cookie($co) == '') {
                     \System::setCookie($co, $i . '|' . $so, 0);
                 }
             }
             // Add cell
             $arrHeader[] = array('class' => 'head_' . $i . ($i == 0 ? ' col_first' : '') . ($i == count($rows[0]) - 1 ? ' col_last' : '') . ($i == 0 && $this->tleft ? ' unsortable' : ''), 'content' => $v != '' ? nl2br_html5($v) : ' ');
         }
         array_shift($rows);
     }
     $this->Template->header = $arrHeader;
     $limit = $this->tfoot ? count($rows) - 1 : count($rows);
     // Table body
     for ($j = 0; $j < $limit; $j++) {
         $class_tr = '';
         if ($j == 0) {
             $class_tr .= ' row_first';
         }
         if ($j == $limit - 1) {
             $class_tr .= ' row_last';
         }
         $class_eo = $j % 2 == 0 ? ' odd' : ' even';
         foreach ($rows[$j] as $i => $v) {
             $class_td = '';
             if ($i == 0) {
                 $class_td .= ' col_first';
             }
             if ($i == count($rows[$j]) - 1) {
                 $class_td .= ' col_last';
             }
             $arrBody['row_' . $j . $class_tr . $class_eo][] = array('class' => 'col_' . $i . $class_td, 'content' => $v != '' ? nl2br_html5($v) : '&nbsp;');
         }
     }
     $this->Template->body = $arrBody;
     // Table footer
     if ($this->tfoot) {
         foreach ($rows[count($rows) - 1] as $i => $v) {
             $arrFooter[] = array('class' => 'foot_' . $i . ($i == 0 ? ' col_first' : '') . ($i == count($rows[count($rows) - 1]) - 1 ? ' col_last' : ''), 'content' => $v != '' ? nl2br_html5($v) : '&nbsp;');
         }
     }
     $this->Template->footer = $arrFooter;
 }
    /**
     * Add the type of input field
     * @param array
     * @return string
     */
    public function listNewsletterArticles($arrRow)
    {
        $strStats = '';
        $strContents = '';
        $objContents = \ContentModel::findPublishedByPidAndTable($arrRow['id'], 'tl_newsletter');
        if (!is_null($objContents)) {
            foreach ($objContents as $objContent) {
                $strContents .= $this->getContentElement($objContent->id) . '<hr>';
            }
        }
        $intTotal = $arrRow['recipients'] + $arrRow['rejected'];
        //		$intTracked = NewsletterContent\Models\NewsletterTrackingModel::countTrackedByPid($arrRow['id']);
        $objTracked = NewsletterContent\Models\NewsletterTrackingModel::findTrackedInteractionsByPid($arrRow['id']);
        $intTracked = !is_null($objTracked) ? $objTracked->count() : 0;
        $intPercent = @round($intTracked / $intTotal * 100);
        $strStats = sprintf($GLOBALS['TL_LANG']['tl_newsletter']['sentTo'], $arrRow['recipients'], strval($intTotal), strval($intTracked), strval($intPercent));
        return '
<div class="cte_type ' . ($arrRow['sent'] && $arrRow['date'] ? 'published' : 'unpublished') . '"><strong>' . $arrRow['subject'] . '</strong> - ' . ($arrRow['sent'] && $arrRow['date'] ? sprintf($GLOBALS['TL_LANG']['tl_newsletter']['sentOn'], Date::parse($GLOBALS['TL_CONFIG']['datimFormat'], $arrRow['date'])) . '<br>' . $strStats : $GLOBALS['TL_LANG']['tl_newsletter']['notSent']) . '</div>
<div class="limit_height' . (!$GLOBALS['TL_CONFIG']['doNotCollapse'] ? ' h128' : '') . '">
' . (!$arrRow['sendText'] && strlen($strContents) ? '
' . $strContents : '') . '
' . nl2br_html5($arrRow['text']) . '
</div>' . "\n";
        return '<div class="tl_content_left">' . $arrRow['subject'] . ' <span style="color:#b3b3b3;padding-left:3px">[' . $arrRow['senderName'] . ' &lt;' . $arrRow['sender'] . '&gt;]</span></div>';
    }
    /**
     * Add the type of input field
     * @param array
     * @return string
     */
    public function listNewsletterArticles($arrRow)
    {
        $strStats = '';
        $strContents = '';
        $objContents = \ContentModel::findPublishedByPidAndTable($arrRow['id'], 'tl_newsletter');
        if (!is_null($objContents)) {
            foreach ($objContents as $objContent) {
                $strContents .= $this->getContentElement($objContent->id) . '<hr>';
            }
        }
        $strStats = sprintf($GLOBALS['TL_LANG']['tl_newsletter']['hoja_status_string'], $arrRow['hoja_recipients'], $arrRow['hoja_rejected']);
        return '
<div class="cte_type ' . ($arrRow['sent'] && $arrRow['date'] ? 'published' : 'unpublished') . '"><strong>' . $arrRow['subject'] . '</strong> - ' . ($arrRow['sent'] && $arrRow['date'] ? sprintf($GLOBALS['TL_LANG']['tl_newsletter']['sentOn'], Date::parse($GLOBALS['TL_CONFIG']['datimFormat'], $arrRow['date'])) . '<br>' . $strStats : $GLOBALS['TL_LANG']['tl_newsletter']['notSent']) . '</div>
<div class="limit_height' . (!$GLOBALS['TL_CONFIG']['doNotCollapse'] ? ' h128' : '') . '">
' . (!$arrRow['sendText'] && strlen($strContents) ? '
' . $strContents : '') . '
' . nl2br_html5($arrRow['text']) . '
</div>' . "\n";
    }
Example #4
0
 /**
  * Render a property value to readable text.
  *
  * @param RenderReadablePropertyValueEvent $event The event being processed.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 public static function renderReadablePropertyValue(RenderReadablePropertyValueEvent $event)
 {
     if ($event->getRendered() !== null) {
         return;
     }
     $dispatcher = $event->getEnvironment()->getEventDispatcher();
     $property = $event->getProperty();
     $value = self::decodeValue($event->getEnvironment(), $event->getModel(), $event->getProperty()->getName(), $event->getValue());
     $extra = $property->getExtra();
     // TODO: refactor - foreign key handling is not yet supported.
     /*
             if (isset($arrFieldConfig['foreignKey']))
             {
        $temp = array();
        $chunks = explode('.', $arrFieldConfig['foreignKey'], 2);
     
     
        foreach ((array) $value as $v)
        {
     //                    $objKey = $this->Database->prepare("SELECT " . $chunks[1] . " AS value FROM " . $chunks[0] . " WHERE id=?")
     //                            ->limit(1)
     //                            ->execute($v);
     //
     //                    if ($objKey->numRows)
     //                    {
     //                        $temp[] = $objKey->value;
     //                    }
        }
     
     //                $row[$i] = implode(', ', $temp);
             }
             // Decode array
             else
     */
     if (is_array($value)) {
         foreach ($value as $kk => $vv) {
             if (is_array($vv)) {
                 $vals = array_values($vv);
                 $value[$kk] = $vals[0] . ' (' . $vals[1] . ')';
             }
         }
         $event->setRendered(implode(', ', $value));
     } elseif (isset($extra['rgxp'])) {
         // Date format.
         if ($extra['rgxp'] == 'date' || $extra['rgxp'] == 'time' || $extra['rgxp'] == 'datim') {
             $event->setRendered(self::parseDateTime($dispatcher, $GLOBALS['TL_CONFIG'][$extra['rgxp'] . 'Format'], $value));
         }
     } elseif ($property->getName() == 'tstamp') {
         // Date and time format.
         $dateEvent = new ParseDateEvent($value, $GLOBALS['TL_CONFIG']['timeFormat']);
         $dispatcher->dispatch(ContaoEvents::DATE_PARSE, $dateEvent);
         $event->setRendered($dateEvent->getResult());
     } elseif ($property->getWidgetType() == 'checkbox' && !$extra['multiple']) {
         $event->setRendered(strlen($value) ? $GLOBALS['TL_LANG']['MSC']['yes'] : $GLOBALS['TL_LANG']['MSC']['no']);
     } elseif ($property->getWidgetType() == 'textarea' && (!empty($extra['allowHtml']) || !empty($extra['preserveTags']))) {
         $event->setRendered(nl2br_html5(specialchars($value)));
     } elseif (isset($extra['reference']) && is_array($extra['reference'])) {
         if (isset($extra['reference'][$value])) {
             $event->setRendered(is_array($extra['reference'][$value]) ? $extra['reference'][$value][0] : $extra['reference'][$value]);
         }
     } elseif ($value instanceof \DateTime) {
         $dateEvent = new ParseDateEvent($value->getTimestamp(), $GLOBALS['TL_CONFIG']['datimFormat']);
         $dispatcher->dispatch(ContaoEvents::DATE_PARSE, $dateEvent);
         $event->setRendered($dateEvent->getResult());
     } else {
         $options = $property->getOptions();
         if (!$options) {
             $options = self::getOptions($event->getEnvironment(), $event->getModel(), $event->getProperty());
             if ($options) {
                 $property->setOptions($options);
             }
         }
         if (array_is_assoc($options)) {
             $event->setRendered($options[$value]);
         }
     }
 }
Example #5
0
	/**
	 * Edit a task
	 */
	protected function editTask()
	{
		$this->Template = new BackendTemplate('be_task_edit');
		$fs = $this->Session->get('fieldset_states');

		$this->Template->titleClass = (isset($fs['tl_tasks']['title_legend']) && !$fs['tl_tasks']['title_legend']) ? ' collapsed' : '';
		$this->Template->assignClass = (isset($fs['tl_tasks']['assign_legend']) && !$fs['tl_tasks']['assign_legend']) ? ' collapsed' : '';
		$this->Template->statusClass = (isset($fs['tl_tasks']['status_legend']) && !$fs['tl_tasks']['status_legend']) ? ' collapsed' : '';
		$this->Template->historyClass = (isset($fs['tl_tasks']['history_legend']) && !$fs['tl_tasks']['history_legend']) ? ' collapsed' : '';

		$this->Template->goBack = $GLOBALS['TL_LANG']['MSC']['goBack'];
		$this->Template->headline = sprintf($GLOBALS['TL_LANG']['tl_task']['edit'][1], $this->Input->get('id'));

		$objTask = $this->Database->prepare("SELECT *, (SELECT name FROM tl_user u WHERE u.id=t.createdBy) AS creator FROM tl_task t WHERE id=?")
								  ->limit(1)
								  ->execute($this->Input->get('id'));

		if ($objTask->numRows < 1)
		{
			$this->log('Invalid task ID "' . $this->Input->get('id') . '"', 'ModuleTask editTask()', TL_ERROR);
			$this->redirect('contao/main.php?act=error');
		}

		// Check if the user is allowed to edit the task
		if (!$this->User->isAdmin && $objTask->createdBy != $this->User->id)
		{
			$this->log('Not enough permissions to edit task ID "' . $this->Input->get('id') . '"', 'ModuleTask editTask()', TL_ERROR);
			$this->redirect('contao/main.php?act=error');
		}

		// Advanced options
		$this->blnAdvanced = ($this->User->isAdmin || $objTask->createdBy == $this->User->id);
		$this->Template->advanced = $this->blnAdvanced;

		$this->Template->title = $this->blnAdvanced ? $this->getTitleWidget($objTask->title) : $objTask->title;
		$this->Template->deadline = $this->blnAdvanced ? $this->getDeadlineWidget($this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $objTask->deadline)) : $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $objTask->deadline);

		$arrHistory = array();

		// Get the status
		$objStatus = $this->Database->prepare("SELECT *, (SELECT name FROM tl_user u WHERE u.id=s.assignedTo) AS name FROM tl_task_status s WHERE pid=? ORDER BY tstamp")
									->execute($this->Input->get('id'));

		while($objStatus->next())
		{
			$arrHistory[] = array
			(
				'creator' => $objTask->creator,
				'date' => $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $objStatus->tstamp),
				'status' => (($GLOBALS['TL_LANG']['tl_task_status'][$objStatus->status] != '') ? $GLOBALS['TL_LANG']['tl_task_status'][$objStatus->status] : $objStatus->status),
				'comment' => (($objStatus->comment != '') ? nl2br_html5($objStatus->comment) : '&nbsp;'),
				'assignedTo' => $objStatus->assignedTo,
				'progress' => $objStatus->progress,
				'class' => $objStatus->status,
				'name' => $objStatus->name
			);
		}

		$this->Template->assignedTo = $this->getAssignedToWidget($objStatus->assignedTo);
		$this->Template->notify = $this->getNotifyWidget();
		$this->Template->status = $this->getStatusWidget($objStatus->status, $objStatus->progress);
		$this->Template->progress = $this->getProgressWidget($objStatus->progress);
		$this->Template->comment = $this->getCommentWidget();

		// Update task
		if ($this->Input->post('FORM_SUBMIT') == 'tl_tasks' && $this->blnSave)
		{
			// Update task
			if ($this->blnAdvanced)
			{
				$deadline = new Date($this->Template->deadline->value, $GLOBALS['TL_CONFIG']['dateFormat']);

				$this->Database->prepare("UPDATE tl_task SET title=?, deadline=? WHERE id=?")
							   ->execute($this->Template->title->value, $deadline->dayBegin, $this->Input->get('id'));
			}

			// Insert status
			$arrSet = array
			(
				'pid' => $this->Input->get('id'),
				'tstamp' => time(),
				'assignedTo' => $this->Template->assignedTo->value,
				'status' => $this->Template->status->value,
				'progress' => (($this->Template->status->value == 'completed') ? 100 : $this->Template->progress->value),
				'comment' => trim($this->Template->comment->value)
			);

			$this->Database->prepare("INSERT INTO tl_task_status %s")->set($arrSet)->execute();

			// Notify user
			if ($this->Input->post('notify'))
			{
				$objUser = $this->Database->prepare("SELECT email FROM tl_user WHERE id=?")
										  ->limit(1)
										  ->execute($this->Template->assignedTo->value);

				if ($objUser->numRows)
				{
					$objEmail = new Email();

					$objEmail->from = $GLOBALS['TL_ADMIN_EMAIL'];
					$objEmail->fromName = $GLOBALS['TL_ADMIN_NAME'];
					$objEmail->subject = $objTask->title;

					$objEmail->text = trim($this->Template->comment->value);
					$objEmail->text .= sprintf($GLOBALS['TL_LANG']['tl_task']['message'], $this->User->name, $this->Environment->base . 'contao/main.php?do=tasks&act=edit&id=' . $objTask->id);

					$objEmail->sendTo($objUser->email);
				}
			}

			// Go back
			$this->redirect('contao/main.php?do=tasks');
		}

		$this->Template->history = $arrHistory;
		$this->Template->historyLabel = $GLOBALS['TL_LANG']['tl_task']['history'];
		$this->Template->deadlineLabel = $GLOBALS['TL_LANG']['tl_task']['deadline'][0];
		$this->Template->dateLabel = $GLOBALS['TL_LANG']['tl_task']['date'];
		$this->Template->assignedToLabel = $GLOBALS['TL_LANG']['tl_task']['assignedTo'];
		$this->Template->createdByLabel = $GLOBALS['TL_LANG']['tl_task']['creator'];
		$this->Template->statusLabel = $GLOBALS['TL_LANG']['tl_task']['status'][0];
		$this->Template->progressLabel = $GLOBALS['TL_LANG']['tl_task']['progress'][0];
		$this->Template->submit = $GLOBALS['TL_LANG']['tl_task']['editSubmit'];
		$this->Template->titleLabel = $GLOBALS['TL_LANG']['tl_task']['title'][0];
		$this->Template->assignLabel = $GLOBALS['TL_LANG']['tl_task']['assignedTo'];
	}
Example #6
0
/**
 * Replace line breaks with <br> tags preserving preformatted text
 * @param string
 * @param boolean
 * @return string
 */
function nl2br_pre($str, $xhtml = false)
{
    $str = $xhtml ? nl2br_xhtml($str) : nl2br_html5($str);
    if (stripos($str, '<pre') === false) {
        return $str;
    }
    $chunks = array();
    preg_match_all('/<pre[^>]*>.*<\\/pre>/Uis', $str, $chunks);
    foreach ($chunks as $chunk) {
        $str = str_replace($chunk, str_ireplace(array('<br>', '<br />'), '', $chunk), $str);
    }
    return $str;
}
Example #7
0
    /**
     * Renturn a form to choose an existing style sheet and import it
     * @param object
     * @return string
     */
    public function send(DataContainer $objDc)
    {
        $objNewsletter = $this->Database->prepare("SELECT n.*, c.useSMTP, c.smtpHost, c.smtpPort, c.smtpUser, c.smtpPass FROM tl_newsletter n LEFT JOIN tl_newsletter_channel c ON n.pid=c.id WHERE n.id=?")->limit(1)->execute($objDc->id);
        // Return if there is no newsletter
        if ($objNewsletter->numRows < 1) {
            return '';
        }
        // Overwrite the SMTP configuration
        if ($objNewsletter->useSMTP) {
            $GLOBALS['TL_CONFIG']['useSMTP'] = true;
            $GLOBALS['TL_CONFIG']['smtpHost'] = $objNewsletter->smtpHost;
            $GLOBALS['TL_CONFIG']['smtpUser'] = $objNewsletter->smtpUser;
            $GLOBALS['TL_CONFIG']['smtpPass'] = $objNewsletter->smtpPass;
            $GLOBALS['TL_CONFIG']['smtpEnc'] = $objNewsletter->smtpEnc;
            $GLOBALS['TL_CONFIG']['smtpPort'] = $objNewsletter->smtpPort;
        }
        // Add default sender address
        if (!strlen($objNewsletter->sender)) {
            list($objNewsletter->senderName, $objNewsletter->sender) = $this->splitFriendlyName($GLOBALS['TL_CONFIG']['adminEmail']);
        }
        $arrAttachments = array();
        // Add attachments
        if ($objNewsletter->addFile) {
            $files = deserialize($objNewsletter->files);
            if (is_array($files) && count($files) > 0) {
                foreach ($files as $file) {
                    if (is_file(TL_ROOT . '/' . $file)) {
                        $arrAttachments[] = $file;
                    }
                }
            }
        }
        $css = '';
        // Add style sheet newsletter.css
        if (!$objNewsletter->sendText && file_exists(TL_ROOT . '/newsletter.css')) {
            $buffer = file_get_contents(TL_ROOT . '/newsletter.css');
            $buffer = preg_replace('@/\\*\\*.*\\*/@Us', '', $buffer);
            $css = '<style type="text/css">' . "\n";
            $css .= trim($buffer) . "\n";
            $css .= '</style>' . "\n";
        }
        // Replace insert tags
        $html = $this->replaceInsertTags($objNewsletter->content);
        $text = $this->replaceInsertTags($objNewsletter->text);
        // Convert relative URLs
        if ($objNewsletter->externalImages) {
            $html = $this->convertRelativeUrls($html);
        }
        // Send newsletter
        if (strlen($this->Input->get('token')) && $this->Input->get('token') == $this->Session->get('tl_newsletter_send')) {
            $referer = preg_replace('/&(amp;)?(start|mpc|token|recipient|preview)=[^&]*/', '', $this->Environment->request);
            // Preview
            if (isset($_GET['preview'])) {
                // Check the e-mail address
                if (!$this->isValidEmailAddress($this->Input->get('recipient', true))) {
                    $_SESSION['TL_PREVIEW_ERROR'] = true;
                    $this->redirect($referer);
                }
                $arrRecipient['email'] = urldecode($this->Input->get('recipient', true));
                // Send
                $objEmail = $this->generateEmailObject($objNewsletter, $arrAttachments);
                $this->sendNewsletter($objEmail, $objNewsletter, $arrRecipient, $text, $html, $css);
                // Redirect
                $_SESSION['TL_CONFIRM'][] = sprintf($GLOBALS['TL_LANG']['tl_newsletter']['confirm'], 1);
                $this->redirect($referer);
            }
            // Get the total number of recipients
            $objTotal = $this->Database->prepare("SELECT COUNT(DISTINCT email) AS total FROM tl_newsletter_recipients WHERE pid=? AND active=1")->execute($objNewsletter->pid);
            // Return if there are no recipients
            if ($objTotal->total < 1) {
                $this->Session->set('tl_newsletter_send', null);
                $_SESSION['TL_ERROR'][] = $GLOBALS['TL_LANG']['tl_newsletter']['error'];
                $this->redirect($referer);
            }
            $intTotal = $objTotal->total;
            // Get page and timeout
            $intTimeout = $this->Input->get('timeout') > 0 ? $this->Input->get('timeout') : 1;
            $intStart = $this->Input->get('start') ? $this->Input->get('start') : 0;
            $intPages = $this->Input->get('mpc') ? $this->Input->get('mpc') : 10;
            // Get recipients
            $objRecipients = $this->Database->prepare("SELECT *, r.email FROM tl_newsletter_recipients r LEFT JOIN tl_member m ON(r.email=m.email) WHERE r.pid=? AND r.active=1 GROUP BY r.email ORDER BY r.email")->limit($intPages, $intStart)->execute($objNewsletter->pid);
            echo '<div style="font-family:Verdana, sans-serif; font-size:11px; line-height:16px; margin-bottom:12px;">';
            // Send newsletter
            if ($objRecipients->numRows > 0) {
                // Update status
                if ($intStart == 0) {
                    $this->Database->prepare("UPDATE tl_newsletter SET sent=1, date=? WHERE id=?")->execute(time(), $objNewsletter->id);
                    $_SESSION['REJECTED_RECIPIENTS'] = array();
                }
                while ($objRecipients->next()) {
                    $objEmail = $this->generateEmailObject($objNewsletter, $arrAttachments);
                    $this->sendNewsletter($objEmail, $objNewsletter, $objRecipients->row(), $text, $html, $css);
                    echo 'Sending newsletter to <strong>' . $objRecipients->email . '</strong><br>';
                }
            }
            echo '<div style="margin-top:12px;">';
            // Redirect back home
            if ($objRecipients->numRows < 1 || $intStart + $intPages >= $intTotal) {
                $this->Session->set('tl_newsletter_send', null);
                // Deactivate rejected addresses
                if (!empty($_SESSION['REJECTED_RECIPIENTS'])) {
                    $intRejected = count($_SESSION['REJECTED_RECIPIENTS']);
                    $_SESSION['TL_INFO'][] = sprintf($GLOBALS['TL_LANG']['tl_newsletter']['rejected'], $intRejected);
                    $intTotal -= $intRejected;
                    foreach ($_SESSION['REJECTED_RECIPIENTS'] as $strRecipient) {
                        $this->Database->prepare("UPDATE tl_newsletter_recipients SET active='' WHERE email=?")->execute($strRecipient);
                        $this->log('Recipient address "' . $strRecipient . '" was rejected and has been deactivated', 'Newsletter sendNewsletter()', TL_ERROR);
                    }
                }
                $_SESSION['TL_CONFIRM'][] = sprintf($GLOBALS['TL_LANG']['tl_newsletter']['confirm'], $intTotal);
                echo '<script>setTimeout(\'window.location="' . $this->Environment->base . $referer . '"\', 1000);</script>';
                echo '<a href="' . $this->Environment->base . $referer . '">Please click here to proceed if you are not using JavaScript</a>';
            } else {
                $url = preg_replace('/&(amp;)?(start|mpc|recipient)=[^&]*/', '', $this->Environment->request) . '&start=' . ($intStart + $intPages) . '&mpc=' . $intPages;
                echo '<script>setTimeout(\'window.location="' . $this->Environment->base . $url . '"\', ' . $intTimeout * 1000 . ');</script>';
                echo '<a href="' . $this->Environment->base . $url . '">Please click here to proceed if you are not using JavaScript</a>';
            }
            echo '</div></div>';
            exit;
        }
        $strToken = md5(uniqid(mt_rand(), true));
        $this->Session->set('tl_newsletter_send', $strToken);
        $sprintf = strlen($objNewsletter->senderName) ? $objNewsletter->senderName . ' &lt;%s&gt;' : '%s';
        $this->import('BackendUser', 'User');
        // Preview newsletter
        $return = '
<div id="tl_buttons">
<a href="' . $this->getReferer(true) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBT']) . '" accesskey="b">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>
</div>

<h2 class="sub_headline">' . sprintf($GLOBALS['TL_LANG']['tl_newsletter']['send'][1], $objNewsletter->id) . '</h2>
' . $this->getMessages() . '
<form action="' . ampersand($this->Environment->script, true) . '" id="tl_newsletter_send" class="tl_form" method="get">
<div class="tl_formbody_edit tl_newsletter_send">
<input type="hidden" name="do" value="' . $this->Input->get('do') . '">
<input type="hidden" name="table" value="' . $this->Input->get('table') . '">
<input type="hidden" name="key" value="' . $this->Input->get('key') . '">
<input type="hidden" name="id" value="' . $this->Input->get('id') . '">
<input type="hidden" name="token" value="' . $strToken . '">
<table class="prev_header">
  <tr class="row_0">
    <td class="col_0">' . $GLOBALS['TL_LANG']['tl_newsletter']['from'] . '</td>
    <td class="col_1">' . sprintf($sprintf, $objNewsletter->sender) . '</td>
  </tr>
  <tr class="row_1">
    <td class="col_0">' . $GLOBALS['TL_LANG']['tl_newsletter']['subject'][0] . '</td>
    <td class="col_1">' . $objNewsletter->subject . '</td>
  </tr>
  <tr class="row_2">
    <td class="col_0">' . $GLOBALS['TL_LANG']['tl_newsletter']['template'][0] . '</td>
    <td class="col_1">' . $objNewsletter->template . '</td>
  </tr>' . (is_array($arrAttachments) && count($arrAttachments) > 0 ? '
  <tr class="row_3">
    <td class="col_0">' . $GLOBALS['TL_LANG']['tl_newsletter']['attachments'] . '</td>
    <td class="col_1">' . implode(', ', $arrAttachments) . '</td>
  </tr>' : '') . '
</table>' . (!$objNewsletter->sendText ? '
<div class="preview_html">
' . $html . '
</div>' : '') . '
<div class="preview_text">
' . nl2br_html5($text) . '
</div>
<div class="tl_tbox block">
<div class="w50">
  <h3><label for="ctrl_mpc">' . $GLOBALS['TL_LANG']['tl_newsletter']['mailsPerCycle'][0] . '</label></h3>
  <input type="text" name="mpc" id="ctrl_mpc" value="10" class="tl_text" onfocus="Backend.getScrollOffset();">' . ($GLOBALS['TL_LANG']['tl_newsletter']['mailsPerCycle'][1] && $GLOBALS['TL_CONFIG']['showHelp'] ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_newsletter']['mailsPerCycle'][1] . '</p>' : '') . '
</div>
<div class="w50">
  <h3><label for="ctrl_timeout">' . $GLOBALS['TL_LANG']['tl_newsletter']['timeout'][0] . '</label></h3>
  <input type="text" name="timeout" id="ctrl_timeout" value="1" class="tl_text" onfocus="Backend.getScrollOffset();">' . ($GLOBALS['TL_LANG']['tl_newsletter']['timeout'][1] && $GLOBALS['TL_CONFIG']['showHelp'] ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_newsletter']['timeout'][1] . '</p>' : '') . '
</div>
<div class="w50">
  <h3><label for="ctrl_start">' . $GLOBALS['TL_LANG']['tl_newsletter']['start'][0] . '</label></h3>
  <input type="text" name="start" id="ctrl_start" value="0" class="tl_text" onfocus="Backend.getScrollOffset();">' . ($GLOBALS['TL_LANG']['tl_newsletter']['start'][1] && $GLOBALS['TL_CONFIG']['showHelp'] ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_newsletter']['start'][1] . '</p>' : '') . '
</div>
<div class="w50">
  <h3><label for="ctrl_recipient">' . $GLOBALS['TL_LANG']['tl_newsletter']['sendPreviewTo'][0] . '</label></h3>' . (strlen($_SESSION['TL_PREVIEW_ERROR']) ? '
  <div class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['email'] . '</div>' : '') . '
  <input type="text" name="recipient" id="ctrl_recipient" value="' . $this->User->email . '" class="tl_text" onfocus="Backend.getScrollOffset();">' . ($GLOBALS['TL_LANG']['tl_newsletter']['sendPreviewTo'][1] && $GLOBALS['TL_CONFIG']['showHelp'] ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_newsletter']['sendPreviewTo'][1] . '</p>' : '') . '
</div>
</div>
</div>

<div class="tl_formbody_submit">

<div class="tl_submit_container">
<input type="submit" name="preview" class="tl_submit" accesskey="p" value="' . specialchars($GLOBALS['TL_LANG']['tl_newsletter']['preview']) . '">
<input type="submit" id="send" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['tl_newsletter']['send'][0]) . '" onclick="return confirm(\'' . str_replace("'", "\\'", $GLOBALS['TL_LANG']['tl_newsletter']['sendConfirm']) . '\')">
</div>

</div>
</form>';
        $_SESSION['TL_PREVIEW_ERROR'] = false;
        return $return;
    }
    /**
     * Renturn a form to choose an existing style sheet and import it
     * @param \DataContainer
     * @return string
     */
    public function send(\DataContainer $objDc)
    {
        if (TL_MODE == 'BE') {
            $GLOBALS['TL_CSS'][] = 'system/modules/newsletter_content/assets/css/style.css';
            if ($this->isFlexible) {
                $GLOBALS['TL_CSS'][] = 'system/modules/newsletter_content/assets/css/style-flexible.css';
            }
        }
        $objNewsletter = $this->Database->prepare("SELECT n.*, c.useSMTP, c.smtpHost, c.smtpPort, c.smtpUser, c.smtpPass FROM tl_newsletter n LEFT JOIN tl_newsletter_channel c ON n.pid=c.id WHERE n.id=?")->limit(1)->execute($objDc->id);
        // Return if there is no newsletter
        if ($objNewsletter->numRows < 1) {
            return '';
        }
        // Overwrite the SMTP configuration
        if ($objNewsletter->useSMTP) {
            $GLOBALS['TL_CONFIG']['useSMTP'] = true;
            $GLOBALS['TL_CONFIG']['smtpHost'] = $objNewsletter->smtpHost;
            $GLOBALS['TL_CONFIG']['smtpUser'] = $objNewsletter->smtpUser;
            $GLOBALS['TL_CONFIG']['smtpPass'] = $objNewsletter->smtpPass;
            $GLOBALS['TL_CONFIG']['smtpEnc'] = $objNewsletter->smtpEnc;
            $GLOBALS['TL_CONFIG']['smtpPort'] = $objNewsletter->smtpPort;
        }
        // Add default sender address
        if ($objNewsletter->sender == '') {
            list($objNewsletter->senderName, $objNewsletter->sender) = \String::splitFriendlyEmail($GLOBALS['TL_CONFIG']['adminEmail']);
        }
        $arrAttachments = array();
        $blnAttachmentsFormatError = false;
        // Add attachments
        if ($objNewsletter->addFile) {
            $files = deserialize($objNewsletter->files);
            if (!empty($files) && is_array($files)) {
                $objFiles = \FilesModel::findMultipleByUuids($files);
                if ($objFiles === null) {
                    if (!\Validator::isUuid($files[0])) {
                        $blnAttachmentsFormatError = true;
                        \Message::addError($GLOBALS['TL_LANG']['ERR']['version2format']);
                    }
                } else {
                    while ($objFiles->next()) {
                        if (is_file(TL_ROOT . '/' . $objFiles->path)) {
                            $arrAttachments[] = $objFiles->path;
                        }
                    }
                }
            }
        }
        // Get content
        $html = '';
        $objContentElements = \ContentModel::findPublishedByPidAndTable($objNewsletter->id, 'tl_newsletter');
        if ($objContentElements !== null) {
            if (!defined('NEWSLETTER_CONTENT_PREVIEW')) {
                define('NEWSLETTER_CONTENT_PREVIEW', true);
            }
            while ($objContentElements->next()) {
                $html .= $this->getContentElement($objContentElements->id);
            }
        }
        // Replace insert tags
        $text = $this->replaceInsertTags($objNewsletter->text);
        $html = $this->replaceInsertTags($html);
        // Convert relative URLs
        $html = $this->convertRelativeUrls($html);
        // Set back to object
        $objNewsletter->content = $html;
        // Send newsletter
        if (!$blnAttachmentsFormatError && \Input::get('token') != '' && \Input::get('token') == $this->Session->get('tl_newsletter_send')) {
            $referer = preg_replace('/&(amp;)?(start|mpc|token|recipient|preview)=[^&]*/', '', \Environment::get('request'));
            // Preview
            if (isset($_GET['preview'])) {
                // Check the e-mail address
                if (!\Validator::isEmail(\Input::get('recipient', true))) {
                    $_SESSION['TL_PREVIEW_MAIL_ERROR'] = true;
                    $this->redirect($referer);
                }
                // get preview recipient
                $arrRecipient = array();
                $strEmail = urldecode(\Input::get('recipient', true));
                $objRecipient = $this->Database->prepare("SELECT * FROM tl_member m WHERE email=? ORDER BY email")->limit(1)->execute($strEmail);
                if ($objRecipient->num_rows < 1) {
                    $arrRecipient['email'] = $strEmail;
                } else {
                    $arrRecipient = $objRecipient->row();
                }
                $arrRecipient = array_merge($arrRecipient, array('extra' => '&preview=1', 'tracker_png' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $strEmail . '&preview=1&t=png', 'tracker_gif' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $strEmail . '&preview=1&t=gif', 'tracker_css' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $strEmail . '&preview=1&t=css', 'tracker_js' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $strEmail . '&preview=1&t=js'));
                // Send
                $objEmail = $this->generateEmailObject($objNewsletter, $arrAttachments);
                $objNewsletter->email = $strEmail;
                $this->sendNewsletter($objEmail, $objNewsletter, $arrRecipient, $text, $html);
                // Redirect
                \Message::addConfirmation(sprintf($GLOBALS['TL_LANG']['tl_newsletter']['confirm'], 1));
                $this->redirect($referer);
            }
            // Get the total number of recipients
            $objTotal = $this->Database->prepare("SELECT COUNT(DISTINCT email) AS count FROM tl_newsletter_recipients WHERE pid=? AND active=1")->execute($objNewsletter->pid);
            // Return if there are no recipients
            if ($objTotal->count < 1) {
                $this->Session->set('tl_newsletter_send', null);
                \Message::addError($GLOBALS['TL_LANG']['tl_newsletter']['error']);
                $this->redirect($referer);
            }
            $intTotal = $objTotal->count;
            // Get page and timeout
            $intTimeout = \Input::get('timeout') > 0 ? \Input::get('timeout') : 1;
            $intStart = \Input::get('start') ? \Input::get('start') : 0;
            $intPages = \Input::get('mpc') ? \Input::get('mpc') : 10;
            // Get recipients
            $objRecipients = $this->Database->prepare("SELECT *, r.email FROM tl_newsletter_recipients r LEFT JOIN tl_member m ON(r.email=m.email) WHERE r.pid=? AND r.active=1 GROUP BY r.email ORDER BY r.email")->limit($intPages, $intStart)->execute($objNewsletter->pid);
            echo '<div style="font-family:Verdana,sans-serif;font-size:11px;line-height:16px;margin-bottom:12px">';
            // Send newsletter
            if ($objRecipients->numRows > 0) {
                // Update status
                if ($intStart == 0) {
                    $this->Database->prepare("UPDATE tl_newsletter SET sent=1, date=? WHERE id=?")->execute(time(), $objNewsletter->id);
                    $_SESSION['REJECTED_RECIPIENTS'] = array();
                }
                while ($objRecipients->next()) {
                    $objEmail = $this->generateEmailObject($objNewsletter, $arrAttachments);
                    $objNewsletter->email = $objRecipients->email;
                    $arrRecipient = array_merge($objRecipients->row(), array('tracker_png' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $objRecipients->email . '&t=png', 'tracker_gif' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $objRecipients->email . '&t=gif', 'tracker_css' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $objRecipients->email . '&t=css', 'tracker_js' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $objRecipients->email . '&t=js'));
                    $this->sendNewsletter($objEmail, $objNewsletter, $arrRecipient, $text, $html);
                    echo 'Sending newsletter to <strong>' . $objRecipients->email . '</strong><br>';
                }
            }
            echo '<div style="margin-top:12px">';
            // Redirect back home
            if ($objRecipients->numRows < 1 || $intStart + $intPages >= $intTotal) {
                $this->Session->set('tl_newsletter_send', null);
                // Deactivate rejected addresses
                if (!empty($_SESSION['REJECTED_RECIPIENTS'])) {
                    $intRejected = count($_SESSION['REJECTED_RECIPIENTS']);
                    \Message::addInfo(sprintf($GLOBALS['TL_LANG']['tl_newsletter']['rejected'], $intRejected));
                    $intTotal -= $intRejected;
                    foreach ($_SESSION['REJECTED_RECIPIENTS'] as $strRecipient) {
                        $this->Database->prepare("UPDATE tl_newsletter_recipients SET active='' WHERE email=?")->execute($strRecipient);
                        $this->log('Recipient address "' . $strRecipient . '" was rejected and has been deactivated', __METHOD__, TL_ERROR);
                    }
                }
                $this->Database->prepare("UPDATE tl_newsletter SET recipients=?, rejected=? WHERE id=?")->execute($intTotal, $intRejected, $objNewsletter->id);
                \Message::addConfirmation(sprintf($GLOBALS['TL_LANG']['tl_newsletter']['confirm'], $intTotal));
                echo '<script>setTimeout(\'window.location="' . \Environment::get('base') . $referer . '"\',1000)</script>';
                echo '<a href="' . \Environment::get('base') . $referer . '">Please click here to proceed if you are not using JavaScript</a>';
            } else {
                $url = preg_replace('/&(amp;)?(start|mpc|recipient)=[^&]*/', '', \Environment::get('request')) . '&start=' . ($intStart + $intPages) . '&mpc=' . $intPages;
                echo '<script>setTimeout(\'window.location="' . \Environment::get('base') . $url . '"\',' . $intTimeout * 1000 . ')</script>';
                echo '<a href="' . \Environment::get('base') . $url . '">Please click here to proceed if you are not using JavaScript</a>';
            }
            echo '</div></div>';
            exit;
        }
        $strToken = md5(uniqid(mt_rand(), true));
        $this->Session->set('tl_newsletter_send', $strToken);
        $sprintf = $objNewsletter->senderName != '' ? $objNewsletter->senderName . ' &lt;%s&gt;' : '%s';
        $this->import('BackendUser', 'User');
        // prepare preview
        $preview = $text;
        if (!$objNewsletter->sendText) {
            // Default template
            if ($objNewsletter->template == '') {
                $objNewsletter->template = 'mail_default';
            }
            // Load the mail template
            $objTemplate = new \BackendTemplate($objNewsletter->template);
            $objTemplate->setData($objNewsletter->row());
            $objTemplate->title = $objNewsletter->subject;
            $objTemplate->body = $html;
            $objTemplate->charset = $GLOBALS['TL_CONFIG']['characterSet'];
            $objTemplate->css = $css;
            // Backwards compatibility
            // Parse template
            $preview = $objTemplate->parse();
        }
        // Replace inserttags
        $arrName = explode(' ', $this->User->name);
        $preview = $this->replaceInsertTags($preview);
        $preview = $this->prepareLinkTracking($preview, $objNewsletter->id, $this->User->email, '&preview=1');
        $preview = $this->parseSimpleTokens($preview, array('firstname' => $arrName[0], 'lastname' => $arrName[sizeof($arrName) - 1], 'street' => 'Königsbrücker Str. 9', 'postal' => '01099', 'city' => 'Dresden', 'phone' => '0351 30966184', 'email' => $this->User->email, 'tracker_png' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $this->User->email . '&preview=1&t=png', 'tracker_gif' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $this->User->email . '&preview=1&t=gif', 'tracker_css' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $this->User->email . '&preview=1&t=css', 'tracker_js' => \Environment::get('base') . 'tracking/?n=' . $objNewsletter->id . '&e=' . $this->User->email . '&preview=1&t=js'));
        // Create cache folder
        if (!file_exists(TL_ROOT . '/system/cache/newsletter')) {
            mkdir(TL_ROOT . '/system/cache/newsletter');
            file_put_contents(TL_ROOT . '/system/cache/newsletter/.htaccess', '<IfModule !mod_authz_core.c>
  Order allow,deny
  Allow from all
</IfModule>
<IfModule mod_authz_core.c>
  Require all granted
</IfModule>');
        }
        // Cache preview
        file_put_contents(TL_ROOT . '/system/cache/newsletter/' . $objNewsletter->alias . '.html', preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', $preview));
        // Preview newsletter
        $return = '
<div id="tl_buttons">
<a href="' . $this->getReferer(true) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>
</div>

<h2 class="sub_headline">' . sprintf($GLOBALS['TL_LANG']['tl_newsletter']['send'][1], $objNewsletter->id) . '</h2>
' . \Message::generate() . '
<form action="' . ampersand(\Environment::get('script'), true) . '" id="tl_newsletter_send" class="tl_form" method="get">
<div class="tl_formbody_edit tl_newsletter_send">
<input type="hidden" name="do" value="' . \Input::get('do') . '">
<input type="hidden" name="table" value="' . \Input::get('table') . '">
<input type="hidden" name="key" value="' . \Input::get('key') . '">
<input type="hidden" name="id" value="' . \Input::get('id') . '">
<input type="hidden" name="token" value="' . $strToken . '">
<table class="prev_header">
  <tr class="row_0">
    <td class="col_0">' . $GLOBALS['TL_LANG']['tl_newsletter']['from'] . '</td>
    <td class="col_1">' . sprintf($sprintf, $objNewsletter->sender) . '</td>
  </tr>
  <tr class="row_1">
    <td class="col_0">' . $GLOBALS['TL_LANG']['tl_newsletter']['subject'][0] . '</td>
    <td class="col_1">' . $objNewsletter->subject . '</td>
  </tr>
  <tr class="row_2">
    <td class="col_0">' . $GLOBALS['TL_LANG']['tl_newsletter']['template'][0] . '</td>
    <td class="col_1">' . $objNewsletter->template . '</td>
  </tr>' . (!empty($arrAttachments) && is_array($arrAttachments) ? '
  <tr class="row_3">
    <td class="col_0">' . $GLOBALS['TL_LANG']['tl_newsletter']['attachments'] . '</td>
    <td class="col_1">' . implode(', ', $arrAttachments) . '</td>
  </tr>' : '') . '
</table>' . (!$objNewsletter->sendText ? '
<iframe class="preview_html" id="preview_html" seamless border="0" width="703px" height="503px" style="padding:0" src="system/cache/newsletter/' . $objNewsletter->alias . '.html"></iframe>
' : '') . '
<div class="preview_text">
' . nl2br_html5($text) . '
</div>

<div class="tl_tbox">
<div class="w50">
  <h3><label for="ctrl_mpc">' . $GLOBALS['TL_LANG']['tl_newsletter']['mailsPerCycle'][0] . '</label></h3>
  <input type="text" name="mpc" id="ctrl_mpc" value="10" class="tl_text" onfocus="Backend.getScrollOffset()">' . ($GLOBALS['TL_LANG']['tl_newsletter']['mailsPerCycle'][1] && $GLOBALS['TL_CONFIG']['showHelp'] ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_newsletter']['mailsPerCycle'][1] . '</p>' : '') . '
</div>
<div class="w50">
  <h3><label for="ctrl_timeout">' . $GLOBALS['TL_LANG']['tl_newsletter']['timeout'][0] . '</label></h3>
  <input type="text" name="timeout" id="ctrl_timeout" value="1" class="tl_text" onfocus="Backend.getScrollOffset()">' . ($GLOBALS['TL_LANG']['tl_newsletter']['timeout'][1] && $GLOBALS['TL_CONFIG']['showHelp'] ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_newsletter']['timeout'][1] . '</p>' : '') . '
</div>
<div class="w50">
  <h3><label for="ctrl_start">' . $GLOBALS['TL_LANG']['tl_newsletter']['start'][0] . '</label></h3>
  <input type="text" name="start" id="ctrl_start" value="0" class="tl_text" onfocus="Backend.getScrollOffset()">' . ($GLOBALS['TL_LANG']['tl_newsletter']['start'][1] && $GLOBALS['TL_CONFIG']['showHelp'] ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_newsletter']['start'][1] . '</p>' : '') . '
</div>
<div class="w50">
  <h3><label for="ctrl_recipient">' . $GLOBALS['TL_LANG']['tl_newsletter']['sendPreviewTo'][0] . '</label></h3>
  <input type="text" name="recipient" id="ctrl_recipient" value="' . $this->User->email . '" class="tl_text" onfocus="Backend.getScrollOffset()">' . (isset($_SESSION['TL_PREVIEW_MAIL_ERROR']) ? '
  <div class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['email'] . '</div>' : ($GLOBALS['TL_LANG']['tl_newsletter']['sendPreviewTo'][1] && $GLOBALS['TL_CONFIG']['showHelp'] ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_newsletter']['sendPreviewTo'][1] . '</p>' : '')) . '
</div>
<div class="clear"></div>
</div>
</div>';
        // Do not send the newsletter if there is an attachment format error
        if (!$blnAttachmentsFormatError) {
            $return .= '

<div class="tl_formbody_submit">
<div class="tl_submit_container">
<input type="submit" name="preview" class="tl_submit" accesskey="p" value="' . specialchars($GLOBALS['TL_LANG']['tl_newsletter']['preview']) . '">
<input type="submit" id="send" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['tl_newsletter']['send'][0]) . '" onclick="return confirm(\'' . str_replace("'", "\\'", $GLOBALS['TL_LANG']['tl_newsletter']['sendConfirm']) . '\')">
</div>
</div>';
        }
        $return .= '

</form>';
        unset($_SESSION['TL_PREVIEW_MAIL_ERROR']);
        return $return;
    }
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var PageModel $objPage */
     global $objPage;
     $this->Template->content = '';
     $this->Template->referer = 'javascript:history.go(-1)';
     $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
     $objNewsletter = \NewsletterModel::findSentByParentAndIdOrAlias(\Input::get('items'), $this->nl_channels);
     if (null === $objNewsletter) {
         throw new PageNotFoundException('Page not found: ' . \Environment::get('uri'));
     }
     // Overwrite the page title (see #2853 and #4955)
     if ($objNewsletter->subject != '') {
         $objPage->pageTitle = strip_tags(\StringUtil::stripInsertTags($objNewsletter->subject));
     }
     // Add enclosure
     if ($objNewsletter->addFile) {
         $this->addEnclosuresToTemplate($this->Template, $objNewsletter->row(), 'files');
     }
     // Support plain text newsletters (thanks to Hagen Klemp)
     if ($objNewsletter->sendText) {
         $strContent = nl2br_html5($objNewsletter->text);
     } else {
         $strContent = str_ireplace(' align="center"', '', $objNewsletter->content);
     }
     // Parse simple tokens and insert tags
     $strContent = $this->replaceInsertTags($strContent);
     $strContent = \StringUtil::parseSimpleTokens($strContent, array());
     // Encode e-mail addresses
     $strContent = \StringUtil::encodeEmail($strContent);
     $this->Template->content = $strContent;
     $this->Template->subject = $objNewsletter->subject;
 }
Example #10
0
    /**
     * List records
     * @param array
     * @return string
     */
    public function listNewsletters($arrRow)
    {
        return '
<div class="cte_type ' . ($arrRow['sent'] && $arrRow['date'] ? 'published' : 'unpublished') . '"><strong>' . $arrRow['subject'] . '</strong> - ' . ($arrRow['sent'] && $arrRow['date'] ? sprintf($GLOBALS['TL_LANG']['tl_newsletter']['sentOn'], $this->parseDate($GLOBALS['TL_CONFIG']['datimFormat'], $arrRow['date'])) : $GLOBALS['TL_LANG']['tl_newsletter']['notSent']) . '</div>
<div class="limit_height' . (!$GLOBALS['TL_CONFIG']['doNotCollapse'] ? ' h128' : '') . '">' . (!$arrRow['sendText'] ? '
' . $arrRow['content'] . '<hr>' : '') . '
' . nl2br_html5($arrRow['text']) . '
</div>' . "\n";
    }
Example #11
0
 /**
  * Get for a field the readable value
  *
  * @param string $strFieldName
  * @param mixed $mixValue
  * @return mixed [string|int]
  */
 public function getReadableFieldValue($strFieldName, $mixValue)
 {
     if (!key_exists($strFieldName, $this->arrDCA['fields'])) {
         return $mixValue;
     }
     // Load the config for current field
     $arrFieldConfig = $this->arrDCA['fields'][$strFieldName];
     $mixModelField = $this->objCurrentModel->getProperty($strFieldName);
     /*
      * @todo Maybe the controlle should handle this ?
      */
     if (isset($arrFieldConfig['foreignKey'])) {
         $temp = array();
         $chunks = explode('.', $arrFieldConfig['foreignKey'], 2);
         foreach ((array) $value as $v) {
             //                    $objKey = $this->Database->prepare("SELECT " . $chunks[1] . " AS value FROM " . $chunks[0] . " WHERE id=?")
             //                            ->limit(1)
             //                            ->execute($v);
             //
             //                    if ($objKey->numRows)
             //                    {
             //                        $temp[] = $objKey->value;
             //                    }
         }
         //                $row[$i] = implode(', ', $temp);
     } else {
         if (is_array($mixValue)) {
             foreach ($mixValue as $kk => $vv) {
                 if (is_array($vv)) {
                     $vals = array_values($vv);
                     $mixValue[$kk] = $vals[0] . ' (' . $vals[1] . ')';
                 }
             }
             return implode(', ', $mixValue);
         } else {
             if ($arrFieldConfig['eval']['rgxp'] == 'date') {
                 return $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $mixValue);
             } else {
                 if ($arrFieldConfig['eval']['rgxp'] == 'time') {
                     return $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $mixValue);
                 } else {
                     if ($arrFieldConfig['eval']['rgxp'] == 'datim' || in_array($arrFieldConfig['flag'], array(5, 6, 7, 8, 9, 10)) || $strFieldName == 'tstamp') {
                         return $this->parseDate($GLOBALS['TL_CONFIG']['datimFormat'], $mixValue);
                     } else {
                         if ($arrFieldConfig['inputType'] == 'checkbox' && !$arrFieldConfig['eval']['multiple']) {
                             return strlen($mixValue) ? $GLOBALS['TL_LANG']['MSC']['yes'] : $GLOBALS['TL_LANG']['MSC']['no'];
                         } else {
                             if ($arrFieldConfig['inputType'] == 'textarea' && ($arrFieldConfig['eval']['allowHtml'] || $arrFieldConfig['eval']['preserveTags'])) {
                                 return nl2br_html5(specialchars($mixValue));
                             } else {
                                 if (is_array($arrFieldConfig['reference'])) {
                                     return isset($arrFieldConfig['reference'][$mixModelField]) ? is_array($arrFieldConfig['reference'][$mixModelField]) ? $arrFieldConfig['reference'][$mixModelField][0] : $arrFieldConfig['reference'][$mixModelField] : $mixModelField;
                                 } else {
                                     if (array_is_assoc($arrFieldConfig['options'])) {
                                         return $arrFieldConfig['options'][$mixModelField];
                                     } else {
                                         return $mixValue;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #12
0
 /**
  * Render a string if not allow html or preserve tags is given.
  *
  * @param RenderReadablePropertyValueEvent $event The event to store the value to.
  *
  * @param array                            $extra The extra data from the property.
  *
  * @param string                           $value The value to format.
  *
  * @return void
  */
 private static function renderTextAreaReadable(RenderReadablePropertyValueEvent $event, $extra, $value)
 {
     if (empty($extra['allowHtml']) && empty($extra['preserveTags'])) {
         return;
     }
     $event->setRendered(nl2br_html5(specialchars($value)));
 }
Example #13
0
 /**
  * Returns the information-array about an album
  *
  * @param $intAlbumId
  * @param $objContentElement
  * @return array
  */
 public static function getAlbumInformationArray($intAlbumId, $objContentElement)
 {
     global $objPage;
     // Get the page model
     $objPageModel = \PageModel::findByPk($objPage->id);
     $objAlbum = \Database::getInstance()->prepare('SELECT * FROM tl_gallery_creator_albums WHERE id=?')->execute($intAlbumId);
     //Anzahl Subalben ermitteln
     $objSubAlbums = \Database::getInstance()->prepare('SELECT thumb, count(id) AS countSubalbums FROM tl_gallery_creator_albums WHERE published=? AND pid=? GROUP BY ?')->execute('1', $intAlbumId, 'id');
     $objPics = \Database::getInstance()->prepare('SELECT * FROM tl_gallery_creator_pictures WHERE pid=? AND published=?')->execute($objAlbum->id, '1');
     //Array Thumbnailbreite
     $arrSize = unserialize($objContentElement->gc_size_albumlisting);
     $href = null;
     if (TL_MODE == 'FE') {
         //generate the url as a formated string
         $href = $objPageModel->getFrontendUrl($GLOBALS['TL_CONFIG']['useAutoItem'] ? '/%s' : '/items/%s', $objPage->language);
         // add albumAlias
         $href = sprintf($href, $objAlbum->alias);
     }
     $arrPreviewThumb = $objContentElement->getAlbumPreviewThumb($objAlbum->id);
     $strImageSrc = $arrPreviewThumb['path'];
     //Generate the thumbnails and the picture element
     try {
         $thumbSrc = \Image::create($strImageSrc, $arrSize)->executeResize()->getResizedPath();
         $picture = \Picture::create($strImageSrc, $arrSize)->getTemplateData();
         if ($thumbSrc !== $strImageSrc) {
             new \File(rawurldecode($thumbSrc), true);
         }
     } catch (\Exception $e) {
         \System::log('Image "' . $strImageSrc . '" could not be processed: ' . $e->getMessage(), __METHOD__, TL_ERROR);
     }
     $picture['alt'] = specialchars($objAlbum->name);
     $picture['title'] = specialchars($objAlbum->name);
     // CSS class
     $strCSSClass = \GalleryCreatorAlbumsModel::hasChildAlbums($objAlbum->id) ? 'has-child-album' : '';
     $strCSSClass .= $objPics->numRows < 1 ? ' empty-album' : '';
     $arrAlbum = array('id' => $objAlbum->id, 'pid' => $objAlbum->pid, 'sorting' => $objAlbum->sorting, 'published' => $objAlbum->published, 'owner' => $objAlbum->owner, 'owners_name' => $objAlbum->owners_name, 'tstamp' => $objAlbum->tstamp, 'event_tstamp' => $objAlbum->date, 'date' => $objAlbum->date, 'event_date' => \Date::parse($GLOBALS['TL_CONFIG']['dateFormat'], $objAlbum->date), 'event_location' => specialchars($objAlbum->event_location), 'name' => specialchars($objAlbum->name), 'alias' => $objAlbum->alias, 'comment' => $objPage->outputFormat == 'xhtml' ? \StringUtil::toXhtml(nl2br_xhtml($objAlbum->comment)) : \StringUtil::toHtml5(nl2br_html5($objAlbum->comment)), 'caption' => $objPage->outputFormat == 'xhtml' ? \StringUtil::toXhtml(nl2br_xhtml($objAlbum->comment)) : \StringUtil::toHtml5(nl2br_html5($objAlbum->comment)), 'visitors' => $objAlbum->visitors, 'href' => $href, 'title' => $objAlbum->name . ' [' . ($objPics->numRows ? $objPics->numRows . ' ' . $GLOBALS['TL_LANG']['gallery_creator']['pictures'] : '') . ($objContentElement->gc_hierarchicalOutput && $objSubAlbums->countSubalbums > 0 ? ' ' . $GLOBALS['TL_LANG']['gallery_creator']['contains'] . ' ' . $objSubAlbums->countSubalbums . '  ' . $GLOBALS['TL_LANG']['gallery_creator']['subalbums'] . ']' : ']'), 'count' => $objPics->numRows, 'count_subalbums' => count(\GalleryCreatorAlbumsModel::getChildAlbums($objAlbum->id)), 'alt' => $arrPreviewThumb['name'], 'src' => TL_FILES_URL . $arrPreviewThumb['path'], 'thumb_src' => TL_FILES_URL . \Image::get($arrPreviewThumb['path'], $arrSize[0], $arrSize[1], $arrSize[2]), 'insert_article_pre' => $objAlbum->insert_article_pre ? $objAlbum->insert_article_pre : null, 'insert_article_post' => $objAlbum->insert_article_post ? $objAlbum->insert_article_post : null, 'class' => 'thumb', 'size' => $arrSize, 'thumbMouseover' => $objContentElement->gc_activateThumbSlider ? "objGalleryCreator.initThumbSlide(this," . $objAlbum->id . "," . $objPics->numRows . ");" : "", 'picture' => $picture, 'cssClass' => trim($strCSSClass));
     // Fuegt dem Array weitere Eintraege hinzu, falls tl_gallery_creator_albums erweitert wurde
     $objAlbum = \GalleryCreatorAlbumsModel::findByPk($intAlbumId);
     if ($objAlbum !== null) {
         $arrAlbum = array_merge($objAlbum->row(), $arrAlbum);
     }
     return $arrAlbum;
 }