Display rollback/branch switcher for single site installation.

@access protected

@param \stdClass $theme

@return string
172803
protected function single_install_switcher( $theme ) {
		$nonced_update_url = wp_nonce_url(
			$this->get_update_url( 'theme', 'upgrade-theme', $theme->slug ),
			'upgrade-theme_' . $theme->slug
		);
		$rollback_url      = sprintf( '%s%s', $nonced_update_url, '&rollback=' );

		if ( ! isset( static::$options['branch_switch'] ) ) {
			return;
		}

		ob_start();
		if ( '1' === static::$options['branch_switch'] ) {
			printf(
				/* translators: 1: branch name, 2: jQuery dropdown, 3: closing tag */
				'<p>' . esc_html__( 'Current branch is `%1$s`, try %2$sanother version%3$s', 'github-updater' ),
				$theme->branch,
				'<a href="#" onclick="jQuery(\'#ghu_versions\').toggle();return false;">',
				'</a>.</p>'
			);
			?>
			<div id="ghu_versions" style="display:none; width: 100%;">
				<label><select style="width: 60%;" onchange="if(jQuery(this).val() != '') { jQuery(this).parent().next().show(); jQuery(this).parent().next().attr('href','<?php echo esc_url( $rollback_url ); ?>'+jQuery(this).val()); } else jQuery(this).parent().next().hide();">
				<option value=""><?php esc_html_e( 'Choose a Version', 'github-updater' ); ?>&#8230;</option>
			<?php
			if ( isset( $theme->branches ) ) {
				foreach ( array_keys( $theme->branches ) as $branch ) {
					echo '<option>' . $branch . '</option>';
				}
			}
			if ( ! empty( $theme->rollback ) ) {
				$rollback = array_keys( $theme->rollback );
				usort( $rollback, 'version_compare' );
				krsort( $rollback );
				$rollback = array_splice( $rollback, 0, 4, true );
				array_shift( $rollback ); // Dump current tag.
				foreach ( $rollback as $tag ) {
					echo '<option>' . $tag . '</option>';
				}
			}
			if ( empty( $theme->rollback ) ) {
				echo '<option>' . esc_html__( 'No previous tags to rollback to.', 'github-updater' ) . '</option></select></label>';
			}
			?>
					</select></label>
				<a style="display: none;" class="button-primary" href="?"><?php esc_html_e( 'Install', 'github-updater' ); ?></a>
			</div>
			<?php
		}

		return trim( ob_get_clean(), '1' );
	}
275538
def switch_theme(root_element, theme)
      old_map = @mapping
      new_map = map(theme)

      root_element.each_child do |e|
        old_classes = css_classes_for_map e.class.name, old_map
        new_classes = css_classes_for_map e.class.name, new_map
        update_element_css_classes(e, old_classes, new_classes)

        old_classes = css_classes_for_map e.class.superclass.name, old_map
        new_classes = css_classes_for_map e.class.superclass.name, new_map
        update_element_css_classes(e, old_classes, new_classes)
      end

      @mapping = new_map
    end
272275
private static function find_theme_config($themename, $settings, $parentscheck = true) {
        // We have to use the variable name $THEME (upper case) because that
        // is what is used in theme config.php files.

        if (!$dir = theme_config::find_theme_location($themename)) {
            return null;
        }

        $THEME = new stdClass();
        $THEME->name     = $themename;
        $THEME->dir      = $dir;
        $THEME->settings = $settings;

        global $CFG; // just in case somebody tries to use $CFG in theme config
        include("$THEME->dir/config.php");

        // verify the theme configuration is OK
        if (!is_array($THEME->parents)) {
            // parents option is mandatory now
            return null;
        } else {
            // We use $parentscheck to only check the direct parents (avoid infinite loop).
            if ($parentscheck) {
                // Find all parent theme configs.
                foreach ($THEME->parents as $parent) {
                    $parentconfig = theme_config::find_theme_config($parent, $settings, false);
                    if (empty($parentconfig)) {
                        return null;
                    }
                }
            }
        }

        return $THEME;
    }
485749
protected function collectBranch() : string
    {
        $branchesResult = $this->executor->execute('git branch');

        foreach ($branchesResult as $result) {
            if (strpos($result, '* ') === 0) {
                $exploded = explode('* ', $result, 2);

                return $exploded[1];
            }
        }

        throw new \RuntimeException();
    }
563398
public function getTargetBranch(string $component) : string {
        return array_key_exists($component, $this->branches)
                ? $this->branches[$component]
                : self::$defaultBranch;
    }
241744
protected function append_theme_actions_content( $theme ) {
		$details_url       = esc_attr(
			add_query_arg(
				[
					'tab'       => 'theme-information',
					'theme'     => $theme->slug,
					'TB_iframe' => 'true',
					'width'     => 270,
					'height'    => 400,
				],
				self_admin_url( 'theme-install.php' )
			)
		);
		$nonced_update_url = wp_nonce_url(
			$this->get_update_url( 'theme', 'upgrade-theme', $theme->slug ),
			'upgrade-theme_' . $theme->slug
		);

		$current = get_site_transient( 'update_themes' );

		/**
		 * Display theme update links.
		 */
		ob_start();
		if ( isset( $current->response[ $theme->slug ] ) ) {
			?>
			<p>
				<strong>
					<?php
					printf(
						/* translators: %s: theme name */
						esc_html__( 'There is a new version of %s available.', 'github-updater' ),
						$theme->name
					);
					printf(
						' <a href="%s" class="thickbox open-plugin-details-modal" title="%s">',
						$details_url,
						esc_attr( $theme->name )
					);
					printf(
						/* translators: 1: version number, 2: closing anchor tag, 3: update URL */
						esc_html__( 'View version %1$s details%2$s or %3$supdate now%2$s.', 'github-updater' ),
						$theme->remote_version = isset( $theme->remote_version ) ? $theme->remote_version : null,
						'</a>',
						sprintf(
							/* translators: %s: theme name */
							'<a aria-label="' . esc_html__( 'Update %s now', 'github-updater' ) . '" id="update-theme" data-slug="' . $theme->slug . '" href="' . $nonced_update_url . '">',
							$theme->name
						)
					);
					?>
				</strong>
			</p>
			<?php
		}

		return trim( ob_get_clean(), '1' );
	}
878831
public function main()
    {
        $this->out(__d('installer', '<info>Themes Shell</info>'));
        $this->hr();
        $this->out(__d('installer', '[1] Install new theme'));
        $this->out(__d('installer', '[2] Remove an existing theme'));
        $this->out(__d('installer', '[3] Change site theme'));
        $this->out(__d('installer', '[H]elp'));
        $this->out(__d('installer', '[Q]uit'));

        $choice = (string)strtolower($this->in(__d('installer', 'What would you like to do?'), ['1', '2', '3', 'H', 'Q']));
        switch ($choice) {
            case '1':
                $this->_install();
                break;
            case '2':
                $this->_uninstall();
                break;
            case '3':
                $this->_change();
                break;
            case 'h':
                $this->out($this->OptionParser->help());
                break;
            case 'q':
                return $this->_stop();
            default:
                $this->out(__d('installer', 'You have made an invalid selection. Please choose a command to execute by entering 1, 2, 3, H, or Q.'));
        }
        $this->hr();
        $this->main();
    }
1365061
private function mirrorThemes()
    {
        $filesystem = $this->app['filesystem'];
        $themes = $filesystem->find()
            ->directories()
            ->in('root://vendor/bolt/themes')
            ->depth(0)
        ;

        $confirm = $this->io->confirm('Continuing will copy/update the example themes into your installation, overwriting older copies. Is this OK?');
        if (!$confirm) {
            $this->io->note('Skipping theme copy');

            return;
        }

        foreach ($themes as $theme) {
            /** @var Directory $theme */
            $origin = $theme->getFullPath();
            $target = 'themes://' . $theme->getFilename();

            $this->io->title('Installing theme: ' . $theme->getFilename());
            $filesystem->mirror($origin, $target, ['override' => true]);
            $this->io->success('');
        }
    }
198288
public function symlink($theme)
    {
        $trace = debug_backtrace();

        if (! isset($trace[1])) return;

        $link = str_replace($this->getThemeName(), $theme, array_get($trace[1], 'file'));

        extract($this->arguments);
        extract($this->view->getShared());

        return require($link);
    }
722517
public function getThemeRegionConfigFor($theme, $contextType)
    {
        return array_filter(
            variable_get('ucms_layout_regions_' . $theme, []),
            function ($value) use ($contextType) {
                return $value == $contextType;
            }
        );
    }
844731
protected function getBasePath(Theme $theme = null) : string
    {
        $theme = $theme ?? $this->getTheme();

        if (isset($this->fullPaths[$theme->getKey()])) {
            return $this->fullPaths[$theme->getKey()];
        }

        return $this->fullPaths[$theme->getKey()] = $this->createPath($theme->getPath(), $this->directory);
    }
1108301
public function destroy($theme)
    {
        if ($this->themes->uninstall($theme)) {
            flash()->success(trans('cms::theme.deleted', compact('theme')));
        } else {
            flash()->error(trans('cms::theme.error', compact('theme')));
        }

        return back();
    }
285370
private function start_rollback_theme() {
		add_filter( 'update_theme_complete_actions', array( $this, 'alter_links_theme_upgrade' ) );
		$rollback   = $this->get_rollback();
		$transient  = get_site_transient( 'update_themes' );
		$folder     = $this->product->get_slug();
		$version    = $rollback['version'];
		$temp_array = array(
			'new_version' => $version,
			'package'     => $rollback['url'],
		);

		$transient->response[ $folder . '/style.css' ] = $temp_array;
		set_site_transient( 'update_themes', $transient );

		$transient = get_transient( $this->product->get_key() . '_warning_rollback' );

		if ( false === $transient ) {
			set_transient( $this->product->get_key() . '_warning_rollback', 'in progress', 30 );
			require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
			$title = sprintf( apply_filters( $this->product->get_key() . '_rollback_message', 'Rolling back %s to v%s' ), $this->product->get_name(), $version );
			$theme = $folder . '/style.css';
			$nonce = 'upgrade-theme_' . $theme;
			$url   = 'update.php?action=upgrade-theme&theme=' . urlencode( $theme );

			$upgrader = new \Theme_Upgrader( new \Theme_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'theme' ) ) );
			$upgrader->upgrade( $theme );
			delete_transient( $this->product->get_key() . '_warning_rollback' );
			wp_die(
				'',
				$title,
				array(
					'response' => 200,
				)
			);
		}
	}
90903
public static function convertFromLegacyTheme($theme)
    {
        if ($theme instanceof ConfigurablePlatformTheme) {
            return $theme;
        }

        // older themes are stored as an instance, newer ones as array
        if(is_array($theme)) {
            if(empty($theme[ThemeServiceInterface::THEME_CLASS_OFFSET])) {
                throw new \common_exception_MissingParameter(
                    ThemeServiceInterface::THEME_CLASS_OFFSET,
                    __METHOD__
                );
            }

            $options = !empty($theme[ThemeServiceInterface::THEME_OPTIONS_OFFSET])
                ? $theme[ThemeServiceInterface::THEME_OPTIONS_OFFSET]
                : []
            ;

            $theme = new $theme[ThemeServiceInterface::THEME_CLASS_OFFSET]($options);
        }

        // list of all previously used templates
        $templates = ['footer', 'header', 'header-logo', 'login-message'];

        // all keys associated with a public getter from previously used theme classes
        $getKeys = ['id', 'label', 'stylesheet', 'logoUrl', 'link', 'message', 'customTexts'];

        // collect options
        $options = [];
        if (method_exists($theme, 'getOptions')) {
            $options = $theme->getOptions();
        }

        if (method_exists($theme, 'getThemeData')) {
            $options = array_merge($options, $theme->getThemeData());
        }
        unset($options['data']);

        foreach ($getKeys as $key) {
            $method = 'get' . ucfirst($key);
            if (method_exists($theme, $method)) {
                $options[$key] = $theme->{$method}();
            }
        }
        // TAO default logo URL is different
        if($theme instanceof DefaultTheme) {
            $options['logoUrl'] = Template::img('tao-logo.png', 'tao');
        }

        if (method_exists($theme, 'getTemplate')) {
            if (empty($options[ConfigurablePlatformTheme::TEMPLATES])) {
                $options[ConfigurablePlatformTheme::TEMPLATES] = [];
            }
            foreach ($templates as $id) {
                $template = $theme->getTemplate($id);
                if(!is_null($template)) {
                    $options[ConfigurablePlatformTheme::TEMPLATES][$id] = $template;
                }
            }
        }

        // example: oat\taoExtension\model\theme\MyTheme
        $themeClass = get_class($theme);
        //@todo: map to container id
        if (empty($options[ConfigurablePlatformTheme::EXTENSION_ID])) {
            strtok($themeClass, '\\');
            $options[ConfigurablePlatformTheme::EXTENSION_ID] = strtok('\\');
        }

        if (empty($options[ConfigurablePlatformTheme::LABEL])) {
            $options[ConfigurablePlatformTheme::LABEL] = basename($themeClass);
        }
        return new ConfigurablePlatformTheme($options);
    }
1002100
public function findThemeAsset($theme, $asset)
    {
        if (! empty($theme)) {
            $Folders = $this->engine->getFolders();

            if ($Folders->exists($theme)) {
                $this->Folder = $Folders->get($theme);
                $folderPath = rtrim($this->Folder->getPath(), '/');

                $folderPath = $this->removeViewFromPath($folderPath);

                if (file_exists($folderPath . DS . $asset)) {
                    $this->createSymlink($folderPath);

                    return '/' . $this->assetDir . '/' . $this->asset['asset'];
                }
            }
        }
        return false;
    }
294493
public function find($themeName)
    {
        foreach ($this->getDirectories() as $directory) {
            if (! str_contains($directory, $themeName)) {
                continue;
            }

            return $this->getThemeInfoForPath($directory);
        }

        throw new ThemeNotFoundException($themeName);
    }
72684
public function getThemesFromDb($default_theme=null)
	{
		$criteria = new CDbCriteria;
		if($default_theme != null)
			$criteria->compare('default_theme', $default_theme);
		$criteria->order = 'folder ASC';
		$themes = OmmuThemes::model()->findAll($criteria);
		
		return $themes;
	}