aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorSebastian Egbers <sebastian@egbers.info>2012-06-25 13:59:39 +0200
committerSebastian Egbers <sebastian@egbers.info>2012-06-25 13:59:39 +0200
commit020deedd7c68ce016b65056062d85567c91c3d37 (patch)
treeb07a71b2d57d5dfae527ab9e2a6f42423bc8b327 /include
parentcbf1cab0da2b67c8a88f301ce9ce6b83db27ec0b (diff)
parent7ea5917bf794c431fe304fa25380f19a6927cf63 (diff)
downloadvolse-hubzilla-020deedd7c68ce016b65056062d85567c91c3d37.tar.gz
volse-hubzilla-020deedd7c68ce016b65056062d85567c91c3d37.tar.bz2
volse-hubzilla-020deedd7c68ce016b65056062d85567c91c3d37.zip
Merge branch 'master' of https://github.com/friendica/friendica
Diffstat (limited to 'include')
-rw-r--r--include/bb2diaspora.php50
-rw-r--r--include/conversation.php8
-rwxr-xr-xinclude/diaspora.php14
-rw-r--r--include/follow.php36
-rwxr-xr-xinclude/items.php17
-rw-r--r--include/network.php18
-rw-r--r--include/plugin.php81
-rw-r--r--include/profile_advanced.php5
-rw-r--r--include/user.php14
9 files changed, 218 insertions, 25 deletions
diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php
index 96cc735bd..ac693127b 100644
--- a/include/bb2diaspora.php
+++ b/include/bb2diaspora.php
@@ -68,9 +68,14 @@ function stripdcode_br_cb($s) {
function diaspora_ul($s) {
- // Replace "[\\*]" followed by any number (including zero) of
+ // Replace "[*]" followed by any number (including zero) of
// spaces by "* " to match Diaspora's list format
- return preg_replace("/\[\\\\\*\]( *)/", "* ", $s[1]);
+ if( strpos($s[0], "[list]") === 0 )
+ return '<ul class="listbullet" style="list-style-type: circle;">' . preg_replace("/\[\*\]( *)/", "* ", $s[1]) . '</ul>';
+ elseif( strpos($s[0], "[ul]") === 0 )
+ return '<ul class="listbullet" style="list-style-type: circle;">' . preg_replace("/\[\*\]( *)/", "* ", $s[1]) . '</ul>';
+ else
+ return $s[0];
}
@@ -80,12 +85,45 @@ function diaspora_ol($s) {
// 1. First element
// 1. Second element
// 1. Third element
- return preg_replace("/\[\\\\\*\]( *)/", "1. ", $s[1]);
+ if( strpos($s[0], "[list=1]") === 0 )
+ return '<ul class="listdecimal" style="list-style-type: decimal;">' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '</ul>';
+ elseif( strpos($s[0], "[list=i]") === 0 )
+ return '<ul class="listlowerroman" style="list-style-type: lower-roman;">' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '</ul>';
+ elseif( strpos($s[0], "[list=I]") === 0 )
+ return '<ul class="listupperroman" style="list-style-type: upper-roman;">' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '</ul>';
+ elseif( strpos($s[0], "[list=a]") === 0 )
+ return '<ul class="listloweralpha" style="list-style-type: lower-alpha;">' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '</ul>';
+ elseif( strpos($s[0], "[list=A]") === 0 )
+ return '<ul class="listupperalpha" style="list-style-type: upper-alpha;">' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '</ul>';
+ elseif( strpos($s[0], "[ol]") === 0 )
+ return '<ul class="listdecimal" style="list-style-type: decimal;">' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '</ul>';
+ else
+ return $s[0];
}
function bb2diaspora($Text,$preserve_nl = false) {
+ // bbcode() will convert "[*]" into "<li>" with no closing "</li>"
+ // Markdownify() is unable to handle these, as it makes each new
+ // "<li>" into a deeper nested element until it crashes. So pre-format
+ // the lists as Diaspora lists before sending the $Text to bbcode()
+ //
+ // Note that regular expressions are really not suitable for parsing
+ // text with opening and closing tags, so nested lists may make things
+ // wonky
+ $endlessloop = 0;
+ while ((strpos($Text, "[/list]") !== false) && (strpos($Text, "[list") !== false) && (++$endlessloop < 20)) {
+ $Text = preg_replace_callback("/\[list\](.*?)\[\/list\]/is", 'diaspora_ul', $Text);
+ $Text = preg_replace_callback("/\[list=1\](.*?)\[\/list\]/is", 'diaspora_ol', $Text);
+ $Text = preg_replace_callback("/\[list=i\](.*?)\[\/list\]/s",'diaspora_ol', $Text);
+ $Text = preg_replace_callback("/\[list=I\](.*?)\[\/list\]/s", 'diaspora_ol', $Text);
+ $Text = preg_replace_callback("/\[list=a\](.*?)\[\/list\]/s", 'diaspora_ol', $Text);
+ $Text = preg_replace_callback("/\[list=A\](.*?)\[\/list\]/s", 'diaspora_ol', $Text);
+ }
+ $Text = preg_replace_callback("/\[ul\](.*?)\[\/ul\]/is", 'diaspora_ul', $Text);
+ $Text = preg_replace_callback("/\[ol\](.*?)\[\/ol\]/is", 'diaspora_ol', $Text);
+
// Convert it to HTML - don't try oembed
$Text = bbcode($Text, $preserve_nl, false);
@@ -93,6 +131,12 @@ function bb2diaspora($Text,$preserve_nl = false) {
$md = new Markdownify(false, false, false);
$Text = $md->parseString($Text);
+ // If the text going into bbcode() has a plain URL in it, i.e.
+ // with no [url] tags around it, it will come out of parseString()
+ // looking like: <http://url.com>, which gets removed by strip_tags().
+ // So take off the angle brackets of any such URL
+ $Text = preg_replace("/<http(.*?)>/is", "http$1", $Text);
+
// Remove all unconverted tags
$Text = strip_tags($Text);
diff --git a/include/conversation.php b/include/conversation.php
index 946014b6d..c2113dead 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -427,8 +427,8 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
// We've already parsed out like/dislike for special treatment. We can ignore them now
if(((activity_match($item['verb'],ACTIVITY_LIKE))
- || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
- && ($item['id'] != $item['parent']))
+ || (activity_match($item['verb'],ACTIVITY_DISLIKE))))
+// && ($item['id'] != $item['parent']))
continue;
$toplevelpost = (($item['id'] == $item['parent']) ? true : false);
@@ -549,13 +549,13 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
$shareable = ((($profile_owner == local_user()) && ((! $item['private']) || $item['network'] === NETWORK_FEED)) ? true : false);
if($page_writeable) {
- /* if($toplevelpost) { */
+/* if($toplevelpost) { */
$likebuttons = array(
'like' => array( t("I like this \x28toggle\x29"), t("like")),
'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
);
if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
- /* } */
+/* } */
$qc = $qcomment = null;
diff --git a/include/diaspora.php b/include/diaspora.php
index 80fb10404..a398007e1 100755
--- a/include/diaspora.php
+++ b/include/diaspora.php
@@ -1560,7 +1560,8 @@ function diaspora_photo($importer,$xml,$msg) {
$link_text = '[img]' . $remote_photo_path . $remote_photo_name . '[/img]' . "\n";
- $link_text = scale_external_images($link_text);
+ $link_text = scale_external_images($link_text, true,
+ array($remote_photo_name, 'scaled_full_' . $remote_photo_name));
if(strpos($parent_item['body'],$link_text) === false) {
$r = q("update item set `body` = '%s', `visible` = 1 where `id` = %d and `uid` = %d limit 1",
@@ -2251,7 +2252,6 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
$relay_retract = true;
$target_type = ( ($item['verb'] === ACTIVITY_LIKE) ? 'Like' : 'Comment');
- $sender_signed_text = $item['guid'] . ';' . $target_type ;
$sql_sign_id = 'retract_iid';
$tpl = get_markup_template('diaspora_relayable_retraction.tpl');
@@ -2262,13 +2262,10 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
$target_type = 'Post';
// $positive = (($item['deleted']) ? 'false' : 'true');
$positive = 'true';
- $sender_signed_text = $item['guid'] . ';' . $target_type . ';' . $parent_guid . ';' . $positive . ';' . $myaddr;
$tpl = get_markup_template('diaspora_like_relay.tpl');
}
else { // item is a comment
- $sender_signed_text = $item['guid'] . ';' . $parent_guid . ';' . $text . ';' . $myaddr;
-
$tpl = get_markup_template('diaspora_comment_relay.tpl');
}
@@ -2294,6 +2291,13 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
return;
}
+ if($relay_retract)
+ $sender_signed_text = $item['guid'] . ';' . $target_type;
+ elseif($like)
+ $sender_signed_text = $item['guid'] . ';' . $target_type . ';' . $parent_guid . ';' . $positive . ';' . $handle;
+ else
+ $sender_signed_text = $item['guid'] . ';' . $parent_guid . ';' . $text . ';' . $handle;
+
// Sign the relayable with the top-level owner's signature
//
// We'll use the $sender_signed_text that we just created, instead of the $signed_text
diff --git a/include/follow.php b/include/follow.php
index 22288a0da..b4d1732b8 100644
--- a/include/follow.php
+++ b/include/follow.php
@@ -62,6 +62,11 @@ function new_contact($uid,$url,$interactive = false) {
}
}
+
+
+
+
+
// This extra param just confuses things, remove it
if($ret['network'] === NETWORK_DIASPORA)
$ret['url'] = str_replace('?absolute=true','',$ret['url']);
@@ -89,6 +94,11 @@ function new_contact($uid,$url,$interactive = false) {
$ret['notify'] = '';
}
+
+
+
+
+
if(! $ret['notify']) {
$result['message'] .= t('Limited profile. This person will be unable to receive direct/personal notifications from you.') . EOL;
}
@@ -129,6 +139,32 @@ function new_contact($uid,$url,$interactive = false) {
}
else {
+
+ // check service class limits
+
+ $r = q("select count(*) as total from contact where uid = %d and pending = 0 and self = 0",
+ intval($uid)
+ );
+ if(count($r))
+ $total_contacts = $r[0]['total'];
+
+ if(! service_class_allows($uid,'total_contacts',$total_contacts)) {
+ $result['message'] .= upgrade_message();
+ return $result;
+ }
+
+ $r = q("select count(network) as total from contact where uid = %d and network = '%s' and pending = 0 and self = 0",
+ intval($uid),
+ dbesc($network)
+ );
+ if(count($r))
+ $total_network = $r[0]['total'];
+
+ if(! service_class_allows($uid,'total_contacts_' . $network,$total_network)) {
+ $result['message'] .= upgrade_message();
+ return $result;
+ }
+
$new_relation = (($ret['network'] === NETWORK_MAIL) ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING);
if($ret['network'] === NETWORK_DIASPORA)
$new_relation = CONTACT_IS_FOLLOWER;
diff --git a/include/items.php b/include/items.php
index 9f90d66e4..e495393fa 100755
--- a/include/items.php
+++ b/include/items.php
@@ -1726,10 +1726,12 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
$datarray['type'] = 'activity';
$datarray['gravity'] = GRAVITY_LIKE;
// only one like or dislike per person
- $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 limit 1",
+ $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`parent-uri` = '%s' OR `thr_parent` = '%s') limit 1",
intval($datarray['uid']),
intval($datarray['contact-id']),
- dbesc($datarray['verb'])
+ dbesc($datarray['verb']),
+ dbesc($parent_uri),
+ dbesc($parent_uri)
);
if($r && count($r))
continue;
@@ -2269,12 +2271,13 @@ function local_delivery($importer,$data) {
$r = q("select `item`.`id`, `item`.`uri`, `item`.`tag`, `item`.`forum_mode`,`item`.`origin`,`item`.`wall`,
`contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item`
LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
- WHERE `item`.`uri` = '%s' AND `item`.`parent-uri` = '%s'
+ WHERE `item`.`uri` = '%s' AND (`item`.`parent-uri` = '%s' or `item`.`thr-parent` = '%s')
AND `item`.`uid` = %d
$sql_extra
LIMIT 1",
dbesc($parent_uri),
dbesc($parent_uri),
+ dbesc($parent_uri),
intval($importer['importer_uid'])
);
if($r && count($r))
@@ -2362,7 +2365,7 @@ function local_delivery($importer,$data) {
$datarray['gravity'] = GRAVITY_LIKE;
$datarray['last-child'] = 0;
// only one like or dislike per person
- $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and (`thr-parent` = '%s' or `parent-uri` = '%s') and deleted = 0 limit 1",
+ $r = q("select id from item where uid = %d and `contact-id` = %d and verb = '%s' and (`thr-parent` = '%s' or `parent-uri` = '%s') and deleted = 0 limit 1",
intval($datarray['uid']),
intval($datarray['contact-id']),
dbesc($datarray['verb']),
@@ -2536,10 +2539,12 @@ function local_delivery($importer,$data) {
$datarray['type'] = 'activity';
$datarray['gravity'] = GRAVITY_LIKE;
// only one like or dislike per person
- $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 limit 1",
+ $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`parent-uri` = '%s' OR `thr-parent` = '%s') limit 1",
intval($datarray['uid']),
intval($datarray['contact-id']),
- dbesc($datarray['verb'])
+ dbesc($datarray['verb']),
+ dbesc($parent_uri),
+ dbesc($parent_uri)
);
if($r && count($r))
continue;
diff --git a/include/network.php b/include/network.php
index 446413cd8..c1a76000e 100644
--- a/include/network.php
+++ b/include/network.php
@@ -793,7 +793,7 @@ function add_fcontact($arr,$update = false) {
}
-function scale_external_images($s,$include_link = true) {
+function scale_external_images($s, $include_link = true, $scale_replace = false) {
$a = get_app();
@@ -803,10 +803,22 @@ function scale_external_images($s,$include_link = true) {
require_once('include/Photo.php');
foreach($matches as $mtch) {
logger('scale_external_image: ' . $mtch[1]);
+
$hostname = str_replace('www.','',substr($a->get_baseurl(),strpos($a->get_baseurl(),'://')+3));
if(stristr($mtch[1],$hostname))
continue;
- $i = fetch_url($mtch[1]);
+
+ // $scale_replace, if passed, is an array of two elements. The
+ // first is the name of the full-size image. The second is the
+ // name of a remote, scaled-down version of the full size image.
+ // This allows Friendica to display the smaller remote image if
+ // one exists, while still linking to the full-size image
+ if($scale_replace)
+ $scaled = str_replace($scale_replace[0], $scale_replace[1], $mtch[1]);
+ else
+ $scaled = $mtch[1];
+ $i = fetch_url($scaled);
+
// guess mimetype from headers or filename
$type = guess_image_type($mtch[1],true);
@@ -822,7 +834,7 @@ function scale_external_images($s,$include_link = true) {
$new_width = $ph->getWidth();
$new_height = $ph->getHeight();
logger('scale_external_images: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], LOGGER_DEBUG);
- $s = str_replace($mtch[0],'[img=' . $new_width . 'x' . $new_height. ']' . $mtch[1] . '[/img]'
+ $s = str_replace($mtch[0],'[img=' . $new_width . 'x' . $new_height. ']' . $scaled . '[/img]'
. "\n" . (($include_link)
? '[url=' . $mtch[1] . ']' . t('view full size') . '[/url]' . "\n"
: ''),$s);
diff --git a/include/plugin.php b/include/plugin.php
index c6b61ae6e..d762e8717 100644
--- a/include/plugin.php
+++ b/include/plugin.php
@@ -316,3 +316,84 @@ function get_theme_screenshot($theme) {
}
return($a->get_baseurl() . '/images/blank.png');
}
+
+
+// check service_class restrictions. If there are no service_classes defined, everything is allowed.
+// if $usage is supplied, we check against a maximum count and return true if the current usage is
+// less than the subscriber plan allows. Otherwise we return boolean true or false if the property
+// is allowed (or not) in this subscriber plan. An unset property for this service plan means
+// the property is allowed, so it is only necessary to provide negative properties for each plan,
+// or what the subscriber is not allowed to do.
+
+
+function service_class_allows($uid,$property,$usage = false) {
+
+ if($uid == local_user()) {
+ $service_class = $a->user['service_class'];
+ }
+ else {
+ $r = q("select service_class from user where uid = %d limit 1",
+ intval($uid)
+ );
+ if($r !== false and count($r)) {
+ $service_class = $r[0]['service_class'];
+ }
+ }
+ if(! x($service_class))
+ return true; // everything is allowed
+
+ $arr = get_config('service_class',$service_class);
+ if(! is_array($arr) || (! count($arr)))
+ return true;
+
+ if($usage === false)
+ return ((x($arr[$property])) ? (bool) $arr['property'] : true);
+ else {
+ if(! array_key_exists($property,$arr))
+ return true;
+ return (((intval($usage)) < intval($arr[$property])) ? true : false);
+ }
+}
+
+
+function service_class_fetch($uid,$property) {
+
+ if($uid == local_user()) {
+ $service_class = $a->user['service_class'];
+ }
+ else {
+ $r = q("select service_class from user where uid = %d limit 1",
+ intval($uid)
+ );
+ if($r !== false and count($r)) {
+ $service_class = $r[0]['service_class'];
+ }
+ }
+ if(! x($service_class))
+ return false; // everything is allowed
+
+ $arr = get_config('service_class',$service_class);
+ if(! is_array($arr) || (! count($arr)))
+ return false;
+
+ return((array_key_exists($property,$arr)) ? $arr[$property] : false);
+
+}
+
+function upgrade_link() {
+ $l = get_config('service_class','upgrade_link');
+ $t = sprintf('<a href="%s">' . t('Click here to upgrade.') . '</div>', $l);
+ if($l)
+ return $t;
+ return '';
+}
+
+function upgrade_message() {
+ $x = upgrade_link();
+ return t('This action exceeds the limits set by your subscription plan.') . (($x) ? ' ' . $x : '') ;
+}
+
+function upgrade_bool_message() {
+ $x = upgrade_link();
+ return t('This action is not available under your subscription plan.') . (($x) ? ' ' . $x : '') ;
+}
diff --git a/include/profile_advanced.php b/include/profile_advanced.php
index ffb45090b..8dfb1beec 100644
--- a/include/profile_advanced.php
+++ b/include/profile_advanced.php
@@ -59,6 +59,11 @@ function advanced_profile(&$a) {
if($txt = prepare_text($a->profile['interest'])) $profile['interest'] = array( t('Hobbies/Interests:'), $txt);
+ if($txt = prepare_text($a->profile['likes'])) $profile['likes'] = array( t('Likes:'), $txt);
+
+ if($txt = prepare_text($a->profile['dislikes'])) $profile['dislikes'] = array( t('Dislikes:'), $txt);
+
+
if($txt = prepare_text($a->profile['contact'])) $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
if($txt = prepare_text($a->profile['music'])) $profile['music'] = array( t('Musical interests:'), $txt);
diff --git a/include/user.php b/include/user.php
index 2477438bf..383a3b3e1 100644
--- a/include/user.php
+++ b/include/user.php
@@ -147,13 +147,18 @@ function create_user($arr) {
require_once('include/crypto.php');
- $keys = new_keypair(1024);
+ $keys = new_keypair(4096);
if($keys === false) {
$result['message'] .= t('SERIOUS ERROR: Generation of security keys failed.') . EOL;
return $result;
}
+ $default_service_class = get_config('system','default_service_class');
+ if(! $default_service_class)
+ $default_service_class = '';
+
+
$prvkey = $keys['prvkey'];
$pubkey = $keys['pubkey'];
@@ -173,8 +178,8 @@ function create_user($arr) {
$spubkey = $sres['pubkey'];
$r = q("INSERT INTO `user` ( `guid`, `username`, `password`, `email`, `openid`, `nickname`,
- `pubkey`, `prvkey`, `spubkey`, `sprvkey`, `register_date`, `verified`, `blocked`, `timezone` )
- VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, 'UTC' )",
+ `pubkey`, `prvkey`, `spubkey`, `sprvkey`, `register_date`, `verified`, `blocked`, `timezone`, `service_class` )
+ VALUES ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, 'UTC', '%s' )",
dbesc(generate_user_guid()),
dbesc($username),
dbesc($new_password_encoded),
@@ -187,7 +192,8 @@ function create_user($arr) {
dbesc($sprvkey),
dbesc(datetime_convert()),
intval($verified),
- intval($blocked)
+ intval($blocked),
+ dbesc($default_service_class)
);
if($r) {