public function test_get_key_type_name()
 {
     $unique = md5(uniqid());
     $generator = $this->getMock('\\ITELIC\\Key\\Generator');
     itelic_register_key_type($unique, 'Type Name', $generator);
     $this->assertEquals('Type Name', itelic_get_key_type_name($unique));
 }
示例#2
0
    /**
     * This echos the feature metabox.
     *
     * @since 1.0
     *
     * @param \WP_Post $post
     */
    function print_metabox($post)
    {
        add_action('admin_footer', array($this, 'changelog_popup'));
        wp_enqueue_style('itelic-add-edit-product');
        wp_enqueue_script('itelic-add-edit-product');
        wp_localize_script('itelic-add-edit-product', 'ITELIC', array('ajax' => admin_url('admin-ajax.php'), 'product' => isset($post->ID) ? $post->ID : 0, 'df' => it_exchange_php_date_format_to_jquery_datepicker_format(get_option('date_format'))));
        $settings = it_exchange_get_option('addon_itelic');
        $downloads = it_exchange_get_product_feature(isset($post->ID) ? $post->ID : 0, 'downloads');
        if (!is_array($downloads)) {
            $downloads = array();
        }
        $data = it_exchange_get_product_feature(isset($post->ID) ? $post->ID : 0, $this->slug);
        $hidden = $data['enabled'] ? '' : ' hide-if-js';
        $hidden_variants = $data['enabled_variant_activations'] ? '' : ' hide-if-js';
        $hidden_simple = $hidden_variants ? '' : ' hide-if-js';
        $version_read = empty($data['version']) ? '' : 'readonly';
        ?>

		<p><?php 
        echo $this->description;
        ?>
</p>

		<p>
			<input type="checkbox" id="itelic-enable" name="itelic[enabled]" <?php 
        checked(true, $data['enabled']);
        ?>
>
			<label for="itelic-enable"><?php 
        _e("Enable Licensing for this product", Plugin::SLUG);
        ?>
</label>
		</p>

		<div class="itelic-settings<?php 
        echo esc_attr($hidden);
        ?>
">

			<?php 
        if ($settings['sell-online-software']) {
            ?>
				<p>
					<input type="checkbox" id="itelic-online-software" name="itelic[online-software]" <?php 
            checked(true, $data['online-software']);
            ?>
>
					<label for="itelic-online-software"><?php 
            _e("Enable online software tools for this product", Plugin::SLUG);
            ?>
</label>
					<span class="tip" title="
					<?php 
            _e("Online software tools allows for your customers to remotely activate and deactivate their license keys.", Plugin::SLUG);
            ?>
					<?php 
            _e("Remote activation and remote deactivation needs to be enabled in the add-on settings for this to take effect.", Plugin::SLUG);
            ?>
					">
						i
					</span>
				</p>
			<?php 
        }
        ?>

			<label for="itelic-update-file"><?php 
        _e("Update File", Plugin::SLUG);
        ?>
</label>

			<?php 
        if (empty($downloads)) {
            ?>
				<div class="notice notice-warning below-h2">
					<p><?php 
            _e("You need to upload a new file to the Product Files section and save the product before configuring the Update File.", Plugin::SLUG);
            ?>
</p>
				</div>
			<?php 
        } else {
            ?>
				<select id="itelic-update-file" name="itelic[update-file]">
					<?php 
            foreach ($downloads as $download) {
                ?>
						<option value="<?php 
                echo esc_attr($download['id']);
                ?>
" <?php 
                selected($data['update-file'], $download['id']);
                ?>
>
							<?php 
                echo $download['name'];
                ?>
						</option>
					<?php 
            }
            ?>
				</select>
			<?php 
        }
        ?>

			<p class="description">
				<?php 
        _e("Select a file to be used for automatic updates.", Plugin::SLUG);
        ?>
				<?php 
        _e("You shouldn't need to update this after the initial release.", Plugin::SLUG);
        ?>
			</p>

			<label for="itelic-version">

				<?php 
        if ($version_read) {
            ?>
					<?php 
            _e("Current Version", Plugin::SLUG);
            ?>
				<?php 
        } else {
            ?>
					<?php 
            _e("Initial Version", Plugin::SLUG);
            ?>
				<?php 
        }
        ?>
			</label>
			<input type="text" id="itelic-version" name="itelic[version]" <?php 
        echo $version_read;
        ?>
 value="<?php 
        echo esc_attr($data['version']);
        ?>
">

			<p class="description">
				<?php 
        if (!$version_read) {
            ?>
					<?php 
            _e("Set the initial version of this product.", Plugin::SLUG);
            ?>
&nbsp;
				<?php 
        } else {
            ?>
					<?php 
            printf(__('Create a new release from the <a href="%s">releases</a> tab.', Plugin::SLUG), add_query_arg('view', 'add-new', Dispatch::get_tab_link('releases')));
            ?>
				<?php 
        }
        ?>
			</p>

			<label for="itelic-changelog"><?php 
        _e("Changelog", Plugin::SLUG);
        ?>
</label>
			<button id="view-changelog" class="button"><?php 
        _e("View Changelog", Plugin::SLUG);
        ?>
</button>
			<p class="description"><?php 
        _e("View the compiled changelog from the last 10 releases.", Plugin::SLUG);
        ?>
</p>

			<label for="itelic-key-type"><?php 
        _e("Key Type", Plugin::SLUG);
        ?>
</label>
			<select id="itelic-key-type" name="itelic[key-type]">

				<option value=""><?php 
        _e("Select a Key Type", Plugin::SLUG);
        ?>
</option>

				<?php 
        foreach (itelic_get_key_types() as $slug => $type) {
            ?>
					<option value="<?php 
            echo esc_attr($slug);
            ?>
" <?php 
            selected($data['key-type'], $slug);
            ?>
>
						<?php 
            echo itelic_get_key_type_name($slug);
            ?>
					</option>
				<?php 
        }
        ?>
			</select>

			<p class="description"><?php 
        _e("How should license keys be generated for this product.", Plugin::SLUG);
        ?>
</p>

			<div id="itelic-key-type-settings">
				<?php 
        if (!empty($data['key-type'])) {
            ?>
					<?php 
            $this->get_key_type_settings($data['key-type'], isset($post->ID) ? $post->ID : 0);
            ?>
				<?php 
        }
        ?>
			</div>

			<?php 
        $controller = $this->get_variants_controller($post->ID);
        ?>

			<?php 
        if ($controller) {
            ?>
				<p>
					<input type="checkbox" id="itelic-enable-variant-activations" name="itelic[enabled_variant_activations]"
						<?php 
            checked(true, $data['enabled_variant_activations']);
            ?>
>
					<label for="itelic-enable-variant-activations"><?php 
            _e("Enable Variant Activation limits", Plugin::SLUG);
            ?>
</label>
				</p>
			<?php 
        }
        ?>

			<div class="itelic-activation-limit<?php 
        echo esc_attr($hidden_simple);
        ?>
">
				<label for="itelic-limit"><?php 
        _e("Activation Limit", Plugin::SLUG);
        ?>
</label>
				<input type="number" name="itelic[limit]" id="itelic-limit" min="0" value="<?php 
        echo esc_attr($data['limit']);
        ?>
">
			</div>

			<div class="notice-container <?php 
        echo $data['enabled_variant_activations'] ? '' : 'hide-if-js';
        ?>
">

				<?php 
        if ($controller && !$controller->all_variant_combos_for_product) {
            ?>
					<div class="notice notice-warning below-h2">
						<p><?php 
            _e("You need to create Product Variants and save the product before setting variant activation limits.", Plugin::SLUG);
            ?>
</p>
					</div>
				<?php 
        }
        ?>
			</div>

			<?php 
        if ($controller && $controller->all_variant_combos_for_product) {
            ?>
				<?php 
            $hashes = $data['activation_variant'];
            ?>

				<div class="itelic-variants-activation-limit-table<?php 
            echo esc_attr($hidden_variants);
            ?>
">

					<div class="itelic-activation-limit-variant-header-row">
						<div class="itelic-activation-limit-variant-header-cell"><?php 
            _e("Variant", Plugin::SLUG);
            ?>
</div>
						<div class="itelic-activation-limit-variant-header-cell itelic-activation-limit-variant-input-cell"><?php 
            _e("Limit", Plugin::SLUG);
            ?>
</div>
					</div>

					<?php 
            foreach ($controller->all_variant_combos_for_product as $combo) {
                ?>
						<?php 
                $hash = $this->combo_to_hash($combo);
                ?>
						<div class="itelic-activation-limit-variant-row">

							<div class="itelic-activation-limit-variant-cell"><?php 
                echo $controller->generate_title_from_combos($combo);
                ?>
</div>

							<div class="itelic-activation-limit-variant-cell itelic-activation-limit-variant-input-cell">
								<input class="itelic-activation-limit-variant-input" name="itelic[activation_variant][<?php 
                echo esc_attr($hash);
                ?>
]"
								       type="number" min="0" value="<?php 
                echo isset($hashes[$hash]) ? $hashes[$hash] : '';
                ?>
">
							</div>
						</div>
					<?php 
            }
            ?>
				</div>

			<?php 
        }
        ?>

			<p class="description"><?php 
        _e("How many times can this license be activated. Leave blank for unlimited.", Plugin::SLUG);
        ?>
</p>
		</div>
		<?php 
    }