From 036754e4550eab119cae93c1d8ad40572f85fe79 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Thu, 9 Nov 2017 11:08:32 -0500 Subject: [PATCH] Move Cache to src Cache class moved to Friendica\Core namespace --- curweather/curweather.php | 1 + geocoordinates/geocoordinates.php | 19 +++++--- googlemaps/googlemaps.php | 25 ++++++---- openstreetmap/openstreetmap.php | 77 +++++++++++++++++++------------ 4 files changed, 76 insertions(+), 46 deletions(-) diff --git a/curweather/curweather.php b/curweather/curweather.php index 2e64453e..6197c961 100644 --- a/curweather/curweather.php +++ b/curweather/curweather.php @@ -13,6 +13,7 @@ require_once('include/network.php'); require_once("mod/proxy.php"); require_once('include/text.php'); +use Friendica\Core\Cache; use Friendica\Core\Config; use Friendica\Core\PConfig; diff --git a/geocoordinates/geocoordinates.php b/geocoordinates/geocoordinates.php index 11643168..69b73f72 100644 --- a/geocoordinates/geocoordinates.php +++ b/geocoordinates/geocoordinates.php @@ -6,20 +6,24 @@ * Author: Michael Vogel */ +use Friendica\Core\Cache; use Friendica\Core\Config; -function geocoordinates_install() { +function geocoordinates_install() +{ register_hook('post_local', 'addon/geocoordinates/geocoordinates.php', 'geocoordinates_post_hook'); register_hook('post_remote', 'addon/geocoordinates/geocoordinates.php', 'geocoordinates_post_hook'); } -function geocoordinates_uninstall() { +function geocoordinates_uninstall() +{ unregister_hook('post_local', 'addon/geocoordinates/geocoordinates.php', 'geocoordinates_post_hook'); unregister_hook('post_remote', 'addon/geocoordinates/geocoordinates.php', 'geocoordinates_post_hook'); } -function geocoordinates_resolve_item(&$item) { +function geocoordinates_resolve_item(&$item) +{ if((!$item["coord"]) || ($item["location"])) return; @@ -72,11 +76,13 @@ function geocoordinates_resolve_item(&$item) { Cache::set("geocoordinates:".$language.":".$coords[0]."-".$coords[1], $item["location"]); } -function geocoordinates_post_hook($a, &$item) { +function geocoordinates_post_hook($a, &$item) +{ geocoordinates_resolve_item($item); } -function geocoordinates_plugin_admin(&$a,&$o) { +function geocoordinates_plugin_admin(&$a, &$o) +{ $t = get_markup_template("admin.tpl", "addon/geocoordinates/"); @@ -87,7 +93,8 @@ function geocoordinates_plugin_admin(&$a,&$o) { )); } -function geocoordinates_plugin_admin_post(&$a) { +function geocoordinates_plugin_admin_post(&$a) +{ $api_key = ((x($_POST,'api_key')) ? notags(trim($_POST['api_key'])) : ''); Config::set('geocoordinates','api_key',$api_key); diff --git a/googlemaps/googlemaps.php b/googlemaps/googlemaps.php index 0b031f4d..f5b573ac 100644 --- a/googlemaps/googlemaps.php +++ b/googlemaps/googlemaps.php @@ -7,35 +7,40 @@ * */ -require_once('include/cache.php'); +use Friendica\Core\Cache; - -function googlemaps_install() { +function googlemaps_install() +{ register_hook('render_location', 'addon/googlemaps/googlemaps.php', 'googlemaps_location'); logger("installed googlemaps"); } -function googlemaps_uninstall() { +function googlemaps_uninstall() +{ unregister_hook('render_location', 'addon/googlemaps/googlemaps.php', 'googlemaps_location'); logger("removed googlemaps"); } -function googlemaps_location($a, &$item) { +function googlemaps_location($a, &$item) +{ - if(! (strlen($item['location']) || strlen($item['coord']))) + if(! (strlen($item['location']) || strlen($item['coord']))) { return; + } - if ($item['coord'] != "") + if ($item['coord'] != ""){ $target = "http://maps.google.com/?q=".urlencode($item['coord']); - else + } else { $target = "http://maps.google.com/?q=".urlencode($item['location']); + } - if ($item['location'] != "") + if ($item['location'] != "") { $title = $item['location']; - else + } else { $title = $item['coord']; + } $item['html'] = ''.$title.''; } diff --git a/openstreetmap/openstreetmap.php b/openstreetmap/openstreetmap.php index 175e5862..8335f38e 100644 --- a/openstreetmap/openstreetmap.php +++ b/openstreetmap/openstreetmap.php @@ -9,12 +9,12 @@ * */ -require_once('include/cache.php'); - +use Friendica\Core\Cache; use Friendica\Core\Config; -function openstreetmap_install() { +function openstreetmap_install() +{ register_hook('render_location', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_location'); register_hook('generate_map', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_generate_map'); register_hook('generate_named_map', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_generate_named_map'); @@ -23,7 +23,8 @@ function openstreetmap_install() { logger("installed openstreetmap"); } -function openstreetmap_uninstall() { +function openstreetmap_uninstall() +{ unregister_hook('render_location', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_location'); unregister_hook('generate_map', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_generate_map'); unregister_hook('generate_named_map', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_generate_named_map'); @@ -32,7 +33,8 @@ function openstreetmap_uninstall() { logger("removed openstreetmap"); } -function openstreetmap_alterheader($a, &$navHtml) { +function openstreetmap_alterheader($a, &$navHtml) +{ $addScriptTag = '' . "\r\n"; $a->page['htmlhead'] .= $addScriptTag; } @@ -48,8 +50,9 @@ function openstreetmap_alterheader($a, &$navHtml) { */ function openstreetmap_location($a, &$item) { - if(! (strlen($item['location']) || strlen($item['coord']))) + if(! (strlen($item['location']) || strlen($item['coord']))) { return; + } /* * Get the configuration variables from the config. @@ -60,20 +63,24 @@ function openstreetmap_location($a, &$item) { */ $tmsserver = Config::get('openstreetmap', 'tmsserver'); - if(! $tmsserver) + if(! $tmsserver) { $tmsserver = 'http://www.openstreetmap.org'; + } $nomserver = Config::get('openstreetmap', 'nomserver'); - if(! $nomserver) + if(! $nomserver) { $nomserver = 'http://nominatim.openstreetmap.org/search.php'; + } $zoom = Config::get('openstreetmap', 'zoom'); - if(! $zoom) + if(! $zoom) { $zoom = 16; + } $marker = Config::get('openstreetmap', 'marker'); - if(! $marker) + if(! $marker) { $marker = 0; + } if ($item['coord'] != "") { $coords = explode(' ', $item['coord']); @@ -87,21 +94,22 @@ function openstreetmap_location($a, &$item) { } } - if ($target == "") + if ($target == "") { $target = $nomserver.'?q='.urlencode($item['location']); + } - if ($item['location'] != "") + if ($item['location'] != "") { $title = $item['location']; - else + } else { $title = $item['coord']; + } $item['html'] = ''.$title.''; } -function openstreetmap_generate_named_map(&$a,&$b) { - - +function openstreetmap_generate_named_map(&$a, &$b) +{ $nomserver = Config::get('openstreetmap', 'nomserver'); if(! $nomserver) $nomserver = 'http://nominatim.openstreetmap.org/search.php'; @@ -119,22 +127,26 @@ function openstreetmap_generate_named_map(&$a,&$b) { } } -function openstreetmap_generate_map(&$a,&$b) { - +function openstreetmap_generate_map(&$a, &$b) +{ $tmsserver = Config::get('openstreetmap', 'tmsserver'); - if(! $tmsserver) + if(! $tmsserver) { $tmsserver = 'http://www.openstreetmap.org'; - if(strpos(z_root(),'https:') !== false) + } + if(strpos(z_root(),'https:') !== false) { $tmsserver = str_replace('http:','https:',$tmsserver); + } $zoom = Config::get('openstreetmap', 'zoom'); - if(! $zoom) + if(! $zoom) { $zoom = 16; + } $marker = Config::get('openstreetmap', 'marker'); - if(! $marker) + if(! $marker) { $marker = 0; + } $lat = $b['lat']; // round($b['lat'], 5); $lon = $b['lon']; // round($b['lon'], 5); @@ -151,20 +163,25 @@ function openstreetmap_generate_map(&$a,&$b) { } -function openstreetmap_plugin_admin(&$a, &$o) { +function openstreetmap_plugin_admin(&$a, &$o) +{ $t = get_markup_template("admin.tpl", "addon/openstreetmap/"); $tmsserver = Config::get('openstreetmap', 'tmsserver'); - if(! $tmsserver) + if(! $tmsserver) { $tmsserver = 'http://www.openstreetmap.org'; + } $nomserver = Config::get('openstreetmap', 'nomserver'); - if(! $nomserver) + if(! $nomserver) { $nomserver = 'http://nominatim.openstreetmap.org/search.php'; + } $zoom = Config::get('openstreetmap', 'zoom'); - if(! $zoom) + if(! $zoom) { $zoom = 16; + } $marker = Config::get('openstreetmap', 'marker'); - if(! $marker) + if(! $marker) { $marker = 0; + } $o = replace_macros($t, array( '$submit' => t('Submit'), @@ -174,7 +191,9 @@ function openstreetmap_plugin_admin(&$a, &$o) { '$marker' => array('marker', t('Include marker on map'), $marker, t('Include a marker on the map.')), )); } -function openstreetmap_plugin_admin_post(&$a) { + +function openstreetmap_plugin_admin_post(&$a) +{ $urltms = ((x($_POST, 'tmsserver')) ? notags(trim($_POST['tmsserver'])) : ''); $urlnom = ((x($_POST, 'nomserver')) ? notags(trim($_POST['nomserver'])) : ''); $zoom = ((x($_POST, 'zoom')) ? intval(trim($_POST['zoom'])) : '16'); @@ -185,5 +204,3 @@ function openstreetmap_plugin_admin_post(&$a) { Config::set('openstreetmap', 'marker', $marker); info( t('Settings updated.') . EOL); } - -