diff --git a/gist_filter.module b/gist_filter.module index 441924c..1633840 100644 --- a/gist_filter.module +++ b/gist_filter.module @@ -39,6 +39,37 @@ function gist_filter_filter_info() { } /** + * Implementation of hook_menu(). + * + */ +function gist_filter_menu() { + $items = array(); + + $items['admin/config/content/gist-filter'] = array( + 'title' => 'Gist Filter settings', + 'description' => 'Enter global settings for the Gist Filter module', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('gist_filter_config_form'), + 'access arguments' => array('administer gist filter'), + 'type' => MENU_NORMAL_ITEM, + ); + + return $items; +} + +/** + * Implementation of hook_permission(). + */ +function gist_filter_permission() { + return array( + 'administer gist filter' => array( + 'title' => t('Administer Gist Filter global settings'), + 'description' => t('Configure global settings for Gist Filter, like authentication credentials'), + ), + ); +} + +/** * Process callback for hook_filter_info(). */ function gist_filter_gist_filter_process($text, $filter, $format) { @@ -48,6 +79,27 @@ function gist_filter_gist_filter_process($text, $filter, $format) { } /** + * Settings callback for gist_filter_config_form + */ +function gist_filter_config_form() { + $form = array(); + + $form['gist_filter_username'] = array( + '#type' => 'textfield', + '#title' => 'GitHub / Gist username', + '#default_value' => variable_get('gist_filter_username', ''), + ); + $form['gist_filter_password'] = array( + '#type' => 'password', + '#title' => 'GitHub / Gist password', + '#default_value' => variable_get('gist_filter_password', ''), + '#description' => 'For security reasons, please enter your password every time.', + ); + + return system_settings_form($form); +} + +/** * Settings callback for gist_filter. */ function gist_filter_gist_filter_settings($form, $form_state, $filter, $format, $defaults) { @@ -161,8 +213,13 @@ function gist_filter_get_gist($id) { $gist = $cached->data; } else { - // Not available in the cache, so retrive the gist from Github - $url = 'https://api.github.com/gists/' . $id; + // Not available in the cache, so retrieve the gist from GitHub + $authentication = ''; + if ( ($username = variable_get('gist_filter_username', '')) && ($password = variable_get('gist_filter_password', '')) ) { + $authentication = $username . ':' . $password . '@'; + } + $url = 'https://'.$authentication.'api.github.com/gists/' . $id; + $response = drupal_http_request($url, array('headers' => array('Content-Type' => 'application/json'))); $gist = drupal_json_decode($response->data);