本文整理汇总了PHP中fetch_web_data函数的典型用法代码示例。如果您正苦于以下问题:PHP fetch_web_data函数的具体用法?PHP fetch_web_data怎么用?PHP fetch_web_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fetch_web_data函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: add_cache
function add_cache($tweet)
{
global $smcFunc, $txt, $sourcedir;
$twitterapi_url = "https://api.twitter.com/1/statuses/oembed.json?id=";
$twitterapi_url = $twitterapi_url . $tweet;
if (function_exists('curl_init')) {
$curl = curl_init($twitterapi_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($curl);
curl_close($curl);
} else {
require_once $sourcedir . '/Subs-Package.php';
$response = fetch_web_data($twitterapi_url);
}
$json_content = json_decode($response, true);
$json_content = preg_replace("/\r|\n/", "", $json_content);
$html = $json_content['html'];
if (!empty($html)) {
$request = $smcFunc['db_insert']('', '{db_prefix}tweet_cache', array('tweetid' => 'raw', 'html' => 'text'), array($tweet, addslashes($html)), array('tweetid', 'html'));
echo '{"html" : "' . addslashes($html) . '"}';
} else {
echo '{"html":"<p style=\\"color: #666; border: 1px dotted #666; padding: 5px; width: 490px;\\">' . $txt['autotwitter_tweeterror'] . '</p>"}';
}
}
开发者ID:VBGAMER45,项目名称:SMFMods,代码行数:25,代码来源:tweet-cache.php
示例2: list_getLanguagesList
function list_getLanguagesList()
{
global $forum_version, $context, $sourcedir, $smcFunc, $txt, $scripturl;
// We're going to use this URL.
$url = 'http://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => '')));
// Load the class file and stick it into an array.
require_once $sourcedir . '/Class-Package.php';
$language_list = new xmlArray(fetch_web_data($url), true);
// Check that the site responded and that the language exists.
if (!$language_list->exists('languages')) {
$context['smf_error'] = 'no_response';
} elseif (!$language_list->exists('languages/language')) {
$context['smf_error'] = 'no_files';
} else {
$language_list = $language_list->path('languages[0]');
$lang_files = $language_list->set('language');
$smf_languages = array();
foreach ($lang_files as $file) {
// Were we searching?
if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false) {
continue;
}
$smf_languages[] = array('id' => $file->fetch('id'), 'name' => $smcFunc['ucwords']($file->fetch('name')), 'version' => $file->fetch('version'), 'utf8' => $file->fetch('utf8') ? $txt['yes'] : $txt['no'], 'description' => $file->fetch('description'), 'install_link' => '<a href="' . $scripturl . '?action=admin;area=languages;sa=downloadlang;did=' . $file->fetch('id') . ';' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['add_language_smf_install'] . '</a>');
}
if (empty($smf_languages)) {
$context['smf_error'] = 'no_files';
} else {
return $smf_languages;
}
}
}
开发者ID:Glyph13,项目名称:SMF2.1,代码行数:31,代码来源:ManageLanguages.php
示例3: getServerInfo
/**
* Retrieve server information.
*
* @param string $openid_url
* @return boolean|array
*/
public function getServerInfo($openid_url)
{
require_once SUBSDIR . '/Package.subs.php';
// Get the html and parse it for the openid variable which will tell us where to go.
$webdata = fetch_web_data($openid_url);
if (empty($webdata)) {
return false;
}
$response_data = array();
// dirty, but .. Yadis response? Let's get the <URI>
preg_match('~<URI.*?>(.*)</URI>~', $webdata, $uri);
if ($uri) {
$response_data['provider'] = $uri[1];
$response_data['server'] = $uri[1];
return $response_data;
}
// Some OpenID servers have strange but still valid HTML which makes our job hard.
if (preg_match_all('~<link([\\s\\S]*?)/?>~i', $webdata, $link_matches) == 0) {
fatal_lang_error('openid_server_bad_response');
}
foreach ($link_matches[1] as $link_match) {
if (preg_match('~rel="([\\s\\S]*?)"~i', $link_match, $rel_match) == 0 || preg_match('~href="([\\s\\S]*?)"~i', $link_match, $href_match) == 0) {
continue;
}
$rels = preg_split('~\\s+~', $rel_match[1]);
foreach ($rels as $rel) {
if (preg_match('~openid2?\\.(server|delegate|provider)~i', $rel, $match) != 0) {
$response_data[$match[1]] = $href_match[1];
}
}
}
if (empty($response_data['provider'])) {
$response_data['server'] = $openid_url;
} else {
$response_data['server'] = $response_data['provider'];
}
return $response_data;
}
开发者ID:KeiroD,项目名称:Elkarte,代码行数:44,代码来源:OpenID.subs.php
示例4: PackageDownload
function PackageDownload()
{
global $txt, $scripturl, $boarddir, $context, $sourcedir, $db_prefix;
// Use the downloaded sub template.
$context['sub_template'] = 'downloaded';
// Security is good...
checkSession('get');
if (isset($_GET['server'])) {
$server = (int) $_GET['server'];
// Query the server table to find the requested server.
$request = db_query("\n\t\t\tSELECT name, url\n\t\t\tFROM {$db_prefix}package_servers\n\t\t\tWHERE ID_SERVER = {$server}\n\t\t\tLIMIT 1", __FILE__, __LINE__);
list($name, $url) = mysql_fetch_row($request);
mysql_free_result($request);
// If server does not exist then dump out.
if (empty($url)) {
fatal_lang_error('smf191', false);
}
$url = $url . '/';
} else {
// Initialize the requried variables.
$server = '';
$url = '';
}
$package_name = basename($_REQUEST['package']);
if (isset($_REQUEST['conflict']) || isset($_REQUEST['auto']) && file_exists($boarddir . '/Packages/' . $package_name)) {
// Find the extension, change abc.tar.gz to abc_1.tar.gz...
if (strrpos(substr($package_name, 0, -3), '.') !== false) {
$ext = substr($package_name, strrpos(substr($package_name, 0, -3), '.'));
$package_name = substr($package_name, 0, strrpos(substr($package_name, 0, -3), '.')) . '_';
} else {
$ext = '';
}
// Find the first available.
$i = 1;
while (file_exists($boarddir . '/Packages/' . $package_name . $i . $ext)) {
$i++;
}
$package_name = $package_name . $i . $ext;
}
// First make sure it's a package.
if (getPackageInfo($url . $_REQUEST['package']) == false) {
fatal_lang_error('package45', false);
}
// Use FTP if necessary.
packageRequireFTP($scripturl . '?action=packageget;sa=download' . (isset($_GET['server']) ? ';server=' . $_GET['server'] : '') . (isset($_REQUEST['auto']) ? ';auto' : '') . ';package=' . $_REQUEST['package'] . (isset($_REQUEST['conflict']) ? ';conflict' : '') . ';sesc=' . $context['session_id'], array($boarddir . '/Packages/' . $package_name));
package_put_contents($boarddir . '/Packages/' . $package_name, fetch_web_data($url . $_REQUEST['package']));
// Done! Did we get this package automatically?
if (preg_match('~^http://[\\w_\\-]+\\.simplemachines\\.org/~', $_REQUEST['package']) == 1 && strpos($_REQUEST['package'], 'dlattach') === false && isset($_REQUEST['auto'])) {
redirectexit('action=packages;sa=install;package=' . $package_name . ';sesc=' . $context['session_id']);
}
// You just downloaded a mod from SERVER_NAME_GOES_HERE.
$context['package_server'] = $server;
$context['package'] = getPackageInfo($package_name);
if (empty($context['package'])) {
fatal_lang_error('package_cant_download', false);
}
if ($context['package']['type'] == 'modification') {
$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=packages;sa=install;package=' . $context['package']['filename'] . ';sesc=' . $context['session_id'] . '">[ ' . $txt['package11'] . ' ]</a>';
} elseif ($context['package']['type'] == 'avatar') {
$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=packages;sa=install;package=' . $context['package']['filename'] . ';sesc=' . $context['session_id'] . '">[ ' . $txt['package12'] . ' ]</a>';
} elseif ($context['package']['type'] == 'language') {
$context['package']['install']['link'] = '<a href="' . $scripturl . '?action=packages;sa=install;package=' . $context['package']['filename'] . ';sesc=' . $context['session_id'] . '">[ ' . $txt['package13'] . ' ]</a>';
} else {
$context['package']['install']['link'] = '';
}
$context['package']['list_files']['link'] = '<a href="' . $scripturl . '?action=packages;sa=list;package=' . $context['package']['filename'] . '">[ ' . $txt['package14'] . ' ]</a>';
// Free a little bit of memory...
unset($context['package']['xml']);
$context['page_title'] = $txt['smf192'];
}
开发者ID:alencarmo,项目名称:OCF,代码行数:70,代码来源:PackageGet.php
示例5: url_image_size
function url_image_size($url)
{
global $sourcedir;
// Make sure it is a proper URL.
$url = str_replace(' ', '%20', $url);
// Can we pull this from the cache... please please?
if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
return $temp;
}
$t = microtime();
// Get the host to pester...
preg_match('~^\\w+://(.+?)/(.*)$~', $url, $match);
// Can't figure it out, just try the image size.
if ($url == '' || $url == 'http://' || $url == 'https://') {
return false;
} elseif (!isset($match[1])) {
$size = @getimagesize($url);
} else {
// Try to connect to the server... give it half a second.
$temp = 0;
$fp = @fsockopen($match[1], 80, $temp, $temp, 0.5);
// Successful? Continue...
if ($fp != false) {
// Send the HEAD request (since we don't have to worry about chunked, HTTP/1.1 is fine here.)
fwrite($fp, 'HEAD /' . $match[2] . ' HTTP/1.1' . "\r\n" . 'Host: ' . $match[1] . "\r\n" . 'User-Agent: PHP/SMF' . "\r\n" . 'Connection: close' . "\r\n\r\n");
// Read in the HTTP/1.1 or whatever.
$test = substr(fgets($fp, 11), -1);
fclose($fp);
// See if it returned a 404/403 or something.
if ($test < 4) {
$size = @getimagesize($url);
// This probably means allow_url_fopen is off, let's try GD.
if ($size === false && function_exists('imagecreatefromstring')) {
include_once $sourcedir . '/Subs-Package.php';
// It's going to hate us for doing this, but another request...
$image = @imagecreatefromstring(fetch_web_data($url));
if ($image !== false) {
$size = array(imagesx($image), imagesy($image));
imagedestroy($image);
}
}
}
}
}
// If we didn't get it, we failed.
if (!isset($size)) {
$size = false;
}
// If this took a long time, we may never have to do it again, but then again we might...
if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
cache_put_data('url_image_size-' . md5($url), $size, 240);
}
// Didn't work.
return $size;
}
开发者ID:AhoyLemon,项目名称:ballpit,代码行数:55,代码来源:Subs.backup.2.php
示例6: fetch_web_data
function fetch_web_data($url, $post_data = '', $keep_alive = false, $redirection_level = 0)
{
global $webmaster_email;
static $keep_alive_dom = null, $keep_alive_fp = null;
preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\\d+))?(.+)$~', $url, $match);
// An FTP url. We should try connecting and RETRieving it...
if (empty($match[1])) {
return false;
} elseif ($match[1] == 'ftp') {
// Include the file containing the ftp_connection class.
loadClassFile('Class-Package.php');
// Establish a connection and attempt to enable passive mode.
$ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email);
if ($ftp->error !== false || !$ftp->passive()) {
return false;
}
// I want that one *points*!
fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n");
// Since passive mode worked (or we would have returned already!) open the connection.
$fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5);
if (!$fp) {
return false;
}
// The server should now say something in acknowledgement.
$ftp->check_response(150);
$data = '';
while (!feof($fp)) {
$data .= fread($fp, 4096);
}
fclose($fp);
// All done, right? Good.
$ftp->check_response(226);
$ftp->close();
} elseif (isset($match[1]) && $match[1] == 'http') {
if ($keep_alive && $match[3] == $keep_alive_dom) {
$fp = $keep_alive_fp;
}
if (empty($fp)) {
// Open the socket on the port we want...
$fp = @fsockopen(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? $match[2] ? 443 : 80 : $match[5], $err, $err, 5);
if (!$fp) {
return false;
}
}
if ($keep_alive) {
$keep_alive_dom = $match[3];
$keep_alive_fp = $fp;
}
// I want this, from there, and I'm not going to be bothering you for more (probably.)
if (empty($post_data)) {
fwrite($fp, 'GET ' . $match[6] . ' HTTP/1.0' . "\r\n");
fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? $match[2] ? ':443' : '' : ':' . $match[5]) . "\r\n");
fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n");
if ($keep_alive) {
fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n");
} else {
fwrite($fp, 'Connection: close' . "\r\n\r\n");
}
} else {
fwrite($fp, 'POST ' . $match[6] . ' HTTP/1.0' . "\r\n");
fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? $match[2] ? ':443' : '' : ':' . $match[5]) . "\r\n");
fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n");
if ($keep_alive) {
fwrite($fp, 'Connection: Keep-Alive' . "\r\n");
} else {
fwrite($fp, 'Connection: close' . "\r\n");
}
fwrite($fp, 'Content-Type: application/x-www-form-urlencoded' . "\r\n");
fwrite($fp, 'Content-Length: ' . strlen($post_data) . "\r\n\r\n");
fwrite($fp, $post_data);
}
$response = fgets($fp, 768);
// Redirect in case this location is permanently or temporarily moved.
if ($redirection_level < 3 && preg_match('~^HTTP/\\S+\\s+30[127]~i', $response) === 1) {
$header = '';
$location = '';
while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') {
if (strpos($header, 'Location:') !== false) {
$location = trim(substr($header, strpos($header, ':') + 1));
}
}
if (empty($location)) {
return false;
} else {
if (!$keep_alive) {
fclose($fp);
}
return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1);
}
} elseif (preg_match('~^HTTP/\\S+\\s+20[01]~i', $response) === 0) {
return false;
}
// Skip the headers...
while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') {
if (preg_match('~content-length:\\s*(\\d+)~i', $header, $match) != 0) {
$content_length = $match[1];
} elseif (preg_match('~connection:\\s*close~i', $header) != 0) {
$keep_alive_dom = null;
$keep_alive = false;
}
//.........这里部分代码省略.........
开发者ID:norv,项目名称:EosAlpha,代码行数:101,代码来源:Subs-Package.php
示例7: scheduled_fetchSMfiles
function scheduled_fetchSMfiles()
{
global $sourcedir, $txt, $language, $settings, $forum_version, $modSettings, $smcFunc;
return;
// todo this does no longer make sense
// What files do we want to get
$request = smf_db_query('
SELECT id_file, filename, path, parameters
FROM {db_prefix}admin_info_files', array());
$js_files = array();
while ($row = mysql_fetch_assoc($request)) {
$js_files[$row['id_file']] = array('filename' => $row['filename'], 'path' => $row['path'], 'parameters' => sprintf($row['parameters'], $language, urlencode($modSettings['time_format']), urlencode($forum_version)));
}
mysql_free_result($request);
// We're gonna need fetch_web_data() to pull this off.
require_once $sourcedir . '/lib/Subs-Package.php';
// Just in case we run into a problem.
loadEssentialThemeData();
loadLanguage('Errors', $language, false);
foreach ($js_files as $ID_FILE => $file) {
// Create the url
$server = empty($file['path']) || substr($file['path'], 0, 7) != 'http://' ? 'http://www.simplemachines.org' : '';
$url = $server . (!empty($file['path']) ? $file['path'] : $file['path']) . $file['filename'] . (!empty($file['parameters']) ? '?' . $file['parameters'] : '');
// Get the file
$file_data = fetch_web_data($url);
// If we got an error - give up - the site might be down.
if ($file_data === false) {
log_error(sprintf($txt['st_cannot_retrieve_file'], $url));
return false;
}
// Save the file to the database.
smf_db_query('
UPDATE {db_prefix}admin_info_files
SET data = SUBSTRING({string:file_data}, 1, 65534)
WHERE id_file = {int:id_file}', array('id_file' => $ID_FILE, 'file_data' => $file_data));
}
return true;
}
开发者ID:norv,项目名称:EosAlpha,代码行数:38,代码来源:ScheduledTasks.php
示例8: resizeImageFile
/**
* Resizes an image from a remote location or a local file.
*
* - Puts the resized image at the destination location.
* - The file would have the format preferred_format if possible,
* otherwise the default format is jpeg.
*
* @package Graphics
* @param string $source
* @param string $destination
* @param int $max_width
* @param int $max_height
* @param int $preferred_format = 0
*/
function resizeImageFile($source, $destination, $max_width, $max_height, $preferred_format = 0)
{
// Nothing to do without GD or IM
if (!checkGD() && !checkImagick()) {
return false;
}
static $default_formats = array('1' => 'gif', '2' => 'jpeg', '3' => 'png', '6' => 'bmp', '15' => 'wbmp');
require_once SUBSDIR . '/Package.subs.php';
// Get the image file, we have to work with something after all
$fp_destination = fopen($destination, 'wb');
if ($fp_destination && (substr($source, 0, 7) == 'http://' || substr($source, 0, 8) == 'https://')) {
$fileContents = fetch_web_data($source);
fwrite($fp_destination, $fileContents);
fclose($fp_destination);
$sizes = @getimagesize($destination);
} elseif ($fp_destination) {
$sizes = @getimagesize($source);
$fp_source = fopen($source, 'rb');
if ($fp_source !== false) {
while (!feof($fp_source)) {
fwrite($fp_destination, fread($fp_source, 8192));
}
fclose($fp_source);
} else {
$sizes = array(-1, -1, -1);
}
fclose($fp_destination);
} else {
$sizes = array(-1, -1, -1);
}
// See if we have -or- can get the needed memory for this operation
if (checkGD() && !imageMemoryCheck($sizes)) {
return false;
}
// A known and supported format?
if (checkImagick() && isset($default_formats[$sizes[2]])) {
return resizeImage(null, $destination, null, null, $max_width, $max_height, true, $preferred_format);
} elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]])) {
$imagecreatefrom = 'imagecreatefrom' . $default_formats[$sizes[2]];
if ($src_img = @$imagecreatefrom($destination)) {
return resizeImage($src_img, $destination, imagesx($src_img), imagesy($src_img), $max_width === null ? imagesx($src_img) : $max_width, $max_height === null ? imagesy($src_img) : $max_height, true, $preferred_format);
}
}
return false;
}
开发者ID:scripple,项目名称:Elkarte,代码行数:59,代码来源:Graphics.subs.php
示例9: AdminSearchOM
function AdminSearchOM()
{
global $context, $sourcedir;
$docsURL = 'docs.simplemachines.org';
$context['doc_scripturl'] = 'http://docs.simplemachines.org/index.php';
// Set all the parameters search might expect.
$postVars = array('search' => $context['search_term']);
// Encode the search data.
foreach ($postVars as $k => $v) {
$postVars[$k] = urlencode($k) . '=' . urlencode($v);
}
// This is what we will send.
$postVars = implode('&', $postVars);
// Get the results from the doc site.
require_once $sourcedir . '/lib/Subs-Package.php';
$search_results = fetch_web_data($context['doc_scripturl'] . '?action=search2&xml', $postVars);
// If we didn't get any xml back we are in trouble - perhaps the doc site is overloaded?
if (!$search_results || preg_match('~<' . '\\?xml\\sversion="\\d+\\.\\d+"\\sencoding=".+?"\\?' . '>\\s*(<smf>.+?</smf>)~is', $search_results, $matches) != true) {
fatal_lang_error('cannot_connect_doc_site');
}
$search_results = $matches[1];
// Otherwise we simply walk through the XML and stick it in context for display.
$context['search_results'] = array();
loadClassFile('Class-Package.php');
// Get the results loaded into an array for processing!
$results = new xmlArray($search_results, false);
// Move through the smf layer.
if (!$results->exists('smf')) {
fatal_lang_error('cannot_connect_doc_site');
}
$results = $results->path('smf[0]');
// Are there actually some results?
if (!$results->exists('noresults') && !$results->exists('results')) {
fatal_lang_error('cannot_connect_doc_site');
} elseif ($results->exists('results')) {
foreach ($results->set('results/result') as $result) {
if (!$result->exists('messages')) {
continue;
}
$context['search_results'][$result->fetch('id')] = array('topic_id' => $result->fetch('id'), 'relevance' => $result->fetch('relevance'), 'board' => array('id' => $result->fetch('board/id'), 'name' => $result->fetch('board/name'), 'href' => $result->fetch('board/href')), 'category' => array('id' => $result->fetch('category/id'), 'name' => $result->fetch('category/name'), 'href' => $result->fetch('category/href')), 'messages' => array());
// Add the messages.
foreach ($result->set('messages/message') as $message) {
$context['search_results'][$result->fetch('id')]['messages'][] = array('id' => $message->fetch('id'), 'subject' => $message->fetch('subject'), 'body' => $message->fetch('body'), 'time' => $message->fetch('time'), 'timestamp' => $message->fetch('timestamp'), 'start' => $message->fetch('start'), 'author' => array('id' => $message->fetch('author/id'), 'name' => $message->fetch('author/name'), 'href' => $message->fetch('author/href')));
}
}
}
}
开发者ID:norv,项目名称:EosAlpha,代码行数:47,代码来源:Admin.php
示例10: sp_rssFeed
function sp_rssFeed($parameters, $id, $return_parameters = false)
{
global $smcFunc, $sourcedir, $context, $txt;
$block_parameters = array('url' => 'text', 'show_title' => 'check', 'show_content' => 'check', 'show_date' => 'check', 'strip_preserve' => 'text', 'count' => 'int', 'limit' => 'int');
if ($return_parameters) {
return $block_parameters;
}
$feed = !empty($parameters['url']) ? un_htmlspecialchars($parameters['url']) : '';
$show_title = !empty($parameters['show_title']);
$show_content = !empty($parameters['show_content']);
$show_date = !empty($parameters['show_date']);
$strip_preserve = !empty($parameters['strip_preserve']) ? $parameters['strip_preserve'] : 'br';
$strip_preserve = preg_match_all('~[A-Za-z0-9]+~', $strip_preserve, $match) ? $match[0] : array();
$count = !empty($parameters['count']) ? (int) $parameters['count'] : 5;
$limit = !empty($parameters['limit']) ? (int) $parameters['limit'] : 150;
if (empty($feed)) {
echo '
', $txt['error_sp_invalid_feed'];
return;
}
$rss = array();
require_once $sourcedir . '/Subs-Package.php';
$data = fetch_web_data($feed);
if (function_exists('mb_convert_encoding')) {
preg_match('~encoding="([^"]*)"~', $data, $charset);
if (!empty($charset[1]) && $charset != $context['character_set']) {
$data = mb_convert_encoding($data, $context['character_set'], $charset[1]);
}
} elseif (function_exists('iconv')) {
preg_match('~encoding="([^"]*)"~', $data, $charset);
if (!empty($charset[1]) && $charset != $context['character_set']) {
$data = iconv($charset[1], $context['character_set'], $data);
}
}
$data = str_replace(array("\n", "\r", "\t"), '', $data);
$data = preg_replace('~<\\!\\[CDATA\\[(.+?)\\]\\]>~e' . ($context['utf8'] ? 'u' : ''), '\'#cdata_escape_encode#\' . $smcFunc[\'htmlspecialchars\'](\'$1\')', $data);
preg_match_all('~<item>(.+?)</item>~', $data, $items);
foreach ($items[1] as $item_id => $item) {
if ($item_id === $count) {
break;
}
preg_match_all('~<([A-Za-z]+)>(.+?)</\\1>~', $item, $match);
foreach ($match[0] as $tag_id => $dummy) {
if ($smcFunc['strpos']($match[2][$tag_id], '#cdata_escape_encode#') === 0) {
$match[2][$tag_id] = stripslashes(un_htmlspecialchars($smcFunc['substr']($match[2][$tag_id], 21)));
}
$rss[$item_id][strtolower($match[1][$tag_id])] = un_htmlspecialchars($match[2][$tag_id]);
}
}
if (empty($rss)) {
echo '
', $txt['error_sp_invalid_feed'];
return;
}
$items = array();
foreach ($rss as $item) {
$item['title'] = isset($item['title']) ? strip_tags($item['title']) : '';
$item['description'] = isset($item['description']) ? strip_tags($item['description'], empty($strip_preserve) ? '' : '<' . implode('><', $strip_preserve) . '>') : '';
$items[] = array('title' => $item['title'], 'href' => $item['link'], 'link' => $item['title'] == '' ? '' : ($item['link'] == '' ? $item['title'] : '<a href="' . $item['link'] . '" target="_blank" class="new_win">' . $item['title'] . '</a>'), 'content' => $limit > 0 && $smcFunc['strlen']($item['description']) > $limit ? $smcFunc['substr']($item['description'], 0, $limit) . '...' : $item['description'], 'date' => !empty($item['pubdate']) ? timeformat(strtotime($item['pubdate']), '%d %B') : '');
}
if (empty($items)) {
echo '
', $txt['error_sp_invalid_feed'];
return;
} else {
$items[count($items) - 1]['is_last'] = true;
}
if ($show_content) {
echo '
<div class="sp_rss_flow">
<ul class="sp_list">';
foreach ($items as $item) {
if ($show_title && !empty($item['link'])) {
echo '
<li class="sp_list_top">', sp_embed_image('post'), ' <strong>', $item['link'], '</strong>', $show_date && !empty($item['date']) ? ' - ' . $item['date'] : '', '</li>';
}
echo '
<li', empty($item['is_last']) ? ' class="sp_list_divider"' : '', '>', $item['content'], '</li>';
}
echo '
</ul>
</div>';
} else {
echo '
<ul class="sp_list">';
foreach ($items as $item) {
echo '
<li>', sp_embed_image('dot_feed'), ' ', $item['link'], $show_date && !empty($item['date']) ? ' - ' . $item['date'] : '', '</li>';
}
echo '
</ul>';
}
}
开发者ID:sk8rdude461,项目名称:moparscape.org-smf,代码行数:93,代码来源:PortalBlocks.php
示例11: list_getLanguagesList
/**
* Gets a list of available languages from the mother ship
*
* - Will return a subset if searching, otherwise all available
*
* @package Languages
* @return string
*/
function list_getLanguagesList()
{
global $forum_version, $context, $txt, $scripturl;
// We're going to use this URL.
// @todo no we are not, this needs to be changed - again
$url = 'http://download.elkarte.net/fetch_language.php?version=' . urlencode(strtr($forum_version, array('ElkArte ' => '')));
// Load the class file and stick it into an array.
require_once SUBSDIR . '/XmlArray.class.php';
$language_list = new Xml_Array(fetch_web_data($url), true);
// Check that the site responded and that the language exists.
if (!$language_list->exists('languages')) {
$context['langfile_error'] = 'no_response';
} elseif (!$language_list->exists('languages/language')) {
$context['langfile_error'] = 'no_files';
} else {
$language_list = $language_list->path('languages[0]');
$lang_files = $language_list->set('language');
$languages = array();
foreach ($lang_files as $file) {
// Were we searching?
if (!empty($context['elk_search_term']) && strpos($file->fetch('name'), Util::strtolower($context['elk_search_term'])) === false) {
continue;
}
$languages[] = array('id' => $file->fetch('id'), 'name' => Util::ucwords($file->fetch('name')), 'version' => $file->fetch('version'), 'utf8' => $txt['yes'], 'description' => $file->fetch('description'), 'install_link' => '<a href="' . $scripturl . '?action=admin;area=languages;sa=downloadlang;did=' . $file->fetch('id') . ';' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['add_language_elk_install'] . '</a>');
}
if (empty($languages)) {
$context['langfile_error'] = 'no_files';
} else {
return $languages;
}
}
}
开发者ID:KeiroD,项目名称:Elkarte,代码行数:40,代码来源:Language.subs.php
示例12: fb_do_agree
public static function fb_do_agree()
{
global $sourcedir, $context, $boarddir, $boardurl, $user_info, $fb_hook_object;
require_once $sourcedir . '/Subs-Package.php';
if (isset($_GET['agree'])) {
loadLanguage('Login');
$context['sub_template'] = 'regfb_agree';
if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) {
$context['agreement'] = parse_bbc(fetch_web_data($boardurl . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']);
} elseif (file_exists($boarddir . '/agreement.txt')) {
$context['agreement'] = parse_bbc(fetch_web_data($boardurl . '/agreement.txt'), true, 'agreement');
} else {
$context['agreement'] = '';
}
} else {
if (!isset($_POST['accept_agreement']) && !empty($fb_hook_object->modSettings['requireAgreement'])) {
redirectexit('action=facebookintegrate;area=connect;agree');
}
}
}
开发者ID:VBGAMER45,项目名称:SMFMods,代码行数:20,代码来源:FacebookIntergrate.php
示例13: downloadAvatar
function downloadAvatar($url, $memID, $max_width, $max_height)
{
global $modSettings, $db_prefix, $sourcedir, $gd2;
$destName = 'avatar_' . $memID . '.' . (!empty($modSettings['avatar_download_png']) ? 'png' : 'jpeg');
$default_formats = array('1' => 'gif', '2' => 'jpeg', '3' => 'png', '6' => 'bmp', '15' => 'wbmp');
// Check to see if GD is installed and what version.
$testGD = get_extension_funcs('gd');
// If GD is not installed, this function is pointless.
if (empty($testGD)) {
return false;
}
// Just making sure there is a non-zero member.
if (empty($memID)) {
return false;
}
// GD 2 maybe?
$gd2 = in_array('imagecreatetruecolor', $testGD) && function_exists('imagecreatetruecolor');
unset($testGD);
require_once $sourcedir . '/ManageAttachments.php';
removeAttachments('a.ID_MEMBER = ' . $memID);
$avatar_hash = empty($modSettings['custom_avatar_enabled']) ? getAttachmentFilename($destName, false, true) : '';
db_query("\n\t\tINSERT INTO {$db_prefix}attachments\n\t\t\t(ID_MEMBER, attachmentType, filename, file_hash, size)\n\t\tVALUES ({$memID}, " . (empty($modSettings['custom_avatar_enabled']) ? '0' : '1') . ", '{$destName}', '" . (empty($avatar_hash) ? "" : "{$avatar_hash}") . "', 1)", __FILE__, __LINE__);
$attachID = db_insert_id();
$destName = (empty($modSettings['custom_avatar_enabled']) ? $modSettings['attachmentUploadDir'] : $modSettings['custom_avatar_dir']) . '/' . $destName . '.tmp';
$success = false;
$sizes = url_image_size($url);
require_once $sourcedir . '/Subs-Package.php';
$fp = fopen($destName, 'wb');
if ($fp && substr($url, 0, 7) == 'http://') {
$fileContents = fetch_web_data($url);
// Though not an exhaustive list, better safe than sorry.
if (preg_match('~(iframe|\\<\\?php|\\<\\?[\\s=]|\\<%[\\s=]|html|eval|body|script\\W)~', $fileContents) === 1) {
fclose($fp);
return false;
}
fwrite($fp, $fileContents);
fclose($fp);
} elseif ($fp) {
$fp2 = fopen($url, 'rb');
$prev_chunk = '';
while (!feof($fp2)) {
$cur_chunk = fread($fp2, 8192);
// Make sure nothing odd came through.
if (preg_match('~(iframe|\\<\\?php|\\<\\?[\\s=]|\\<%[\\s=]|html|eval|body|script\\W)~', $prev_chunk . $cur_chunk) === 1) {
fclose($fp2);
fclose($fp);
unlink($destName);
return false;
}
fwrite($fp, $cur_chunk);
$prev_chunk = $cur_chunk;
}
fclose($fp2);
fclose($fp);
} else {
$sizes = array(-1, -1, -1);
}
// Gif? That might mean trouble if gif support is not available.
if ($sizes[2] == 1 && !function_exists('imagecreatefromgif') && function_exists('imagecreatefrompng')) {
// Download it to the temporary file... use the special gif library... and save as png.
if ($img = @gif_loadFile($destName) && gif_outputAsPng($img, $destName)) {
$sizes[2] = 3;
}
}
// A known and supported format?
if (isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]])) {
$imagecreatefrom = 'imagecreatefrom' . $default_formats[$sizes[2]];
if ($src_img = @$imagecreatefrom($destName)) {
resizeImage($src_img, $destName, imagesx($src_img), imagesy($src_img), $max_width, $max_height);
$success = true;
}
}
// Remove the .tmp extension.
$destName = substr($destName, 0, -4);
if ($success) {
// Remove the .tmp extension from the attachment.
if (rename($destName . '.tmp', empty($avatar_hash) ? $destName : $modSettings['attachmentUploadDir'] . '/' . $attachID . '_' . $avatar_hash)) {
$destName = empty($avatar_hash) ? $destName : $modSettings['attachmentUploadDir'] . '/' . $attachID . '_' . $avatar_hash;
list($width, $height) = getimagesize($destName);
// Write filesize in the database.
db_query("\n\t\t\t\tUPDATE {$db_prefix}attachments\n\t\t\t\tSET size = " . filesize($destName) . ", width = " . (int) $width . ", height = " . (int) $height . "\n\t\t\t\tWHERE ID_ATTACH = {$attachID}\n\t\t\t\tLIMIT 1", __FILE__, __LINE__);
return true;
} else {
return false;
}
} else {
db_query("\n\t\t\tDELETE FROM {$db_prefix}attachments\n\t\t\tWHERE ID_ATTACH = {$attachID}\n\t\t\tLIMIT 1", __FILE__, __LINE__);
@unlink($destName . '.tmp');
return false;
}
}
开发者ID:VBGAMER45,项目名称:SMFMods,代码行数:91,代码来源:Subs-Graphics.php
示例14: sp_rssFeed
/**
* RSS Block, Displays rss feed in a block.
*
* @param mixed[] $parameters
* 'url' => url of the feed
* 'show_title' => Show the feed title
* 'show_content' => Show the content of the feed
* 'show_date' => Show the date of the feed item
* 'strip_preserve' => preserve tags
* 'count' => number of items to show
* 'limit' => number of characters of content to show
* @param int $id - not used in this block
* @param boolean $return_parameters if true returns the configuration options for the block
*/
function sp_rssFeed($parameters, $id, $return_parameters = false)
{
global $txt;
$block_parameters = array('url' => 'text', 'show_title' => 'check', 'show_content' => 'check', 'show_date' => 'check', 'strip_preserve' => 'text', 'count' => 'int', 'limit' => 'int');
if ($return_parameters) {
return $block_parameters;
}
$feed = !empty($parameters['url']) ? un_htmlspecialchars($parameters['url']) : '';
$show_title = !empty($parameters['show_title']);
$show_content = !empty($parameters['show_content']);
$show_date = !empty($parameters['show_date']);
$strip_preserve = !empty($parameters['strip_preserve']) ? $parameters['strip_preserve'] : 'br';
$strip_preserve = preg_match_all('~[A-Za-z0-9]+~', $strip_preserve, $match) ? $match[0] : array();
$count = !empty($parameters['count']) ? (int) $parameters['count'] : 5;
$limit = !empty($parameters['limit']) ? (int) $parameters['limit'] : 0;
// Need a feed name to load it
if (empty($feed)) {
echo '
', $txt['error_sp_invalid_feed'];
return;
}
$rss = array();
require_once SUBSDIR . '/Package.subs.php';
$data = fetch_web_data($feed);
$data_save = $data;
// Convert it to UTF8 if we can and its not already
preg_match('~encoding="([^"]*)"~', $data, $charset);
if (!empty($charset[1]) && $charset != 'UTF-8') {
// Use iconv if its available
if (function_exists('iconv')) {
$data = @iconv($charset[1], 'UTF-8' . '//TRANSLIT//IGNORE', $data);
}
// No iconv or a false response from it
if (!function_exists('iconv') || $data == false) {
// PHP (some 5.4 versions) mishandles //TRANSLIT//IGNORE and returns false: see https://bugs.php.net/bug.php?id=61484
if ($data == false) {
$data = $data_save;
}
if (function_exists('mb_convert_encoding')) {
// Replace unknown characters with a space
@ini_set('mbstring.substitute_character', '32');
$data = @mb_convert_encoding($data, 'UTF-8', $charset[1]);
} elseif (function_exists('recode_string')) {
$data = @recode_string($charset[1] . '..' . 'UTF-8', $data);
}
}
}
$data = str_replace(array("\n", "\r", "\t"), '', $data);
$data = preg_replace('~<\\!\\[CDATA\\[(.+?)\\]\\]>~eu', '\'#cdata_escape_encode#\' . Util::htmlspecialchars(\'$1\')', $data);
// Find all the feed items
preg_match_all('~<item>(.+?)</item>~', $data, $items);
foreach ($items[1] as $item_id => $item) {
if ($item_id === $count) {
break;
}
preg_match_all('~<([A-Za-z]+)>(.+?)</\\1>~', $item, $match);
foreach ($match[0] as $tag_id => $dummy) {
if (Util::strpos($match[2][$tag_id], '#cdata_escape_encode#') === 0) {
$match[2][$tag_id] = stripslashes(un_htmlspecialchars(Util::substr($match[2][$tag_id], 21)));
}
$rss[$item_id][strtolower($match[1][$tag_id])] = un_htmlspecialchars($match[2][$tag_id]);
}
}
// Nothing, say its invalid
if (empty($rss)) {
echo '
', $txt['error_sp_invalid_feed'];
return;
}
// Add all the items to an array
$items = array();
foreach ($rss as $item) {
$item['title'] = isset($item['title']) ? strip_tags($item['title']) : '';
$item['description'] = isset($item['description']) ? strip_tags($item['description'], empty($strip_preserve) ? '' : '<' . implode('><', $strip_preserve) . '>') : '';
$items[] = array('title' => $item['title'], 'href' => $item['link'], 'link' => $item['title'] == '' ? '' : ($item['link'] == '' ? $item['title'] : '<a href="' . $item['link'] . '" target="_blank" class="new_win">' . $item['title'] . '</a>'), 'content' => $limit > 0 ? Util::shorten_text($item['description'], $limit, true) : $item['description'], 'date' => !empty($item['pubdate']) ? standardTime(strtotime($item['pubdate']), '%d %B') : '');
}
// No items in the feed
if (empty($items)) {
echo '
', $txt['error_sp_invalid_feed'];
return;
} else {
$items[count($items) - 1]['is_last'] = true;
}
if ($show_content) {
echo '
//.........这里部分代码省略.........
开发者ID:emanuele45,项目名称:SimplePortal_ElkArte,代码行数:101,代码来源:PortalBlocks.subs.php
示例15: action_install
/**
* Install a smiley set.
*/
public function action_install()
{
global $modSettings, $scripturl, $context, $txt, $user_info;
isAllowedTo('manage_smileys');
checkSession('request');
// One of these two may be necessary
loadLanguage('Errors');
loadLanguage('Packages');
require_once SUBSDIR . '/Smileys.subs.php';
require_once SUBSDIR . '/Package.subs.php';
// Installing unless proven otherwise
$testing = false;
$destination = '';
$name = '';
if (isset($_REQUEST['set_gz'])) {
$base_name = strtr(basename($_REQUEST['set_gz']), ':/', '-_');
$name = Util::htmlspecialchars(strtok(basename($_REQUEST['set_gz']), '.'));
$name_pr = preg_replace(array('/\\s/', '/\\.[\\.]+/', '/[^\\w_\\.\\-]/'), array('_', '.', ''), $name);
$context['filename'] = $base_name;
// Check that the smiley is from simplemachines.org, for now... maybe add mirroring later.
if (!isAuthorizedServer($_REQUEST['set_gz']) == 0) {
fatal_lang_error('not_valid_server');
}
$destination = BOARDDIR . '/packages/' . $base_name;
if (file_exists($destination)) {
fatal_lang_error('package_upload_error_exists');
}
// Let's copy it to the packages directory
file_put_contents($destination, fetch_web_data($_REQUEST['set_gz']));
$testing = true;
} elseif (isset($_REQUEST['package'])) {
$base_name = basename($_REQUEST['package']);
$name = Util::htmlspecialchars(strtok(basename($
|
请发表评论