SettingsController::mobileThemes PHP Method

mobileThemes() public method

Mobile Themes management screen.
Since: 2.2.10.3
public mobileThemes ( string $ThemeName = '', string $TransientKey = '' )
$ThemeName string Unique ID.
$TransientKey string Security token.
    public function mobileThemes($ThemeName = '', $TransientKey = '')
    {
        $IsMobile = true;
        $this->addJsFile('addons.js');
        $this->addJsFile('addons.js');
        $this->setData('Title', t('Mobile Themes'));
        $this->permission('Garden.Settings.Manage');
        $this->setHighlightRoute('dashboard/settings/themes');
        // Get currently enabled theme.
        $EnabledThemeName = Gdn::ThemeManager()->MobileTheme();
        $ThemeInfo = Gdn::themeManager()->getThemeInfo($EnabledThemeName);
        $this->setData('EnabledThemeInfo', $ThemeInfo);
        $this->setData('EnabledThemeFolder', val('Folder', $ThemeInfo));
        $this->setData('EnabledTheme', $ThemeInfo);
        $this->setData('EnabledThemeScreenshotUrl', val('ScreenshotUrl', $ThemeInfo));
        $this->setData('EnabledThemeName', val('Name', $ThemeInfo, val('Index', $ThemeInfo)));
        // Get all themes.
        $Themes = Gdn::themeManager()->availableThemes();
        // Filter themes.
        foreach ($Themes as $ThemeKey => $ThemeData) {
            // Only show mobile themes.
            if (empty($ThemeData['IsMobile'])) {
                unset($Themes[$ThemeKey]);
            }
            // Remove themes that are archived
            if (!empty($ThemeData['Archived'])) {
                unset($Themes[$ThemeKey]);
            }
        }
        uasort($Themes, array('SettingsController', '_NameSort'));
        $this->setData('AvailableThemes', $Themes);
        // Process self-post.
        if ($ThemeName != '' && Gdn::session()->validateTransientKey($TransientKey)) {
            try {
                $ThemeInfo = Gdn::themeManager()->getThemeInfo($ThemeName);
                if ($ThemeInfo === false) {
                    throw new Exception(sprintf(t("Could not find a theme identified by '%s'"), $ThemeName));
                }
                Gdn::session()->setPreference(array('PreviewMobileThemeName' => '', 'PreviewMobileThemeFolder' => ''));
                // Clear out the preview
                Gdn::themeManager()->enableTheme($ThemeName, $IsMobile);
                $this->EventArguments['ThemeName'] = $ThemeName;
                $this->EventArguments['ThemeInfo'] = $ThemeInfo;
                $this->fireEvent('AfterEnableTheme');
            } catch (Exception $Ex) {
                $this->Form->addError($Ex);
            }
            $AsyncRequest = $this->deliveryType() === DELIVERY_TYPE_VIEW ? true : false;
            if ($this->Form->errorCount() == 0) {
                if ($AsyncRequest) {
                    echo 'Success';
                    $this->render('Blank', 'Utility', 'Dashboard');
                    exit;
                } else {
                    redirect('/settings/mobilethemes');
                }
            } else {
                if ($AsyncRequest) {
                    echo $this->Form->errorString();
                    $this->render('Blank', 'Utility', 'Dashboard');
                    exit;
                }
            }
        }
        $this->render();
    }