<commit_before><?php

namespace wcf\acp\form;

use wcf\data\style\Style;
use wcf\data\style\StyleEditor;
use wcf\form\AbstractForm;
use wcf\system\exception\IllegalLinkException;
use wcf\system\WCF;

/**
 * Shows the style export form.
 *
 * @author  <NAME>
 * @copyright   2001-2019 WoltLab GmbH
 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package WoltLabSuite\Core\Acp\Form
 */
class StyleExportForm extends AbstractForm
{
    /**
     * @inheritDoc
     */
    public $activeMenuItem = 'wcf.acp.menu.link.style.list';

    /**
     * true, if style has custom images
     * @var bool
     */
    public $canExportImages = false;

    /**
     * true, if style has custom templates
     * @var bool
     */
    public $canExportTemplates = false;

    /**
     * export style as installable package
     * @var bool
     */
    public $exportAsPackage = false;

    /**
     * true, if templates should be exported
     * @var bool
     */
    public $exportTemplates = false;

    /**
     * @inheritDoc
     */
    public $neededPermissions = ['admin.style.canManageStyle'];

    /**
     * style object
     * @var Style
     */
    public $style;

    /**
     * style id
     * @var int
     */
    public $styleID = 0;

    /**
     * @inheritDoc
     */
    public function readParameters()
    {
        parent::readParameters();

        if (isset($_REQUEST['id'])) {
            $this->styleID = \intval($_REQUEST['id']);
        }
        $this->style = new Style($this->styleID);
        if (!$this->style->styleID) {
            throw new IllegalLinkException();
        }

        if ($this->style->templateGroupID) {
            $this->canExportTemplates = true;
        }
    }

    /**
     * @inheritDoc
     */
    public function readFormParameters()
    {
        parent::readFormParameters();

        if ($this->canExportTemplates && isset($_POST['exportTemplates'])) {
            $this->exportTemplates = true;
        }

        if ($this->style->packageName && isset($_POST['exportAsPackage'])) {
            $this->exportAsPackage = true;
        }
    }

    /**
     * @inheritDoc
     */
    public function save()
    {
        parent::save();

        // get style filename
        $filename = \str_replace(' ', '-', \preg_replace(
            '/[^a-z0-9 _-]/',
            '',
            \mb_strtolower($this->style->styleName)
        ));

        // send headers
        \header('Content-Type: application/x-gzip; charset=utf-8');

        if ($this->exportAsPackage) {
            \header('Content-Disposition: attachment; filename="' . $this->style->packageName . '.tar.gz"');
        } else {
            \header('Content-Disposition: attachment; filename="' . $filename . '-style.tgz"');
        }

        // export style
        $styleEditor = new StyleEditor($this->style);
        $styleEditor->export($this->exportTemplates, true, ($this->exportAsPackage ? $this->style->packageName : ''));

        // call saved event
        $this->saved();

        exit;
    }

    /**
     * @inheritDoc
     */
    public function assignVariables()
    {
        parent::assignVariables();
<commit_msg>Fix content-type for style export<commit_after><?php

namespace wcf\acp\form;

use wcf\data\style\Style;
use wcf\data\style\StyleEditor;
use wcf\form\AbstractForm;
use wcf\system\exception\IllegalLinkException;
use wcf\system\WCF;

/**
 * Shows the style export form.
 *
 * @author  <NAME>
 * @copyright   2001-2019 WoltLab GmbH
 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package WoltLabSuite\Core\Acp\Form
 */
class StyleExportForm extends AbstractForm
{
    /**
     * @inheritDoc
     */
    public $activeMenuItem = 'wcf.acp.menu.link.style.list';

    /**
     * true, if style has custom images
     * @var bool
     */
    public $canExportImages = false;

    /**
     * true, if style has custom templates
     * @var bool
     */
    public $canExportTemplates = false;

    /**
     * export style as installable package
     * @var bool
     */
    public $exportAsPackage = false;

    /**
     * true, if templates should be exported
     * @var bool
     */
    public $exportTemplates = false;

    /**
     * @inheritDoc
     */
    public $neededPermissions = ['admin.style.canManageStyle'];

    /**
     * style object
     * @var Style
     */
    public $style;

    /**
     * style id
     * @var int
     */
    public $styleID = 0;

    /**
     * @inheritDoc
     */
    public function readParameters()
    {
        parent::readParameters();

        if (isset($_REQUEST['id'])) {
            $this->styleID = \intval($_REQUEST['id']);
        }
        $this->style = new Style($this->styleID);
        if (!$this->style->styleID) {
            throw new IllegalLinkException();
        }

        if ($this->style->templateGroupID) {
            $this->canExportTemplates = true;
        }
    }

    /**
     * @inheritDoc
     */
    public function readFormParameters()
    {
        parent::readFormParameters();

        if ($this->canExportTemplates && isset($_POST['exportTemplates'])) {
            $this->exportTemplates = true;
        }

        if ($this->style->packageName && isset($_POST['exportAsPackage'])) {
            $this->exportAsPackage = true;
        }
    }

    /**
     * @inheritDoc
     */
    public function save()
    {
        parent::save();

        // get style filename
        $filename = \str_replace(' ', '-', \preg_replace(
            '/[^a-z0-9 _-]/',
            '',
            \mb_strtolower($this->style->styleName)
        ));

        // send headers
        \header('Content-Type: application/gzip');

        if ($this->exportAsPackage) {
            \header('Content-Disposition: attachment; filename="' . $this->style->packageName . '.tar.gz"');
        } else {
            \header('Content-Disposition: attachment; filename="' . $filename . '-style.tgz"');
        }

        // export style
        $styleEditor = new StyleEditor($this->style);
        $styleEditor->export($this->exportTemplates, true, ($this->exportAsPackage ? $this->style->packageName : ''));

        // call saved event
        $this->saved();

        exit;
    }

    /**
     * @inheritDoc
     */
    public function assignVariables()
    {
        parent::assignVariables();

{'fraction_non_alphanumeric': 0.1490226739640344, 'fraction_numerical': 0.003596559812353401, 'mean_word_length': 1.981818181818182, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 57, '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': '6201237', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1858, 'n_words': 377}