当前位置: 首页>>代码示例>>PHP>>正文


PHP drupal_json_decode函数代码示例

本文整理汇总了PHP中drupal_json_decode函数的典型用法代码示例。如果您正苦于以下问题:PHP drupal_json_decode函数的具体用法?PHP drupal_json_decode怎么用?PHP drupal_json_decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了drupal_json_decode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: doRequest

 /**
  * Do CURL request with authorization.
  *
  * @param string $resource
  *   A request action of api.
  * @param string $method
  *   A method of curl request.
  * @param string $input
  *   A data of curl request.
  *
  * @return array
  *   An associate array with respond data.
  */
 private function doRequest($resource, $method, $input)
 {
     if (!function_exists('curl_init')) {
         $msg = 'SendinBlue requires CURL module';
         watchdog('sendinblue', $msg, NULL, WATCHDOG_ERROR);
         return NULL;
     }
     $called_url = $this->baseUrl . "/" . $resource;
     $ch = curl_init($called_url);
     $auth_header = 'api-key:' . $this->apiKey;
     $content_header = "Content-Type:application/json";
     //if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
     // Windows only over-ride because of our api server.
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     //}
     curl_setopt($ch, CURLOPT_HTTPHEADER, array($auth_header, $content_header));
     //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $input);
     $data = curl_exec($ch);
     if (curl_errno($ch)) {
         watchdog('sendinblue', 'Curl error: @error', array('@error' => curl_error($ch)), WATCHDOG_ERROR);
     }
     curl_close($ch);
     return drupal_json_decode($data);
 }
开发者ID:geodesfour,项目名称:dp741,代码行数:41,代码来源:sendinblue.mailin.php

示例2: _soc_boxauth_get_code_from_box_handler

/**
 * This function is handles the callback from Box API.
 * @return string
 */
function _soc_boxauth_get_code_from_box_handler()
{
    // get query string parameters
    $qs = drupal_get_query_parameters();
    watchdog(SOC_BOXAUTH_MODULENAME, "Got code back from Box", $qs, WATCHDOG_INFO);
    // Stage post data and create http query
    $post_data = ['grant_type' => 'authorization_code', 'code' => $qs['code'], 'client_id' => variable_get(SOC_BOXAUTH_CLIENTID_VARIABLE), 'client_secret' => variable_get(SOC_BOXAUTH_CLIENTSECRET_VARIABLE)];
    $result = BoxFolderOperations::doPost('https://api.box.com/oauth2/token', $post_data, 'Content-type: application/x-www-form-urlencoded', 'QUERY');
    // save to session. Decoded json object into php array
    $_SESSION['box'] = drupal_json_decode($result);
    $_SESSION['box']['expires_time'] = time() + SOC_BOXAUTH_EXPIREOFFSET;
    // If successful, the ['box']['access_token'] will exists. Log and report
    // to user.
    if (isset($_SESSION['box']['access_token'])) {
        drupal_set_message(t(variable_get(SOC_BOXAUTH_SUCCESSMESSAGE_VARIABLE)));
        watchdog(SOC_BOXAUTH_MODULENAME, 'Successful box access_token');
        $next_steps = variable_get(SOC_BOXAUTH_NEXTSTEPS_VARIABLE, ['value' => t('Next steps...')]);
        return $next_steps['value'];
    } else {
        $message = t(variable_get(SOC_BOXAUTH_FAILUREMESSAGE_VARIABLE));
        drupal_set_message($message, 'error');
        watchdog(SOC_BOXAUTH_MODULENAME, 'Failed box access_token');
        return $message;
    }
}
开发者ID:rgoodie,项目名称:soc_boxauth,代码行数:29,代码来源:soc_boxauth_handler.inc.php

示例3: testRESTCalls

 /**
  * Tests rest calls.
  */
 public function testRESTCalls()
 {
     // Create a user account that has the required permissions to read
     // the watchdog resource via the REST API.
     $account = $this->drupalCreateUser();
     $this->drupalLogin($account);
     $response = $this->httpRequest('exampleGetCall', 'GET', NULL, $this->defaultMimeType);
     $this->assertResponse(200);
     $this->assertHeader('content-type', $this->defaultMimeType);
     $decoded_response = drupal_json_decode($response);
     $decoded_expected = array('message' => 'Hello World!');
     $this->assertIdentical($decoded_expected, $decoded_response, 'exampleGetCall response expected');
     $response = $this->httpRequest('examplePostCall', 'POST', NULL, $this->defaultMimeType);
     $decoded_response = drupal_json_decode($response);
     $decoded_expected = array('message' => array('POST call'));
     $this->assertIdentical($decoded_expected, $decoded_response, 'examplePostCall response expected');
     $arg1 = $this->randomName();
     $arg2 = $this->randomName();
     $response = $this->httpRequest("getCallArguments/{$arg1}/{$arg2}", 'GET', NULL, $this->defaultMimeType);
     $decoded_response = drupal_json_decode($response);
     $decoded_expected = array('arg1' => $arg1, 'arg2' => $arg2);
     $this->assertIdentical($decoded_expected, $decoded_response, 'getCallArguments response expected');
     $body = json_encode($decoded_expected);
     $response = $this->httpRequest("postCallArguments", 'POST', $body, $this->defaultMimeType);
     $decoded_response = drupal_json_decode($response);
     $this->assertIdentical($decoded_response, $decoded_expected, 'postCallArguments response is correct');
     $arg3 = $this->randomName();
     $arg4 = $this->randomName();
     $body = json_encode(array('body_arg1' => $arg1, 'body_arg2' => $arg2));
     $response = $this->httpRequest("postCallMixedArguments/{$arg3}/{$arg4}", 'POST', $body, $this->defaultMimeType);
     $decoded_response = drupal_json_decode($response);
     $decoded_expected = array('body_arg1' => $arg1, 'body_arg2' => $arg2, 'uri_arg1' => $arg3, 'uri_arg2' => $arg4);
     $this->assertIdentical($decoded_expected, $decoded_response, 'postCallMixedArguments response expected');
 }
开发者ID:alexku,项目名称:travisintegrationtest,代码行数:37,代码来源:AnnotationResourceExampleTest.php

示例4: test_function

/**
 * Implements functionThatShouldNotShowUp();
 */
function test_function()
{
    // Test a normal function should work properly.
    normalFunction('test data');
    // Test exceptions: start simple - call a function that doesn't exist with a space in between the function name
    // and "(".
    functionThatDoesNotExist('param1', 'param2');
    functionThatDoesNotExist2('param1', 'param2');
    // Call a function within a function.
    abc(def('abc'));
    // Use a constant, that can be misconstrued as a function potentially.
    $test_result = 3 - TEST_CONST;
    // Test referring to an object.
    $testJsonResponse = (object) array('data' => 'abc');
    $testJsonResponse->data = 'abc';
    $result = drupal_json_decode($json->data);
    // Create a reference to returned value
    $a =& reference_returner_function();
    // Static method call
    StaticTestClass::staticFunctionCall();
    // Method call
    $someInstance->someMetod();
    // Creating a class
    $a = new stdClass();
}
开发者ID:myplanetdigital,项目名称:function_mock,代码行数:28,代码来源:test_php.php

示例5: decodeJsonArray

 /**
  * Decodes a JSON string into an array.
  *
  * @param string $json
  *   A JSON string.
  *
  * @return array
  *   A PHP array.
  *
  * @throws RuntimeException
  *   Thrown if the encoded JSON does not result in an array.
  */
 public static function decodeJsonArray($json)
 {
     $parsed = drupal_json_decode($json);
     if (!is_array($parsed)) {
         throw new RuntimeException(t('The JSON is invalid.'));
     }
     return $parsed;
 }
开发者ID:EarthTeam,项目名称:earthteam.net,代码行数:20,代码来源:Utility.php

示例6: getJson

 public static function getJson($url, array $options = array())
 {
     $data = NULL;
     $response = static::cachedRequest($url, $options);
     if (empty($response->error)) {
         $data = drupal_json_decode($response->data);
         if ($data === FALSE) {
             trigger_error("Unable to decode JSON response from {$url}.", E_USER_WARNING);
         }
     }
     return $data;
 }
开发者ID:juampynr,项目名称:DrupalCampEs,代码行数:12,代码来源:HttpHelper.php

示例7: huoltopelaa2015_js_alter

/**
 * Implements hook_js_alter().
 */
function huoltopelaa2015_js_alter(&$js)
{
    $theme_path = drupal_get_path('theme', 'huoltopelaa2015');
    // The whitelist in case of single_js == TRUE, the blacklist otherwise
    $whitelist = array("sites/all/libraries/datetimepicker/jquery.datetimepicker.js", drupal_get_path('module', 'mon_scheduler') . '/mon_scheduler.js');
    // single_js means we work in a production environment, so include only
    // our single JS file, generated by gulp, and some whitelisted ones
    if (variable_get('single_js', TRUE)) {
        foreach ($js as $name => $settings) {
            // Exclude all files except for our own, and Drupal.settings
            if ($name != 'settings' && $name != $theme_path . '/dist/script.min.js' && !in_array($name, $whitelist, TRUE)) {
                unset($js[$name]);
            }
        }
        // Change its group and weight to be the first one included.
        // In that way, all other scripts whitelisted don't have to take care about
        // group and weight regarding to this global aggregate scripts which may
        // contains libraries.
        $js[$theme_path . '/dist/script.min.js']['group'] = JS_DEFAULT;
        $js[$theme_path . '/dist/script.min.js']['weight'] = -100;
    } else {
        // On development environments, we will try to populate the map.json file
        // with JS files that are included on the fly, excluding the one we generated
        $path = $theme_path . '/js/map.json';
        // Load previous list from map.json
        $contents = file_get_contents($path);
        $list = FALSE;
        if ($contents !== FALSE) {
            // We have a list, parse it
            $list = drupal_json_decode($contents);
        }
        // else reading file failed, and we won't update it programmatically, but
        // we will still remove our single file
        foreach ($js as $name => $settings) {
            if ($name == $theme_path . '/dist/script.min.js') {
                // We won't need our single file here
                unset($js[$name]);
                continue;
            }
            // If we have a list, update it
            if ($list !== FALSE && $name != 'settings' && !in_array($name, $whitelist, TRUE) && strstr($name, 'languages/fr') === FALSE) {
                // TRUE will add it, FALSE will remove it, edit the map.json file
                // directly if you need to exclude a file
                $list[$name] = isset($list[$name]) ? $list[$name] : TRUE;
            }
        }
        // Udpate map.json
        if ($list !== FALSE && defined('JSON_PRETTY_PRINT')) {
            file_put_contents($path, json_encode($list, JSON_PRETTY_PRINT) . "\n");
        }
    }
}
开发者ID:jazbah,项目名称:huoltopelaa2015,代码行数:55,代码来源:template.php

示例8: findAgent

 function findAgent($json)
 {
     $json_array = drupal_json_decode($json);
     if (!isset($json_array['mbox']) && !isset($json_array['mbox_sha1sum']) && !isset($json_array['openid']) && (!isset($json_array['account']) && !isset($json_array['account']['homePage']) && !isset($json_array['account']['name']))) {
         return 0;
     }
     $query = new EntityFieldQuery();
     $query->entityCondition('entity_type', 'tincan_agent');
     if (isset($json_array['objectType'])) {
         switch ($json_array['objectType']) {
             case 'Agent':
                 $query->propertyCondition('object_type', 'Agent');
                 break;
             case 'Group':
                 $query->propertyCondition('object_type', 'Group');
                 break;
         }
     } else {
         $query->propertyCondition('object_type', 'Agent');
     }
     if (isset($json_array['mbox'])) {
         $query->propertyCondition('mbox', $json_array['mbox']);
     }
     if (isset($json_array['mbox_sha1sum'])) {
         $query->propertyCondition('mbox_sha1sum', $json_array['mbox_sha1sum']);
     }
     if (isset($json_array['openid'])) {
         $query->propertyCondition('openid', $json_array['openid']);
     }
     if (isset($json_array['account'])) {
         if (isset($json_array['account']['homePage'])) {
             $query->propertyCondition('account_home_page', $json_array['account']['homePage']);
         }
         if (isset($json_array['account']['name'])) {
             $query->propertyCondition('account_name', $json_array['account']['name']);
         }
     }
     $result = $query->execute();
     if (isset($result['tincan_agent'])) {
         foreach ($result['tincan_agent'] as $key => $agent) {
             return $key;
         }
     } else {
         return 0;
     }
 }
开发者ID:jackrabbithanna,项目名称:tincan_lrs,代码行数:46,代码来源:State.php

示例9: send

 public function send($endpoint, $payload = array())
 {
     $this->debug('Sending data to ' . $endpoint);
     // Attach the transaction to the payload.
     $payload['transaction'] = $this->generateTransactionObject();
     // Generate the full endpoint URL.
     $request_url = trim($this->remote->url, '/') . '/' . self::ENDPOINT_PREFIX . $endpoint;
     // Generate the headers.
     $headers = $this->generateHeaders();
     // Generate the payload.
     $this->debug($payload);
     $payload = \drupal_json_encode($payload);
     // Set the payload.
     $this->payload = $payload;
     // Start the curl request.
     $handle = curl_init($request_url);
     curl_setopt($handle, CURLOPT_POST, true);
     curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($handle, CURLOPT_POSTFIELDS, $payload);
     // Execute the request and debug the output.
     $response = curl_exec($handle);
     $json = \drupal_json_decode($response);
     if ($json === null) {
         $this->debug($response);
         throw new TransactionException('Response from server was malformed. Check the recent log messages for more details. Response: ' . $response);
     } else {
         $this->debug($json);
         // Update the data for the current transaction.
         if (isset($json['transaction']['data']) && is_array($json['transaction']['data'])) {
             $this->data = $json['transaction']['data'];
         }
         // If there were messages sent back from the server, forward them to drupal_set_message.
         if (array_key_exists('messages', $json) && is_array($json['messages']) && count($json['messages']) > 0) {
             foreach ($json['messages'] as $message) {
                 drupal_set_message('[' . $this->remote->label . '] ' . $message['message'], $message['type']);
             }
         }
         return $json;
     }
 }
开发者ID:sammarks,项目名称:publisher,代码行数:41,代码来源:Transaction.php

示例10: publisher_get_payload

function publisher_get_payload()
{
    return drupal_json_decode(file_get_contents('php://input'));
}
开发者ID:sammarks,项目名称:publisher,代码行数:4,代码来源:api.php

示例11: parseBody

 /**
  * {@inheritdoc}
  */
 public function parseBody($body)
 {
     if (!($decoded_json = drupal_json_decode($body))) {
         throw new BadRequestException(sprintf('Invalid JSON provided: %s.', $body));
     }
     return $decoded_json;
 }
开发者ID:jhoffman-tm,项目名称:waldorf-deployment,代码行数:10,代码来源:FormatterJson.php

示例12: retrieveUserInfo

 /**
  * Implements OpenIDConnectClientInterface::retrieveUserInfo().
  */
 public function retrieveUserInfo($access_token)
 {
     $request_options = array('headers' => array('Authorization' => 'Bearer ' . $access_token));
     $endpoints = $this->getEndpoints();
     $response = drupal_http_request($endpoints['userinfo'], $request_options);
     if (!isset($response->error) && $response->code == 200) {
         return drupal_json_decode($response->data);
     } else {
         openid_connect_log_request_error(__FUNCTION__, $this->name, $response);
         return FALSE;
     }
 }
开发者ID:AlexMazaltov,项目名称:myauth,代码行数:15,代码来源:OpenIDConnectClientBase.class.php

示例13: decodeImageInfo

 /**
  * Helper function that decodes the image info from the corresponding field.
  *
  * @param stirng $field_name
  *   The name of the field containing the image data.
  *
  * @return array|FALSE
  *   An array of image info matching what is returned from image_get_info(),
  *   FALSE if the data is not available.
  */
 public function decodeImageInfo($field_name)
 {
     $info = FALSE;
     $info_field_name = rich_snippets_get_apachesolr_image_info_field($field_name);
     if (!empty($this->_solrFields[$info_field_name])) {
         if ($info = drupal_json_decode($this->_solrFields[$info_field_name][0])) {
             $info += array('width' => 0, 'height' => 0, 'extension' => '', 'mime_type' => '', 'file_size' => 0);
         }
     }
     return $info;
 }
开发者ID:drupalicus,项目名称:drupal-commons,代码行数:21,代码来源:ApachesolrSchemaPreprocessor.php

示例14: md_boom_multi_restore_theme_settings

/**
 * Restore Theme settings
 */
function md_boom_multi_restore_theme_settings($form, &$form_state)
{
    variable_set('theme_md_boom_multi_settings', array());
    if ($restore_file = file_save_upload('restore_file_upload')) {
        $file_content = file_get_contents($restore_file->uri);
        $restore_settings = drupal_json_decode(base64_decode(unserialize($file_content)));
        variable_set('theme_md_boom_multi_settings', $restore_settings);
        cache_clear_all();
        drupal_set_message(t('All your theme settings have been restored'));
    } elseif ($restore_file_path = $form_state['values']['restore_file_path']) {
        $restore_file_scheme = file_uri_scheme($restore_file_path);
        if ($restore_file_scheme == 'http' || $restore_file_scheme == 'https') {
            $restore_file_url = rawurldecode($restore_file_path);
            $restore_file_content = file_get_contents($restore_file_url);
            $restore_settings = drupal_json_decode(base64_decode(unserialize($restore_file_content)));
            variable_set('theme_md_boom_multi_settings', $restore_settings);
            cache_clear_all();
            drupal_set_message(t('All your theme settings have been restored'));
        } else {
            $restore_file_content = file_get_contents($restore_file_path);
            $restore_settings = drupal_json_decode(base64_decode(unserialize($restore_file_content)));
            variable_set('theme_md_boom_multi_settings', $restore_settings);
            cache_clear_all();
            drupal_set_message(t('All your theme settings have been restored'));
        }
    }
}
开发者ID:reasonat,项目名称:pukka,代码行数:30,代码来源:theme-settings.php

示例15: populate

 private function populate()
 {
     $json = $this->notation;
     $json_array = drupal_json_decode($json);
     dsm($json_array);
     // Object Type
     if (isset($json_array['objectType'])) {
         if ($json_array['objectType'] == 'Activity') {
         } else {
             // some kind of validation error
         }
     } else {
         $this->object_type = 'Activity';
     }
     // activity_id
     if (isset($json_array['id'])) {
         $this->activity_id = $json_array['id'];
     }
     // Definition
     if (isset($json_array['definition'])) {
         // Name
         if (isset($json_array['definition']['name'])) {
             // full name language map as json
             $this->name_json = drupal_json_encode($json_array['definition']['name']);
             // US English name
             if (isset($json_array['definition']['name']['en-US'])) {
                 $this->name_en_us = $json_array['definition']['name']['en-US'];
             }
         }
         // Description
         if (isset($json_array['definition']['description'])) {
             // full description language map as json
             $this->description_json = drupal_json_encode($json_array['definition']['description']);
             // US English description
             if (isset($json_array['definition']['description']['en-US'])) {
                 $this->description_en_us = $json_array['definition']['description']['en-US'];
             }
         }
         // type
         if (isset($json_array['definition']['type'])) {
             $this->type = $json_array['definition']['type'];
         }
         // more_info
         if (isset($json_array['definition']['moreInfo'])) {
             $this->more_info = $json_array['definition']['moreInfo'];
         }
         // extensions
         if (isset($json_array['definition']['extensions'])) {
             $this->type = drupal_json_encode($json_array['definition']['extensions']);
         }
         //interaction_type
         if (isset($json_array['definition']['interactionType'])) {
             $this->interaction_type = $json_array['definition']['interactionType'];
         }
         // correct_responses_pattern
         if (isset($json_array['definition']['correctResponsesPattern'])) {
             $this->correct_responses_pattern = drupal_json_encode($json_array['definition']['correctResponsesPattern']);
         }
         //Next the interaction fields
         $this->interaction_components_json = '';
         $intact_type = array('choices', 'scale', 'source', 'steps', 'target');
         foreach ($intact_type as $type) {
             if (isset($json_array['definition'][$type]) && is_array($json_array['definition'][$type])) {
                 if (!isset($json_array['definition'][$type][0])) {
                     $this->{'tincan_interaction_com_' . $type}[LANGUAGE_NONE][0]['json'] = drupal_json_encode($json_array['definition'][$type]);
                     $this->interaction_components_json .= ' ' . drupal_json_encode($item) . ' ';
                     if (isset($json_array['definition'][$type]['id'])) {
                         $this->{'tincan_interaction_com_' . $type}[LANGUAGE_NONE][0]['id'] = $json_array['definition'][$type]['id'];
                     }
                     if (isset($json_array['definition'][$type]['description'])) {
                         $this->{'tincan_interaction_com_' . $type}[LANGUAGE_NONE][0]['description'] = drupal_json_encode($json_array['definition'][$type]['description']);
                     }
                     if (isset($json_array['definition'][$type]['description']['en-US'])) {
                         $this->{'tincan_interaction_com_' . $type}[LANGUAGE_NONE][0]['description_en_us'] = $json_array['definition'][$type]['description']['en-US'];
                     }
                 } else {
                     $count = 0;
                 }
                 foreach ($json_array['definition'][$type] as $key => $item) {
                     $this->{'tincan_interaction_com_' . $type}[LANGUAGE_NONE][$count]['json'] = drupal_json_encode($item);
                     $this->interaction_components_json .= ' ' . drupal_json_encode($item) . ' ';
                     if (isset($item['id'])) {
                         $this->{'tincan_interaction_com_' . $type}[LANGUAGE_NONE][$count]['id'] = $item['id'];
                     }
                     if (isset($item['description'])) {
                         $this->{'tincan_interaction_com_' . $type}[LANGUAGE_NONE][$count]['description'] = drupal_json_encode($item['description']);
                     }
                     if (isset($item['description']['en-US'])) {
                         $this->{'tincan_interaction_com_' . $type}[LANGUAGE_NONE][$count]['description_en_us'] = $item['description']['en-US'];
                     }
                     $count += 1;
                 }
                 //end else
             }
             //end if isset(type)
         }
         // end foreach type
     }
     //end if isset(definition)
 }
开发者ID:jackrabbithanna,项目名称:tincan_lrs,代码行数:100,代码来源:Activity.php


注:本文中的drupal_json_decode函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。