findMultipleByUuids() public static method

Find multiple files by their UUIDs
public static findMultipleByUuids ( array $arrUuids, array $arrOptions = [] ) : Collection | FilesModel[] | FilesModel | null
$arrUuids array An array of UUIDs
$arrOptions array An optional options array
return Contao\Model\Collection | FilesModel[] | FilesModel | null A collection of models or null if there are no files
 private function getContaoFile($uuid)
 {
     $uuid = StringUtil::deserialize($uuid);
     if (is_array($uuid)) {
         return FilesModel::findMultipleByUuids($uuid);
     }
     return FilesModel::findByUuid($uuid);
 }
 public function moveFiles(\DataContainer $dc)
 {
     $arrPost = Request::getPost();
     foreach ($arrPost as $key => $value) {
         $arrData = $GLOBALS['TL_DCA'][$dc->table]['fields'][$key];
         if ($arrData['inputType'] != MultiFileUpload::NAME) {
             continue;
         }
         $arrFiles = deserialize($dc->activeRecord->{$key});
         $strUploadFolder = Files::getFolderFromDca($arrData['eval']['uploadFolder'], $dc);
         if ($strUploadFolder === null) {
             throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['uploadNoUploadFolderDeclared'], $key, MultiFileUpload::UPLOAD_TMP));
         }
         if (!is_array($arrFiles)) {
             $arrFiles = array($arrFiles);
         }
         $objFileModels = FilesModel::findMultipleByUuids($arrFiles);
         if ($objFileModels === null) {
             continue;
         }
         $arrPaths = $objFileModels->fetchEach('path');
         $arrTargets = array();
         // do not loop over $objFileModels as $objFile->close() will pull models away
         foreach ($arrPaths as $strPath) {
             $objFile = new \File($strPath);
             $strName = $objFile->name;
             $strTarget = $strUploadFolder . '/' . $strName;
             // upload_path_callback
             if (is_array($arrData['upload_path_callback'])) {
                 foreach ($arrData['upload_path_callback'] as $callback) {
                     $strTarget = \System::importStatic($callback[0])->{$callback[1]}($strTarget, $objFile, $dc) ?: $strTarget;
                 }
             }
             if (StringUtil::startsWith($objFile->path, ltrim($strTarget, '/'))) {
                 continue;
             }
             if ($objFile->renameTo($strTarget)) {
                 $arrTargets[] = $strTarget;
                 $objFile->close();
                 continue;
             }
             $arrTargets[] = $strPath;
         }
         // HOOK: post upload callback
         if (isset($GLOBALS['TL_HOOKS']['postUpload']) && is_array($GLOBALS['TL_HOOKS']['postUpload'])) {
             foreach ($GLOBALS['TL_HOOKS']['postUpload'] as $callback) {
                 if (is_array($callback)) {
                     \System::importStatic($callback[0])->{$callback[1]}($arrTargets);
                 } elseif (is_callable($callback)) {
                     $callback($arrTargets);
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 /**
  * 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 = \StringUtil::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) {
         return '';
     }
     return parent::generate();
 }
Exemplo n.º 4
0
    /**
     * Show header of the parent table and list all records of the current table
     *
     * @return string
     */
    protected function parentView()
    {
        /** @var SessionInterface $objSession */
        $objSession = \System::getContainer()->get('session');
        $blnClipboard = false;
        $arrClipboard = $objSession->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') ? '&nbsp;' : ($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&amp;mode=create' : 'act=create&amp;mode=2&amp;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 hover-div">';
        // 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'] . '&amp;mode=2&amp;pid=' . $objParent->id . (!$blnMultiboard ? '&amp;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 != '' ? '&amp;table=' . $this->ptable : '', $this->addToUrl('act=edit')) . '" class="edit" title="' . specialchars(isset($GLOBALS['TL_LANG'][$this->ptable]['editmeta'][1]) ? $GLOBALS['TL_LANG'][$this->ptable]['editmeta'][1] : $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&amp;mode=2&amp;pid=' . $objParent->id . '&amp;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=?";
                        $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
            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 hover-div">
<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&amp;mode=1&amp;pid=' . $row[$i]['id'] . '&amp;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'] . '&amp;mode=1&amp;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'] . '&amp;mode=1&amp;pid=' . $row[$i]['id'] . '&amp;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'] = '<button type="submit" name="delete" id="delete" class="tl_submit" accesskey="d" onclick="return confirm(\'' . $GLOBALS['TL_LANG']['MSC']['delAllConfirm'] . '\')">' . $GLOBALS['TL_LANG']['MSC']['deleteSelected'] . '</button>';
            }
            if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notSortable']) {
                $arrButtons['cut'] = '<button type="submit" name="cut" id="cut" class="tl_submit" accesskey="x">' . $GLOBALS['TL_LANG']['MSC']['moveSelected'] . '</button>';
            }
            if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notCopyable']) {
                $arrButtons['copy'] = '<button type="submit" name="copy" id="copy" class="tl_submit" accesskey="c">' . $GLOBALS['TL_LANG']['MSC']['copySelected'] . '</button>';
            }
            if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notEditable']) {
                $arrButtons['override'] = '<button type="submit" name="override" id="override" class="tl_submit" accesskey="v">' . $GLOBALS['TL_LANG']['MSC']['overrideSelected'] . '</button>';
                $arrButtons['edit'] = '<button type="submit" name="edit" id="edit" class="tl_submit" accesskey="s">' . $GLOBALS['TL_LANG']['MSC']['editSelected'] . '</button>';
            }
            // 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;
    }
Exemplo n.º 5
0
 /**
  * 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;
     \System::getContainer()->get('request_stack')->getCurrentRequest()->setLocale($this->language);
     \System::getContainer()->get('translator')->setLocale($this->language);
     // Deprecated since Contao 4.0, to be removed in Contao 5.0
     $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', 'imageSizes');
     // 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});
                 }
             }
         }
     }
     // 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
     if (!$this->isAdmin && !empty($this->filemounts)) {
         $objFiles = \FilesModel::findMultipleByUuids($this->filemounts);
         if ($objFiles !== null) {
             $this->filemounts = $objFiles->fetchEach('path');
         }
     }
 }
Exemplo n.º 6
0
    /**
     * 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.template AS channelTemplate, c.sender AS channelSender, c.senderName as channelSenderName 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 '';
        }
        // Set the template
        if ($objNewsletter->template == '') {
            $objNewsletter->template = $objNewsletter->channelTemplate;
        }
        // Set the sender address
        if ($objNewsletter->sender == '') {
            $objNewsletter->sender = $objNewsletter->channelSender;
        }
        // Set the sender name
        if ($objNewsletter->senderName == '') {
            $objNewsletter->senderName = $objNewsletter->channelSenderName;
        }
        // No sender address given
        if ($objNewsletter->sender == '') {
            throw new InternalServerErrorException('No sender address given. Please check the newsletter channel settings.');
        }
        $arrAttachments = array();
        // Add attachments
        if ($objNewsletter->addFile) {
            $files = deserialize($objNewsletter->files);
            if (!empty($files) && is_array($files)) {
                $objFiles = \FilesModel::findMultipleByUuids($files);
                if ($objFiles !== null) {
                    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);
        }
        /** @var SessionInterface $objSession */
        $objSession = \System::getContainer()->get('session');
        // Send newsletter
        if (\Input::get('token') != '' && \Input::get('token') == $objSession->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) {
                $objSession->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) {
                $objSession->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));
        $objSession->set('tl_newsletter_send', $strToken);
        $sprintf = $objNewsletter->senderName != '' ? $objNewsletter->senderName . ' &lt;%s&gt;' : '%s';
        $this->import('BackendUser', 'User');
        // Preview newsletter
        $return = '
<div id="tl_buttons">
<a href="' . $this->getReferer(true) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['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>';
        $return .= '

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

</form>';
        unset($_SESSION['TL_PREVIEW_MAIL_ERROR']);
        return $return;
    }
Exemplo n.º 7
0
 /**
  * Create all header scripts
  *
  * @param \PageModel   $objPage
  * @param \LayoutModel $objLayout
  */
 protected function createHeaderScripts($objPage, $objLayout)
 {
     $strStyleSheets = '';
     $strCcStyleSheets = '';
     $arrStyleSheets = deserialize($objLayout->stylesheet);
     $arrFramework = deserialize($objLayout->framework);
     // Google web fonts
     if ($objLayout->webfonts != '') {
         $strStyleSheets .= \Template::generateStyleTag('//fonts.googleapis.com/css?family=' . str_replace('|', '%7C', $objLayout->webfonts), 'all') . "\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/' . basename($strFile, '.css') . '.min.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);
                         }
                     } else {
                         $strStyleSheet = \Template::generateStyleTag(TL_ASSETS_URL . 'assets/css/' . $objStylesheets->name . '.css', $media);
                     }
                     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]]';
     // 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) . "\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) . "\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;
 }
Exemplo n.º 8
0
 /**
  * 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 = \StringUtil::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);
     }
 }
Exemplo n.º 9
0
 /**
  * Add enclosures to a template
  *
  * @param object $objTemplate The template object to add the enclosures to
  * @param array  $arrItem     The element or module as array
  * @param string $strKey      The name of the enclosures field in $arrItem
  */
 public static function addEnclosuresToTemplate($objTemplate, $arrItem, $strKey = 'enclosure')
 {
     $arrEnclosures = deserialize($arrItem[$strKey]);
     if (!is_array($arrEnclosures) || empty($arrEnclosures)) {
         return;
     }
     $objFiles = \FilesModel::findMultipleByUuids($arrEnclosures);
     if ($objFiles === null) {
         return;
     }
     $file = \Input::get('file', true);
     // Send the file to the browser and do not send a 404 header (see #5178)
     if ($file != '') {
         while ($objFiles->next()) {
             if ($file == $objFiles->path) {
                 static::sendFileToBrowser($file);
             }
         }
         $objFiles->reset();
     }
     /** @var \PageModel $objPage */
     global $objPage;
     $arrEnclosures = array();
     $allowedDownload = trimsplit(',', strtolower(\Config::get('allowedDownload')));
     // Add download links
     while ($objFiles->next()) {
         if ($objFiles->type == 'file') {
             if (!in_array($objFiles->extension, $allowedDownload) || !is_file(TL_ROOT . '/' . $objFiles->path)) {
                 continue;
             }
             $objFile = new \File($objFiles->path);
             $strHref = \Environment::get('request');
             // Remove an existing file parameter (see #5683)
             if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
                 $strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
             }
             $strHref .= (strpos($strHref, '?') !== false ? '&amp;' : '?') . 'file=' . \System::urlEncode($objFiles->path);
             $arrMeta = \Frontend::getMetaData($objFiles->meta, $objPage->language);
             if (empty($arrMeta) && $objPage->rootFallbackLanguage !== null) {
                 $arrMeta = \Frontend::getMetaData($objFiles->meta, $objPage->rootFallbackLanguage);
             }
             // Use the file name as title if none is given
             if ($arrMeta['title'] == '') {
                 $arrMeta['title'] = specialchars($objFile->basename);
             }
             $arrEnclosures[] = array('link' => $arrMeta['title'], 'filesize' => static::getReadableSize($objFile->filesize), 'title' => specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['download'], $objFile->basename)), 'href' => $strHref, 'enclosure' => $objFiles->path, 'icon' => TL_ASSETS_URL . 'assets/contao/images/' . $objFile->icon, 'mime' => $objFile->mime, 'extension' => $objFile->extension, 'meta' => $arrMeta);
         }
     }
     $objTemplate->enclosure = $arrEnclosures;
 }