Merge pull request #914 from annando/master

Vier, API and Twitter cards
This commit is contained in:
Tobias Diekershoff 2014-02-24 07:21:15 +01:00
commit 0eec22f656
11 changed files with 277 additions and 70 deletions

View file

@ -1625,6 +1625,8 @@
if ($include_entities != "true") if ($include_entities != "true")
return array(); return array();
$bbcode = bb_CleanPictureLinks($bbcode);
// Change pure links in text to bbcode uris // Change pure links in text to bbcode uris
$bbcode = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1[url=$2]$2[/url]', $bbcode); $bbcode = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1[url=$2]$2[/url]', $bbcode);
@ -2392,6 +2394,8 @@ function api_get_nick($profile) {
function api_clean_plain_items($Text) { function api_clean_plain_items($Text) {
$include_entities = strtolower(x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:"false"); $include_entities = strtolower(x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:"false");
$Text = bb_CleanPictureLinks($Text);
if ($include_entities == "true") { if ($include_entities == "true") {
$URLSearchString = "^\[\]"; $URLSearchString = "^\[\]";

View file

@ -533,22 +533,93 @@ function GetProfileUsername($profile, $username) {
return($username); return($username);
} }
function RemovePictureLinks($match) { function bb_RemovePictureLinks($match) {
$ch = @curl_init($match[2]); $text = Cache::get($match[1]);
@curl_setopt($ch, CURLOPT_NOBODY, true);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Friendica)");
@curl_exec($ch);
$curl_info = @curl_getinfo($ch);
if (substr($curl_info["content_type"], 0, 6) == "image/") if(is_null($text)){
$text = "[url=".$match[2]."]".$match[2]."[/url]"; $ch = @curl_init($match[1]);
else @curl_setopt($ch, CURLOPT_NOBODY, true);
$text = "[url=".$match[1]."]".$match[1]."[/url]"; @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Friendica)");
@curl_exec($ch);
$curl_info = @curl_getinfo($ch);
if (substr($curl_info["content_type"], 0, 6) == "image/")
$text = "[url=".$match[1]."]".$match[1]."[/url]";
else {
$text = "[url=".$match[2]."]".$match[2]."[/url]";
// if its not a picture then look if its a page that contains a picture link
require_once("include/network.php");
$body = fetch_url($match[1]);
$doc = new DOMDocument();
@$doc->loadHTML($body);
$xpath = new DomXPath($doc);
$list = $xpath->query("//meta[@name]");
foreach ($list as $node) {
$attr = array();
if ($node->attributes->length)
foreach ($node->attributes as $attribute)
$attr[$attribute->name] = $attribute->value;
if (strtolower($attr["name"]) == "twitter:image")
$text = "[url=".$attr["content"]."]".$attr["content"]."[/url]";
}
}
Cache::set($match[1],$text);
}
return($text); return($text);
} }
function bb_CleanPictureLinksSub($match) {
$text = Cache::get($match[1]);
if(is_null($text)){
$ch = @curl_init($match[1]);
@curl_setopt($ch, CURLOPT_NOBODY, true);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Friendica)");
@curl_exec($ch);
$curl_info = @curl_getinfo($ch);
// if its a link to a picture then embed this picture
if (substr($curl_info["content_type"], 0, 6) == "image/")
$text = "[img]".$match[1]."[/img]";
else {
$text = "[img]".$match[2]."[/img]";
// if its not a picture then look if its a page that contains a picture link
require_once("include/network.php");
$body = fetch_url($match[1]);
$doc = new DOMDocument();
@$doc->loadHTML($body);
$xpath = new DomXPath($doc);
$list = $xpath->query("//meta[@name]");
foreach ($list as $node) {
$attr = array();
if ($node->attributes->length)
foreach ($node->attributes as $attribute)
$attr[$attribute->name] = $attribute->value;
if (strtolower($attr["name"]) == "twitter:image")
$text = "[img]".$attr["content"]."[/img]";
}
}
Cache::set($match[1],$text);
}
return($text);
}
function bb_CleanPictureLinks($text) {
$text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'bb_CleanPictureLinksSub', $text);
return ($text);
}
// BBcode 2 HTML was written by WAY2WEB.net // BBcode 2 HTML was written by WAY2WEB.net
// extended to work with Mistpark/Friendica - Mike Macgirvin // extended to work with Mistpark/Friendica - Mike Macgirvin
@ -635,6 +706,10 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
// Set up the parameters for a MAIL search string // Set up the parameters for a MAIL search string
$MAILSearchString = $URLSearchString; $MAILSearchString = $URLSearchString;
// Bookmarks in red - will be converted to bookmarks in friendica
$Text = preg_replace("/#\^\[url\]([$URLSearchString]*)\[\/url\]/ism", '[bookmark=$1]$1[/bookmark]', $Text);
$Text = preg_replace("/#\^\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[bookmark=$1]$2[/bookmark]', $Text);
if ($simplehtml == 5) if ($simplehtml == 5)
$Text = preg_replace("/[^#@]\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[url]$1[/url]', $Text); $Text = preg_replace("/[^#@]\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[url]$1[/url]', $Text);
@ -652,7 +727,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
$Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1<a href="$2" target="_blank">$2</a>', $Text); $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1<a href="$2" target="_blank">$2</a>', $Text);
else { else {
$Text = preg_replace("(\[url\]([$URLSearchString]*)\[\/url\])ism"," $1 ",$Text); $Text = preg_replace("(\[url\]([$URLSearchString]*)\[\/url\])ism"," $1 ",$Text);
$Text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'RemovePictureLinks', $Text); $Text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'bb_RemovePictureLinks', $Text);
} }
if ($tryoembed) if ($tryoembed)

View file

@ -4,12 +4,21 @@
*/ */
class Cache { class Cache {
public static function get($key){ public static function get($key) {
if (function_exists("apc_fetch") AND function_exists("apc_exists"))
if (apc_exists($key))
return(apc_fetch($key));
$r = q("SELECT `v` FROM `cache` WHERE `k`='%s' limit 1", $r = q("SELECT `v` FROM `cache` WHERE `k`='%s' limit 1",
dbesc($key) dbesc($key)
); );
if (count($r)) return $r[0]['v']; if (count($r)) {
if (function_exists("apc_store"))
apc_store($key, $r[0]['v'], 600);
return $r[0]['v'];
}
return null; return null;
} }
@ -19,6 +28,10 @@
dbesc($key), dbesc($key),
dbesc($value), dbesc($value),
dbesc(datetime_convert())); dbesc(datetime_convert()));
if (function_exists("apc_store"))
apc_store($key, $value, 600);
} }

View file

@ -203,6 +203,10 @@ function display_content(&$a, $update = 0) {
$title = trim(html2plain(bbcode($r[0]["title"], false, false), 0, true)); $title = trim(html2plain(bbcode($r[0]["title"], false, false), 0, true));
$author_name = $r[0]["author-name"]; $author_name = $r[0]["author-name"];
$image = "";
if ($image == "")
$image = $r[0]["thumb"];
if ($title == "") if ($title == "")
$title = $author_name; $title = $author_name;
@ -219,9 +223,16 @@ function display_content(&$a, $update = 0) {
// Schema.org microdata // Schema.org microdata
$a->page['htmlhead'] .= '<meta itemprop="name" content="'.$title.'" />'."\n"; $a->page['htmlhead'] .= '<meta itemprop="name" content="'.$title.'" />'."\n";
$a->page['htmlhead'] .= '<meta itemprop="description" content="'.$description.'" />'."\n"; $a->page['htmlhead'] .= '<meta itemprop="description" content="'.$description.'" />'."\n";
$a->page['htmlhead'] .= '<meta itemprop="image" content="'.$r[0]["thumb"].'" />'."\n"; $a->page['htmlhead'] .= '<meta itemprop="image" content="'.$image.'" />'."\n";
$a->page['htmlhead'] .= '<meta itemprop="author" content="'.$author_name.'" />'."\n"; $a->page['htmlhead'] .= '<meta itemprop="author" content="'.$author_name.'" />'."\n";
// Twitter cards
$a->page['htmlhead'] .= '<meta name="twitter:card" content="summary" />'."\n";
$a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$title.'" />'."\n";
$a->page['htmlhead'] .= '<meta name="twitter:description" content="'.$description.'" />'."\n";
$a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$image.'" />'."\n";
$a->page['htmlhead'] .= '<meta name="twitter:url" content="'.$r[0]["plink"].'" />'."\n";
// Dublin Core // Dublin Core
$a->page['htmlhead'] .= '<meta name="DC.title" content="'.$title.'" />'."\n"; $a->page['htmlhead'] .= '<meta name="DC.title" content="'.$title.'" />'."\n";
$a->page['htmlhead'] .= '<meta name="DC.description" content="'.$description.'" />'."\n"; $a->page['htmlhead'] .= '<meta name="DC.description" content="'.$description.'" />'."\n";
@ -229,7 +240,7 @@ function display_content(&$a, $update = 0) {
// Open Graph // Open Graph
$a->page['htmlhead'] .= '<meta property="og:type" content="website" />'."\n"; $a->page['htmlhead'] .= '<meta property="og:type" content="website" />'."\n";
$a->page['htmlhead'] .= '<meta property="og:title" content="'.$title.'" />'."\n"; $a->page['htmlhead'] .= '<meta property="og:title" content="'.$title.'" />'."\n";
$a->page['htmlhead'] .= '<meta property="og:image" content="'.$r[0]["thumb"].'" />'."\n"; $a->page['htmlhead'] .= '<meta property="og:image" content="'.$image.'" />'."\n";
$a->page['htmlhead'] .= '<meta property="og:url" content="'.$r[0]["plink"].'" />'."\n"; $a->page['htmlhead'] .= '<meta property="og:url" content="'.$r[0]["plink"].'" />'."\n";
$a->page['htmlhead'] .= '<meta property="og:description" content="'.$description.'" />'."\n"; $a->page['htmlhead'] .= '<meta property="og:description" content="'.$description.'" />'."\n";
$a->page['htmlhead'] .= '<meta name="og:article:author" content="'.$author_name.'" />'."\n"; $a->page['htmlhead'] .= '<meta name="og:article:author" content="'.$author_name.'" />'."\n";

View file

@ -52,6 +52,9 @@ function completeurl($url, $scheme) {
function parseurl_getsiteinfo($url, $no_guessing = false) { function parseurl_getsiteinfo($url, $no_guessing = false) {
$siteinfo = array(); $siteinfo = array();
$siteinfo["type"] = "link";
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_HEADER, 1);
@ -165,6 +168,18 @@ function parseurl_getsiteinfo($url, $no_guessing = false) {
case "description": case "description":
$siteinfo["text"] = $attr["content"]; $siteinfo["text"] = $attr["content"];
break; break;
case "twitter:image":
$siteinfo["image"] = $attr["content"];
break;
case "twitter:card":
$siteinfo["type"] = $attr["content"];
break;
case "twitter:description":
$siteinfo["text"] = $attr["content"];
break;
case "twitter:title":
$siteinfo["title"] = $attr["content"];
break;
case "dc.title": case "dc.title":
$siteinfo["title"] = $attr["content"]; $siteinfo["title"] = $attr["content"];
break; break;
@ -311,9 +326,9 @@ function parse_url_content(&$a) {
logger('parse_url: ' . $url); logger('parse_url: ' . $url);
if($textmode) if($textmode)
$template = '[bookmark=%s]%s[/bookmark]%s' . $br; $template = '[bookmark=%s]%s[/bookmark]%s';
else else
$template = "<a class=\"bookmark\" href=\"%s\" >%s</a>%s<br />"; $template = "<a class=\"bookmark\" href=\"%s\" >%s</a>%s";
$arr = array('url' => $url, 'text' => ''); $arr = array('url' => $url, 'text' => '');
@ -386,9 +401,10 @@ function parse_url_content(&$a) {
$text = '<blockquote>'.htmlspecialchars(trim($text)).'</blockquote>'; $text = '<blockquote>'.htmlspecialchars(trim($text)).'</blockquote>';
} }
if($image) { if($image)
$text = $br.$br.$image.$text; $text = $br.$br.$image.$text;
} else
$text = $br.$text;
$title = str_replace(array("\r","\n"),array('',''),$title); $title = str_replace(array("\r","\n"),array('',''),$title);
@ -398,7 +414,10 @@ function parse_url_content(&$a) {
$sitedata .= trim($result); $sitedata .= trim($result);
echo "[class=type-link]".$sitedata."[/class]"; if (($siteinfo["type"] != "photo"))
echo "[class=type-link]".$sitedata."[/class]";
else
echo "[class=type-photo]".$title.$br.$image."[/class]";
killme(); killme();
} }

View file

@ -1368,7 +1368,11 @@ function photos_content(&$a) {
$photo = array( $photo = array(
'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']], 'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
'title'=> t('View Full Size'), 'title'=> t('View Full Size'),
'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis') 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis'),
'height' => $hires['height'],
'width' => $hires['width'],
'album' => $hires['album'],
'filename' => $hires['filename'],
); );
if($nextlink) if($nextlink)
@ -1723,6 +1727,12 @@ function photos_content(&$a) {
'$paginate' => $paginate, '$paginate' => $paginate,
)); ));
$a->page['htmlhead'] .= "\n".'<meta name="twitter:card" content="photo" />'."\n";
$a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$photo["album"].'" />'."\n";
$a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$photo["href"].'" />'."\n";
$a->page['htmlhead'] .= '<meta name="twitter:image:width" content="'.$photo["width"].'" />'."\n";
$a->page['htmlhead'] .= '<meta name="twitter:image:height" content="'.$photo["height"].'" />'."\n";
return $o; return $o;
} }

View file

@ -0,0 +1,52 @@
<?php
/**
* Theme settings
*/
function theme_content(&$a){
if(!local_user())
return;
$style = get_pconfig(local_user(), 'vier', 'style');
return vier_form($a,$style);
}
function theme_post(&$a){
if(! local_user())
return;
if (isset($_POST['vier-settings-submit'])){
set_pconfig(local_user(), 'vier', 'style', $_POST['vier_style']);
}
}
function theme_admin(&$a){
$style = get_config('vier', 'style');
return vier_form($a,$style);
}
function theme_admin_post(&$a){
if (isset($_POST['vier-settings-submit'])){
set_config('vier', 'style', $_POST['vier_style']);
}
}
function vier_form(&$a, $style){
$styles = array(
"shadow"=>"Shadow",
"flat"=>"Flat"
);
$t = get_markup_template("theme_settings.tpl" );
$o .= replace_macros($t, array(
'$submit' => t('Submit'),
'$baseurl' => $a->get_baseurl(),
'$title' => t("Theme settings"),
'$style' => array('vier_style',t ('Set style'),$style,'',$styles),
));
return $o;
}

4
view/theme/vier/flat.css Normal file
View file

@ -0,0 +1,4 @@
*{ box-shadow: 0 0 0 0 !important;}
body, section { background-color: #ffffff !important;}
#profile-jot-form { background-color: #ffffff !important;}
.dspr, .twit, .pump, .dfrn { background-color: #ffffff !important;}

View file

@ -1219,6 +1219,10 @@ border-bottom: 1px solid #D2D2D2;
.type-link .oembed { .type-link .oembed {
} }
.type-link img + br{
display: none;
}
.wall-item-container .wall-item-content { .wall-item-container .wall-item-content {
/* font-size: 14px; */ /* font-size: 14px; */
max-width: 660px; max-width: 660px;

View file

@ -0,0 +1,11 @@
{{*
* AUTOMATICALLY GENERATED TEMPLATE
* DO NOT EDIT THIS FILE, CHANGES WILL BE OVERWRITTEN
*
*}}
{{include file="field_select.tpl" field=$style}}
<div class="settings-submit-wrapper">
<input type="submit" value="{{$submit}}" class="settings-submit" name="vier-settings-submit" />
</div>

View file

@ -15,6 +15,10 @@ $baseurl = $a->get_baseurl();
$a->theme_info = array(); $a->theme_info = array();
$style = get_pconfig(local_user(), 'vier', 'style');
if ($style == "flat")
$a->page['htmlhead'] .= '<link rel="stylesheet" href="view/theme/vier/flat.css" type="text/css" media="screen"/>'."\n";
$a->page['htmlhead'] .= <<< EOT $a->page['htmlhead'] .= <<< EOT
<script type="text/javascript" src="$baseurl/view/theme/vier/js/jquery.divgrow-1.3.1.f1.min.js"></script> <script type="text/javascript" src="$baseurl/view/theme/vier/js/jquery.divgrow-1.3.1.f1.min.js"></script>
<script> <script>