/** * Generate the metamodels renderer button. * * @param array $row Current row. * @param string $href The button href. * @param string $label The button label. * @param string $title The button title. * @param string $icon The button icon. * @param string $attributes Optional attributes. * * @return string */ public function generateRendererButton($row, $href, $label, $title, $icon, $attributes) { if (empty($this->layers[$row['type']]['metamodels'])) { return ''; } return sprintf('<a href="%s" title="%s">%s</a> ', \Backend::addToUrl($href . '&id=' . $row['id']), $title, \Image::getHtml($icon, $label, $attributes)); }
/** * Generate the clear cache button. * * @param array $row The data row. * @param string $href The link. * @param string $label The label. * @param string $title The title. * @param string $icon The icon. * @param string $attributes The attributes. * * @return string */ public function generateButton($row, $href, $label, $title, $icon, $attributes) { $count = $this->service()->countPageCacheEntries($row['id']); if (!$count) { return \Image::getHtml($icon, $label, 'style="opacity:0.5;filter: gray;-webkit-filter: grayscale(100%);"'); } return sprintf('<a href="%s" title="%s"%s>%s</a> ', \Backend::addToUrl($href . '&id=' . $row['id']), $title . sprintf($GLOBALS['TL_LANG']['tl_page']['clearCacheCount'], $count), $attributes, \Image::getHtml($icon, $label)); }
/** * Callback edit button * @return string */ public function callbackEditButton($row, $href, $label, $title, $icon, $attributes, $strTable, $arrRootIds, $arrChildRecordIds, $blnCircularReference, $strPrevious, $strNext) { $return = ''; $strDcaKey = array_search($row['form'], $this->Formdata->arrFormsDcaKey); if ($strDcaKey) { $return .= '<a href="' . \Backend::addToUrl($href . '&do=fd_' . $strDcaKey . '&id=' . $row['id']) . '" title="' . specialchars($title) . '"' . $attributes . '>' . \Image::getHtml($icon, $label) . '</a> '; } return $return; }
/** * Apply a filter when looking at the history. * * @return void */ public function applyFilter() { if (\Input::get('providerName') && \Input::get('id')) { $entityId = EntityId::fromProviderNameAndId(\Input::get('providerName'), \Input::get('id')); $session = \Session::getInstance(); $filter = $session->get('filter'); $filter['tl_workflow_state'] = array('entityId' => (string) $entityId); $session->set('filter', $filter); \Backend::redirect(\Backend::addToUrl('providerName=', true, array('providerName', 'id'))); } }
/** * Return the "toggle visibility" button * @param array * @param string * @param string * @param string * @param string * @param string * @return string */ public function toggleIcon($row, $href, $label, $title, $icon, $attributes) { if (strlen(\Input::get('tid'))) { $this->toggleVisibility(\Input::get('tid'), \Input::get('state') == 1, @func_get_arg(12) ?: null); \Backend::redirect(\Controller::getReferer()); } $href .= '&tid=' . $row['id'] . '&state=' . ($row['published'] ? '' : 1); if (!$row['published']) { $icon = 'invisible.gif'; } return '<a href="' . \Backend::addToUrl($href) . '" title="' . specialchars($title) . '"' . $attributes . '>' . \Image::getHtml($icon, $label) . '</a> '; }
/** * Redirect to the content page when trying to access the content node. * * This fixes the edit links on the header. * * @return void */ public function redirect() { if ($this->input->get('table') === 'tl_content_node') { $model = \ContentModel::findByPk($this->input->get('id')); if (!$model) { \Controller::log(sprintf('Content node "%s" not found', $this->input->get('id')), __METHOD__, TL_ERROR); \Controller::redirect('contao/main.php?act=error'); } $nodes = $model->ptable === 'tl_content_node' ? '1' : ''; $url = \Backend::addToUrl('table=tl_content&nodes=' . $nodes); \Controller::redirect($url); } }
/** * Generate the wrapper. * * @return string * * @SuppressWarnings(PHPMD.Superglobals) */ public function generate() { // backend mode if (TL_MODE == 'BE') { if (!$this->wrapper->isTypeOf(Wrapper\Helper::TYPE_START) && !$this->bootstrap_parentId) { return sprintf('<a href="%s" class="bootstrap-wrapper-incomplete">%s</a>', \Backend::addToUrl('act=edit&bootstrap=parent&id=' . $this->id), $GLOBALS['TL_LANG']['tl_content']['fixBootstrapParent']); } if ($this->wrapper->isTypeOf(Wrapper\Helper::TYPE_STOP)) { return ''; } // do not display title if element is a wrapper element if (version_compare(VERSION, '3.1', '<')) { return sprintf('<strong class="title">%s</strong>', $this->type); } return ''; } $this->wrapperType = $this->wrapper->getType(); return parent::generate(); }
public function pasteButton(\DataContainer $dc, $row, $table, $cr, $arrClipboard = null) { $html = ''; if ($row['id'] > 0) { if ($row['pid'] > 0) { $parentCondition = ConditionModel::findByPk($row['pid']); $disabled = $parentCondition->type != 'or' && $parentCondition->type != 'and' && ($parentCondition->type != 'parent' || (bool) ConditionModel::findBy('pid', $row['id'])); } else { $disabled = false; } if ($disabled) { $html .= \Image::getHtml('pasteafter_.gif', sprintf($GLOBALS['TL_LANG'][$table]['pasteafter'][1], $row['id'])); } else { $html .= sprintf('<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a> ', \Backend::addToUrl('act=' . $arrClipboard['mode'] . '&mode=1&pid=' . $row['id'] . (!is_array($arrClipboard['id']) ? '&id=' . $arrClipboard['id'] : '')), specialchars(sprintf($GLOBALS['TL_LANG'][$table]['pasteafter'][1], $row['id'])), \Image::getHtml('pasteafter.gif', sprintf($GLOBALS['TL_LANG'][$table]['pasteafter'][1], $row['id']))); } } if ($row['id'] == 0 || $row['type'] == 'or' || $row['type'] == 'and' || $row['type'] == 'parent' && !ConditionModel::findBy('pid', $row['id'])) { $html .= sprintf('<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a> ', \Backend::addToUrl('act=' . $arrClipboard['mode'] . '&mode=2&pid=' . $row['id'] . (!is_array($arrClipboard['id']) ? '&id=' . $arrClipboard['id'] : '')), specialchars(sprintf($GLOBALS['TL_LANG'][$table]['pasteinto'][1], $row['id'])), \Image::getHtml('pasteinto.gif', sprintf($GLOBALS['TL_LANG'][$table]['pasteinto'][1], $row['id']))); } else { $html .= \Image::getHtml('pasteinto_.gif', sprintf($GLOBALS['TL_LANG'][$table]['pasteinto'][1], $row['id'])); } return $html; }
/** * Render the versions dropdown menu * * @return string */ public function renderDropdown() { $objVersion = $this->Database->prepare("SELECT tstamp, version, username, active FROM tl_version WHERE fromTable=? AND pid=? ORDER BY version DESC")->execute($this->strTable, $this->intPid); if ($objVersion->numRows < 2) { return ''; } $versions = ''; while ($objVersion->next()) { $versions .= ' <option value="' . $objVersion->version . '"' . ($objVersion->active ? ' selected="selected"' : '') . '>' . $GLOBALS['TL_LANG']['MSC']['version'] . ' ' . $objVersion->version . ' (' . \Date::parse(\Config::get('datimFormat'), $objVersion->tstamp) . ') ' . $objVersion->username . '</option>'; } return ' <div class="tl_version_panel"> <form action="' . ampersand(\Environment::get('request'), true) . '" id="tl_version" class="tl_form" method="post"> <div class="tl_formbody"> <input type="hidden" name="FORM_SUBMIT" value="tl_version"> <input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '"> <select name="version" class="tl_select">' . $versions . ' </select> <input type="submit" name="showVersion" id="showVersion" class="tl_submit" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['restore']) . '"> <a href="' . \Backend::addToUrl('versions=1&popup=1') . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['showDifferences']) . '" onclick="Backend.openModalIframe({\'width\':768,\'title\':\'' . specialchars(str_replace("'", "\\'", $GLOBALS['TL_LANG']['MSC']['showDifferences'])) . '\',\'url\':this.href});return false">' . \Image::getHtml('diff.gif') . '</a> </div> </form> </div> '; }
/** * Add and remove parameters from the current url. * * @param string|array $parameters Array of parameters to set. * * @param bool $addRefererId Flag if the referer token shall be added to the url. * * @param array $unsetParameters Array of parameters that shall be unset. * * @return string * * @SuppressWarnings(PHPMD.CamelCaseMethodName) * @codingStandardsIgnoreStart */ public function _addToUrl($parameters, $addRefererId = true, $unsetParameters = array()) { if (is_array($parameters)) { $parameters = http_build_query($parameters); } if (TL_MODE == 'BE') { return \Backend::addToUrl($parameters, $addRefererId, $unsetParameters); } return \Controller::addToUrl($parameters, $addRefererId, $unsetParameters); }
/** * Add a node. * * @param int $nodeId The node id. * @param string $label The label. * @param string|null $class The class. * @param bool $nodes The nodes. * * @return $this */ public function addNode($nodeId, $label, $class = null, $nodes = true) { $this->nodes[] = array('id' => $nodeId, 'label' => $label, 'class' => $class, 'link' => \Backend::addToUrl('id=' . $nodeId . '&nodes=' . (int) $nodes)); return $this; }
/** * Recursively render the grouptree * @param integer * @param integer * @param boolean * @return string */ protected function renderGrouptree($id, $intMargin, $blnNoRecursion = false) { $session = $this->Session->getData(); $flag = substr($this->strField, 0, 2) . 'g'; $node = 'tree_' . $this->strTable . '_' . $this->strField; $xtnode = 'tree_' . $this->strTable . '_' . $this->strName; // Get session data and toggle nodes if (\Input::get($flag . 'tg')) { $session[$node][\Input::get($flag . 'tg')] = isset($session[$node][\Input::get($flag . 'tg')]) && $session[$node][\Input::get($flag . 'tg')] == 1 ? 0 : 1; $this->Session->setData($session); \Controller::redirect(preg_replace('/(&(amp;)?|\\?)' . $flag . 'tg=[^& ]*/i', '', \Environment::get('request'))); } $objGroup = \Database::getInstance()->prepare("SELECT * FROM tl_iso_group WHERE id=?")->execute($id); // Return if there is no result if ($objGroup->numRows < 1) { return ''; } $return = ''; $intSpacing = 20; $childs = array(); // Check whether there are child records if (!$blnNoRecursion) { $objNodes = \Database::getInstance()->prepare("SELECT id FROM tl_iso_group WHERE pid=? ORDER BY sorting")->execute($id); if ($objNodes->numRows) { $childs = $objNodes->fetchEach('id'); } } $return .= "\n " . '<li class="tl_file" onmouseover="Theme.hoverDiv(this, 1);" onmouseout="Theme.hoverDiv(this, 0);" onclick="Theme.toggleSelect(this)"><div class="tl_left" style="padding-left:' . ($intMargin + $intSpacing) . 'px;">'; $folderAttribute = 'style="margin-left:20px;"'; $session[$node][$id] = is_numeric($session[$node][$id]) ? $session[$node][$id] : 0; $level = $intMargin / $intSpacing + 1; $blnIsOpen = $session[$node][$id] == 1 || in_array($id, $this->arrNodes); if (!empty($childs)) { $folderAttribute = ''; $img = $blnIsOpen ? 'folMinus.gif' : 'folPlus.gif'; $alt = $blnIsOpen ? $GLOBALS['TL_LANG']['MSC']['collapseNode'] : $GLOBALS['TL_LANG']['MSC']['expandNode']; $return .= '<a href="' . \Backend::addToUrl($flag . 'tg=' . $id) . '" title="' . specialchars($alt) . '" onclick="Backend.getScrollOffset(); return Isotope.toggleProductGroupTree(this, \'' . $xtnode . '_' . $id . '\', \'' . $this->strField . '\', \'' . $this->strName . '\', ' . $level . ');">' . \Image::getHtml($img, '', 'style="margin-right:2px;"') . '</a>'; } $callback = $GLOBALS['TL_DCA']['tl_iso_group']['list']['label']['label_callback']; // Load the label_callback if (is_array($callback) && !empty($callback)) { $return .= static::importStatic($callback[0])->{$callback}[1]($objGroup->row(), $objGroup->name, null, $folderAttribute); } $return .= '</div> <div class="tl_right">'; // Add checkbox or radio button switch ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['fieldType']) { case 'checkbox': $return .= '<input type="checkbox" name="' . $this->strName . '[]" id="' . $this->strName . '_' . $id . '" class="tl_tree_checkbox" value="' . specialchars($id) . '" onfocus="Backend.getScrollOffset()"' . static::optionChecked($id, $this->varValue) . '>'; break; default: case 'radio': $return .= '<input type="radio" name="' . $this->strName . '" id="' . $this->strName . '_' . $id . '" class="tl_tree_radio" value="' . specialchars($id) . '" onfocus="Backend.getScrollOffset()"' . static::optionChecked($id, $this->varValue) . '>'; break; } $return .= '</div><div style="clear:both"></div></li>'; // Begin a new submenu if (!empty($childs) && ($blnIsOpen || $this->Session->get('product_group_selector_search') != '')) { $return .= '<li class="parent" id="' . $node . '_' . $id . '"><ul class="level_' . $level . '">'; for ($k = 0, $c = count($childs); $k < $c; $k++) { $return .= $this->renderGrouptree($childs[$k], $intMargin + $intSpacing); } $return .= '</ul></li>'; } return $return; }
/** * Adds the buttons to the buttons bar and exports the data if it is an export button. * * @param array $arrButtons * * @return mixed */ public function addButtons($arrButtons) { $arrConfigs = \Database::getInstance()->prepare("SELECT id, name FROM tl_lead_export WHERE pid=? ORDER BY name")->execute(\Input::get('master'))->fetchAllAssoc(); // Run the export if ('tl_select' === \Input::post('FORM_SUBMIT')) { $arrIds = \Input::post('IDS'); if (empty($arrIds)) { \Controller::reload(); } if (\Input::post('notification')) { \Controller::redirect(\Backend::addToUrl('key=notification')); } foreach ($arrConfigs as $config) { if (\Input::post('export_' . $config['id'])) { $this->exportAndCatchExceptions($config['id'], $arrIds); } } } \System::loadLanguageFile('tl_lead_export'); // Generate buttons foreach ($arrConfigs as $config) { $arrButtons['export_' . $config['id']] = '<input type="submit" name="export_' . $config['id'] . '" id="export_' . $config['id'] . '" class="tl_submit" value="' . specialchars($GLOBALS['TL_LANG']['tl_lead']['export'][0] . ' "' . $config['name'] . '"') . '">'; } // Notification Center integration if (\Leads\NotificationCenterIntegration::available(true)) { $arrButtons['notification'] = '<input type="submit" name="notification" id="notification" class="tl_submit" value="' . specialchars($GLOBALS['TL_LANG']['tl_lead']['notification'][0]) . '">'; } return $arrButtons; }
/** * Generate a button. * * @param array $row Current row. * @param string $href The button href. * @param string $label The button label. * @param string $title The button title. * @param string $icon The button icon. * @param string $attributes Optional attributes. * * @return string */ protected function generateButton($row, $href, $label, $title, $icon, $attributes) { return sprintf('<a href="%s" title="%s">%s</a> ', \Backend::addToUrl($href . '&id=' . $row['id']), $title, \Image::getHtml($icon, $label, $attributes)); }
/** * List an file * * @param array * * @return string */ public function listFileFor($row, $layoutField = false) { switch ($row['type']) { case 'code': $label = $row['code_snippet_title']; break; case 'url': $label = preg_replace('#/([^/]+)$#', '/<strong>$1</strong>', $row['url']); break; case 'file': if ($row['filesource'] == $GLOBALS['TL_CONFIG']['uploadPath'] && version_compare(VERSION, '3', '>=')) { $file = version_compare(VERSION, '3.2', '>=') ? \FilesModel::findByUuid($row['file']) : \FilesModel::findByPk($row['file']); if ($file) { $label = preg_replace('#/([^/]+)$#', '/<strong>$1</strong>', $file->path); break; } } else { $label = preg_replace('#([^/]+)$#', '<strong>$1</strong>', $row['file']); break; } default: $label = '?'; } if ($row['inline']) { \Controller::loadLanguageFile('tl_theme_plus_file'); $label = sprintf('<span title="%s">‹›</span> %s', htmlentities($GLOBALS['TL_LANG']['tl_theme_plus_file']['inline'], ENT_QUOTES, 'UTF-8'), $label); } else { if ($row['standalone']) { \Controller::loadLanguageFile('tl_theme_plus_file'); $label = sprintf('<span title="%s">×</span> %s', htmlentities($GLOBALS['TL_LANG']['tl_theme_plus_file']['standalone'], ENT_QUOTES, 'UTF-8'), $label); } } if (strlen($row['position'])) { $label = '[' . strtoupper($row['position']) . '] ' . $label; } if (strlen($row['cc'])) { $label .= ' <span style="padding-left: 3px; color: #B3B3B3;">[' . $row['cc'] . ']</span>'; } $filterRules = static::renderFilterRules($row); if ($filterRules) { $label .= sprintf('<br><span style="margin-left: 20px; padding-left: 3px; color: #B3B3B3;">[%s]</span>', $filterRules); } if ($layoutField) { $assignedLayouts = []; $themes = \ThemeModel::findAll(['order' => 'name']); foreach ($themes as $theme) { $assignedThemeLayouts = []; $layouts = \LayoutModel::findBy('pid', $theme->id, ['order' => 'name']); foreach ($layouts as $layout) { $files = deserialize($layout->{$layoutField}, true); if (in_array($row['id'], $files)) { $assignedThemeLayouts[$layout->id] = $layout->name; } } if (count($assignedThemeLayouts)) { $assignedLayouts[$theme->name] = $assignedThemeLayouts; } } if (count($assignedLayouts)) { $label .= '<ul style="margin-left: 20px; padding-left: 3px; color: #B3B3B3;">'; foreach ($assignedLayouts as $theme => $layouts) { $label .= '<li>'; $label .= sprintf('<strong>%s</strong>', $theme); $label .= '<ul>'; foreach ($layouts as $id => $layout) { $label .= sprintf('<li> ↳ <a href="%s">%s</a></li>', \Backend::addToUrl('table=tl_layout&act=edit&id=' . $id), $layout); } $label .= '</ul>'; $label .= '</li>'; } $label .= '</ul>'; } } $image = 'assets/theme-plus/images/' . $row['type'] . '.png'; return '<div>' . ($image ? $this->generateImage($image, $label, 'style="vertical-align:-3px"') . ' ' : '') . $label . "</div>\n"; }
/** * List all records of the current table and return them as HTML string * @return string */ protected function listView() { $return = ''; $table = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 6 ? $this->ptable : $this->strTable; $table_alias = $table == 'tl_formdata' ? ' f' : ''; $orderBy = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['fields']; $firstOrderBy = preg_replace('/\\s+.*$/i', '', $orderBy[0]); if (is_array($this->orderBy) && $this->orderBy[0] != '') { $orderBy = $this->orderBy; $firstOrderBy = $this->firstOrderBy; } if (\Input::get('table') && $GLOBALS['TL_DCA'][$this->strTable]['config']['ptable'] && \Database::getInstance()->fieldExists('pid', $this->strTable)) { $this->procedure[] = 'pid=?'; $this->values[] = \Input::get('id'); } $query = "SELECT * " . (!empty($this->arrSqlDetails) ? ', ' . implode(',', array_values($this->arrSqlDetails)) : '') . " FROM " . $this->strTable . $table_alias; $sqlWhere = ''; if (!empty($this->procedure)) { $arrProcedure = $this->procedure; foreach ($arrProcedure as $kProc => $vProc) { $arrParts = preg_split('/[\\s=><\\!]/si', $vProc); $strProcField = $arrParts[0]; if (in_array($strProcField, $this->arrDetailFields)) { $arrProcedure[$kProc] = "(SELECT value FROM tl_formdata_details WHERE ff_name='" . $strProcField . "' AND pid=f.id)=?"; } } $sqlWhere = " WHERE " . implode(' AND ', $arrProcedure); } if ($sqlWhere != '') { $query .= $sqlWhere; } if (is_array($orderBy) && $orderBy[0] != '') { foreach ($orderBy as $o => $strVal) { $arrOrderField = explode(' ', $strVal); $strOrderField = $arrOrderField[0]; unset($arrOrderField); if (!in_array($strOrderField, $this->arrBaseFields)) { $orderBy[$o] = "(SELECT value FROM tl_formdata_details WHERE ff_name='" . $strOrderField . "' AND pid=f.id)"; } } $query .= " ORDER BY " . implode(', ', $orderBy); } if ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 1 && $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['flag'] % 2 == 0) { $query .= " DESC"; } $objRowStmt = \Database::getInstance()->prepare($query); if ($this->limit != '') { $arrLimit = explode(',', $this->limit); $objRowStmt->limit($arrLimit[1], $arrLimit[0]); } $objRow = $objRowStmt->execute($this->values); $this->bid = $return != '' ? $this->bid : 'tl_buttons'; // Display buttons if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] || !empty($GLOBALS['TL_DCA'][$this->strTable]['list']['global_operations'])) { $return .= ' <div id="' . $this->bid . '">' . (\Input::get('act') == 'select' || $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' ? ' ' . (!$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] ? '<a href="' . ($this->ptable != '' ? \Backend::addToUrl('act=create' . ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] < 4 ? '&mode=2' : '') . '&pid=' . $this->intId) : \Backend::addToUrl('act=create')) . '" 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> ' : '') . $this->generateGlobalButtons() : '') . ' </div>' . \Message::generate(true); } // Return "no records found" message if ($objRow->numRows < 1) { $return .= ' <p class="tl_empty">' . $GLOBALS['TL_LANG']['MSC']['noResult'] . '</p>'; } else { $result = $objRow->fetchAllAssoc(); $return .= (\Input::get('act') == 'select' ? ' <form action="' . ampersand(\Environment::get('request'), true) . '" id="tl_select" class="tl_form" method="post"> <div class="tl_formbody"> <input type="hidden" name="FORM_SUBMIT" value="tl_select"> <input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">' : '') . ' <div class="tl_listing_container list_view">' . (\Input::get('act') == 'select' ? ' <div class="tl_select_trigger"> <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"> </div>' : '') . ' <table class="tl_listing' . ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['showColumns'] ? ' showColumns' : '') . '">'; // Automatically add the "order by" field as last column if we do not have group headers if ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['showColumns'] && !in_array($firstOrderBy, $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['fields'])) { $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['fields'][] = $firstOrderBy; } // Rename each pid to its label and resort the result (sort by parent table) if ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 3) { $firstOrderBy = 'pid'; $showFields = $GLOBALS['TL_DCA'][$table]['list']['label']['fields']; foreach ($result as $k => $v) { $objField = \Database::getInstance()->prepare("SELECT " . $showFields[0] . " FROM " . $this->ptable . " WHERE id=?")->limit(1)->execute($v['pid']); $result[$k]['pid'] = $objField->{$showFields}[0]; } $aux = array(); foreach ($result as $row) { $aux[] = $row['pid']; } array_multisort($aux, SORT_ASC, $result); } // Generate the table header if the "show columns" option is active if ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['showColumns']) { $return .= ' <tr>'; foreach ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['fields'] as $f) { $return .= ' <th class="tl_folder_tlist col_' . $f . ($f == $firstOrderBy ? ' ordered_by' : '') . '">' . $GLOBALS['TL_DCA'][$this->strTable]['fields'][$f]['label'][0] . '</th>'; } $return .= ' <th class="tl_folder_tlist tl_right_nowrap"> </th> </tr>'; } // Process result and add label and buttons $remoteCur = false; $groupclass = 'tl_folder_tlist'; $eoCount = -1; foreach ($result as $row) { $rowFormatted = array(); $args = array(); $this->current[] = $row['id']; $showFields = $GLOBALS['TL_DCA'][$table]['list']['label']['fields']; // Label foreach ($showFields as $k => $v) { if (in_array($v, $this->arrDetailFields) && in_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['inputType'], array('radio', 'efgLookupRadio', 'select', 'efgLookupSelect', 'checkbox', 'efgLookupCheckbox', 'efgImageSelect', 'fileTree'))) { $strSep = isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['csv']) ? $GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['csv'] : '|'; $row[$v] = str_replace($strSep, ', ', $row[$v]); } if (in_array($v, $this->arrDetailFields) && $GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['multiple']) { $strSep = isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['csv']) ? $GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['csv'] : '|'; $row[$v] = str_replace($strSep, ', ', $row[$v]); } if (in_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['flag'], array(5, 6, 7, 8, 9, 10))) { if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['rgxp'] == 'date') { $args[$k] = strlen($row[$v]) ? \Date::parse($GLOBALS['TL_CONFIG']['dateFormat'], $row[$v]) : '-'; $rowFormatted[$v] = $args[$k]; } elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['rgxp'] == 'time') { $args[$k] = strlen($row[$v]) ? \Date::parse($GLOBALS['TL_CONFIG']['timeFormat'], $row[$v]) : '-'; $rowFormatted[$v] = $args[$k]; } else { $args[$k] = strlen($row[$v]) ? \Date::parse($GLOBALS['TL_CONFIG']['datimFormat'], $row[$v]) : '-'; $rowFormatted[$v] = $args[$k]; } } elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['inputType'] == 'checkbox' && !$GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['multiple']) { if (in_array($v, $this->arrDetailFields)) { $args[$k] = strlen($row[$v]) ? $row[$v] : '-'; $rowFormatted[$v] = $args[$k]; } else { $args[$k] = strlen($row[$v]) ? $GLOBALS['TL_DCA'][$table]['fields'][$v]['label'][0] : '-'; $rowFormatted[$v] = $args[$k]; } } elseif (in_array($v, $this->arrBaseFields) && in_array($v, $this->arrOwnerFields)) { if ($v == 'fd_member') { $args[$k] = $this->arrMembers[$row[$v]]; $rowFormatted[$v] = $args[$k]; } elseif ($v == 'fd_user') { $args[$k] = $this->arrUsers[$row[$v]]; $rowFormatted[$v] = $args[$k]; } elseif ($v == 'fd_member_group') { $args[$k] = $this->arrMemberGroups[$row[$v]]; $rowFormatted[$v] = $args[$k]; } elseif ($v == 'fd_user_group') { $args[$k] = $this->arrUserGroups[$row[$v]]; $rowFormatted[$v] = $args[$k]; } } else { $row_v = deserialize($row[$v]); if (is_array($row_v)) { $args_k = array(); foreach ($row_v as $option) { $args_k[] = strlen($GLOBALS['TL_DCA'][$table]['fields'][$v]['reference'][$option]) ? $GLOBALS['TL_DCA'][$table]['fields'][$v]['reference'][$option] : $option; } $args[$k] = implode(', ', $args_k); $rowFormatted[$v] = $args[$k]; } elseif (isset($GLOBALS['TL_DCA'][$table]['fields'][$v]['reference'][$row[$v]])) { $args[$k] = is_array($GLOBALS['TL_DCA'][$table]['fields'][$v]['reference'][$row[$v]]) ? $GLOBALS['TL_DCA'][$table]['fields'][$v]['reference'][$row[$v]][0] : $GLOBALS['TL_DCA'][$table]['fields'][$v]['reference'][$row[$v]]; } elseif (($GLOBALS['TL_DCA'][$table]['fields'][$v]['eval']['isAssociative'] || array_is_assoc($GLOBALS['TL_DCA'][$table]['fields'][$v]['options'])) && isset($GLOBALS['TL_DCA'][$table]['fields'][$v]['options'][$row[$v]])) { $args[$k] = $GLOBALS['TL_DCA'][$table]['fields'][$v]['options'][$row[$v]]; } else { // check multiline value if (!is_bool(strpos($row[$v], "\n"))) { $row[$v] = $this->Formdata->formatMultilineValue($row[$v]); } $args[$k] = $row[$v]; $rowFormatted[$v] = $args[$k]; } } } // Shorten the label it if it is too long $label = vsprintf(strlen($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['format']) ? $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['format'] : '%s', $args); if ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['maxCharacters'] > 0 && $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['maxCharacters'] < strlen(strip_tags($label))) { $label = trim(\String::substrHtml($label, $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['maxCharacters'])) . ' …'; } // Build the sorting groups if ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] > 0) { $current = $row[$firstOrderBy]; $orderBy = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['fields']; $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, $current, $sortingMode); // Add the group header if (!$GLOBALS['TL_DCA'][$this->strTable]['list']['label']['showColumns'] && !$GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['disableGrouping'] && ($remoteNew != $remoteCur || $remoteCur === false)) { $eoCount = -1; $group = $this->formatGroupHeader($firstOrderBy, $remoteNew, $sortingMode, $row); $remoteCur = $remoteNew; $return .= ' <tr> <td colspan="2" class="' . $groupclass . '">' . $group . '</td> </tr>'; $groupclass = 'tl_folder_list'; } } $return .= ' <tr class="' . (++$eoCount % 2 == 0 ? 'even' : 'odd') . ' click2edit" onmouseover="Theme.hoverRow(this,1)" onmouseout="Theme.hoverRow(this,0)" onclick="Theme.toggleSelect(this)"> '; $colspan = 1; // Call the label_callback ($row, $label, $this) if (is_array($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback']) || is_callable($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback'])) { if (is_array($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback'])) { $strClass = $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback'][0]; $strMethod = $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback'][1]; $this->import($strClass); $args = $this->{$strClass}->{$strMethod}($row, $label, $this, $args); } elseif (is_callable($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback'])) { $args = $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['label_callback']($row, $label, $this, $args); } // Handle strings and arrays (backwards compatibility) if (!$GLOBALS['TL_DCA'][$this->strTable]['list']['label']['showColumns']) { $label = is_array($args) ? implode(' ', $args) : $args; } elseif (!is_array($args)) { $args = array($args); $colspan = count($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['fields']); } } // Show columns if ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['showColumns']) { foreach ($args as $j => $arg) { $return .= '<td colspan="' . $colspan . '" class="tl_file_list col_' . $GLOBALS['TL_DCA'][$this->strTable]['list']['label']['fields'][$j] . ($GLOBALS['TL_DCA'][$this->strTable]['list']['label']['fields'][$j] == $firstOrderBy ? ' ordered_by' : '') . '">' . ($arg ?: '-') . '</td>'; } } else { $return .= '<td class="tl_file_list">' . $label . '</td>'; } // Buttons ($row, $table, $root, $blnCircularReference, $childs, $previous, $next) $return .= (\Input::get('act') == 'select' ? ' <td class="tl_file_list tl_right_nowrap"><input type="checkbox" name="IDS[]" id="ids_' . $row['id'] . '" class="tl_tree_checkbox" value="' . $row['id'] . '"></td>' : ' <td class="tl_file_list tl_right_nowrap">' . $this->generateButtons($row, $this->strTable, $this->root) . '</td>') . ' </tr>'; } // Close the table $return .= ' </table> </div>'; // Close the form if (\Input::get('act') == 'select') { $callbacks = ''; // Call the buttons_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'] as $callback) { $this->import($callback[0]); $callbacks .= $this->{$callback}[0]->{$callback}[1]($this); } } $return .= ' <div class="tl_formbody_submit" style="text-align:right"> <div class="tl_submit_container">' . (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notDeletable'] ? ' <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']) . '"> ' : '') . (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notEditable'] ? ' <input type="submit" name="edit" id="edit" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['editSelected']) . '"> ' : '') . ' </div> </div> </div> </form>'; } } return $return; }
/** * Gets the default button callback. * * @param string $name * @param string $table * @param array $hasteAjaxOperationSettings * * @return \Closure */ private function getDefaultButtonCallback($name, $table, array $hasteAjaxOperationSettings) { return function (array $row, $href, $label, $title, $icon, $attributes) use($name, $table, $hasteAjaxOperationSettings) { // If the user doesn't have access, hide the button if (!$this->checkPermission($table, $hasteAjaxOperationSettings)) { return ''; } $value = $row[$hasteAjaxOperationSettings['field']]; $options = $this->getOptions($hasteAjaxOperationSettings); $icon = null; foreach ($options as $k => $option) { if ($option['value'] == $value) { $icon = $option['icon']; } } // Default is the first value in the options array if (null === $icon) { $icon = $options[0]['icon']; } return sprintf('<a data-haste-ajax-operation-value="%s" data-haste-ajax-operation-name="%s" href="%s" title="%s"%s>%s</a> ', $value, $name, \Backend::addToUrl($href), specialchars($title), $attributes, \Image::getHtml($icon, $label)); }; }
/** * Generate the node type button. * * @param array $row The data row. * @param string $href The button href. * @param string $title The button title. * @param string $label The button label. * @param string $icon The icon. * @param string $attributes Html attributes. * * @return string */ public function generateButton($row, $href, $title, $label, $icon, $attributes) { if (!$this->registry->hasNodeType($row['type'])) { return ''; } return sprintf('<a href="%s" title="%s"%s>%s</a> ', \Backend::addToUrl($href . '&id=' . $row['id'], true, array('act', 'mode')), $title, $attributes, \Image::getHtml($icon, $label)); }
/** * Generate the move button. * * @param array $row The current row. * * @return string */ private function generateMoveButton($row) { $clipboard = \Session::getInstance()->get('CLIPBOARD'); $isClipboard = !empty($clipboard[$this->definition->getName()]); // Paste buttons if ($isClipboard) { $clipboard = $clipboard[$this->definition->getName()]; if (\Input::get('mode') == 'cut' && $this->isChildOf($row, $clipboard['id'])) { return \Image::getHtml('pasteafter_.gif', $this->translator->translate('pasteafter.0', $this->definition->getName())); } $url = \Backend::addToUrl('act=' . $clipboard['mode'] . '&mode=1&pid=' . $row['id'] . '&id=' . $clipboard['id']); return sprintf(' <a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a>', $url, specialchars(sprintf($this->translator->translate('pasteafter.1', $this->definition->getName()), $row['id'])), \Image::getHtml('pasteafter.gif', $this->translator->translate('pasteafter.0', $this->definition->getName()))); } return ''; }
/** * icon function. * * @access public * @static * @param int $intId * @param string $href * @param string $label * @param string $title * @param string $icon * @return string */ public static function icon($intId, $href, $label, $title, $icon) { return '<a href="' . \Backend::addToUrl($href . '&id=' . $intId . '&popup=1') . '" title="' . specialchars($title) . '" onclick="Backend.openModalIframe({\'width\':765,\'title\':\'' . specialchars(str_replace("'", "\\'", sprintf($title, $intId))) . '\',\'url\':this.href});return false">' . \Image::getHtml($icon, $label) . '</a> '; }
/** * Return the "cut" button * * @param array $row * @param string $href * @param string $label * @param string $title * @param string $icon * @param string $attributes * *@return string */ public function forGroup($row, $href, $label, $title, $icon, $attributes) { if ($row['pid'] > 0) { return ''; } // Check permission if (!\BackendUser::getInstance()->isAdmin) { $groups = deserialize(\BackendUser::getInstance()->iso_groups); if (!is_array($groups) || empty($groups)) { return \Image::getHtml(preg_replace('/\\.gif$/i', '_.gif', $icon)) . ' '; } } return '<a href="system/modules/isotope/group.php?do=' . \Input::get('do') . '&table=' . Group::getTable() . '&field=gid&value=' . $row['gid'] . '" title="' . specialchars($title) . '"' . $attributes . ' onclick="Backend.getScrollOffset();Isotope.openModalGroupSelector({\'width\':765,\'title\':\'' . specialchars($GLOBALS['TL_LANG']['tl_iso_product']['product_groups'][0]) . '\',\'url\':this.href,\'action\':\'moveProduct\',\'redirect\':\'' . \Backend::addToUrl($href . '&pid=' . intval(\Input::get('pid')) . '&id=' . $row['id']) . '\'});return false">' . \Image::getHtml($icon, $label) . '</a> '; }
/** * Add some suffix to the current URL. * * @param AddToUrlEvent $event The event. * * @return void */ public static function handleAddToUrl(AddToUrlEvent $event) { $event->setUrl(\Backend::addToUrl($event->getSuffix())); }
* Register models. */ $GLOBALS['TL_MODELS']['tl_leaflet_mm_renderer'] = 'Netzmacht\\Contao\\Leaflet\\MetaModels\\Model\\RendererModel'; /* * Add leaflet mapper. */ $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\\Contao\\Leaflet\\MetaModels\\LayerMapper'; /* * Add metamodels layer. */ $GLOBALS['LEAFLET_LAYERS']['metamodels'] = array('children' => false, 'icon' => 'system/modules/leaflet-metamodels/assets/img/layer.png', 'metamodels' => true, 'boundsMode' => array('extend' => true, 'fit' => true), 'label' => function ($row, $label) { $metaModel = \MetaModels\Factory::byId($row['metamodel']); if (!$metaModel) { return $label; } return $label . sprintf(' <span><a href="%s" class="tl_gray">(%s)</a></span>', \Backend::addToUrl(sprintf('do=metamodel_%s&table=%s', $metaModel->getTableName(), $metaModel->getTableName())), $metaModel->getName()); }); /* * Metamodels layer renderers */ $GLOBALS['LEAFLET_MM_RENDERER']['marker'] = 'Netzmacht\\Contao\\Leaflet\\MetaModels\\Renderer\\MarkerRenderer'; $GLOBALS['LEAFLET_MM_RENDERER']['geojson'] = 'Netzmacht\\Contao\\Leaflet\\MetaModels\\Renderer\\GeoJsonRenderer'; $GLOBALS['LEAFLET_MM_RENDERER']['reference'] = 'Netzmacht\\Contao\\Leaflet\\MetaModels\\Renderer\\ReferenceRenderer'; /* * MetaModel attribute factory. */ $GLOBALS['TL_EVENTS'][\MetaModels\MetaModelsEvents::ATTRIBUTE_FACTORY_CREATE][] = function (\MetaModels\Attribute\Events\CreateAttributeFactoryEvent $event) { $factory = $event->getFactory(); $factory->addTypeFactory(new \Netzmacht\Contao\Leaflet\MetaModels\Attribute\AttributeTypeFactory()); }; /*
/** * Copy multilingual fields from fallback to current language */ public function copyFallback() { $session = $this->Session->getData(); $strLanguage = $session['language'][$this->strTable][$this->intId]; $this->strPalette = trimsplit('[;,]', $this->getPalette()); $arrDuplicate = array(); foreach ($this->strPalette as $field) { if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]) && $GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['attributes']['multilingual']) { $arrDuplicate[] = $field; } } if (!empty($arrDuplicate)) { $intLanguageId = $this->Database->execute("SELECT id FROM {$this->strTable} WHERE pid={$this->intId} AND language='{$strLanguage}'")->id; $this->createInitialVersion($this->strTable, $intLanguageId); $arrRow = $this->Database->execute("SELECT " . implode(',', $arrDuplicate) . " FROM {$this->strTable} WHERE id={$this->intId}")->fetchAssoc(); \Database::getInstance()->prepare("UPDATE {$this->strTable} %s WHERE id={$intLanguageId}")->set($arrRow)->execute(); $this->createNewVersion($this->strTable, $intLanguageId); \System::log(sprintf('A new version of record ID %s (table %s) has been created', $intLanguageId, $this->strTable), 'DC_ProductData copyFallback()', TL_GENERAL); } \Controller::redirect(\Backend::addToUrl('act=edit')); }
/** * Return the "undo" button * @param array * @param string * @param string * @param string * @param string * @param string * @return string */ public function button($row, $href, $label, $title, $icon, $attributes) { if (static::hasData($row['id'])) { $href = '&key=haste_undo'; } return '<a href="' . \Backend::addToUrl($href . '&id=' . $row['id']) . '" title="' . specialchars($title) . '"' . $attributes . '>' . \Image::getHtml($icon, $label) . '</a> '; }