aboutsummaryrefslogtreecommitdiffstats
path: root/include/text.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/text.php')
-rw-r--r--include/text.php290
1 files changed, 141 insertions, 149 deletions
diff --git a/include/text.php b/include/text.php
index f4122845e..25743e872 100644
--- a/include/text.php
+++ b/include/text.php
@@ -454,63 +454,7 @@ function alt_pager(&$a, $i, $more = '', $less = '') {
}
-/**
- * @brief Turn user/group ACLs stored as angle bracketed text into arrays.
- *
- * turn string array of angle-bracketed elements into string array
- * e.g. "<123xyz><246qyo><sxo33e>" => array(123xyz,246qyo,sxo33e);
- *
- * @param string $s
- * @return array
- */
-function expand_acl($s) {
- $ret = array();
- if(strlen($s)) {
- $t = str_replace('<','',$s);
- $a = explode('>',$t);
- foreach($a as $aa) {
- if($aa)
- $ret[] = $aa;
- }
- }
-
- return $ret;
-}
-
-/**
- * @brief Used to wrap ACL elements in angle brackets for storage.
- *
- * @param[in,out] array &$item
- */
-function sanitise_acl(&$item) {
- if (strlen($item))
- $item = '<' . notags(trim($item)) . '>';
- else
- unset($item);
-}
-
-/**
- * @brief Convert an ACL array to a storable string.
- *
- * @param array $p
- * @return array
- */
-function perms2str($p) {
- $ret = '';
-
- if (is_array($p))
- $tmp = $p;
- else
- $tmp = explode(',', $p);
-
- if (is_array($tmp)) {
- array_walk($tmp, 'sanitise_acl');
- $ret = implode('', $tmp);
- }
-
- return $ret;
-}
/**
* @brief Generate a guaranteed unique (for this domain) item ID for ATOM.
@@ -575,9 +519,9 @@ function attribute_contains($attr, $s) {
}
/**
- * @brief Logging function for RedMatrix.
+ * @brief Logging function for Hubzilla.
*
- * Logging output is configured through RedMatrix's system config. The log file
+ * Logging output is configured through Hubzilla's system config. The log file
* is set in system logfile, log level in system loglevel and to enable logging
* set system debugging.
*
@@ -743,7 +687,7 @@ function get_tags($s) {
// make sure the longer tags are returned first so that if two or more have common substrings
// we'll replace the longest ones first. Otherwise the common substring would be found in
// both strings and the string replacement would link both to the shorter strings and
- // fail to link the longer string. RedMatrix github issue #378
+ // fail to link the longer string. Hubzilla github issue #378
usort($ret,'tag_sort_length');
@@ -808,20 +752,21 @@ function contact_block() {
return;
$is_owner = ((local_channel() && local_channel() == $a->profile['uid']) ? true : false);
+ $sql_extra = '';
+
+ $abook_flags = " and abook_pending = 0 and abook_self = 0 ";
- $abook_flags = ABOOK_FLAG_PENDING|ABOOK_FLAG_SELF;
- $xchan_flags = XCHAN_FLAGS_ORPHAN|XCHAN_FLAGS_DELETED;
if(! $is_owner) {
- $abook_flags = $abook_flags | ABOOK_FLAG_HIDDEN;
- $xchan_flags = $xchan_flags | XCHAN_FLAGS_HIDDEN;
+ $abook_flags .= " and abook_hidden = 0 ";
+ $sql_extra = " and xchan_hidden = 0 ";
}
if((! is_array($a->profile)) || ($a->profile['hide_friends']))
return $o;
- $r = q("SELECT COUNT(abook_id) AS total FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d and ( abook_flags & %d ) = 0 and ( xchan_flags & %d ) = 0",
- intval($a->profile['uid']),
- intval($abook_flags),
- intval($xchan_flags)
+
+ $r = q("SELECT COUNT(abook_id) AS total FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d
+ $abook_flags and xchan_orphan = 0 and xchan_deleted = 0 $sql_extra",
+ intval($a->profile['uid'])
);
if(count($r)) {
$total = intval($r[0]['total']);
@@ -830,21 +775,19 @@ function contact_block() {
$contacts = t('No connections');
$micropro = null;
} else {
-
+
$randfunc = db_getfunc('RAND');
-
- $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash WHERE abook_channel = %d AND ( abook_flags & %d ) = 0 and ( xchan_flags & %d ) = 0 ORDER BY $randfunc LIMIT %d",
- intval($a->profile['uid']),
- intval($abook_flags|ABOOK_FLAG_ARCHIVED),
- intval($xchan_flags),
- intval($shown)
+
+ $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash WHERE abook_channel = %d $abook_flags and abook_archived = 0 and xchan_orphan = 0 and xchan_deleted = 0 $sql_extra ORDER BY $randfunc LIMIT %d",
+ intval($a->profile['uid']),
+ intval($shown)
);
if(count($r)) {
$contacts = sprintf( tt('%d Connection','%d Connections', $total),$total);
$micropro = Array();
foreach($r as $rr) {
- $rr['archived'] = (($rr['abook_flags'] & ABOOK_FLAG_ARCHIVED) ? true : false);
+ $rr['archived'] = (intval($rr['abook_archived']) ? true : false);
$micropro[] = micropro($rr,true,'mpfriend');
}
}
@@ -1241,17 +1184,16 @@ function link_compare($a, $b) {
function unobscure(&$item) {
- if(array_key_exists('item_flags',$item) && ($item['item_flags'] & ITEM_OBSCURED)) {
+ if(array_key_exists('item_obscured',$item) && intval($item['item_obscured'])) {
$key = get_config('system','prvkey');
if($item['title'])
$item['title'] = crypto_unencapsulate(json_decode_plus($item['title']),$key);
if($item['body'])
$item['body'] = crypto_unencapsulate(json_decode_plus($item['body']),$key);
if(get_config('system','item_cache')) {
- q("update item set title = '%s', body = '%s', item_flags = %d where id = %d",
+ q("update item set title = '%s', body = '%s', item_obscured = 0 where id = %d",
dbesc($item['title']),
dbesc($item['body']),
- intval($item['item_flags'] - ITEM_OBSCURED),
intval($item['id'])
);
}
@@ -1259,12 +1201,11 @@ function unobscure(&$item) {
}
function unobscure_mail(&$item) {
- if(array_key_exists('mail_flags',$item) && ($item['mail_flags'] & MAIL_OBSCURED)) {
- $key = get_config('system','prvkey');
+ if(array_key_exists('mail_obscured',$item) && intval($item['mail_obscured'])) {
if($item['title'])
- $item['title'] = crypto_unencapsulate(json_decode_plus($item['title']),$key);
+ $item['title'] = base64url_decode(str_rot47($item['title']));
if($item['body'])
- $item['body'] = crypto_unencapsulate(json_decode_plus($item['body']),$key);
+ $item['body'] = base64url_decode(str_rot47($item['body']));
}
}
@@ -1275,36 +1216,15 @@ function theme_attachments(&$item) {
if(is_array($arr) && count($arr)) {
$attaches = array();
foreach($arr as $r) {
- $icon = '';
- $icontype = substr($r['type'],0,strpos($r['type'],'/'));
-
- /**
- * @FIXME This should probably be a giant "if" statement in the
- * template so that we don't have icon names embedded in php code.
- */
-
- switch($icontype) {
- case 'video':
- $icon = 'icon-facetime-video';
- break;
- case 'audio':
- $icon = 'icon-volume-up';
- break;
- case 'image':
- $icon = 'icon-picture';
- break;
- case 'text':
- $icon = 'icon-align-justify';
- break;
- default:
- $icon = 'icon-question';
- break;
- }
- $title = htmlspecialchars($r['title'], ENT_COMPAT,'UTF-8');
- if(! $title)
- $title = t('unknown.???');
- $title .= ' ' . $r['length'] . ' ' . t('bytes');
+ $icon = getIconFromType($r['type']);
+ $label = (($r['title']) ? urldecode(htmlspecialchars($r['title'], ENT_COMPAT, 'UTF-8')) : t('Unknown Attachment'));
+
+ //some feeds provide an attachment where title an empty space
+ if($label == ' ')
+ $label = t('Unknown Attachment');
+
+ $title = t('Attachment') . ' - ' . (($r['length']) ? userReadableSize($r['length']) : t('Size Unknown'));
require_once('include/identity.php');
if(is_foreigner($item['author_xchan']))
@@ -1312,14 +1232,14 @@ function theme_attachments(&$item) {
else
$url = z_root() . '/magic?f=&hash=' . $item['author_xchan'] . '&dest=' . $r['href'] . '/' . $r['revision'];
- $s .= '<a href="' . $url . '" title="' . $title . '" class="attachlink" >' . $icon . '</a>';
- $attaches[] = array('title' => $title, 'url' => $url, 'icon' => $icon );
+ //$s .= '<a href="' . $url . '" title="' . $title . '" class="attachlink" >' . $icon . '</a>';
+ $attaches[] = array('label' => $label, 'url' => $url, 'icon' => $icon, 'title' => $title);
}
- }
- $s = replace_macros(get_markup_template('item_attach.tpl'), array(
- '$attaches' => $attaches
- ));
+ $s = replace_macros(get_markup_template('item_attach.tpl'), array(
+ '$attaches' => $attaches
+ ));
+ }
return $s;
}
@@ -1338,11 +1258,12 @@ function format_categories(&$item,$writeable) {
$removelink = (($writeable) ? z_root() . '/filerm/' . $item['id'] . '?f=&cat=' . urlencode($t['term']) : '');
$categories[] = array('term' => $term, 'writeable' => $writeable, 'removelink' => $removelink, 'url' => zid($t['url']));
}
+
+ $s = replace_macros(get_markup_template('item_categories.tpl'),array(
+ '$remove' => t('remove category'),
+ '$categories' => $categories
+ ));
}
- $s = replace_macros(get_markup_template('item_categories.tpl'),array(
- '$remove' => t('remove category'),
- '$categories' => $categories
- ));
return $s;
}
@@ -1353,6 +1274,7 @@ function format_categories(&$item,$writeable) {
* @param[in] array &$item
* @return string HTML link of hashtag
*/
+
function format_hashtags(&$item) {
$s = '';
@@ -1413,11 +1335,12 @@ function format_filer(&$item) {
$removelink = z_root() . '/filerm/' . $item['id'] . '?f=&term=' . urlencode($t['term']);
$categories[] = array('term' => $term, 'removelink' => $removelink);
}
+
+ $s = replace_macros(get_markup_template('item_filer.tpl'),array(
+ '$remove' => t('remove from file'),
+ '$categories' => $categories
+ ));
}
- $s = replace_macros(get_markup_template('item_filer.tpl'),array(
- '$remove' => t('remove from file'),
- '$categories' => $categories
- ));
return $s;
}
@@ -1441,16 +1364,24 @@ function generate_named_map($location) {
function prepare_body(&$item,$attach = false) {
- call_hooks('prepare_body_init', $item);
-
- unobscure($item);
-
- $s = prepare_text($item['body'],$item['mimetype']);
+// if($item['html']) {
+// $s = bb_observer($item['html']);
+// }
+// else {
+ call_hooks('prepare_body_init', $item);
+// unobscure($item);
+ $s = prepare_text($item['body'],$item['mimetype'], false);
+// }
$prep_arr = array('item' => $item, 'html' => $s);
call_hooks('prepare_body', $prep_arr);
$s = $prep_arr['html'];
+// q("update item set html = '%s' where id = %d",
+// dbesc($s),
+// intval($item['id'])
+// );
+
if(! $attach) {
return $s;
}
@@ -1462,19 +1393,19 @@ function prepare_body(&$item,$attach = false) {
}
}
- $s .= theme_attachments($item);
+ $attachments = theme_attachments($item);
$writeable = ((get_observer_hash() == $item['owner_xchan']) ? true : false);
- $s .= format_hashtags($item);
+ $tags = format_hashtags($item);
if($item['resource_type'])
- $s .= format_mentions($item);
+ $mentions = format_mentions($item);
- $s .= format_categories($item,$writeable);
+ $categories = format_categories($item,$writeable);
if(local_channel() == $item['uid'])
- $s .= format_filer($item);
+ $filer = format_filer($item);
$s = sslify($s);
@@ -1507,10 +1438,19 @@ function prepare_body(&$item,$attach = false) {
$s = substr($s, 0, $pos).$authorreplace.substr($s, $pos+strlen($authorsearch));
}
- $prep_arr = array('item' => $item, 'html' => $s);
+ $prep_arr = array(
+ //'item' => $item,
+ 'html' => $s,
+ 'categories' => $categories,
+ 'folders' => $filer,
+ 'tags' => $tags,
+ 'mentions' => $mentions,
+ 'attachments' => $attachments
+ );
+
call_hooks('prepare_body_final', $prep_arr);
- return $prep_arr['html'];
+ return $prep_arr;
}
/**
@@ -1520,7 +1460,7 @@ function prepare_body(&$item,$attach = false) {
* @param sting $content_type
* @return string
*/
-function prepare_text($text, $content_type = 'text/bbcode') {
+function prepare_text($text, $content_type = 'text/bbcode', $cache = false) {
switch($content_type) {
case 'text/plain':
@@ -1558,9 +1498,9 @@ function prepare_text($text, $content_type = 'text/bbcode') {
require_once('include/bbcode.php');
if(stristr($text,'[nosmile]'))
- $s = bbcode($text);
+ $s = bbcode($text,false,true,$cache);
else
- $s = smilies(bbcode($text));
+ $s = smilies(bbcode($text,false,true,$cache));
$s = zidify_links($s);
break;
}
@@ -1672,9 +1612,9 @@ function unamp($s) {
}
function layout_select($channel_id, $current = '') {
- $r = q("select mid,sid from item left join item_id on iid = item.id where service = 'PDL' and item.uid = item_id.uid and item_id.uid = %d and (item_restrict & %d)>0",
+ $r = q("select mid,sid from item left join item_id on iid = item.id where service = 'PDL' and item.uid = item_id.uid and item_id.uid = %d and item_type = %d ",
intval($channel_id),
- intval(ITEM_PDL)
+ intval(ITEM_TYPE_PDL)
);
if($r) {
@@ -1738,14 +1678,14 @@ function mimetype_select($channel_id, $current = 'text/bbcode') {
function lang_selector() {
global $a;
- $langs = glob('view/*/strings.php');
+ $langs = glob('view/*/hstrings.php');
$lang_options = array();
$selected = "";
if(is_array($langs) && count($langs)) {
$langs[] = '';
- if(! in_array('view/en/strings.php',$langs))
+ if(! in_array('view/en/hstrings.php',$langs))
$langs[] = 'view/en/';
asort($langs);
foreach($langs as $l) {
@@ -2027,15 +1967,15 @@ function xchan_query(&$items,$abook = true,$effective_uid = 0) {
if(count($arr)) {
if($abook) {
$chans = q("select * from xchan left join hubloc on hubloc_hash = xchan_hash left join abook on abook_xchan = xchan_hash and abook_channel = %d
- where xchan_hash in (" . implode(',', $arr) . ") and ( hubloc_flags & " . intval(HUBLOC_FLAGS_PRIMARY) . " )>0",
+ where xchan_hash in (" . implode(',', $arr) . ") and hubloc_primary = 1",
intval($item['uid'])
);
}
else {
$chans = q("select xchan.*,hubloc.* from xchan left join hubloc on hubloc_hash = xchan_hash
- where xchan_hash in (" . implode(',', $arr) . ") and ( hubloc_flags & " . intval(HUBLOC_FLAGS_PRIMARY) . " )>0");
+ where xchan_hash in (" . implode(',', $arr) . ") and hubloc_primary = 1");
}
- $xchans = q("select * from xchan where xchan_hash in (" . implode(',',$arr) . ") and xchan_network in ('rss','unknown')");
+ $xchans = q("select * from xchan where xchan_hash in (" . protect_sprintf(implode(',',$arr)) . ") and xchan_network in ('rss','unknown')");
if(! $chans)
$chans = $xchans;
else
@@ -2061,7 +2001,7 @@ function xchan_mail_query(&$item) {
if(count($arr)) {
$chans = q("select xchan.*,hubloc.* from xchan left join hubloc on hubloc_hash = xchan_hash
- where xchan_hash in (" . implode(',', $arr) . ") and ( hubloc_flags & " . intval(HUBLOC_FLAGS_PRIMARY) . " )>0");
+ where xchan_hash in (" . implode(',', $arr) . ") and hubloc_primary = 1");
}
if($chans) {
$item['from'] = find_xchan_in_array($item['from_xchan'],$chans);
@@ -2273,7 +2213,7 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $d
}
if($tag == '#getzot') {
$basetag = 'getzot';
- $url = 'https://redmatrix.me';
+ $url = 'http://hubzilla.org';
$newtag = '#[zrl=' . $url . ']' . $basetag . '[/zrl]';
$body = str_replace($tag,$newtag,$body);
$replaced = true;
@@ -2542,6 +2482,7 @@ function linkify_tags($a, &$body, $uid, $diaspora = false) {
*
* @param string $type mime type
* @return string
+ * @todo rename to get_icon_from_type()
*/
function getIconFromType($type) {
$iconMap = array(
@@ -2594,6 +2535,7 @@ function getIconFromType($type) {
*
* @param int $size filesize in bytes
* @return string human readable formatted filesize
+ * @todo rename to user_readable_size()
*/
function userReadableSize($size) {
$ret = '';
@@ -2610,3 +2552,53 @@ function userReadableSize($size) {
return $ret;
}
+
+function str_rot47($str) {
+ return strtr($str,
+ '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~',
+ 'PQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO');
+}
+
+
+function string_replace($old,$new,&$s) {
+
+ $x = str_replace($old,$new,$s);
+ $replaced = false;
+ if($x !== $s) {
+ $replaced = true;
+ }
+ $s = $x;
+ return $replaced;
+}
+
+
+function json_url_replace($old,$new,&$s) {
+
+ $old = str_replace('/','\\/',$old);
+ $new = str_replace('/','\\/',$new);
+
+ $x = str_replace($old,$new,$s);
+ $replaced = false;
+ if($x !== $s) {
+ $replaced = true;
+ }
+ $s = $x;
+ return $replaced;
+}
+
+
+function item_url_replace($channel,&$item,$old,$new) {
+
+ if($item['attach'])
+ json_url_replace($old,$new,$item['attach']);
+ if($item['object'])
+ json_url_replace($old,$new,$item['object']);
+ if($item['target'])
+ json_url_replace($old,$new,$item['target']);
+
+ if(string_replace($old,$new,$item['body'])) {
+ $item['sig'] = base64url_encode(rsa_sign($item['body'],$channel['channel_prvkey']));
+ $item['item_verified'] = 1;
+ }
+
+}