1
0
Fork 0

Merge pull request #906 from annando/master

API now supports entities/Design changes to "vier"
This commit is contained in:
Tobias Diekershoff 2014-02-02 01:48:47 -08:00
commit ebc04e8506
7 changed files with 255 additions and 53 deletions

View file

@ -807,6 +807,10 @@
'statusnet_conversation_id' => $lastwall['parent'],
);
$entities = api_get_entitities($status_info['text'], $lastwall['body']);
if (count($entities) > 0)
$status_info['entities'] = $entities;
if (($lastwall['item_network'] != "") AND ($status["source"] == 'web'))
$status_info["source"] = network_to_name($lastwall['item_network']);
elseif (($lastwall['item_network'] != "") AND (network_to_name($lastwall['item_network']) != $status_info["source"]))
@ -896,6 +900,10 @@
'statusnet_conversation_id' => $lastwall['parent'],
);
$entities = api_get_entitities($user_info['text'], $lastwall['body']);
if (count($entities) > 0)
$user_info['entities'] = $entities;
if (($lastwall['item_network'] != "") AND ($user_info["status"]["source"] == 'web'))
$user_info["status"]["source"] = network_to_name($lastwall['item_network']);
if (($lastwall['item_network'] != "") AND (network_to_name($lastwall['item_network']) != $user_info["status"]["source"]))
@ -965,7 +973,7 @@
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
$sql_extra
AND `item`.`id`>%d
ORDER BY `item`.`received` DESC LIMIT %d ,%d ",
ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
//intval($user_info['uid']),
intval(api_user()),
intval($since_id),
@ -1046,7 +1054,7 @@
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
$sql_extra
AND `item`.`id`>%d
ORDER BY `received` DESC LIMIT %d, %d ",
ORDER BY `item`.`id` DESC LIMIT %d, %d ",
intval($since_id),
intval($start),
intval($count));
@ -1178,7 +1186,7 @@
AND `item`.`uid` = %d AND `contact`.`id` = `item`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
AND `item`.`id`>%d $sql_extra
ORDER BY `item`.`received` DESC LIMIT %d ,%d",
ORDER BY `item`.`id` DESC LIMIT %d ,%d",
intval($id), intval(api_user()),
intval($since_id),
intval($start), intval($count)
@ -1348,7 +1356,7 @@
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
$sql_extra
AND `item`.`id`>%d
ORDER BY `item`.`received` DESC LIMIT %d ,%d ",
ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
//intval($user_info['uid']),
intval(api_user()),
intval($since_id),
@ -1421,7 +1429,7 @@
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
$sql_extra
AND `item`.`id`>%d
ORDER BY `item`.`received` DESC LIMIT %d ,%d ",
ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
intval(api_user()),
intval($user_info['cid']),
intval($since_id),
@ -1485,7 +1493,7 @@
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
$sql_extra
AND `item`.`id`>%d
ORDER BY `item`.`received` DESC LIMIT %d ,%d ",
ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
//intval($user_info['uid']),
intval(api_user()),
intval($since_id),
@ -1615,6 +1623,120 @@
return $ret;
}
function api_get_entitities($text, $bbcode) {
/*
To-Do:
* remove links to pictures if they are links of a picture
* Some video stuff isn't recognized
* Links at the first character of the post
* different sizes of pictures
* caching picture data (using the id for that?) (See privacy_image_cache)
*/
$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:true);
// To-Do
// if (!$include_entities OR ($include_entities == "false"))
// return false;
$entities = array();
$entities["hashtags"] = array();
$entities["symbols"] = array();
$entities["urls"] = array();
$entities["user_mentions"] = array();
$bbcode = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'[url=$1]$2[/url]',$bbcode);
//$bbcode = preg_replace("/\[url\](.*?)\[\/url\]/ism",'[url=$1]$1[/url]',$bbcode);
$bbcode = preg_replace("/\[video\](.*?)\[\/video\]/ism",'[url=$1]$1[/url]',$bbcode);
$bbcode = preg_replace("/\[youtube\](.*?)\[\/youtube\]/ism",'[url=$1]$1[/url]',$bbcode);
$bbcode = preg_replace("/\[vimeo\](.*?)\[\/vimeo\]/ism",'[url=$1]$1[/url]',$bbcode);
$bbcode = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $bbcode);
$URLSearchString = "^\[\]";
//preg_match_all("/\[url\]([$URLSearchString]*)\[\/url\]/ism", $bbcode, $urls1);
preg_match_all("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", $bbcode, $urls);
$ordered_urls = array();
foreach ($urls[1] AS $id=>$url) {
//$start = strpos($text, $url, $offset);
$start = iconv_strpos($text, $url, 0, "UTF-8");
if (!($start === false))
$ordered_urls[$start] = array("url" => $url, "title" => $urls[2][$id]);
}
ksort($ordered_urls);
$offset = 0;
//foreach ($urls[1] AS $id=>$url) {
foreach ($ordered_urls AS $url) {
if ((substr($url["title"], 0, 7) != "http://") AND (substr($url["title"], 0, 8) != "https://") AND
!strpos($url["title"], "http://") AND !strpos($url["title"], "https://"))
$display_url = $url["title"];
else {
$display_url = str_replace(array("http://www.", "https://www."), array("", ""), $url["url"]);
$display_url = str_replace(array("http://", "https://"), array("", ""), $display_url);
if (strlen($display_url) > 26)
$display_url = substr($display_url, 0, 25)."";
}
//$start = strpos($text, $url, $offset);
$start = iconv_strpos($text, $url["url"], $offset, "UTF-8");
if (!($start === false)) {
$entities["urls"][] = array("url" => $url["url"],
"expanded_url" => $url["url"],
"display_url" => $display_url,
"indices" => array($start, $start+strlen($url["url"])));
$offset = $start + 1;
}
}
preg_match_all("/\[img](.*?)\[\/img\]/ism", $bbcode, $images);
$ordered_images = array();
foreach ($images[1] AS $image) {
//$start = strpos($text, $url, $offset);
$start = iconv_strpos($text, $image, 0, "UTF-8");
if (!($start === false))
$ordered_images[$start] = $image;
}
//$entities["media"] = array();
$offset = 0;
foreach ($ordered_images AS $url) {
$display_url = str_replace(array("http://www.", "https://www."), array("", ""), $url);
$display_url = str_replace(array("http://", "https://"), array("", ""), $display_url);
if (strlen($display_url) > 26)
$display_url = substr($display_url, 0, 25)."";
$start = iconv_strpos($text, $url, $offset, "UTF-8");
if (!($start === false)) {
$redirects = 0;
$img_str = fetch_url($url,true, $redirects, 10);
$image = @imagecreatefromstring($img_str);
if ($image) {
$entities["media"][] = array(
"id" => $start,
"id_str" => (string)$start,
"indices" => array($start, $start+strlen($url)),
"media_url" => $url,
"media_url_https" => $url,
"url" => $url,
"display_url" => $display_url,
"expanded_url" => $url,
"type" => "photo",
"sizes" => array("medium" => array(
"w" => imagesx($image),
"h" => imagesy($image),
"resize" => "fit")));
}
$offset = $start + 1;
}
}
return($entities);
}
function api_format_items($r,$user_info, $filter_user = false) {
$a = get_app();
@ -1669,6 +1791,7 @@
}
// Workaround for ostatus messages where the title is identically to the body
//$statusbody = trim(html2plain(bbcode(api_clean_plain_items($item['body']), false, false, 5, true), 0));
$statusbody = trim(html2plain(bbcode(api_clean_plain_items($item['body']), false, false, 2, true), 0));
$statustitle = trim($item['title']);
@ -1697,10 +1820,15 @@
'favorited' => $item['starred'] ? true : false,
//'attachments' => array(),
'user' => $status_user ,
//'entities' => NULL,
'statusnet_html' => trim(bbcode($item['body'], false, false)),
'statusnet_conversation_id' => $item['parent'],
);
$entities = api_get_entitities($status['text'], $item['body']);
if (count($entities) > 0)
$status['entities'] = $entities;
if (($item['item_network'] != "") AND ($status["source"] == 'web'))
$status["source"] = network_to_name($item['item_network']);
else if (($item['item_network'] != "") AND (network_to_name($item['item_network']) != $status["source"]))
@ -1779,6 +1907,20 @@
}
api_register_func('api/help/test','api_help_test',false);
function api_lists(&$a,$type) {
$ret = array();
return array($ret);
}
api_register_func('api/lists','api_lists',true);
function api_lists_list(&$a,$type) {
$ret = array();
return array($ret);
}
api_register_func('api/lists/list','api_lists_list',true);
/**
* https://dev.twitter.com/docs/api/1/get/statuses/friends
* This function is deprecated by Twitter
@ -2052,7 +2194,7 @@
if ($max_id > 0)
$sql_extra .= ' AND `mail`.`id` <= '.intval($max_id);
$r = q("SELECT `mail`.*, `contact`.`nurl` AS `contact-url` FROM `mail`,`contact` WHERE `mail`.`contact-id` = `contact`.`id` AND `mail`.`uid`=%d AND $sql_extra AND `mail`.`id` > %d ORDER BY `mail`.`created` DESC LIMIT %d,%d",
$r = q("SELECT `mail`.*, `contact`.`nurl` AS `contact-url` FROM `mail`,`contact` WHERE `mail`.`contact-id` = `contact`.`id` AND `mail`.`uid`=%d AND $sql_extra AND `mail`.`id` > %d ORDER BY `mail`.`id` DESC LIMIT %d,%d",
intval(api_user()),
intval($since_id),
intval($start), intval($count)

View file

@ -554,7 +554,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
$Text = preg_replace("/\[(\w*)\](\s*)/ism", '$2[$1]', $Text);
$Text = preg_replace("/(\s*)\[\/(\w*)\]/ism", '[/$2]$1', $Text);
// Extract the private images which use data url's since preg has issues with
// Extract the private images which use data urls since preg has issues with
// large data sizes. Stash them away while we do bbcode conversion, and then put them back
// in after we've done all the regex matching. We cannot use any preg functions to do this.
@ -618,18 +618,23 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
// Set up the parameters for a MAIL search string
$MAILSearchString = $URLSearchString;
if ($simplehtml == 5)
$Text = preg_replace("/[^#@]\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[url]$1[/url]', $Text);
// Perform URL Search
if ($tryoembed)
$Text = preg_replace_callback("/\[bookmark\=([^\]]*)\].*?\[\/bookmark\]/ism",'tryoembed',$Text);
if ($simplehtml == 5)
$Text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'[url]$1[/url]',$Text);
else
$Text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'[url=$1]$2[/url]',$Text);
// if the HTML is used to generate plain text, then don't do this search, but replace all URL of that kind to text
if (!$forplaintext)
$Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1<a href="$2" target="external-link">$2</a>', $Text);
else
$Text = preg_replace("(\[url\](.*?)\[\/url\])ism","$1",$Text);
if ($tryoembed)
$Text = preg_replace_callback("/\[bookmark\=([^\]]*)\].*?\[\/bookmark\]/ism",'tryoembed',$Text);
$Text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'[url=$1]$2[/url]',$Text);
$Text = preg_replace("(\[url\](.*?)\[\/url\])ism"," $1 ",$Text);
if ($tryoembed)
$Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism",'tryoembed',$Text);
@ -786,7 +791,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
$Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text);
elseif ($simplehtml == 1)
$Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributesSimple",$Text);
elseif ($simplehtml == 2)
elseif (($simplehtml == 2) OR ($simplehtml == 5))
$Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributesSimple2",$Text);
elseif ($simplehtml == 3)
$Text = preg_replace_callback("/(.*?)\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributesDiaspora",$Text);

View file

@ -191,9 +191,9 @@ function html2plain($html, $wraplength = 75, $compact = false)
//node2bbcode($doc, 'img', array('title'=>'/(.+)/'), '$1', '');
//node2bbcode($doc, 'img', array(), '', '');
if (!$compact)
node2bbcode($doc, 'img', array('src'=>'/(.+)/'), '[img]$1', '[/img]');
node2bbcode($doc, 'img', array('src'=>'/(.+)/'), ' [img]$1', '[/img] ');
else
node2bbcode($doc, 'img', array('src'=>'/(.+)/'), '', '');
node2bbcode($doc, 'img', array('src'=>'/(.+)/'), ' ', ' ');
node2bbcode($doc, 'iframe', array('src'=>'/(.+)/'), ' $1 ', '', true);

View file

@ -191,6 +191,10 @@ if(strlen($a->module)) {
if ($a->module == "stream")
$a->module = "network";
// Compatibility with the Firefox App
if (($a->module == "users") AND ($a->cmd == "users/sign_in"))
$a->module = "login";
$privateapps = get_config('config','private_addons');
if(is_array($a->plugins) && in_array($a->module,$a->plugins) && file_exists("addon/{$a->module}/{$a->module}.php")) {
@ -461,7 +465,7 @@ if ($_GET["mode"] == "raw") {
exit;
} elseif (get_pconfig(local_user(),'system','infinite_scroll')
AND ($_GET["q"] == "network") AND ($_GET["mode"] != "minimal")) {
AND ($a->module == "network") AND ($_GET["mode"] != "minimal")) {
if (is_string($_GET["page"]))
$pageno = $_GET["page"];
else

View file

@ -299,6 +299,8 @@ class Item extends BaseObject {
'title' => $title_e,
'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
'app' => $item['app'],
'created' => relative_date($item['created']),
'lock' => $lock,
'location' => $location_e,
'indent' => $indent,

View file

@ -289,11 +289,15 @@ blockquote.shared_content {
/* global */
body {
font-family: 'Lato', "Helvetica Neue", Helvetica, Arial, sans-serif;
/* font-family: 'Lato', "Helvetica Neue", Helvetica, Arial, sans-serif; */
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
/* font-size: 13px; */
/* line-height: 19.5px; */
font-weight: 400;
/* background-color: #ffffff; */
background-color: #FAFAFA;
/* background-color: rgb(252, 252, 252); */
/* background-color: #FAFAFA; */
background-color: rgb(229, 229, 229);
color: #2d2d2d;
margin: 0px 0px 0px 0px;
display: table;
@ -550,8 +554,8 @@ nav {
z-index: 100;
/*-webkit-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.7);
-moz-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.7);
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.7);
border-bottom: 5px solid #F80; */
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.7);
}
nav .icon {
@ -880,11 +884,12 @@ aside {
top: 32px;
overflow-y: auto;
z-index: 2;
line-height: 17px;
position: fixed;
/* overflow: auto; */
height: calc(100% - 42px);
/* overflow: scroll; */
box-shadow: 1px 1px 6px -3px #666;
}
aside .vcard .fn {
font-size: 18px;
@ -1091,13 +1096,15 @@ section {
padding: 10px 10px 10px 10px;
/* background-color: white; */
/* background-color: rgb(252, 252, 252); */
background-color: #FAFAFA;
border-bottom: 1px solid lightgray;
/* background-color: #FAFAFA; */
background-color: inherit;
/* border-bottom: 1px solid lightgray;
border-right: 1px solid lightgray;
border-left: 1px solid lightgray;
border-left: 1px solid lightgray; */
position: absolute;
left: 215px;
/*left: 215px;*/
left: calc(215px + (100% - (215px + 766px)) / 6);
/* left: calc(215px + (100% - 215px) / 10); */
}
section.minimal {
@ -1111,12 +1118,15 @@ section.minimal {
border-bottom: 1px solid #D2D2D2;
position: relative;
padding: 5px;
margin-bottom: 0px;
/* width: 755px; */
margin-bottom: 10px;
box-shadow: 1px 1px 6px -3px rgba(0, 0, 0, 0.7);
background-color: #FAFaFa;
/* width: 755px; */
}
.wall-item-decor {
position: absolute;
left: 755px;
/* left: 755px; */
left: calc(100% - 7px);
/* top: -10px; */
width: 16px;
}
@ -1125,7 +1135,8 @@ border-bottom: 1px solid #D2D2D2;
}
.wall-item-container {
display: table;
width: 745px;
/* width: 745px; */
width: calc(100% - 10px);
}
.wall-item-content hr {
@ -1143,7 +1154,7 @@ border-bottom: 1px solid #D2D2D2;
display: table-row;
}
.wall-item-bottom {
font-size: 14px;
/* font-size: 14px; */
}
.wall-item-container .wall-item-bottom {
opacity: 0;
@ -1208,20 +1219,22 @@ border-bottom: 1px solid #D2D2D2;
}
.wall-item-container .wall-item-content {
font-size: 14px;
/* font-size: 14px; */
max-width: 660px;
word-wrap: break-word;
line-height: 1.36;
/* line-height: 1.36; */
padding-bottom: 6px;
}
.wall-item-container .wall-item-content img {
max-width: 650px;
max-width: 100%;
/* max-width: 650px; */
/* max-width: 580px; */
}
.children .wall-item-container .wall-item-item .wall-item-content img {
/* max-width: 650px; */
max-width: 580px;
/* max-width: 580px; */
max-width: 100%;
}
.wall-item-container .wall-item-links, .wall-item-container .wall-item-actions {
display: table-cell;
@ -1338,7 +1351,8 @@ border-bottom: 1px solid #D2D2D2;
margin-top: 5px;
margin-bottom: 5px;
margin-left: 80px;
width: 665px;
/* width: 665px; */
width: calc(100% - 90px);
border-bottom: 1px solid hsl(198, 21%, 79%);
}
.wall-item-container.comment .wall-item-content {
@ -1371,13 +1385,13 @@ border-bottom: 1px solid #D2D2D2;
.wall-item-comment-wrapper textarea {
height: 1.2em;
width: 100%;
font-size: 10px;
font-size: 13px;
color: #999999;
border: 1px solid #DDD;
padding: 0.3em;
}
.wall-item-comment-wrapper .comment-edit-text-full {
font-size: 14px;
/* font-size: 14px; */
height: 4em;
color: #2d2d2d;
border: 1px solid #2d2d2d;
@ -1427,34 +1441,47 @@ border-bottom: 1px solid #D2D2D2;
}
.twit {
background-color: #FFFAFA;
/* background-color: #FFFAFA; */
background-color: #fafeff;
}
.pump {
background-color: #FAFFFA;
/* background-color: #FAFFFA; */
background-color: #fcfffa;
}
.face {
background-color: #FAFAFF;
/* background-color: #FAFAFF; */
background-color: #fafcff;
}
.feed {
background-color: #FFFFFA;
/* background-color: #FFFFFA; */
background-color: #fffdfa;
}
.dspr {
background-color: #FFFAFF;
}
.dfrn {
background-color: #FAFFFF;
}
.stat {
background-color: #FAFAFA;
}
.stat {
/* background-color: #FAFFFF; */
background-color: #fffafd;
}
.mail {
background-color: #FFFFF9;
/* background-color: #FFFFF9; */
background-color: #fffafa;
}
#profile-jot-form {
box-shadow: 1px 1px 6px -3px #666;
background-color: #fafafa;
padding: 10px;
}
#profile-jot-form #profile-jot-text {
height: 2.0em;
/* width: 99%; */
width: 752px;
/* width: 752px; */
width: calc(100% - 10px);
font-size: 15px;
color: #999999;
border: 1px solid #DDD;
@ -1469,7 +1496,8 @@ border-bottom: 1px solid #D2D2D2;
height: 20px;
margin: 0 0 5px;
/* width: 60%; */
width: 762px;
/* width: 762px; */
width: 100%;
border: 1px solid #d2d2d2;
}
@ -1480,7 +1508,8 @@ border-bottom: 1px solid #D2D2D2;
font-weight: normal;
}
#profile-jot-form #profile-jot-text_parent #profile-jot-text_tbl{
width: 785px;
/* width: 785px; */
width: 100%;
height: 100px;
}
@ -1911,6 +1940,26 @@ ul.tabs a {
color: #444;
}
ul.tabs a {
box-shadow: 1px 1px 6px -3px #666;
margin-right: 5px;
}
#birthday-notice, #event-notice {
box-shadow: 1px 1px 6px -3px #666;
margin-bottom: 5px;
}
#birthday-wrapper, #event-wrapper {
background-color: #FAFAFA;
box-shadow: 1px 1px 6px -3px #666;
padding-left: 10px;
padding-right: 10px;
padding-top: 5px;
padding-bottom: 5px;
margin-bottom: 10px;
}
div.pager, .birthday-notice, #jot-preview-link, .comment-edit-submit-wrapper .fakelink {
padding: 2px 7px 2px 7px;
color: black;

View file

@ -59,10 +59,10 @@
<a href="{{$item.profile_url}}" target="redir" title="{{$item.linktitle}}" class="wall-item-name-link"><span class="wall-item-name{{$item.sparkle}}">{{$item.name}}</span></a>
{{if $item.owner_url}}{{$item.via}} <a href="{{$item.owner_url}}" target="redir" title="{{$item.olinktitle}}" class="wall-item-name-link"><span class="wall-item-name{{$item.osparkle}}" id="wall-item-ownername-{{$item.id}}">{{$item.owner_name}}</span></a> <!-- {{$item.vwall}} -->{{/if}}
<span class="wall-item-ago">
{{if $item.plink}}<a title="{{$item.plink.title}}" href="{{$item.plink.href}}" style="color: #999">{{$item.ago}}</a>{{else}} {{$item.ago}} {{/if}}
{{if $item.plink}}<a title="{{$item.plink.title}}" href="{{$item.plink.href}}" style="color: #999">{{$item.created}}</a>{{else}} {{$item.created}} {{/if}}
{{if $item.lock}}<span class="fakelink" style="color: #999" onclick="lockview(event,{{$item.id}});">{{$item.lock}}</span> {{/if}}
</span>
<span class="wall-item-network">
<span class="wall-item-network" title="{{$item.app}}">
{{$item.network_name}}
</span>
</div>