<commit_before><?php
namespace Concrete\Controller\Panel\Page\Design;

use Concrete\Controller\Backend\UserInterface\Page as BackendInterfacePageController;
use Concrete\Core\Page\PageList;
use Permissions;
use Page;
use PermissionKey;
use PageTheme;
use PageEditResponse;
use Request;
use Response;
use Core;

class Customize extends BackendInterfacePageController
{
    protected $viewPath = '/panels/page/design/customize';
    protected $controllerActionPath = '/ccm/system/panels/page/design/customize';
    protected $helpers = array('form');

    public function canAccess()
    {
        return $this->permissions->canEditPageTheme();
    }

    public function view($pThemeID)
    {
        $this->requireAsset('core/style-customizer');
        $pt = PageTheme::getByID($pThemeID);
        if (is_object($pt) && $pt->isThemeCustomizable()) {
            $presets = $pt->getThemeCustomizableStylePresets();
            foreach ($presets as $preset) {
                if ($preset->isDefaultPreset()) {
                    $defaultPreset = $preset;
                }
            }

            // load the defaults for the panel, before we get to any
            // request-based tomfoolery.
            if ($this->page->hasPageThemeCustomizations()) {
                $object = $this->page->getCustomStyleObject();
            } else {
                $object = $pt->getThemeCustomStyleObject();
            }

            if (is_object($object)) {
                $handle = $object->getPresetHandle();
                if ($handle) {
                    $selectedPreset = $pt->getThemeCustomizablePreset($handle);
                }
                $valueList = $object->getValueList();
                $sccRecord = $object->getCustomCssRecord();
            } else {
                $selectedPreset = $defaultPreset;
                $valueList = $defaultPreset->getStyleValueList();
            }

            if ($this->request->request->has('handle')) {
                $preset = $pt->getThemeCustomizablePreset($this->request->request->get('handle'));
                if (is_object($preset)) {
                    $selectedPreset = $preset;
                    $valueList = $preset->getStyleValueList();
                }
            }

            // finally, we sort the presets so that the selected
            // preset is at the top
            usort($presets, function ($a, $b) use ($selectedPreset) {
                if (!$selectedPreset) {
                    return -1;
                }
                if ($selectedPreset->getPresetHandle() == $a->getPresetHandle()) {
                    return -1;
                }
                if ($selectedPreset->getPresetHandle() == $b->getPresetHandle()) {
                    return 1;
                }

                return strcasecmp($a->getPresetDisplayName('text'), $b->getPresetDisplayName('text'));<commit_msg>Avoid accessing undefined variable in page/design/customize.php controller (#4308)<commit_after><?php
namespace Concrete\Controller\Panel\Page\Design;

use Concrete\Controller\Backend\UserInterface\Page as BackendInterfacePageController;
use Concrete\Core\Page\PageList;
use Permissions;
use Page;
use PermissionKey;
use PageTheme;
use PageEditResponse;
use Request;
use Response;
use Core;

class Customize extends BackendInterfacePageController
{
    protected $viewPath = '/panels/page/design/customize';
    protected $controllerActionPath = '/ccm/system/panels/page/design/customize';
    protected $helpers = ['form'];

    public function canAccess()
    {
        return $this->permissions->canEditPageTheme();
    }

    public function view($pThemeID)
    {
        $this->requireAsset('core/style-customizer');
        $pt = PageTheme::getByID($pThemeID);
        if (is_object($pt) && $pt->isThemeCustomizable()) {
            $presets = $pt->getThemeCustomizableStylePresets();
            foreach ($presets as $preset) {
                if ($preset->isDefaultPreset()) {
                    $defaultPreset = $preset;
                }
            }

            // load the defaults for the panel, before we get to any
            // request-based tomfoolery.
            if ($this->page->hasPageThemeCustomizations()) {
                $object = $this->page->getCustomStyleObject();
            } else {
                $object = $pt->getThemeCustomStyleObject();
            }

            if (is_object($object)) {
                $handle = $object->getPresetHandle();
                if ($handle) {
                    $selectedPreset = $pt->getThemeCustomizablePreset($handle);
                }
                $valueList = $object->getValueList();
                $sccRecord = $object->getCustomCssRecord();
            } else {
                $selectedPreset = $defaultPreset;
                $valueList = $defaultPreset->getStyleValueList();
                $sccRecord = null;
            }

            if ($this->request->request->has('handle')) {
                $preset = $pt->getThemeCustomizablePreset($this->request->request->get('handle'));
                if (is_object($preset)) {
                    $selectedPreset = $preset;
                    $valueList = $preset->getStyleValueList();
                }
            }

            // finally, we sort the presets so that the selected
            // preset is at the top
            usort($presets, function ($a, $b) use ($selectedPreset) {
                if (!$selectedPreset) {
                    return -1;
                }
                if ($selectedPreset->getPresetHandle() == $a->getPresetHandle()) {
                    return -1;
                }
                if ($selectedPreset->getPresetHandle() == $b->getPresetHandle()) {
                    return 1;
                }

                return strcasecmp($a->getPresetDisplayName('text'), $b->getPresetDisplayName('text'));
{'fraction_non_alphanumeric': 0.12318964048389845, 'fraction_numerical': 0.0017038677798602829, 'mean_word_length': 1.8774509803921569, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 63, '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': '1557844', 'n_tokens_mistral': 1588, 'n_tokens_neox': 1515, 'n_words': 300}