tl_page::pastePage PHP Method

pastePage() public method

Return the paste page button
public pastePage ( DataContainer $dc, array $row, string $table, boolean $cr, array $arrClipboard = null ) : string
$dc DataContainer
$row array
$table string
$cr boolean
$arrClipboard array
return string
    public function pastePage(DataContainer $dc, $row, $table, $cr, $arrClipboard = null)
    {
        $disablePA = false;
        $disablePI = false;
        // Disable all buttons if there is a circular reference
        if ($arrClipboard !== false && ($arrClipboard['mode'] == 'cut' && ($cr == 1 || $arrClipboard['id'] == $row['id']) || $arrClipboard['mode'] == 'cutAll' && ($cr == 1 || in_array($row['id'], $arrClipboard['id'])))) {
            $disablePA = true;
            $disablePI = true;
        }
        // Prevent adding non-root pages on top-level
        if (Input::get('mode') != 'create' && $row['pid'] == 0) {
            $objPage = $this->Database->prepare("SELECT * FROM " . $table . " WHERE id=?")->limit(1)->execute(Input::get('id'));
            if ($objPage->type != 'root') {
                $disablePA = true;
                if ($row['id'] == 0) {
                    $disablePI = true;
                }
            }
        }
        // Check permissions if the user is not an administrator
        if (!$this->User->isAdmin) {
            // Disable "paste into" button if there is no permission 2 (move) or 1 (create) for the current page
            if (!$disablePI) {
                if (!$this->User->isAllowed(BackendUser::CAN_EDIT_PAGE_HIERARCHY, $row) || Input::get('mode') == 'create' && !$this->User->isAllowed(BackendUser::CAN_EDIT_PAGE, $row)) {
                    $disablePI = true;
                }
            }
            $objPage = $this->Database->prepare("SELECT * FROM " . $table . " WHERE id=?")->limit(1)->execute($row['pid']);
            // Disable "paste after" button if there is no permission 2 (move) or 1 (create) for the parent page
            if (!$disablePA && $objPage->numRows) {
                if (!$this->User->isAllowed(BackendUser::CAN_EDIT_PAGE_HIERARCHY, $objPage->row()) || Input::get('mode') == 'create' && !$this->User->isAllowed(BackendUser::CAN_EDIT_PAGE, $objPage->row())) {
                    $disablePA = true;
                }
            }
            // Disable "paste after" button if the parent page is a root page and the user is not an administrator
            if (!$disablePA && ($row['pid'] < 1 || in_array($row['id'], $dc->rootIds))) {
                $disablePA = true;
            }
        }
        $return = '';
        // Return the buttons
        $imagePasteAfter = Image::getHtml('pasteafter.svg', sprintf($GLOBALS['TL_LANG'][$table]['pasteafter'][1], $row['id']));
        $imagePasteInto = Image::getHtml('pasteinto.svg', sprintf($GLOBALS['TL_LANG'][$table]['pasteinto'][1], $row['id']));
        if ($row['id'] > 0) {
            $return = $disablePA ? Image::getHtml('pasteafter_.svg') . ' ' : '<a href="' . $this->addToUrl('act=' . $arrClipboard['mode'] . '&amp;mode=1&amp;pid=' . $row['id'] . (!is_array($arrClipboard['id']) ? '&amp;id=' . $arrClipboard['id'] : '')) . '" title="' . StringUtil::specialchars(sprintf($GLOBALS['TL_LANG'][$table]['pasteafter'][1], $row['id'])) . '" onclick="Backend.getScrollOffset()">' . $imagePasteAfter . '</a> ';
        }
        return $return . ($disablePI ? Image::getHtml('pasteinto_.svg') . ' ' : '<a href="' . $this->addToUrl('act=' . $arrClipboard['mode'] . '&amp;mode=2&amp;pid=' . $row['id'] . (!is_array($arrClipboard['id']) ? '&amp;id=' . $arrClipboard['id'] : '')) . '" title="' . StringUtil::specialchars(sprintf($GLOBALS['TL_LANG'][$table]['pasteinto'][1], $row['id'])) . '" onclick="Backend.getScrollOffset()">' . $imagePasteInto . '</a> ');
    }

Usage Example

コード例 #1
0
ファイル: tl_page.php プロジェクト: Ainschy/contao-core
 public function pastePage(DataContainer $dc, $row, $table, $cr, $clipboardData = false)
 {
     if ($row['type'] == 'avisota') {
         $disablePA = false;
         // Disable all buttons if there is a circular reference
         if ($clipboardData !== false && ($clipboardData['mode'] == 'cut' && ($cr == 1 || $clipboardData['id'] == $row['id']) || $clipboardData['mode'] == 'cutAll' && ($cr == 1 || in_array($row['id'], $clipboardData['id'])))) {
             $disablePA = true;
         }
         // Check permissions if the user is not an administrator
         if (!$this->User->isAdmin) {
             $page = \Database::getInstance()->prepare("SELECT * FROM " . $table . " WHERE id=?")->limit(1)->execute($row['pid']);
             // Disable "paste after" button if there is no permission 2 for the parent page
             if (!$disablePA && $page->numRows) {
                 if (!$this->User->isAllowed(2, $page->row())) {
                     $disablePA = true;
                 }
             }
             // Disable "paste after" button if the parent page is a root page and the user is not an administrator
             if (!$disablePA && ($row['pid'] < 1 || in_array($row['id'], $dc->rootIds))) {
                 $disablePA = true;
             }
         }
         // Return the buttons
         $imagePasteAfter = $this->generateImage('pasteafter.gif', sprintf($GLOBALS['TL_LANG'][$table]['pasteafter'][1], $row['id']), 'class="blink"');
         if ($row['id'] > 0) {
             return $disablePA ? $this->generateImage('pasteafter_.gif', '', 'class="blink"') . ' ' : '<a href="' . $this->addToUrl('act=' . $clipboardData['mode'] . '&amp;mode=1&amp;pid=' . $row['id'] . (!is_array($clipboardData['id']) ? '&amp;id=' . $clipboardData['id'] : '')) . '" title="' . specialchars(sprintf($GLOBALS['TL_LANG'][$table]['pasteafter'][1], $row['id'])) . '" onclick="Backend.getScrollOffset();">' . $imagePasteAfter . '</a> ' . $this->generateImage('pasteinto_.gif', '', 'class="blink"');
         }
         return '';
     }
     return parent::pastePage($dc, $row, $table, $cr, $clipboardData);
 }