/** * Return if there are no files * * @return string */ public function generate() { // Use the home directory of the current user as file source if ($this->useHomeDir && FE_USER_LOGGED_IN) { $this->import('FrontendUser', 'User'); if ($this->User->assignDir && $this->User->homeDir) { $this->multiSRC = array($this->User->homeDir); } } else { $this->multiSRC = deserialize($this->multiSRC); } // Return if there are no files if (!is_array($this->multiSRC) || empty($this->multiSRC)) { return ''; } // Get the file entries from the database $this->objFiles = \FilesModel::findMultipleByUuids($this->multiSRC); if ($this->objFiles === null) { if (!\Validator::isUuid($this->multiSRC[0])) { return '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } return ''; } return parent::generate(); }
/** * Collect all Songs per Playlist and return them as array * * @param object $objSongs * @return array */ public function getFiles($objSongs) { $arrFiles = array(); $i = 0; if ($objSongs === null) { return; } while ($objSongs->next()) { $arrSong = $objSongs->row(); $arrFiles[$i]['protected'] = $arrSong['protected']; $arrFiles[$i]['groups'] = $arrSong['groups']; $arrFiles[$i]['id'] = $arrSong['id']; $arrFiles[$i]['interpreter'] = $arrSong['interpreter']; $arrFiles[$i]['title'] = $arrSong['title']; $arrFiles[$i]['album'] = $arrSong['album']; $arrFiles[$i]['track'] = $arrSong['track']; $arrFiles[$i]['files'] = array(); $arrUuids = deserialize($arrSong['file']); $objSongFiles = \FilesModel::findMultipleByUuids($arrUuids); while ($objSongFiles->next()) { $arrSongFile = $objSongFiles->row(); $objFile = new \Contao\File($arrSongFile['path'], true); $arrFiles[$i]['files'][] = array('file' => $arrSongFile['path'], 'type' => $objFile->mime); } $i++; } // sort out protected songs $arrFiles = $this->sortOutProtected($arrFiles); return $arrFiles; }
/** * Return if there are no files * * @return string */ public function generate() { // Use the home directory of the current user as file source if ($this->useHomeDir && FE_USER_LOGGED_IN) { $this->import('FrontendUser', 'User'); if ($this->User->assignDir && $this->User->homeDir) { $this->multiSRC = array($this->User->homeDir); } } else { $this->multiSRC = deserialize($this->multiSRC); } // Return if there are no files if (!is_array($this->multiSRC) || empty($this->multiSRC)) { return ''; } // Get the file entries from the database $this->objFiles = \FilesModel::findMultipleByUuids($this->multiSRC); if ($this->objFiles === null) { if (!\Validator::isUuid($this->multiSRC[0])) { return '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } return ''; } $file = \Input::get('file', true); // Send the file to the browser and do not send a 404 header (see #4632) if ($file != '' && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', basename($file))) { while ($this->objFiles->next()) { if ($file == $this->objFiles->path || dirname($file) == $this->objFiles->path) { \Controller::sendFileToBrowser($file); } } $this->objFiles->reset(); } return parent::generate(); }
/** * @param $multiSRC */ public function getAllImages($multiSRC) { $this->multiSRC = $multiSRC; $arrMultiSRC = $multiSRC ? deserialize($multiSRC) : array(); if (!$this->objFiles && is_array($arrMultiSRC)) { $this->objFiles = \FilesModel::findMultipleByUuids($arrMultiSRC); } }
/** * Check the source folder * * @return string */ public function generate() { $this->multiSRC = deserialize($this->multiSRC); if (!is_array($this->multiSRC) || empty($this->multiSRC)) { return ''; } $this->objFiles = \FilesModel::findMultipleByUuids($this->multiSRC); if ($this->objFiles === null) { return ''; } return parent::generate(); }
/** * Generate the content element */ public function compile() { $newMultiSRC = array(); if (strlen(\Input::get('tag')) && !$this->tag_ignore || strlen($this->tag_filter)) { $tagids = array(); $relatedlist = strlen(\Input::get('related')) ? preg_split("/,/", \Input::get('related')) : array(); $alltags = array_merge(array(\Input::get('tag')), $relatedlist); $first = true; if (strlen($this->tag_filter)) { $headlinetags = preg_split("/,/", $this->tag_filter); $tagids = $this->getFilterTags(); $first = false; } else { $headlinetags = array(); } foreach ($alltags as $tag) { if (strlen(trim($tag))) { if (count($tagids)) { $tagids = $this->Database->prepare("SELECT tid FROM tl_tag WHERE from_table = ? AND tag = ? AND tid IN (" . join($tagids, ",") . ")")->execute('tl_files', $tag)->fetchEach('tid'); } else { if ($first) { $tagids = $this->Database->prepare("SELECT tid FROM tl_tag WHERE from_table = ? AND tag = ?")->execute('tl_files', $tag)->fetchEach('tid'); $first = false; } } } } while ($this->objFiles->next()) { if ($this->objFiles->type == 'file') { if (in_array($this->objFiles->id, $tagids)) { array_push($newMultiSRC, $this->objFiles->uuid); } } else { $objSubfiles = \FilesModel::findByPid($this->objFiles->uuid); if ($objSubfiles === null) { continue; } while ($objSubfiles->next()) { if (in_array($objSubfiles->id, $tagids)) { array_push($newMultiSRC, $objSubfiles->uuid); } } } } $this->multiSRC = $newMultiSRC; $this->objFiles = \FilesModel::findMultipleByUuids($this->multiSRC); if ($this->objFiles === null) { return ''; } } parent::compile(); }
/** * Check the source folder * @return string */ public function generate() { $this->multiSRC = deserialize($this->multiSRC); if (!is_array($this->multiSRC) || empty($this->multiSRC)) { return ''; } $this->objFiles = \FilesModel::findMultipleByUuids($this->multiSRC); if ($this->objFiles === null) { if (!\Validator::isUuid($this->multiSRC[0])) { return '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } return ''; } return parent::generate(); }
public function getAttachments() { // Token attachments $arrAttachments = StringUtil::getTokenAttachments($this->objLanguage->attachment_tokens, $this->arrTokens); // Add static attachments $arrStaticAttachments = deserialize($this->objLanguage->attachments, true); if (!empty($arrStaticAttachments)) { $objFiles = \FilesModel::findMultipleByUuids($arrStaticAttachments); if ($objFiles === null) { return $arrAttachments; } while ($objFiles->next()) { $arrAttachments[] = TL_ROOT . '/' . $objFiles->path; } } return $arrAttachments; }
public function generate(\PageModel $objPage, \LayoutModel $objLayout, \PageRegular $objPageRegular) { if (TL_MODE == 'BE') { return; } $this->objPageBg = $this->searchForBackgroundImages($objPage); // Return if there are no files if (!$this->objPageBg) { return; } // Get the file entries from the database $this->objFiles = \FilesModel::findMultipleByUuids($this->objPageBg->paSRC); if ($this->objFiles === null) { if (!\Validator::isUuid($this->objPageBg->paSRC[0])) { \System::log($GLOBALS['TL_LANG']['ERR']['version2format'], __METHOD__, TL_ERROR); } return; } $this->order = $this->objPageBg->paOrder; $this->compile($objPage); }
private function getMultiMetaData($multiSRC) { global $objPage; $images = array(); $objFiles = \FilesModel::findMultipleByUuids(unserialize($multiSRC)); if ($objFiles !== null) { while ($objFiles->next()) { // Continue if the files has been processed or does not exist if (isset($images[$objFiles->path]) || !file_exists(TL_ROOT . '/' . $objFiles->path)) { continue; } // Single files if ($objFiles->type == 'file') { $objFile = new \File($objFiles->path, true); if (!$objFile->isGdImage) { continue; } $images[$objFiles->path] = $this->getMetaData($objFiles->meta, $objPage->language); } else { $objSubfiles = \FilesModel::findByPid($objFiles->uuid); if ($objSubfiles === null) { continue; } while ($objSubfiles->next()) { // Skip subfolders if ($objSubfiles->type == 'folder') { continue; } $objFile = new \File($objSubfiles->path, true); if (!$objFile->isGdImage) { continue; } $images[$objFile->path] = $this->getMetaData($objSubfiles->meta, $objPage->language); } } } } // END if($objFiles !== null) return $images; }
/** * Return if there are no files * * @return string */ public function generate() { $this->multiSRC = deserialize($this->dk_msryMultiSRC); // Return if there are no files if (!is_array($this->multiSRC) || empty($this->multiSRC)) { return ''; } // Get the file entries from the database $this->objFiles = \FilesModel::findMultipleByUuids($this->multiSRC); if ($this->objFiles === null) { return ''; } // replace default (HTML) template with chosen one if ($this->dk_msryHtmlTpl) { $this->strTemplate = $this->dk_msryHtmlTpl; } // replace default (JS) template with chosen one if ($this->dk_msryJsTpl) { $this->strTemplateJs = $this->dk_msryJsTpl; } return parent::generate(); }
/** * Show header of the parent table and list all records of the current table * * @return string */ protected function parentView() { $blnClipboard = false; $arrClipboard = $this->Session->get('CLIPBOARD'); $table = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 6 ? $this->ptable : $this->strTable; $blnHasSorting = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['fields'][0] == 'sorting'; $blnMultiboard = false; // Check clipboard if (!empty($arrClipboard[$table])) { $blnClipboard = true; $arrClipboard = $arrClipboard[$table]; if (is_array($arrClipboard['id'])) { $blnMultiboard = true; } } // Load the fonts to display the paste hint \Config::set('loadGoogleFonts', $blnClipboard); // Load the language file and data container array of the parent table \System::loadLanguageFile($this->ptable); $this->loadDataContainer($this->ptable); $return = ' <div id="tl_buttons">' . (\Input::get('nb') ? ' ' : ($this->ptable ? ' <a href="' . $this->getReferer(true, $this->ptable) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>' : (isset($GLOBALS['TL_DCA'][$this->strTable]['config']['backlink']) ? ' <a href="contao/main.php?' . $GLOBALS['TL_DCA'][$this->strTable]['config']['backlink'] . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>' : ''))) . ' ' . (\Input::get('act') != 'select' && !$blnClipboard && !$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable'] ? ' <a href="' . $this->addToUrl($blnHasSorting ? 'act=paste&mode=create' : 'act=create&mode=2&pid=' . $this->intId) . '" class="header_new" title="' . specialchars($GLOBALS['TL_LANG'][$this->strTable]['new'][1]) . '" accesskey="n" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG'][$this->strTable]['new'][0] . '</a> ' : '') . ($blnClipboard ? ' <a href="' . $this->addToUrl('clipboard=1') . '" class="header_clipboard" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['clearClipboard']) . '" accesskey="x">' . $GLOBALS['TL_LANG']['MSC']['clearClipboard'] . '</a> ' : $this->generateGlobalButtons()) . ' </div>' . \Message::generate(true); // Get all details of the parent record $objParent = $this->Database->prepare("SELECT * FROM " . $this->ptable . " WHERE id=?")->limit(1)->execute(CURRENT_ID); if ($objParent->numRows < 1) { return $return; } $return .= (\Input::get('act') == 'select' ? ' <form action="' . ampersand(\Environment::get('request'), true) . '" id="tl_select" class="tl_form' . (\Input::get('act') == 'select' ? ' unselectable' : '') . '" method="post" novalidate> <div class="tl_formbody"> <input type="hidden" name="FORM_SUBMIT" value="tl_select"> <input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">' : '') . ($blnClipboard ? ' <div id="paste_hint"> <p>' . $GLOBALS['TL_LANG']['MSC']['selectNewPosition'] . '</p> </div>' : '') . ' <div class="tl_listing_container parent_view"> <div class="tl_header click2edit toggle_select" onmouseover="Theme.hoverDiv(this,1)" onmouseout="Theme.hoverDiv(this,0)">'; // List all records of the child table if (!\Input::get('act') || \Input::get('act') == 'paste' || \Input::get('act') == 'select') { $this->import('BackendUser', 'User'); // Header $imagePasteNew = \Image::getHtml('new.gif', $GLOBALS['TL_LANG'][$this->strTable]['pastenew'][0]); $imagePasteAfter = \Image::getHtml('pasteafter.gif', $GLOBALS['TL_LANG'][$this->strTable]['pasteafter'][0]); $imageEditHeader = \Image::getHtml('header.gif', $GLOBALS['TL_LANG'][$this->strTable]['editheader'][0]); $return .= ' <div class="tl_content_right">' . (\Input::get('act') == 'select' ? ' <label for="tl_select_trigger" class="tl_select_label">' . $GLOBALS['TL_LANG']['MSC']['selectAll'] . '</label> <input type="checkbox" id="tl_select_trigger" onclick="Backend.toggleCheckboxes(this)" class="tl_tree_checkbox">' : ($blnClipboard ? ' <a href="' . $this->addToUrl('act=' . $arrClipboard['mode'] . '&mode=2&pid=' . $objParent->id . (!$blnMultiboard ? '&id=' . $arrClipboard['id'] : '')) . '" title="' . specialchars($GLOBALS['TL_LANG'][$this->strTable]['pasteafter'][0]) . '" onclick="Backend.getScrollOffset()">' . $imagePasteAfter . '</a>' : (!$GLOBALS['TL_DCA'][$this->ptable]['config']['notEditable'] && $this->User->canEditFieldsOf($this->ptable) ? ' <a href="' . preg_replace('/&(amp;)?table=[^& ]*/i', $this->ptable != '' ? '&table=' . $this->ptable : '', $this->addToUrl('act=edit')) . '" class="edit" title="' . specialchars($GLOBALS['TL_LANG'][$this->strTable]['editheader'][1]) . '">' . $imageEditHeader . '</a>' : '') . ($blnHasSorting && !$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable'] ? ' <a href="' . $this->addToUrl('act=create&mode=2&pid=' . $objParent->id . '&id=' . $this->intId) . '" title="' . specialchars($GLOBALS['TL_LANG'][$this->strTable]['pastenew'][0]) . '">' . $imagePasteNew . '</a>' : ''))) . ' </div>'; // Format header fields $add = array(); $headerFields = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['headerFields']; foreach ($headerFields as $v) { $_v = deserialize($objParent->{$v}); // Translate UUIDs to paths if ($GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['inputType'] == 'fileTree') { $objFiles = \FilesModel::findMultipleByUuids((array) $_v); if ($objFiles !== null) { $_v = $objFiles->fetchEach('path'); } } if (is_array($_v)) { $_v = implode(', ', $_v); } elseif ($GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['inputType'] == 'checkbox' && !$GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['eval']['multiple']) { $_v = $_v != '' ? $GLOBALS['TL_LANG']['MSC']['yes'] : $GLOBALS['TL_LANG']['MSC']['no']; } elseif ($GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['eval']['rgxp'] == 'date') { $_v = $_v ? \Date::parse(\Config::get('dateFormat'), $_v) : '-'; } elseif ($GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['eval']['rgxp'] == 'time') { $_v = $_v ? \Date::parse(\Config::get('timeFormat'), $_v) : '-'; } elseif ($GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['eval']['rgxp'] == 'datim') { $_v = $_v ? \Date::parse(\Config::get('datimFormat'), $_v) : '-'; } elseif ($v == 'tstamp') { if ($GLOBALS['TL_DCA'][$this->strTable]['config']['dynamicPtable']) { $ptable = $GLOBALS['TL_DCA'][$this->strTable]['config']['ptable']; $cond = $ptable == 'tl_article' ? "(ptable=? OR ptable='')" : "ptable=?"; // backwards compatibility $objMaxTstamp = $this->Database->prepare("SELECT MAX(tstamp) AS tstamp FROM " . $this->strTable . " WHERE pid=? AND {$cond}")->execute($objParent->id, $ptable); } else { $objMaxTstamp = $this->Database->prepare("SELECT MAX(tstamp) AS tstamp FROM " . $this->strTable . " WHERE pid=?")->execute($objParent->id); } if (!$objMaxTstamp->tstamp) { $objMaxTstamp->tstamp = $objParent->tstamp; } $_v = \Date::parse(\Config::get('datimFormat'), max($objParent->tstamp, $objMaxTstamp->tstamp)); } elseif (isset($GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['foreignKey'])) { $arrForeignKey = explode('.', $GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['foreignKey'], 2); $objLabel = $this->Database->prepare("SELECT " . $arrForeignKey[1] . " AS value FROM " . $arrForeignKey[0] . " WHERE id=?")->limit(1)->execute($_v); if ($objLabel->numRows) { $_v = $objLabel->value; } } elseif (is_array($GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['reference'][$_v])) { $_v = $GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['reference'][$_v][0]; } elseif (isset($GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['reference'][$_v])) { $_v = $GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['reference'][$_v]; } elseif ($GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['eval']['isAssociative'] || array_is_assoc($GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['options'])) { $_v = $GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['options'][$_v]; } elseif (is_array($GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['options_callback'])) { $strClass = $GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['options_callback'][0]; $strMethod = $GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['options_callback'][1]; $this->import($strClass); $options_callback = $this->{$strClass}->{$strMethod}($this); $_v = $options_callback[$_v]; } elseif (is_callable($GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['options_callback'])) { $options_callback = $GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['options_callback']($this); $_v = $options_callback[$_v]; } // Add the sorting field if ($_v != '') { if (isset($GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['label'])) { $key = is_array($GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['label']) ? $GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['label'][0] : $GLOBALS['TL_DCA'][$this->ptable]['fields'][$v]['label']; } else { $key = isset($GLOBALS['TL_LANG'][$this->ptable][$v][0]) ? $GLOBALS['TL_LANG'][$this->ptable][$v][0] : $v; } $add[$key] = $_v; } } // Trigger the header_callback (see #3417) if (is_array($GLOBALS['TL_DCA'][$table]['list']['sorting']['header_callback'])) { $strClass = $GLOBALS['TL_DCA'][$table]['list']['sorting']['header_callback'][0]; $strMethod = $GLOBALS['TL_DCA'][$table]['list']['sorting']['header_callback'][1]; $this->import($strClass); $add = $this->{$strClass}->{$strMethod}($add, $this); } elseif (is_callable($GLOBALS['TL_DCA'][$table]['list']['sorting']['header_callback'])) { $add = $GLOBALS['TL_DCA'][$table]['list']['sorting']['header_callback']($add, $this); } // Output the header data $return .= ' <table class="tl_header_table">'; foreach ($add as $k => $v) { if (is_array($v)) { $v = $v[0]; } $return .= ' <tr> <td><span class="tl_label">' . $k . ':</span> </td> <td>' . $v . '</td> </tr>'; } $return .= ' </table> </div>'; $orderBy = array(); $firstOrderBy = array(); // Add all records of the current table $query = "SELECT * FROM " . $this->strTable; if (is_array($this->orderBy) && strlen($this->orderBy[0])) { $orderBy = $this->orderBy; $firstOrderBy = preg_replace('/\\s+.*$/', '', $orderBy[0]); // Order by the foreign key if (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$firstOrderBy]['foreignKey'])) { $key = explode('.', $GLOBALS['TL_DCA'][$this->strTable]['fields'][$firstOrderBy]['foreignKey'], 2); $query = "SELECT *, (SELECT " . $key[1] . " FROM " . $key[0] . " WHERE " . $this->strTable . "." . $firstOrderBy . "=" . $key[0] . ".id) AS foreignKey FROM " . $this->strTable; $orderBy[0] = 'foreignKey'; } } elseif (is_array($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['fields'])) { $orderBy = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['fields']; $firstOrderBy = preg_replace('/\\s+.*$/', '', $orderBy[0]); } $arrProcedure = $this->procedure; $arrValues = $this->values; // Support empty ptable fields (backwards compatibility) if ($GLOBALS['TL_DCA'][$this->strTable]['config']['dynamicPtable']) { $arrProcedure[] = $this->ptable == 'tl_article' ? "(ptable=? OR ptable='')" : "ptable=?"; $arrValues[] = $this->ptable; } // WHERE if (!empty($arrProcedure)) { $query .= " WHERE " . implode(' AND ', $arrProcedure); } if (!empty($this->root) && is_array($this->root)) { $query .= (!empty($arrProcedure) ? " AND " : " WHERE ") . "id IN(" . implode(',', array_map('intval', $this->root)) . ")"; } // ORDER BY if (!empty($orderBy) && is_array($orderBy)) { $query .= " ORDER BY " . implode(', ', $orderBy); } $objOrderByStmt = $this->Database->prepare($query); // LIMIT if (strlen($this->limit)) { $arrLimit = explode(',', $this->limit); $objOrderByStmt->limit($arrLimit[1], $arrLimit[0]); } $objOrderBy = $objOrderByStmt->execute($arrValues); if ($objOrderBy->numRows < 1) { return $return . ' <p class="tl_empty_parent_view">' . $GLOBALS['TL_LANG']['MSC']['noResult'] . '</p> </div>'; } // Call the child_record_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['child_record_callback']) || is_callable($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['child_record_callback'])) { $strGroup = ''; $blnIndent = false; $intWrapLevel = 0; $row = $objOrderBy->fetchAllAssoc(); // Make items sortable if ($blnHasSorting) { $return .= ' <ul id="ul_' . CURRENT_ID . '">'; } for ($i = 0, $c = count($row); $i < $c; $i++) { $this->current[] = $row[$i]['id']; $imagePasteAfter = \Image::getHtml('pasteafter.gif', sprintf($GLOBALS['TL_LANG'][$this->strTable]['pasteafter'][1], $row[$i]['id'])); $imagePasteNew = \Image::getHtml('new.gif', sprintf($GLOBALS['TL_LANG'][$this->strTable]['pastenew'][1], $row[$i]['id'])); // Decrypt encrypted value foreach ($row[$i] as $k => $v) { if ($GLOBALS['TL_DCA'][$table]['fields'][$k]['eval']['encrypt']) { $row[$i][$k] = \Encryption::decrypt(deserialize($v)); } } // Make items sortable if ($blnHasSorting) { $return .= ' <li id="li_' . $row[$i]['id'] . '">'; } // Add the group header if (!$GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['disableGrouping'] && $firstOrderBy != 'sorting') { $sortingMode = count($orderBy) == 1 && $firstOrderBy == $orderBy[0] && $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['flag'] != '' && $GLOBALS['TL_DCA'][$this->strTable]['fields'][$firstOrderBy]['flag'] == '' ? $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['flag'] : $GLOBALS['TL_DCA'][$this->strTable]['fields'][$firstOrderBy]['flag']; $remoteNew = $this->formatCurrentValue($firstOrderBy, $row[$i][$firstOrderBy], $sortingMode); $group = $this->formatGroupHeader($firstOrderBy, $remoteNew, $sortingMode, $row); if ($group != $strGroup) { $return .= "\n\n" . '<div class="tl_content_header">' . $group . '</div>'; $strGroup = $group; } } $blnWrapperStart = in_array($row[$i]['type'], $GLOBALS['TL_WRAPPERS']['start']); $blnWrapperSeparator = in_array($row[$i]['type'], $GLOBALS['TL_WRAPPERS']['separator']); $blnWrapperStop = in_array($row[$i]['type'], $GLOBALS['TL_WRAPPERS']['stop']); // Closing wrappers if ($blnWrapperStop) { if (--$intWrapLevel < 1) { $blnIndent = false; } } $return .= ' <div class="tl_content' . ($blnWrapperStart ? ' wrapper_start' : '') . ($blnWrapperSeparator ? ' wrapper_separator' : '') . ($blnWrapperStop ? ' wrapper_stop' : '') . ($blnIndent ? ' indent indent_' . $intWrapLevel : '') . ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['child_record_class'] != '' ? ' ' . $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['child_record_class'] : '') . ($i % 2 == 0 ? ' even' : ' odd') . ' click2edit toggle_select" onmouseover="Theme.hoverDiv(this,1)" onmouseout="Theme.hoverDiv(this,0)"> <div class="tl_content_right">'; // Opening wrappers if ($blnWrapperStart) { if (++$intWrapLevel > 0) { $blnIndent = true; } } // Edit multiple if (\Input::get('act') == 'select') { $return .= '<input type="checkbox" name="IDS[]" id="ids_' . $row[$i]['id'] . '" class="tl_tree_checkbox" value="' . $row[$i]['id'] . '">'; } else { $return .= $this->generateButtons($row[$i], $this->strTable, $this->root, false, null, $row[$i - 1]['id'], $row[$i + 1]['id']); // Sortable table if ($blnHasSorting) { // Create new button if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable']) { $return .= ' <a href="' . $this->addToUrl('act=create&mode=1&pid=' . $row[$i]['id'] . '&id=' . $objParent->id) . '" title="' . specialchars(sprintf($GLOBALS['TL_LANG'][$this->strTable]['pastenew'][1], $row[$i]['id'])) . '">' . $imagePasteNew . '</a>'; } // Prevent circular references if ($blnClipboard && $arrClipboard['mode'] == 'cut' && $row[$i]['id'] == $arrClipboard['id'] || $blnMultiboard && $arrClipboard['mode'] == 'cutAll' && in_array($row[$i]['id'], $arrClipboard['id'])) { $return .= ' ' . \Image::getHtml('pasteafter_.gif'); } elseif ($blnMultiboard) { $return .= ' <a href="' . $this->addToUrl('act=' . $arrClipboard['mode'] . '&mode=1&pid=' . $row[$i]['id']) . '" title="' . specialchars(sprintf($GLOBALS['TL_LANG'][$this->strTable]['pasteafter'][1], $row[$i]['id'])) . '" onclick="Backend.getScrollOffset()">' . $imagePasteAfter . '</a>'; } elseif ($blnClipboard) { $return .= ' <a href="' . $this->addToUrl('act=' . $arrClipboard['mode'] . '&mode=1&pid=' . $row[$i]['id'] . '&id=' . $arrClipboard['id']) . '" title="' . specialchars(sprintf($GLOBALS['TL_LANG'][$this->strTable]['pasteafter'][1], $row[$i]['id'])) . '" onclick="Backend.getScrollOffset()">' . $imagePasteAfter . '</a>'; } // Drag handle if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notSortable']) { $return .= ' ' . \Image::getHtml('drag.gif', '', 'class="drag-handle" title="' . sprintf($GLOBALS['TL_LANG'][$this->strTable]['cut'][1], $row[$i]['id']) . '"'); } } } if (is_array($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['child_record_callback'])) { $strClass = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['child_record_callback'][0]; $strMethod = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['child_record_callback'][1]; $this->import($strClass); $return .= '</div>' . $this->{$strClass}->{$strMethod}($row[$i]) . '</div>'; } elseif (is_callable($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['child_record_callback'])) { $return .= '</div>' . $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['child_record_callback']($row[$i]) . '</div>'; } // Make items sortable if ($blnHasSorting) { $return .= ' </li>'; } } } } // Make items sortable if ($blnHasSorting && !$GLOBALS['TL_DCA'][$this->strTable]['config']['notSortable'] && \Input::get('act') != 'select') { $return .= ' </ul> <script> Backend.makeParentViewSortable("ul_' . CURRENT_ID . '"); </script>'; } $return .= ' </div>'; // Close form if (\Input::get('act') == 'select') { // Submit buttons $arrButtons = array(); if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notDeletable']) { $arrButtons['delete'] = '<input type="submit" name="delete" id="delete" class="tl_submit" accesskey="d" onclick="return confirm(\'' . $GLOBALS['TL_LANG']['MSC']['delAllConfirm'] . '\')" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['deleteSelected']) . '">'; } if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notSortable']) { $arrButtons['cut'] = '<input type="submit" name="cut" id="cut" class="tl_submit" accesskey="x" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['moveSelected']) . '">'; } if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notCopyable']) { $arrButtons['copy'] = '<input type="submit" name="copy" id="copy" class="tl_submit" accesskey="c" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['copySelected']) . '">'; } if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notEditable']) { $arrButtons['override'] = '<input type="submit" name="override" id="override" class="tl_submit" accesskey="v" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['overrideSelected']) . '">'; $arrButtons['edit'] = '<input type="submit" name="edit" id="edit" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['editSelected']) . '">'; } // Call the buttons_callback (see #4691) if (is_array($GLOBALS['TL_DCA'][$this->strTable]['select']['buttons_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['select']['buttons_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $arrButtons = $this->{$callback[0]}->{$callback[1]}($arrButtons, $this); } elseif (is_callable($callback)) { $arrButtons = $callback($arrButtons, $this); } } } $return .= ' <div class="tl_formbody_submit" style="text-align:right"> <div class="tl_submit_container"> ' . implode(' ', $arrButtons) . ' </div> </div> </div> </form>'; } return $return; }
/** * Generate the widget and return it as string * * @return string */ public function generate() { $arrSet = array(); $arrValues = array(); $blnHasOrder = $this->orderField != '' && is_array($this->{$this->orderField}); if (!empty($this->varValue)) { $objFiles = \FilesModel::findMultipleByUuids((array) $this->varValue); $allowedDownload = trimsplit(',', strtolower(\Config::get('allowedDownload'))); if ($objFiles !== null) { while ($objFiles->next()) { // File system and database seem not in sync if (!file_exists(TL_ROOT . '/' . $objFiles->path)) { continue; } $arrSet[$objFiles->id] = $objFiles->uuid; // Show files and folders if (!$this->isGallery && !$this->isDownloads) { if ($objFiles->type == 'folder') { $arrValues[$objFiles->uuid] = \Image::getHtml('folderC.gif') . ' ' . $objFiles->path; } else { $objFile = new \File($objFiles->path, true); $strInfo = $objFiles->path . ' <span class="tl_gray">(' . $this->getReadableSize($objFile->size) . ($objFile->isImage ? ', ' . $objFile->width . 'x' . $objFile->height . ' px' : '') . ')</span>'; if ($objFile->isImage) { $image = 'placeholder.png'; if (($objFile->isSvgImage || $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth')) && $objFile->viewWidth && $objFile->viewHeight) { $image = \Image::get($objFiles->path, 80, 60, 'center_center'); } $arrValues[$objFiles->uuid] = \Image::getHtml($image, '', 'class="gimage" title="' . specialchars($strInfo) . '"'); } else { $arrValues[$objFiles->uuid] = \Image::getHtml($objFile->icon) . ' ' . $strInfo; } } } else { if ($objFiles->type == 'folder') { $objSubfiles = \FilesModel::findByPid($objFiles->uuid); if ($objSubfiles === null) { continue; } while ($objSubfiles->next()) { // Skip subfolders if ($objSubfiles->type == 'folder') { continue; } $objFile = new \File($objSubfiles->path, true); $strInfo = '<span class="dirname">' . dirname($objSubfiles->path) . '/</span>' . $objFile->basename . ' <span class="tl_gray">(' . $this->getReadableSize($objFile->size) . ($objFile->isImage ? ', ' . $objFile->width . 'x' . $objFile->height . ' px' : '') . ')</span>'; if ($this->isGallery) { // Only show images if ($objFile->isImage) { $image = 'placeholder.png'; if (($objFile->isSvgImage || $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth')) && $objFile->viewWidth && $objFile->viewHeight) { $image = \Image::get($objSubfiles->path, 80, 60, 'center_center'); } $arrValues[$objSubfiles->uuid] = \Image::getHtml($image, '', 'class="gimage" title="' . specialchars($strInfo) . '"'); } } else { // Only show allowed download types if (in_array($objFile->extension, $allowedDownload) && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) { $arrValues[$objSubfiles->uuid] = \Image::getHtml($objFile->icon) . ' ' . $strInfo; } } } } else { $objFile = new \File($objFiles->path, true); $strInfo = '<span class="dirname">' . dirname($objFiles->path) . '/</span>' . $objFile->basename . ' <span class="tl_gray">(' . $this->getReadableSize($objFile->size) . ($objFile->isImage ? ', ' . $objFile->width . 'x' . $objFile->height . ' px' : '') . ')</span>'; if ($this->isGallery) { // Only show images if ($objFile->isImage) { $image = 'placeholder.png'; if (($objFile->isSvgImage || $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth')) && $objFile->viewWidth && $objFile->viewHeight) { $image = \Image::get($objFiles->path, 80, 60, 'center_center'); } $arrValues[$objFiles->uuid] = \Image::getHtml($image, '', 'class="gimage" title="' . specialchars($strInfo) . '"'); } } else { // Only show allowed download types if (in_array($objFile->extension, $allowedDownload) && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) { $arrValues[$objFiles->uuid] = \Image::getHtml($objFile->icon) . ' ' . $strInfo; } } } } } } // Apply a custom sort order if ($blnHasOrder) { $arrNew = array(); foreach ((array) $this->{$this->orderField} as $i) { if (isset($arrValues[$i])) { $arrNew[$i] = $arrValues[$i]; unset($arrValues[$i]); } } if (!empty($arrValues)) { foreach ($arrValues as $k => $v) { $arrNew[$k] = $v; } } $arrValues = $arrNew; unset($arrNew); } } // Load the fonts for the drag hint (see #4838) \Config::set('loadGoogleFonts', true); // Convert the binary UUIDs $strSet = implode(',', array_map('StringUtil::binToUuid', $arrSet)); $strOrder = $blnHasOrder ? implode(',', array_map('StringUtil::binToUuid', $this->{$this->orderField})) : ''; $return = '<input type="hidden" name="' . $this->strName . '" id="ctrl_' . $this->strId . '" value="' . $strSet . '">' . ($blnHasOrder ? ' <input type="hidden" name="' . $this->strOrderName . '" id="ctrl_' . $this->strOrderId . '" value="' . $strOrder . '">' : '') . ' <div class="selector_container">' . ($blnHasOrder && count($arrValues) > 1 ? ' <p class="sort_hint">' . $GLOBALS['TL_LANG']['MSC']['dragItemsHint'] . '</p>' : '') . ' <ul id="sort_' . $this->strId . '" class="' . trim(($blnHasOrder ? 'sortable ' : '') . ($this->isGallery ? 'sgallery' : '')) . '">'; foreach ($arrValues as $k => $v) { $return .= '<li data-id="' . \StringUtil::binToUuid($k) . '">' . $v . '</li>'; } $return .= '</ul> <p><a href="contao/file.php?do=' . \Input::get('do') . '&table=' . $this->strTable . '&field=' . $this->strField . '&act=show&id=' . $this->activeRecord->id . '&value=' . implode(',', array_keys($arrSet)) . '&rt=' . REQUEST_TOKEN . '" class="tl_submit" onclick="Backend.getScrollOffset();Backend.openModalSelector({\'width\':768,\'title\':\'' . specialchars(str_replace("'", "\\'", $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['label'][0])) . '\',\'url\':this.href,\'id\':\'' . $this->strId . '\'});return false">' . $GLOBALS['TL_LANG']['MSC']['changeSelection'] . '</a></p>' . ($blnHasOrder ? ' <script>Backend.makeMultiSrcSortable("sort_' . $this->strId . '", "ctrl_' . $this->strOrderId . '")</script>' : '') . ' </div>'; if (!\Environment::get('isAjaxRequest')) { $return = '<div>' . $return . '</div>'; } return $return; }
/** * {@inheritdoc} */ public function generate() { $values = array(); $icons = array(); if (!empty($this->varValue)) { $files = \FilesModel::findMultipleByUuids((array) $this->varValue); $this->renderList($icons, $files, $this->isGallery || $this->isDownloads); $icons = $this->applySorting($icons); // PHP 7 compatibility, see https://github.com/contao/core-bundle/issues/309 if (version_compare(VERSION . '.' . BUILD, '3.5.5', '>=')) { $mapFunc = 'StringUtil::binToUuid'; } else { $mapFunc = 'String::binToUuid'; } foreach ($files as $model) { $values[] = call_user_func($mapFunc, $model->uuid); } } $template = new ContaoBackendViewTemplate($this->subTemplate); $buffer = $template->setTranslator($this->getEnvironment()->getTranslator())->set('name', $this->strName)->set('id', $this->strId)->set('value', implode(',', $values))->set('hasOrder', $this->orderField != '' && is_array($this->orderFieldValue))->set('icons', $icons)->set('isGallery', $this->isGallery)->set('orderId', $this->orderId)->set('link', $this->generateLink($values))->parse(); if (!\Environment::get('isAjaxRequest')) { $buffer = '<div>' . $buffer . '</div>'; } return $buffer; }
/** * Set all user properties from a database record */ protected function setUserFromDb() { $this->intId = $this->id; // Unserialize values foreach ($this->arrData as $k => $v) { if (!is_numeric($v)) { $this->{$k} = deserialize($v); } } $GLOBALS['TL_USERNAME'] = $this->username; $GLOBALS['TL_LANGUAGE'] = str_replace('_', '-', $this->language); \Config::set('showHelp', $this->showHelp); \Config::set('useRTE', $this->useRTE); \Config::set('useCE', $this->useCE); \Config::set('thumbnails', $this->thumbnails); \Config::set('backendTheme', $this->backendTheme); // Inherit permissions $always = array('alexf'); $depends = array('modules', 'themes', 'pagemounts', 'alpty', 'filemounts', 'fop', 'forms', 'formp'); // HOOK: Take custom permissions if (!empty($GLOBALS['TL_PERMISSIONS']) && is_array($GLOBALS['TL_PERMISSIONS'])) { $depends = array_merge($depends, $GLOBALS['TL_PERMISSIONS']); } // Overwrite user permissions if only group permissions shall be inherited if ($this->inherit == 'group') { foreach ($depends as $field) { $this->{$field} = array(); } } // Merge permissions $inherit = in_array($this->inherit, array('group', 'extend')) ? array_merge($always, $depends) : $always; $time = \Date::floorToMinute(); foreach ((array) $this->groups as $id) { $objGroup = $this->Database->prepare("SELECT * FROM tl_user_group WHERE id=? AND disable!='1' AND (start='' OR start<='{$time}') AND (stop='' OR stop>'" . ($time + 60) . "')")->limit(1)->execute($id); if ($objGroup->numRows > 0) { foreach ($inherit as $field) { $value = deserialize($objGroup->{$field}, true); // The new page/file picker can return integers instead of arrays, so use empty() instead of is_array() and deserialize(true) here if (!empty($value)) { $this->{$field} = array_merge(is_array($this->{$field}) ? $this->{$field} : ($this->{$field} != '' ? array($this->{$field}) : array()), $value); $this->{$field} = array_unique($this->{$field}); } } } } // Restore session if (is_array($this->session)) { $this->Session->setData($this->session); } else { $this->session = array(); } // Make sure pagemounts and filemounts are set! if (!is_array($this->pagemounts)) { $this->pagemounts = array(); } else { $this->pagemounts = array_filter($this->pagemounts); } if (!is_array($this->filemounts)) { $this->filemounts = array(); } else { $this->filemounts = array_filter($this->filemounts); } // Store the numeric file mounts $this->arrFilemountIds = $this->filemounts; // Convert the file mounts into paths (backwards compatibility) if (!$this->isAdmin && !empty($this->filemounts)) { $objFiles = \FilesModel::findMultipleByUuids($this->filemounts); if ($objFiles !== null) { $this->filemounts = $objFiles->fetchEach('path'); } } }
/** * Generate an XML files and save them to the root directory * @param array */ protected function generateFiles($arrFeed) { $arrArchives = deserialize($arrFeed['archives']); if (!is_array($arrArchives) || empty($arrArchives)) { return; } $strType = $arrFeed['format'] == 'atom' ? 'generateAtom' : 'generateRss'; $strLink = $arrFeed['feedBase'] ?: \Environment::get('base'); $strFile = $arrFeed['feedName']; $objFeed = new \Feed($strFile); $objFeed->link = $strLink; $objFeed->title = $arrFeed['title']; $objFeed->description = $arrFeed['description']; $objFeed->language = $arrFeed['language']; $objFeed->published = $arrFeed['tstamp']; $arrCategories = deserialize($arrFeed['categories']); // Filter by categories if (is_array($arrCategories) && !empty($arrCategories)) { $GLOBALS['NEWS_FILTER_CATEGORIES'] = true; $GLOBALS['NEWS_FILTER_DEFAULT'] = $arrCategories; } else { $GLOBALS['NEWS_FILTER_CATEGORIES'] = false; } // Get the items if ($arrFeed['maxItems'] > 0) { $objArticle = \NewsModel::findPublishedByPids($arrArchives, null, $arrFeed['maxItems']); } else { $objArticle = \NewsModel::findPublishedByPids($arrArchives); } // Parse the items if ($objArticle !== null) { $arrUrls = array(); while ($objArticle->next()) { $jumpTo = $objArticle->getRelated('pid')->jumpTo; // No jumpTo page set (see #4784) if (!$jumpTo) { continue; } // Get the jumpTo URL if (!isset($arrUrls[$jumpTo])) { $objParent = \PageModel::findWithDetails($jumpTo); // A jumpTo page is set but does no longer exist (see #5781) if ($objParent === null) { $arrUrls[$jumpTo] = false; } else { $arrUrls[$jumpTo] = $this->generateFrontendUrl($objParent->row(), $GLOBALS['TL_CONFIG']['useAutoItem'] && !$GLOBALS['TL_CONFIG']['disableAlias'] ? '/%s' : '/items/%s', $objParent->language); } } // Skip the event if it requires a jumpTo URL but there is none if ($arrUrls[$jumpTo] === false && $objArticle->source == 'default') { continue; } // Get the categories if ($arrFeed['categories_show']) { $arrCategories = array(); if (($objCategories = NewsCategoryModel::findPublishedByIds(deserialize($objArticle->categories, true))) !== null) { $arrCategories = $objCategories->fetchEach('title'); } } $strUrl = $arrUrls[$jumpTo]; $objItem = new \FeedItem(); // Add the categories to the title if ($arrFeed['categories_show'] == 'title') { $objItem->title = sprintf('[%s] %s', implode(', ', $arrCategories), $objArticle->headline); } else { $objItem->title = $objArticle->headline; } $objItem->link = $this->getLink($objArticle, $strUrl, $strLink); $objItem->published = $objArticle->date; $objItem->author = $objArticle->authorName; // Prepare the description if ($arrFeed['source'] == 'source_text') { $strDescription = ''; $objElement = \ContentModel::findPublishedByPidAndTable($objArticle->id, 'tl_news'); if ($objElement !== null) { while ($objElement->next()) { $strDescription .= $this->getContentElement($objElement->id); } } } else { $strDescription = $objArticle->teaser; } // Add the categories to the description if ($arrFeed['categories_show'] == 'text_before' || $arrFeed['categories_show'] == 'text_after') { $strCategories = '<p>' . $GLOBALS['TL_LANG']['MSC']['newsCategories'] . ' ' . implode(', ', $arrCategories) . '</p>'; if ($arrFeed['categories_show'] == 'text_before') { $strDescription = $strCategories . $strDescription; } else { $strDescription .= $strCategories; } } $strDescription = $this->replaceInsertTags($strDescription, false); $objItem->description = $this->convertRelativeUrls($strDescription, $strLink); // Add the article image as enclosure if ($objArticle->addImage) { $objFile = \FilesModel::findByUuid($objArticle->singleSRC); if ($objFile !== null) { $objItem->addEnclosure($objFile->path); } } // Enclosures if ($objArticle->addEnclosure) { $arrEnclosure = deserialize($objArticle->enclosure, true); if (is_array($arrEnclosure)) { $objFile = \FilesModel::findMultipleByUuids($arrEnclosure); if ($objFile !== null) { while ($objFile->next()) { $objItem->addEnclosure($objFile->path); } } } } $objFeed->addItem($objItem); } } // Create the file \File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}(), false)); }
/** * Parse the model value based on the config. * * @param \Model $model The model. * @param mixed $property The property config. * * @return array|mixed|null */ private function parseModelValue(\Model $model, &$property) { if (is_array($property)) { list($property, $type) = $property; $value = $model->{$property}; switch ($type) { case 'array': case 'object': $value = deserialize($value, true); break; case 'file': $file = \FilesModel::findByUuid($value); $value = $file->path; break; case 'files': $collection = \FilesModel::findMultipleByUuids(deserialize($value, true)); if ($collection) { $value = $collection->fetchEach('path'); } else { $value = array(); } break; default: $value = null; } } else { $value = $model->{$property}; } return $value; }
/** * Generate the widget and return it as string * @param array * @return string */ public function parse($arrAttributes = null) { $arrSet = array(); $arrValues = array(); if (!empty($this->varValue)) { // Can be an array $arrUuids = array(); $arrTemp = array(); $this->varValue = (array) $this->varValue; foreach ($this->varValue as $varFile) { if (\Validator::isBinaryUuid($varFile)) { $arrUuids[] = $varFile; } else { $arrTemp[] = $varFile; } } $objFiles = \FilesModel::findMultipleByUuids($arrUuids); // Get the database files if ($objFiles !== null) { while ($objFiles->next()) { $chunk = $this->generateFileItem($objFiles->path); if (strlen($chunk)) { $arrValues[$objFiles->uuid] = array('id' => in_array($objFiles->uuid, $arrTemp) ? $objFiles->uuid : \StringUtil::binToUuid($objFiles->uuid), 'value' => $chunk); $arrSet[] = $objFiles->uuid; } } } // Get the temporary files foreach ($arrTemp as $varFile) { $chunk = $this->generateFileItem($varFile); if (strlen($chunk)) { $arrValues[$varFile] = array('id' => in_array($varFile, $arrTemp) ? $varFile : \StringUtil::binToUuid($varFile), 'value' => $chunk); $arrSet[] = $varFile; } } } // Load the fonts for the drag hint (see #4838) $GLOBALS['TL_CONFIG']['loadGoogleFonts'] = true; // Parse the set array foreach ($arrSet as $k => $v) { if (in_array($v, $arrTemp)) { $strSet[$k] = $v; } else { $arrSet[$k] = \StringUtil::binToUuid($v); } } $this->set = implode(',', $arrSet); $this->sortable = count($arrValues) > 1; $this->orderHint = $GLOBALS['TL_LANG']['MSC']['dragItemsHint']; $this->values = $arrValues; $this->ajax = \Environment::get('isAjaxRequest') && \Input::post('action') !== 'toggleSubpalette'; $this->deleteTitle = specialchars($GLOBALS['TL_LANG']['MSC']['delete']); $this->extensions = json_encode(trimsplit(',', $this->arrConfiguration['extensions'])); $this->limit = $this->arrConfiguration['uploaderLimit'] ? $this->arrConfiguration['uploaderLimit'] : 0; $this->minSizeLimit = $this->arrConfiguration['minlength'] ? $this->arrConfiguration['minlength'] : 0; $this->sizeLimit = $this->arrConfiguration['maxlength'] ? $this->arrConfiguration['maxlength'] : 0; $this->chunkSize = $this->arrConfiguration['chunkSize'] ? $this->arrConfiguration['chunkSize'] : 0; $this->concurrent = $this->arrConfiguration['concurrent'] ? true : false; $this->maxConnections = $this->arrConfiguration['maxConnections'] ? $this->arrConfiguration['maxConnections'] : 3; return parent::parse($arrAttributes); }
/** * Add a data row to the XML document * @param \DOMDocument $xml * @param \DOMNode|\DOMElement $table * @param array $arrRow * @param array $arrOrder */ protected function addDataRow(\DOMDocument $xml, \DOMElement $table, array $arrRow, array $arrOrder = array()) { $t = $table->getAttribute('name'); $row = $xml->createElement('row'); $row = $table->appendChild($row); foreach ($arrRow as $k => $v) { $field = $xml->createElement('field'); $field->setAttribute('name', $k); $field = $row->appendChild($field); if ($v === null) { $v = 'NULL'; } elseif ($GLOBALS['TL_DCA'][$t]['fields'][$k]['inputType'] == 'fileTree' && !$GLOBALS['TL_DCA'][$t]['fields'][$k]['eval']['multiple']) { $objFile = \FilesModel::findByUuid($v); if ($objFile !== null) { $v = $this->standardizeUploadPath($objFile->path); } else { $v = 'NULL'; } } elseif ($GLOBALS['TL_DCA'][$t]['fields'][$k]['inputType'] == 'fileTree' || in_array($k, $arrOrder)) { $arrFiles = deserialize($v); if (!empty($arrFiles) && is_array($arrFiles)) { $objFiles = \FilesModel::findMultipleByUuids($arrFiles); if ($objFiles !== null) { $arrTmp = array(); while ($objFiles->next()) { $arrTmp[] = $this->standardizeUploadPath($objFiles->path); } $v = serialize($arrTmp); } else { $v = 'NULL'; } } } elseif ($t == 'tl_style' && ($k == 'bgimage' || $k == 'liststyleimage')) { $v = $this->standardizeUploadPath($v); } $value = $xml->createTextNode($v); $field->appendChild($value); } }
/** * Create all header scripts * * @param \PageModel $objPage * @param \LayoutModel $objLayout */ protected function createHeaderScripts($objPage, $objLayout) { $strStyleSheets = ''; $strCcStyleSheets = ''; $arrStyleSheets = deserialize($objLayout->stylesheet); $blnXhtml = $objPage->outputFormat == 'xhtml'; $arrFramework = deserialize($objLayout->framework); // Google web fonts if ($objLayout->webfonts != '') { $strStyleSheets .= \Template::generateStyleTag('//fonts.googleapis.com/css?family=' . str_replace('|', '%7C', $objLayout->webfonts), 'all', $blnXhtml) . "\n"; } // Add the Contao CSS framework style sheets if (is_array($arrFramework)) { foreach ($arrFramework as $strFile) { if ($strFile != 'tinymce.css') { $GLOBALS['TL_FRAMEWORK_CSS'][] = 'assets/contao/css/' . $strFile; } } } // Add the TinyMCE style sheet if (is_array($arrFramework) && in_array('tinymce.css', $arrFramework) && file_exists(TL_ROOT . '/' . \Config::get('uploadPath') . '/tinymce.css')) { $GLOBALS['TL_FRAMEWORK_CSS'][] = \Config::get('uploadPath') . '/tinymce.css'; } // Make sure TL_USER_CSS is set if (!is_array($GLOBALS['TL_USER_CSS'])) { $GLOBALS['TL_USER_CSS'] = array(); } // User style sheets if (is_array($arrStyleSheets) && strlen($arrStyleSheets[0])) { $objStylesheets = \StyleSheetModel::findByIds($arrStyleSheets); if ($objStylesheets !== null) { while ($objStylesheets->next()) { $media = implode(',', deserialize($objStylesheets->media)); // Overwrite the media type with a custom media query if ($objStylesheets->mediaQuery != '') { $media = $objStylesheets->mediaQuery; } // Style sheets with a CC or a combination of font-face and media-type != all cannot be aggregated (see #5216) if ($objStylesheets->cc || $objStylesheets->hasFontFace && $media != 'all') { $strStyleSheet = ''; // External style sheet if ($objStylesheets->type == 'external') { $objFile = \FilesModel::findByPk($objStylesheets->singleSRC); if ($objFile !== null) { $strStyleSheet = \Template::generateStyleTag(TL_ASSETS_URL . $objFile->path, $media, $blnXhtml); } } else { $strStyleSheet = \Template::generateStyleTag(TL_ASSETS_URL . 'assets/css/' . $objStylesheets->name . '.css', $media, $blnXhtml); } if ($objStylesheets->cc) { $strStyleSheet = '<!--[' . $objStylesheets->cc . ']>' . $strStyleSheet . '<![endif]-->'; } $strCcStyleSheets .= $strStyleSheet . "\n"; } else { // External style sheet if ($objStylesheets->type == 'external') { $objFile = \FilesModel::findByPk($objStylesheets->singleSRC); if ($objFile !== null) { $GLOBALS['TL_USER_CSS'][] = $objFile->path . '|' . $media . '|static|' . filemtime(TL_ROOT . '/' . $objFile->path); } } else { $GLOBALS['TL_USER_CSS'][] = 'assets/css/' . $objStylesheets->name . '.css|' . $media . '|static|' . max($objStylesheets->tstamp, $objStylesheets->tstamp2, $objStylesheets->tstamp3); } } } } } $arrExternal = deserialize($objLayout->external); // External style sheets if (!empty($arrExternal) && is_array($arrExternal)) { // Consider the sorting order (see #5038) if ($objLayout->orderExt != '') { $tmp = deserialize($objLayout->orderExt); if (!empty($tmp) && is_array($tmp)) { // Remove all values $arrOrder = array_map(function () { }, array_flip($tmp)); // Move the matching elements to their position in $arrOrder foreach ($arrExternal as $k => $v) { if (array_key_exists($v, $arrOrder)) { $arrOrder[$v] = $v; unset($arrExternal[$k]); } } // Append the left-over style sheets at the end if (!empty($arrExternal)) { $arrOrder = array_merge($arrOrder, array_values($arrExternal)); } // Remove empty (unreplaced) entries $arrExternal = array_values(array_filter($arrOrder)); unset($arrOrder); } } // Get the file entries from the database $objFiles = \FilesModel::findMultipleByUuids($arrExternal); if ($objFiles !== null) { $arrFiles = array(); while ($objFiles->next()) { if (file_exists(TL_ROOT . '/' . $objFiles->path)) { $arrFiles[] = $objFiles->path . '|static'; } } // Inject the external style sheets before or after the internal ones (see #6937) if ($objLayout->loadingOrder == 'external_first') { array_splice($GLOBALS['TL_USER_CSS'], 0, 0, $arrFiles); } else { array_splice($GLOBALS['TL_USER_CSS'], count($GLOBALS['TL_USER_CSS']), 0, $arrFiles); } } } // Add a placeholder for dynamic style sheets (see #4203) $strStyleSheets .= '[[TL_CSS]]'; // Add the debug style sheet if (\Config::get('debugMode')) { $strStyleSheets .= \Template::generateStyleTag($this->addStaticUrlTo('assets/contao/css/debug.css'), 'all', $blnXhtml) . "\n"; } // Always add conditional style sheets at the end $strStyleSheets .= $strCcStyleSheets; $newsfeeds = deserialize($objLayout->newsfeeds); $calendarfeeds = deserialize($objLayout->calendarfeeds); // Add newsfeeds if (!empty($newsfeeds) && is_array($newsfeeds)) { $objFeeds = \NewsFeedModel::findByIds($newsfeeds); if ($objFeeds !== null) { while ($objFeeds->next()) { $strStyleSheets .= \Template::generateFeedTag(($objFeeds->feedBase ?: \Environment::get('base')) . 'share/' . $objFeeds->alias . '.xml', $objFeeds->format, $objFeeds->title, $blnXhtml) . "\n"; } } } // Add calendarfeeds if (!empty($calendarfeeds) && is_array($calendarfeeds)) { $objFeeds = \CalendarFeedModel::findByIds($calendarfeeds); if ($objFeeds !== null) { while ($objFeeds->next()) { $strStyleSheets .= \Template::generateFeedTag(($objFeeds->feedBase ?: \Environment::get('base')) . 'share/' . $objFeeds->alias . '.xml', $objFeeds->format, $objFeeds->title, $blnXhtml) . "\n"; } } } // Add a placeholder for dynamic <head> tags (see #4203) $strHeadTags = '[[TL_HEAD]]'; // Add the user <head> tags if (($strHead = trim($objLayout->head)) != false) { $strHeadTags .= $strHead . "\n"; } $this->Template->stylesheets = $strStyleSheets; $this->Template->head = $strHeadTags; }
/** * Collect the images from content element * @param object * @param string */ public function collectContentElementImages($objModel, $strBuffer) { if (!is_array($GLOBALS['SOCIAL_IMAGES']) || !in_array($objModel->type, $GLOBALS['SOCIAL_IMAGES_CE'])) { return $strBuffer; } switch ($objModel->type) { case 'text': if ($objModel->addImage) { $objFile = \FilesModel::findByPk($objModel->singleSRC); if ($objFile !== null && is_file(TL_ROOT . '/' . $objFile->path)) { $GLOBALS['SOCIAL_IMAGES'][] = $objFile->path; } } break; case 'image': $objFile = \FilesModel::findByPk($objModel->singleSRC); if ($objFile !== null && is_file(TL_ROOT . '/' . $objFile->path)) { $GLOBALS['SOCIAL_IMAGES'][] = $objFile->path; } break; case 'gallery': $objFiles = \FilesModel::findMultipleByUuids(deserialize($objModel->multiSRC)); if ($objFiles !== null) { $images = array(); $auxDate = array(); // Get all images while ($objFiles->next()) { // Continue if the files has been processed or does not exist if (isset($images[$objFiles->path]) || !file_exists(TL_ROOT . '/' . $objFiles->path)) { continue; } // Single files if ($objFiles->type == 'file') { $objFile = new \File($objFiles->path, true); if (!$objFile->isGdImage) { continue; } $images[$objFiles->path] = array('path' => $objFiles->path, 'uuid' => $objFiles->uuid); $auxDate[] = $objFile->mtime; } else { $objSubfiles = \FilesModel::findByPid($objFiles->uuid); if ($objSubfiles === null) { continue; } while ($objSubfiles->next()) { // Skip subfolders if ($objSubfiles->type == 'folder') { continue; } $objFile = new \File($objSubfiles->path, true); if (!$objFile->isGdImage) { continue; } $images[$objSubfiles->path] = array('path' => $objSubfiles->path, 'uuid' => $objSubfiles->uuid); $auxDate[] = $objFile->mtime; } } } // Sort array switch ($objModel->sortBy) { default: case 'name_asc': uksort($images, 'basename_natcasecmp'); break; case 'name_desc': uksort($images, 'basename_natcasercmp'); break; case 'date_asc': array_multisort($images, SORT_NUMERIC, $auxDate, SORT_ASC); break; case 'date_desc': array_multisort($images, SORT_NUMERIC, $auxDate, SORT_DESC); break; case 'meta': // Backwards compatibility // Backwards compatibility case 'custom': if ($objModel->orderSRC != '') { $tmp = deserialize($objModel->orderSRC); if (!empty($tmp) && is_array($tmp)) { // Remove all values $arrOrder = array_map(function () { }, array_flip($tmp)); // Move the matching elements to their position in $arrOrder foreach ($images as $k => $v) { if (array_key_exists($v['uuid'], $arrOrder)) { $arrOrder[$v['uuid']] = $v; unset($images[$k]); } } // Append the left-over images at the end if (!empty($images)) { $arrOrder = array_merge($arrOrder, array_values($images)); } // Remove empty (unreplaced) entries $images = array_values(array_filter($arrOrder)); unset($arrOrder); } } break; case 'random': shuffle($images); break; } $images = array_values($images); // Limit the total number of items (see #2652) if ($objModel->numberOfItems > 0) { $images = array_slice($images, 0, $objModel->numberOfItems); } $offset = 0; $total = count($images); $limit = $total; // Pagination if ($objModel->perPage > 0) { // Get the current page $id = 'page_g' . $objModel->id; $page = \Input::get($id) ?: 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $objModel->perPage), 1)) { global $objPage; $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); return $strBuffer; } // Set limit and offset $offset = ($page - 1) * $objModel->perPage; $limit = min($this->perPage + $offset, $total); } // Limit the images if ($offset > 0) { $images = array_slice($images, $offset, $limit); } foreach ($images as $image) { $GLOBALS['SOCIAL_IMAGES'][] = $image['path']; } } break; case 'player': case 'youtube': $objFile = \FilesModel::findByPk($objModel->posterSRC); if ($objFile !== null && is_file(TL_ROOT . '/' . $objFile->path)) { $GLOBALS['SOCIAL_IMAGES'][] = $objFile->path; } break; } return $strBuffer; }
/** * Add a data row to the XML document * @param \DOMDocument * @param \DOMElement * @param \Database\Result * @param array */ protected function addDataRow(\DOMDocument $xml, \DOMElement $table, \Database\Result $objData, array $arrOrder = array()) { $t = $table->getAttribute('name'); $row = $xml->createElement('row'); $row = $table->appendChild($row); foreach ($objData->row() as $k => $v) { $field = $xml->createElement('field'); $field->setAttribute('name', $k); $field = $row->appendChild($field); if ($v === null) { $v = 'NULL'; } elseif ($GLOBALS['TL_DCA'][$t]['fields'][$k]['inputType'] == 'fileTree' && !$GLOBALS['TL_DCA'][$t]['fields'][$k]['eval']['multiple']) { $objFile = \FilesModel::findByUuid($v); if ($objFile !== null) { // Standardize the upload path if it is not "files" if (\Config::get('uploadPath') != 'files') { $v = 'files/' . preg_replace('@^' . preg_quote(\Config::get('uploadPath'), '@') . '/@', '', $objFile->path); } else { $v = $objFile->path; } } else { $v = 'NULL'; } } elseif ($GLOBALS['TL_DCA'][$t]['fields'][$k]['inputType'] == 'fileTree' || in_array($k, $arrOrder)) { $arrFiles = deserialize($v); if (!empty($arrFiles) && is_array($arrFiles)) { $objFiles = \FilesModel::findMultipleByUuids($arrFiles); if ($objFiles !== null) { // Standardize the upload path if it is not "files" if (\Config::get('uploadPath') != 'files') { $arrTmp = array(); while ($objFiles->next()) { $arrTmp[] = 'files/' . preg_replace('@^' . preg_quote(\Config::get('uploadPath'), '@') . '/@', '', $objFiles->path); } $v = serialize($arrTmp); } else { $v = serialize($objFiles->fetchEach('path')); } } else { $v = 'NULL'; } } } $value = $xml->createTextNode($v); $field->appendChild($value); } }
public function showAll() { $return = ''; $query = 'SELECT * FROM tl_theme ORDER BY name '; $objRowStmt = $this->Database->prepare($query); $objRow = $objRowStmt->execute(); $themeList = array(); $result = $objRow->fetchAllAssoc(); $this->import('FilesModel'); foreach ($result as $row) { $files = array(); if (version_compare(VERSION, '3.2', '<')) { $folders = \FilesModel::findMultipleByIds(deserialize($row['folders'])); } else { $folders = \FilesModel::findMultipleByUuids(deserialize($row['folders'])); } if ($folders !== null) { foreach ($folders->fetchEach('path') as $folder) { $filesResult = \FilesModel::findBy(array($this->FilesModel->getTable() . '.path LIKE ? AND extension = \'base\''), $folder . '/%'); if ($filesResult === null) { continue; } foreach ($filesResult->fetchEach('path') as $file) { if (!file_exists(TL_ROOT . '/' . substr($file, 0, -5))) { continue; } $extension = explode('.', $file); $extension = $extension[count($extension) - 2]; $files[] = array('id' => $file, 'type' => $extension === 'html5' ? 'html' : $extension, 'name' => substr($file, strlen($folder) + 1, -5)); } } } $templateFiles = scandir(TL_ROOT . '/' . $row['templates']); foreach ($templateFiles as $file) { if (substr($file, -5) === '.base' && file_exists(TL_ROOT . '/' . $row['templates'] . '/' . substr($file, 0, -5))) { $extension = explode('.', $file); $extension = $extension[count($extension) - 2]; $files[] = array('id' => $row['templates'] . '/' . $file, 'type' => $extension === 'html5' ? 'html' : $extension, 'name' => substr($file, 0, -5)); } } if (version_compare(VERSION, '3.2', '<')) { $screenshot = \FilesModel::findByPk($row['screenshot']); } else { $screenshot = \FilesModel::findByUuid($row['screenshot']); } if ($screenshot) { $screenshot = TL_FILES_URL . \Image::get($screenshot->path, 40, 30, 'center_top'); } if (count($files)) { $themeList[] = array('name' => $row['name'], 'files' => $files, 'screenshot' => $screenshot); } } if (!count($themeList)) { return '<p class="tl_empty">' . $GLOBALS['TL_LANG']['MSC']['noResult'] . '</p>'; } $return .= '<div id="tl_buttons">' . $this->generateGlobalButtons() . '</div>' . \Message::generate(true); $return .= '<div class="tl_listing_container list_view">'; $return .= '<table class="tl_listing' . ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['showColumns'] ? ' showColumns' : '') . '">'; foreach ($themeList as $key => $theme) { if ($key) { $return .= '<tr style="height: 30px;"><td colspan="2"> </td></tr>'; } $return .= '<tr><td colspan="2" class="tl_folder_tlist">'; if ($theme['screenshot']) { $return .= '<img src="' . $theme['screenshot'] . '" alt="" class="theme_preview"> '; } $return .= $theme['name'] . '</td></tr>'; $eoCount = -1; foreach ($theme['files'] as $file) { $return .= '<tr class="' . (++$eoCount % 2 == 0 ? 'even' : 'odd') . '" onmouseover="Theme.hoverRow(this,1)" onmouseout="Theme.hoverRow(this,0)">'; $return .= '<td class="tl_file_list">' . $GLOBALS['TL_LANG']['rocksolid_theme_assistant']['file_types'][$file['type']] . ' (' . $file['name'] . ')</td>'; $return .= '<td class="tl_file_list tl_right_nowrap">' . $this->generateButtons($file, $this->strTable) . '</td>'; $return .= '</tr>'; } } $return .= '</table>'; $return .= '</div>'; return $return; }
public static function observeCssGroupFolder($groupId) { $objCss = ExtCssModel::findByPk($groupId); if ($objCss === null || $objCss->observeFolderSRC == '') { return false; } $objObserveModel = \FilesModel::findByUuid($objCss->observeFolderSRC); if ($objObserveModel === null || !is_dir(TL_ROOT . '/' . $objObserveModel->path)) { return false; } $lastUpdate = filemtime(TL_ROOT . '/' . $objObserveModel->path); // check if folder content has updated if ($lastUpdate <= $objObserveModel->tstamp) { return false; } $objCssFiles = ExtCssFileModel::findMultipleByPids(array($groupId)); $arrOldFileNames = array(); if ($objCssFiles !== null) { $objCssFilesModel = \FilesModel::findMultipleByUuids($objCssFiles->fetchEach('src')); if ($objCssFilesModel !== null) { $arrOldFileNames = $objCssFilesModel->fetchEach('path'); } } $arrFileNames = static::scanLessFiles($objObserveModel->path); $arrDiff = array_diff($arrFileNames, $arrOldFileNames); // exclude bootstrap variables src $objVariablesModel = \FilesModel::findMultipleByUuids(deserialize($objCss->variablesOrderSRC, true)); $arrRemove = array(); if ($objVariablesModel !== null) { $arrVariables = $objVariablesModel->fetchEach('path'); // remove variables from oberserve files $arrDiff = array_diff($arrDiff, $arrVariables); // remove variables from oberserve files $arrRemove = array_intersect($arrOldFileNames, $arrVariables); } if (!empty($arrDiff)) { // add new files foreach ($arrDiff as $key => $path) { static::addCssFileToGroup($path, $groupId); } } // cleanup $arrRemove = array_merge($arrRemove, array_diff($arrOldFileNames, $arrFileNames)); if (!empty($arrRemove)) { // add new files foreach ($arrRemove as $key => $path) { // file is not part of the observed folder if (strpos($path, $objObserveModel->path) === FALSE) { continue; } static::removeCssFileFromGroup($path, $groupId); } } return true; }
protected function addCustomFontsToPDF(\TCPDF &$pdf, array $arrFonts) { $objModels = \FilesModel::findMultipleByUuids($arrFonts); if ($objModels === null) { return false; } while ($objModels->next()) { if (!file_exists(TL_ROOT . '/' . $objModels->path)) { continue; } $font = \TCPDF_FONTS::addTTFfont(TL_ROOT . '/' . $objModels->path, 'TrueTypeUnicode', '', 96); $pdf->SetFont($font, '', $this->objModel->share_pdfFontSize ? $this->objModel->share_pdfFontSize : 13, false); } }
/** * Generate the widget and return it as string * @param array * @return string */ public function parse($arrAttributes = null) { if (!$this->blnValuesPrepared) { $arrSet = array(); $arrValues = array(); $arrUuids = array(); $arrTemp = array(); if (!empty($this->varValue)) { // Can be an array $this->varValue = (array) $this->varValue; foreach ($this->varValue as $varFile) { if (\Validator::isUuid($varFile)) { $arrUuids[] = $varFile; } else { $arrTemp[] = $varFile; } } $objFiles = \FilesModel::findMultipleByUuids($arrUuids); // Get the database files if ($objFiles !== null) { while ($objFiles->next()) { $chunk = $this->generateFileItem($objFiles->path); if (strlen($chunk)) { $arrValues[$objFiles->uuid] = array('id' => in_array($objFiles->uuid, $arrTemp) ? $objFiles->uuid : \StringUtil::binToUuid($objFiles->uuid), 'value' => $chunk); $arrSet[] = $objFiles->uuid; } } } // Get the temporary files foreach ($arrTemp as $varFile) { $chunk = $this->generateFileItem($varFile); if (strlen($chunk)) { $arrValues[$varFile] = array('id' => in_array($varFile, $arrTemp) ? $varFile : \StringUtil::binToUuid($varFile), 'value' => $chunk); $arrSet[] = $varFile; } } } // Parse the set array foreach ($arrSet as $k => $v) { if (in_array($v, $arrTemp)) { $strSet[$k] = $v; } else { $arrSet[$k] = \StringUtil::binToUuid($v); } } $this->set = implode(',', $arrSet); $this->values = $arrValues; $this->deleteTitle = specialchars($GLOBALS['TL_LANG']['MSC']['delete']); $this->extensions = json_encode(trimsplit(',', $this->arrConfiguration['extensions'])); $this->limit = $this->arrConfiguration['uploaderLimit'] ? $this->arrConfiguration['uploaderLimit'] : 0; $this->minSizeLimit = $this->arrConfiguration['minlength'] ? $this->arrConfiguration['minlength'] : 0; $this->sizeLimit = $this->arrConfiguration['maxlength'] ? $this->arrConfiguration['maxlength'] : 0; $this->chunkSize = $this->arrConfiguration['chunkSize'] ? $this->arrConfiguration['chunkSize'] : 0; $this->concurrent = $this->arrConfiguration['concurrent'] ? true : false; $this->maxConnections = $this->arrConfiguration['maxConnections'] ? $this->arrConfiguration['maxConnections'] : 3; $this->blnValuesPrepared = true; } return parent::parse($arrAttributes); }
/** * {@inheritdoc} */ public function generate() { $values = array(); $icons = array(); if (!empty($this->varValue)) { $files = \FilesModel::findMultipleByUuids((array) $this->varValue); $this->renderList($values, $icons, $files, $this->isGallery || $this->isDownloads); $icons = $this->applySorting($icons); } $template = new ContaoBackendViewTemplate($this->subTemplate); $buffer = $template->setTranslator($this->getEnvironment()->getTranslator())->set('name', $this->strName)->set('id', $this->strId)->set('value', implode(',', array_map('String::binToUuid', $values)))->set('hasOrder', $this->orderField != '' && is_array($this->orderFieldValue))->set('icons', $icons)->set('isGallery', $this->isGallery)->set('orderId', $this->orderId)->set('link', $this->generateLink($values))->parse(); if (!\Environment::get('isAjaxRequest')) { $buffer = '<div>' . $buffer . '</div>'; } return $buffer; }
/** * 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 . ' <%s>' : '%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 an XML files and save them to the root directory * * @param array $arrFeed */ protected function generateFiles($arrFeed) { $arrArchives = deserialize($arrFeed['archives']); if (!is_array($arrArchives) || empty($arrArchives)) { return; } $strType = $arrFeed['format'] == 'atom' ? 'generateAtom' : 'generateRss'; $strLink = $arrFeed['feedBase'] ?: \Environment::get('base'); $strFile = $arrFeed['feedName']; $objFeed = new \Feed($strFile); $objFeed->link = $strLink; $objFeed->title = $arrFeed['title']; $objFeed->description = $arrFeed['description']; $objFeed->language = $arrFeed['language']; $objFeed->published = $arrFeed['tstamp']; // Get the items if ($arrFeed['maxItems'] > 0) { $objArticle = \NewsModel::findPublishedByPids($arrArchives, null, $arrFeed['maxItems']); } else { $objArticle = \NewsModel::findPublishedByPids($arrArchives); } // Parse the items if ($objArticle !== null) { $arrUrls = array(); while ($objArticle->next()) { /** @var \PageModel $objPage */ $objPage = $objArticle->getRelated('pid'); $jumpTo = $objPage->jumpTo; // No jumpTo page set (see #4784) if (!$jumpTo) { continue; } // Get the jumpTo URL if (!isset($arrUrls[$jumpTo])) { $objParent = \PageModel::findWithDetails($jumpTo); // A jumpTo page is set but does no longer exist (see #5781) if ($objParent === null) { $arrUrls[$jumpTo] = false; } else { $arrUrls[$jumpTo] = $objParent->getFrontendUrl(\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/items/%s'); } } // Skip the event if it requires a jumpTo URL but there is none if ($arrUrls[$jumpTo] === false && $objArticle->source == 'default') { continue; } $strUrl = $arrUrls[$jumpTo]; $objItem = new \FeedItem(); $objItem->title = $objArticle->headline; $objItem->link = $this->getLink($objArticle, $strUrl, $strLink); $objItem->published = $objArticle->date; $objItem->author = $objArticle->authorName; // Prepare the description if ($arrFeed['source'] == 'source_text') { $strDescription = ''; $objElement = \ContentModel::findPublishedByPidAndTable($objArticle->id, 'tl_news'); if ($objElement !== null) { // Overwrite the request (see #7756) $strRequest = \Environment::get('request'); \Environment::set('request', $objItem->link); while ($objElement->next()) { $strDescription .= $this->getContentElement($objElement->current()); } \Environment::set('request', $strRequest); } } else { $strDescription = $objArticle->teaser; } $strDescription = $this->replaceInsertTags($strDescription, false); $objItem->description = $this->convertRelativeUrls($strDescription, $strLink); // Add the article image as enclosure if ($objArticle->addImage) { $objFile = \FilesModel::findByUuid($objArticle->singleSRC); if ($objFile !== null) { $objItem->addEnclosure($objFile->path, $strLink); } } // Enclosures if ($objArticle->addEnclosure) { $arrEnclosure = deserialize($objArticle->enclosure, true); if (is_array($arrEnclosure)) { $objFile = \FilesModel::findMultipleByUuids($arrEnclosure); if ($objFile !== null) { while ($objFile->next()) { $objItem->addEnclosure($objFile->path, $strLink); } } } } $objFeed->addItem($objItem); } } // Create the file \File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}(), false)); }
/** * Renturn a form to choose an existing style sheet and import it * * @param \DataContainer $dc * * @return string */ public function send(\DataContainer $dc) { $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($dc->id); // Return if there is no newsletter if ($objNewsletter->numRows < 1) { return ''; } // Overwrite the SMTP configuration if ($objNewsletter->useSMTP) { \Config::set('useSMTP', true); \Config::set('smtpHost', $objNewsletter->smtpHost); \Config::set('smtpUser', $objNewsletter->smtpUser); \Config::set('smtpPass', $objNewsletter->smtpPass); \Config::set('smtpEnc', $objNewsletter->smtpEnc); \Config::set('smtpPort', $objNewsletter->smtpPort); } // Add default sender address if ($objNewsletter->sender == '') { list($objNewsletter->senderName, $objNewsletter->sender) = \String::splitFriendlyEmail(\Config::get('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; } } } } } // Replace insert tags $html = $this->replaceInsertTags($objNewsletter->content, false); $text = $this->replaceInsertTags($objNewsletter->text, false); // Convert relative URLs if ($objNewsletter->externalImages) { $html = $this->convertRelativeUrls($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); } $arrRecipient['email'] = urldecode(\Input::get('recipient', true)); // Send $objEmail = $this->generateEmailObject($objNewsletter, $arrAttachments); $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); $this->sendNewsletter($objEmail, $objNewsletter, $objRecipients->row(), $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); } } \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 . ' <%s>' : '%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']['backBTTitle']) . '" accesskey="b">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a> </div> ' . \Message::generate() . ' <form action="' . TL_SCRIPT . '" 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 ? ' <div class="preview_html"> ' . $html . ' </div>' : '') . ' <div class="preview_text"> <pre style="white-space:pre-wrap">' . $text . '</pre> </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] && \Config::get('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] && \Config::get('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] && \Config::get('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] && \Config::get('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; }