<commit_before><?php

namespace Concrete\Controller\Backend\Page;

use Concrete\Controller\Backend\UserInterface\Page;
use Concrete\Core\Area\Area;
use Concrete\Core\Block\Block;
use Concrete\Core\Http\ResponseFactoryInterface;
use Concrete\Core\Page\EditResponse as PageEditResponse;
use Concrete\Core\Page\Stack\Stack;
use Concrete\Core\Permission\Checker;

class ArrangeBlocks extends Page
{
    public function canAccess()
    {
        return $this->permissions->canEditPageContents();
    }

    public function arrange()
    {
        $pc = new PageEditResponse();
        $pc->setPage($this->page);
        $this->performArrangement($pc);

        return $this->app->make(ResponseFactoryInterface::class)->json($pc);
    }

    /**
     * @param \Concrete\Core\Page\EditResponse $pc
     */
    protected function performArrangement(PageEditResponse $pc)
    {
        $e = $pc->getError();
        $post = $this->request->request;
        $nvc = $this->page->getVersionToModify();

        $sourceAreaID = (int) $post->get('sourceArea');
        $sourceAreaHandle = $sourceAreaID === 0 ? null : Area::getAreaHandleFromID($sourceAreaID);
        $sourceArea = (string) $sourceAreaHandle === '' ? null : Area::get($nvc, $sourceAreaHandle);
        if ($sourceArea === null) {
            $e->add(t('Unable to find the source area.'));

            return;
        }

        $destinationAreaID = (int) $post->get('area');
        if ($destinationAreaID === $sourceAreaID) {
            $destinationAreaHandle = $sourceAreaHandle;
            $desinationArea = $sourceArea;
        } else {
            $destinationAreaHandle = $destinationAreaID === 0 ? null : Area::getAreaHandleFromID($destinationAreaID);
            $destinationArea = (string) $destinationAreaHandle === '' ? null : Area::get($nvc, $destinationAreaHandle);
            if ($destinationArea === null) {
                $e->add(t('Unable to find the destination area.'));

                return;
            }
        }

        $movingBlockID = (int) $post->get('block');
        if ($movingBlockID === 0) {
            $e->add(t('Unable to find the block to be moved.'));

            return;
        }

        $otherBlockIDs = $post->get('blocks', []);

        if ($this->app->make('config')->get('concrete.permissions.model') == 'advanced') {
            // first, we check to see if we have permissions to edit the area contents for the source area.
            $ap = new Checker($sourceArea);
            if (!$ap->canEditAreaContents()) {
                $e->add(t('You may not arrange the contents of area %s.', $sourceAreaHandle));

                return;
            }
            // now we get further in. We check to see if we're dealing with both a source AND a destination area.
            // if so, we check the area permissions for the destination area.
            if ($sourceAreaID !== $destinationAreaID) {
                $destAP = new Checker($desinationArea);
                if (!$destAP->canEditAreaContents()) {
                    $e->add(t('You may not arrange the contents of area %s.', $destinationAreaHandle));

                    return;
                }
                // we're not done yet. Now we have to check to see whether this user has permission to add
                // a block of this type to the destination area.
                if ($sourceArea->isGlobalArea()) {
                    $sourceStack = Stack::getByName($sourceAreaHandle);
                    $block = Block::getByID($movingBlockID, $sourceStack, STACKS_AREA_NAME);
                } else {
                    $block = Block::getByID($movingBlockID, $nvc, $sourceAreaHandle);
                }
                if (!$block) {
                    $e->add(t('Unable to find the block to be moved.'));

                    return;
                }
                $bt = $block->getBlockTypeObject();
                if (!$destAP->canAddBlock($bt)) {
                    $e->add(t('You may not add %s to area %s.', t($bt->getBlockTypeName()), $destinationAreaHandle));<commit_msg>Fix typo<commit_after><?php

namespace Concrete\Controller\Backend\Page;

use Concrete\Controller\Backend\UserInterface\Page;
use Concrete\Core\Area\Area;
use Concrete\Core\Block\Block;
use Concrete\Core\Http\ResponseFactoryInterface;
use Concrete\Core\Page\EditResponse as PageEditResponse;
use Concrete\Core\Page\Stack\Stack;
use Concrete\Core\Permission\Checker;

class ArrangeBlocks extends Page
{
    public function canAccess()
    {
        return $this->permissions->canEditPageContents();
    }

    public function arrange()
    {
        $pc = new PageEditResponse();
        $pc->setPage($this->page);
        $this->performArrangement($pc);

        return $this->app->make(ResponseFactoryInterface::class)->json($pc);
    }

    /**
     * @param \Concrete\Core\Page\EditResponse $pc
     */
    protected function performArrangement(PageEditResponse $pc)
    {
        $e = $pc->getError();
        $post = $this->request->request;
        $nvc = $this->page->getVersionToModify();

        $sourceAreaID = (int) $post->get('sourceArea');
        $sourceAreaHandle = $sourceAreaID === 0 ? null : Area::getAreaHandleFromID($sourceAreaID);
        $sourceArea = (string) $sourceAreaHandle === '' ? null : Area::get($nvc, $sourceAreaHandle);
        if ($sourceArea === null) {
            $e->add(t('Unable to find the source area.'));

            return;
        }

        $destinationAreaID = (int) $post->get('area');
        if ($destinationAreaID === $sourceAreaID) {
            $destinationAreaHandle = $sourceAreaHandle;
            $destinationArea = $sourceArea;
        } else {
            $destinationAreaHandle = $destinationAreaID === 0 ? null : Area::getAreaHandleFromID($destinationAreaID);
            $destinationArea = (string) $destinationAreaHandle === '' ? null : Area::get($nvc, $destinationAreaHandle);
            if ($destinationArea === null) {
                $e->add(t('Unable to find the destination area.'));

                return;
            }
        }

        $movingBlockID = (int) $post->get('block');
        if ($movingBlockID === 0) {
            $e->add(t('Unable to find the block to be moved.'));

            return;
        }

        $otherBlockIDs = $post->get('blocks', []);

        if ($this->app->make('config')->get('concrete.permissions.model') == 'advanced') {
            // first, we check to see if we have permissions to edit the area contents for the source area.
            $ap = new Checker($sourceArea);
            if (!$ap->canEditAreaContents()) {
                $e->add(t('You may not arrange the contents of area %s.', $sourceAreaHandle));

                return;
            }
            // now we get further in. We check to see if we're dealing with both a source AND a destination area.
            // if so, we check the area permissions for the destination area.
            if ($sourceAreaID !== $destinationAreaID) {
                $destAP = new Checker($destinationArea);
                if (!$destAP->canEditAreaContents()) {
                    $e->add(t('You may not arrange the contents of area %s.', $destinationAreaHandle));

                    return;
                }
                // we're not done yet. Now we have to check to see whether this user has permission to add
                // a block of this type to the destination area.
                if ($sourceArea->isGlobalArea()) {
                    $sourceStack = Stack::getByName($sourceAreaHandle);
                    $block = Block::getByID($movingBlockID, $sourceStack, STACKS_AREA_NAME);
                } else {
                    $block = Block::getByID($movingBlockID, $nvc, $sourceAreaHandle);
                }
                if (!$block) {
                    $e->add(t('Unable to find the block to be moved.'));

                    return;
                }
                $bt = $block->getBlockTypeObject();
                if (!$destAP->canAddBlock($bt)) {
                    $e->add(t('You may not add %s to area %s.', t($bt->getBlockTypeName()), $destinationAreaHandle));
{'fraction_non_alphanumeric': 0.13402188614287472, 'fraction_numerical': 0.0007377351530800443, 'mean_word_length': 2.121258633921719, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6883699', 'n_tokens_mistral': 2231, 'n_tokens_neox': 2152, 'n_words': 552}