本文整理汇总了PHP中build_query函数的典型用法代码示例。如果您正苦于以下问题:PHP build_query函数的具体用法?PHP build_query怎么用?PHP build_query使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了build_query函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: api
public function api($endpoint = '', $params = array(), $method = 'post')
{
// No endpoint = no query
if (!$endpoint) {
return;
}
// Parameters must be an array
if (!is_array($params)) {
return;
}
// Only valid methods allowed
if (!in_array($method, array('post', 'get', 'delete'))) {
return;
}
// Set up query URL
$url = $this->api_url . $endpoint;
// Set up request arguments
$args['headers'] = array('Authorization' => 'Basic ' . base64_encode($this->settings['api_key'] . ':'));
$args['sslverify'] = true;
$args['timeout'] = 60;
$args['user-agent'] = 'WooCommerce/' . WC()->version;
// Process request based on method in use
switch ($method) {
case 'post':
if (!empty($params)) {
$params = json_encode($params);
$args['body'] = $params;
$args['headers']['Content-Length'] = strlen($args['body']);
}
$args['headers']['Content-Type'] = 'application/json';
$args['headers']['Content-Length'] = strlen($args['body']);
$response = wp_remote_post($url, $args);
break;
case 'get':
$param_string = '';
if (!empty($params)) {
$params = array_map('urlencode', $params);
$param_string = build_query($params);
}
if ($param_string) {
$url = $url . '?' . $param_string;
}
$response = wp_remote_get($url, $args);
break;
case 'delete':
$args['method'] = "DELETE";
$response = wp_remote_request($url, $args);
break;
}
// Return null if WP error is generated
if (is_wp_error($response)) {
return;
}
// Return null if query is not successful
if ('200' != $response['response']['code'] || !isset($response['body']) || !$response['body']) {
return;
}
// Return response object
return json_decode($response['body']);
}
示例2: wp_get_cat_archives
function wp_get_cat_archives($opts, $cat)
{
$args = wp_parse_args($opts, array('echo' => '1'));
// default echo is 1.
// 与えられた $opts を解析して配列に入れ、第2引数 と結合
$echo = $args['echo'] != '0';
// remember the original echo flag.
$args['echo'] = 0;
$args['cat'] = $cat;
$archives = wp_get_archives(build_query($args));
// アーカイブ取得 // 連想配列からページ用のクエリー文字列を作る
$archs = explode('</li>', $archives);
// 配列化した変数
$links = array();
foreach ($archs as $archive) {
$link = preg_replace("/href='([^']+)'/", "href='\$1?cat={$cat}'", $archive);
// 正規表現での置き換え
array_push($links, $link);
// 配列の末尾に値を追加
}
$result = implode('</li>', $links);
// 配列を連結して1つの文字列に
if ($echo) {
echo $result;
} else {
return $result;
}
}
示例3: requestVerificationCode
/**
* The authorization sequence begins when your application redirects a browser to a Google URL;
* the URL includes query parameters that indicate the type of access being requested.
*
* As in other scenarios, Google handles user authentication, session selection, and user consent.
* The result is an authorization code, which Google returns to your application in a query string.
*
* (non-PHPdoc)
*
* @see PostmanAuthenticationManager::requestVerificationCode()
*/
public function requestVerificationCode($transactionId)
{
$params = array('response_type' => 'code', 'redirect_uri' => urlencode($this->getCallbackUri()), 'client_id' => $this->getClientId(), 'state' => $transactionId, 'language' => get_locale());
$authUrl = $this->getAuthorizationUrl() . '?' . build_query($params);
$this->getLogger()->debug('Requesting verification code from Yahoo');
PostmanUtils::redirect($authUrl);
}
示例4: grab_articles
function grab_articles($f, $o, $ot, $offset, $limit)
{
global $_time_intervals;
global $_sortable_fields;
list($conds, $params) = build_query($f);
// make sure ordering params are sensible
$o = strtolower($o);
assert(in_array($o, $_sortable_fields));
$ot = strtolower($ot);
assert($ot == 'asc' || $ot == 'desc');
$from_clause = " FROM (article a INNER JOIN organisation o ON o.id=a.srcorg)\n";
$where_clause = '';
if ($conds) {
$where_clause = ' WHERE ' . implode(' AND ', $conds) . "\n";
}
if ($o == 'publication') {
$o = 'lower(o.prettyname)';
}
if ($o == 'byline') {
$o = 'lower(byline)';
}
if ($o == 'title') {
$o = 'lower(title)';
}
$order_clause = sprintf(" ORDER BY %s %s\n", $o, $ot);
$limit_clause = sprintf(" OFFSET %d LIMIT %d\n", $offset, $limit);
$sql = "SELECT a.id,a.title,a.byline,a.description,a.permalink, a.pubdate, a.lastscraped, " . "o.id as pub_id, o.shortname as pub_shortname, o.prettyname as pub_name, o.home_url as pub_home_url\n" . $from_clause . $where_clause . $order_clause . $limit_clause;
$arts = db_getAll($sql, $params);
$sql = "SELECT COUNT(*)\n" . $from_clause . $where_clause;
$total = intval(db_getOne($sql, $params));
return array(&$arts, $total);
}
示例5: read_listing
function read_listing($params, $url = 'http://www.auto24.ee/kasutatud/nimekiri.php')
{
$endpoint = build_query($url, $params);
$html = scraperWiki::scrape($endpoint);
$dom = new simple_html_dom();
$dom->load($html);
$totalResultsEl = $dom->find('.paginator .current-range strong');
$totalResults = $totalResultsEl[0]->plaintext;
$medianItem = ($totalResults + 1) / 2;
if ($medianItem > RESULTS_PER_PAGE) {
$listingOffset = floor($medianItem / RESULTS_PER_PAGE) * RESULTS_PER_PAGE;
$params['ak'] = $listingOffset;
$medianItem -= $listingOffset;
$endpoint = build_query($url, $params);
$html = scraperWiki::scrape($endpoint);
$dom = new simple_html_dom();
$dom->load($html);
}
$rows = $dom->find("[@id=usedVehiclesSearchResult] .result-row");
$lPoint = floor($medianItem) - 1;
$hPoint = ceil($medianItem) - 1;
$a24ksi = 0;
if ($lPoint == $hPoint) {
$rowData = get_row_data($rows[$lPoint]);
$a24ksi = $rowData['price'];
} else {
$lRowData = get_row_data($rows[$lPoint]);
$hRowData = get_row_data($rows[$hPoint]);
$a24ksi = round(($lRowData['price'] + $hRowData['price']) / 2);
}
return array('n' => $totalResults, 'val' => $a24ksi);
}
示例6: bp_follow_blogs_add_activity_scope_filter
/**
* Filter the activity loop.
*
* Specifically, when on the activity directory and clicking on the "Followed
* Sites" tab.
*
* @param str $qs The querystring for the BP loop
* @param str $object The current object for the querystring
* @return str Modified querystring
*/
function bp_follow_blogs_add_activity_scope_filter($qs, $object)
{
// not on the blogs object? stop now!
if ($object != 'activity') {
return $qs;
}
// parse querystring into an array
$r = wp_parse_args($qs);
if (bp_is_current_action(constant('BP_FOLLOW_BLOGS_USER_ACTIVITY_SLUG'))) {
$r['scope'] = 'followblogs';
}
if (!isset($r['scope'])) {
return $qs;
}
if ('followblogs' !== $r['scope']) {
return $qs;
}
// get blog IDs that the user is following
$following_ids = bp_get_following_ids(array('user_id' => bp_displayed_user_id() ? bp_displayed_user_id() : bp_loggedin_user_id(), 'follow_type' => 'blogs'));
// if $following_ids is empty, pass a negative number so no blogs can be found
$following_ids = empty($following_ids) ? -1 : $following_ids;
$args = array('user_id' => 0, 'object' => 'blogs', 'primary_id' => $following_ids);
// make sure we add a separator if we have an existing querystring
if (!empty($qs)) {
$qs .= '&';
}
// add our follow parameters to the end of the querystring
$qs .= build_query($args);
// support BP Groupblog
// We need to filter the WHERE SQL conditions to do this
if (function_exists('bp_groupblog_init')) {
add_filter('bp_activity_get_where_conditions', 'bp_follow_blogs_groupblog_activity_where_conditions', 10, 2);
}
return $qs;
}
示例7: requestVerificationCode
/**
* **********************************************
* Request Verification Code
* https://msdn.microsoft.com/en-us/library/ff749592.aspx
*
* The following example shows a URL that enables
* a user to provide consent to an application by
* using a Windows Live ID.
*
* When successful, this URL returns the user to
* your application, along with a verification
* code.
* **********************************************
*/
public function requestVerificationCode($transactionId)
{
$params = array('response_type' => 'code', 'redirect_uri' => urlencode($this->getCallbackUri()), 'client_id' => $this->getClientId(), 'client_secret' => $this->getClientSecret(), 'scope' => urlencode(self::SCOPE), 'access_type' => 'offline', 'approval_prompt' => 'force');
$authUrl = $this->getAuthorizationUrl() . '?' . build_query($params);
$this->getLogger()->debug('Requesting verification code from Microsoft');
PostmanUtils::redirect($authUrl);
}
示例8: bpdev_exclude_users
function bpdev_exclude_users($qs = false, $object = false)
{
//list of users to exclude
$excluded_user = '1';
//comma separated ids of users whom you want to exclude
/*
// Remove the comment lines here to only disable admin listing ONLY on the members page.
//if($object!='members')//hide for members only
//{
//return $qs;
//}
*/
$args = wp_parse_args($qs);
//check if we are listing friends?, do not exclude in this case
if (!empty($args['user_id'])) {
return $qs;
}
if (!empty($args['exclude'])) {
$args['exclude'] = $args['exclude'] . ',' . $excluded_user;
} else {
$args['exclude'] = $excluded_user;
}
$qs = build_query($args);
return $qs;
}
示例9: requestVerificationCode
/**
* The authorization sequence begins when your application redirects a browser to a Google URL;
* the URL includes query parameters that indicate the type of access being requested.
*
* As in other scenarios, Google handles user authentication, session selection, and user consent.
* The result is an authorization code, which Google returns to your application in a query string.
*
* (non-PHPdoc)
*
* @see PostmanAuthenticationManager::requestVerificationCode()
*/
public function requestVerificationCode($transactionId)
{
$params = array('response_type' => 'code', 'redirect_uri' => urlencode($this->getCallbackUri()), 'client_id' => $this->getClientId(), 'scope' => urlencode(self::SCOPE_FULL_ACCESS), 'access_type' => 'offline', 'approval_prompt' => 'force', 'state' => $transactionId, 'login_hint' => $this->senderEmail);
$authUrl = $this->getAuthorizationUrl() . '?' . build_query($params);
$this->getLogger()->debug('Requesting verification code from Google');
PostmanUtils::redirect($authUrl);
}
示例10: sso_login
/**
* Initiate an SSO login
* @return void
*/
public function sso_login()
{
// Get SSO hash
$hash = '';
if (isset($_REQUEST['SSO_HASH'])) {
$hash = $_REQUEST['SSO_HASH'];
}
// @codeCoverageIgnoreStart
// Redirect for www domains
if (preg_match('/^www\\./', parse_url(get_option('home'), PHP_URL_HOST)) && !preg_match('/^www\\./', $_SERVER['HTTP_HOST'])) {
@wp_safe_redirect(home_url() . '?' . build_query(array('GD_COMMAND' => 'SSO_LOGIN', 'SSO_HASH' => $_REQUEST['SSO_HASH'], 'SSO_USER_ID' => $_REQUEST['SSO_USER_ID'])));
add_filter('wp_die_handler', 'gd_system_die_handler', 10, 1);
wp_die();
}
// @codeCoverageIgnoreEnd
// Get SSO user
$user_id = 0;
if (isset($_REQUEST['SSO_USER_ID']) && !empty($_REQUEST['SSO_USER_ID'])) {
$user_id = $_REQUEST['SSO_USER_ID'];
} else {
$user = get_users(array('role' => 'administrator', 'number' => 1));
if (!$user[0] instanceof WP_User) {
return;
}
$user_id = $user[0]->ID;
}
// Set the cookie
if ($this->_is_valid_sso_login($hash)) {
@wp_set_auth_cookie($user_id);
}
// Redirect to the dashboard
@wp_safe_redirect(self_admin_url());
add_filter('wp_die_handler', 'gd_system_die_handler', 10, 1);
wp_die();
}
示例11: get_user_followers
function get_user_followers($userid, $page, $username)
{
$text = "SELECT id, following_user_id AS username FROM follow WHERE follower_user_id='{$userid}' AND deleted_time=''";
$return['query'] = build_query($text, $page);
$return['pagination'] = get_pagination($text, $page);
return $return;
}
示例12: get_total
function get_total($dbc, $subject, $predicate, $object)
{
$query = build_query($dbc, $subject, $predicate, $object, true);
$result = mysqli_query($dbc, $query);
$row = mysqli_fetch_array($result);
$total = $row['count'];
return $total;
}
示例13: get_total
function get_total($dbc, $type)
{
$query = build_query($dbc, $type, true);
$result = mysqli_query($dbc, $query);
$row = mysqli_fetch_array($result);
$total = $row['count'];
return $total;
}
示例14: get_total
function get_total($dbc, $keywords, $active_relation, $dbc)
{
$query = build_query($dbc, $keywords, $active_relation, true);
$result = mysqli_query($dbc, $query);
$row = mysqli_fetch_array($result);
$total = $row['count'];
return $total;
}
示例15: get_tracking_url
/**
* Gets a Google Analytics Campaign url for this product
*
* @param string $path
* @param string $link_identifier
* @return string The full URL
*/
public function get_tracking_url($path = '', $link_identifier = '')
{
$tracking_vars = array('utm_campaign' => $this->item_name . ' licensing', 'utm_medium' => 'link', 'utm_source' => $this->item_name, 'utm_content' => $link_identifier);
// url encode tracking vars
$tracking_vars = urlencode_deep($tracking_vars);
$query_string = build_query($tracking_vars);
return $this->item_url . ltrim($path, '/') . '#' . $query_string;
}