Merge branch 'origin' into 'develop'
marge from origin 4.0 See merge request harukin/core!40
This commit is contained in:
463
include/text.php
463
include/text.php
@@ -3,8 +3,11 @@
|
||||
* @file include/text.php
|
||||
*/
|
||||
|
||||
use \Zotlabs\Lib as Zlib;
|
||||
use \Michelf\MarkdownExtra;
|
||||
use Zotlabs\Lib as Zlib;
|
||||
|
||||
use Michelf\MarkdownExtra;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
|
||||
|
||||
require_once("include/bbcode.php");
|
||||
|
||||
@@ -38,12 +41,12 @@ function replace_macros($s, $r) {
|
||||
|
||||
$t = App::template_engine();
|
||||
|
||||
try {
|
||||
$output = $t->replace_macros($arr['template'], $arr['params']);
|
||||
} catch (Exception $e) {
|
||||
logger("Unable to render template: ".$e->getMessage());
|
||||
$output = "<h3>ERROR: there was an error creating the output.</h3>";
|
||||
}
|
||||
try {
|
||||
$output = $t->replace_macros($arr['template'], $arr['params']);
|
||||
} catch (Exception $e) {
|
||||
logger('Unable to render template: ' . $e->getMessage());
|
||||
$output = '<h3>ERROR: there was an error creating the output.</h3>';
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
@@ -536,7 +539,14 @@ function paginate(&$a) {
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param int $i
|
||||
* @param string $more
|
||||
* @param string $less
|
||||
* @return string Parsed HTML from template 'alt_pager.tpl'
|
||||
*/
|
||||
function alt_pager($i, $more = '', $less = '') {
|
||||
|
||||
if(! $more)
|
||||
@@ -571,18 +581,9 @@ function alt_pager($i, $more = '', $less = '') {
|
||||
* @return string a unique id
|
||||
*/
|
||||
function item_message_id() {
|
||||
do {
|
||||
$dups = false;
|
||||
$hash = random_string();
|
||||
$mid = $hash . '@' . App::get_hostname();
|
||||
|
||||
$r = q("SELECT id FROM item WHERE mid = '%s' LIMIT 1",
|
||||
dbesc($mid));
|
||||
if($r)
|
||||
$dups = true;
|
||||
} while($dups == true);
|
||||
return new_uuid();
|
||||
|
||||
return $mid;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -593,17 +594,9 @@ function item_message_id() {
|
||||
* @return string a uniqe hash
|
||||
*/
|
||||
function photo_new_resource() {
|
||||
do {
|
||||
$found = false;
|
||||
$resource = hash('md5', uniqid(mt_rand(), true));
|
||||
|
||||
$r = q("SELECT id FROM photo WHERE resource_id = '%s' LIMIT 1",
|
||||
dbesc($resource));
|
||||
if($r)
|
||||
$found = true;
|
||||
} while($found === true);
|
||||
return new_uuid();
|
||||
|
||||
return $resource;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -824,7 +817,7 @@ function activity_match($haystack,$needle) {
|
||||
* and strip the period from any tags which end with one.
|
||||
*
|
||||
* @param string $s
|
||||
* @return Returns array of tags found, or empty array.
|
||||
* @return array Returns an array of tags found, or empty array.
|
||||
*/
|
||||
function get_tags($s) {
|
||||
$ret = array();
|
||||
@@ -840,6 +833,9 @@ function get_tags($s) {
|
||||
// ignore anything in [color= ], because it may contain color codes which are mistaken for tags
|
||||
$s = preg_replace('/\[color=(.*?)\]/sm','',$s);
|
||||
|
||||
// skip anchors in URL
|
||||
$s = preg_replace('/\[url=(.*?)\]/sm','',$s);
|
||||
|
||||
// match any double quoted tags
|
||||
|
||||
if(preg_match_all('/([@#\!]\"\;.*?\"\;)/',$s,$match)) {
|
||||
@@ -911,6 +907,7 @@ function tag_sort_length($a,$b) {
|
||||
function total_sort($a,$b) {
|
||||
if($a['total'] == $b['total'])
|
||||
return 0;
|
||||
|
||||
return(($b['total'] > $a['total']) ? 1 : (-1));
|
||||
}
|
||||
|
||||
@@ -997,7 +994,7 @@ function contact_block() {
|
||||
|
||||
// There is no setting to discover if you are bi-directionally connected
|
||||
// Use the ability to post comments as an indication that this relationship is more
|
||||
// than wishful thinking; even though soapbox channels and feeds will disable it.
|
||||
// than wishful thinking; even though soapbox channels and feeds will disable it.
|
||||
|
||||
if(! intval(get_abconfig(App::$profile['uid'],$rr['xchan_hash'],'their_perms','post_comments'))) {
|
||||
$rr['oneway'] = true;
|
||||
@@ -1015,9 +1012,15 @@ function contact_block() {
|
||||
'$micropro' => $micropro,
|
||||
));
|
||||
|
||||
$arr = array('contacts' => $r, 'output' => $o);
|
||||
|
||||
$arr = ['contacts' => $r, 'output' => $o];
|
||||
/**
|
||||
* @hooks contact_block_end
|
||||
* Called at the end of contact_block(), but can not manipulate the output.
|
||||
* * \e array \b contacts - Result array from database
|
||||
* * \e string \b output - the generated output
|
||||
*/
|
||||
call_hooks('contact_block_end', $arr);
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
@@ -1104,7 +1107,7 @@ function searchbox($s,$id='search-box',$url='/search',$save = false) {
|
||||
* @return string
|
||||
*/
|
||||
function linkify($s, $me = false) {
|
||||
$s = preg_replace("/(https?\:\/\/[a-zA-Z0-9\pL\:\/\-\?\&\;\.\=\_\@\~\#\'\%\$\!\+\,\@]*)/u", (($me) ? ' <a href="$1" rel="me" >$1</a>' : ' <a href="$1" >$1</a>'), $s);
|
||||
$s = preg_replace("/(https?\:\/\/[a-zA-Z0-9\pL\:\/\-\?\&\;\.\=\_\@\~\#\'\%\$\!\+\,\@]*)/u", (($me) ? ' <a href="$1" rel="me nofollow" >$1</a>' : ' <a href="$1" >$1</a>'), $s);
|
||||
$s = preg_replace("/\<(.*?)(src|href)=(.*?)\&\;(.*?)\>/ism",'<$1$2=$3&$4>',$s);
|
||||
|
||||
return($s);
|
||||
@@ -1122,6 +1125,21 @@ function linkify($s, $me = false) {
|
||||
* @returns string
|
||||
*/
|
||||
function sslify($s) {
|
||||
|
||||
// Local photo cache
|
||||
$str = [
|
||||
'body' => $s,
|
||||
'uid' => local_channel()
|
||||
];
|
||||
/**
|
||||
* @hooks cache_body_hook
|
||||
* * \e string \b body The content to parse and also the return value
|
||||
* * \e int|bool \b uid
|
||||
*/
|
||||
call_hooks('cache_body_hook', $str);
|
||||
|
||||
$s = $str['body'];
|
||||
|
||||
if (strpos(z_root(),'https:') === false)
|
||||
return $s;
|
||||
|
||||
@@ -1131,11 +1149,10 @@ function sslify($s) {
|
||||
// Complain to your browser maker
|
||||
|
||||
$allow = get_config('system','sslify_everything');
|
||||
|
||||
$pattern = (($allow) ? "/\<(.*?)src=\"(http\:.*?)\"(.*?)\>/" : "/\<img(.*?)src=\"(http\:.*?)\"(.*?)\>/" );
|
||||
$pattern = (($allow) ? "/\<(.*?)src=[\"|'](http\:.*?)[\"|'](.*?)\>/" : "/\<img(.*?)src=[\"|'](http\:.*?)[\"|'](.*?)\>/" );
|
||||
|
||||
$matches = null;
|
||||
$cnt = preg_match_all($pattern,$s,$matches,PREG_SET_ORDER);
|
||||
$cnt = preg_match_all($pattern, $s, $matches, PREG_SET_ORDER);
|
||||
if ($cnt) {
|
||||
foreach ($matches as $match) {
|
||||
$filename = basename( parse_url($match[2], PHP_URL_PATH) );
|
||||
@@ -1223,7 +1240,11 @@ function get_mood_verbs() {
|
||||
/**
|
||||
* @brief Function to list all smilies, both internal and from addons.
|
||||
*
|
||||
* @return Returns array with keys 'texts' and 'icons'
|
||||
* @param boolean $default_only (optional) default false
|
||||
* true will prevent that plugins can add smilies
|
||||
* @return array Returns an associative array with:
|
||||
* * \e array \b texts
|
||||
* * \e array \b icons
|
||||
*/
|
||||
function list_smilies($default_only = false) {
|
||||
|
||||
@@ -1309,6 +1330,11 @@ function list_smilies($default_only = false) {
|
||||
if($default_only)
|
||||
return $params;
|
||||
|
||||
/**
|
||||
* @hooks smile
|
||||
* * \e array \b texts - default values and also return value
|
||||
* * \e array \b icons - default values and also return value
|
||||
*/
|
||||
call_hooks('smilie', $params);
|
||||
|
||||
return $params;
|
||||
@@ -1464,7 +1490,7 @@ function theme_attachments(&$item) {
|
||||
foreach($arr as $r) {
|
||||
|
||||
$icon = getIconFromType($r['type']);
|
||||
|
||||
|
||||
if($r['title'])
|
||||
$label = urldecode(htmlspecialchars($r['title'], ENT_COMPAT, 'UTF-8'));
|
||||
|
||||
@@ -1634,6 +1660,10 @@ function generate_named_map($location) {
|
||||
|
||||
function prepare_body(&$item,$attach = false,$opts = false) {
|
||||
|
||||
/**
|
||||
* @hooks prepare_body_init
|
||||
* * \e array \b item
|
||||
*/
|
||||
call_hooks('prepare_body_init', $item);
|
||||
|
||||
$s = '';
|
||||
@@ -1660,18 +1690,29 @@ function prepare_body(&$item,$attach = false,$opts = false) {
|
||||
$s .= prepare_binary($item);
|
||||
}
|
||||
else {
|
||||
$s .= prepare_text($item['body'],$item['mimetype'], $opts);
|
||||
if($item['summary']) {
|
||||
$s .= prepare_text('[summary]' . $item['summary'] . '[/summary]' . $item['body'],$item['mimetype'],$opts);
|
||||
}
|
||||
else {
|
||||
$s .= prepare_text($item['body'],$item['mimetype'], $opts);
|
||||
}
|
||||
}
|
||||
|
||||
$event = (($item['obj_type'] === ACTIVITY_OBJ_EVENT) ? format_event_obj($item['obj']) : false);
|
||||
|
||||
$prep_arr = array(
|
||||
$prep_arr = [
|
||||
'item' => $item,
|
||||
'html' => $event ? $event['content'] : $s,
|
||||
'event' => $event['header'],
|
||||
'photo' => $photo
|
||||
);
|
||||
|
||||
];
|
||||
/**
|
||||
* @hooks prepare_body
|
||||
* * \e array \b item
|
||||
* * \e string \b html - the parsed HTML to return
|
||||
* * \e string \b event - the event header to return
|
||||
* * \e string \b photo - the photo to return
|
||||
*/
|
||||
call_hooks('prepare_body', $prep_arr);
|
||||
|
||||
$s = $prep_arr['html'];
|
||||
@@ -1703,7 +1744,14 @@ function prepare_body(&$item,$attach = false,$opts = false) {
|
||||
if(local_channel() == $item['uid'])
|
||||
$filer = format_filer($item);
|
||||
|
||||
$s = sslify($s);
|
||||
if($s)
|
||||
$s = sslify($s);
|
||||
|
||||
if($photo)
|
||||
$photo = sslify($photo);
|
||||
|
||||
if($event)
|
||||
$event = sslify($event);
|
||||
|
||||
$prep_arr = array(
|
||||
'item' => $item,
|
||||
@@ -1734,17 +1782,24 @@ function prepare_binary($item) {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Given a text string, convert from bbcode to html and add smilie icons.
|
||||
* @brief Given a text string, convert from content_type to HTML.
|
||||
*
|
||||
* Take a text in plain text, html, markdown, bbcode, PDL or PHP and prepare
|
||||
* it to return HTML.
|
||||
*
|
||||
* In bbcode this function will add smilie icons.
|
||||
*
|
||||
* @param string $text
|
||||
* @param string $content_type (optional) default text/bbcode
|
||||
* @param boolean $cache (optional) default false
|
||||
*
|
||||
* @param string $content_type (optional)
|
||||
* default 'text/bbcode', other values are 'text/plain', 'text/html',
|
||||
* 'text/markdown', 'application/x-pdl', 'application/x-php'
|
||||
* @param boolean|array $opts (optional)
|
||||
* default false, otherwise configuration array for bbcode()
|
||||
* @return string
|
||||
* The parsed $text as prepared HTML.
|
||||
*/
|
||||
function prepare_text($text, $content_type = 'text/bbcode', $opts = false) {
|
||||
|
||||
|
||||
switch($content_type) {
|
||||
case 'text/plain':
|
||||
$s = escape_tags($text);
|
||||
@@ -1784,8 +1839,8 @@ function prepare_text($text, $content_type = 'text/bbcode', $opts = false) {
|
||||
default:
|
||||
require_once('include/bbcode.php');
|
||||
|
||||
if(stristr($text,'[nosmile]'))
|
||||
$s = bbcode($text, [ 'cache' => $cache ]);
|
||||
if(stristr($text, '[nosmile]'))
|
||||
$s = bbcode($text, ((is_array($opts)) ? $opts : [] ));
|
||||
else
|
||||
$s = smilies(bbcode($text, ((is_array($opts)) ? $opts : [] )));
|
||||
|
||||
@@ -2145,7 +2200,7 @@ function legal_webbie($s) {
|
||||
return '';
|
||||
|
||||
// WARNING: This regex may not work in a federated environment.
|
||||
// You will probably want something like
|
||||
// You will probably want something like
|
||||
// preg_replace('/([^a-z0-9\_])/','',strtolower($s));
|
||||
|
||||
$r = preg_replace('/([^a-z0-9\-\_])/','',strtolower($s));
|
||||
@@ -2244,19 +2299,24 @@ function ids_to_querystr($arr,$idx = 'id',$quote = false) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief array_elm_to_str($arr,$elm,$delim = ',') extract unique individual elements from an array of arrays and return them as a string separated by a delimiter
|
||||
* similar to ids_to_querystr, but allows a different delimiter instead of a db-quote option
|
||||
* empty elements (evaluated after trim()) are ignored.
|
||||
* @param $arr array
|
||||
* @param $elm array key to extract from sub-array
|
||||
* @param $delim string default ','
|
||||
* @param $each filter function to apply to each element before evaluation, default is 'trim'.
|
||||
* @brief Extract unique individual elements from an array of arrays and return
|
||||
* them as a string separated by a delimiter.
|
||||
*
|
||||
* Similar to ids_to_querystr, but allows a different delimiter instead of a
|
||||
* db-quote option empty elements (evaluated after trim()) are ignored.
|
||||
*
|
||||
* @see ids_to_querystr()
|
||||
*
|
||||
* @param array $arr
|
||||
* @param string $elm key to extract from sub-array
|
||||
* @param string $delim (optional) default ','
|
||||
* @param string $each (optional) default is 'trim'
|
||||
* Filter function to apply to each element before evaluation.
|
||||
* @returns string
|
||||
*/
|
||||
|
||||
function array_elm_to_str($arr,$elm,$delim = ',',$each = 'trim') {
|
||||
|
||||
function array_elm_to_str($arr, $elm, $delim = ',', $each = 'trim') {
|
||||
$tmp = [];
|
||||
|
||||
if($arr && is_array($arr)) {
|
||||
foreach($arr as $x) {
|
||||
if(is_array($x) && array_key_exists($elm,$x)) {
|
||||
@@ -2267,7 +2327,8 @@ function array_elm_to_str($arr,$elm,$delim = ',',$each = 'trim') {
|
||||
}
|
||||
}
|
||||
}
|
||||
return implode($delim,$tmp);
|
||||
|
||||
return implode($delim, $tmp);
|
||||
}
|
||||
|
||||
function trim_and_unpunify($s) {
|
||||
@@ -2491,9 +2552,9 @@ function design_tools() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Creates website portation tools menu
|
||||
* @brief Creates website portation tools menu.
|
||||
*
|
||||
* @return string
|
||||
* @return string Parsed HTML code from template 'website_portation_tools.tpl'
|
||||
*/
|
||||
function website_portation_tools() {
|
||||
|
||||
@@ -2506,7 +2567,7 @@ function website_portation_tools() {
|
||||
$sys = true;
|
||||
}
|
||||
|
||||
return replace_macros(get_markup_template('website_portation_tools.tpl'), array(
|
||||
return replace_macros(get_markup_template('website_portation_tools.tpl'), [
|
||||
'$title' => t('Import'),
|
||||
'$import_label' => t('Import website...'),
|
||||
'$import_placeholder' => t('Select folder to import'),
|
||||
@@ -2523,7 +2584,7 @@ function website_portation_tools() {
|
||||
'$cloud_export_desc' => t('/path/to/export/folder'),
|
||||
'$cloud_export_hint' => t('Enter a path to a cloud files destination.'),
|
||||
'$cloud_export_select' => t('Specify folder'),
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2583,8 +2644,9 @@ function extra_query_args() {
|
||||
* @param boolean $in_network default true
|
||||
* @return boolean true if replaced, false if not replaced
|
||||
*/
|
||||
function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $in_network = true) {
|
||||
function handle_tag(&$body, &$str_tags, $profile_uid, $tag, $in_network = true) {
|
||||
|
||||
$channel = App::get_channel();
|
||||
$replaced = false;
|
||||
$r = null;
|
||||
$match = array();
|
||||
@@ -2640,21 +2702,20 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
|
||||
|
||||
$str_tags .= $newtag;
|
||||
}
|
||||
return [
|
||||
'replaced' => $replaced,
|
||||
'termtype' => $termtype,
|
||||
'term' => $basetag,
|
||||
'url' => $url,
|
||||
'contact' => []
|
||||
];
|
||||
|
||||
return [ [
|
||||
'replaced' => $replaced,
|
||||
'termtype' => $termtype,
|
||||
'term' => $basetag,
|
||||
'url' => $url,
|
||||
'contact' => [],
|
||||
'access_tag' => '',
|
||||
]];
|
||||
}
|
||||
|
||||
// END hashtags
|
||||
|
||||
// BEGIN mentions
|
||||
|
||||
|
||||
if ( in_array($termtype, [ TERM_MENTION, TERM_FORUM ] )) {
|
||||
|
||||
// The @! tag and !! tag will alter permissions
|
||||
@@ -2665,13 +2726,13 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
|
||||
$exclusive = (((strpos(substr($tag,1), '!') === 0) && $in_network) ? true : false);
|
||||
|
||||
//is it already replaced?
|
||||
if(strpos($tag,'[zrl=') || strpos($tag,'[url='))
|
||||
if(strpos($tag,"[zrl=") || strpos($tag,"[url="))
|
||||
return $replaced;
|
||||
|
||||
// get the channel name
|
||||
// First extract the name or name fragment we are going to replace
|
||||
|
||||
$name = substr($tag,(($exclusive) ? 2 : 1));
|
||||
$name = substr($tag,(($exclusive) ? 2 : 1));
|
||||
$newname = $name; // make a copy that we can mess with
|
||||
$tagcid = 0;
|
||||
|
||||
@@ -2683,7 +2744,7 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
|
||||
$newname = substr($name,1);
|
||||
$newname = substr($newname,0,-1);
|
||||
|
||||
$r = q("select * from xchan where xchan_addr = '%s' or xchan_url = '%s' limit 1",
|
||||
$r = q("select * from xchan where xchan_addr = '%s' or xchan_url = '%s'",
|
||||
dbesc($newname),
|
||||
dbesc($newname)
|
||||
);
|
||||
@@ -2706,7 +2767,7 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
|
||||
// select someone from this user's contacts by name
|
||||
|
||||
$r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash
|
||||
WHERE xchan_name = '%s' AND abook_channel = %d LIMIT 1",
|
||||
WHERE xchan_name = '%s' AND abook_channel = %d ",
|
||||
dbesc($newname),
|
||||
intval($profile_uid)
|
||||
);
|
||||
@@ -2714,8 +2775,8 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
|
||||
// select anybody by full hubloc_addr
|
||||
|
||||
if((! $r) && strpos($newname,'@')) {
|
||||
$r = q("SELECT * FROM xchan left join hubloc on xchan_hash = hubloc_hash
|
||||
WHERE hubloc_addr = '%s' LIMIT 1",
|
||||
$r = q("SELECT * FROM xchan left join hubloc on xchan_hash = hubloc_hash
|
||||
WHERE hubloc_addr = '%s' ",
|
||||
dbesc($newname)
|
||||
);
|
||||
}
|
||||
@@ -2724,7 +2785,7 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
|
||||
|
||||
if(! $r) {
|
||||
$r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash
|
||||
WHERE xchan_addr like ('%s') AND abook_channel = %d LIMIT 1",
|
||||
WHERE xchan_addr like ('%s') AND abook_channel = %d ",
|
||||
dbesc(((strpos($newname,'@')) ? $newname : $newname . '@%')),
|
||||
intval($profile_uid)
|
||||
);
|
||||
@@ -2732,17 +2793,62 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$fn_results = [];
|
||||
$access_tag = EMPTY_STR;
|
||||
|
||||
|
||||
// $r is set if we found something
|
||||
|
||||
$channel = App::get_channel();
|
||||
|
||||
if($r) {
|
||||
$profile = $r[0]['xchan_url'];
|
||||
$newname = $r[0]['xchan_name'];
|
||||
// add the channel's xchan_hash to $access_tag if exclusive
|
||||
if($exclusive) {
|
||||
$access_tag .= 'cid:' . $r[0]['xchan_hash'];
|
||||
foreach($r as $xc) {
|
||||
$profile = $xc['xchan_url'];
|
||||
$newname = $xc['xchan_name'];
|
||||
// add the channel's xchan_hash to $access_tag if exclusive
|
||||
if($exclusive) {
|
||||
$access_tag = 'cid:' . $xc['xchan_hash'];
|
||||
}
|
||||
|
||||
// if there is a url for this channel
|
||||
|
||||
if(isset($profile)) {
|
||||
$replaced = true;
|
||||
//create profile link
|
||||
$profile = str_replace(',','%2c',$profile);
|
||||
$url = $profile;
|
||||
if($termtype === TERM_FORUM) {
|
||||
$newtag = '!' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]';
|
||||
$body = str_replace('!' . (($exclusive) ? '!' : '') . $name, $newtag, $body);
|
||||
}
|
||||
else {
|
||||
// ( $termtype === TERM_MENTION )
|
||||
$newtag = '@' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]';
|
||||
$body = str_replace('@' . (($exclusive) ? '!' : '') . $name, $newtag, $body);
|
||||
}
|
||||
|
||||
// append tag to str_tags
|
||||
if(! stristr($str_tags,$newtag)) {
|
||||
if(strlen($str_tags))
|
||||
$str_tags .= ',';
|
||||
$str_tags .= $newtag;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$fn_results[] = [
|
||||
'replaced' => $replaced,
|
||||
'termtype' => $termtype,
|
||||
'term' => $newname,
|
||||
'url' => $url,
|
||||
'access_tag' => $access_tag,
|
||||
'contact' => (($r) ? $xc : []),
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -2754,7 +2860,6 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
|
||||
// weird - as all the other tags are linked to something.
|
||||
|
||||
if(local_channel() && local_channel() == $profile_uid) {
|
||||
require_once('include/group.php');
|
||||
$grp = group_byname($profile_uid,$name);
|
||||
|
||||
if($grp) {
|
||||
@@ -2771,58 +2876,62 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if there is a url for this channel
|
||||
|
||||
if(isset($profile)) {
|
||||
$replaced = true;
|
||||
//create profile link
|
||||
$profile = str_replace(',','%2c',$profile);
|
||||
$url = $profile;
|
||||
if($termtype === TERM_FORUM) {
|
||||
$newtag = '!' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]';
|
||||
$body = str_replace('!' . (($exclusive) ? '!' : '') . $name, $newtag, $body);
|
||||
}
|
||||
else {
|
||||
// ( $termtype === TERM_MENTION )
|
||||
$newtag = '@' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]';
|
||||
$body = str_replace('@' . (($exclusive) ? '!' : '') . $name, $newtag, $body);
|
||||
// if there is a url for this channel
|
||||
|
||||
if(isset($profile)) {
|
||||
$replaced = true;
|
||||
//create profile link
|
||||
$profile = str_replace(',','%2c',$profile);
|
||||
$url = $profile;
|
||||
if($termtype === TERM_FORUM) {
|
||||
$newtag = '!' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]';
|
||||
$body = str_replace('!' . (($exclusive) ? '!' : '') . $name, $newtag, $body);
|
||||
}
|
||||
else {
|
||||
// ( $termtype === TERM_MENTION )
|
||||
$newtag = '@' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]';
|
||||
$body = str_replace('@' . (($exclusive) ? '!' : '') . $name, $newtag, $body);
|
||||
}
|
||||
|
||||
// append tag to str_tags
|
||||
if(! stristr($str_tags,$newtag)) {
|
||||
if(strlen($str_tags))
|
||||
$str_tags .= ',';
|
||||
$str_tags .= $newtag;
|
||||
}
|
||||
}
|
||||
|
||||
// append tag to str_tags
|
||||
if(! stristr($str_tags,$newtag)) {
|
||||
if(strlen($str_tags))
|
||||
$str_tags .= ',';
|
||||
$str_tags .= $newtag;
|
||||
}
|
||||
$fn_results[] = [
|
||||
'replaced' => $replaced,
|
||||
'termtype' => $termtype,
|
||||
'term' => $newname,
|
||||
'url' => $url,
|
||||
'access_tag' => $access_tag,
|
||||
'contact' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $fn_results;
|
||||
|
||||
return [
|
||||
'replaced' => $replaced,
|
||||
'termtype' => $termtype,
|
||||
'term' => $newname,
|
||||
'url' => $url,
|
||||
'contact' => (($r) ? $r[0] : [])
|
||||
];
|
||||
}
|
||||
|
||||
function linkify_tags($a, &$body, $uid, $in_network = true) {
|
||||
function linkify_tags(&$body, $uid, $in_network = true) {
|
||||
$str_tags = EMPTY_STR;
|
||||
$tagged = [];
|
||||
$results = [];
|
||||
|
||||
$tags = get_tags($body);
|
||||
|
||||
if(count($tags)) {
|
||||
foreach($tags as $tag) {
|
||||
$access_tag = '';
|
||||
|
||||
$success = handle_tag($a, $body, $access_tag, $str_tags, ($uid) ? $uid : App::$profile_uid , $tag, $in_network);
|
||||
$success = handle_tag($body, $str_tags, ($uid) ? $uid : App::$profile_uid , $tag, $in_network);
|
||||
|
||||
$results[] = array('success' => $success, 'access_tag' => $access_tag);
|
||||
if($success['replaced']) $tagged[] = $tag;
|
||||
foreach($success as $handled_tag) {
|
||||
$results[] = [ 'success' => $handled_tag ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2880,7 +2989,7 @@ function getIconFromType($type) {
|
||||
'video/x-matroska' => 'fa-file-video-o'
|
||||
);
|
||||
|
||||
$catMap = [
|
||||
$catMap = [
|
||||
'application' => 'fa-file-code-o',
|
||||
'multipart' => 'fa-folder',
|
||||
'audio' => 'fa-file-audio-o',
|
||||
@@ -2888,7 +2997,7 @@ function getIconFromType($type) {
|
||||
'text' => 'fa-file-text-o',
|
||||
'image' => 'fa=file-picture-o',
|
||||
'message' => 'fa-file-text-o'
|
||||
];
|
||||
];
|
||||
|
||||
|
||||
$iconFromType = '';
|
||||
@@ -2898,7 +3007,7 @@ function getIconFromType($type) {
|
||||
}
|
||||
else {
|
||||
$parts = explode('/',$type);
|
||||
if($parts[0] && $catMap[$parts[0]]) {
|
||||
if($parts[0] && $catMap[$parts[0]]) {
|
||||
$iconFromType = $catMap[$parts[0]];
|
||||
}
|
||||
}
|
||||
@@ -2986,9 +3095,9 @@ function item_url_replace($channel,&$item,$old,$new,$oldnick = '') {
|
||||
json_url_replace('/' . $oldnick . '/' ,'/' . $channel['channel_address'] . '/' ,$item['target']);
|
||||
}
|
||||
|
||||
$x = preg_replace("/".preg_quote($old,'/')."\/(search|\w+\/".$channel['channel_address'].")/", $new.'/${1}', $item['body']);
|
||||
if($x) {
|
||||
$item['body'] = $x;
|
||||
$x = preg_replace("/".preg_quote($old,'/')."\/(search|\w+\/".$channel['channel_address'].")/", $new.'/${1}', $item['body']);
|
||||
if($x) {
|
||||
$item['body'] = $x;
|
||||
$item['sig'] = base64url_encode(rsa_sign($item['body'],$channel['channel_prvkey']));
|
||||
$item['item_verified'] = 1;
|
||||
}
|
||||
@@ -3098,7 +3207,13 @@ function pdl_selector($uid, $current='') {
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
$arr = array('channel_id' => $uid, 'current' => $current, 'entries' => $r);
|
||||
$arr = ['channel_id' => $uid, 'current' => $current, 'entries' => $r];
|
||||
/**
|
||||
* @hooks pdl_selector
|
||||
* * \e int \b channel_id
|
||||
* * \e string \b current
|
||||
* * \e array \b entries - Result from database query
|
||||
*/
|
||||
call_hooks('pdl_selector', $arr);
|
||||
|
||||
$entries = $arr['entries'];
|
||||
@@ -3139,7 +3254,7 @@ function flatten_array_recursive($arr) {
|
||||
$ret = array_merge($ret, $tmp);
|
||||
}
|
||||
}
|
||||
elseif($a) {
|
||||
elseif(isset($a)) {
|
||||
$ret[] = $a;
|
||||
}
|
||||
}
|
||||
@@ -3154,7 +3269,7 @@ function flatten_array_recursive($arr) {
|
||||
* @param string $lang Which language should be highlighted
|
||||
* @return string
|
||||
* Important: The returned text has the text pattern 'http' translated to '%eY9-!' which should be converted back
|
||||
* after further processing. This was done to prevent oembed links from occurring inside code blocks.
|
||||
* after further processing. This was done to prevent oembed links from occurring inside code blocks.
|
||||
* See include/bbcode.php
|
||||
*/
|
||||
function text_highlight($s, $lang) {
|
||||
@@ -3173,7 +3288,6 @@ function text_highlight($s, $lang) {
|
||||
'language' => $lang,
|
||||
'success' => false
|
||||
];
|
||||
|
||||
/**
|
||||
* @hooks text_highlight
|
||||
* * \e string \b text
|
||||
@@ -3225,28 +3339,6 @@ function array2XML($obj, $array) {
|
||||
}
|
||||
}
|
||||
|
||||
function array_path_exists($str,$arr) {
|
||||
|
||||
$ptr = $arr;
|
||||
$search = explode('/', $str);
|
||||
|
||||
if($search) {
|
||||
foreach($search as $s) {
|
||||
if(array_key_exists($s,$ptr)) {
|
||||
$ptr = $ptr[$s];
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Inserts an array into $table.
|
||||
*
|
||||
@@ -3396,13 +3488,17 @@ function punify($s) {
|
||||
|
||||
}
|
||||
|
||||
// Be aware that unpunify will only convert domain names and not pathnames
|
||||
|
||||
/**
|
||||
* Be aware that unpunify() will only convert domain names and not pathnames.
|
||||
*
|
||||
* @param string $s
|
||||
* @return string
|
||||
*/
|
||||
function unpunify($s) {
|
||||
require_once('vendor/simplepie/simplepie/idn/idna_convert.class.php');
|
||||
$x = new idna_convert(['encoding' => 'utf8']);
|
||||
return $x->decode($s);
|
||||
|
||||
return $x->decode($s);
|
||||
}
|
||||
|
||||
|
||||
@@ -3410,7 +3506,7 @@ function unique_multidim_array($array, $key) {
|
||||
$temp_array = array();
|
||||
$i = 0;
|
||||
$key_array = array();
|
||||
|
||||
|
||||
foreach($array as $val) {
|
||||
if (!in_array($val[$key], $key_array)) {
|
||||
$key_array[$i] = $val[$key];
|
||||
@@ -3438,7 +3534,7 @@ function get_forum_channels($uid) {
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
if($x2) {
|
||||
if($x2) {
|
||||
$xf = ids_to_querystr($x2,'xchan',true);
|
||||
|
||||
// private forums
|
||||
@@ -3451,7 +3547,7 @@ function get_forum_channels($uid) {
|
||||
}
|
||||
}
|
||||
|
||||
$sql_extra = (($xf) ? " and ( xchan_hash in (" . $xf . ") or xchan_pubforum = 1 ) " : " and xchan_pubforum = 1 ");
|
||||
$sql_extra = (($xf) ? " and ( xchan_hash in (" . $xf . ") or xchan_pubforum = 1 ) " : " and xchan_pubforum = 1 ");
|
||||
|
||||
$r = q("select abook_id, xchan_hash, xchan_name, xchan_url, xchan_addr, xchan_photo_s from abook left join xchan on abook_xchan = xchan_hash where xchan_deleted = 0 and abook_channel = %d and abook_pending = 0 and abook_ignored = 0 and abook_blocked = 0 and abook_archived = 0 $sql_extra order by xchan_name",
|
||||
intval($uid)
|
||||
@@ -3487,14 +3583,14 @@ function print_array($arr, $level = 0) {
|
||||
$o .= $tabs . '[' . $k . '] => ' . print_array($v, $level + 1) . "\n";
|
||||
}
|
||||
else {
|
||||
$o .= $tabs . '[' . $k . '] => ' . print_val($v) . ",\n";
|
||||
$o .= $tabs . '[' . $k . '] => ' . print_val($v) . ",\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
$o .= substr($tabs,0,-1) . ']' . (($level) ? ',' : ';' ). "\n";
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function print_val($v) {
|
||||
@@ -3509,3 +3605,40 @@ function print_val($v) {
|
||||
|
||||
}
|
||||
|
||||
function array_path_exists($str,$arr) {
|
||||
|
||||
$ptr = $arr;
|
||||
$search = explode('/', $str);
|
||||
|
||||
if($search) {
|
||||
foreach($search as $s) {
|
||||
if(array_key_exists($s,$ptr)) {
|
||||
$ptr = $ptr[$s];
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Generate a unique ID.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function new_uuid() {
|
||||
|
||||
try {
|
||||
$hash = Uuid::uuid4()->toString();
|
||||
} catch (UnsatisfiedDependencyException $e) {
|
||||
$hash = random_string(48);
|
||||
}
|
||||
|
||||
return $hash;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user