Merge pull request #504 from zeroadam/feature/Network

Network was moved to src
pull/507/head
Hypolite Petovan 2018-01-27 12:20:55 -05:00 committed by GitHub
commit f96a41a411
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 77 additions and 71 deletions

View File

@ -8,6 +8,7 @@
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Util\Network;
function blogger_install() function blogger_install()
{ {
@ -205,7 +206,7 @@ EOT;
logger('blogger: data: ' . $xml, LOGGER_DATA); logger('blogger: data: ' . $xml, LOGGER_DATA);
if ($bl_blog !== 'test') { if ($bl_blog !== 'test') {
$x = post_url($bl_blog, $xml); $x = Network::post($bl_blog, $xml);
} }
logger('posted to blogger: ' . (($x) ? $x : ''), LOGGER_DEBUG); logger('posted to blogger: ' . (($x) ? $x : ''), LOGGER_DEBUG);

View File

@ -272,11 +272,9 @@ function buffer_send(App $a, &$b)
$client_secret = Config::get("buffer", "client_secret"); $client_secret = Config::get("buffer", "client_secret");
$access_token = PConfig::get($b['uid'], "buffer","access_token"); $access_token = PConfig::get($b['uid'], "buffer","access_token");
if($access_token) { if ($access_token) {
$buffer = new BufferApp($client_id, $client_secret, $callback_url, $access_token); $buffer = new BufferApp($client_id, $client_secret, $callback_url, $access_token);
require_once 'include/network.php';
$profiles = $buffer->go('/profiles'); $profiles = $buffer->go('/profiles');
if (is_array($profiles)) { if (is_array($profiles)) {
logger("Will send these parameter ".print_r($b, true), LOGGER_DEBUG); logger("Will send these parameter ".print_r($b, true), LOGGER_DEBUG);
@ -353,11 +351,11 @@ function buffer_send(App $a, &$b)
//if ($includedlinks) { //if ($includedlinks) {
// if (isset($post["url"])) // if (isset($post["url"]))
// $post["url"] = short_link($post["url"]); // $post["url"] = Network::shortenUrl($post["url"]);
// if (isset($post["image"])) // if (isset($post["image"]))
// $post["image"] = short_link($post["image"]); // $post["image"] = Network::shortenUrl($post["image"]);
// if (isset($post["preview"])) // if (isset($post["preview"]))
// $post["preview"] = short_link($post["preview"]); // $post["preview"] = Network::shortenUrl($post["preview"]);
//} //}
// Seems like a bug to me // Seems like a bug to me

View File

@ -9,7 +9,6 @@
* *
*/ */
require_once 'include/network.php';
require_once 'mod/proxy.php'; require_once 'mod/proxy.php';
require_once 'include/text.php'; require_once 'include/text.php';
@ -18,6 +17,7 @@ use Friendica\Core\Cache;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Util\Network;
// get the weather data from OpenWeatherMap // get the weather data from OpenWeatherMap
function getWeather( $loc, $units='metric', $lang='en', $appid='', $cachetime=0) { function getWeather( $loc, $units='metric', $lang='en', $appid='', $cachetime=0) {
@ -32,7 +32,7 @@ function getWeather( $loc, $units='metric', $lang='en', $appid='', $cachetime=0)
} }
} }
try { try {
$res = new SimpleXMLElement(fetch_url($url)); $res = new SimpleXMLElement(Network::fetchUrl($url));
} catch (Exception $e) { } catch (Exception $e) {
info(L10n::t('Error fetching weather data.\nError was: '.$e->getMessage())); info(L10n::t('Error fetching weather data.\nError was: '.$e->getMessage()));
return false; return false;

View File

@ -10,6 +10,7 @@
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Util\Network;
function dwpost_install() { function dwpost_install() {
Addon::registerHook('post_local', 'addon/dwpost/dwpost.php', 'dwpost_post_local'); Addon::registerHook('post_local', 'addon/dwpost/dwpost.php', 'dwpost_post_local');
@ -220,10 +221,10 @@ EOT;
logger('dwpost: data: ' . $xml, LOGGER_DATA); logger('dwpost: data: ' . $xml, LOGGER_DATA);
if($dw_blog !== 'test') if($dw_blog !== 'test') {
$x = post_url($dw_blog,$xml,["Content-Type: text/xml"]); $x = Network::post($dw_blog, $xml, ["Content-Type: text/xml"]);
}
logger('posted to dreamwidth: ' . ($x) ? $x : '', LOGGER_DEBUG); logger('posted to dreamwidth: ' . ($x) ? $x : '', LOGGER_DEBUG);
} }
} }

View File

@ -6,31 +6,33 @@
* Author: Mike Macgirvin <http://macgirvin.com/profile/mike> * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
*/ */
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Util\Network;
// IMPORTANT: SET THIS to your fortunate server // IMPORTANT: SET THIS to your fortunate server
define ('FORTUNATE_SERVER', 'hostname.com'); define('FORTUNATE_SERVER', 'hostname.com');
function fortunate_install() { function fortunate_install()
{
Addon::registerHook('page_end', 'addon/fortunate/fortunate.php', 'fortunate_fetch'); Addon::registerHook('page_end', 'addon/fortunate/fortunate.php', 'fortunate_fetch');
if(FORTUNATE_SERVER == 'hostname.com' && is_site_admin()) { if (FORTUNATE_SERVER == 'hostname.com' && is_site_admin()) {
notice('Fortunate addon requires configuration. See README'); notice('Fortunate addon requires configuration. See README');
} }
} }
function fortunate_uninstall() { function fortunate_uninstall()
{
Addon::unregisterHook('page_end', 'addon/fortunate/fortunate.php', 'fortunate_fetch'); Addon::unregisterHook('page_end', 'addon/fortunate/fortunate.php', 'fortunate_fetch');
} }
function fortunate_fetch(&$a,&$b) { function fortunate_fetch(&$a, &$b)
{
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="'
. $a->get_baseurl() . '/addon/fortunate/fortunate.css' . '" media="all" />' . "\r\n"; . $a->get_baseurl() . '/addon/fortunate/fortunate.css' . '" media="all" />' . "\r\n";
if(FORTUNATE_SERVER != 'hostname.com') { if (FORTUNATE_SERVER != 'hostname.com') {
$s = fetch_url('http://' . FORTUNATE_SERVER . '/cookie.php?numlines=2&equal=1&rand=' . mt_rand()); $s = Network::fetchUrl('http://' . FORTUNATE_SERVER . '/cookie.php?numlines=2&equal=1&rand=' . mt_rand());
$b .= '<div class="fortunate">' . $s . '</div>'; $b .= '<div class="fortunate">' . $s . '</div>';
} }
} }

View File

@ -14,6 +14,7 @@ use Friendica\Core\Config;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Util\Network;
require_once 'mod/share.php'; require_once 'mod/share.php';
require_once 'mod/parse_url.php'; require_once 'mod/parse_url.php';
@ -313,8 +314,7 @@ function fromgplus_cleantext($text) {
} }
function fromgplus_handleattachments($a, $uid, $item, $displaytext, $shared) { function fromgplus_handleattachments($a, $uid, $item, $displaytext, $shared) {
require_once("include/items.php"); require_once 'include/items.php';
require_once("include/network.php");
$post = ""; $post = "";
$quote = ""; $quote = "";
@ -325,13 +325,13 @@ function fromgplus_handleattachments($a, $uid, $item, $displaytext, $shared) {
switch($attachment->objectType) { switch($attachment->objectType) {
case "video": case "video":
$pagedata["type"] = "video"; $pagedata["type"] = "video";
$pagedata["url"] = original_url($attachment->url); $pagedata["url"] = Network::finalUrl($attachment->url);
$pagedata["title"] = fromgplus_html2bbcode($attachment->displayName); $pagedata["title"] = fromgplus_html2bbcode($attachment->displayName);
break; break;
case "article": case "article":
$pagedata["type"] = "link"; $pagedata["type"] = "link";
$pagedata["url"] = original_url($attachment->url); $pagedata["url"] = Network::finalUrl($attachment->url);
$pagedata["title"] = fromgplus_html2bbcode($attachment->displayName); $pagedata["title"] = fromgplus_html2bbcode($attachment->displayName);
$images = fromgplus_cleanupgoogleproxy($attachment->fullImage, $attachment->image); $images = fromgplus_cleanupgoogleproxy($attachment->fullImage, $attachment->image);
@ -382,7 +382,7 @@ function fromgplus_handleattachments($a, $uid, $item, $displaytext, $shared) {
break; break;
case "photo-album": case "photo-album":
$pagedata["url"] = original_url($attachment->url); $pagedata["url"] = Network::finalUrl($attachment->url);
$pagedata["title"] = fromgplus_html2bbcode($attachment->displayName); $pagedata["title"] = fromgplus_html2bbcode($attachment->displayName);
$post .= "\n\n[bookmark=".$pagedata["url"]."]".$pagedata["title"]."[/bookmark]\n"; $post .= "\n\n[bookmark=".$pagedata["url"]."]".$pagedata["title"]."[/bookmark]\n";
@ -403,7 +403,7 @@ function fromgplus_handleattachments($a, $uid, $item, $displaytext, $shared) {
case "album": case "album":
$pagedata["type"] = "link"; $pagedata["type"] = "link";
$pagedata["url"] = original_url($attachment->url); $pagedata["url"] = Network::finalUrl($attachment->url);
$pagedata["title"] = fromgplus_html2bbcode($attachment->displayName); $pagedata["title"] = fromgplus_html2bbcode($attachment->displayName);
$thumb = $attachment->thumbnails[0]; $thumb = $attachment->thumbnails[0];
@ -416,7 +416,7 @@ function fromgplus_handleattachments($a, $uid, $item, $displaytext, $shared) {
break; break;
case "audio": case "audio":
$pagedata["url"] = original_url($attachment->url); $pagedata["url"] = Network::finalUrl($attachment->url);
$pagedata["title"] = fromgplus_html2bbcode($attachment->displayName); $pagedata["title"] = fromgplus_html2bbcode($attachment->displayName);
$post .= "\n\n[bookmark=".$pagedata["url"]."]".$pagedata["title"]."[/bookmark]\n"; $post .= "\n\n[bookmark=".$pagedata["url"]."]".$pagedata["title"]."[/bookmark]\n";
break; break;
@ -441,7 +441,7 @@ function fromgplus_fetch($a, $uid) {
$account = PConfig::get($uid,'fromgplus','account'); $account = PConfig::get($uid,'fromgplus','account');
$key = Config::get('fromgplus','key'); $key = Config::get('fromgplus','key');
$result = fetch_url("https://www.googleapis.com/plus/v1/people/".$account."/activities/public?alt=json&pp=1&key=".$key."&maxResults=".$maxfetch); $result = Network::fetchUrl("https://www.googleapis.com/plus/v1/people/".$account."/activities/public?alt=json&pp=1&key=".$key."&maxResults=".$maxfetch);
//$result = file_get_contents("google.txt"); //$result = file_get_contents("google.txt");
//file_put_contents("google.txt", $result); //file_put_contents("google.txt", $result);

View File

@ -9,6 +9,7 @@ use Friendica\Core\Addon;
use Friendica\Core\Cache; use Friendica\Core\Cache;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Util\Network;
function geocoordinates_install() function geocoordinates_install()
{ {
@ -50,7 +51,7 @@ function geocoordinates_resolve_item(&$item)
return; return;
} }
$s = fetch_url("https://api.opencagedata.com/geocode/v1/json?q=".$coords[0].",".$coords[1]."&key=".$key."&language=".$language); $s = Network::fetchUrl("https://api.opencagedata.com/geocode/v1/json?q=".$coords[0].",".$coords[1]."&key=".$key."&language=".$language);
if (!$s) { if (!$s) {
logger("API could not be queried", LOGGER_DEBUG); logger("API could not be queried", LOGGER_DEBUG);

View File

@ -23,6 +23,8 @@ use Friendica\Core\Addon;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Util\Network;
use Friendica\Util\XML;
function geonames_install() { function geonames_install() {
@ -111,12 +113,12 @@ function geonames_post_hook($a, &$item) {
* *
*/ */
$s = fetch_url('http://api.geonames.org/findNearbyPlaceName?lat=' . $coords[0] . '&lng=' . $coords[1] . '&username=' . $geo_account); $s = Network::fetchUrl('http://api.geonames.org/findNearbyPlaceName?lat=' . $coords[0] . '&lng=' . $coords[1] . '&username=' . $geo_account);
if(! $s) if(! $s)
return; return;
$xml = parse_xml_string($s); $xml = XML::parseString($s);
if($xml->geoname->name && $xml->geoname->countryName) if($xml->geoname->name && $xml->geoname->countryName)
$item['location'] = $xml->geoname->name . ', ' . $xml->geoname->countryName; $item['location'] = $xml->geoname->name . ', ' . $xml->geoname->countryName;

View File

@ -10,6 +10,7 @@
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Util\Network;
function ijpost_install() { function ijpost_install() {
Addon::registerHook('post_local', 'addon/ijpost/ijpost.php', 'ijpost_post_local'); Addon::registerHook('post_local', 'addon/ijpost/ijpost.php', 'ijpost_post_local');
@ -219,8 +220,9 @@ EOT;
logger('ijpost: data: ' . $xml, LOGGER_DATA); logger('ijpost: data: ' . $xml, LOGGER_DATA);
if($ij_blog !== 'test') if($ij_blog !== 'test') {
$x = post_url($ij_blog,$xml,["Content-Type: text/xml"]); $x = Network::post($ij_blog, $xml, ["Content-Type: text/xml"]);
}
logger('posted to insanejournal: ' . ($x) ? $x : '', LOGGER_DEBUG); logger('posted to insanejournal: ' . ($x) ? $x : '', LOGGER_DEBUG);
} }

View File

@ -68,6 +68,7 @@ use Friendica\Core\Config;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Util\Network;
function jappixmini_install() function jappixmini_install()
{ {
@ -658,7 +659,7 @@ function jappixmini_cron(App $a, $d)
try { try {
// send request // send request
$answer_json = fetch_url($url); $answer_json = Network::fetchUrl($url);
// parse answer // parse answer
$answer = json_decode($answer_json); $answer = json_decode($answer_json);

View File

@ -7,6 +7,7 @@
*/ */
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Util\Network;
function leistungsschutzrecht_install() { function leistungsschutzrecht_install() {
Addon::registerHook('cron', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_cron'); Addon::registerHook('cron', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_cron');
@ -65,18 +66,17 @@ function leistungsschutzrecht_cuttext($text) {
return $text; return $text;
} }
function leistungsschutzrecht_fetchsites() { function leistungsschutzrecht_fetchsites()
require_once("include/network.php"); {
// This list works - but question is how current it is // This list works - but question is how current it is
$url = "http://leistungsschutzrecht-stoppen.d-64.org/blacklist.txt"; $url = "http://leistungsschutzrecht-stoppen.d-64.org/blacklist.txt";
$sitelist = fetch_url($url); $sitelist = Network::fetchUrl($url);
$siteurls = explode(',', $sitelist); $siteurls = explode(',', $sitelist);
$whitelist = ['tagesschau.de', 'heute.de', 'wdr.de']; $whitelist = ['tagesschau.de', 'heute.de', 'wdr.de'];
$sites = []; $sites = [];
foreach ($siteurls AS $site) { foreach ($siteurls as $site) {
if (!in_array($site, $whitelist)) { if (!in_array($site, $whitelist)) {
$sites[$site] = $site; $sites[$site] = $site;
} }
@ -89,7 +89,7 @@ function leistungsschutzrecht_fetchsites() {
$url = "http://www.vg-media.de/lizenzen/digitale-verlegerische-angebote/wahrnehmungsberechtigte-digitale-verlegerische-angebote.html"; $url = "http://www.vg-media.de/lizenzen/digitale-verlegerische-angebote/wahrnehmungsberechtigte-digitale-verlegerische-angebote.html";
$site = fetch_url($url); $site = Network::fetchUrl($url);
$doc = new DOMDocument(); $doc = new DOMDocument();
@$doc->loadHTML($site); @$doc->loadHTML($site);

View File

@ -8,6 +8,7 @@
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Util\Network;
function libertree_install() { function libertree_install() {
Addon::registerHook('post_local', 'addon/libertree/libertree.php', 'libertree_post_local'); Addon::registerHook('post_local', 'addon/libertree/libertree.php', 'libertree_post_local');
@ -229,9 +230,7 @@ function libertree_send(&$a,&$b) {
// 'token' => $ltree_api_token // 'token' => $ltree_api_token
]; ];
$result = post_url($ltree_blog,$params); $result = Network::post($ltree_blog, $params);
logger('libertree: ' . $result); logger('libertree: ' . $result);
} }
} }

View File

@ -10,6 +10,7 @@
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Util\Network;
function ljpost_install() { function ljpost_install() {
Addon::registerHook('post_local', 'addon/ljpost/ljpost.php', 'ljpost_post_local'); Addon::registerHook('post_local', 'addon/ljpost/ljpost.php', 'ljpost_post_local');
@ -233,10 +234,10 @@ EOT;
logger('ljpost: data: ' . $xml, LOGGER_DATA); logger('ljpost: data: ' . $xml, LOGGER_DATA);
if($lj_blog !== 'test') if ($lj_blog !== 'test') {
$x = post_url($lj_blog,$xml,["Content-Type: text/xml"]); $x = Network::post($lj_blog, $xml, ["Content-Type: text/xml"]);
}
logger('posted to livejournal: ' . ($x) ? $x : '', LOGGER_DEBUG); logger('posted to livejournal: ' . ($x) ? $x : '', LOGGER_DEBUG);
} }
} }

View File

@ -10,6 +10,7 @@ use Friendica\Core\Config;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Util\Network;
function mailstream_install() { function mailstream_install() {
Addon::registerHook('addon_settings', 'addon/mailstream/mailstream.php', 'mailstream_addon_settings'); Addon::registerHook('addon_settings', 'addon/mailstream/mailstream.php', 'mailstream_addon_settings');
@ -155,7 +156,7 @@ function mailstream_do_images($a, &$item, &$attachments) {
$redirects; $redirects;
$cookiejar = tempnam(get_temppath(), 'cookiejar-mailstream-'); $cookiejar = tempnam(get_temppath(), 'cookiejar-mailstream-');
$attachments[$url] = [ $attachments[$url] = [
'data' => fetch_url($url, true, $redirects, 0, Null, $cookiejar), 'data' => Network::fetchUrl($url, true, $redirects, 0, null, $cookiejar),
'guid' => hash("crc32", $url), 'guid' => hash("crc32", $url),
'filename' => basename($url), 'filename' => basename($url),
'type' => $a->get_curl_content_type()]; 'type' => $a->get_curl_content_type()];

View File

@ -12,6 +12,7 @@ use Friendica\Core\Addon;
use Friendica\Core\Cache; use Friendica\Core\Cache;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Util\Network;
function openstreetmap_install() function openstreetmap_install()
{ {
@ -115,7 +116,7 @@ function openstreetmap_generate_named_map(&$a, &$b)
$nomserver = 'http://nominatim.openstreetmap.org/search.php'; $nomserver = 'http://nominatim.openstreetmap.org/search.php';
$args = '?q=' . urlencode($b['location']) . '&format=json'; $args = '?q=' . urlencode($b['location']) . '&format=json';
$x = z_fetch_url($nomserver . $args); $x = Network::curl($nomserver . $args);
if($x['success']) { if($x['success']) {
$j = json_decode($x['body'],true); $j = json_decode($x['body'],true);

View File

@ -16,6 +16,7 @@ use Friendica\Model\Group;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Queue; use Friendica\Model\Queue;
use Friendica\Util\Network;
require 'addon/pumpio/oauth/http.php'; require 'addon/pumpio/oauth/http.php';
require 'addon/pumpio/oauth/oauth_client.php'; require 'addon/pumpio/oauth/oauth_client.php';
@ -1698,7 +1699,7 @@ function pumpio_fetchallcomments(&$a, $uid, $id) {
function pumpio_reachable($url) { function pumpio_reachable($url) {
$data = z_fetch_url($url, false, $redirects, ['timeout'=>10]); $data = Network::curl($url, false, $redirects, ['timeout'=>10]);
return(intval($data['return_code']) != 0); return(intval($data['return_code']) != 0);
} }

View File

@ -57,6 +57,7 @@ use Friendica\Model\GContact;
use Friendica\Model\Group; use Friendica\Model\Group;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Util\Network;
class StatusNetOAuth extends TwitterOAuth class StatusNetOAuth extends TwitterOAuth
{ {
@ -234,7 +235,7 @@ function statusnet_settings_post(App $a, $post)
foreach ($globalsn as $asn) { foreach ($globalsn as $asn) {
if ($asn['apiurl'] == $_POST['statusnet-preconf-apiurl']) { if ($asn['apiurl'] == $_POST['statusnet-preconf-apiurl']) {
$apibase = $asn['apiurl']; $apibase = $asn['apiurl'];
$c = fetch_url($apibase . 'statusnet/version.xml'); $c = Network::fetchUrl($apibase . 'statusnet/version.xml');
if (strlen($c) > 0) { if (strlen($c) > 0) {
PConfig::set(local_user(), 'statusnet', 'consumerkey', $asn['consumerkey']); PConfig::set(local_user(), 'statusnet', 'consumerkey', $asn['consumerkey']);
PConfig::set(local_user(), 'statusnet', 'consumersecret', $asn['consumersecret']); PConfig::set(local_user(), 'statusnet', 'consumersecret', $asn['consumersecret']);
@ -252,7 +253,7 @@ function statusnet_settings_post(App $a, $post)
// we'll check the API Version for that, if we don't get one we'll try to fix the path but will // we'll check the API Version for that, if we don't get one we'll try to fix the path but will
// resign quickly after this one try to fix the path ;-) // resign quickly after this one try to fix the path ;-)
$apibase = $_POST['statusnet-baseapi']; $apibase = $_POST['statusnet-baseapi'];
$c = fetch_url($apibase . 'statusnet/version.xml'); $c = Network::fetchUrl($apibase . 'statusnet/version.xml');
if (strlen($c) > 0) { if (strlen($c) > 0) {
// ok the API path is correct, let's save the settings // ok the API path is correct, let's save the settings
PConfig::set(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']); PConfig::set(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']);
@ -262,7 +263,7 @@ function statusnet_settings_post(App $a, $post)
} else { } else {
// the API path is not correct, maybe missing trailing / ? // the API path is not correct, maybe missing trailing / ?
$apibase = $apibase . '/'; $apibase = $apibase . '/';
$c = fetch_url($apibase . 'statusnet/version.xml'); $c = Network::fetchUrl($apibase . 'statusnet/version.xml');
if (strlen($c) > 0) { if (strlen($c) > 0) {
// ok the API path is now correct, let's save the settings // ok the API path is now correct, let's save the settings
PConfig::set(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']); PConfig::set(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']);
@ -641,7 +642,6 @@ function statusnet_post_hook(App $a, &$b)
PConfig::set($b['uid'], 'statusnet', 'max_char', $max_char); PConfig::set($b['uid'], 'statusnet', 'max_char', $max_char);
$tempfile = ""; $tempfile = "";
require_once "include/network.php";
$msgarr = BBCode::toPlaintext($b, $max_char, true, 7); $msgarr = BBCode::toPlaintext($b, $max_char, true, 7);
$msg = $msgarr["text"]; $msg = $msgarr["text"];
@ -653,7 +653,7 @@ function statusnet_post_hook(App $a, &$b)
if (isset($msgarr["url"]) && ($msgarr["type"] != "photo")) { if (isset($msgarr["url"]) && ($msgarr["type"] != "photo")) {
if ((strlen($msgarr["url"]) > 20) && if ((strlen($msgarr["url"]) > 20) &&
((strlen($msg . " \n" . $msgarr["url"]) > $max_char))) { ((strlen($msg . " \n" . $msgarr["url"]) > $max_char))) {
$msg .= " \n" . short_link($msgarr["url"]); $msg .= " \n" . Network::shortenUrl($msgarr["url"]);
} else { } else {
$msg .= " \n" . $msgarr["url"]; $msg .= " \n" . $msgarr["url"];
} }
@ -662,7 +662,7 @@ function statusnet_post_hook(App $a, &$b)
} }
if ($image != "") { if ($image != "") {
$img_str = fetch_url($image); $img_str = Network::fetchUrl($image);
$tempfile = tempnam(get_temppath(), "cache"); $tempfile = tempnam(get_temppath(), "cache");
file_put_contents($tempfile, $img_str); file_put_contents($tempfile, $img_str);
$postdata = ["status" => $msg, "media[]" => $tempfile]; $postdata = ["status" => $msg, "media[]" => $tempfile];
@ -1613,7 +1613,7 @@ function statusnet_complete_conversation(App $a, $uid, $self, $create_user, $nic
if (is_array($items)) { if (is_array($items)) {
$posts = array_reverse($items); $posts = array_reverse($items);
foreach ($posts AS $post) { foreach ($posts as $post) {
$postarray = statusnet_createpost($a, $uid, $post, $self, false, false); $postarray = statusnet_createpost($a, $uid, $post, $self, false, false);
if (trim($postarray['body']) == "") { if (trim($postarray['body']) == "") {
@ -1635,7 +1635,6 @@ function statusnet_complete_conversation(App $a, $uid, $self, $create_user, $nic
function statusnet_convertmsg(App $a, $body, $no_tags = false) function statusnet_convertmsg(App $a, $body, $no_tags = false)
{ {
require_once "include/items.php"; require_once "include/items.php";
require_once "include/network.php";
$body = preg_replace("=\[url\=https?://([0-9]*).([0-9]*).([0-9]*).([0-9]*)/([0-9]*)\](.*?)\[\/url\]=ism", "$1.$2.$3.$4/$5", $body); $body = preg_replace("=\[url\=https?://([0-9]*).([0-9]*).([0-9]*).([0-9]*)/([0-9]*)\](.*?)\[\/url\]=ism", "$1.$2.$3.$4/$5", $body);
@ -1653,7 +1652,7 @@ function statusnet_convertmsg(App $a, $body, $no_tags = false)
logger("statusnet_convertmsg: expanding url " . $match[1], LOGGER_DEBUG); logger("statusnet_convertmsg: expanding url " . $match[1], LOGGER_DEBUG);
$expanded_url = original_url($match[1]); $expanded_url = Network::finalUrl($match[1]);
logger("statusnet_convertmsg: fetching data for " . $expanded_url, LOGGER_DEBUG); logger("statusnet_convertmsg: fetching data for " . $expanded_url, LOGGER_DEBUG);
@ -1677,7 +1676,7 @@ function statusnet_convertmsg(App $a, $body, $no_tags = false)
} elseif ($oembed_data->type != "link") { } elseif ($oembed_data->type != "link") {
$body = str_replace($search, "[url=" . $expanded_url . "]" . $expanded_url . "[/url]", $body); $body = str_replace($search, "[url=" . $expanded_url . "]" . $expanded_url . "[/url]", $body);
} else { } else {
$img_str = fetch_url($expanded_url, true, $redirects, 4); $img_str = Network::fetchUrl($expanded_url, true, $redirects, 4);
$tempfile = tempnam(get_temppath(), "cache"); $tempfile = tempnam(get_temppath(), "cache");
file_put_contents($tempfile, $img_str); file_put_contents($tempfile, $img_str);

View File

@ -74,6 +74,7 @@ use Friendica\Model\Photo;
use Friendica\Model\Queue; use Friendica\Model\Queue;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Util\Network;
require_once 'include/enotify.php'; require_once 'include/enotify.php';
@ -424,8 +425,6 @@ function twitter_action(App $a, $uid, $pid, $action)
function twitter_post_hook(App $a, &$b) function twitter_post_hook(App $a, &$b)
{ {
// Post to Twitter // Post to Twitter
require_once "include/network.php";
if (!PConfig::get($b["uid"], 'twitter', 'import') if (!PConfig::get($b["uid"], 'twitter', 'import')
&& ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited']))) { && ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited']))) {
return; return;
@ -545,7 +544,7 @@ function twitter_post_hook(App $a, &$b)
// and now tweet it :-) // and now tweet it :-)
if (strlen($msg) && ($image != "")) { if (strlen($msg) && ($image != "")) {
$img_str = fetch_url($image); $img_str = Network::fetchUrl($image);
$tempfile = tempnam(get_temppath(), "cache"); $tempfile = tempnam(get_temppath(), "cache");
file_put_contents($tempfile, $img_str); file_put_contents($tempfile, $img_str);
@ -1172,8 +1171,6 @@ function twitter_fetchuser(App $a, $uid, $screen_name = "", $user_id = "")
function twitter_expand_entities(App $a, $body, $item, $no_tags = false, $picture) function twitter_expand_entities(App $a, $body, $item, $no_tags = false, $picture)
{ {
require_once "include/network.php";
$tags = ""; $tags = "";
$plain = $body; $plain = $body;
@ -1184,11 +1181,11 @@ function twitter_expand_entities(App $a, $body, $item, $no_tags = false, $pictur
$footerlink = ""; $footerlink = "";
$footer = ""; $footer = "";
foreach ($item->entities->urls AS $url) { foreach ($item->entities->urls as $url) {
$plain = str_replace($url->url, '', $plain); $plain = str_replace($url->url, '', $plain);
if ($url->url && $url->expanded_url && $url->display_url) { if ($url->url && $url->expanded_url && $url->display_url) {
$expanded_url = original_url($url->expanded_url); $expanded_url = Network::finalUrl($url->expanded_url);
$oembed_data = OEmbed::fetchURL($expanded_url); $oembed_data = OEmbed::fetchURL($expanded_url);
@ -1217,7 +1214,7 @@ function twitter_expand_entities(App $a, $body, $item, $no_tags = false, $pictur
} elseif ($oembed_data->type != "link") { } elseif ($oembed_data->type != "link") {
$body = str_replace($url->url, "[url=" . $expanded_url . "]" . $expanded_url . "[/url]", $body); $body = str_replace($url->url, "[url=" . $expanded_url . "]" . $expanded_url . "[/url]", $body);
} else { } else {
$img_str = fetch_url($expanded_url, true, $redirects, 4); $img_str = Network::fetchUrl($expanded_url, true, $redirects, 4);
$tempfile = tempnam(get_temppath(), "cache"); $tempfile = tempnam(get_temppath(), "cache");
file_put_contents($tempfile, $img_str); file_put_contents($tempfile, $img_str);

View File

@ -313,10 +313,9 @@ EOT;
logger('wppost: data: ' . $xml, LOGGER_DATA); logger('wppost: data: ' . $xml, LOGGER_DATA);
if($wp_blog !== 'test') { if ($wp_blog !== 'test') {
$x = post_url($wp_blog,$xml); $x = Network::post($wp_blog, $xml);
} }
logger('posted to wordpress: ' . (($x) ? $x : ''), LOGGER_DEBUG); logger('posted to wordpress: ' . (($x) ? $x : ''), LOGGER_DEBUG);
} }
} }