Plugin Directory

Changeset 3090225


Ignore:
Timestamp:
05/21/2024 01:37:12 PM (19 months ago)
Author:
viitorcloudvc
Message:

Fixed issue and deprecated functions also tested with latest WordPress version

Location:
access-fotoweb-media/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • access-fotoweb-media/trunk/callback.php

    r2257057 r3090225  
    11<?php
    2 if(!isset($_SESSION)){session_start();}
    3 if(isset($_SESSION['fw_url'])){
    4     $_SESSION['fw_url'] = filter_var($_SESSION['fw_url'], FILTER_SANITIZE_URL);
    5     $fw_url = $_SESSION['fw_url'];
     2if ( ! isset( $_SESSION ) ) {
     3    session_start();
    64}
    7 if(isset($_SESSION['client_id'])){
    8     $_SESSION['client_id'] = filter_var($_SESSION['client_id'], FILTER_SANITIZE_STRING);
    9     $client_id = $_SESSION['client_id'];
     5if ( isset( $_SESSION['fw_url'] ) ) {
     6    $_SESSION['fw_url'] = filter_var( $_SESSION['fw_url'], FILTER_SANITIZE_URL );
     7    $fw_url             = $_SESSION['fw_url'];
    108}
    11 if(isset($_SESSION['client_secret'])){
    12     $_SESSION['client_id'] = filter_var($_SESSION['client_secret'], FILTER_SANITIZE_STRING);
    13     $client_secret = $_SESSION['client_secret'];
     9if ( isset( $_SESSION['client_id'] ) ) {
     10    $_SESSION['client_id'] = filter_var( $_SESSION['client_id'], FILTER_SANITIZE_SPECIAL_CHARS );
     11    $client_id             = $_SESSION['client_id'];
    1412}
    15 if(isset($_SESSION['redirect_uri'])){
    16     $_SESSION['redirect_uri'] = filter_var($_SESSION['redirect_uri'], FILTER_SANITIZE_URL);
    17     $redirect_uri = $_SESSION['redirect_uri'];
     13if ( isset( $_SESSION['client_secret'] ) ) {
     14    $_SESSION['client_secret'] = filter_var( $_SESSION['client_secret'], FILTER_SANITIZE_SPECIAL_CHARS );
     15    $client_secret             = $_SESSION['client_secret'];
    1816}
    19 if(isset($_GET['code'])){
    20     $_GET['code'] = filter_var($_GET['code'], FILTER_SANITIZE_STRING);
    21     $authorization_code = $_GET['code'];
     17if ( isset( $_SESSION['redirect_uri'] ) ) {
     18    $_SESSION['redirect_uri'] = filter_var( $_SESSION['redirect_uri'], FILTER_SANITIZE_URL );
     19    $redirect_uri             = $_SESSION['redirect_uri'];
    2220}
    23 if(isset($_SESSION['state'])){
    24     $_SESSION['state'] = filter_var($_SESSION['state'], FILTER_SANITIZE_URL);
    25     $session_state = $_SESSION['state'];
     21if ( isset( $_GET['code'] ) ) {
     22    $_GET['code']       = filter_var( $_GET['code'], FILTER_SANITIZE_SPECIAL_CHARS );
     23    $authorization_code = $_GET['code'];
    2624}
    27 if(isset($_GET['state'])){
    28     $_GET['state'] = filter_var($_GET['state'], FILTER_SANITIZE_STRING);
    29     $state = $_GET['state'];
     25if ( isset( $_SESSION['state'] ) ) {
     26    $_SESSION['state'] = filter_var( $_SESSION['state'], FILTER_SANITIZE_URL );
     27    $session_state     = $_SESSION['state'];
    3028}
    31 if(!isset($_SESSION['access_token'])){
    32  fw_media_get_access_token();
     29if ( isset( $_GET['state'] ) ) {
     30    $_GET['state'] = filter_var( $_GET['state'], FILTER_SANITIZE_SPECIAL_CHARS );
     31    $state         = $_GET['state'];
     32}
     33if ( ! isset( $_SESSION['access_token'] ) ) {
     34    fw_media_get_access_token();
    3335}
    3436
    35 function fw_media_get_access_token(){
    36     global $client_id;
    37     global $client_secret;
    38     global $redirect_uri;
    39     global $authorization_code;
    40     global $fw_url;
    41     global $session_state;
    42     global $state;
    43    
    44     if(!$authorization_code or ($state == null)){
    45          return;
    46     }
    47    
    48     $url = "$fw_url/fotoweb/oauth2/token";
    49    
    50     $data = array(
    51         'grant_type' => 'authorization_code',
    52         'client_id' => $client_id,
    53         'client_secret' => $client_secret,
    54         'code' => $authorization_code,
    55         'redirect_uri' => $redirect_uri
    56      );
    57     $options = array(
    58         'http' => array(
    59             'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
    60             'method'  => 'POST',
    61             'content' =>  http_build_query($data)
    62         )
    63     );
    64     $context  = stream_context_create($options);
    65     $result = file_get_contents($url, false, $context);
     37function fw_media_get_access_token() {
     38    global $client_id;
     39    global $client_secret;
     40    global $redirect_uri;
     41    global $authorization_code;
     42    global $fw_url;
     43    global $session_state;
     44    global $state;
    6645
    67     $access_token = json_decode($result)->access_token;
    68     $_SESSION['access_token'] = $access_token;
     46    if ( ! $authorization_code || ( null === $state ) ) {
     47        return;
     48    }
    6949
    70     $refresh_token = json_decode($result)->refresh_token;
    71     $_SESSION['refresh_token'] = $refresh_token;
     50    $url = "$fw_url/fotoweb/oauth2/token";
    7251
    73     if ($_SESSION['access_token']){
    74         echo 'You have now been successfully logged in. Please close this tab and return to your WordPress site.';
    75         ?>
    76         <script> window.localStorage.setItem('isLoggedIn', 'true');</script>
    77         <?php
    78     }
     52    $data    = array(
     53        'grant_type'    => 'authorization_code',
     54        'client_id'     => $client_id,
     55        'client_secret' => $client_secret,
     56        'code'          => $authorization_code,
     57        'redirect_uri'  => $redirect_uri,
     58    );
     59    $options = array(
     60        'http' => array(
     61            'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
     62            'method'  => 'POST',
     63            'content' => http_build_query( $data ),
     64        ),
     65    );
     66    $context = stream_context_create( $options );
     67    $result  = file_get_contents( $url, false, $context );
     68
     69    $access_token             = json_decode( $result )->access_token;
     70    $_SESSION['access_token'] = $access_token;
     71
     72    $refresh_token             = json_decode( $result )->refresh_token;
     73    $_SESSION['refresh_token'] = $refresh_token;
     74
     75    if ( $_SESSION['access_token'] ) {
     76        echo 'You have now been successfully logged in. Please close this tab and return to your WordPress site.';
     77        ?>
     78        <script> window.localStorage.setItem('isLoggedIn', 'true');</script>
     79        <?php
     80    }
    7981}
    8082?>
  • access-fotoweb-media/trunk/fotoware-auth.php

    r2257057 r3090225  
    11<?php
    2 if(!isset($_SESSION)){session_start();}
    3 if(isset($_SESSION['fw_url'])){
    4     $_SESSION['fw_url'] = filter_var($_SESSION['fw_url'], FILTER_SANITIZE_URL);
    5     $fotoweb_url = $_SESSION['fw_url'];
     2if ( ! isset( $_SESSION ) ) {
     3    session_start();
    64}
    7 if(isset($_SESSION['access_token'])){
    8     $_SESSION['access_token'] = filter_var($_SESSION['access_token'], FILTER_SANITIZE_STRING);
    9     $access_token = $_SESSION['access_token'];
     5if ( isset( $_SESSION['fw_url'] ) ) {
     6    $_SESSION['fw_url'] = filter_var( $_SESSION['fw_url'], FILTER_SANITIZE_URL );
     7    $fotoweb_url        = $_SESSION['fw_url'];
    108}
    11 if(isset($_SESSION['client_id'])){
    12     $_SESSION['client_id'] = filter_var($_SESSION['client_id'], FILTER_SANITIZE_STRING);
    13     $client_id = $_SESSION['client_id'];
     9if ( isset( $_SESSION['access_token'] ) ) {
     10    $_SESSION['access_token'] = filter_var( $_SESSION['access_token'], FILTER_SANITIZE_SPECIAL_CHARS );
     11    $access_token             = $_SESSION['access_token'];
    1412}
    15 if(isset($_SESSION['client_secret'])){
    16     $_SESSION['client_id'] = filter_var($_SESSION['client_secret'], FILTER_SANITIZE_STRING);
    17     $client_secret = $_SESSION['client_secret'];
     13if ( isset( $_SESSION['client_id'] ) ) {
     14    $_SESSION['client_id'] = filter_var( $_SESSION['client_id'], FILTER_SANITIZE_SPECIAL_CHARS );
     15    $client_id             = $_SESSION['client_id'];
    1816}
    19 if(isset($_SESSION['redirect_uri'])){
    20     $_SESSION['redirect_uri'] = filter_var($_SESSION['redirect_uri'], FILTER_SANITIZE_URL);
    21     $redirect_uri = $_SESSION['redirect_uri'];
     17if ( isset( $_SESSION['client_secret'] ) ) {
     18    $_SESSION['client_id'] = filter_var( $_SESSION['client_secret'], FILTER_SANITIZE_SPECIAL_CHARS );
     19    $client_secret         = $_SESSION['client_secret'];
    2220}
    23 if(isset($_GET['code'])){
    24     $_GET['code'] = filter_var($_GET['code'], FILTER_SANITIZE_STRING);
    25     $authorization_code = $_GET['code'];
     21if ( isset( $_SESSION['redirect_uri'] ) ) {
     22    $_SESSION['redirect_uri'] = filter_var( $_SESSION['redirect_uri'], FILTER_SANITIZE_URL );
     23    $redirect_uri             = $_SESSION['redirect_uri'];
    2624}
    27 if(isset($_SESSION['state'])){
    28     $_SESSION['state'] = filter_var($_SESSION['state'], FILTER_SANITIZE_URL);
    29     $session_state = $_SESSION['state'];
     25if ( isset( $_GET['code'] ) ) {
     26    $_GET['code']       = filter_var( $_GET['code'], FILTER_SANITIZE_SPECIAL_CHARS );
     27    $authorization_code = $_GET['code'];
    3028}
    31 if(isset($_GET['state'])){
    32     $_GET['state'] = filter_var($_GET['state'], FILTER_SANITIZE_STRING);
    33     $state = $_GET['state'];
     29if ( isset( $_SESSION['state'] ) ) {
     30    $_SESSION['state'] = filter_var( $_SESSION['state'], FILTER_SANITIZE_URL );
     31    $session_state     = $_SESSION['state'];
    3432}
    35 function fw_media_get_access_token_from_refresh_token(){
    36     $refresh_token = $_SESSION['refresh_token'];
    37     global $access_token;
    38     global $client_id;
    39     global $client_secret;
    40     global $fw_url;
     33if ( isset( $_GET['state'] ) ) {
     34    $_GET['state'] = filter_var( $_GET['state'], FILTER_SANITIZE_SPECIAL_CHARS );
     35    $state         = $_GET['state'];
     36}
     37function fw_media_get_access_token_from_refresh_token() {
     38    $refresh_token = $_SESSION['refresh_token'];
     39    global $access_token;
     40    global $client_id;
     41    global $client_secret;
     42    global $fw_url;
    4143
    42     $url = "$fw_url/fotoweb/oauth2/token";
     44    $url = "$fw_url/fotoweb/oauth2/token";
    4345
    44     //Refresh the token
    45     $data = array(
    46         'grant_type' => 'refresh_token',
    47         'refresh_token' => $refresh_token,
    48         'client_id' => $client_id,
    49         'client_secret' => $client_secret,
    50      );
    51    
    52     $options = array(
    53         'http' => array(
    54             'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
    55             'method'  => 'POST',
    56             'content' => http_build_query($data)
    57         )
    58     );
    59     $context  = stream_context_create($options);
    60     $refresh_result = file_get_contents($url, false, $context);
     46    // Refresh the token.
     47    $data = array(
     48        'grant_type'    => 'refresh_token',
     49        'refresh_token' => $refresh_token,
     50        'client_id'     => $client_id,
     51        'client_secret' => $client_secret,
     52    );
    6153
    62     if($refresh_result){
    63         $_SESSION['access_token'] = json_decode($refresh_result)->access_token;
    64         $_SESSION['refresh_token'] = json_decode($refresh_result)->refresh_token;
    65     }
     54    $options        = array(
     55        'http' => array(
     56            'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
     57            'method'  => 'POST',
     58            'content' => http_build_query( $data ),
     59        ),
     60    );
     61    $context        = stream_context_create( $options );
     62    $refresh_result = file_get_contents( $url, false, $context );
    6663
    67     return json_decode($refresh_result)->access_token;
     64    if ( $refresh_result ) {
     65        $_SESSION['access_token']  = json_decode( $refresh_result )->access_token;
     66        $_SESSION['refresh_token'] = json_decode( $refresh_result )->refresh_token;
     67    }
     68
     69    return json_decode( $refresh_result )->access_token;
    6870}
  • access-fotoweb-media/trunk/fotoware-main.php

    r2257057 r3090225  
    1 <?php
    2 // Exit if accessed directly
    3 if ( !defined( 'ABSPATH' ) ) exit;
    4 if( !class_exists('FotoWeb')){
     1<?php
     2// Exit if accessed directly.
     3if ( ! defined( 'ABSPATH' ) ) {
     4    exit;
     5}
     6if ( ! class_exists( 'FotoWeb' ) ) {
    57
    6     function fw_media_generateState($length = 10) {
    7         $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    8         $charactersLength = strlen($characters);
    9         $state = '';
    10         for ($i = 0; $i < $length; $i++) {
    11             $state .= $characters[rand(0, $charactersLength - 1)];
    12         }
    13         return $state;
    14     }
     8    function fw_media_generateState( $length = 10 ) {
     9        $characters      = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
     10        $charactersLength = strlen( $characters );
     11        $state            = '';
     12        for ( $i = 0; $i < $length; $i++ ) {
     13            $state .= $characters[ rand( 0, $charactersLength - 1 ) ];
     14        }
     15        return $state;
     16    }
    1517
    16     $_SESSION['state'] = fw_media_generateState();
     18    $_SESSION['state'] = fw_media_generateState();
    1719
    18     class FotoWeb {
    19        
    20         public $plugin;
    21         public $fw_options;
    22         public $logged_in;
     20    class FotoWeb {
    2321
    24         function __construct () {
    25             $this->fw_options = new FotoWeb_Options();
    26             $this->plugin = plugin_basename(__FILE__);
    27            
    28             global $fotoweb_url;
    29             $fotoweb_url = $this->fw_options->options['fw_url'];
    30             $_SESSION['fw_url'] = $this->fw_options->options['fw_url'];
    31             $_SESSION['client_id'] = $this->fw_options->options['client_id'];
    32             $_SESSION['client_secret'] = $this->fw_options->options['client_secret'];
    33             $_SESSION['redirect_uri'] =  FW_MEDIA_AC_URL.'callback.php';
    34             $_SESSION['afterlog_url'] =  FW_MEDIA_AC_URL;
    35         }
     22        public $plugin;
     23        public $fw_options;
     24        public $logged_in;
    3625
    37         function fw_media_register_script(){
    38             add_filter("plugin_action_links_$this->plugin" , array($this, 'settings_link'));
     26        function __construct() {
     27            $this->fw_options = new FotoWeb_Options();
     28            $this->plugin     = plugin_basename( __FILE__ );
    3929
    40             if($this->fw_options->options['fw_url']) {
    41                 add_action('media_buttons', array($this,'login_fotoweb_button'), 15);
    42             }
    43         }
    44      
    45         public function settings_link( $links){
    46             $settings_link = '<a href=admin.php?page=fotoweb_plugin>Settings</a>';
    47             array_push($links, $settings_link);
    48             return $links;
    49         }
     30            global $fotoweb_url;
     31            $fotoweb_url               = $this->fw_options->options['fw_url'];
     32            $_SESSION['fw_url']        = $this->fw_options->options['fw_url'];
     33            $_SESSION['client_id']     = $this->fw_options->options['client_id'];
     34            $_SESSION['client_secret'] = $this->fw_options->options['client_secret'];
     35            $_SESSION['redirect_uri']  = FW_MEDIA_AC_URL . 'callback.php';
     36            $_SESSION['afterlog_url']  = FW_MEDIA_AC_URL;
     37        }
    5038
    51         public function login_fotoweb_button(){
    52              echo '<a  onclick="handleOpenWindow
     39        function fw_media_register_script() {
     40            add_filter( "plugin_action_links_$this->plugin", array( $this, 'settings_link' ) );
     41
     42            if ( $this->fw_options->options['fw_url'] ) {
     43                add_action( 'media_buttons', array( $this, 'login_fotoweb_button' ), 15 );
     44            }
     45        }
     46
     47        public function settings_link( $links ) {
     48            $settings_link = '<a href=admin.php?page=fotoweb_plugin>Settings</a>';
     49            array_push( $links, $settings_link );
     50            return $links;
     51        }
     52
     53        public function login_fotoweb_button() {
     54            echo '<a  onclick="handleOpenWindow
    5355             
    54         ()" target="_blank"   id="fotoweb_button" class="button"><img src="'. FW_MEDIA_AC_IMG_URL.'/fotoweb_icon.png" style="vertical-align:sub; padding-right: 4px; padding-left: 0px;" height="16px" width="16px"/>Add Media from FotoWare</a>';     
    55         ?>
     56        ()" target="_blank"   id="fotoweb_button" class="button"><img src="' . FW_MEDIA_AC_IMG_URL . '/fotoweb_icon.png" style="vertical-align:sub; padding-right: 4px; padding-left: 0px;" height="16px" width="16px"/>Add Media from FotoWare</a>';
     57            ?>
    5658        <script>
    57            const fw_url = '<?php echo $_SESSION['fw_url'];?>';
    58             const afterlog_url = '<?php echo $_SESSION['afterlog_url'];?>';
    59             function handleOpenWindow(){
    60             const access_token = '<?php echo $_SESSION['access_token']?>';
    61             const client_id = '<?php echo $_SESSION['client_id']?>';
    62             const redirect_uri = '<?php echo $_SESSION['redirect_uri']?>';
    63             const state = '<?php echo $_SESSION['state']?>';
     59            const fw_url = '<?php echo $_SESSION['fw_url']; ?>';
     60            const afterlog_url = '<?php echo $_SESSION['afterlog_url']; ?>';
     61            function handleOpenWindow(){
     62            const access_token = '<?php echo $_SESSION['access_token']; ?>';
     63            const client_id = '<?php echo $_SESSION['client_id']; ?>';
     64            const redirect_uri = '<?php echo $_SESSION['redirect_uri']; ?>';
     65            const state = '<?php echo $_SESSION['state']; ?>';
    6466
    6567            const isLoggedIn = window.localStorage.getItem('isLoggedIn');
    6668            if(isLoggedIn === 'true'){
    67                 const token = '<?php echo fw_media_get_access_token_from_refresh_token() ?>';
     69                const token = '<?php echo fw_media_get_access_token_from_refresh_token(); ?>';
    6870                showcontactusform();
    6971            }else{
     
    7274        }
    7375        function showcontactusform() {
    74               //set the width and height of the
    75               //pop up window in pixels
    76               var width = 655;
    77               var height = 555;
     76                //set the width and height of the
     77                //pop up window in pixels
     78                var width = 655;
     79                var height = 555;
    7880         
    79               //Get the TOP coordinate by
    80               //getting the 50% of the screen height minus
    81               //the 50% of the pop up window height
    82               var top = parseInt((screen.availHeight/2) - (height/2));
     81                //Get the TOP coordinate by
     82                //getting the 50% of the screen height minus
     83                //the 50% of the pop up window height
     84                var top = parseInt((screen.availHeight/2) - (height/2));
    8385         
    84               //Get the LEFT coordinate by
    85               //getting the 50% of the screen width minus
    86               //the 50% of the pop up window width
    87               var left = parseInt((screen.availWidth/2) - (width/2));
     86                //Get the LEFT coordinate by
     87                //getting the 50% of the screen width minus
     88                //the 50% of the pop up window width
     89                var left = parseInt((screen.availWidth/2) - (width/2));
    8890         
    89               //Open the window with the
    90               //file to show on the pop up window
    91               //title of the pop up
    92               //and other parameter where we will use the
    93               //values of the variables above
    94               window.open(afterlog_url +"fotoware-selection.php",
     91                //Open the window with the
     92                //file to show on the pop up window
     93                //title of the pop up
     94                //and other parameter where we will use the
     95                //values of the variables above
     96                window.open(afterlog_url +"fotoware-selection.php",
    9597                    "",
    96                     "menubar=no,resizable=no,width=655,height=555,scrollbars=0,left=" 
    97                     + left + ",top=" + top + ",screenX=" + left + ",screenY=" + top);   
    98               }
     98                    "menubar=no,resizable=no,width=655,height=555,scrollbars=0,left="
     99                    + left + ",top=" + top + ",screenX=" + left + ",screenY=" + top);
     100                }
    99101
    100102        const popup = () =>  {
     
    107109                wp.media.editor.insert(exported_url);
    108110                window.localStorage.removeItem('exported_url');
    109             }   
     111            }
    110112        }, false);
    111113
    112         window.addEventListener('storage', function(e) { 
    113          if(e.newValue === 'true'){
    114              popup();
    115          }
     114        window.addEventListener('storage', function(e) {
     115        if(e.newValue === 'true'){
     116            popup();
     117        }
    116118        });</script>
    117         <?php } 
     119        <?php }
    118120
    119         public function fw_media_registrer_my_scripts(){
    120             wp_localize_script( 'fw-javascript', 'fwParams', $this->fw_options->options );
    121         }
    122  }
    123 $fotoweb = new FotoWeb();
    124 $fotoweb -> fw_media_register_script();
     121        public function fw_media_registrer_my_scripts() {
     122            wp_localize_script( 'fw-javascript', 'fwParams', $this->fw_options->options );
     123        }
     124    }
     125    $fotoweb = new FotoWeb();
     126    $fotoweb->fw_media_register_script();
    125127} ?>
  • access-fotoweb-media/trunk/fotoware-media-access.php

    r2610724 r3090225  
    11<?php
    22/**
    3  * Plugin Name: FotoWare Wordpress Lite
     3 * Plugin Name: FotoWare WordPress Lite
    44 * Plugin URI: https://viitorcloud.com/
    55 * Description: The Plugin's WordPress editor button connector for Fotoware allows to include images directly from the Fotoweb DAM, into WordPress.
    6  * Version:1.0.0
     6 * Version:2.0.0
    77 * Author: VIITORCLOUD
    88 * Author URI: https://viitorcloud.com/
    99 * License: GPL2
    10  */
     10 *
     11 * @package Fotoware_wordpress_plugin
     12 */
    1113
    12 
    13 // Exit if accessed directly
    14 if ( !defined( 'ABSPATH' ) ) exit;
     14// Exit if accessed directly.
     15if ( ! defined( 'ABSPATH' ) ) {
     16    exit;
     17}
    1518
    1619global $wpdb;
    1720
    18 if( !defined( 'FW_MEDIA_AC_DIR' ) ) {
    19     define( 'FW_MEDIA_AC_DIR', dirname( __FILE__ ) ); // plugin dir
     21if ( ! defined( 'FW_MEDIA_AC_DIR' ) ) {
     22    define( 'FW_MEDIA_AC_DIR', __DIR__ ); // plugin dir.
    2023}
    2124
    22 if( !defined( 'FW_MEDIA_AC_URL' ) ) {
    23     define( 'FW_MEDIA_AC_URL', plugin_dir_url( __FILE__ ) ); // plugin url
     25if ( ! defined( 'FW_MEDIA_AC_URL' ) ) {
     26    define( 'FW_MEDIA_AC_URL', plugin_dir_url( __FILE__ ) ); // plugin url.
    2427}
    25 if( !defined( 'FW_MEDIA_AC_IMG_URL' ) ) {
    26     define( 'FW_MEDIA_AC_IMG_URL', FW_MEDIA_AC_URL . '/images' ); // plugin images url
     28if ( ! defined( 'FW_MEDIA_AC_IMG_URL' ) ) {
     29    define( 'FW_MEDIA_AC_IMG_URL', FW_MEDIA_AC_URL . '/images' ); // plugin images url.
    2730}
    28 if( !defined( 'FW_MEDIA_AC_TEXT_DOMAIN' ) ) {
    29     define( 'FW_MEDIA_AC_TEXT_DOMAIN', 'fotoware_media_access' ); // text domain for doing language translation
     31if ( ! defined( 'FW_MEDIA_AC_TEXT_DOMAIN' ) ) {
     32    define( 'FW_MEDIA_AC_TEXT_DOMAIN', 'fotoware_media_access' ); // text domain for doing language translation.
    3033}
    3134
    3235/**
    3336 * Load Text Domain
    34  * 
     37 *
    3538 * This gets the plugin ready for translation.
    36  * 
     39 *
    3740 * @package FotoWare Media Access
    38  * @since 1.0.0
     41 * @since 2.0.0
    3942 */
    4043load_plugin_textdomain( 'fotoware_media_access', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
    4144/**
    4245 * Activation hook
    43  * 
     46 *
    4447 * Register plugin activation hook.
    45  * 
     48 *
    4649 * @package FotoWare Media Access
    47  *@since 1.0.0
     50 *@since 2.0.0
    4851 */
    4952register_activation_hook( __FILE__, 'fotoware_media_access_install' );
     
    5356 *
    5457 * Register plugin deactivation hook.
    55  * 
     58 *
    5659 * @package FotoWare Media Access
    57  * @since 1.0.0
     60 * @since 2.0.0
    5861 */
    5962register_deactivation_hook( __FILE__, 'fotoware_media_access_uninstall' );
    6063
    6164/**
    62  * Plugin Setup Activation hook call back 
     65 * Plugin Setup Activation hook call back
    6366 *
    64  * Initial setup of the plugin setting default options 
     67 * Initial setup of the plugin setting default options
    6568 * and database tables creations.
    66  * 
     69 *
    6770 * @package FotoWare Media Access
    68  * @since 1.0.0
     71 * @since 2.0.0
    6972 */
    7073function fotoware_media_access_install() {
    71    
    72     global $wpdb;
    73        
     74
     75    global $wpdb;
    7476}
    7577/**
     
    8082 *
    8183 * @package FotoWare Media Access
    82  * @since 1.0.0
     84 * @since 2.0.0
    8385 */
    8486function fotoware_media_access_uninstall() {
    85    
     87
    8688    global $wpdb;
    87            
    8889}
    8990
     
    9495 *
    9596 * @package FotoWare Media Access
    96  * @since 1.0.0
     97 * @since 2.0.0
    9798 */
    9899
    99 //require_once options file
    100 require_once( FW_MEDIA_AC_DIR . '/fotoware-options.php');
     100// require_once options file.
     101require_once FW_MEDIA_AC_DIR . '/fotoware-options.php';
    101102
    102 //require_once callback file
    103 require_once( FW_MEDIA_AC_DIR . '/callback.php');
     103// require_once callback file.
     104require_once FW_MEDIA_AC_DIR . '/callback.php';
    104105
    105 //require_once auth file
    106 require_once( FW_MEDIA_AC_DIR . '/fotoware-auth.php');
     106// require_once auth file.
     107require_once FW_MEDIA_AC_DIR . '/fotoware-auth.php';
    107108
    108 //require_once options file
    109  require_once( FW_MEDIA_AC_DIR . '/fotoware-main.php');
     109// require_once options file.
     110require_once FW_MEDIA_AC_DIR . '/fotoware-main.php';
  • access-fotoweb-media/trunk/fotoware-options.php

    r2289189 r3090225  
    1 <?php
    2 // Exit if accessed directly
    3 if ( !defined( 'ABSPATH' ) ) exit;
     1<?php
     2// Exit if accessed directly.
     3if ( ! defined( 'ABSPATH' ) ) {
     4    exit;
     5}
    46class FotoWeb_Options {
    57
    68    public $options;
    7     public $options_name = 'fotoweb_plugin_options';
    8     public $state;
     9    public $options_name = 'fotoweb_plugin_options';
     10    public $state;
    911
    10     public function __construct () {
    11        $this->fw_media_setup_globals();
    12         $this->setup_hooks();
    13         add_action('admin_init', array($this, 'register_settings_and_fields'));
    14         add_action('admin_menu', array($this, 'add_menu_page'));
    15         $this->options = get_option( $this->options_name);
     12    public function __construct() {
     13        $this->fw_media_setup_globals();
     14        $this->setup_hooks();
     15        add_action( 'admin_init', array( $this, 'register_settings_and_fields' ) );
     16        add_action( 'admin_menu', array( $this, 'add_menu_page' ) );
     17        $this->options = get_option( $this->options_name );
    1618    }
    1719
    18     public function fw_media_generateState($length = 10) {
    19         $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    20         $charactersLength = strlen($characters);
    21         $state = '';
    22         for ($i = 0; $i < $length; $i++) {
    23             $state .= $characters[rand(0, $charactersLength - 1)];
    24         }
    25         return $state;
    26     }
    27 
    28     public function add_menu_page() {
    29         add_menu_page('FotoWare Plugin', 'FotoWare Settings', 'manage_options', 'fotoweb_plugin', array($this, 'fw_media_display_options_page'), '
    30         dashicons-admin-generic', 110);
     20    public function fw_media_generateState( $length = 10 ) {
     21        $characters       = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
     22        $charactersLength = strlen( $characters );
     23        $state            = '';
     24        for ( $i = 0; $i < $length; $i++ ) {
     25            $state .= $characters[ rand( 0, $charactersLength - 1 ) ];
     26        }
     27        return $state;
    3128    }
    3229
    33     public function fw_media_display_options_page () {
     30    public function add_menu_page() {
     31        add_menu_page(
     32            'FotoWare Plugin',
     33            'FotoWare Settings',
     34            'manage_options',
     35            'fotoweb_plugin',
     36            array( $this, 'fw_media_display_options_page' ),
     37            '
     38        dashicons-admin-generic',
     39            110
     40        );
     41    }
     42
     43    public function fw_media_display_options_page() {
    3444        ?>
    3545            <div class="wrap fotoware-setting">
    3646                <div class="fotoware-setting-form">
    3747                    <form method="post" action="options.php">
    38                         <?php 
    39                             settings_fields($this->options_name);
    40                             do_settings_sections(__FILE__);
     48                        <?php
     49                            settings_fields( $this->options_name );
     50                            do_settings_sections( __FILE__ );
    4151                            submit_button();
    4252                        ?>
     
    4656        <?php
    4757    }
    48    
    49     public function register_settings_and_fields () {
    50         register_setting($this->options_name, $this->options_name, array($this, 'fotoweb_validate_settings'));
    51         add_settings_section( 'fw_main_section', 'FotoWare Settings', array($this, 'fw_main_section_cb'), __FILE__ );
    52         add_settings_field( 'fw_url', 'FotoWare URL', array($this, 'fw_url_setting'), __FILE__, 'fw_main_section');
    53         add_settings_field( 'client_id', 'Client ID', array($this, 'client_id_setting'), __FILE__, 'fw_main_section');
    54         add_settings_field( 'client_secret', 'Client Secret', array($this, 'client_secret_setting'), __FILE__, 'fw_main_section');
    55         add_settings_field( 'redirect_uri', 'Redirect URI', array($this, 'redirect_uri_setting'), __FILE__, 'fw_main_section');
    56         add_settings_field( 'logout', '', array($this, 'fotoweb_logout_settings'), __FILE__, 'fw_main_section');
    5758
     59    public function register_settings_and_fields() {
     60        register_setting( $this->options_name, $this->options_name, array( $this, 'fotoweb_validate_settings' ) );
     61        add_settings_section( 'fw_main_section', 'FotoWare Settings', array( $this, 'fw_main_section_cb' ), __FILE__ );
     62        add_settings_field( 'fw_url', 'FotoWare URL', array( $this, 'fw_url_setting' ), __FILE__, 'fw_main_section' );
     63        add_settings_field( 'client_id', 'Client ID', array( $this, 'client_id_setting' ), __FILE__, 'fw_main_section' );
     64        add_settings_field( 'client_secret', 'Client Secret', array( $this, 'client_secret_setting' ), __FILE__, 'fw_main_section' );
     65        add_settings_field( 'redirect_uri', 'Redirect URI', array( $this, 'redirect_uri_setting' ), __FILE__, 'fw_main_section' );
     66        add_settings_field( 'logout', '', array( $this, 'fotoweb_logout_settings' ), __FILE__, 'fw_main_section' );
    5867    }
    5968
    6069
    61     public function fotoweb_validate_settings ($plugin_options) {
     70    public function fotoweb_validate_settings( $plugin_options ) {
    6271        return $plugin_options;
    6372    }
     
    6978    *
    7079    */
    71     public function fw_main_section_cb () {
    72         echo "Add below details and save settings";
     80    public function fw_main_section_cb() {
     81        echo 'Add below details and save settings';
    7382    }
    74     public function fw_url_setting () {
     83    public function fw_url_setting() {
    7584        echo "<input name='$this->options_name[fw_url]' type='text' value='{$this->options['fw_url']}' />";
    7685    }
    77     public function client_id_setting () {
     86    public function client_id_setting() {
    7887        echo "<input name='$this->options_name[client_id]' type='text' value='{$this->options['client_id']}' />";
    7988    }
    80     public function client_secret_setting () {
     89    public function client_secret_setting() {
    8190        echo "<input name='$this->options_name[client_secret]' type='text' value='{$this->options['client_secret']}' />";
    8291    }
    83     public function wordpress_url_setting () {
     92    public function wordpress_url_setting() {
    8493        echo "<input name='$this->options_name[wordpress_url]' type='text' value='{$this->options['wordpress_url']}' />";
    8594    }
    8695
    87     public function redirect_uri_setting () {
     96    public function redirect_uri_setting() {
    8897        $fotoware_base_uri = get_site_url();
    89         echo '<div> '.FW_MEDIA_AC_URL.'callback.php</div>';
     98        echo '<div> ' . FW_MEDIA_AC_URL . 'callback.php</div>';
    9099    }
    91     public function fotoweb_logout_settings(){
    92             echo '<a href="'.FW_MEDIA_AC_URL.'fotoware-logout.php" class="button">Log out From FotoWare</a>';
     100    public function fotoweb_logout_settings() {
     101            echo '<a href="' . FW_MEDIA_AC_URL . 'fotoware-logout.php" class="button">Log out From FotoWare</a>';
    93102    }
    94103    private function fw_media_setup_globals() {
    95         // let's define some globals to easily build the url to your scripts
    96         $this->version      = '1.0.0';
    97         $this->file         = __FILE__;
    98  
    99         // url to your plugin dir : site.url/wp-content/wp-fotoweb-api/
    100         $this->plugin_url  = plugin_dir_url( $this->file );
    101  
    102         // url to your plugin's includes dir : site.url/wp-content/plugins/wp-fotoweb-api/includes/
    103         $this->includes_url = trailingslashit( $this->plugin_url . 'includes' );
    104  
    105         // url to your plugin's js dir : site.url/wp-content/plugins/wp-fotoweb-api/includes/js/
    106         $this->plugin_js    = trailingslashit( $this->includes_url . 'js' );
    107  
    108         // url to your plugin's css dir : site.url/wp-content/plugins/wp-fotoweb-api/includes/css/
    109         $this->plugin_css  = trailingslashit( $this->includes_url . 'css' );
    110  
    111         $this->component_id   = 'wp-fotoweb-api';
    112         $this->component_slug = 'wp-fotoweb-api';
    113     }
    114  
    115     private function setup_hooks() {
    116         // As soon as WordPress meets this hook, your cssjs function will be called
    117         add_action( 'admin_enqueue_scripts', array( $this, 'fw_media_include' ) );
    118     }
    119  
    120     public function fw_media_include() {
    121         // Your css file is reachable at site.url/wp-content/plugins/buddyplug/includes/css/buddyplug.css
    122         wp_enqueue_style( 'fotoware-media', FW_MEDIA_AC_URL . 'css/fotoware-media.css', false, $this->version );
    123     }
     104        // let's define some globals to easily build the url to your scripts.
     105        $this->version = '1.0.0';
     106        $this->file    = __FILE__;
     107
     108        // url to your plugin dir : site.url/wp-content/wp-fotoweb-api/.
     109        $this->plugin_url = plugin_dir_url( $this->file );
     110
     111        // url to your plugin's includes dir : site.url/wp-content/plugins/wp-fotoweb-api/includes/.
     112        $this->includes_url = trailingslashit( $this->plugin_url . 'includes' );
     113
     114        // url to your plugin's js dir : site.url/wp-content/plugins/wp-fotoweb-api/includes/js/.
     115        $this->plugin_js = trailingslashit( $this->includes_url . 'js' );
     116
     117        // url to your plugin's css dir : site.url/wp-content/plugins/wp-fotoweb-api/includes/css/.
     118        $this->plugin_css = trailingslashit( $this->includes_url . 'css' );
     119
     120        $this->component_id   = 'wp-fotoweb-api';
     121        $this->component_slug = 'wp-fotoweb-api';
     122    }
     123
     124    private function setup_hooks() {
     125        // As soon as WordPress meets this hook, your cssjs function will be called.
     126        add_action( 'admin_enqueue_scripts', array( $this, 'fw_media_include' ) );
     127    }
     128
     129    public function fw_media_include() {
     130        // Your css file is reachable at site.url/wp-content/plugins/buddyplug/includes/css/buddyplug.css.
     131        wp_enqueue_style( 'fotoware-media', FW_MEDIA_AC_URL . 'css/fotoware-media.css', false, $this->version );
     132    }
    124133}
    125134?>
  • access-fotoweb-media/trunk/fotoware-selection.php

    r2257057 r3090225  
    11<?php
    2 include_once 'fotoware-auth.php';
    3 if(isset($_SESSION['fw_url'])){
    4     $_SESSION['fw_url'] = filter_var($_SESSION['fw_url'], FILTER_SANITIZE_URL);
    5     $fotoweb_url = $_SESSION['fw_url'];
     2require_once 'fotoware-auth.php';
     3if ( isset( $_SESSION['fw_url'] ) ) {
     4    $_SESSION['fw_url'] = filter_var( $_SESSION['fw_url'], FILTER_SANITIZE_URL );
     5    $fotoweb_url        = $_SESSION['fw_url'];
    66}
    7 if(isset($_SESSION['access_token'])){
    8     $_SESSION['access_token'] = filter_var($_SESSION['access_token'], FILTER_SANITIZE_STRING);
    9     $access_token = $_SESSION['access_token'];
     7if ( isset( $_SESSION['access_token'] ) ) {
     8    $_SESSION['access_token'] = filter_var( $_SESSION['access_token'], FILTER_SANITIZE_STRING );
     9    $access_token            = $_SESSION['access_token'];
    1010}
    11 if(isset($_SESSION['client_id'])){
    12     $_SESSION['client_id'] = filter_var($_SESSION['client_id'], FILTER_SANITIZE_STRING);
    13     $client_id = $_SESSION['client_id'];
     11if ( isset( $_SESSION['client_id'] ) ) {
     12    $_SESSION['client_id'] = filter_var( $_SESSION['client_id'], FILTER_SANITIZE_STRING );
     13    $client_id            = $_SESSION['client_id'];
    1414}
    15 if(isset($_SESSION['redirect_uri'])){
    16     $_SESSION['redirect_uri'] = filter_var($_SESSION['redirect_uri'], FILTER_SANITIZE_URL);
    17     $redirect_uri = $_SESSION['redirect_uri'];
     15if ( isset( $_SESSION['redirect_uri'] ) ) {
     16    $_SESSION['redirect_uri'] = filter_var( $_SESSION['redirect_uri'], FILTER_SANITIZE_URL );
     17    $redirect_uri            = $_SESSION['redirect_uri'];
    1818}
    19 if(isset($_SESSION['state'])){
    20     $_SESSION['state'] = filter_var($_SESSION['state'], FILTER_SANITIZE_STRING);
    21     $state = $_SESSION['state'];
    22 } 
     19if ( isset( $_SESSION['state'] ) ) {
     20    $_SESSION['state'] = filter_var( $_SESSION['state'], FILTER_SANITIZE_STRING );
     21    $state            = $_SESSION['state'];
     22}
    2323
    24 if(isset($_SESSION['access_token'])){
    25  echo '<iframe src="'.$fotoweb_url.'/fotoweb/widgets/selection?access_token='.$access_token.'" width="100%" height="100%"  frameBorder="0" id="iframe"></iframe>';
    26 }
    27 else{
    28     echo 'Something went wrong! Please <a href="'.$fotoweb_url.'/fotoweb/oauth2/authorize?response_type=code&client_id='.$client_id.'&redirect_uri='.$redirect_uri.'&state='.$state.'"> log in </a> again!';
     24if ( isset( $_SESSION['access_token'] ) ) {
     25    echo '<iframe src="' . $fotoweb_url . '/fotoweb/widgets/selection?access_token=' . $access_token . '" width="100%" height="100%"  frameBorder="0" id="iframe"></iframe>';
     26} else {
     27    echo 'Something went wrong! Please <a href="' . $fotoweb_url . '/fotoweb/oauth2/authorize?response_type=code&client_id=' . $client_id . '&redirect_uri=' . $redirect_uri . '&state=' . $state . '"> log in </a> again!';
    2928}
    3029?>
    3130<script>
    32 const fw_url = '<?php echo $_SESSION['fw_url'];?>';
     31const fw_url = '<?php echo $_SESSION['fw_url']; ?>';
    3332document.title = "Add Media from FotoWare";
    34 document.documentElement.style.overflow = 'hidden';  // firefox, chrome
     33document.documentElement.style.overflow = 'hidden';  // firefox, chrome.
    3534document.getElementsByTagName("body")[0].style.margin = "0";
    3635document.getElementsByTagName("body")[0].style.padding = "0";
    3736
    3837function listener (event) {
    39     if (event.data === 'authenticated') {
     38    if (event.data === 'authenticated') {
    4039        const iframes = document.getElementById('iframe');
    4140        const FW_iframe = '';
     
    5150        handleExported(event.data);
    5251    }else if (event.data.event === 'selectionWidgetCancel') {
    53         window.close();
    54     }
     52        window.close();
     53    }
    5554}
    5655function handleSelected(data) {
     
    6362        '" width="' + data.export.export.size.w +
    6463        '" height="' + data.export.export.size.h +
    65         '" />';
     64        '" />';
    6665window.localStorage.setItem('exported_url',exported_url);
    6766    window.close();
     
    6968
    7069function getFrameURL (data, url) {
    71     const token = '<?php echo $_SESSION['access_token']?>';
     70    const token = '<?php echo $_SESSION['access_token']; ?>';
    7271    const frameURL = url + '/fotoweb/widgets/publish?access_token=' + token + '&i=' + encodeURIComponent(data.asset.href);
    7372    return frameURL;
  • access-fotoweb-media/trunk/index.php

    r2257057 r3090225  
    11<?php
    22// Silence is golden.
    3 ?>
  • access-fotoweb-media/trunk/readme.txt

    r2894187 r3090225  
    44Tags:DAM, FOTOWARE, upload image from FotoWare,
    55Requires at least: 3.8
    6 Tested up to: 6.2
    7 Requires PHP: 5.2.4
     6Tested up to: 6.5.3
     7Requires PHP: 7.4 or higher
    88Stable tag: 3.2.0
    99License: GPLv3
Note: See TracChangeset for help on using the changeset viewer.