/**
  * Makes the request to the server.
  * 
  * @param string $server	
  * @param string $service		The rest service to access e.g. /connections/communities/all
  * @param string $method		GET, POST or PUT
  * @param string $body
  * @param string $headers
  */
 public function makeRequest($server, $service, $method, $options, $body = null, $headers = null, $endpointName = "connections")
 {
     $store = SBTCredentialStore::getInstance();
     $settings = new SBTSettings();
     $token = $store->getToken($endpointName);
     $response = null;
     $client = new Client($server);
     $client->setDefaultOption('verify', false);
     // If global username and password is set, then use it; otherwise use user-specific credentials
     if ($settings->getBasicAuthMethod($endpointName) == 'global') {
         $user = $settings->getBasicAuthUsername($endpointName);
         $password = $settings->getBasicAuthPassword($endpointName);
     } else {
         $user = $store->getBasicAuthUsername($endpointName);
         $password = $store->getBasicAuthPassword($endpointName);
     }
     try {
         $request = $client->createRequest($method, $service, $headers, $body, $options);
         if ($settings->forceSSLTrust($endpointName)) {
             $request->getCurlOptions()->set(CURLOPT_SSL_VERIFYHOST, false);
             $request->getCurlOptions()->set(CURLOPT_SSL_VERIFYPEER, false);
         }
         if ($method == 'POST' && isset($_FILES['file']['tmp_name'])) {
             $request->addPostFile('file', $_FILES['file']['tmp_name']);
         }
         $request->setAuth($user, $password);
         $response = $request->send();
     } catch (Guzzle\Http\Exception\BadResponseException $e) {
         $response = $e->getResponse();
     }
     return $response;
 }
예제 #2
0
 /**
  * Tests create, update and delete operations.
  */
 public function testCRUD()
 {
     $this->tearDown();
     $this->setUp();
     $settings = new SBTSettings();
     global $USER;
     global $CFG;
     $USER->id = $this->uid;
     // Create
     $_POST = $this->_prepareCreatePOST();
     require $CFG->dirroot . '/blocks/ibmsbt/endpoint_settings.php';
     // Check that endpoint really has been created
     $settings = new SBTSettings();
     // Update
     $newValue = $this->_prepareUpdatePOST();
     require $CFG->dirroot . '/blocks/ibmsbt/endpoint_settings.php';
     $settings = new SBTSettings();
     $this->assertEquals($settings->getAPIVersion($this->config['name']), $newValue);
     // Get
     $this->_prepareGet();
     require $CFG->dirroot . '/blocks/ibmsbt/endpoint_settings.php';
     // Delete
     $this->_prepareDeletePOST();
     require $CFG->dirroot . '/blocks/ibmsbt/endpoint_settings.php';
     $settings = new SBTSettings();
     $this->assertEquals($settings->getAPIVersion($this->config['name']), null);
 }
예제 #3
0
 protected function specific_definition($mform)
 {
     // Section header title according to language file.
     $mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
     // List of available samples. Note: keys must reflect relative path from
     // core/samples and must omit the .php file extension
     $plugins = array('choose' => get_string('choose_one', 'block_ibmsbt'));
     $path = str_replace('core', '', BASE_PATH) . '/user_widgets/';
     if ($handle = opendir($path)) {
         while (false !== ($file = readdir($handle))) {
             if ($file != "." && $file != "..") {
                 if (!strpos($file, '.php') && !strpos($file, '.html')) {
                     continue;
                 }
                 $widgetName = str_replace('.php', '', $file);
                 $widgetName = str_replace('-', ' ', $widgetName);
                 $plugins[$path . $file] = $widgetName;
             }
         }
         closedir($handle);
     }
     $mform->addElement('html', '<p>For documentation, tutorials and guides on how to use the Social Business SDK, go to 
     		<a href="https://www.ibmdw.net/social/">https://www.ibmdw.net/social/</a> or visit <a href="https://greenhousestage.lotus.com/sbt/sbtplayground.nsf">our playground</a>
     		 directly if you need JavaScript snippets.</p>');
     global $CFG;
     $blockPath = $CFG->dirroot . '/blocks/ibmsbt/';
     global $PAGE;
     $mform->addElement('html', '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>');
     $mform->addElement('html', '<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>');
     $PAGE->requires->js(new moodle_url($CFG->wwwroot . '/blocks/ibmsbt/views/js/endpointConfig.js'));
     ob_start();
     require $blockPath . 'views/endpointSetupDialog.php';
     $html = ob_get_clean();
     $mform->addElement('html', $html);
     $settings = new SBTSettings();
     $records = $settings->getEndpoints();
     $endpoints = array();
     foreach ($records as $record) {
         $endpoints[$record->name] = $record->name;
     }
     $mform->addElement('select', 'config_endpoint', 'Endpoint: (<a href="#" onclick="ibm_sbt_manage_endpoints();">' . get_string('click_here_to', 'block_ibmsbt') . '<strong>' . get_string('manage_your_endpoints', 'block_ibmsbt') . '</strong></a>)', $endpoints);
     $mform->setDefault('config_endpoint', 'connections');
     // Type dropdown
     $mform->addElement('select', 'config_plugin', 'Plugin:', $plugins);
     $mform->setDefault('config_plugin', 'choose');
     // Block title
     $mform->addElement('text', 'config_elementID', 'Element ID:');
     $mform->setDefault('config_elementID', 'ibm-sbt-element-' . time());
     $mform->setType('config_elementID', PARAM_MULTILANG);
     $mform->addElement('text', 'config_title', 'Title:');
     $mform->setDefault('config_title', 'default value');
     $mform->setType('config_title', PARAM_MULTILANG);
 }
예제 #4
0
 /**
  * Tests whether settings are saved correctly by simulating post
  * requests using mock data.
  */
 function test_endpoint_save_settings()
 {
     // Load mock data
     require 'mock_data.php';
     if (!class_exists('SBTEndpointUpdate')) {
         require BASE_PATH . '/controllers/SBTEndpointUpdate.php';
     }
     // Fake post request - populate it with mock data
     $_POST['endpoint_name'] = $config['wp_endpoint_2_name'];
     $_POST['endpoint_url'] = $config['wp_endpoint_2_url'];
     $_POST['consumer_key'] = $config['wp_endpoint_2_consumer_key'];
     $_POST['consumer_secret'] = $config['wp_endpoint_2_consumer_secret'];
     $_POST['authorization_url'] = $config['wp_endpoint_2_authorization_url'];
     $_POST['access_token_url'] = $config['wp_endpoint_2_access_token_url'];
     $_POST['request_token_url'] = $config['wp_endpoint_2_request_token_url'];
     $_POST['authentication_method'] = $config['wp_endpoint_2_authentication_method'];
     $_POST['basic_auth_username'] = $config['wp_endpoint_2_basic_auth_username'];
     $_POST['basic_auth_password'] = $config['wp_endpoint_2_basic_auth_password'];
     $_POST['basic_auth_method'] = $config['wp_endpoint_2_basic_auth_method'];
     $_POST['sdk_deploy_url'] = $config['sdk_deploy_url'];
     $_POST['delete_endpoint'] = 'no';
     $_POST['libraries_list'] = $config['js_library'];
     // Update the endpoint
     $update = new SBTEndpointUpdate();
     // Load settings
     if (!class_exists('SBTSettings')) {
         require BASE_PATH . '/core/models/SBTSettings.php';
     }
     $settings = new SBTSettings();
     // Check that settings have been saved
     $this->assertEquals($config['wp_endpoint_2_name'], $settings->getName());
     $this->assertEquals($config['wp_endpoint_2_url'], $settings->getURL());
     $this->assertEquals($config['wp_endpoint_2_consumer_key'], $settings->getConsumerKey());
     $this->assertEquals($config['wp_endpoint_2_consumer_secret'], $settings->getConsumerSecret());
     $this->assertEquals($config['wp_endpoint_2_authorization_url'], $settings->getAuthorizationURL());
     $this->assertEquals($config['wp_endpoint_2_access_token_url'], $settings->getAccessTokenURL());
     $this->assertEquals($config['wp_endpoint_2_request_token_url'], $settings->getRequestTokenURL());
     $this->assertEquals($config['wp_endpoint_2_authentication_method'], $settings->getAuthenticationMethod());
     $this->assertEquals($config['wp_endpoint_2_basic_auth_username'], $settings->getBasicAuthUsername());
     $this->assertEquals($config['wp_endpoint_2_basic_auth_password'], $settings->getBasicAuthPassword());
     $this->assertEquals($config['wp_endpoint_2_basic_auth_method'], $settings->getBasicAuthMethod());
     $this->assertEquals($config['sdk_deploy_url'], $settings->getSDKDeployURL());
     $this->assertEquals($config['js_library'], $settings->getJSLibrary());
     // Now delete the endpoint
     $_POST['delete_endpoint'] = 'yes';
     // Perform update
     $update = new SBTEndpointUpdate();
     // Make sure that the endpoint has been deleted
     $settings = new SBTSettings();
     $this->assertNotEquals($config['wp_endpoint_2_name'], $settings->getName());
 }
예제 #5
0
 function test_js_libraries()
 {
     // Load mock data
     require 'mock_data.php';
     // Load settings
     if (!class_exists('SBTSettings')) {
         require BASE_PATH . '/core/models/SBTSettings.php';
     }
     $settings = new SBTSettings();
     $libs = $config['js_libraries'];
     foreach ($libs as $lib) {
         $viewData['deploy_url'] = $settings->getSDKDeployURL();
         $viewData['authentication_method'] = $settings->getAuthenticationMethod();
         $viewData['js_library'] = $lib;
         $viewData['url'] = $settings->getURL();
         $viewData['name'] = $settings->getName();
         $file = '../views/includes/header.php';
         @(include $file);
     }
 }
예제 #6
0
 public function makeRequest($method, $service, $header = array(), $body = null, $options = array())
 {
     $settings = new SBTSettings();
     $store = SBTCredentialStore::getInstance();
     $server = $settings->getURL($this->endpointName);
     if ($settings->getAuthenticationMethod($this->endpointName) == "basic") {
         $endpoint = new SBTBasicAuthEndpoint();
     } else {
         if ($settings->getAuthenticationMethod($this->endpointName) == "oauth2") {
             $endpoint = new SBTOAuth2Endpoint();
         } else {
             if ($settings->getAuthenticationMethod($this->endpointName) == "oauth1") {
                 $endpoint = new SBTOAuth1Endpoint();
             }
         }
     }
     // Make request
     $response = $endpoint->makeRequest($settings->getURL($this->endpointName), $service, $method, $options, $body, $header, $this->endpointName);
     $this->document = $response->getBody(TRUE);
     $this->_parseXML();
     return $this->document;
 }
 /**
  * Makes the request to the server.
  *
  * @param string $server
  * @param string $service		The rest service to access e.g. /connections/communities/all
  * @param string $method		GET, POST or PUT
  * @param string $body
  * @param string $headers
  */
 public function makeRequest($server, $service, $method, $options, $body = null, $headers = null, $endpointName = "connections")
 {
     $store = SBTCredentialStore::getInstance();
     $token = $store->getOAuthAccessToken($endpointName);
     $store = SBTCredentialStore::getInstance();
     $settings = new SBTSettings();
     $response = null;
     if ($options == null) {
         $options = array();
     }
     try {
         $client = new Client($server);
         $request = $client->createRequest($method, $service, $headers, $body, $options);
         $request->addHeader('authorization', 'Bearer ' . $token);
         if ($settings->forceSSLTrust($endpointName)) {
             $request->getCurlOptions()->set(CURLOPT_SSL_VERIFYHOST, false);
             $request->getCurlOptions()->set(CURLOPT_SSL_VERIFYPEER, false);
         }
         if ($method == 'POST' && isset($_FILES['file']['tmp_name'])) {
             $request->addPostFile('file', $_FILES['file']['tmp_name']);
         }
         $response = $request->send();
     } catch (Guzzle\Http\Exception\BadResponseException $e) {
         $response = $e->getResponse();
     }
     return $response;
 }
/**
 * Callback for creating the plugin header.
 *
 * @param unknown $args
 */
function ibm_sbtk_header($args = array())
{
    $settings = new SBTSettings();
    $store = SBTCredentialStore::getInstance();
    $endpoints = $settings->getEndpoints();
    if ($endpoints == null || empty($endpoints)) {
        return;
    }
    foreach ($endpoints as $endpoint) {
        if (($settings->getAuthenticationMethod($endpoint['name']) == 'oauth1' || $settings->getAuthenticationMethod($endpoint['name']) == 'oauth2') && $store->getOAuthAccessToken($endpoint['name']) == null && (!isset($_COOKIE['IBMSBTKOAuthLogin']) || $_COOKIE['IBMSBTKOAuthLogin'] != 'yes')) {
            $deploy_url = $settings->getSDKDeployURL($endpoint['name']);
            $authentication_method = $settings->getAuthenticationMethod($endpoint['name']);
            $js_library = $settings->getJSLibrary($endpoint['name']);
            $url = $settings->getURL($endpoint['name']);
            $name = $settings->getName($endpoint['name']);
            $api_version = $settings->getAPIVersion($endpoint['name']);
            $type = $settings->getServerType($endpoint['name']);
            $allow_client_access = $settings->allowClientAccess($endpoint['name']);
            $endpoints = $settings->getEndpoints();
            // Load the header view
            require BASE_PATH . '/views/includes/header.php';
            return;
        }
    }
    $plugin = new SBTPlugin($endpoints[0]['name']);
    $plugin->createHeader();
}
<?php

$settings = new SBTSettings();
// Ensure that element IDs are unique
$milliseconds = microtime(true) * 1000;
$timestamp = round($milliseconds);
?>
<button style="font-size: 12px;" class="btn btn-primary" onclick="window.open('<?php 
echo $settings->getURL($instance['ibm-sbtk-endpoint']);
?>
/files/app#', '_blank');"><?php 
echo $GLOBALS[LANG]['open_files'];
?>
</button><br/><br/>
<div id="<?php 
echo isset($instance['ibm-sbtk-element-id']) ? $instance['ibm-sbtk-element-id'] : $this->elID;
?>
"></div>

<?php 
if (isset($instance['ibm-sbtk-template']) && $instance['ibm-sbtk-template'] != "") {
    require BASE_PATH . "{$instance['ibm-sbtk-template']}";
} else {
    require 'templates/ibm-sbt-files-grid-row.php';
}
?>

<script type="text/javascript">
require([ "sbt/connections/ProfileService", "sbt/dom", "sbt/config", "sbt/connections/controls/files/FileGrid"], 
	function(ProfileService, dom, config, FileGrid) {
예제 #10
0
 /**
  * Makes the request to the server.
  * 
  * @param string $server	
  * @param string $service		The rest service to access e.g. /connections/communities/all
  * @param string $method		GET, POST or PUT
  * @param string $body
  * @param string $headers
  */
 public function makeRequest($server, $service, $method, $options, $body = null, $headers = null, $endpointName = "connections")
 {
     $store = SBTCredentialStore::getInstance();
     $settings = new SBTSettings();
     $random = mt_rand(0, 999999);
     $nonce = sha1($random);
     if ($store->getOAuthAccessToken($endpointName) == null) {
         $this->_getAccessToken($endpointName);
     }
     $url = $server . '/' . $service;
     $client = new Client($url);
     $client->setDefaultOption('verify', false);
     $options = array();
     $response = null;
     try {
         $request = $client->createRequest($method, $url, $headers, $body, $options);
         $request->addHeader('Authorization', 'OAuth oauth_nonce="' . $nonce . '",oauth_version="1.0", oauth_timestamp="' . time() . '",oauth_signature="' . $settings->getConsumerSecret($endpointName) . '&' . $store->getTokenSecret($endpointName) . '",oauth_signature_method="PLAINTEXT",oauth_consumer_key="' . $settings->getConsumerKey($endpointName) . '",oauth_token="' . $store->getOAuthAccessToken($endpointName) . '"');
         if ($settings->forceSSLTrust($endpointName)) {
             $request->getCurlOptions()->set(CURLOPT_SSL_VERIFYHOST, false);
             $request->getCurlOptions()->set(CURLOPT_SSL_VERIFYPEER, false);
         }
         if ($method == 'POST' && isset($_FILES['file']['tmp_name'])) {
             $request->addPostFile('file', $_FILES['file']['tmp_name']);
         }
         $response = $request->send();
     } catch (Guzzle\Http\Exception\BadResponseException $e) {
         $response = $e->getResponse();
     }
     return $response;
 }
예제 #11
0
 /**
  * Initiates the OAuth dance.
  * 
  * @param SBTSettings $settings
  */
 private function _startOAuthDance($settings)
 {
     global $USER;
     if (isset($USER->id) && $USER->id !== null) {
         setcookie('ibm-sbt-uid', $USER->id, time() + 604800);
     }
     // Check the authentication method (different dance depending on whether we are
     // using OAuth 1.0 or OAuth 2.0)
     $authMethod = $settings->getAuthenticationMethod($this->config->endpoint);
     if ($authMethod == 'oauth1') {
         // Check if we have an access token. If not, re-direct user to authentication page
         $this->loadModel('SBTCredentialStore');
         $store = SBTCredentialStore::getInstance();
         $token = $store->getRequestToken($this->config->endpoint);
         if ($token == null) {
             if (file_exists(BASE_PATH . '/core/controllers/endpoint/SBTOAuth1Endpoint.php')) {
                 include BASE_PATH . '/core/controllers/endpoint/SBTOAuth1Endpoint.php';
             }
             // Create endpoint
             $oauth = new SBTOAuth1Endpoint();
             // Send request to authenticate user (auth token is automatically being stored when callback method = authenticationCallback)
             // find out the domain:
             $domain = $_SERVER['HTTP_HOST'];
             // find out the path to the current file:
             $path = $_SERVER['SCRIPT_NAME'];
             // find out the QueryString:
             $queryString = $_SERVER['QUERY_STRING'];
             // put it all together:
             $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://";
             $url = $protocol . $domain . $path . "?" . $queryString;
             $body = null;
             if (strpos(BASE_LOCATION, 'core') !== FALSE) {
                 $body = $oauth->request($url, BASE_LOCATION . '/index.php?plugin=guzzle&class=SBTOAuth1Endpoint&method=authenticationCallback', 'POST', $this->config->endpoint);
             } else {
                 $body = $oauth->request($url, BASE_LOCATION . '/core/index.php?plugin=guzzle&class=SBTOAuth1Endpoint&method=authenticationCallback', 'POST', $this->config->endpoint);
             }
             var_dump($body);
         }
     } else {
         if ($authMethod == 'oauth2') {
             // Check if we have an access token. If not, re-direct user to authentication page
             $this->loadModel('SBTCredentialStore');
             $store = SBTCredentialStore::getInstance();
             $token = $store->getOAuthAccessToken($this->config->endpoint);
             if ($token == null) {
                 $parameters = array('response_type' => 'code', 'client_id' => $settings->getClientId($this->config->endpoint), 'callback_uri' => $settings->getOAuth2CallbackURL($this->config->endpoint));
                 $authURL = $settings->getAuthorizationURL($this->config->endpoint) . '?' . http_build_query($parameters, null, '&');
                 // If headers have already been sent, then we need to use a JavaScript re-direct
                 if (!headers_sent()) {
                     header("Location: " . $authURL);
                 } else {
                     echo '<script type="text/javascript" language="javascript">window.location = "' . $authURL . '";</script>';
                 }
             }
         }
     }
 }
예제 #12
0
// Autoloader for loading dependencies
require_once 'core/autoload.php';
// Widget registration
require_once 'ibm-sbt-widget-registration.php';
// Load base controllers
require_once 'core/system/core/BaseController.php';
require_once 'core/system/core/BasePluginController.php';
// Check database for expired sessions. Delete them
$sessions = get_option(USER_SESSIONS);
if ($sessions !== false) {
    $now = time();
    for ($i = 0; $i < sizeof($sessions); $i++) {
        $session = $sessions[$i];
        // Delete sessions that are older than seven days 604800
        if ($now - $session['created'] >= 604800) {
            delete_option($session['id']);
            unset($sessions[$i]);
            update_option(USER_SESSIONS, $sessions);
        }
    }
}
// If we are posting date to this page, then create an options update.
// Otherwise display the settings page as normal
if (isset($_POST['endpoint_name'])) {
    $settings = new SBTSettings();
    $settings->update();
} else {
    if (is_admin()) {
        $mySettingsPage = new SBTPluginSettings();
    }
}
예제 #13
0
$method = $_REQUEST['method'];
$classpath = isset($_REQUEST['classpath']) ? $_REQUEST['classpath'] : '';
$plugin = null;
// See if the user is loading a plugin
if (!empty($_REQUEST['plugin'])) {
    $plugin = $_REQUEST['plugin'];
}
// Load plugin dependencies
if ($plugin != null) {
    switch ($plugin) {
        case "guzzle":
            // Load dependencies for Guzzle
            require_once "controllers/endpoint/SBTOAuth1Endpoint.php";
            // Load properties
            require_once 'models/SBTSettings.php';
            $settings = new SBTSettings();
            //  Init the OAuth options
            $options = array('consumer_key' => $settings->getConsumerKey(), 'consumer_secret' => $settings->getConsumerSecret(), 'server_uri' => $settings->getURL(), 'request_token_uri' => $settings->getRequestTokenURL(), 'authorize_uri' => $settings->getAuthorizationURL(), 'access_token_uri' => $settings->getAccessTokenURL());
            // Instantiate controller object
            $obj = new $class($options);
            // Call method on you controller object
            call_user_func_array(array($obj, $method), array());
            break;
    }
} else {
    // Make sure that the classpath isn't blacklisted
    $blacklisted = false;
    foreach ($blacklist as $blacklistedItem) {
        if (startsWith($classpath, $blacklistedItem)) {
            $blacklisted = true;
            break;
예제 #14
0
 /**
  * Routes requests.
  * 
  * @param string server			The URL of the server to which to re-direct the request to. Uses SBTSettings if none given.
  */
 public function route($server = null)
 {
     $this->loadModel('SBTSettings');
     $this->loadModel('SBTCredentialStore');
     $proxyHelper = new SBTProxyHelper();
     $store = SBTCredentialStore::getInstance();
     $settings = new SBTSettings();
     $endpointName = $proxyHelper->determineEndpoint();
     if (!isset($_REQUEST["_redirectUrl"])) {
         // Request to check if the user is authenticated
         if (isset($_REQUEST["isAuthenticated"])) {
             $_REQUEST["_redirectUrl"] = '/files/basic/api/myuserlibrary/feed';
             //used to be /connections/files/basic/api/myuserlibrary/feed
             $_SERVER['REQUEST_METHOD'] = 'GET';
         } else {
             if (isset($_REQUEST["basicAuthLogout"])) {
                 // Logout request
                 $store->deleteBasicAuthCredentials($endpointName);
             }
         }
         if (isset($_REQUEST["OAuthLogout"])) {
             $store->deleteOAuthCredentials($endpointName);
             $timestamp = time();
             unset($_COOKIE['IBMSBTKOAuthLogin']);
             setcookie('IBMSBTKOAuthLogin', "", $timestamp - 604800);
             return;
         } else {
             return;
         }
         if (isset($_REQUEST["basicAuthLogout"])) {
             return;
         }
     }
     // Handle any file operations
     // If file operations exist, then control flow
     // will be interrupted and route() will be called
     // again
     if ($this->fileOperations()) {
         return;
     }
     $url = $_REQUEST["_redirectUrl"];
     $url = str_replace("/connections/", "", $url);
     if (isset($_REQUEST['basicAuthRequest']) && $_REQUEST['basicAuthRequest'] == 'true') {
         $store->storeBasicAuthUsername($_POST['username'], $endpointName);
         $store->storeBasicAuthPassword($_POST['password'], $endpointName);
         $result = array('status' => 200, 'result' => true);
         print_r(json_encode($result));
         return;
     }
     $method = $_SERVER['REQUEST_METHOD'];
     $options = $proxyHelper->getOptions();
     $response = null;
     $body = file_get_contents('php://input');
     $endpoint = null;
     if ($server == null) {
         $server = $settings->getURL($endpointName);
     }
     $method = $_SERVER['REQUEST_METHOD'];
     $forwardHeader = $proxyHelper->getHeader($method);
     if ($settings->getAuthenticationMethod($endpointName) == "basic") {
         $endpoint = new SBTBasicAuthEndpoint();
     } else {
         if ($settings->getAuthenticationMethod($endpointName) == "oauth2") {
             $endpoint = new SBTOAuth2Endpoint();
         } else {
             if ($settings->getAuthenticationMethod($endpointName) == "oauth1") {
                 $endpoint = new SBTOAuth1Endpoint();
             }
         }
     }
     $url = $proxyHelper->cleanURL($url, $server);
     // Make request
     $response = $endpoint->makeRequest($server, $url, $method, $options, $body, $forwardHeader, $endpointName);
     // Print response
     $proxyHelper->outputResponse($response, $url);
 }
 /**
  * Creates the header for the SBTK plugin.
  */
 public function createHeader()
 {
     $this->loadModel('SBTSettings');
     $settings = new SBTSettings();
     $viewData['deploy_url'] = $settings->getSDKDeployURL($this->endpointName);
     $viewData['authentication_method'] = $settings->getAuthenticationMethod($this->endpointName);
     $viewData['js_library'] = $settings->getJSLibrary($this->endpointName);
     $viewData['url'] = $settings->getURL($this->endpointName);
     $viewData['name'] = $settings->getName($this->endpointName);
     $viewData['api_version'] = $settings->getAPIVersion($this->endpointName);
     $viewData['type'] = $settings->getServerType($this->endpointName);
     $viewData['allow_client_access'] = $settings->allowClientAccess($this->endpointName);
     $viewData['endpoints'] = $settings->getEndpoints();
     // Load the header view
     return $this->loadView('includes/header', $viewData);
 }
			ibm_sbt_change_new_basic_auth_method();
			$("#ibmsbtDialog").dialog("open");
	    },
	    error: function (jqXHR, textStatus, errorThrown)
	    {
	 		console.log(textStatus);
	    }
	});

}
</script>

<div id="ibm-sbt-endpoint-manager" title="Manage your endpoints" style="display: none;">
	<select id="endpoint_list" multiple="multiple" style="width: 100%;">
		<?php 
$settings = new SBTSettings();
$endpoints = $settings->getEndpoints();
foreach ($endpoints as $endpoint) {
    echo '<option value="' . $endpoint->id . '">' . $endpoint->name . ' (' . $endpoint->server_url . ')</option>';
}
?>
	</select><button onclick="ibm_sbt_new_endpoint();">Add</button> <button onclick="ibm_sbt_edit_endpoint()">Edit</button> <button onclick="ibm_sbt_remove_endpoint();">Remove</button>
</div>

<div id="ibmsbtDialog" title="Create a new endpoint" style="display: none;">
	<table>
		<tr>
			<td style="width: 200px;">
				What server do you want to connect to?
			</td>
			<td>
예제 #17
0
    /**
     * Ouputs the options form on admin
     *
     * @param array $instance The widget options
     */
    public function form($instance)
    {
        if (isset($instance['ibm-sbtk-element-id'])) {
            $this->elID = $instance['ibm-sbtk-element-id'];
        } else {
            $this->elID = "ibm-sbtk-element-" . time();
        }
        if (isset($instance['ibm-sbtk-template'])) {
            $template = $instance['ibm-sbtk-template'];
        } else {
            $template = "";
        }
        if (isset($instance['ibm-sbtk-endpoint'])) {
            $this->endpoint = $instance['ibm-sbtk-endpoint'];
        } else {
            $this->endpoint = "connections";
        }
        ?>
				<p>
					<label for="<?php 
        echo $this->get_field_id('ibm-sbtk-element-id');
        ?>
">ID:<br/><span style="font-size: 10px; color: red;">(For this widget to work, the ID must be unique)</label> 
					<input class="widefat" id="<?php 
        echo $this->get_field_id('ibm-sbtk-element-id');
        ?>
" name="<?php 
        echo $this->get_field_name('ibm-sbtk-element-id');
        ?>
" type="text" value="<?php 
        echo esc_attr($this->elID);
        ?>
"/>
				</p>
				<p>
					<label for="<?php 
        echo $this->get_field_id('ibm-sbtk-template');
        ?>
">Template<br/><span style="font-size: 10px;">(path must be relative to <?php 
        echo BASE_PATH;
        ?>
)</span>:</label> 
					<input class="widefat" id="<?php 
        echo $this->get_field_id('ibm-sbtk-template');
        ?>
" name="<?php 
        echo $this->get_field_name('ibm-sbtk-template');
        ?>
" type="text" value="<?php 
        echo esc_attr($template);
        ?>
"/>
				</p>
				
				<p>
				<label for="<?php 
        echo $this->get_field_id('ibm-sbtk-endpoint');
        ?>
"><?php 
        echo $GLOBALS[LANG]['endpoint'];
        ?>
:</label> 
				<select id="<?php 
        echo $this->get_field_id('ibm-sbtk-endpoint');
        ?>
" name="<?php 
        echo $this->get_field_name('ibm-sbtk-endpoint');
        ?>
">
					<?php 
        $settings = new SBTSettings();
        $endpoints = $settings->getEndpoints();
        foreach ($endpoints as $ep) {
            echo '<option ' . ($ep['name'] == $this->endpoint ? 'selected="selected"' : '') . ' value="' . $ep['name'] . '">' . $ep['name'] . '</option>';
        }
        ?>
				</select>
			</p>
			<?php 
    }