commit
dd2fbb0c9f
6 changed files with 160 additions and 20 deletions
|
@ -7,25 +7,25 @@ Inline
|
|||
-----
|
||||
|
||||
|
||||
<pre>[b]bold[/b]</pre> : <strong>bold</strong>
|
||||
<pre>[b]bold[/b]</pre> : <strong>bold</strong>
|
||||
|
||||
<pre>[i]italic[/i]</pre> : <em>italic</em>
|
||||
<pre>[i]italic[/i]</pre> : <em>italic</em>
|
||||
|
||||
<pre>[u]underlined[/u]</pre> : <u>underlined</u>
|
||||
<pre>[u]underlined[/u]</pre> : <u>underlined</u>
|
||||
|
||||
<pre>[s]strike[/s]</pre> : <strike>strike</strike>
|
||||
<pre>[s]strike[/s]</pre> : <strike>strike</strike>
|
||||
|
||||
<pre>[color=red]red[/color]</pre> : <span style="color: red;">red</span>
|
||||
<pre>[color=red]red[/color]</pre> : <span style="color: red;">red</span>
|
||||
|
||||
<pre>[url=http://www.friendica.com]Friendica[/url]</pre> : <a href="http://www.friendica.com" target="external-link">Friendica</a>
|
||||
<pre>[url=http://www.friendica.com]Friendica[/url]</pre> : <a href="http://www.friendica.com" target="external-link">Friendica</a>
|
||||
|
||||
<pre>[img]http://friendica.com/sites/default/files/friendika-32.png[/img]</pre> : <img src="http://friendica.com/sites/default/files/friendika-32.png" alt="Immagine/foto">
|
||||
<pre>[img]http://friendica.com/sites/default/files/friendika-32.png[/img]</pre> : <img src="http://friendica.com/sites/default/files/friendika-32.png" alt="Immagine/foto">
|
||||
|
||||
<pre>[size=xx-small]small text[/size]</pre> : <span style="font-size: xx-small;">small text</span>
|
||||
<pre>[size=xx-small]small text[/size]</pre> : <span style="font-size: xx-small;">small text</span>
|
||||
|
||||
<pre>[size=xx-large]big text[/size]</pre> : <span style="font-size: xx-large;">big text</span>
|
||||
<pre>[size=xx-large]big text[/size]</pre> : <span style="font-size: xx-large;">big text</span>
|
||||
|
||||
<pre>[size=20]exact size[/size] (size can be any number, in pixel)</pre> : <span style="font-size: 20px;">exact size</span>
|
||||
<pre>[size=20]exact size[/size] (size can be any number, in pixel)</pre> : <span style="font-size: 20px;">exact size</span>
|
||||
|
||||
|
||||
|
||||
|
@ -126,6 +126,14 @@ Where *url* can be an url to youtube, vimeo, soundcloud, or other sites wich sup
|
|||
If *url* supports oembed or opengraph specifications the embedded object will be shown (eg, documents from scribd).
|
||||
Page title with a link to *url* will be shown.
|
||||
|
||||
Map
|
||||
---
|
||||
|
||||
<pre>[map]address[/map]</pre>
|
||||
<pre>[map=lat,long]</pre>
|
||||
|
||||
You can embed maps from coordinates or addresses.
|
||||
This require "openstreetmap" addon version 1.3 or newer.
|
||||
|
||||
|
||||
Special
|
||||
|
|
|
@ -1,6 +1,17 @@
|
|||
<?php
|
||||
require_once("include/oembed.php");
|
||||
require_once('include/event.php');
|
||||
require_once('include/map.php');
|
||||
|
||||
|
||||
function bb_map_coords($match) {
|
||||
// the extra space in the following line is intentional
|
||||
return str_replace($match[0],'<div class="map" >' . generate_map(str_replace('/',' ',$match[1])) . '</div>', $match[0]);
|
||||
}
|
||||
function bb_map_location($match) {
|
||||
// the extra space in the following line is intentional
|
||||
return str_replace($match[0],'<div class="map" >' . generate_named_map($match[1]) . '</div>', $match[0]);
|
||||
}
|
||||
|
||||
function bb_attachment($Text, $plaintext = false, $tryoembed = true) {
|
||||
$Text = preg_replace_callback("/(.*?)\[attachment(.*?)\](.*?)\[\/attachment\]/ism",
|
||||
|
@ -932,7 +943,20 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
|
|||
// Perform MAIL Search
|
||||
$Text = preg_replace("/\[mail\]([$MAILSearchString]*)\[\/mail\]/", '<a href="mailto:$1">$1</a>', $Text);
|
||||
$Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.*?)\[\/mail\]/", '<a href="mailto:$1">$2</a>', $Text);
|
||||
|
||||
// leave open the posibility of [map=something]
|
||||
// this is replaced in prepare_body() which has knowledge of the item location
|
||||
|
||||
if (strpos($Text,'[/map]') !== false) {
|
||||
$Text = preg_replace_callback("/\[map\](.*?)\[\/map\]/ism", 'bb_map_location', $Text);
|
||||
}
|
||||
if (strpos($Text,'[map=') !== false) {
|
||||
$Text = preg_replace_callback("/\[map=(.*?)\]/ism", 'bb_map_coords', $Text);
|
||||
}
|
||||
if (strpos($Text,'[map]') !== false) {
|
||||
$Text = preg_replace("/\[map\]/", '<div class="map"></div>', $Text);
|
||||
}
|
||||
|
||||
// Check for headers
|
||||
$Text = preg_replace("(\[h1\](.*?)\[\/h1\])ism",'<h1>$1</h1>',$Text);
|
||||
$Text = preg_replace("(\[h2\](.*?)\[\/h2\])ism",'<h2>$1</h2>',$Text);
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
|
||||
require_once('include/bbcode.php');
|
||||
require_once('include/map.php');
|
||||
|
||||
function format_event_html($ev) {
|
||||
|
||||
require_once('include/bbcode.php');
|
||||
|
||||
|
||||
if(! ((is_array($ev)) && count($ev)))
|
||||
return '';
|
||||
|
@ -36,10 +38,17 @@ function format_event_html($ev) {
|
|||
$ev['finish'] , $bd_format )))
|
||||
. '</abbr></p>' . "\r\n";
|
||||
|
||||
if(strlen($ev['location']))
|
||||
if(strlen($ev['location'])){
|
||||
$o .= '<p class="event-location"> ' . t('Location:') . ' <span class="location">'
|
||||
. bbcode($ev['location'])
|
||||
. '</span></p>' . "\r\n";
|
||||
|
||||
if (str_pos("[map", $ev['location'])==0) {
|
||||
$map = generate_named_map($ev['location']);
|
||||
if ($map!==$ev['location']) $o.=$map;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$o .= '</div>' . "\r\n";
|
||||
return $o;
|
||||
|
|
18
include/map.php
Normal file
18
include/map.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Leaflet Map related functions
|
||||
*/
|
||||
|
||||
function generate_map($coord) {
|
||||
$coord = trim($coord);
|
||||
$coord = str_replace(array(',','/',' '),array(' ',' ',' '),$coord);
|
||||
$arr = array('lat' => trim(substr($coord,0,strpos($coord,' '))), 'lon' => trim(substr($coord,strpos($coord,' ')+1)), 'html' => '');
|
||||
call_hooks('generate_map',$arr);
|
||||
return (($arr['html']) ? $arr['html'] : $coord);
|
||||
}
|
||||
function generate_named_map($location) {
|
||||
$arr = array('location' => $location, 'html' => '');
|
||||
call_hooks('generate_named_map',$arr);
|
||||
return (($arr['html']) ? $arr['html'] : $location);
|
||||
}
|
|
@ -9,6 +9,49 @@
|
|||
if(! function_exists('fetch_url')) {
|
||||
function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_content=Null, $cookiejar = 0) {
|
||||
|
||||
$ret = z_fetch_url(
|
||||
$url,
|
||||
$binary,
|
||||
$redirects,
|
||||
array('timeout'=>$timeout,
|
||||
'accept_content'=>$accept_content,
|
||||
'cookiejar'=>$cookiejar
|
||||
));
|
||||
|
||||
|
||||
|
||||
return($ret['body']);
|
||||
}}
|
||||
|
||||
if(!function_exists('z_fetch_url')){
|
||||
/**
|
||||
* @brief fetches an URL.
|
||||
*
|
||||
* @param string $url
|
||||
* URL to fetch
|
||||
* @param boolean $binary default false
|
||||
* TRUE if asked to return binary results (file download)
|
||||
* @param int $redirects default 0
|
||||
* internal use, recursion counter
|
||||
* @param array $opts (optional parameters) assoziative array with:
|
||||
* * \b accept_content => supply Accept: header with 'accept_content' as the value
|
||||
* * \b timeout => int seconds, default system config value or 60 seconds
|
||||
* * \b http_auth => username:password
|
||||
* * \b novalidate => do not validate SSL certs, default is to validate using our CA list
|
||||
* * \b nobody => only return the header
|
||||
* * \b cookiejar => path to cookie jar file
|
||||
*
|
||||
* @return array an assoziative array with:
|
||||
* * \e int \b return_code => HTTP return code or 0 if timeout or failure
|
||||
* * \e boolean \b success => boolean true (if HTTP 2xx result) or false
|
||||
* * \e string \b header => HTTP headers
|
||||
* * \e string \b body => fetched content
|
||||
*/
|
||||
function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) {
|
||||
|
||||
$ret = array('return_code' => 0, 'success' => false, 'header' => "", 'body' => "");
|
||||
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
|
||||
$a = get_app();
|
||||
|
@ -19,18 +62,18 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
|
|||
|
||||
@curl_setopt($ch, CURLOPT_HEADER, true);
|
||||
|
||||
if($cookiejar) {
|
||||
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar);
|
||||
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar);
|
||||
if(x($opts,"cookiejar")) {
|
||||
curl_setopt($ch, CURLOPT_COOKIEJAR, $opts["cookiejar"]);
|
||||
curl_setopt($ch, CURLOPT_COOKIEFILE, $opts["cookiejar"]);
|
||||
}
|
||||
|
||||
// These settings aren't needed. We're following the location already.
|
||||
// @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
// @curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
|
||||
|
||||
if (!is_null($accept_content)){
|
||||
if (x($opts,'accept_content')){
|
||||
curl_setopt($ch,CURLOPT_HTTPHEADER, array (
|
||||
"Accept: " . $accept_content
|
||||
"Accept: " . $opts['accept_content']
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -38,6 +81,13 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
|
|||
@curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent());
|
||||
|
||||
|
||||
|
||||
if(x($opts,'headers')){
|
||||
@curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']);
|
||||
}
|
||||
if(x($opts,'nobody')){
|
||||
@curl_setopt($ch, CURLOPT_NOBODY, $opts['nobody']);
|
||||
}
|
||||
if(intval($timeout)) {
|
||||
@curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
}
|
||||
|
@ -72,7 +122,7 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
|
|||
|
||||
$base = $s;
|
||||
$curl_info = @curl_getinfo($ch);
|
||||
@curl_close($ch);
|
||||
|
||||
$http_code = $curl_info['http_code'];
|
||||
logger('fetch_url '.$url.': '.$http_code." ".$s, LOGGER_DATA);
|
||||
$header = '';
|
||||
|
@ -103,19 +153,40 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
|
|||
$newurl = $old_location_info["scheme"]."://".$old_location_info["host"].$newurl;
|
||||
if (filter_var($newurl, FILTER_VALIDATE_URL)) {
|
||||
$redirects++;
|
||||
@curl_close($ch);
|
||||
return fetch_url($newurl,$binary,$redirects,$timeout,$accept_content,$cookiejar);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$a->set_curl_code($http_code);
|
||||
$a->set_curl_content_type($curl_info['content_type']);
|
||||
|
||||
$body = substr($s,strlen($header));
|
||||
$a->set_curl_headers($header);
|
||||
|
||||
$a->save_timestamp($stamp1, "network");
|
||||
|
||||
return($body);
|
||||
|
||||
$rc = intval($http_code);
|
||||
$ret['return_code'] = $rc;
|
||||
$ret['success'] = (($rc >= 200 && $rc <= 299) ? true : false);
|
||||
if(! $ret['success']) {
|
||||
$ret['error'] = curl_error($ch);
|
||||
$ret['debug'] = $curl_info;
|
||||
logger('z_fetch_url: error: ' . $url . ': ' . $ret['error'], LOGGER_DEBUG);
|
||||
logger('z_fetch_url: debug: ' . print_r($curl_info,true), LOGGER_DATA);
|
||||
}
|
||||
$ret['body'] = substr($s,strlen($header));
|
||||
$ret['header'] = $header;
|
||||
if(x($opts,'debug')) {
|
||||
$ret['debug'] = $curl_info;
|
||||
}
|
||||
@curl_close($ch);
|
||||
|
||||
$a->save_timestamp($stamp1, "network");
|
||||
|
||||
return($ret);
|
||||
|
||||
}}
|
||||
|
||||
// post request to $url. $params is an array of post variables.
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
require_once("include/template_processor.php");
|
||||
require_once("include/friendica_smarty.php");
|
||||
require_once("include/map.php");
|
||||
require_once("mod/proxy.php");
|
||||
|
||||
|
||||
if(! function_exists('replace_macros')) {
|
||||
/**
|
||||
* This is our template processor
|
||||
|
@ -1461,6 +1463,14 @@ function prepare_body(&$item,$attach = false, $preview = false) {
|
|||
}
|
||||
$s = $s . $as;
|
||||
|
||||
// map
|
||||
if(strpos($s,'<div class="map">') !== false && $item['coord']) {
|
||||
$x = generate_map(trim($item['coord']));
|
||||
if($x) {
|
||||
$s = preg_replace('/\<div class\=\"map\"\>/','$0' . $x,$s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Look for spoiler
|
||||
$spoilersearch = '<blockquote class="spoiler">';
|
||||
|
|
Loading…
Reference in a new issue