diff options
Diffstat (limited to 'include/text.php')
-rw-r--r-- | include/text.php | 196 |
1 files changed, 97 insertions, 99 deletions
diff --git a/include/text.php b/include/text.php index f4122845e..205736502 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'])); } } @@ -1304,7 +1245,7 @@ function theme_attachments(&$item) { $title = htmlspecialchars($r['title'], ENT_COMPAT,'UTF-8'); if(! $title) $title = t('unknown.???'); - $title .= ' ' . $r['length'] . ' ' . t('bytes'); + $title .= ' ' . (($r['length']) ? $r['length'] . ' ' . t('bytes') : ''); require_once('include/identity.php'); if(is_foreigner($item['author_xchan'])) @@ -1441,16 +1382,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; } @@ -1509,7 +1458,6 @@ function prepare_body(&$item,$attach = false) { $prep_arr = array('item' => $item, 'html' => $s); call_hooks('prepare_body_final', $prep_arr); - return $prep_arr['html']; } @@ -1520,7 +1468,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 +1506,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 +1620,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 +1686,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,13 +1975,13 @@ 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')"); if(! $chans) @@ -2061,7 +2009,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); @@ -2610,3 +2558,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; + } + +}
\ No newline at end of file |