Plugin Directory

Changeset 1027192


Ignore:
Timestamp:
11/17/2014 10:35:33 AM (11 years ago)
Author:
thirdlight
Message:

Updated for WP 4.0. Detect insufficient PHP at activation time, support login using user name or email address from wordpress, and detect needed site features on being provided API key

Location:
third-light-browser/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • third-light-browser/trunk/includes/settings.php

    r905592 r1027192  
    121121        <div class="wrap">
    122122            <?php screen_icon(); ?>
    123             <h2>My Settings</h2> 
     123            <h2>Third Light Browser Settings</h2>
    124124
    125125            <form method="post" action="options.php">
     
    151151        );
    152152
    153         $general_settings = "general_settings";
     153        $general_settings = "site_settings";
    154154        add_settings_section(
    155155            $general_settings, // ID
    156             __('General Settings'), // Title
    157             function(){ _e('General settings for the Third Light Browser:'); },
     156            __('Site Settings'), // Title
     157            function(){ _e('Settings to configure the Third Light Browser to work with a Third Light IMS site.'); },
    158158            'my-setting-admin' // Page
    159159        ); 
     
    166166            'my-setting-admin', // Page
    167167            $general_settings // Section           
    168         );     
     168        );
     169
     170        $apikey = "apikey";
     171        add_settings_field(
     172            $apikey, // ID
     173            __('Third Light API Key'), // Title
     174            $this->input_apikey_field(array(self::NAME, "global_options", $apikey)), // Callback
     175            'my-setting-admin', // Page
     176            $general_settings // Section
     177        );
    169178
    170179        $autoLogin = "automaticLogin";
     
    178187        );
    179188
     189        $display_settings = "display_settings";
     190            add_settings_section(
     191            $display_settings, // ID
     192                __('Display Settings'), // Title
     193                function(){ _e('Settings to configure the appearance of the Third Light Browser.'); },
     194                'my-setting-admin' // Page
     195            );
     196
    180197        $theme = "theme";
    181198        add_settings_field(
     
    187204            )),
    188205            'my-setting-admin',
    189             $general_settings
     206            $display_settings
    190207        );   
    191208
     
    199216            )),
    200217            'my-setting-admin',
    201             $general_settings
     218            $display_settings
    202219        );
    203220
     
    211228            )),
    212229            'my-setting-admin',
    213             $general_settings
     230            $display_settings
    214231        );
    215232
     
    279296            }
    280297
     298            $keyValid = false;
    281299            //if there is an apikey, is it valid. If so, set the sessionId from it. Else, complain and set sessionId to false.
    282             if($global_options["automaticLogin"] !== "disabled" && !empty($global_options["apikey"]))
    283             {
    284                 try{
    285                     $imsAPI = new IMSApiClient($global_options["site"], $global_options["apikey"]);
    286                     $keyValid = true;
     300            if(!empty($global_options["apikey"]))
     301            {
     302                try{
     303                    $imsAPI = new IMSApiClient($global_options["site"], $global_options["apikey"]);
     304                    $keyValid = true;
     305                    $globalSFFConfig = $imsAPI->Config_CheckFeatureAvailable(array("featureKey"=> "SECURE_FILE_FETCH_PERMANENT"));
     306                    if(!$globalSFFConfig)
     307                    {
     308                        add_settings_error(self::NAME, null, __('The Third Light site does not have permanent Secure File Fetch enabled - this is required by the Third Light Browser.'));
     309                    }
     310                    $globalRevConfig = $imsAPI->Config_CheckFeatureAvailable(array("featureKey"=> "REVISIONS"));
     311                    if(!$globalRevConfig && !empty($global_options["showRevisions"]))
     312                    {
     313                        add_settings_error(self::NAME, null, __('Version control is disabled on the Third Light site.'));
     314                    }
    287315                }
    288316                catch(IMSApiActionException $e) {
     
    295323                    add_settings_error(self::NAME, null, __('The API key could not be validated.'));
    296324                }
    297                 if(!$keyValid){
    298                     add_settings_error(self::NAME, null, __('Automatic log in requires that the API key be configured correctly.'));
    299                     $global_options["automaticLogin"] = "disabled";
    300                 }
    301             }
    302             else
    303             {
    304                 $global_options["automaticLogin"] = "disabled";
     325            }
     326
     327
     328            if($global_options["automaticLogin"] !== "disabled")
     329            {
     330                if(!$keyValid) {
     331                    add_settings_error("automaticLogin", null, __('Automatic log in requires that the API key be configured correctly.'));
     332                    $global_options["automaticLogin"] = "disabled";
     333                }
    305334            }
    306335
     
    313342
    314343            //if we try to autologin and don't provide a userref, turn autologin off:
    315             if(!$global_options["userRef"])
    316             {
     344            if(($global_options["automaticLogin"] === "username") && !$global_options["userRef"])
     345            {
     346                add_settings_error(self::NAME, null, __('Username for automatic login was not supplied.'));
    317347                $global_options["automaticLogin"] = "disabled";
    318348            }
     
    428458    }
    429459
     460
     461    public function input_apikey_field($fieldName){
     462        return function() use ($fieldName){
     463            if(!function_exists("curl_init")) {
     464                echo "<p>"._("Third Light API integration requires the cURL PHP extension, but it is not installed")."</p>";
     465                return;
     466            }
     467
     468            echo "<p><small>"._('An optional API key for your Third Light IMS site. Supplying this enables additional authentication and metadata options.')."</small></p>";
     469            call_user_func($this->input_field_factory($fieldName, "thirdlight-apikey-field"));
     470        };
     471    }
     472
     473
    430474    public function input_autologin_field($fieldName){
    431475        return function() use ($fieldName){
     476            if(!function_exists("curl_init")) {
     477                echo "<p>"._("Automatic login requires the cURL PHP extension, but it is not installed")."</p>";
     478                return;
     479            }
    432480
    433481            //generate a standard input field:
    434482            call_user_func($this->input_dropdown_factory(array(self::NAME, "global_options", $fieldName), array(
    435                 "username" => __("Username"),
    436                 "email" => __("Email Address"),
    437                 "disabled" => __("No Automatic Login")
     483                "username" => __("A specific username"),
     484                "email" => __("A specific e-mail address"),
     485                "username_dynamic" => __("The username from WordPress"),
     486                "email_dynamic" => __("The e-mail address from WordPress"),
     487                "disabled" => __("No automatic login")
    438488            ), "thirdlight-automaticlogin-field"));
     489
     490
    439491
    440492            echo '<div class="thirdlight-automaticlogin-options">';
     
    443495                echo '<p class="thirdlight-userref-desc"></p>';
    444496                call_user_func($this->input_field_factory(array(self::NAME, "global_options", "userRef"), "thirdlight-userref-field"));
    445 
    446                 //apikey:
    447                 echo "<p>"._("An API key is required for automatic login:")."</p>";
    448                 call_user_func($this->input_field_factory(array(self::NAME, "global_options", "apikey"), "thirdlight-apikey-field"));
    449497
    450498            echo '</div>';
     
    464512                    switch(this.value) {
    465513                    case "disabled":
     514                    case "username_dynamic":
     515                    case "email_dynamic":
    466516                        $autoLoginOptions.hide();
    467517                    break;
  • third-light-browser/trunk/js/IMS.IframeApp.js

    r905592 r1027192  
    9999        if(typeof data != "object") return;
    100100        if(typeof data.action != "string") return;
    101         if(data == null) return;
     101        if(data === null) return;
    102102
    103103        //data is OK, let's use it:
  • third-light-browser/trunk/js/IMS.IframeAppOverlay.js

    r905592 r1027192  
    3434    }
    3535
    36     // I attach events to elements and return a func which detatches:
    37     function addEvent(el, evt, func){
    38         if(el.addEventListener) {
    39             el.addEventListener(evt, func, false);
    40             return function(){ el.removeEventListener(evt, func); }
    41         }
    42         else if(el.attachEvent) {
    43             evt = "on"+evt;
    44             el.attachEvent(evt, func);
    45             return function(){ el.detatchEvent(evt, func); }
    46         }
    47     }
    48 
    4936    // I make sure that dimensions passed in are valid:
    5037    function dim(val){
    5138        if(typeof val == "number") return val+"px";
    5239        if(typeof val == "string") {
    53             ndim = parseInt(val,10);
     40            var ndim = parseInt(val,10);
    5441            if(isNaN(ndim)) throw Error("IframeAppOverlay: cannot parse val "+val);
    5542            var suffix = val.match(/[0-9]+(.*)$/)[1];
     
    10794
    10895    // I turn off scrolling on body until the function I return is executed:
    109     reenableScrolling = (function(){
     96    var reenableScrolling = (function(){
    11097        var body = document.getElementsByTagName("body")[0];
    11198        var oldoverflow = body.style.overflow;
  • third-light-browser/trunk/readme.txt

    r905644 r1027192  
    33Tags: Third Light Browser, image library, thirdlight, Third Light, IMS, digital asset management, DAM
    44Requires at least: 3.4.0
    5 Tested up to: 3.9
    6 Stable tag: 0.0.6
     5Tested up to: 4.0
     6Stable tag: 0.1.0
    77License: GPLv2
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3434== Changelog ==
    3535
     36= 0.1.0 =
     37* Update for WordPress 4.0
     38* Detect insufficient PHP version at plugin activation time.
     39* Support login using user name or e-mail address from WordPress
     40* Detect sites without needed features when an API key is provided
     41
    3642= 0.0.6 =
    3743* Minor tweaks to bring inline with WordPress submission guidelines.
     
    5460* Initial release.
    5561
    56 == Upgrade Notice ==
    57 
    58 = 0.0.5 =
    59 If using PHP < 5.4, you must upgrade to this version to avoid breakage.
  • third-light-browser/trunk/thirdlightbrowser.php

    r905594 r1027192  
    44 * Plugin URI: http://www.thirdlight.com
    55 * Description: This plugin allows users to use a Third Light server as an image library in WordPress.
    6  * Version: 0.0.6
     6 * Version: 0.1.0
    77 * Author: Third Light
    88 * Author URI: http://www.thirdlight.com
     
    4343    $options = array(
    4444        "options" => array_merge(
    45             $global_options,
    46             array(
     45//          $global_options,
     46            [],
     47            array(
    4748                "metadata" => $global_options["showMetadata"] == "yes"? true : false,
    4849                "revisions" => $global_options["showRevisions"] == "yes"? true : false,
     
    5455    );
    5556
    56     //get a sessionId based on the current options to pass to the client.
    57     //if this cannot be obtained, set isValid to a suitable error message.
    58     $sessionId = call_user_func(function() use ($global_options, $options, &$isValid) {
    59         if($global_options["automaticLogin"] == "disabled") return false;
    60 
    61         try
    62         {
    63             $API = new IMSApiClient($global_options["site"], $global_options["apikey"]);
    64             $userDetails = $API->Core_ImpersonateUser(array(
    65                 "userRef" => $global_options["userRef"],
    66                 "lookupType" => $global_options["automaticLogin"]
    67             ));
    68         }
    69         catch(IMSApiActionException $e)
    70         {
    71             $isValid = "The automatic login name/email address provided in the Third Light Browser settings does not appear to be valid.";
     57    //get a sessionId based on the current options to pass to the client.
     58    //if this cannot be obtained, set isValid to a suitable error message.
     59    $sessionId = call_user_func(function() use ($global_options, &$options, &$isValid) {
     60        if($global_options["automaticLogin"] == "disabled") return false;
     61        global $current_user;
     62        $alertOnError = false;
     63        try
     64        {
     65            switch($global_options["automaticLogin"])
     66            {
     67                case "email":
     68                case "username":
     69                    $userRef = $global_options["userRef"];
     70                    $lookupType = $global_options["automaticLogin"];
     71                    $alertOnError = true;
     72                    break;
     73                case "username_dynamic":
     74                    if(!is_user_logged_in())
     75                    {
     76                        return false;
     77                    }
     78                    get_currentuserinfo();
     79                    $lookupType = "username";
     80                    $userRef= $current_user->user_login;
     81                    break;
     82                case "email_dynamic":
     83                    if(!is_user_logged_in())
     84                    {
     85                        return false;
     86                    }
     87                    get_currentuserinfo();
     88                    $lookupType = "email";
     89                    $userRef= $current_user->user_email;
     90                    break;
     91                default:
     92                    // Not supported type
     93                    $isValid = "The automatic login configuration provided in the Third Light Browser settings does not appear to be valid.";
     94                    return false;
     95            }
     96            $API = new IMSApiClient($global_options["site"], $global_options["apikey"]);
     97            try
     98            {
     99            $userDetails = $API->Core_ImpersonateUser(array(
     100                                                      "userRef" => $userRef,
     101                                                      "lookupType" => $lookupType
     102                                                      ));
     103            }
     104            catch(IMSApiActionException $e)
     105                    {
     106                        if($alertOnError)
     107                        {
     108                            $isValid = "The automatic login name/email address provided in the Third Light Browser settings does not appear to be valid.";
     109                        }
     110                        else
     111                        {
     112                            $isValid = "Your account does not appear to be enabled for use with the Third Light Browser.";
     113                        }
     114                        return false;
     115                    }
     116        }
     117        catch(IMSApiActionException $e)
     118        {
     119            $isValid = "The Third Light Browser does not appear to be configured correctly";
    72120            return false;
    73121        }
     
    75123        return $userDetails["sessionId"];
    76124    });
     125
     126
    77127
    78128    //if we got a sessionId, pass it to the client:
     
    153203    <?php
    154204}
     205
     206register_activation_hook(__FILE__, "activate");
     207function activate()
     208{
     209    if(version_compare(PHP_VERSION, '5.4', '<')) {
     210        deactivate_plugins( basename( __FILE__ ) );
     211        wp_die('<p>The <strong>Third Light Browser</strong> plugin requires PHP 5.4 or greater.</p>','Plugin Activation Error',  array( 'response'=>200, 'back_link'=>TRUE ) );
     212    }
     213    global $wp_version;
     214    if(version_compare( $wp_version, '3.4', '<' )) {
     215        deactivate_plugins( basename( __FILE__ ) );
     216        wp_die('<p>The <strong>Third Light Browser</strong> plugin requires WordPress 3.4 or greater.</p>','Plugin Activation Error',  array( 'response'=>200, 'back_link'=>TRUE ) );
     217    }
     218
     219}
Note: See TracChangeset for help on using the changeset viewer.