示例#1
1
/**
 * Processes variables for block.tpl.php.
 *
 * Prepares the values passed to the theme_block function to be passed
 * into a pluggable template engine. Uses block properties to generate a
 * series of template file suggestions. If none are found, the default
 * block.tpl.php is used.
 *
 * Most themes utilize their own copy of block.tpl.php. The default is located
 * inside "modules/block/block.tpl.php". Look in there for the full list of
 * variables.
 *
 * The $variables array contains the following arguments:
 * - $block
 *
 * @see block.tpl.php
 */
function scsmetronic_subtheme_preprocess_page(&$variables)
{
    global $user;
    if (variable_get('scsmetronic_redirect_to_login') && $user->uid == 0 && arg(0) != 'user') {
        //header('Location: ' . url('user/login', array( 'absolute' => TRUE)), TRUE, 302);
        // Handle redirection to the login form.
        // using drupal_goto() with destination set causes a recursive redirect loop
        $login_path = 'user/login';
        $code = 302;
        // The code in drupal_get_destination() doesn't preserve any query string
        // on 403 pages, so reproduce the part we want here.
        $path = isset($_GET['destination']) ? $_GET['destination'] : '<front>';
        $query = drupal_http_build_query(drupal_get_query_parameters(NULL, array('q', 'destination')));
        if ($query != '') {
            $path .= '?' . $query;
        }
        $destination = array('destination' => $path);
        header('Location: ' . url($login_path, array('query' => $destination, 'absolute' => TRUE)), TRUE, 302);
        drupal_exit();
    }
    $variables['navbar_top'] = 'navbar-static-top';
    $theme_header = theme_get_setting('theme_header', 'scsmetronic');
    if (!empty($theme_header) && $theme_header !== 'default') {
        $variables['navbar_top'] = 'navbar-fixed-top';
    }
    //Get the entire main menu tree
    $main_menu_name = theme_get_setting('theme_main_menu', 'scsmetronic');
    $main_menu_tree = menu_tree_all_data($main_menu_name);
    $user_menu_tree = menu_tree_all_data('user-menu');
    //Add the rendered output to the $main_menu_expanded variable
    $variables['main_menu_expanded'] = menu_tree_output($main_menu_tree);
    $variables['user_menu_expanded'] = menu_tree_output($user_menu_tree);
    if ($modal_form_paths = theme_get_setting('theme_modal')) {
        $modal_forms = explode("\r\n", $modal_form_paths);
        drupal_add_js(array('scsmetronic_forms_modal' => $modal_forms), 'setting');
    }
    if ($user->uid) {
        $name = theme('username', array('account' => $user, 'link_path' => NULL));
    } else {
        $name = variable_get('anonymous', t('Guest'));
    }
    $variables['loggedin_user_name'] = $name;
    $variables['image'] = scsmetronic_login_user_image($user);
}
 function verify()
 {
     $vars = $this->ipn_vars;
     $this->ipn = $this->ipn_vars;
     $vars['cmd'] = '_notify-validate';
     $options = array('headers' => array('Content-Type' => 'application/x-www-form-urlencoded'), 'method' => 'POST', 'data' => drupal_http_build_query($vars));
     $result = drupal_http_request($this->ipnLink, $options);
     $this->ipnResult = $result->data;
     if (!empty($result->error)) {
         $this->lastError = t('IPN Validation Error: @error', array('@error' => $result->error));
         return FALSE;
     } else {
         if ($result->code == 200) {
             if ($result->data == 'VERIFIED') {
                 return TRUE;
             } else {
                 $this->lastError = t('IPN Validation Failed: @error', array('@error' => $result->data));
                 return FALSE;
             }
         } else {
             // The server might be down, let's log an error but still pass the
             // validation.
             ms_core_log_error('ms_paypal_wps', 'The Validation Server had an error processing a request. Request: !request Response: !response', array('!request' => ms_core_print_r($options), '!response' => ms_core_print_r($result)), WATCHDOG_CRITICAL);
             return TRUE;
         }
     }
 }
 public static function authenticateInstagramCredentials($instagramBookModel, $code)
 {
     global $base_url;
     $url = "https://api.instagram.com/oauth/access_token";
     $data = array('client_id' => $instagramBookModel->instagram_client_id, 'client_secret' => $instagramBookModel->instagram_client_secret, 'grant_type' => 'authorization_code', 'redirect_uri' => $base_url . "/" . ADMIN_URL, 'code' => $code);
     $options = array('method' => 'POST', 'data' => drupal_http_build_query($data), 'timeout' => 15, 'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'));
     $response = drupal_http_request($url, $options);
     return json_decode($response->data);
 }
示例#4
0
 /**
  * Implements AcsfMessage::sendMessage().
  */
 protected function sendMessage($url, $method, $endpoint, array $parameters, $username, $password)
 {
     $useragent = sprintf('%s.%s %s', $this->ahSite, $this->ahEnv, gethostname());
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_USERAGENT, $useragent);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $password);
     // @todo can we remove this in prod?
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
     // If it is not a GET request, set the method here.
     if ($method != 'GET') {
         curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
     }
     // If we are sending parameters, set the query string or POST fields here.
     $query_string = '';
     if ($method == 'GET' && !empty($parameters)) {
         $query_string = '?' . drupal_http_build_query($parameters);
     } elseif (!empty($parameters)) {
         $data_string = json_encode($parameters);
         curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
         curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string)));
     }
     $full_url = sprintf('%s/%s%s', $url, $endpoint, $query_string);
     curl_setopt($curl, CURLOPT_URL, $full_url);
     $attempts = 0;
     $response = FALSE;
     while (!$response && ++$attempts <= $this->retryMax) {
         $response = curl_exec($curl);
         if (!$response) {
             $error = curl_error($curl);
             watchdog('AcsfMessageRest', $error, array(), WATCHDOG_ERROR);
             sleep($this->retryWait);
         }
     }
     if (!$response) {
         throw new AcsfMessageFailureException(sprintf('Error reaching url "%s" with method "%s." Returned error "%s."', $full_url, $method, $error));
     }
     $response_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     curl_close($curl);
     $response_body = json_decode($response, TRUE);
     return new AcsfMessageResponseRest($endpoint, $response_code, $response_body);
 }
示例#5
0
文件: install.php 项目: blipp/drupal
/**
 * Return the URL that should be redirected to during an installation request.
 *
 * The output of this function is suitable for sending to install_goto().
 *
 * @param $install_state
 *   An array of information about the current installation state.
 * @return
 *   The URL to redirect to.
 *
 * @see install_full_redirect_url()
 */
function install_redirect_url($install_state)
{
    return 'install.php?' . drupal_http_build_query($install_state['parameters']);
}
 /**
  * Util function for building a Petfinder API request URL
  */
 protected function _build_request_url($method, $args)
 {
     // Tack on the API key and format if not already manually set
     $args['key'] = $this->api_key;
     $args['format'] = 'json';
     // If we've got a session token, generate the request signature using the secret key
     if (!empty($this->token)) {
         $args['token'] = $this->token;
         $args['sig'] = md5($this->secret_key . drupal_http_build_query($args));
     }
     // Build the URL from the final argument list
     $url = 'http://api.petfinder.com/' . $method . '?' . drupal_http_build_query($args);
     return $url;
 }
示例#7
0
 /**
  * Executes a Twitter Search API call
  * @return string JSON encoded search response.
  */
 function search()
 {
     $this->url_query .= drupal_http_build_query($this->options);
     $ch = curl_init($this->url_query);
     // Applications must have a meaningful and unique User Agent.
     curl_setopt($ch, CURLOPT_USERAGENT, "Drupal Twitter Block Module");
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
     $twitter_data = curl_exec($ch);
     $this->http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     curl_close($ch);
     return $twitter_data;
 }
 public function doGet($parameters, $addDownload = true)
 {
     //drupal_http_build_query($parameters);
     $options['headers']['Content-Type'] = 'application/json';
     $options['headers']['Accept-Encoding'] = 'gzip, deflate';
     $options['method'] = 'get';
     //'post';
     //$options['data'] = drupal_http_build_query($parameters);//json_encode($send);
     $options['timeout'] = 3000000000.0;
     global $DEBUG;
     if ($DEBUG) {
         $f = fopen("/tmp/proxyPost.log", "a");
         fwrite($f, "CALL: GET='" . var_export($options, TRUE) . "'\n");
     }
     $postServer = $this->server;
     if ($addDownload) {
         $postServer .= '/download';
     }
     //Hack to  test if get works like this.
     $postServer .= "?" . drupal_http_build_query($parameters);
     $result = _bim_http_request($postServer, $options);
     //bimserverJsonConnector::_bim_http_request($postServer, $options);
     if ($result->headers['Content-Encoding'] == 'gzip' || $result->headers['content-encoding'] == 'gzip') {
         $result->data2 = substr($result->data, 10);
         $result->data3 = gzinflate(substr($result->data, 10));
         $result->data = drupal_json_decode(gzinflate(substr($result->data, 10)));
         if (isset($result->headers['Content-Encoding'])) {
             unset($result->headers['Content-Encoding']);
             $result->headers['Content-Encoding'] = "text/plain";
         }
         if (isset($result->headers['content-encoding'])) {
             unset($result->headers['content-encoding']);
             $result->headers['content-encoding'] = "text/plain";
         }
         //$result->headers['Content-Encoding'] = "text/plain";
     }
     if ($DEBUG) {
         fwrite($f, "AWNS: \t'" . var_export($result, TRUE) . "'\n");
         fclose($f);
     }
     //dsm($result);
     /*
         if ($shorten) {
           if (empty($result->data)) {
             $result = $result; //->data;
           }
           else {
             $result = drupal_json_decode($result->data);
           }
         }
         else {
           if (!empty($result->data)) {
             $result->data = drupal_json_decode($result->data);
           }
         }*/
     return $result;
 }
示例#9
0
/**
 *
 */
function _bvng_get_destination($req_path)
{
    $destination =& drupal_static(__FUNCTION__);
    if (isset($destination)) {
        return $destination;
    }
    if (isset($_GET['destination'])) {
        $destination = array('destination' => $_GET['destination']);
    } else {
        $path = $req_path;
        $query = drupal_http_build_query(drupal_get_query_parameters());
        if ($query != '') {
            $path .= '?' . $query;
        }
        $destination = array('destination' => $path);
    }
    return $destination;
}
示例#10
0
 /**
  * @param $path
  * @param $options
  * @return string
  */
 public static function url($path = NULL, $options = array())
 {
     // Merge in defaults.
     $options += array('fragment' => '', 'query' => array(), 'absolute' => FALSE, 'alias' => FALSE, 'prefix' => '');
     // A duplicate of the code from url_is_external() to avoid needing another
     // function call, since performance inside url() is critical.
     if (!isset($options['external'])) {
         // Return an external link if $path contains an allowed absolute URL. Avoid
         // calling drupal_strip_dangerous_protocols() if there is any slash (/),
         // hash (#) or question_mark (?) before the colon (:) occurrence - if any -
         // as this would clearly mean it is not a URL. If the path starts with 2
         // slashes then it is always considered an external URL without an explicit
         // protocol part.
         $colonpos = strpos($path, ':');
         $options['external'] = strpos($path, '//') === 0 || $colonpos !== FALSE && !preg_match('![/?#]!', substr($path, 0, $colonpos)) && drupal_strip_dangerous_protocols($path) == $path;
     }
     // Preserve the original path before altering or aliasing.
     $original_path = $path;
     // Allow other modules to alter the outbound URL and options.
     // drupal_alter('url_outbound', $path, $options, $original_path);
     if (isset($options['fragment']) && $options['fragment'] !== '') {
         $options['fragment'] = '#' . $options['fragment'];
     }
     if ($options['external']) {
         // Split off the fragment.
         if (strpos($path, '#') !== FALSE) {
             list($path, $old_fragment) = explode('#', $path, 2);
             // If $options contains no fragment, take it over from the path.
             if (isset($old_fragment) && !$options['fragment']) {
                 $options['fragment'] = '#' . $old_fragment;
             }
         }
         // Append the query.
         if ($options['query']) {
             $path .= (strpos($path, '?') !== FALSE ? '&' : '?') . drupal_http_build_query($options['query']);
         }
         if (isset($options['https']) && variable_get('https', FALSE)) {
             if ($options['https'] === TRUE) {
                 $path = str_replace('http://', 'https://', $path);
             } elseif ($options['https'] === FALSE) {
                 $path = str_replace('https://', 'http://', $path);
             }
         }
         // Reassemble.
         return $path . $options['fragment'];
     }
     // Strip leading slashes from internal paths to prevent them becoming external
     // URLs without protocol. /example.com should not be turned into
     // //example.com.
     $path = ltrim($path, '/');
     global $base_url, $base_secure_url, $base_insecure_url;
     // The base_url might be rewritten from the language rewrite in domain mode.
     if (!isset($options['base_url'])) {
         $options['base_url'] = 'http://amazons3.example.com';
     }
     // The special path '<front>' links to the default front page.
     if ($path == '<front>') {
         $path = '';
     }
     $base = $options['absolute'] ? $options['base_url'] . '/' : base_path();
     $prefix = empty($path) ? rtrim($options['prefix'], '/') : $options['prefix'];
     $path = static::drupal_encode_path($prefix . $path);
     if ($options['query']) {
         return $base . $path . '?' . drupal_http_build_query($options['query']) . $options['fragment'];
     } else {
         return $base . $path . $options['fragment'];
     }
 }
示例#11
0
 /**
  * This function will retrieve a new
  * single use token from stripe. Helpful
  * for if you are doing a lot of repetitive testing.
  *
  * Note, you will need Guzzle for this. Hopefully you
  * are already using composer. If not, what are you doing?
  */
 public static function getStripeToken($param = array())
 {
     //$client = new \GuzzleHttp\Client();
     $pubKey = variable_get('mp_stripe_public', 'pk_test_jLHDb7FuCHiWnVVr03QnyVBV');
     $cardNumber = isset($param['credit_card']['number']) ? $param['credit_card']['number'] : "4242424242424242";
     $cvc = isset($param['credit_card']['code']) ? $param['credit_card']['code'] : "123";
     $expMonth = isset($param['credit_card']['exp_month']) ? $param['credit_card']['exp_month'] : "11";
     $expYear = isset($param['credit_card']['exp_year']) ? $param['credit_card']['exp_year'] : "2018";
     $headers = ['Pragma' => 'no-cache', 'Origin' => 'https://js.stripe.com', 'Accept-Encoding' => 'gzip, deflate', 'Accept-Language' => 'en-US,en;q=0.8', 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36', 'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json', 'Cache-Control' => 'no-cache', 'Referer' => 'https://js.stripe.com/v2/channel.html?stripe_xdm_e=http%3A%2F%2Fwww.beanstalk.dev&stripe_xdm_c=default176056&stripe_xdm_p=1', 'Connection' => 'keep-alive'];
     $postBody = ['key' => $pubKey, 'payment_user_agent' => 'stripe.js/Fbebcbe6', 'card[number]' => $cardNumber, 'card[cvc]' => $cvc, 'card[exp_month]' => $expMonth, 'card[exp_year]' => $expYear];
     // if drupal_http_request not response data then we need to make this call again and again three time.
     for ($i = 0; $i < 3; $i++) {
         $response = drupal_http_request('https://api.stripe.com/v1/tokens', array('headers' => $headers, 'method' => 'POST', 'data' => drupal_http_build_query($postBody), 'timeout' => 120));
         if ($response->code == 200) {
             $response = drupal_json_decode($response->data);
             return new Response(TRUE, $response['id'], "");
         }
     }
     $response_date = json_decode($response->data);
     return new Response(FALSE, $response_date->error->message, $response_date->error->message);
 }
 /**
  * Run the query and return a result.
  *
  * @return
  *  Remote entity objects as retrieved from the remote connection.
  */
 function execute()
 {
     // If there are any validation errors, don't perform a search.
     if (form_set_error()) {
         return array();
     }
     $querystring = array();
     $path = variable_get($this->base_entity_type . '_resource_name', '');
     // Iterate through all of the conditions and add them to the query.
     if (isset($this->conditions[$this->remote_base])) {
         foreach ($this->conditions[$this->remote_base] as $condition) {
             switch ($condition['field']) {
                 case 'event_id':
                     $querystring['eventId'] = $condition['value'];
                     break;
                 case 'login_id':
                     $querystring['userId'] = $condition['value'];
                     break;
             }
         }
     }
     // "From date" parameter.
     if (isset($this->from_date)) {
         $querystring['startDate'] = $this->from_date;
     }
     // "To date" parameter.
     if (isset($this->to_date)) {
         $querystring['endDate'] = $this->to_date;
     }
     // Add user id based filter if present.
     if (isset($this->user_id)) {
         $querystring['userId'] = $this->user_id;
     }
     // Assemble all of the query parameters.
     if (count($querystring)) {
         $path .= '?' . drupal_http_build_query($querystring);
     }
     // Make the request.
     try {
         $response = $this->connection->makeRequest($path, 'GET');
     } catch (Exception $e) {
         if ($e->getCode() == OUR_REST_LOGIN_REQUIRED_NO_SESSION) {
             drupal_set_message($e->getMessage());
             drupal_goto('user/login', array('query' => drupal_get_destination()));
         } elseif ($e->getCode() == OUR_REST_LOGIN_REQUIRED_TOKEN_EXPIRED) {
             // Logout
             global $user;
             module_invoke_all('user_logout', $user);
             session_destroy();
             // Redirect
             drupal_set_message($e->getMessage());
             drupal_goto('user/login', array('query' => drupal_get_destination()));
         }
     }
     switch ($this->base_entity_type) {
         case 'siteshortname_entities_remote_event':
             $entities = $this->parseEventResponse($response);
             break;
     }
     // Return the list of results.
     return $entities;
 }
 /**
  * Implements OpenIDConnectClientInterface::retrieveIDToken().
  */
 public function retrieveTokens($authorization_code)
 {
     // Exchange `code` for access token and ID token.
     $redirect_uri = OPENID_CONNECT_REDIRECT_PATH_BASE . '/' . $this->name;
     $post_data = array('code' => $authorization_code, 'client_id' => $this->getSetting('client_id'), 'client_secret' => $this->getSetting('client_secret'), 'redirect_uri' => url($redirect_uri, array('absolute' => TRUE)), 'grant_type' => 'authorization_code');
     $request_options = array('method' => 'POST', 'data' => drupal_http_build_query($post_data), 'timeout' => 15, 'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'));
     $endpoints = $this->getEndpoints();
     $response = drupal_http_request($endpoints['token'], $request_options);
     if (!isset($response->error) && $response->code == 200) {
         $response_data = drupal_json_decode($response->data);
         return array('id_token' => $response_data['id_token'], 'access_token' => $response_data['access_token'], 'expire' => REQUEST_TIME + $response_data['expires_in']);
     } else {
         openid_connect_log_request_error(__FUNCTION__, $this->name, $response);
         return FALSE;
     }
 }