示例#1
0
文件: api.php 项目: philum/cms
function api_j($p, $o = '', $res = '')
{
    req('api,pop,art,spe,tri,mod');
    list($p, $o) = ajxp($res, $p, $o);
    $ret = api_call($p, $o);
    return $ret;
}
示例#2
0
function api_content(&$a)
{
    if (App::$cmd == 'api/oauth/authorize') {
        /* 
         * api/oauth/authorize interact with the user. return a standard page
         */
        App::$page['template'] = "minimal";
        // get consumer/client from request token
        try {
            $request = OAuth1Request::from_request();
        } catch (Exception $e) {
            echo "<pre>";
            var_dump($e);
            killme();
        }
        if (x($_POST, 'oauth_yes')) {
            $app = oauth_get_client($request);
            if (is_null($app)) {
                return "Invalid request. Unknown token.";
            }
            $consumer = new OAuth1Consumer($app['client_id'], $app['pw'], $app['redirect_uri']);
            $verifier = md5($app['secret'] . local_channel());
            set_config("oauth", $verifier, local_channel());
            if ($consumer->callback_url != null) {
                $params = $request->get_parameters();
                $glue = "?";
                if (strstr($consumer->callback_url, $glue)) {
                    $glue = "?";
                }
                goaway($consumer->callback_url . $glue . "oauth_token=" . OAuth1Util::urlencode_rfc3986($params['oauth_token']) . "&oauth_verifier=" . OAuth1Util::urlencode_rfc3986($verifier));
                killme();
            }
            $tpl = get_markup_template("oauth_authorize_done.tpl");
            $o = replace_macros($tpl, array('$title' => t('Authorize application connection'), '$info' => t('Return to your app and insert this Securty Code:'), '$code' => $verifier));
            return $o;
        }
        if (!local_channel()) {
            //TODO: we need login form to redirect to this page
            notice(t('Please login to continue.') . EOL);
            return login(false, 'api-login', $request->get_parameters());
        }
        //FKOAuth1::loginUser(4);
        $app = oauth_get_client($request);
        if (is_null($app)) {
            return "Invalid request. Unknown token.";
        }
        $tpl = get_markup_template('oauth_authorize.tpl');
        $o = replace_macros($tpl, array('$title' => t('Authorize application connection'), '$app' => $app, '$authorize' => t('Do you want to authorize this application to access your posts and contacts, and/or create new posts for you?'), '$yes' => t('Yes'), '$no' => t('No')));
        //echo "<pre>"; var_dump($app); killme();
        return $o;
    }
    echo api_call($a);
    killme();
}
 private function refresh_metadata() {
     $res = api_call('GET', $this->index_url, array());  
     $this->metadata = json_decode($res->response);
     return $this->metadata;
 }
示例#4
0
function api_call()
{
    try {
        $method_array = array();
        //if(SC::getParam("controller")) $method_array[] = SC::getParam("controller");
        //if(SC::getParam("action")) $method_array[] = SC::getParam("action");
        $uri = $_SERVER["REQUEST_URI"];
        $route_parts = SCRoutes::parseUrl(true);
        if (!$route_parts) {
            throw new Exception("This api page does not exist", 404);
        }
        //var_dump($route_parts);
        $_GET = array_merge($_GET, $route_parts);
        $method_array[] = $route_parts["controller"];
        $method_array[] = $route_parts["action"];
        $methodname = implode("_", $method_array);
        $api = new SCApi();
        if (method_exists($api, $methodname)) {
            $resp = $api->{$methodname}();
            return $api->handleResponse($resp, $methodname);
        } else {
            throw new APIException("This method ({$methodname}) does not exist in the API", 404);
        }
    } catch (Exception $ex) {
        $code = $ex->getCode() or $code = 400;
        header($ex->getMessage(), true, $code);
        return $ex->getMessage();
    }
}
echo api_call();
示例#5
0
 function postToChannel($text, $extra)
 {
     $this->log[] = array('type' => 'message_post', 'text' => $text, 'extra' => $extra);
     $params = array('text' => $text, 'parse' => 'none', 'channel' => '#general', 'icon_url' => $this->iconUrl(48, true));
     $map_params = array('channel', 'username', 'attachments', 'unfurl_links', 'icon_url', 'icon_emoji');
     foreach ($map_params as $p) {
         if (isset($extra[$p])) {
             if ($p == 'attachments') {
                 $params[$p] = json_encode($extra[$p]);
             } else {
                 $params[$p] = $extra[$p];
             }
         }
     }
     $ret = api_call('chat.postMessage', $params);
     return $ret;
 }
示例#6
0
function api_channels_list()
{
    $ret = api_call('channels.list');
    $channels = array();
    foreach ($ret['data']['channels'] as $row) {
        if (!$row['is_archived']) {
            $channels[$row['id']] = '#' . $row['name'];
        }
    }
    return $channels;
}
示例#7
0
function loop_setup($file_type, $target_array)
{
    $api_return = api_call($target_array[id], $target_array[info]);
    if ($target_array[object] === 'effort') {
        $ride_name = $api_return->{$target_array}[object]->segment->name;
    } else {
        $ride_name = $api_return->{$target_array}[object]->name;
    }
    $offset_date = $api_return->{$target_array}[object]->startDate;
    $utc_offset = $api_return->{$target_array}[object]->timeZoneOffset;
    $total_time = $api_return->{$target_array}[object]->elapsedTime;
    $total_dist = $api_return->{$target_array}[object]->distance;
    //TCX FORMAT REQUIRES AVG HR, MAX HR, AVG CADENCE
    if ($file_type === 'TCX' and $target_array[object] !== 'segment') {
        $stream_return = api_call($target_array[id], $target_array[stream]);
        if ($stream_return->heartrate !== NULL) {
            $hr_avg = array_avg($stream_return->heartrate);
            $hr_max = max($stream_return->heartrate);
        }
        if ($stream_return->cadence !== NULL) {
            $cadence = array_avg($stream_return->cadence);
        }
    }
    $start_epoch = gps_to_epoch($offset_date) - $utc_offset;
    $ride_date = gps_date($start_epoch);
    $export_date = gps_date(time());
    if ($target_array[object] === 'segment') {
        $ride_date = $export_date;
        $total_time = 0;
        $hr_avg = NULL;
        $hr_max = NULL;
        $cadence = NULL;
    }
    $ride_data_array = array('export_date' => $export_date, 'ride_name' => $ride_name, 'ride_date' => $ride_date, 'total_time' => $total_time, 'total_distance' => $total_dist, 'hr_avg' => $hr_avg, 'hr_max' => $hr_max, 'cadence' => $cadence);
    return $ride_data_array;
}
示例#8
0
文件: ajax.php 项目: philum/cms
     }
     $t = suj_of_id($id);
     $s = prma('content') + 20;
     $nl = 'nlpop';
     $ret = art_read_b($id, '', 3, '');
     break;
 case "popartmod":
     req('mod,spe,art,pop,tri,boot');
     deductions_from_read($id, '');
     $ret = build_art_mod('');
     $t = nms(39);
     $s = 440;
     break;
 case "api":
     req('api,art,pop,tri,spe,mod');
     $ret = api_call($id, $va, $opt);
     $tt = $id;
     $s = 700;
     break;
 case "apij":
     req('api,art,pop,tri,spe');
     $ret = api_callj($id, $va, $opt);
     $tt = 'api';
     break;
 case "apicom":
     $ret = apicom($id);
     $tt = $n;
     $s = 440;
     break;
 case "modj":
     req('mod,pop,art,spe,tri');
/**
 * Change the WP login flow, by making a request to a 3rd party system first and then login the user based on the API response.
 * NOTE: In the example below, we'll ignore the main admin user.
 * 
 * @param null or WP_User or WP_Error $user
 * @param string $username
 * @param string $password
 * 
 * @return mixed
 */
function check_custom_login($user, $username, $password)
{
    $username_to_ignore = 'my_wp_admin';
    if ($username == $username_to_ignore) {
        $user = get_user_by('login', $username);
        if ($user && wp_check_password($password, $user->data->user_pass, $user->ID)) {
            return $user;
        }
        return new WP_Error('authentication_failed', __('<strong>ERROR</strong>: Username or password is not correct.'));
    }
    // make a request to a 3rd party system if user provided all of the login credentials
    if (!empty($username) && !empty($password)) {
        // NOTE: "api_call()" is a dummy function used for demo purposes only
        $response = api_call('https://api.service.net/v1/login', array('username' => $username, 'password' => $password));
        if ($response['success']) {
            $user = get_user_by('login', $username);
        } else {
            $user = new WP_Error('authentication_failed', __('<strong>ERROR</strong>: ' . trim($r['message'], '.') . '.'));
        }
    }
    return $user;
}
 function postMessage($channel, $message, $extras = array())
 {
     $params = array();
     if (!$channel) {
         return array('ok' => false, 'error' => "no channel");
     }
     $params['channel'] = $channel;
     if (!$message['text'] && !$message['attachments']) {
         return array('ok' => false, 'error' => "no text");
     }
     if ($message['text']) {
         $params['text'] = $message['text'];
     }
     if ($message['attachments']) {
         $params['attachments'] = json_encode($message['attachments']);
     }
     $this->icfg['bot_name'] ? $params['username'] = $this->icfg['bot_name'] : $this::DEFAULT_BOT_NAME;
     $this->icfg['bot_icon'] ? $params['icon_url'] = $this->icfg['bot_icon'] : ($params['icon_url'] = $this->iconUrl(48, "bot", true));
     $extra_params = array('text', 'parse', 'link_names', 'unfurl_links', 'icon_emoji');
     foreach ($extra_params as $p) {
         if (isset($extras[$p])) {
             if ($p == 'attachments') {
                 $params[$p] = json_encode($extras[$p]);
             } else {
                 $params[$p] = $extras[$p];
             }
             error_log($params[$p]);
         }
     }
     $ret = api_call('chat.postMessage', $params);
     return $ret;
 }
示例#11
0
function api_groups_list()
{
    $ret = api_call('groups.list');
    $groups = array();
    foreach ($ret['data']['groups'] as $row) {
        if (!$row['is_archived']) {
            $groups[$row['id']] = $row['name'];
        }
    }
    return $groups;
}
示例#12
0
//Ajout des card, 1 par jira
foreach ($versions_unrelease as $version_unrelease) {
    // recupere pour une version donnée, toutes les jiras existantes
    $jira_specific_version = $url_api_jira . "search/?jql=project=" . $project_name . "%20AND%20fixVersion=" . $version_unrelease . "&fields=summary,issuetype,status,fixVersions,description&maxResults=50&lang=en";
    $content_i = api_call($jira_specific_version, null, null, 'jira');
    $content_jvi = json_decode($content_i);
    if (!empty($content_jvi->issues) && isset($content_jvi->issues)) {
        foreach ($content_jvi->issues as $jira) {
            if (isset($jira->fields->fixVersions[0]->name) && isset($current_list[$jira->fields->fixVersions[0]->name])) {
                //Ajout d'une carte dans la liste specifiée.
                $jira_specific_list_create_card = "https://api.trello.com/1/lists/" . $current_list[$jira->fields->fixVersions[0]->name] . "/cards?key=" . $key_trello . "&token=" . $token_trello;
                //Titre de la carte : numero et titre
                $data = "name=" . $jira->key . ' : ' . $jira->fields->summary;
                // si bug alors label rouge, si evol label bleu
                $data .= "&desc=" . $jira->fields->description;
                var_dump($jira->fields);
                if ($jira->fields->issuetype->name == "Bug") {
                    $data .= "&labels=red";
                } elseif ($jira->fields->issuetype->name == "Improvement") {
                    $data .= "&labels=blue";
                }
                //Si la jira est fermé et donc deployé alors label vert
                if ($jira->fields->status->name == 'Closed') {
                    $data .= "&labels=green";
                }
                $abc = api_call($jira_specific_list_create_card, 'POST', $data);
            }
        }
    }
}
echo 'Trello mis a jour';