Exemple #1
0
 function get_service()
 {
     if (!$this->service) {
         $class = $this->get_meta('_classname', true);
         if ($class && class_exists($class)) {
             $this->service = call_user_func(array($class, 'init'));
         } else {
             $this->service = Keyring::get_service_by_name($this->get_name());
         }
     }
     return $this->service;
 }
    /**
     * The first screen the user sees in the import process. Summarizes the process and allows
     * them to either select an existing Keyring token or start the process of creating a new one.
     * Also makes sure they have the correct service available, and that it's configured correctly.
     */
    function greet()
    {
        if (method_exists($this, 'full_custom_greet')) {
            $this->full_custom_greet();
            return;
        }
        $this->header();
        // If this service is not configured, then we can't continue
        if (!($service = Keyring::get_service_by_name(static::SLUG))) {
            ?>
			<p class="error"><?php 
            echo esc_html(sprintf(__("It looks like you don't have the %s service for Keyring installed.", 'keyring'), static::LABEL));
            ?>
</p>
			<?php 
            $this->footer();
            return;
            ?>
		<?php 
        } elseif (!$service->is_configured()) {
            ?>
			<p class="error"><?php 
            echo esc_html(sprintf(__("Before you can use this importer, you need to configure the %s service within Keyring.", 'keyring'), static::LABEL));
            ?>
</p>
			<?php 
            if (current_user_can('read') && !KEYRING__HEADLESS_MODE && has_action('keyring_' . static::SLUG . '_manage_ui')) {
                $manage_kr_nonce = wp_create_nonce('keyring-manage');
                $manage_nonce = wp_create_nonce('keyring-manage-' . static::SLUG);
                echo '<p><a href="' . esc_url(Keyring_Util::admin_url(static::SLUG, array('action' => 'manage', 'kr_nonce' => $manage_kr_nonce, 'nonce' => $manage_nonce))) . '" class="button-primary">' . sprintf(__('Configure %s Service', 'keyring'), static::LABEL) . '</a></p>';
            }
            $this->footer();
            return;
            ?>
		<?php 
        }
        ?>
		<div class="narrow">
			<form action="admin.php?import=<?php 
        echo static::SLUG;
        ?>
&amp;step=greet" method="post">
				<p><?php 
        printf(__("Howdy! This importer requires you to connect to %s before you can continue.", 'keyring'), static::LABEL);
        ?>
</p>
				<?php 
        do_action('keyring_importer_' . static::SLUG . '_greet');
        ?>
				<?php 
        if ($service->is_connected()) {
            ?>
					<p><?php 
            echo sprintf(esc_html(__('It looks like you\'re already connected to %1$s via %2$s. You may use an existing connection, or create a new one:', 'keyring')), static::LABEL, '<a href="' . esc_attr(Keyring_Util::admin_url()) . '">Keyring</a>');
            ?>
</p>
					<?php 
            $service->token_select_box(static::SLUG . '_token', true);
            ?>
					<input type="submit" name="connect_existing" value="<?php 
            echo esc_attr(__('Continue&hellip;', 'keyring'));
            ?>
" id="connect_existing" class="button-primary" />
				<?php 
        } else {
            ?>
					<p><?php 
            echo esc_html(sprintf(__("To get started, we'll need to connect to your %s account so that we can access your content.", 'keyring'), static::LABEL));
            ?>
</p>
					<input type="submit" name="create_new" value="<?php 
            echo esc_attr(sprintf(__('Connect to %s&#0133;', 'keyring'), static::LABEL));
            ?>
" id="create_new" class="button-primary" />
				<?php 
        }
        ?>
			</form>
		</div>
		<?php 
        $this->footer();
    }