<commit_before><?php

namespace Craft;


/**
 * Digital Products Plugin for Craft Commerce.
 *
 * @author    Pixel & Tonic, Inc. <<EMAIL>>
 * @copyright Copyright (c) 2016, Pixel & Tonic, Inc.
 */
class DigitalProductsPlugin extends BasePlugin
{
    public $handle = 'digitalProducts';

    /**
     * Initialize the plugin.
     */
    public function init()
    {
        if (craft()->request->isCpRequest()) {
            craft()->templates->hook('digitalProducts.prepCpTemplate', array($this, 'prepCpTemplate'));
            $this->_includeCpResources();
        }

        $this->_registerEventHandlers();
    }

    /**
     * The plugin name.
     *
     * @return string
     */
    public function getName()
    {
        return 'Digital Products';
    }

    /**
     * The plugin description.
     *
     * @return string|null
     */
    public function getDescription()
    {
        return 'Add digital products to Craft Commerce.';
    }

    /**
     * @inheritdoc
     *
     * @return string
     */
    public function getDeveloper()
    {
        return 'Pixel & Tonic';
    }

    /**
     * Commerce Developer URL.
     *
     * @return string
     */
    public function getDeveloperUrl()
    {
        return 'https://craftcommerce.com';
    }

    /**
     * Commerce Documentation URL.
     *
     * @return string
     */
    public function getDocumentationUrl()
    {
        return;
    }

    /**
     * Digital Products has a control panel section.
     *
     * @return bool
     */
    public function hasCpSection()
    {
        return true;
    }

    /**
     * Make sure requirements are met before installation.
     *
     * @return bool
     * @throws Exception
     */
    public function onBeforeInstall()
    {
    }

    /**
     * Commerce Version.
     *
     * @return string
     */
    public function getVersion()
    {
        return '0.1';
    }

    /**
     * Commerce Schema Version.
     *
     * @return string|null
     */
    public function getSchemaVersion()
    {
        return '0.0.1';
    }

    /**
     * Control Panel routes.
     *
     * @return mixed
     */
    public function registerCpRoutes()
    {
        return [
            'digitalproducts/producttypes/new' => ['action' => 'digitalProducts/productTypes/edit'],
            'digitalproducts/producttypes/(?P<productTypeId>\d+)' => ['action' => 'digitalProducts/productTypes/edit'],
            'digitalproducts/products/(?P<productTypeHandle>{handle})' => ['action' => 'digitalProducts/products/index'],
            'digitalproducts/products/(?P<productTypeHandle>{handle})/new' => ['action' => 'digitalProducts/products/edit'],
            'digitalproducts/products/(?P<productTypeHandle>{handle})/new/(?P<localeId>\w+)' => ['action' => 'digitalProducts/products/edit'],
            'digitalproducts/products/(?P<productTypeHandle>{handle})/(?P<productId>\d+)' => ['action' => 'digitalProducts/products/edit'],
            'digitalproducts/products/(?P<productTypeHandle>{handle})/(?P<productId>\d+)/(?P<localeId>\w+)' => ['action' => 'digitalProducts/products/edit'],

            'digitalproducts/licenses/new' => ['action' => 'digitalProducts/licenses/edit'],
            'digitalproducts/licenses/(?P<licenseId>\d+)' => ['action' => 'digitalProducts/licenses/edit'],
        ];
    }

    /**
     * Prepares a CP template.
     *
     * @param array &$context The current template context
     */
    public function prepCpTemplate(&$context)
    {
        $context['subnav'] = array();

        if (craft()->userSession->checkPermission('commerce-manageProducts')) {
            $context['subnav']['productTypes'] = array('label' => Craft::t('Product types'), 'url' => 'digitalproducts/producttypes');
            $context['subnav']['products'] = array('label' => Craft::t('Products'), 'url' => 'digitalproducts/products');
        }

        if (craft()->userSession->checkPermission('commerce-manageOrders')) {
            $context['subnav']['licenses'] = array('label' => Craft::t('Licenses'), 'url' => 'digitalproducts/licenses');
        }
<commit_msg>Hide items in sidebar, if they are not relevant at the moment.<commit_after><?php

namespace Craft;


/**
 * Digital Products Plugin for Craft Commerce.
 *
 * @author    Pixel & Tonic, Inc. <<EMAIL>>
 * @copyright Copyright (c) 2016, Pixel & Tonic, Inc.
 */
class DigitalProductsPlugin extends BasePlugin
{
    public $handle = 'digitalProducts';

    /**
     * Initialize the plugin.
     */
    public function init()
    {
        if (craft()->request->isCpRequest()) {
            craft()->templates->hook('digitalProducts.prepCpTemplate', array($this, 'prepCpTemplate'));
            $this->_includeCpResources();
        }

        $this->_registerEventHandlers();
    }

    /**
     * The plugin name.
     *
     * @return string
     */
    public function getName()
    {
        return 'Digital Products';
    }

    /**
     * The plugin description.
     *
     * @return string|null
     */
    public function getDescription()
    {
        return 'Add digital products to Craft Commerce.';
    }

    /**
     * @inheritdoc
     *
     * @return string
     */
    public function getDeveloper()
    {
        return 'Pixel & Tonic';
    }

    /**
     * Commerce Developer URL.
     *
     * @return string
     */
    public function getDeveloperUrl()
    {
        return 'https://craftcommerce.com';
    }

    /**
     * Commerce Documentation URL.
     *
     * @return string
     */
    public function getDocumentationUrl()
    {
        return;
    }

    /**
     * Digital Products has a control panel section.
     *
     * @return bool
     */
    public function hasCpSection()
    {
        return true;
    }

    /**
     * Make sure requirements are met before installation.
     *
     * @return bool
     * @throws Exception
     */
    public function onBeforeInstall()
    {
    }

    /**
     * Commerce Version.
     *
     * @return string
     */
    public function getVersion()
    {
        return '0.1';
    }

    /**
     * Commerce Schema Version.
     *
     * @return string|null
     */
    public function getSchemaVersion()
    {
        return '0.0.1';
    }

    /**
     * Control Panel routes.
     *
     * @return mixed
     */
    public function registerCpRoutes()
    {
        return [
            'digitalproducts/producttypes/new' => ['action' => 'digitalProducts/productTypes/edit'],
            'digitalproducts/producttypes/(?P<productTypeId>\d+)' => ['action' => 'digitalProducts/productTypes/edit'],
            'digitalproducts/products/(?P<productTypeHandle>{handle})' => ['action' => 'digitalProducts/products/index'],
            'digitalproducts/products/(?P<productTypeHandle>{handle})/new' => ['action' => 'digitalProducts/products/edit'],
            'digitalproducts/products/(?P<productTypeHandle>{handle})/new/(?P<localeId>\w+)' => ['action' => 'digitalProducts/products/edit'],
            'digitalproducts/products/(?P<productTypeHandle>{handle})/(?P<productId>\d+)' => ['action' => 'digitalProducts/products/edit'],
            'digitalproducts/products/(?P<productTypeHandle>{handle})/(?P<productId>\d+)/(?P<localeId>\w+)' => ['action' => 'digitalProducts/products/edit'],

            'digitalproducts/licenses/new' => ['action' => 'digitalProducts/licenses/edit'],
            'digitalproducts/licenses/(?P<licenseId>\d+)' => ['action' => 'digitalProducts/licenses/edit'],
        ];
    }

    /**
     * Prepares a CP template.
     *
     * @param array &$context The current template context
     */
    public function prepCpTemplate(&$context)
    {
        $context['subnav'] = array();
        $productTypes = craft()->digitalProducts_productTypes->getProductTypes();

        if (craft()->userSession->checkPermission('commerce-manageProducts')) {
            $context['subnav']['productTypes'] = array('label' => Craft::t('Product types'), 'url' => 'digitalproducts/producttypes');

            if (!empty($productTypes)) {
                $context['subnav']['products'] = [
                    'label' => Craft::t('Products'),
                    'url' => 'digitalproducts/products'
                ];
            }
        }

        if (!empty($productTypes)) {
            if (craft()->userSession->checkPermission('commerce-manageOrders')) {
                $context['subnav']['licenses'] = [
                    'label' => Craft::t('Licenses'),
                    'url' => 'digitalproducts/licenses'
                ];
            }
        }
{'fraction_non_alphanumeric': 0.15592466955199438, 'fraction_numerical': 0.0021055094163060007, 'mean_word_length': 2.2312925170068025, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 99, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2127075', 'n_tokens_mistral': 2486, 'n_tokens_neox': 2343, 'n_words': 445}