Plugin Directory

Changeset 1824219


Ignore:
Timestamp:
02/18/2018 08:47:00 PM (8 years ago)
Author:
helmuthb
Message:

New version 1.1

Location:
stellarpress-federation
Files:
12 added
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • stellarpress-federation/tags/1.1/readme.txt

    r1812167 r1824219  
    55Tags: Stellar Federation Server, Lumens, Cryptocurrency
    66Requires at least: 4.0
    7 Tested up to: 4.9.2
    8 Stable tag: 1.0
     7Tested up to: 4.9.4
     8Stable tag: 1.1
    99Requires PHP: 5.2.4
    1010
  • stellarpress-federation/tags/1.1/stellarpress-federation.php

    r1812167 r1824219  
    44 * Plugin URI: https://stellarpress.org/federation/
    55 * Description: This plugin implements a simple Stellar Federation server within WordPress. Stellar address can be specified in the user profile. <em>This requires a blog hosted via HTTPS and in the root folder of the server!</em>
    6  * Version: 1.0
     6 * Version: 1.1
    77 * Author: StellarPress
    88 * Author URI: https://stellarpress.org
     
    2828
    2929if (!defined('STELLARPRESS_FEDERATION_VERSION')) {
    30   define('STELLARPRESS_FEDERATION_VERSION', '1.0');
     30  define('STELLARPRESS_FEDERATION_VERSION', '1.1');
    3131}
    3232
     33/**
     34 * Class containing all functions for the StellarPress plugin,
     35 * both admin UI and runtime functionality.
     36 *
     37 * @since 1.0.0
     38 */
    3339class StellarPress_Federation {
    3440  /**
    35    * constants for return HTTP status codes
     41   * Constants for return HTTP status codes.
     42   *
     43   * @since 1.0.0
     44   * @var int HTTP_OK        HTTP status for everything OK.
     45   * @var int HTTP_NOTFOUND  HTTP status for item not found.
     46   * @var int HTTP_INVALID   HTTP status for invalid request.
     47   * @var int HTTP_NOTIMPL   HTTP status for not (yet) implemented.
    3648   */
    3749  const HTTP_OK = 200;
     
    4153
    4254  /**
    43    * constants for return messages in Federation server
     55   * Constants for return messages in Federation server.
     56   *
     57   * @since 1.0.0
     58   * @var string CODE_NOTFOUND  Text message for HTTP_NOTFOUND.
     59   * @var string CODE_INVALID   Text message for HTTP_INVALID.
     60   * @var string CODE_NOTIMPL   Text message for HTTP_NOTIMPL.
    4461   */
    4562  const CODE_NOTFOUND = "not_found";
     
    4865
    4966  /**
    50    * Static property to hold the singleton
     67   * Static property to hold the singleton.
     68   *
     69   * @since 1.0.0
     70   * @var StellarPress_Federation $instance  The singleton object.
    5171   */
    5272  static $instance = false;
    5373 
    5474  /**
    55    * Constructor: register all hooks needed
    56    *
     75   * Constructor: register all hooks needed.
     76   *
     77   * @since 1.0.0
    5778   * @return void
    5879   */
     
    6586    add_action('personal_options_update', array($this, 'save_profile'));
    6687    add_action('edit_user_profile_update', array($this, 'save_profile'));
     88    // Add scripts for admin user page
     89    add_action('admin_enqueue_scripts', array($this, 'add_admin_scripts'));
    6790  }
    6891
     
    7194   * create one.
    7295   *
    73    * @return StellarPress_Federation
     96   * @since 1.0.0
     97   * @return StellarPress_Federation  The singleton object.
    7498   */
    7599  public static function getInstance() {
     
    85109   *
    86110   * It is to be called early in the WordPress process, and will
    87    * look for very specific URLs ('/.well-known', '.federation').
    88    *
    89    * 1. Check whether we shall return the 'stellar.toml' file
    90    * More details:
    91    * https://www.stellar.org/developers/guides/concepts/stellar-toml.html
    92    * 2. Check whether we shall answer on Federation requests
    93    * More details:
    94    * https://www.stellar.org/developers/guides/concepts/federation.html
    95    *
     111   * look for very specific URLs (`/.well-known`, `.federation`).
     112   *
     113   * 1. Check whether we shall return the `stellar.toml` file
     114   * 2. Check whether we shall answer on _Federation_ requests
     115   *
     116   * @since 1.0.0
     117   * @link https://stellar.org/developers/guides/concepts/stellar-toml.html
     118   * @link https://stellar.org/developers/guides/concepts/federation.html
    96119   * @return void
    97120   */
     
    115138  /**
    116139   * This helper function delivers the stellar.toml file to the client.
     140   *
     141   * @since 1.0.0
    117142   * @return void
    118143   */
     
    131156   * This helper function delivers the response from the Federation server.
    132157   * It will exit the PHP execution.
     158   *
     159   * @since 1.0.0
    133160   */
    134161  function serve_federation() {
     
    169196   * WordPress site_url.
    170197   *
    171    * @return Boolean true if the domain name is matching the server
     198   * @since 1.0.0
     199   * @return boolean  `true` if the domain name is matching the server.
    172200   */
    173201  function is_domain_ok($domain) {
     
    179207
    180208  /**
    181    * This helper finds a user with a specific name & domain.
    182    *
    183    * @param name the name of the user
    184    * @return String the stellar address, or false if not found
     209   * This helper finds a user with a specific name and domain.
     210   *
     211   * @since 1.0.0
     212   * @param  string $name  The name of the user.
     213   * @return string|false  The stellar address, or `false` if not found.
    185214   */
    186215  function find_user($name) {
     
    212241   * object.
    213242   *
    214    * @param user a user-id string for which the stellar address shall be extracted
     243   * @since 1.0.0
     244   * @param  string $user_id  User-id string for which the stellar address
     245   *                          shall be extracted.
     246   * @return string           The user's Stellar account.
    215247   */
    216248  function get_stellar_address($user_id) {
     
    224256   * This function will exit further execution and set the status code.
    225257   *
    226    * @param code    the HTTP status code to be used
    227    * @param message text message as part of the result
     258   * @since 1.0.0
     259   * @param int    $code     The HTTP status code to be used.
     260   * @param string $message  Text message as part of the result.
    228261   */
    229262  function exit_federation_error($code, $message) {
     
    248281   * It will exit further execution and set the status code.
    249282   *
    250    * @param account the Stellar account from the profile
    251    * @param name    the name part of the Stellar address
    252    * @param domain  the domain part of the Stellar address
    253    * @return void
     283   * @since 1.0.0
     284   * @param string $account  The Stellar account from the profile.
     285   * @param string $name     The name part of the Stellar address.
     286   * @param string $domain   The domain part of the Stellar address.
    254287   */
    255288  function exit_federation_result($account, $name, $domain) {
     
    262295  /**
    263296   * This helper will send the JSON result and exit execution.
     297   *
    264298   * It will also set the required headers for the Federation.
    265299   *
    266    * @param rc   an associative array to be sent as JSON
    267    * @param code the HTTP status code to be used
     300   * @since 1.0.0
     301   * @param array $rc    An associative array to be sent as JSON.
     302   * @param int   $code  The HTTP status code to be used.
    268303   */
    269304  function exit_federation($rc, $code) {
     
    278313   * This function adds a field for the Stellar address of a user
    279314   * to the profile form.
     315   *
    280316   * Based on https://wordpress.stackexchange.com/a/214723
    281    * @param user a WPUser object
     317   *
     318   * @since 1.0.0
     319   * @param WPUser user  A WPUser object.
    282320   * @return void
    283321   */
     
    293331        <td>
    294332          <input type="text" name="stellar_address" id="stellar_address" value="<?php echo esc_attr($stellar_address); ?>" class="regular-text" /><br />
    295           <span class="description"><?php _e("Please enter your Stellar address (your public key, starting with 'G')."); ?></span>
     333          <p class="description"><?php _e("Please enter your Stellar address (your public key, starting with 'G')."); ?></p>
     334          <p class="status" id="stellarpress-check"></p>
    296335        </td>
    297336      </tr>
    298337    </table>
     338    <script>
     339      stellarpressFederation.inform_into("<?php echo esc_attr($user->user_login); ?>", "<?php echo esc_attr($stellar_address); ?>", "stellarpress-check");
     340    </script>
    299341    <?php
    300342  }
     
    303345   * This function adds a field for the Stellar address of a user
    304346   * into the database after being saved by the user.
     347   *
    305348   * Based on https://wordpress.stackexchange.com/a/214723
    306    * @param user_id a WordPress user id
     349   *
     350   * @since 1.0.0
     351   * @param string $user_id  A WordPress user id
    307352   * @return void
    308353   */
     
    313358    update_user_meta($user_id, 'stellar_address', $_POST['stellar_address']);
    314359  }
     360
     361  /**
     362   * This function is used to add JS and CSS files needed for
     363   * the user admin page.
     364   *
     365   * @since 1.1.0
     366   * @param string $hook  Hook name used to identify admin page
     367   * @return void
     368   */
     369  function add_admin_scripts($hook) {
     370    if ($hook === 'profile.php' || $hook === 'user-edit.php') {
     371      wp_enqueue_script('stellarsdk',
     372        'https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/0.8.0/stellar-sdk.js');
     373      wp_enqueue_script('stellarfederation',
     374        plugins_url('js/stellar.js', __FILE__));
     375      wp_enqueue_style('stellarcss',
     376        plugins_url('css/stellar.css', __FILE__));
     377    }
     378  }
    315379}
    316380
  • stellarpress-federation/trunk/readme.txt

    r1812167 r1824219  
    55Tags: Stellar Federation Server, Lumens, Cryptocurrency
    66Requires at least: 4.0
    7 Tested up to: 4.9.2
    8 Stable tag: 1.0
     7Tested up to: 4.9.4
     8Stable tag: 1.1
    99Requires PHP: 5.2.4
    1010
  • stellarpress-federation/trunk/stellarpress-federation.php

    r1812167 r1824219  
    44 * Plugin URI: https://stellarpress.org/federation/
    55 * Description: This plugin implements a simple Stellar Federation server within WordPress. Stellar address can be specified in the user profile. <em>This requires a blog hosted via HTTPS and in the root folder of the server!</em>
    6  * Version: 1.0
     6 * Version: 1.1
    77 * Author: StellarPress
    88 * Author URI: https://stellarpress.org
     
    2828
    2929if (!defined('STELLARPRESS_FEDERATION_VERSION')) {
    30   define('STELLARPRESS_FEDERATION_VERSION', '1.0');
     30  define('STELLARPRESS_FEDERATION_VERSION', '1.1');
    3131}
    3232
     33/**
     34 * Class containing all functions for the StellarPress plugin,
     35 * both admin UI and runtime functionality.
     36 *
     37 * @since 1.0.0
     38 */
    3339class StellarPress_Federation {
    3440  /**
    35    * constants for return HTTP status codes
     41   * Constants for return HTTP status codes.
     42   *
     43   * @since 1.0.0
     44   * @var int HTTP_OK        HTTP status for everything OK.
     45   * @var int HTTP_NOTFOUND  HTTP status for item not found.
     46   * @var int HTTP_INVALID   HTTP status for invalid request.
     47   * @var int HTTP_NOTIMPL   HTTP status for not (yet) implemented.
    3648   */
    3749  const HTTP_OK = 200;
     
    4153
    4254  /**
    43    * constants for return messages in Federation server
     55   * Constants for return messages in Federation server.
     56   *
     57   * @since 1.0.0
     58   * @var string CODE_NOTFOUND  Text message for HTTP_NOTFOUND.
     59   * @var string CODE_INVALID   Text message for HTTP_INVALID.
     60   * @var string CODE_NOTIMPL   Text message for HTTP_NOTIMPL.
    4461   */
    4562  const CODE_NOTFOUND = "not_found";
     
    4865
    4966  /**
    50    * Static property to hold the singleton
     67   * Static property to hold the singleton.
     68   *
     69   * @since 1.0.0
     70   * @var StellarPress_Federation $instance  The singleton object.
    5171   */
    5272  static $instance = false;
    5373 
    5474  /**
    55    * Constructor: register all hooks needed
    56    *
     75   * Constructor: register all hooks needed.
     76   *
     77   * @since 1.0.0
    5778   * @return void
    5879   */
     
    6586    add_action('personal_options_update', array($this, 'save_profile'));
    6687    add_action('edit_user_profile_update', array($this, 'save_profile'));
     88    // Add scripts for admin user page
     89    add_action('admin_enqueue_scripts', array($this, 'add_admin_scripts'));
    6790  }
    6891
     
    7194   * create one.
    7295   *
    73    * @return StellarPress_Federation
     96   * @since 1.0.0
     97   * @return StellarPress_Federation  The singleton object.
    7498   */
    7599  public static function getInstance() {
     
    85109   *
    86110   * It is to be called early in the WordPress process, and will
    87    * look for very specific URLs ('/.well-known', '.federation').
    88    *
    89    * 1. Check whether we shall return the 'stellar.toml' file
    90    * More details:
    91    * https://www.stellar.org/developers/guides/concepts/stellar-toml.html
    92    * 2. Check whether we shall answer on Federation requests
    93    * More details:
    94    * https://www.stellar.org/developers/guides/concepts/federation.html
    95    *
     111   * look for very specific URLs (`/.well-known`, `.federation`).
     112   *
     113   * 1. Check whether we shall return the `stellar.toml` file
     114   * 2. Check whether we shall answer on _Federation_ requests
     115   *
     116   * @since 1.0.0
     117   * @link https://stellar.org/developers/guides/concepts/stellar-toml.html
     118   * @link https://stellar.org/developers/guides/concepts/federation.html
    96119   * @return void
    97120   */
     
    115138  /**
    116139   * This helper function delivers the stellar.toml file to the client.
     140   *
     141   * @since 1.0.0
    117142   * @return void
    118143   */
     
    131156   * This helper function delivers the response from the Federation server.
    132157   * It will exit the PHP execution.
     158   *
     159   * @since 1.0.0
    133160   */
    134161  function serve_federation() {
     
    169196   * WordPress site_url.
    170197   *
    171    * @return Boolean true if the domain name is matching the server
     198   * @since 1.0.0
     199   * @return boolean  `true` if the domain name is matching the server.
    172200   */
    173201  function is_domain_ok($domain) {
     
    179207
    180208  /**
    181    * This helper finds a user with a specific name & domain.
    182    *
    183    * @param name the name of the user
    184    * @return String the stellar address, or false if not found
     209   * This helper finds a user with a specific name and domain.
     210   *
     211   * @since 1.0.0
     212   * @param  string $name  The name of the user.
     213   * @return string|false  The stellar address, or `false` if not found.
    185214   */
    186215  function find_user($name) {
     
    212241   * object.
    213242   *
    214    * @param user a user-id string for which the stellar address shall be extracted
     243   * @since 1.0.0
     244   * @param  string $user_id  User-id string for which the stellar address
     245   *                          shall be extracted.
     246   * @return string           The user's Stellar account.
    215247   */
    216248  function get_stellar_address($user_id) {
     
    224256   * This function will exit further execution and set the status code.
    225257   *
    226    * @param code    the HTTP status code to be used
    227    * @param message text message as part of the result
     258   * @since 1.0.0
     259   * @param int    $code     The HTTP status code to be used.
     260   * @param string $message  Text message as part of the result.
    228261   */
    229262  function exit_federation_error($code, $message) {
     
    248281   * It will exit further execution and set the status code.
    249282   *
    250    * @param account the Stellar account from the profile
    251    * @param name    the name part of the Stellar address
    252    * @param domain  the domain part of the Stellar address
    253    * @return void
     283   * @since 1.0.0
     284   * @param string $account  The Stellar account from the profile.
     285   * @param string $name     The name part of the Stellar address.
     286   * @param string $domain   The domain part of the Stellar address.
    254287   */
    255288  function exit_federation_result($account, $name, $domain) {
     
    262295  /**
    263296   * This helper will send the JSON result and exit execution.
     297   *
    264298   * It will also set the required headers for the Federation.
    265299   *
    266    * @param rc   an associative array to be sent as JSON
    267    * @param code the HTTP status code to be used
     300   * @since 1.0.0
     301   * @param array $rc    An associative array to be sent as JSON.
     302   * @param int   $code  The HTTP status code to be used.
    268303   */
    269304  function exit_federation($rc, $code) {
     
    278313   * This function adds a field for the Stellar address of a user
    279314   * to the profile form.
     315   *
    280316   * Based on https://wordpress.stackexchange.com/a/214723
    281    * @param user a WPUser object
     317   *
     318   * @since 1.0.0
     319   * @param WPUser user  A WPUser object.
    282320   * @return void
    283321   */
     
    293331        <td>
    294332          <input type="text" name="stellar_address" id="stellar_address" value="<?php echo esc_attr($stellar_address); ?>" class="regular-text" /><br />
    295           <span class="description"><?php _e("Please enter your Stellar address (your public key, starting with 'G')."); ?></span>
     333          <p class="description"><?php _e("Please enter your Stellar address (your public key, starting with 'G')."); ?></p>
     334          <p class="status" id="stellarpress-check"></p>
    296335        </td>
    297336      </tr>
    298337    </table>
     338    <script>
     339      stellarpressFederation.inform_into("<?php echo esc_attr($user->user_login); ?>", "<?php echo esc_attr($stellar_address); ?>", "stellarpress-check");
     340    </script>
    299341    <?php
    300342  }
     
    303345   * This function adds a field for the Stellar address of a user
    304346   * into the database after being saved by the user.
     347   *
    305348   * Based on https://wordpress.stackexchange.com/a/214723
    306    * @param user_id a WordPress user id
     349   *
     350   * @since 1.0.0
     351   * @param string $user_id  A WordPress user id
    307352   * @return void
    308353   */
     
    313358    update_user_meta($user_id, 'stellar_address', $_POST['stellar_address']);
    314359  }
     360
     361  /**
     362   * This function is used to add JS and CSS files needed for
     363   * the user admin page.
     364   *
     365   * @since 1.1.0
     366   * @param string $hook  Hook name used to identify admin page
     367   * @return void
     368   */
     369  function add_admin_scripts($hook) {
     370    if ($hook === 'profile.php' || $hook === 'user-edit.php') {
     371      wp_enqueue_script('stellarsdk',
     372        'https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/0.8.0/stellar-sdk.js');
     373      wp_enqueue_script('stellarfederation',
     374        plugins_url('js/stellar.js', __FILE__));
     375      wp_enqueue_style('stellarcss',
     376        plugins_url('css/stellar.css', __FILE__));
     377    }
     378  }
    315379}
    316380
Note: See TracChangeset for help on using the changeset viewer.