PageRenderTime 26ms CodeModel.GetById 16ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/plugin/PBAPI/PBAPI/Response/json.php

https://bitbucket.org/chamilo/chamilo-ext-repo-photobucket-dev/
PHP | 72 lines | 28 code | 8 blank | 36 comment | 2 complexity | 39e74bc456c1201977334bce3687c293 MD5 | raw file
 1<?php
 2use common\libraries\Path;
 3/**
 4 * Photobucket API 
 5 * Fluent interface for PHP5
 6 * json response parser
 7 * 
 8 * @author Photobucket
 9 * @package PBAPI
10 * @subpackage Response
11 * 
12 * @copyright Copyright Copyright (c) 2008, Photobucket, Inc.
13 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
14 */
15
16/**
17 * Load Response parent
18 */
19require_once dirname(__FILE__) . '/../Response.php';
20
21/**
22 * Response json format parser
23 *
24 * Requires either the JSON extension, or the Services_JSON class from PEAR
25 * 
26 * @package PBAPI
27 * @subpackage Response
28 */
29class PBAPI_Response_json extends PBAPI_Response
30{
31
32    /**
33     * Do JSON parse
34     *
35     * @param string $response_string string to parse
36     * @param bool $onlycontent only return content 'node'
37     * @return array associative array of response data
38     */
39    public function parse($string, $onlycontent = false)
40    {
41        $result = array();
42        
43        if (function_exists('json_decode'))
44        {
45            $result = json_decode($string, true);
46        }
47        else
48        {
49            //compatibility using PEAR
50            require_once ('Services/JSON.php');
51            $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
52            $result = $json->decode($string);
53        }
54        
55        $this->detectException($result);
56        
57        if ($onlycontent)
58            return @$result['content'];
59        return $result;
60    }
61
62    /**
63     * Returns optimal format string for given parser
64     *
65     * @return string
66     */
67    public function getFormat()
68    {
69        return 'json';
70    }
71
72}