<?php
/**
* This file is part of contao-community-alliance/contao-clipboard-bundle.
*
* (c) 2013 MEN AT WORK.
* (c) 2021 The CCA team.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* This project is provided in good faith and hope to be usable by anyone.
*
* @package Clipboard
* @author Ingolf Steinhardt <info@e-spin.de>
* @copyright 2013 MEN AT WORK.
* @copyright 2021 The CCA team.
* @license https://spdx.org/licenses/LGPL-3.0-or-later.html LGPL-3.0-or-later
* @filesource
*/
use ContaoCommunityAlliance\ClipboardBundle\Clipboard;
$clipboard = \Contao\System::getContainer()->get(Clipboard::class);
/**
* Create DCA if clipboard is ready to use
*/
if (TL_MODE == 'BE' && $clipboard->isClipboard('page')) {
/**
* Prepare clipboard contextmenu
*/
$clipboard->prepareContext();
/**
* Config
*/
$GLOBALS['TL_DCA']['tl_page']['config']['onload_callback'][] = [Clipboard::class, 'init'];
$GLOBALS['TL_DCA']['tl_page']['config']['dataContainer'] = 'Clipboard';
/**
* List operations
*/
// Copy button.
$GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_copy'] = [
'label' => &$GLOBALS['TL_LANG']['tl_page']['copy']
];
$GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_copy'] = array_merge(
$GLOBALS['CLIPBOARD']['copy'],
$GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_copy']
);
// Copy with children button.
$GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_copyChilds'] = [
'label' => &$GLOBALS['TL_LANG']['tl_page']['copyChilds'],
'button_callback' => ['tl_page_cl', 'cl_copyPageWithSubpages']
];
$GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_copyChilds'] = array_merge(
$GLOBALS['CLIPBOARD']['copy_childs'],
$GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_copyChilds']
);
if ($clipboard->cb()->hasFavorite()) {
// Paste after button.
$GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_paste_after'] = [
'label' => $GLOBALS['TL_LANG']['tl_page']['pasteafter'],
'attributes' => 'class="cl_paste"'
];
$GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_paste_after'] = array_merge(
$GLOBALS['CLIPBOARD']['pasteafter'],
$GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_paste_after']
);
// Paste into button.
$GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_paste_into'] = [
'label' => $GLOBALS['TL_LANG']['tl_page']['pasteinto'],
'attributes' => 'class="cl_paste"'
];
$GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_paste_into'] = array_merge(
$GLOBALS['CLIPBOARD']['pasteinto'],
$GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_paste_into']
);
}
}
class tl_page_cl extends tl_page
{
/**
* Return the copy page with subpages button
*
* @param array $row
* @param string $href
* @param string $label
* @param string $title
* @param string $icon
* @param string $attributes
* @param string $table
*
* @return string
*/
public function cl_copyPageWithSubpages($row, $href, $label, $title, $icon, $attributes, $table)
{
if ($GLOBALS['TL_DCA'][$table]['config']['closed']) {
return '';
}
$objSubpages = $this->Database->prepare("SELECT * FROM `tl_page` WHERE pid=?")
->limit(1)
->execute($row['id']);
return ($objSubpages->numRows
&& ($this->User->isAdmin
|| ($this->User->hasAccess(
$row['type'],
'alpty'
)
&& $this->User->isAllowed(
2,
$row
)))) ? '<a href="' . $this->addToUrl($href . '&id=' . $row['id']) . '" title="' . specialchars(
$title
) . '"' . $attributes . '>' . \Image::getHtml(
$icon,
$label
) . '</a> ' : '';
}
}