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

use Concrete\Controller\Backend\UserInterface\Page as BackendUIPageController;
use Concrete\Core\Page\Collection\Version\Version;
use Concrete\Core\Page\Type\Type;
use Permissions;
use PageTemplate;
use PageTheme;
use Request;
use PageEditResponse;
use Loader;
use Response;
use View;
use User;
use Concrete\Core\Workflow\Request\ApprovePageRequest;
use Config;

class Design extends BackendUIPageController
{
    protected $viewPath = '/panels/page/design';
    public function canAccess()
    {
        return $this->permissions->canEditPageTemplate() || $this->permissions->canEditPageTheme();
    }

    public function view()
    {
        $c = $this->page;
        $cp = $this->permissions;

        $pagetype = $c->getPageTypeObject();
        if (is_object($pagetype)) {
            $_templates = $pagetype->getPageTypePageTemplateObjects();
        } else {
            $_templates = PageTemplate::getList();
        }

        $pTemplateID = $c->getPageTemplateID();
        $templates = array();
        if ($pTemplateID) {
            $selectedTemplate = PageTemplate::getByID($pTemplateID);
            $templates[] = $selectedTemplate;
        }

        foreach ($_templates as $tmp) {
            if (!in_array($tmp, $templates)) {
                $templates[] = $tmp;
            }
        }

        $tArrayTmp = array_merge(PageTheme::getGlobalList(), PageTheme::getLocalList());
        $_themes = array();
        foreach ($tArrayTmp as $pt) {
            if ($cp->canEditPageTheme($pt)) {
                $_themes[] = $pt;
            }
        }

        $pThemeID = $c->getCollectionThemeID();
        if ($pThemeID) {
            $selectedTheme = PageTheme::getByID($pThemeID);
        } else {
            $selectedTheme = PageTheme::getSiteTheme();
        }

        $themes = array($selectedTheme);
        foreach ($_themes as $t) {
            if (!in_array($t, $themes)) {
                $themes[] = $t;
            }
        }

        $templatesSelect = array();
        $themesSelect = array();
        foreach ($_themes as $pt) {
            $themesSelect[$pt->getThemeID()] = $pt->getThemeDisplayName();
        }
        foreach ($_templates as $pt) {
            $templatesSelect[$pt->getPageTemplateID()] = $pt->getPageTemplateDisplayName();
        }

        $tree = $c->getSiteTreeObject();
        $type = $tree->getSiteType();
        $typeList = Type::getList(false, $type);
        $typesSelect = array('0' => t('** None'));
        foreach ($typeList as $_pagetype) {
            $typesSelect[$_pagetype->getPageTypeID()] = $_pagetype->getPageTypeDisplayName();
        }
<commit_msg>Error fix for null site tree object<commit_after><?php
namespace Concrete\Controller\Panel\Page;

use Concrete\Controller\Backend\UserInterface\Page as BackendUIPageController;
use Concrete\Core\Page\Collection\Version\Version;
use Concrete\Core\Page\Type\Type;
use Permissions;
use PageTemplate;
use PageTheme;
use Request;
use PageEditResponse;
use Loader;
use Response;
use View;
use User;
use Concrete\Core\Workflow\Request\ApprovePageRequest;
use Config;

class Design extends BackendUIPageController
{
    protected $viewPath = '/panels/page/design';
    public function canAccess()
    {
        return $this->permissions->canEditPageTemplate() || $this->permissions->canEditPageTheme();
    }

    public function view()
    {
        $c = $this->page;
        $cp = $this->permissions;

        $pagetype = $c->getPageTypeObject();
        if (is_object($pagetype)) {
            $_templates = $pagetype->getPageTypePageTemplateObjects();
        } else {
            $_templates = PageTemplate::getList();
        }

        $pTemplateID = $c->getPageTemplateID();
        $templates = array();
        if ($pTemplateID) {
            $selectedTemplate = PageTemplate::getByID($pTemplateID);
            $templates[] = $selectedTemplate;
        }

        foreach ($_templates as $tmp) {
            if (!in_array($tmp, $templates)) {
                $templates[] = $tmp;
            }
        }

        $tArrayTmp = array_merge(PageTheme::getGlobalList(), PageTheme::getLocalList());
        $_themes = array();
        foreach ($tArrayTmp as $pt) {
            if ($cp->canEditPageTheme($pt)) {
                $_themes[] = $pt;
            }
        }

        $pThemeID = $c->getCollectionThemeID();
        if ($pThemeID) {
            $selectedTheme = PageTheme::getByID($pThemeID);
        } else {
            $selectedTheme = PageTheme::getSiteTheme();
        }

        $themes = array($selectedTheme);
        foreach ($_themes as $t) {
            if (!in_array($t, $themes)) {
                $themes[] = $t;
            }
        }

        $templatesSelect = array();
        $themesSelect = array();
        foreach ($_themes as $pt) {
            $themesSelect[$pt->getThemeID()] = $pt->getThemeDisplayName();
        }
        foreach ($_templates as $pt) {
            $templatesSelect[$pt->getPageTemplateID()] = $pt->getPageTemplateDisplayName();
        }

        $typesSelect = array('0' => t('** None'));
        $tree = $c->getSiteTreeObject();
        if (is_object($tree)) {
            $type = $tree->getSiteType();
            $typeList = Type::getList(false, $type);
            foreach ($typeList as $_pagetype) {
                $typesSelect[$_pagetype->getPageTypeID()] = $_pagetype->getPageTypeDisplayName();
            }
        }

{'fraction_non_alphanumeric': 0.1411098941219423, 'fraction_numerical': 0.0003650967506389193, 'mean_word_length': 2.318594791035736, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '921400', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1562, 'n_words': 302}