Esempio n. 1
0
	/**
	 * Respond to the user selecting the authorize action on the plugin page
	 *
	 */
	public function action_plugin_ui_authorize()
	{
		if ( $this->is_auth() ){
			$deauth_url = URL::get( 'admin', array( 'page' => 'plugins', 'configure' => $this->plugin_id(), 'configaction' => 'deauthorize' ) ) . '#plugin_options';
			echo '<p>' . _t( 'You have already successfully authorized Habari to access your Flickr account.') . '</p>';
			echo '<p>' . _t( 'Do you want to ') . '<a href="">' . _t( 'revoke authorization' ) . '</a>?</p>';
		}
		else{
			$flickr = new Flickr();
			$_SESSION['flickr_frob'] = '' . $flickr->getFrob();
			$auth_url = $flickr->authLink( $_SESSION['flickr_frob'] );
			$confirm_url = URL::get( 'admin', array( 'page' => 'plugins', 'configure' => $this->plugin_id(), 'configaction' => 'confirm' ) ) . '#plugin_options';
			echo '<p>' . _t( 'To use this plugin, you must ') . "<a href=\"{$auth_url}\" target=\"_blank\">" . _t( 'authorize Habari to have access to your Flickr account' ) . '</a>.';
			echo '<p>' . _t( 'When you have completed the authorization on Flickr, return here and ') . "<a href=\"$confirm_url\">" . _t( 'confirm that the authorization was successful') . '</a>.';
		}
	}
Esempio n. 2
0
    /**
     * Respond to the user selecting an action on the plugin page
     *
     * @param string $plugin_id The string id of the acted-upon plugin
     * @param string $action The action string supplied via the filter_plugin_config hook
     */
    public function action_plugin_ui($plugin_id, $action)
    {
        if ($plugin_id == $this->plugin_id()) {
            switch ($action) {
                case 'Authorize':
                    if ($this->is_auth()) {
                        $deauth_url = URL::get('admin', array('page' => 'plugins', 'configure' => $this->plugin_id(), 'configaction' => 'De-Authorize')) . '#plugin_options';
                        echo "<p>You have already successfully authorized Habari to access your Flickr account.</p>";
                        echo "<p>Do you want to <a href=\"\">revoke authorization</a>?</p>";
                    } else {
                        $flickr = new Flickr();
                        $_SESSION['flickr_frob'] = '' . $flickr->getFrob();
                        $auth_url = $flickr->authLink($_SESSION['flickr_frob']);
                        $confirm_url = URL::get('admin', array('page' => 'plugins', 'configure' => $this->plugin_id(), 'configaction' => 'confirm')) . '#plugin_options';
                        echo <<<END_AUTH

<p>To use this plugin, you must <a href="{$auth_url}" target="_blank">authorize Habari to have access to your Flickr account</a>.
<p>When you have completed the authorization on Flickr, return here and <a href="{$confirm_url}">confirm that the authorization was successful</a>.

END_AUTH;
                    }
                    break;
                case 'confirm':
                    $flickr = new Flickr();
                    if (!isset($_SESSION['flickr_frob'])) {
                        $auth_url = URL::get('admin', array('page' => 'plugins', 'configure' => $this->plugin_id(), 'configaction' => 'Authorize')) . '#plugin_options';
                        echo '<p>Either you have already authorized Habari to access your flickr account, or you have not yet done so.  Please <a href="' . $auth_url . '">try again</a>.</p>';
                    } else {
                        $token = $flickr->getToken($_SESSION['flickr_frob']);
                        if (isset($token->auth->perms)) {
                            Options::set('flickr_token_' . User::identify()->id, '' . $token->auth->token);
                            echo '<p>Your authorization was set successfully.</p>';
                        } else {
                            echo '<p>There was a problem with your authorization:</p>';
                            echo Utils::htmlspecialchars($token->asXML());
                        }
                        unset($_SESSION['flickr_frob']);
                    }
                    break;
                case 'De-Authorize':
                    Options::set('flickr_token_' . User::identify()->id);
                    $reauth_url = URL::get('admin', array('page' => 'plugins', 'configure' => $this->plugin_id(), 'configaction' => 'Authorize')) . '#plugin_options';
                    echo '<p>The Flickr Silo Plugin authorization has been deleted.<p>';
                    echo "<p>Do you want to <a href=\"{$reauth_url}\">re-authorize this plugin</a>?<p>";
                    break;
                case 'Configure':
                    $ui = new FormUI(strtolower(get_class($this)));
                    $ui->append('select', 'flickr_size', 'option:flickrsilo__flickr_size', _t('Default size for images in Posts:'));
                    $ui->flickr_size->options = array('_s' => 'Square (75x75)', '_t' => 'Thumbnail (100px)', '_m' => 'Small (240px)', '' => 'Medium (500px)', '_b' => 'Large (1024px)', '_o' => 'Original Size');
                    $ui->append('submit', 'save', _t('Save'));
                    $ui->set_option('success_message', _t('Options saved'));
                    $ui->out();
                    break;
            }
        }
    }