本文整理汇总了PHP中wp_safe_remote_get函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_safe_remote_get函数的具体用法?PHP wp_safe_remote_get怎么用?PHP wp_safe_remote_get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_safe_remote_get函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: _retrieve_videos
/**
* Load the videos from a specified page. Is partly recursive.
*
* @param $url
*
* @return array
*/
public function _retrieve_videos($url)
{
$body = wp_remote_retrieve_body(wp_safe_remote_get($url));
if ('' === $body) {
return false;
}
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($body);
libxml_clear_errors();
$finder = new DOMXPath($dom);
$videos = $finder->query('//*[contains(@class, "video-list")]/li');
$older_videos = $finder->query('//*[contains(@class, "nav-previous")]/a');
$data = array('videos' => '', 'total_videos' => $videos->length);
/** @var $reply \DOMNode */
foreach ($videos as $video) {
$img = $finder->query('*[contains(@class, "video-thumbnail")]/img', $video)->item(0)->getAttribute('src');
$a_text = $finder->query('*[contains(@class, "video-description")]/h4/a', $video)->item(0)->nodeValue;
$a_href = $finder->query('*[contains(@class, "video-description")]/h4/a', $video)->item(0)->getAttribute('href');
$event = $finder->query('*[contains(@class, "video-description")]/*[contains(@class, "video-events")]/a', $video)->item(0)->nodeValue;
$description = $finder->query('*[contains(@class, "video-description")]/*[contains(@class, "video-excerpt")]/p', $video)->item(0)->nodeValue;
preg_match('/^((?:\\S+\\s+){2}\\S+).*/', $description, $matches);
$description = str_replace('—', '–', $description);
$date = new DateTime($matches[1]);
$data['videos'][] = array('title' => $a_text, 'date' => $date->format('Y-m-d'), 'url' => $a_href, 'image' => $img, 'event' => $event, 'description' => $description);
}
if ($older_videos->length) {
$more_videos = $this->_retrieve_videos($older_videos->item(0)->getAttribute('href'));
$data['videos'] = array_merge($data['videos'], $more_videos['videos']);
$data['total_videos'] += $more_videos['total_videos'];
}
return $data;
}
开发者ID:Steadroy,项目名称:wptalents,代码行数:40,代码来源:WordPressTv_Collector.php
示例2: _wpsc_get_exchange_rate
function _wpsc_get_exchange_rate($from, $to)
{
if ($from == $to) {
return 1;
}
$key = "wpsc_exchange_{$from}_{$to}";
if ($rate = get_transient($key)) {
return (double) $rate;
}
$url = add_query_arg(array('a' => '1', 'from' => $from, 'to' => $to), 'http://www.google.com/finance/converter');
$url = esc_url_raw(apply_filters('_wpsc_get_exchange_rate_service_endpoint', $url, $from, $to));
$response = wp_remote_retrieve_body(wp_safe_remote_get($url, array('timeout' => 10)));
if (has_filter('_wpsc_get_exchange_rate')) {
return (double) apply_filters('_wpsc_get_exchange_rate', $response, $from, $to);
}
if (empty($response)) {
return $response;
} else {
$rate = explode('bld>', $response);
$rate = explode($to, $rate[1]);
$rate = trim($rate[0]);
set_transient($key, $rate, DAY_IN_SECONDS);
return (double) $rate;
}
}
开发者ID:ashik968,项目名称:digiplot,代码行数:25,代码来源:currency.helpers.php
示例3: download
public static function download($sURL, $iTimeOut = 300)
{
if (false === filter_var($sURL, FILTER_VALIDATE_URL)) {
return false;
}
$_sTmpFileName = self::setTempPath(self::getBaseNameOfURL($sURL));
if (!$_sTmpFileName) {
return false;
}
$_aoResponse = wp_safe_remote_get($sURL, array('timeout' => $iTimeOut, 'stream' => true, 'filename' => $_sTmpFileName));
if (is_wp_error($_aoResponse)) {
unlink($_sTmpFileName);
return false;
}
if (200 != wp_remote_retrieve_response_code($_aoResponse)) {
unlink($_sTmpFileName);
return false;
}
$_sContent_md5 = wp_remote_retrieve_header($_aoResponse, 'content-md5');
if ($_sContent_md5) {
$_boIsMD5 = verify_file_md5($_sTmpFileName, $_sContent_md5);
if (is_wp_error($_boIsMD5)) {
unlink($_sTmpFileName);
return false;
}
}
return $_sTmpFileName;
}
开发者ID:jaime5x5,项目名称:seamless-donations,代码行数:28,代码来源:AdminPageFramework_WPUtility_File.php
示例4: import
public function import($attachment)
{
$saved_image = $this->_return_saved_image($attachment);
if ($saved_image) {
return $saved_image;
}
// Extract the file name and extension from the url
$filename = basename($attachment['url']);
if (function_exists('file_get_contents')) {
$options = ['http' => ['user_agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux i686 on x86_64; rv:49.0) Gecko/20100101 Firefox/49.0']];
$context = stream_context_create($options);
$file_content = file_get_contents($attachment['url'], false, $context);
} else {
$file_content = wp_remote_retrieve_body(wp_safe_remote_get($attachment['url']));
}
if (empty($file_content)) {
return false;
}
$upload = wp_upload_bits($filename, null, $file_content);
$post = ['post_title' => $filename, 'guid' => $upload['url']];
$info = wp_check_filetype($upload['file']);
if ($info) {
$post['post_mime_type'] = $info['type'];
} else {
// For now just return the origin attachment
return $attachment;
//return new \WP_Error( 'attachment_processing_error', __( 'Invalid file type', 'elementor' ) );
}
$post_id = wp_insert_attachment($post, $upload['file']);
wp_update_attachment_metadata($post_id, wp_generate_attachment_metadata($post_id, $upload['file']));
update_post_meta($post_id, '_elementor_source_image_hash', $this->_get_hash_image($attachment['url']));
$new_attachment = ['id' => $post_id, 'url' => $upload['url']];
$this->_replace_image_ids[$attachment['id']] = $new_attachment;
return $new_attachment;
}
开发者ID:pojome,项目名称:elementor,代码行数:35,代码来源:class-import-images.php
示例5: generate_metadata
protected function generate_metadata($url)
{
$response = wp_safe_remote_get($url);
if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
return false;
}
$body = wp_remote_retrieve_body($response);
$metadata = sprintf('sha384-%s', base64_encode(hash('sha384', $body, true)));
$this->meta->set($url, $metadata);
return true;
}
开发者ID:ssnepenthe,项目名称:homonoia,代码行数:11,代码来源:class-sri-generator.php
示例6: test_get_language_pack_uri
function test_get_language_pack_uri()
{
global $woocommerce_wpml, $woocommerce;
//use stable version to test
$pack_uri = $woocommerce_wpml->languages_upgrader->get_language_pack_uri('uk_UA', $woocommerce_wpml->get_stable_wc_version());
$response = wp_safe_remote_get($pack_uri, array('timeout' => 60));
$response_result = false;
if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) {
$response_result = true;
}
$this->assertTrue($response_result);
}
开发者ID:helgatheviking,项目名称:woocommerce-multilingual,代码行数:12,代码来源:test-urls.php
示例7: output
/**
* Handles output of the reports page in admin.
*/
public static function output()
{
if (false === ($addons = get_transient('woocommerce_addons_data'))) {
$addons_json = wp_safe_remote_get('http://d3t0oesq8995hv.cloudfront.net/woocommerce-addons.json', array('user-agent' => 'WooCommerce Addons Page'));
if (!is_wp_error($addons_json)) {
$addons = json_decode(wp_remote_retrieve_body($addons_json));
if ($addons) {
set_transient('woocommerce_addons_data', $addons, WEEK_IN_SECONDS);
}
}
}
include_once 'views/html-admin-page-addons.php';
}
开发者ID:rahul13bhati,项目名称:woocommerce,代码行数:16,代码来源:class-wc-admin-addons.php
示例8: refresh
public function refresh($url)
{
if (!is_string($url)) {
throw new \InvalidArgumentException(sprintf('The url parameter is required to be string, was: %s', gettype($url)));
}
$r = false;
$args = ['blocking' => false, 'headers' => apply_filters(sprintf('%s\\refresh_headers', __NAMESPACE__), ['X-Nginx-Cache-Purge' => '1']), 'sslverify' => apply_filters(sprintf('%s\\sslverify', __NAMESPACE__), true), 'timeout' => 1];
$response = wp_safe_remote_get($url, $args);
if (!is_wp_error($response)) {
$r = true;
}
return $r;
}
开发者ID:ssnepenthe,项目名称:cache-manager,代码行数:13,代码来源:FastCGIHTTP.php
示例9: wc_rest_upload_image_from_url
/**
* Upload image from URL.
*
* @since 2.6.0
* @param string $image_url
* @return array|WP_Error Attachment data or error message.
*/
function wc_rest_upload_image_from_url($image_url)
{
$file_name = basename(current(explode('?', $image_url)));
$parsed_url = @parse_url($image_url);
// Check parsed URL.
if (!$parsed_url || !is_array($parsed_url)) {
return new WP_Error('woocommerce_rest_invalid_image_url', sprintf(__('Invalid URL %s.', 'woocommerce'), $image_url), array('status' => 400));
}
// Ensure url is valid.
$image_url = esc_url_raw($image_url);
// Get the file.
$response = wp_safe_remote_get($image_url, array('timeout' => 10));
if (is_wp_error($response)) {
return new WP_Error('woocommerce_rest_invalid_remote_image_url', sprintf(__('Error getting remote image %s.', 'woocommerce'), $image_url) . ' ' . sprintf(__('Error: %s.', 'woocommerce'), $response->get_error_message()), array('status' => 400));
} elseif (200 !== wp_remote_retrieve_response_code($response)) {
return new WP_Error('woocommerce_rest_invalid_remote_image_url', sprintf(__('Error getting remote image %s.', 'woocommerce'), $image_url), array('status' => 400));
}
// Ensure we have a file name and type.
$wp_filetype = wp_check_filetype($file_name, wc_rest_allowed_image_mime_types());
if (!$wp_filetype['type']) {
$headers = wp_remote_retrieve_headers($response);
if (isset($headers['content-disposition']) && strstr($headers['content-disposition'], 'filename=')) {
$disposition = end(explode('filename=', $headers['content-disposition']));
$disposition = sanitize_file_name($disposition);
$file_name = $disposition;
} elseif (isset($headers['content-type']) && strstr($headers['content-type'], 'image/')) {
$file_name = 'image.' . str_replace('image/', '', $headers['content-type']);
}
unset($headers);
// Recheck filetype
$wp_filetype = wp_check_filetype($file_name, wc_rest_allowed_image_mime_types());
if (!$wp_filetype['type']) {
return new WP_Error('woocommerce_rest_invalid_image_type', __('Invalid image type.', 'woocommerce'), array('status' => 400));
}
}
// Upload the file.
$upload = wp_upload_bits($file_name, '', wp_remote_retrieve_body($response));
if ($upload['error']) {
return new WP_Error('woocommerce_rest_image_upload_error', $upload['error'], array('status' => 400));
}
// Get filesize.
$filesize = filesize($upload['file']);
if (0 == $filesize) {
@unlink($upload['file']);
unset($upload);
return new WP_Error('woocommerce_rest_image_upload_file_error', __('Zero size file downloaded.', 'woocommerce'), array('status' => 400));
}
do_action('woocommerce_rest_api_uploaded_image_from_url', $upload, $image_url);
return $upload;
}
开发者ID:tlovett1,项目名称:woocommerce,代码行数:57,代码来源:wc-rest-functions.php
示例10: _retrieve_data
/**
* @access protected
*
* @return bool
*/
public function _retrieve_data()
{
$profile = Helper::get_talent_meta($this->post, 'profile');
$url = str_replace('https://secure.gravatar.com/avatar/', 'https://www.gravatar.com/', $profile['avatar']);
$url = remove_query_arg(array('s', 'd'), $url) . '.json';
$body = wp_remote_retrieve_body(wp_safe_remote_get($url));
if ('' === $body) {
return false;
}
$body = json_decode($body);
if (null === $body) {
return false;
}
if (!isset($body->entry[0])) {
return false;
}
$social = get_post_meta($this->post->ID, 'social', true);
if (isset($social[0]) && is_array($social[0])) {
foreach ($social[0] as $key => $value) {
$social[$key] = $value;
}
unset($social[0]);
}
if (isset($body->entry[0]->accounts)) {
foreach ($body->entry[0]->accounts as $account) {
switch ($account->shortname) {
case 'linkedin':
$social['linkedin'] = $account->url;
break;
case 'twitter':
case 'facebook':
$social[$account->shortname] = $account->username;
break;
case 'google':
$social['google-plus'] = $account->userid;
break;
case 'wordpress':
$social['url'] = $account->url;
default:
break;
}
}
}
if (!empty($body->entry[0]->urls)) {
$social['url'] = $body->entry[0]->urls[0]->value;
}
return (bool) update_post_meta($this->post->ID, 'social', $social);
}
开发者ID:Steadroy,项目名称:wptalents,代码行数:53,代码来源:Gravatar_Collector.php
示例11: getJsonData
private function getJsonData($default_url)
{
// Setup our header and auth information
$args = array('headers' => array('Accept' => 'application/json', 'Authorization' => 'Bearer ' . $this->api_key));
$response = wp_safe_remote_get($default_url, $args);
$response['my_url'] = $default_url;
$response['my_args'] = $args;
if (is_wp_error($response)) {
$json = json_encode($return->get_error_message());
} elseif (wp_remote_retrieve_response_code($response) != 200) {
$json = json_encode(wp_remote_retrieve_body($response));
} else {
$json = wp_remote_retrieve_body($response);
}
return $json;
}
开发者ID:agentE,项目名称:coc-api-wordpress-smartcode,代码行数:16,代码来源:CoC_API.php
示例12: _retrieve_data
/**
* @access protected
*
* @return bool
*/
public function _retrieve_data()
{
$results_url = add_query_arg(array('q' => 'props+' . $this->options['username'], 'noquickjump' => '1', 'changeset' => 'on'), 'https://core.trac.wordpress.org/search');
$results = wp_remote_retrieve_body(wp_safe_remote_get($results_url));
if (is_wp_error($results)) {
return false;
}
$pattern = '/<meta name="totalResults" content="(\\d*)" \\/>/';
preg_match($pattern, $results, $matches);
$count = 0;
if (isset($matches[1])) {
$count = intval($matches[1]);
}
$data = array('data' => $count, 'expiration' => time() + $this->expiration);
update_post_meta($this->post->ID, '_changeset_count', $data);
return $data;
}
开发者ID:Steadroy,项目名称:wptalents,代码行数:22,代码来源:Changeset_Collector.php
示例13: get_section_data
/**
* Get section content for the addons screen.
*
* @param string $section_id
*
* @return array
*/
public static function get_section_data($section_id)
{
$section = self::get_section($section_id);
$section_data = '';
if (!empty($section->endpoint)) {
if (false === ($section_data = get_transient('wc_addons_section_' . $section_id))) {
$raw_section = wp_safe_remote_get(esc_url_raw($section->endpoint), array('user-agent' => 'WooCommerce Addons Page'));
if (!is_wp_error($raw_section)) {
$section_data = json_decode(wp_remote_retrieve_body($raw_section));
if (!empty($section_data->products)) {
set_transient('wc_addons_section_' . $section_id, $section_data, WEEK_IN_SECONDS);
}
}
}
}
return apply_filters('woocommerce_addons_section_data', $section_data->products, $section_id);
}
开发者ID:robbenz,项目名称:plugs,代码行数:24,代码来源:class-wc-admin-addons.php
示例14: get
/**
* Send a GET request to the given endpoint.
*
* @param string $endpoint Appended to $url_root to create the URL.
*
* @return array
*
* @throws \InvalidArgumentException When endpoint is not a string.
* @throws \RuntimeException When $response is a WP_Error.
*/
public function get($endpoint)
{
if (!is_string($endpoint)) {
throw new \InvalidArgumentException(sprintf('The endpoint parameter is required to be string, was: %s', gettype($endpoint)));
}
$endpoint = ltrim($endpoint, '/\\');
$url = sprintf('https://wpvulndb.com/api/v2/%s', $endpoint);
$name = 'Soter Security Checker';
$version = '0.3.0';
$soter_url = 'https://github.com/ssnepenthe/soter';
$args = ['user-agent' => sprintf('%s | v%s | %s', $name, $version, $soter_url)];
$response = wp_safe_remote_get($url, $args);
if (is_wp_error($response)) {
throw new \RuntimeException(sprintf('WP Error: %s', $response->get_error_message()));
}
return [wp_remote_retrieve_response_code($response), wp_remote_retrieve_headers($response), wp_remote_retrieve_body($response)];
}
开发者ID:ssnepenthe,项目名称:soter,代码行数:27,代码来源:WPClient.php
示例15: _retrieve_data
/**
* @access protected
*
* @return bool
*/
public function _retrieve_data()
{
$results_url = add_query_arg(array('action' => 'query', 'list' => 'users', 'ususers' => $this->options['username'], 'usprop' => 'editcount', 'format' => 'json'), 'https://codex.wordpress.org/api.php');
$results = wp_remote_retrieve_body(wp_safe_remote_get($results_url));
if (is_wp_error($results)) {
return false;
}
$raw = json_decode($results);
if (isset($raw->query->users[0]->editcount)) {
$count = (int) $raw->query->users[0]->editcount;
} else {
$count = 0;
}
$data = array('data' => $count, 'expiration' => time() + $this->expiration);
update_post_meta($this->post->ID, '_codex_count', $data);
return $data;
}
开发者ID:Steadroy,项目名称:wptalents,代码行数:22,代码来源:Codex_Collector.php
示例16: produce
private function produce($url = false)
{
if (empty($url)) {
$url = $this->get('url');
}
if (empty($url)) {
return $this->error('empty url');
}
$url = $this->add_ga_campain($url, 'fetch-data');
$resp = wp_safe_remote_get($url, array('timeout' => 30));
if (is_wp_error($resp)) {
/**
* if user can manage_options then display a real error message
*/
if (current_user_can('manage_options')) {
return $this->error(false, $resp->get_error_message());
} else {
return $this->error('http request failed');
}
}
if (200 != $resp['response']['code']) {
return $this->error('wrong response status');
}
$title_temp = preg_split('/<h1>/', $resp['body']);
$title_temp_temp = isset($title_temp[1]) ? preg_split('@</h1>@', $title_temp[1]) : array('');
$title = $title_temp_temp[0];
$body = '';
$containers = preg_split('/<div class="container">/', $resp['body']);
foreach ($containers as $container) {
if (!preg_match('/<div class="col-sm-[\\d]+ post-content[^>]+>/', $container)) {
continue;
}
$body = $container;
}
if (empty($body)) {
return $this->error('empty body');
}
$body = preg_split('/<aside/', $body);
$body = $body[0];
if (empty($body)) {
return $this->error('empty body');
}
$body = sprintf('<h1 class="title">%s</h1><div class="container"><div class="post-content">%s', $title, $body);
set_transient($this->cache, $body, 14 * DAY_IN_SECONDS);
return $body;
}
开发者ID:zoran180,项目名称:wp_szf,代码行数:46,代码来源:class.wpcf.marketing.tutorial.php
示例17: output
/**
* Handles output of the upsells in admin.
*
* Data to display is gotten from a JSON file on a remote server. JSON data structure is shown below and can be checked at http://jsoneditoronline.org/.
*
* {
* "all": {
* "plugin-name": {
* "id": "plugin-name",
* "link": "http://molongui.amitzy.com/plugins/plugin-name",
* "price": "123.00",
* "name": "Plugin Name",
* "image": "http://molongui.amitzy.com/plugins/img/banner_en_US.png",
* "excerpt": "Plugin short description in English.",
* "name_es_ES": "Nombre en castellano",
* "image_es_ES": "http://molongui.amitzy.com/plugins/img/banner_es_ES.png",
* "excerpt_es_ES": "Breve descripción del plugin en castellano."
* }
* },
* "featured": {},
* "popular": {},
* "free": {},
* "premium": {}
* }
*
* Images size must be 300x163px.
*
* @acess public
* @param string $category The category to show plugins from.
* @param mixed $num_items The number of featured plugins to show.
* @param int $num_words Number of words to use as plugin description.
* @param string $more Text to add when ellipsing plugin description.
* @since 1.0.0
* @version 1.0.0
*/
public static function output($category = 'all', $num_items = 'all', $num_words = 36, $more = null)
{
// Load configuration
$config = (include MOLONGUI_AUTHORSHIP_DIR . "/config/upsell.php");
// Premium plugins download data from Molongui server
if (MOLONGUI_AUTHORSHIP_LICENSE != 'free') {
// If cached data, don't download it again
if (false === ($upsells = get_site_transient('molongui_sw_data'))) {
// Get data from remote server
$upsell_json = wp_safe_remote_get($config['server']['url'], array('user-agent' => $config['server']['agent']));
if (!is_wp_error($upsell_json)) {
// Decode data to a stdClass object
$upsells = json_decode(wp_remote_retrieve_body($upsell_json));
// Store data (cache) for future uses (within this week time)
if ($upsells) {
set_site_transient('molongui_sw_data', $upsells, WEEK_IN_SECONDS);
}
}
}
} else {
// Get data from local file
$upsell_json = file_get_contents($config['local']['url']);
// Set correct local path
$upsell_json = str_replace('%%MOLONGUI_PLUGIN_URL%%', MOLONGUI_AUTHORSHIP_URL, $upsell_json);
// Decode data to a stdClass object
$upsells = json_decode($upsell_json);
}
// Check there is data to show
$tmp = (array) $upsells->{$category};
if (!empty($tmp)) {
// Avoid current plugin to be displayed
if ($upsells->{$category}->{MOLONGUI_AUTHORSHIP_ID}->id) {
unset($upsells->{$category}->{MOLONGUI_AUTHORSHIP_ID});
}
// Slice array so just $num_items are displayed
if (isset($num_items) && $num_items != 'all' && $num_items > 0) {
$upsells->{$category} = array_slice((array) $upsells->{$category}, 0, $num_items);
}
// DEBUG: Used to display results for development
//echo "<pre>"; print_r($upsells); echo "</pre>";
// Display data
include_once MOLONGUI_AUTHORSHIP_DIR . '/admin/views/html-admin-page-upsells.php';
}
}
开发者ID:evanjmg,项目名称:travelpal,代码行数:79,代码来源:class-plugin-upsell.php
示例18: siw_postcode_lookup
function siw_postcode_lookup()
{
$api_key = siw_get_postcode_api_key();
$postcode = strtoupper(siw_strip_url($_GET['postcode']));
$houseNumber = siw_strip_url($_GET['housenumber']);
$url = 'https://postcode-api.apiwise.nl/v2/addresses/?postcode=' . str_replace(' ', '', $postcode) . '&number=' . $houseNumber;
$args = array('timeout' => 10, 'redirection' => 0, 'headers' => array('X-Api-Key' => $api_key));
$response = json_decode(wp_safe_remote_get($url, $args)['body']);
if ($response->_embedded->addresses) {
$street = $response->_embedded->addresses[0]->street;
$town = $response->_embedded->addresses[0]->city->label;
$data = array('success' => 1, 'resource' => array('street' => $street, 'town' => $town));
} else {
$data = array('success' => 0);
}
$result = json_encode($data);
echo $result;
die;
}
开发者ID:siwvolunteers,项目名称:siw,代码行数:19,代码来源:siw-postcode.php
示例19: _retrieve_data
/**
* @access protected
*
* @return bool
*/
public function _retrieve_data()
{
$url = 'https://wordpress.org/support/profile/' . $this->options['username'];
$body = wp_remote_retrieve_body(wp_safe_remote_get($url));
if ('' === $body) {
return false;
}
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($body);
libxml_clear_errors();
$finder = new DOMXPath($dom);
$recent_replies = $finder->query('//div[@id="user-replies"]/ol/li');
$threads_started = $finder->query('//div[@id="user-threads"]/ol/li');
$page_numbers = $finder->query('//*[contains(@class, "page-numbers")]');
$data = array('replies' => '', 'threads' => '', 'total_replies' => '');
if ($page_numbers->length) {
$total_pages = $page_numbers->item($page_numbers->length / 2 - 2)->nodeValue;
// It's not 100% accurate, as there may be not so many replies on the last page
$data['total_replies'] = $total_pages * $recent_replies->length;
} else {
$data['total_replies'] = $recent_replies->length;
}
/** @var $reply \DOMNode */
foreach ($recent_replies as $reply) {
$a_text = $finder->query('a', $reply)->item(0)->nodeValue;
$a_href = $finder->query('a', $reply)->item(0)->getAttribute('href');
$node_text = $finder->query('text()', $reply)->item(1)->nodeValue;
preg_match('/((([^ ]*)[\\s.]+){3})$/', $node_text, $matches);
$data['replies'][] = array('title' => $a_text, 'url' => esc_url_raw($a_href), 'date' => str_replace('.', '', trim($matches[0])));
}
foreach ($threads_started as $thread) {
$a_text = $finder->query('a', $thread)->item(0)->nodeValue;
$a_href = $finder->query('a', $thread)->item(0)->getAttribute('href');
$node_text = $finder->query('text()', $thread)->item(1)->nodeValue;
preg_match('/((([^ ]*)[\\s.]+){3})$/', $node_text, $matches);
$data['threads'][] = array('title' => $a_text, 'url' => esc_url_raw($a_href), 'date' => str_replace('.', '', trim($matches[0])));
}
$data = array('data' => $data, 'expiration' => time() + $this->expiration);
update_post_meta($this->post->ID, '_forums', $data);
return $data;
}
开发者ID:Steadroy,项目名称:wptalents,代码行数:47,代码来源:Forums_Collector.php
示例20: download_url
function download_url($url, $timeout = 300)
{
//WARNING: The file is not automatically deleted, The script must unlink() the file.
if (!$url) {
return new WP_Error('http_no_url', __('Invalid URL Provided.', 'themify-flow'));
}
$tmpfname = wp_tempnam($url);
if (!$tmpfname) {
return new WP_Error('http_no_file', __('Could not create Temporary file.', 'themify-flow'));
}
$response = wp_safe_remote_get($url, array('cookies' => $this->cookies, 'timeout' => $timeout, 'stream' => true, 'filename' => $tmpfname));
if (is_wp_error($response)) {
unlink($tmpfname);
return $response;
}
if (200 != wp_remote_retrieve_response_code($response)) {
unlink($tmpfname);
return new WP_Error('http_404', trim(wp_remote_retrieve_response_message($response)));
}
return $tmpfname;
}
开发者ID:jhostetter,项目名称:wp_intern_themes,代码行数:21,代码来源:class-tf-upgrader.php
注:本文中的wp_safe_remote_get函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论