Example #1
0
 /**
  * Deferred item download URL.
  *
  * @since 1.0.0
  *
  * @param int $id The item ID.
  * @return string.
  */
 public function deferred_download($id)
 {
     if (empty($id)) {
         return '';
     }
     $args = array('deferred_download' => true, 'item_id' => $id);
     return add_query_arg($args, esc_url(envato_market()->get_page_url()));
 }
Example #2
0
/**
 * Interate over the plugins array and displays each plugin.
 *
 * @since 1.0.0
 *
 * @param string $group The plugin group. Options are 'purchased', 'active', 'installed', or 'install'.
 */
function envato_market_plugins_column($group = 'install')
{
    $premium = envato_market()->items()->plugins($group);
    if (empty($premium)) {
        return;
    }
    $plugins = envato_market()->items()->wp_plugins();
    foreach ($premium as $slug => $plugin) {
        $name = $plugin['name'];
        $author = $plugin['author'];
        $version = $plugin['version'];
        $description = $plugin['description'];
        $url = $plugin['url'];
        $author_url = $plugin['author_url'];
        $plugin['hasUpdate'] = false;
        // Setup the column CSS classes.
        $classes = array('envato-card', 'plugin');
        if ('active' === $group) {
            $classes[] = 'active';
        }
        // Setup the update action links.
        $updateActions = array();
        // Check for an update.
        if (isset($plugins[$slug]) && version_compare($plugins[$slug]['Version'], $plugin['version'], '<')) {
            $plugin['hasUpdate'] = true;
            $classes[] = 'update';
            $classes[] = 'envato-card-' . sanitize_key(dirname($slug));
            if (current_user_can('update_plugins')) {
                // Upgrade link.
                $upgrade_link = add_query_arg(array('action' => 'upgrade-plugin', 'plugin' => $slug), self_admin_url('update.php'));
                // Details link.
                $details_link = add_query_arg(array('action' => 'upgrade-plugin', 'tab' => 'plugin-information', 'plugin' => dirname($slug), 'section' => 'changelog', 'TB_iframe' => 'true', 'width' => 640, 'height' => 662), self_admin_url('plugin-install.php'));
                $updateActions['update'] = sprintf('<a class="update-now" href="%1$s" aria-label="%2$s" data-name="%3$s %6$s" data-plugin="%4$s" data-slug="%5$s" data-version="%6$s">%7$s</a>', wp_nonce_url($upgrade_link, 'upgrade-plugin_' . $slug), esc_attr__('Update %s now', 'envato-market'), esc_attr($name), esc_attr($slug), sanitize_key(dirname($slug)), esc_attr($version), esc_html__('Update Available', 'envato-market'));
                $updateActions['details'] = sprintf('<a href="%1$s" class="thickbox details" title="%2$s">%3$s</a>', esc_url($details_link), esc_attr($name), sprintf(__('View version %1$s details.', 'envato-market'), $version));
            }
        }
        // Setup the action links.
        $actions = array();
        if ('active' === $group) {
            // Deactivate link.
            $deactivate_link = add_query_arg(array('action' => 'deactivate', 'plugin' => $slug), self_admin_url('plugins.php'));
            $actions['deactivate'] = '
			<a href="' . wp_nonce_url($deactivate_link, 'deactivate-plugin_' . $slug) . '" class="button">
				<span aria-hidden="true">' . __('Deactivate', 'envato-market') . '</span>
				<span class="screen-reader-text">' . sprintf(__('Deactivate %s', 'envato-market'), $name) . '</span>
			</a>';
        } elseif ('installed' === $group) {
            if (!is_multisite() && current_user_can('delete_plugins')) {
                // Delete link.
                $delete_link = add_query_arg(array('action' => 'delete-selected', 'checked[]' => $slug), self_admin_url('plugins.php'));
                $actions['delete'] = '
				<a href="' . wp_nonce_url($delete_link, 'bulk-plugins') . '" class="button-delete">
					<span aria-hidden="true">' . __('Delete', 'envato-market') . '</span>
					<span class="screen-reader-text">' . sprintf(__('Delete %s', 'envato-market'), $name) . '</span>
				</a>';
            }
            if (!is_multisite() && current_user_can('activate_plugins')) {
                // Activate link.
                $activate_link = add_query_arg(array('action' => 'activate', 'plugin' => $slug), self_admin_url('plugins.php'));
                $actions['activate'] = '
				<a href="' . wp_nonce_url($activate_link, 'activate-plugin_' . $slug) . '" class="button">
					<span aria-hidden="true">' . __('Activate', 'envato-market') . '</span>
					<span class="screen-reader-text">' . sprintf(__('Activate %s', 'envato-market'), $name) . '</span>
				</a>';
            }
            // @codeCoverageIgnoreStart
            // Multisite needs special attention.
            if (is_multisite()) {
                if (current_user_can('manage_sites')) {
                    $actions['site_activate'] = '
					<a href="' . esc_url(admin_url(wp_nonce_url('plugins.php?action=activate&amp;plugin=' . urlencode($slug), 'activate-plugin_' . $slug))) . '" class="button">
						<span aria-hidden="true">' . __('Site Activate', 'envato-market') . '</span>
						<span class="screen-reader-text">' . sprintf(__('Site Activate %s', 'envato-market'), $name) . '</span>
					</a>';
                }
                if (current_user_can('manage_network_plugins')) {
                    $actions['network_activate'] = '
					<a href="' . esc_url(network_admin_url(wp_nonce_url('plugins.php?action=activate&amp;plugin=' . urlencode($slug), 'activate-plugin_' . $slug))) . '" class="button">
						<span aria-hidden="true">' . __('Network Activate', 'envato-market') . '</span>
						<span class="screen-reader-text">' . sprintf(__('Network Activate %s', 'envato-market'), $name) . '</span>
					</a>';
                }
            }
            // @codeCoverageIgnoreEnd
        } elseif ('install' === $group && current_user_can('install_plugins')) {
            // Install link.
            $install_link = add_query_arg(array('page' => envato_market()->get_slug(), 'action' => 'install-plugin', 'id' => $plugin['id']), self_admin_url('admin.php'));
            $actions['install'] = '
			<a href="' . wp_nonce_url($install_link, 'install-plugin_' . $plugin['id']) . '" class="button button-primary">
				<span aria-hidden="true">' . __('Install', 'envato-market') . '</span>
				<span class="screen-reader-text">' . sprintf(__('Install %s', 'envato-market'), $name) . '</span>
			</a>';
        }
        if (0 === strrpos(html_entity_decode($author), '<a ')) {
            $author_link = $author;
        } else {
            $author_link = '<a href="' . esc_url($author_url) . '">' . esc_html($author) . '</a>';
        }
        ?>
		<div class="col" data-id="<?php 
        echo esc_attr($plugin['id']);
        ?>
">
			<div class="<?php 
        echo esc_attr(implode(' ', $classes));
        ?>
">
				<div class="envato-card-top">
					<a href="<?php 
        echo esc_url($url);
        ?>
" class="column-icon">
						<img src="<?php 
        echo esc_url($plugin['thumbnail_url']);
        ?>
"/>
					</a>
					<div class="column-name">
						<h4>
							<a href="<?php 
        echo esc_url($url);
        ?>
"><?php 
        echo esc_html($name);
        ?>
</a>
							<span class="version" aria-label="<?php 
        esc_attr_e('Version %s', 'envato-market');
        ?>
"><?php 
        echo esc_html(sprintf(__('Version %s', 'envato-market'), isset($plugins[$slug]) ? $plugins[$slug]['Version'] : $version));
        ?>
</span>
						</h4>
					</div>
					<div class="column-description">
						<div class="description">
							<?php 
        echo wp_kses_post(wpautop($description));
        ?>
						</div>
						<p class="author">
							<cite><?php 
        esc_html_e('By', 'envato-market');
        ?>
 <?php 
        echo wp_kses_post($author_link);
        ?>
</cite>
						</p>
					</div>
					<?php 
        if (!empty($updateActions)) {
            ?>
					<div class="column-update">
						<?php 
            echo implode("\n", $updateActions);
            ?>
					</div>
					<?php 
        }
        ?>
				</div>
				<div class="envato-card-bottom">
					<div class="column-rating">
						<?php 
        wp_star_rating(array('rating' => $plugin['rating']['rating'] / 5 * 100, 'type' => 'percent', 'number' => $plugin['rating']['count']));
        ?>
						<span class="num-ratings">(<?php 
        echo esc_html(number_format_i18n($plugin['rating']['count']));
        ?>
)</span>
					</div>
					<div class="column-actions">
						<?php 
        echo implode("\n", $actions);
        ?>
					</div>
				</div>
			</div>
		</div>
	<?php 
    }
}
 /**
  * Modify the install actions.
  *
  * @since 1.0.0
  */
 public function after()
 {
     $plugin_file = $this->upgrader->plugin_info();
     $install_actions = array();
     if (!current_user_can('activate_plugins')) {
         $install_actions['activate_plugin'] = '<a href="' . esc_url(wp_nonce_url('plugins.php?action=activate&amp;plugin=' . urlencode($plugin_file), 'activate-plugin_' . $plugin_file)) . '" target="_parent">' . __('Activate Plugin', 'envato-market') . '</a>';
     }
     if (is_multisite()) {
         unset($install_actions['activate_plugin']);
         if (current_user_can('manage_sites')) {
             $install_actions['site_activate'] = '<a href="' . esc_url(admin_url(wp_nonce_url('plugins.php?action=activate&amp;plugin=' . urlencode($plugin_file), 'activate-plugin_' . $plugin_file))) . '" target="_parent">' . __('Site Activate', 'envato-market') . '</a>';
         }
         if (current_user_can('manage_network_plugins')) {
             $install_actions['network_activate'] = '<a href="' . esc_url(network_admin_url(wp_nonce_url('plugins.php?action=activate&amp;plugin=' . urlencode($plugin_file), 'activate-plugin_' . $plugin_file))) . '" target="_parent">' . __('Network Activate', 'envato-market') . '</a>';
         }
     }
     $install_actions['plugins_page'] = '<a href="' . esc_url(admin_url('admin.php?page=' . envato_market()->get_slug() . '&tab=plugins')) . '" target="_parent">' . __('Return to Plugin Installer', 'envato-market') . '</a>';
     if (!$this->result || is_wp_error($this->result)) {
         unset($install_actions['activate_plugin'], $install_actions['site_activate'], $install_actions['network_activate']);
     }
     if (!empty($install_actions)) {
         $this->feedback(implode(' | ', $install_actions));
     }
 }
Example #4
0
?>
<ul id="envato-market-items">
<?php 
if (!empty($items)) {
    foreach ($items as $key => $item) {
        if (empty($item['name']) || empty($item['token']) || empty($item['id']) || empty($item['type']) || empty($item['authorized'])) {
            continue;
        }
        $class = 'success' === $item['authorized'] ? 'is-authorized' : 'not-authorized';
        echo '
		<li data-id="' . esc_attr($item['id']) . '" class="' . esc_attr($class) . '">
			<span class="item-name">' . esc_html__('ID', 'envato-market') . ': ' . esc_html($item['id']) . ' - ' . esc_html($item['name']) . '</span>
			<button class="item-delete dashicons dashicons-dismiss">
				<span class="screen-reader-text">' . esc_html__('Delete', 'envato-market') . '</span>
			</button>
			<input type="hidden" name="' . esc_attr(envato_market()->get_option_name()) . '[items][' . esc_attr($key) . '][name]" value="' . esc_html($item['name']) . '" />
			<input type="hidden" name="' . esc_attr(envato_market()->get_option_name()) . '[items][' . esc_attr($key) . '][token]" value="' . esc_html($item['token']) . '" />
			<input type="hidden" name="' . esc_attr(envato_market()->get_option_name()) . '[items][' . esc_attr($key) . '][id]" value="' . esc_html($item['id']) . '" />
			<input type="hidden" name="' . esc_attr(envato_market()->get_option_name()) . '[items][' . esc_attr($key) . '][type]" value="' . esc_html($item['type']) . '" />
			<input type="hidden" name="' . esc_attr(envato_market()->get_option_name()) . '[items][' . esc_attr($key) . '][authorized]" value="' . esc_html($item['authorized']) . '" />
		</li>';
    }
}
?>
</ul>

<button class="button add-envato-market-item"><?php 
esc_html_e('Add Item', 'envato-market');
?>
</button>
Example #5
0
 /**
  * Update check.
  *
  * @since 1.0.0
  *
  * @param object $transient The pre-saved value of the `update_plugins` site transient.
  * @return object
  */
 public function update_plugins($transient)
 {
     $state = $this->state();
     if ('activated' === $state) {
         $api_check = $this->api_check();
         if (is_object($api_check) && version_compare(envato_market()->get_version(), $api_check->version, '<')) {
             $transient->response['envato-market/envato-market.php'] = (object) array('slug' => 'envato-market', 'plugin' => 'envato-market/envato-market.php', 'new_version' => $api_check->version, 'url' => 'https://github.com/envato/wp-envato-market', 'package' => $api_check->download_link);
         }
     }
     return $transient;
 }
Example #6
0
 /**
  * Error single-use notice.
  *
  * @since 1.0.0
  */
 public function render_error_single_use_notice()
 {
     require envato_market()->get_plugin_path() . 'inc/admin/view/notice/error-single-use.php';
 }
Example #7
0
<?php

/**
 * Plugins panel partial
 *
 * @package Envato_Market
 * @since 1.0.0
 */
$plugins = envato_market()->items()->plugins('purchased');
?>
<div id="plugins" class="two-col panel <?php 
echo empty($plugins) ? 'hidden' : '';
?>
">
	<?php 
if (!empty($plugins)) {
    envato_market_plugins_column('active');
    envato_market_plugins_column('installed');
    envato_market_plugins_column('install');
}
?>
</div>
Example #8
0
<?php

/**
 * Intro partial
 *
 * @package Envato_Market
 * @since 1.0.0
 */
?>
<div class="two-col">
	<div class="col">
		<h1 class="about-title"><strong><?php 
esc_html_e('Envato Market', 'envato-market');
?>
</strong> <sup><?php 
echo esc_html(envato_market()->get_version());
?>
</sup></h1>
		<p><?php 
esc_html_e('Welcome!', 'envato-market');
?>
</p>
		<p><?php 
esc_html_e('This plugin can install WordPress themes and plugins purchased from ThemeForest & CodeCanyon by connecting with the Envato Market API using a secure OAuth personal token. Once your themes & plugins are installed WordPress will periodically check for updates, so keeping your items up to date is as simple as a few clicks.', 'envato-market');
?>
</p>
		<p><?php 
esc_html_e('You can add a global token to connect all your items from your account, and/or connect directly with a specific item using a singe-use token & item ID. When the global token and single-use token are set for the same item, the single-use token will be used to communicate with the API.', 'envato-market');
?>
</p>
		<p><strong><?php 
Example #9
0
 /**
  * Render Intro partial
  */
 function test_render_intro_partial()
 {
     ob_start();
     $this->admin->render_intro_partial();
     $contents = ob_get_clean();
     $this->assertContains('<h1 class="about-title"><strong>Envato Market</strong> <sup>' . envato_market()->get_version() . '</sup></h1>', $contents);
 }
Example #10
0
 /**
  * @see Envato_Market_Items::rebuild_plugins()
  */
 function test_rebuild_plugins()
 {
     $plugins = array('purchased' => array(array('id' => 12345, 'name' => 'Envato Market', 'author' => 'Derek Herman', 'version' => '10.0.0', 'description' => '', 'url' => 'http://sample.org/custom/', 'author_url' => 'http://sample.org/', 'thumbnail_url' => 'http://sample.org/thumb.png', 'landscape_url' => 'http://sample.org/landscape.png', 'requires' => '4.2', 'tested' => '4.4', 'number_of_sales' => 25000, 'updated_at' => '', 'rating' => array('rating' => 4.79, 'count' => 4457))), 'active' => array(), 'installed' => array('envato-market/envato-market.php' => array('id' => 12345, 'name' => 'Envato Market', 'author' => 'Derek Herman', 'version' => '10.0.0', 'description' => '', 'url' => 'http://sample.org/custom/', 'author_url' => 'http://sample.org/', 'thumbnail_url' => 'http://sample.org/thumb.png', 'landscape_url' => 'http://sample.org/landscape.png', 'requires' => '4.2', 'tested' => '4.4', 'number_of_sales' => 25000, 'updated_at' => '', 'rating' => array('rating' => 4.79, 'count' => 4457))), 'install' => array());
     $expected = array('purchased' => array(array('id' => 12345, 'name' => 'Envato Market', 'author' => 'Derek Herman', 'version' => '10.0.0', 'description' => '', 'url' => 'http://sample.org/custom/', 'author_url' => 'http://sample.org/', 'thumbnail_url' => 'http://sample.org/thumb.png', 'landscape_url' => 'http://sample.org/landscape.png', 'requires' => '4.2', 'tested' => '4.4', 'number_of_sales' => 25000, 'updated_at' => '', 'rating' => array('rating' => 4.79, 'count' => 4457))), 'active' => array('envato-market/envato-market.php' => array('id' => 12345, 'name' => 'Envato Market', 'author' => 'Derek Herman', 'version' => '10.0.0', 'description' => '', 'url' => 'http://sample.org/custom/', 'author_url' => 'http://sample.org/', 'thumbnail_url' => 'http://sample.org/thumb.png', 'landscape_url' => 'http://sample.org/landscape.png', 'requires' => '4.2', 'tested' => '4.4', 'number_of_sales' => 25000, 'updated_at' => '', 'rating' => array('rating' => 4.79, 'count' => 4457))), 'installed' => array(), 'install' => array());
     set_site_transient(envato_market()->get_option_name() . '_plugins', $plugins);
     $ref = new ReflectionProperty('Envato_Market_Items', 'plugins');
     $ref->setAccessible(true);
     $ref->setValue(null, $plugins);
     $this->assertEquals($plugins, $this->items->plugins());
     $this->items->rebuild_plugins('envato-market/envato-market.php');
     $this->assertEquals($expected, $this->items->plugins());
     global $wp_current_filter;
     $wp_current_filter[] = 'deactivated_plugin';
     $this->items->rebuild_plugins('envato-market/envato-market.php');
     $this->assertEquals($plugins, $this->items->plugins());
     $ref = new ReflectionProperty('Envato_Market_Items', 'plugins');
     $ref->setAccessible(true);
     $ref->setValue(null, array());
 }
Example #11
0
<?php

/**
 * Token setting
 *
 * @package Envato_Market
 * @since 1.0.0
 */
?>
<input type="text" name="<?php 
echo esc_attr(envato_market()->get_option_name());
?>
[token]" class="widefat" value="<?php 
echo esc_html(envato_market()->get_option('token'));
?>
" autocomplete="off">

<p class="description"><?php 
esc_html_e('Enter your Envato API Personal Token.', 'envato-market');
?>
</p>
Example #12
0
<?php

/**
 * Themes panel partial
 *
 * @package Envato_Market
 * @since 1.0.0
 */
$themes = envato_market()->items()->themes('purchased');
?>
<div id="themes" class="two-col panel <?php 
echo empty($themes) ? 'hidden' : '';
?>
">
	<?php 
if (!empty($themes)) {
    envato_market_themes_column('active');
    envato_market_themes_column('installed');
    envato_market_themes_column('install');
}
?>
</div>
Example #13
0
 /**
  * Set up a test case.
  *
  * @see WP_UnitTestCase::setup()
  */
 function setUp()
 {
     parent::setUp();
     wp_set_current_user($this->factory->user->create(array('role' => 'administrator')));
     $this->api = envato_market()->api();
 }
Example #14
0
 /**
  * Process the plugins and save the transient.
  *
  * @since 1.0.0
  *
  * @param array $purchased The purchased plugins array.
  * @param array $args Used to remove or add a plugin during activate and deactivate routines.
  */
 private function process_plugins($purchased, $args = array())
 {
     if (is_wp_error($purchased)) {
         $purchased = array();
     }
     $active = array();
     $installed = array();
     $install = $purchased;
     if (!empty($purchased)) {
         foreach (self::wp_plugins(true) as $slug => $plugin) {
             foreach ($install as $key => $value) {
                 if ($this->normalize($value['name']) === $this->normalize($plugin['Name']) && $this->normalize($value['author']) === $this->normalize($plugin['Author']) && file_exists(WP_PLUGIN_DIR . '/' . $slug)) {
                     $installed[$slug] = $value;
                     unset($install[$key]);
                 }
             }
         }
     }
     foreach ($installed as $slug => $plugin) {
         $condition = false;
         if (!empty($args) && $slug === $args['plugin']) {
             if (true === $args['remove']) {
                 continue;
             }
             $condition = true;
         }
         if ($condition || is_plugin_active($slug)) {
             $active[$slug] = $plugin;
             unset($installed[$slug]);
         }
     }
     self::$plugins['purchased'] = array_unique($purchased, SORT_REGULAR);
     self::$plugins['active'] = array_unique($active, SORT_REGULAR);
     self::$plugins['installed'] = array_unique($installed, SORT_REGULAR);
     self::$plugins['install'] = array_unique(array_values($install), SORT_REGULAR);
     set_site_transient(envato_market()->get_option_name() . '_plugins', self::$plugins, HOUR_IN_SECONDS);
 }
Example #15
0
$token = envato_market()->get_option('token');
$items = envato_market()->get_option('items', array());
?>
<div id="settings" class="two-col panel">
	<?php 
settings_fields(envato_market()->get_slug());
?>
	<?php 
Envato_Market_Admin::do_settings_sections(envato_market()->get_slug(), 2);
?>
	<p class="submit">
		<input type="submit" name="submit" id="submit" class="button button-primary" value="<?php 
esc_html_e('Save Changes', 'envato-market');
?>
" />
		<?php 
if (('' !== $token || !empty($items)) && 10 !== has_action('admin_notices', array($this, 'error_notice'))) {
    ?>
			<a href="<?php 
    echo esc_url(add_query_arg(array('authorization' => 'check'), envato_market()->get_page_url()));
    ?>
" class="button button-secondary auth-check-button" style="margin:0 5px"><?php 
    esc_html_e('Test API Connection', 'envato-market');
    ?>
</a>
		<?php 
}
?>
	</p>
</div>
    public function render_oauth_login_fields_callback()
    {
        $option = envato_market()->get_options();
        print_r($option);
        ?>
		<div class="oauth-login" data-username="******">
			<a href="<?php 
        echo esc_url($this->get_oauth_login_url(admin_url('admin.php?page=' . envato_market()->get_slug() . '#settings')));
        ?>
"
			   class="oauth-login-button button">Login with Envato</a>
		</div>
		<?php 
    }
 /**
  * Check for admin class.
  */
 function test_envato_market_admin()
 {
     $this->assertInstanceOf('Envato_Market_Admin', envato_market()->admin());
 }