/** * 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(); }
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); }
$("#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> <select onchange="ibm_sbt_new_server_type_change();" id="new_server_type" name="new_server_type">
/** * 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); }
/** * 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 }