vendor/contao-community-alliance/contao-clipboard-bundle/src/Resources/contao/dca/tl_page.php line 24

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of contao-community-alliance/contao-clipboard-bundle.
  4.  *
  5.  * (c) 2013 MEN AT WORK.
  6.  * (c) 2021 The CCA team.
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  *
  11.  * This project is provided in good faith and hope to be usable by anyone.
  12.  *
  13.  * @package    Clipboard
  14.  * @author     Ingolf Steinhardt <info@e-spin.de>
  15.  * @copyright  2013 MEN AT WORK.
  16.  * @copyright  2021 The CCA team.
  17.  * @license    https://spdx.org/licenses/LGPL-3.0-or-later.html LGPL-3.0-or-later
  18.  * @filesource
  19.  */
  20. use ContaoCommunityAlliance\ClipboardBundle\Clipboard;
  21. $clipboard = \Contao\System::getContainer()->get(Clipboard::class);
  22. /**
  23.  * Create DCA if clipboard is ready to use
  24.  */
  25. if (TL_MODE == 'BE' && $clipboard->isClipboard('page')) {
  26.     /**
  27.      * Prepare clipboard contextmenu
  28.      */
  29.     $clipboard->prepareContext();
  30.     /**
  31.      * Config
  32.      */
  33.     $GLOBALS['TL_DCA']['tl_page']['config']['onload_callback'][] = [Clipboard::class, 'init'];
  34.     $GLOBALS['TL_DCA']['tl_page']['config']['dataContainer']     = 'Clipboard';
  35.     /**
  36.      * List operations
  37.      */
  38.     // Copy button.
  39.     $GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_copy'] = [
  40.         'label' => &$GLOBALS['TL_LANG']['tl_page']['copy']
  41.     ];
  42.     $GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_copy'] = array_merge(
  43.         $GLOBALS['CLIPBOARD']['copy'],
  44.         $GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_copy']
  45.     );
  46.     // Copy with children button.
  47.     $GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_copyChilds'] = [
  48.         'label'           => &$GLOBALS['TL_LANG']['tl_page']['copyChilds'],
  49.         'button_callback' => ['tl_page_cl''cl_copyPageWithSubpages']
  50.     ];
  51.     $GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_copyChilds'] = array_merge(
  52.         $GLOBALS['CLIPBOARD']['copy_childs'],
  53.         $GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_copyChilds']
  54.     );
  55.     if ($clipboard->cb()->hasFavorite()) {
  56.         // Paste after button.
  57.         $GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_paste_after'] = [
  58.             'label'      => $GLOBALS['TL_LANG']['tl_page']['pasteafter'],
  59.             'attributes' => 'class="cl_paste"'
  60.         ];
  61.         $GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_paste_after'] = array_merge(
  62.             $GLOBALS['CLIPBOARD']['pasteafter'],
  63.             $GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_paste_after']
  64.         );
  65.         // Paste into button.
  66.         $GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_paste_into'] = [
  67.             'label'      => $GLOBALS['TL_LANG']['tl_page']['pasteinto'],
  68.             'attributes' => 'class="cl_paste"'
  69.         ];
  70.         $GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_paste_into'] = array_merge(
  71.             $GLOBALS['CLIPBOARD']['pasteinto'],
  72.             $GLOBALS['TL_DCA']['tl_page']['list']['operations']['cl_paste_into']
  73.         );
  74.     }
  75. }
  76. class tl_page_cl extends tl_page
  77. {
  78.     /**
  79.      * Return the copy page with subpages button
  80.      *
  81.      * @param array  $row
  82.      * @param string $href
  83.      * @param string $label
  84.      * @param string $title
  85.      * @param string $icon
  86.      * @param string $attributes
  87.      * @param string $table
  88.      *
  89.      * @return string
  90.      */
  91.     public function cl_copyPageWithSubpages($row$href$label$title$icon$attributes$table)
  92.     {
  93.         if ($GLOBALS['TL_DCA'][$table]['config']['closed']) {
  94.             return '';
  95.         }
  96.         $objSubpages $this->Database->prepare("SELECT * FROM `tl_page` WHERE pid=?")
  97.             ->limit(1)
  98.             ->execute($row['id']);
  99.         return ($objSubpages->numRows
  100.                 && ($this->User->isAdmin
  101.                     || ($this->User->hasAccess(
  102.                         $row['type'],
  103.                         'alpty'
  104.                     )
  105.                         && $this->User->isAllowed(
  106.                         2,
  107.                         $row
  108.                     )))) ? '<a href="' $this->addToUrl($href '&amp;id=' $row['id']) . '" title="' specialchars(
  109.                 $title
  110.             ) . '"' $attributes '>' . \Image::getHtml(
  111.                 $icon,
  112.                 $label
  113.             ) . '</a> ' '';
  114.     }
  115. }