本文整理汇总了PHP中FileUtil::downloadFileFromHttp方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUtil::downloadFileFromHttp方法的具体用法?PHP FileUtil::downloadFileFromHttp怎么用?PHP FileUtil::downloadFileFromHttp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileUtil
的用法示例。
在下文中一共展示了FileUtil::downloadFileFromHttp方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseFeed
/**
* Parse a rss feed.
*
* @param string $sourceURL
* @return array
*/
public static function parseFeed($sourceURL)
{
$newsItems = array();
$filename = FileUtil::downloadFileFromHttp($sourceURL, 'feed');
// open & parse file
$xml = new XML($filename);
$data = $xml->getElementTree('channel');
$items = $data['children'][0]['children'];
foreach ($items as $item) {
if ($item['name'] != 'item') {
continue;
}
$newsItem = array('title' => '', 'author' => '', 'link' => '', 'guid' => '', 'pubDate' => '', 'description' => '');
foreach ($item['children'] as $child) {
if (!isset($child['cdata'])) {
continue;
}
$newsItem[$child['name']] = $child['cdata'];
}
// convert encodings
if (CHARSET != 'UTF-8') {
$newsItem['title'] = StringUtil::convertEncoding('UTF-8', CHARSET, $newsItem['title']);
$newsItem['author'] = StringUtil::convertEncoding('UTF-8', CHARSET, $newsItem['author']);
$newsItem['link'] = StringUtil::convertEncoding('UTF-8', CHARSET, $newsItem['link']);
$newsItem['guid'] = StringUtil::convertEncoding('UTF-8', CHARSET, $newsItem['guid']);
$newsItem['description'] = StringUtil::convertEncoding('UTF-8', CHARSET, $newsItem['description']);
}
@($newsItem['pubDate'] = intval(strtotime($newsItem['pubDate'])));
$newsItems[] = $newsItem;
}
// delete tmp file
@unlink($filename);
return $newsItems;
}
示例2: makeURLTitle
/**
* callback function for adding the title to external urls
*
* @param array $matches
*/
protected function makeURLTitle($matches)
{
$url = $matches[1];
// add protocol if necessary
if (!preg_match("/[a-z]:\\/\\//si", $url)) {
$url = 'http://' . $url;
}
if (!$this->isInternalURL($url)) {
// found an external url (using url bbocdes detection method)
if (!isset(self::$cachedURLs[$url])) {
self::$cachedURLs[$url] = $url;
try {
@ini_set("default_socket_timeout ", 10);
//set timeout if possible
/* Get the MIME type and character set */
$headers = get_headers($url, 1);
$contentType = $headers['Content-Type'];
preg_match('@([\\w/+]+)(;\\s+charset=(\\S+))?@i', $contentType, $matches);
$mime = '';
$charset = 'auto';
if (isset($matches[1])) {
$mime = $matches[1];
}
if (isset($matches[3])) {
$charset = $matches[3];
}
if ($mime = 'text/html') {
$filePath = FileUtil::downloadFileFromHttp($url, 'fetch_hyperlink');
$fileContent = file_get_contents($filePath);
@unlink($filePath);
if (preg_match("/<title>(.*?)<\\/title>/is", $fileContent, $titleMatches)) {
// cache title
self::$cachedURLs[$url] = self::normalizeTitle($titleMatches[1], $charset);
}
}
} catch (Exception $e) {
/* if fetching the title fails for whatever reason, simply do nothing */
}
}
return '[url=\'' . $url . '\']' . self::$cachedURLs[$url] . '[/url]';
}
return '[url]' . $url . '[/url]';
}
示例3: sendRequest
/**
* Sends a request.
*/
protected static function sendRequest($worldID, $args)
{
self::getAccessableServers();
$server = self::$servers[$worldID];
// build query string
$queryStr = $server['url'] . 'board_reg.php';
foreach ($args as $argName => $argValue) {
if (isset($arg)) {
$queryStr .= '&';
} else {
$queryStr .= '?';
$arg = true;
}
$queryStr .= rawurlencode($argName) . '=' . rawurlencode($argValue);
}
// send request
$fileName = FileUtil::downloadFileFromHttp($queryStr, 'lost-worlds');
//if($args['action'] == 2) include($fileName);
// update wcf
self::updateWCF($worldID);
}
示例4: getURL
/**
* @see DisplayableAvatar::getURL()
*/
public function getURL()
{
if ($this->url === null) {
// try to use cached gravatar
$cachedFilename = sprintf(self::GRAVATAR_CACHE_LOCATION, md5($this->gravatar), $this->size);
if (file_exists(WCF_DIR . $cachedFilename) && filemtime(WCF_DIR . $cachedFilename) > TIME_NOW - self::GRAVATAR_CACHE_EXPIRE * 86400) {
$this->url = RELATIVE_WCF_DIR . $cachedFilename;
} else {
$gravatarURL = sprintf(self::GRAVATAR_BASE, md5($this->gravatar), $this->size, rawurlencode(RELATIVE_WCF_DIR . 'images/avatars/avatar-default.png'));
try {
$tmpFile = FileUtil::downloadFileFromHttp($gravatarURL, 'gravatar');
copy($tmpFile, WCF_DIR . $cachedFilename);
@unlink($tmpFile);
@chmod(WCF_DIR . $cachedFilename, 0777);
$this->url = RELATIVE_WCF_DIR . $cachedFilename;
} catch (SystemException $e) {
$this->url = RELATIVE_WCF_DIR . 'images/avatars/avatar-default.png';
}
}
}
return $this->url;
}
示例5: execute
/**
* @see Cronjob::execute()
*/
public function execute($data)
{
$filename = FileUtil::downloadFileFromHttp('http://www.woltlab.com/spiderlist/spiderlist.xml', 'spiders');
$xml = new XML($filename);
$spiders = $xml->getElementTree('spiderlist');
if (count($spiders['children'])) {
// delete old entries
$sql = "TRUNCATE TABLE wcf" . WCF_N . "_spider";
WCF::getDB()->sendQuery($sql);
$inserts = '';
foreach ($spiders['children'] as $spider) {
$identifier = $spider['attrs']['ident'];
// get attributes
foreach ($spider['children'] as $values) {
$spider[$values['name']] = $values['cdata'];
}
$name = $spider['name'];
$info = '';
if (isset($spider['info'])) {
$info = $spider['info'];
}
if (!empty($inserts)) {
$inserts .= ',';
}
$inserts .= "('" . escapeString(StringUtil::toLowerCase($identifier)) . "', '" . escapeString($name) . "', '" . escapeString($info) . "')";
}
if (!empty($inserts)) {
$sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_spider\n\t\t\t\t\t\t\t\t(spiderIdentifier, spiderName, spiderURL)\n\t\t\t\t\tVALUES\t\t\t" . $inserts;
WCF::getDB()->sendQuery($sql);
}
// clear spider cache
WCF::getCache()->clear(WCF_DIR . 'cache', 'cache.spiders.php');
}
// delete tmp file
@unlink($filename);
}
示例6: define
<?php
/*
This file is part of WOT Game.
WOT Game is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
WOT Game is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with WOT Game. If not, see <http://www.gnu.org/licenses/>.
*/
define('INSIDE', true);
$ugamela_root_path = '../';
include $ugamela_root_path . 'extension.inc';
include $ugamela_root_path . 'common.' . $phpEx;
if (!check_user()) {
header("Location: login.php");
die;
}
$fileName = FileUtil::downloadFileFromHttp('http://neu.lost-worlds.de/game/index.php?page=XMLStatistics', 'statistics');
$xmlObj = new XML($fileName);
$arr = $xmlObj->xpath('./*[@userID="156"]');
var_dump($arr);
示例7: validate
/**
* @see Form::validate()
*/
public function validate()
{
parent::validate();
if ($this->avatarID) {
if ($this->avatarID == -1) {
if (empty($this->gravatar)) {
// check permission
WCF::getUser()->checkPermission('user.profile.avatar.canUploadAvatar');
// upload or download avatar
if ($this->avatarUpload && $this->avatarUpload['error'] != 4) {
if ($this->avatarUpload['error'] != 0) {
throw new UserInputException('avatarUpload', 'uploadFailed');
}
$this->avatarID = AvatarEditor::create($this->avatarUpload['tmp_name'], $this->avatarUpload['name'], 'avatarUpload', WCF::getUser()->userID);
} else {
if ($this->avatarURL != 'http://') {
if (StringUtil::indexOf($this->avatarURL, 'http://') !== 0) {
throw new UserInputException('avatarURL', 'downloadFailed');
}
try {
$tmpName = FileUtil::downloadFileFromHttp($this->avatarURL, 'avatar');
} catch (SystemException $e) {
throw new UserInputException('avatarURL', 'downloadFailed');
}
$this->avatarID = AvatarEditor::create($tmpName, $this->avatarURL, 'avatarURL', WCF::getUser()->userID);
} else {
throw new UserInputException('avatarUpload');
}
}
} else {
$this->avatarID = 0;
}
} else {
// check permission
WCF::getUser()->checkPermission('user.profile.avatar.canUseDefaultAvatar');
// use a default avatar
$avatar = new AvatarEditor($this->avatarID);
if (!$avatar->avatarID || $avatar->userID || $avatar->groupID && !in_array($avatar->groupID, WCF::getUser()->getGroupIDs()) || $avatar->neededPoints > WCF::getUser()->activityPoints) {
throw new UserInputException('availableAvatars', 'invalid');
}
// check category permissions
if ($avatar->avatarCategoryID) {
$category = new AvatarCategory($avatar->avatarCategoryID);
if ($category->groupID && !in_array($category->groupID, WCF::getUser()->getGroupIDs()) || $category->neededPoints > WCF::getUser()->activityPoints) {
throw new UserInputException('availableAvatars', 'invalid');
}
}
}
}
}
示例8: validate
/**
* @see Form::validate()
*/
public function validate()
{
parent::validate();
if (!empty($this->filename)) {
// import style
$this->style = StyleEditor::import($this->filename, PACKAGE_ID, $this->destinationStyle !== null && $this->destinationStyle->styleID ? $this->destinationStyle : null);
} else {
// import destination
if ($this->destinationStyle !== null && !$this->destinationStyle->styleID) {
throw new UserInputException('destinationStyleID');
}
// upload style
if ($this->styleUpload && $this->styleUpload['error'] != 4) {
if ($this->styleUpload['error'] != 0) {
throw new UserInputException('styleUpload', 'uploadFailed');
}
$this->newFilename = $this->styleUpload['tmp_name'];
try {
$this->styleData = StyleEditor::getStyleData($this->styleUpload['tmp_name']);
} catch (SystemException $e) {
throw new UserInputException('styleUpload', 'invalid');
}
// copy file
$newFilename = FileUtil::getTemporaryFilename('style_');
if (@move_uploaded_file($this->styleUpload['tmp_name'], $newFilename)) {
$this->newFilename = $newFilename;
}
} else {
if ($this->styleURL != 'http://') {
if (StringUtil::indexOf($this->styleURL, 'http://') !== 0) {
throw new UserInputException('styleURL', 'downloadFailed');
}
try {
$this->newFilename = FileUtil::downloadFileFromHttp($this->styleURL, 'style');
} catch (SystemException $e) {
throw new UserInputException('styleURL', 'downloadFailed');
}
try {
$this->styleData = StyleEditor::getStyleData($this->newFilename);
} catch (SystemException $e) {
throw new UserInputException('styleURL', 'invalid');
}
} else {
throw new UserInputException('styleUpload');
}
}
}
}
示例9: validateDownloadFile
/**
* Validates the download file input.
*
* @throws UserInputException
*/
protected function validateDownloadFile()
{
if (FileUtil::isURL($this->downloadFile)) {
//download file
$parsedUrl = parse_url($this->downloadFile);
$prefix = 'importSubscriber';
try {
// file transfer via hypertext transfer protocol.
if ($parsedUrl['scheme'] == 'http') {
$this->downloadFile = FileUtil::downloadFileFromHttp($this->downloadFile, $prefix);
} elseif ($parsedUrl['scheme'] == 'ftp') {
$this->downloadFile = FTPUtil::downloadFileFromFtp($this->downloadFile, $prefix);
}
} catch (SystemException $e) {
throw new UserInputException('downloadFile', 'notFound');
}
} else {
// probably local path
if (!file_exists($this->downloadFile)) {
throw new UserInputException('downloadFile', 'notFound');
}
}
}
示例10: execute
/**
* @see EventListener::execute()
*/
public function execute($eventObj, $className, $eventName)
{
if (MODULE_AVATAR == 1) {
if ($eventName == 'readFormParameters') {
if (isset($_POST['avatarID'])) {
$this->avatarID = intval($_POST['avatarID']);
}
if (isset($_POST['disableAvatar'])) {
$this->disableAvatar = intval($_POST['disableAvatar']);
}
if (isset($_POST['disableAvatarReason'])) {
$this->disableAvatarReason = $_POST['disableAvatarReason'];
}
if (isset($_POST['useAvatar'])) {
$this->useAvatar = intval($_POST['useAvatar']);
}
if (isset($_POST['avatarURL'])) {
$this->avatarURL = StringUtil::trim($_POST['avatarURL']);
}
if (isset($_FILES['avatarUpload'])) {
$this->avatarUpload = $_FILES['avatarUpload'];
}
if (MODULE_GRAVATAR == 1 && isset($_POST['gravatar'])) {
$this->gravatar = StringUtil::trim($_POST['gravatar']);
}
} else {
if ($eventName == 'validate') {
try {
if ($this->useAvatar == 1) {
if (empty($this->gravatar)) {
// upload or download avatar
if ($this->avatarUpload && $this->avatarUpload['error'] != 4) {
if ($this->avatarUpload['error'] != 0) {
throw new UserInputException('avatarUpload', 'uploadFailed');
}
$this->avatarID = AvatarEditor::create($this->avatarUpload['tmp_name'], $this->avatarUpload['name'], 'avatarUpload', $eventObj->userID);
} else {
if ($this->avatarURL != 'http://') {
if (StringUtil::indexOf($this->avatarURL, 'http://') !== 0) {
throw new UserInputException('avatarURL', 'downloadFailed');
}
try {
$tmpName = FileUtil::downloadFileFromHttp($this->avatarURL, 'avatar');
} catch (SystemException $e) {
throw new UserInputException('avatarURL', 'downloadFailed');
}
$this->avatarID = AvatarEditor::create($tmpName, $this->avatarURL, 'avatarURL', $eventObj->userID);
} else {
$this->avatarID = $eventObj->user->avatarID;
}
}
}
} else {
if ($this->useAvatar == 2) {
// use a default avatar
$avatar = new AvatarEditor($this->avatarID);
if (!$avatar->avatarID || $avatar->userID || $avatar->groupID && !in_array($avatar->groupID, $eventObj->user->getGroupIDs()) || $avatar->neededPoints > $eventObj->user->activityPoints) {
throw new UserInputException('availableAvatars', 'invalid');
}
} else {
$this->avatarID = 0;
}
}
} catch (UserInputException $e) {
$eventObj->errorType[$e->getField()] = $e->getType();
}
} else {
if ($eventName == 'save') {
// delete old avatar if necessary
if ($eventObj->user->avatarID) {
$currentAvatar = new AvatarEditor($eventObj->user->avatarID);
if ($currentAvatar->userID && $this->avatarID != $currentAvatar->avatarID) {
$currentAvatar->delete();
}
}
// update user
$eventObj->additionalFields['avatarID'] = $this->avatarID;
$eventObj->additionalFields['disableAvatar'] = $this->disableAvatar;
$eventObj->additionalFields['disableAvatarReason'] = $this->disableAvatarReason;
$eventObj->additionalFields['gravatar'] = $this->gravatar;
} else {
if ($eventName == 'show') {
// get default values
if (!count($_POST)) {
$this->avatarID = $eventObj->user->avatarID;
$this->disableAvatar = $eventObj->user->disableAvatar;
$this->disableAvatarReason = $eventObj->user->disableAvatarReason;
$this->gravatar = $eventObj->user->gravatar;
}
$currentAvatar = null;
if ($this->avatarID) {
$currentAvatar = new AvatarEditor($this->avatarID);
$this->useAvatar = $currentAvatar->userID ? 1 : 2;
} else {
if ($this->gravatar) {
require_once WCF_DIR . 'lib/data/user/avatar/Gravatar.class.php';
$currentAvatar = new Gravatar($this->gravatar);
//.........这里部分代码省略.........
示例11: getData
/**
* @see CacheBuilder::getData()
*/
public function getData($cacheResource)
{
list($cache, $instanceID) = explode('-', $cacheResource['cache']);
// create array (0 => commits, 1 => api errors)
$data = array(0 => array(), 1 => '');
try {
// create instance
$instance = new InstanceableModule($instanceID);
// create api url
$apiUrl = 'http://github.com/api/v2/xml/commits/list/' . $instance->getOptions()->getGroup('general')->getOption('username')->getValue() . '/' . $instance->getOptions()->getGroup('general')->getOption('repository')->getValue() . '/' . $instance->getOptions()->getGroup('general')->getOption('branch')->getValue();
// download xml
$filename = FileUtil::downloadFileFromHttp($apiUrl);
// create new xml instance
$xml = new XML($filename);
// load tree
$commitXML = $xml->getElementTree('commits');
// check for errors
if (isset($commitXML['children'][0]) and $commitXML['children'][0]['name'] == 'error') {
$data[1] = $commitXML['children'][0]['cdata'];
return $data;
}
// all ok .. loop througt array
foreach ($commitXML['children'] as $commit) {
// create commit array
$tmp = array('url' => 'https://github.com', 'id' => '', 'message' => '', 'author' => '', 'authorEmail' => '', 'date' => 0);
// create information array
$tmpInfo = array();
// loop througt children
foreach ($commit['children'] as $child) {
if ($child['name'] == 'committer') {
// create array for information
$tmpInfo['committer'] = array();
// loop througt children
foreach ($child['children'] as $cChild) {
// no cdata field found ... exit
if (!isset($cChild['cdata'])) {
continue;
}
// write value
$tmpInfo['committer'][$cChild['name']] = $cChild['cdata'];
}
// end loop
continue;
}
// no cdata field found ... exit
if (!isset($child['cdata'])) {
continue;
}
// write value
$tmpInfo[$child['name']] = $child['cdata'];
}
// write values
$tmp['url'] .= $tmpInfo['url'];
$tmp['id'] = $tmpInfo['id'];
$tmp['message'] = $tmpInfo['message'];
$tmp['author'] = $tmpInfo['committer']['name'];
$tmp['authorEmail'] = $tmpInfo['committer']['email'];
$tmp['date'] = strtotime($tmpInfo['committed-date']);
// write tmp array
$data[0][] = $tmp;
// remove old tmp array
unset($tmp);
}
} catch (SystemException $ex) {
$data[1] = $ex->getMessage();
}
// return parsed commits
return $data;
}
示例12: downloadArchive
/**
* Downloads the package archive.
*
* @return string path to the dowloaded file
*/
public function downloadArchive()
{
$parsedUrl = parse_url($this->archive);
$prefix = 'package';
// file transfer via hypertext transfer protocol.
if ($parsedUrl['scheme'] == 'http') {
$this->archive = FileUtil::downloadFileFromHttp($this->archive, $prefix);
} elseif ($parsedUrl['scheme'] == 'ftp') {
$this->archive = FTPUtil::downloadFileFromFtp($this->archive, $prefix);
}
// unzip tar
$this->archive = self::unzipPackageArchive($this->archive);
return $this->archive;
}
示例13: validateText
/**
* @see MessageForm::validateText()
*/
protected function validateText()
{
if (empty($this->text)) {
return;
}
parent::validateText();
// check image count
$imageCount = preg_match_all('!\\[img=.+?\\]!i', $this->text, $m) + preg_match_all('!\\[img\\].+?(\\[/img\\]|$)!is', $this->text, $m);
if ($imageCount > WCF::getUser()->getPermission('user.profile.signature.maxImages')) {
throw new UserInputException('text', 'tooManyImages');
}
if (WCF::getUser()->getPermission('user.profile.signature.maxImageSize') > 0 || WCF::getUser()->getPermission('user.profile.signature.maxImageWidth') > 0 || WCF::getUser()->getPermission('user.profile.signature.maxImageHeight') > 0) {
// get images
$images = array();
// [img=path][/img] syntax
preg_match_all("!\\[img=(?:'([^'\\\\]+|\\\\.)*'|(.+?))(?:,(?:'(?:left|right)'|(?:left|right)))?\\]!i", $this->text, $matches);
$images = array_merge($images, ArrayUtil::trim($matches[1]), ArrayUtil::trim($matches[2]));
// [img]path[/img] syntax
preg_match_all("!\\[img\\](.+?)(\\[/img\\]|\$)!is", $this->text, $matches);
$images = array_merge($images, ArrayUtil::trim($matches[1]));
$errors = array();
foreach ($images as $image) {
// download file
try {
if (@($tmpFile = FileUtil::downloadFileFromHttp($image, 'image_'))) {
if (WCF::getUser()->getPermission('user.profile.signature.maxImageSize') > 0) {
// get remote image size (byte)
if (filesize($tmpFile) > WCF::getUser()->getPermission('user.profile.signature.maxImageSize')) {
$errors[] = array('errorType' => 'tooLarge', 'image' => $image);
continue;
}
}
// get remote image size (pixel)
if (WCF::getUser()->getPermission('user.profile.signature.maxImageWidth') > 0 || WCF::getUser()->getPermission('user.profile.signature.maxImageHeight') > 0) {
if ($size = @getImageSize($tmpFile)) {
$width = $size[0];
$height = $size[1];
if ($width > WCF::getUser()->getPermission('user.profile.signature.maxImageWidth') || $height > WCF::getUser()->getPermission('user.profile.signature.maxImageHeight')) {
$errors[] = array('errorType' => 'tooLarge', 'image' => $image);
}
}
}
}
} catch (SystemException $e) {
}
}
if (count($errors) > 0) {
throw new UserInputException('text', $errors);
}
}
}
示例14: validate
/**
* @see Form::validate()
*/
public function validate()
{
parent::validate();
// use default value for unset variables
foreach ($this->defaultVariables as $name => $value) {
if (!isset($this->variables[$name])) {
$this->variables[$name] = $value;
}
}
// unset unnecessary variables
foreach ($this->variables as $name => $value) {
if (!isset($this->defaultVariables[$name])) {
unset($this->variables[$name]);
}
}
if (empty($this->styleName)) {
throw new UserInputException('styleName');
}
// upload image
if ($this->imageUpload && $this->imageUpload['error'] != 4) {
if ($this->imageUpload['error'] != 0) {
throw new UserInputException('imageUpload', 'uploadFailed');
}
$newImage = WCF_DIR . 'images/' . basename($this->imageUpload['name']);
if (@getImageSize($this->imageUpload['tmp_name']) !== false && @move_uploaded_file($this->imageUpload['tmp_name'], $newImage)) {
$this->image = 'images/' . basename($this->imageUpload['name']);
@chmod($newImage, 0777);
}
} else {
if (!empty($this->image) && FileUtil::isURL($this->image)) {
$newImage = WCF_DIR . 'images/' . basename($this->image);
$tmpFile = FileUtil::downloadFileFromHttp($this->image, 'image');
if (@getImageSize($tmpFile) !== false && @copy($tmpFile, $newImage)) {
$this->image = 'images/' . basename($this->image);
@chmod($newImage, 0777);
}
}
}
// template pack
if ($this->templatePackID) {
$templatePack = new TemplatePackEditor($this->templatePackID);
if (!$templatePack->templatePackID) {
throw new UserInputException('templatePackID');
}
}
}