Example #1
0
/**
 * @param array $json
 * @param string $api_method
 * @param bool $public_req
 * @param bool $url_encode
 * @param bool $debug
 * @return mixed
 */
function api($json = array(), $url = '', $url_encode = true)
{
    /** json parameters */
    if (!empty($json)) {
        $url .= array2String($json, $url_encode);
    }
    $response_json = file_get_contents($url);
    $response_array = json_decode($response_json, true);
    return $response_array['r'];
}
Example #2
0
/**
 * @param array $json
 * @param string $api_method
 * @param bool $public_req
 * @param bool $url_encode
 * @param bool $debug
 * @return mixed
 */
function api($json = array(), $api_method = '', $public_req = false, $url_encode = true, $debug = false, $is_single = true, $is_admin = false)
{
    $identity = Zend_Auth::getInstance()->getIdentity();
    $config = Zend_Registry::get('__CONFIG__');
    $url = $config['api']['url'];
    $json_str = '';
    /** $api_method */
    if (!empty($api_method)) {
        $url .= '/' . $api_method;
    }
    /** json parameters */
    if (!empty($json)) {
        $url .= array2String($json, $url_encode);
    }
    /** if public request */
    if ($public_req) {
        $url .= '&public=true';
        /** else send token */
    } else {
        $url .= '&token=' . $identity['token']['token'];
    }
    /** @var add application_env $response_json */
    if ($is_admin) {
        $url .= '&env=k9_admin';
    } elseif ($is_single) {
        $url .= '&env=' . APPLICATION_ENV;
    } else {
        $url .= '&env=' . $_COOKIE['kennel'];
    }
    $response_json = file_get_contents($url);
    $response_array = json_decode($response_json, true);
    if ($debug) {
        d($url);
        dd($response_array);
    }
    return $response_array['r'];
}
Example #3
0
/** can be deleted
 * Generates a string out of an array.
 * This function is used at the management of the session information
 *
 * So you can store arrays in a text field of the mysql_database
 * If xml version is complete we should use this
 *
 * @return  returns a string
 */
function array2String($array)
{
    $temp_array = array();
    while (list($key, $val) = each($array)) {
        $key = ($key and !is_int($key)) ? '"' . $key . '" => ' : '';
        if (!is_array($val)) {
            $temp_array[] = $key . '"' . $val . '"';
        } else {
            $temp_array[] = $key . array2String($val);
        }
    }
    $array_string = 'array(' . implode(", ", $temp_array) . ')';
    return $array_string;
}