2011-08-01 23:51:01 +00:00
|
|
|
<?php
|
2017-12-04 13:33:49 +00:00
|
|
|
/**
|
|
|
|
* @file include/text.php
|
|
|
|
*/
|
2018-01-25 02:08:45 +00:00
|
|
|
|
2018-02-15 02:33:55 +00:00
|
|
|
use Friendica\Content\Text\BBCode;
|
2018-10-30 18:51:21 +00:00
|
|
|
use Friendica\Model\FileTag;
|
2019-07-15 01:48:35 +00:00
|
|
|
use Friendica\Model\Group;
|
2018-11-08 15:14:37 +00:00
|
|
|
use Friendica\Util\Strings;
|
2018-10-29 20:10:35 +00:00
|
|
|
|
2013-03-27 09:11:40 +00:00
|
|
|
/**
|
2014-07-30 13:23:36 +00:00
|
|
|
* Wrap ACL elements in angle brackets for storage
|
2013-03-27 09:11:40 +00:00
|
|
|
* @param string $item
|
|
|
|
*/
|
2011-08-01 23:51:01 +00:00
|
|
|
function sanitise_acl(&$item) {
|
2017-05-17 16:42:40 +00:00
|
|
|
if (intval($item)) {
|
2018-11-09 18:29:42 +00:00
|
|
|
$item = '<' . intval(Strings::escapeTags(trim($item))) . '>';
|
2019-07-15 01:48:35 +00:00
|
|
|
} elseif (in_array($item, [Group::FOLLOWERS, Group::MUTUALS])) {
|
|
|
|
$item = '<' . $item . '>';
|
2017-05-17 16:42:40 +00:00
|
|
|
} else {
|
2011-08-01 23:51:01 +00:00
|
|
|
unset($item);
|
2017-05-17 16:42:40 +00:00
|
|
|
}
|
2017-11-11 06:42:39 +00:00
|
|
|
}
|
2011-08-01 23:51:01 +00:00
|
|
|
|
|
|
|
|
2013-03-27 09:11:40 +00:00
|
|
|
/**
|
|
|
|
* Convert an ACL array to a storable string
|
2014-07-30 13:23:36 +00:00
|
|
|
*
|
2013-03-27 09:11:40 +00:00
|
|
|
* Normally ACL permissions will be an array.
|
|
|
|
* We'll also allow a comma-separated string.
|
2014-07-30 13:23:36 +00:00
|
|
|
*
|
2013-03-27 09:11:40 +00:00
|
|
|
* @param string|array $p
|
|
|
|
* @return string
|
|
|
|
*/
|
2011-08-01 23:51:01 +00:00
|
|
|
function perms2str($p) {
|
|
|
|
$ret = '';
|
2017-05-17 16:42:40 +00:00
|
|
|
if (is_array($p)) {
|
2012-11-11 21:56:21 +00:00
|
|
|
$tmp = $p;
|
2017-05-17 16:42:40 +00:00
|
|
|
} else {
|
2017-01-26 15:07:30 +00:00
|
|
|
$tmp = explode(',', $p);
|
2017-05-17 16:42:40 +00:00
|
|
|
}
|
2012-11-11 21:56:21 +00:00
|
|
|
|
2017-04-04 17:48:25 +00:00
|
|
|
if (is_array($tmp)) {
|
2017-05-22 11:04:30 +00:00
|
|
|
array_walk($tmp, 'sanitise_acl');
|
|
|
|
$ret = implode('', $tmp);
|
2011-08-01 23:51:01 +00:00
|
|
|
}
|
|
|
|
return $ret;
|
2017-11-11 06:42:39 +00:00
|
|
|
}
|
2011-08-01 23:51:01 +00:00
|
|
|
|
2013-03-27 09:11:40 +00:00
|
|
|
/**
|
|
|
|
* Compare activity uri. Knows about activity namespace.
|
2014-07-30 13:23:36 +00:00
|
|
|
*
|
2013-03-27 09:11:40 +00:00
|
|
|
* @param string $haystack
|
|
|
|
* @param string $needle
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2011-08-01 23:51:01 +00:00
|
|
|
function activity_match($haystack,$needle) {
|
2017-05-17 16:28:00 +00:00
|
|
|
return (($haystack === $needle) || ((basename($needle) === $haystack) && strstr($needle, NAMESPACE_ACTIVITY_SCHEMA)));
|
2017-11-11 06:42:39 +00:00
|
|
|
}
|
2011-08-01 23:51:01 +00:00
|
|
|
|
2013-03-27 09:11:40 +00:00
|
|
|
/**
|
|
|
|
* quick and dirty quoted_printable encoding
|
2014-07-30 13:23:36 +00:00
|
|
|
*
|
2013-03-27 09:11:40 +00:00
|
|
|
* @param string $s
|
|
|
|
* @return string
|
2014-07-30 13:23:36 +00:00
|
|
|
*/
|
2011-08-01 23:51:01 +00:00
|
|
|
function qp($s) {
|
2017-05-17 16:28:00 +00:00
|
|
|
return str_replace("%", "=", rawurlencode($s));
|
2017-11-11 06:42:39 +00:00
|
|
|
}
|
|
|
|
|
2013-03-27 09:11:40 +00:00
|
|
|
/**
|
2017-10-13 17:42:27 +00:00
|
|
|
* @brief Given a text string, convert from bbcode to html and add smilie icons.
|
2014-07-30 13:23:36 +00:00
|
|
|
*
|
2017-10-13 17:42:27 +00:00
|
|
|
* @param string $text String with bbcode.
|
2019-06-20 23:31:47 +00:00
|
|
|
* @return string Formatted HTML
|
2019-01-07 15:24:06 +00:00
|
|
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
2013-03-27 09:11:40 +00:00
|
|
|
*/
|
2019-06-20 19:00:33 +00:00
|
|
|
function prepare_text($text)
|
|
|
|
{
|
|
|
|
$s = BBCode::convert($text);
|
2014-09-07 13:48:44 +00:00
|
|
|
return trim($s);
|
2017-10-13 17:42:27 +00:00
|
|
|
}
|
2013-03-27 09:11:40 +00:00
|
|
|
|
2012-09-20 07:46:49 +00:00
|
|
|
/**
|
2013-03-27 09:11:40 +00:00
|
|
|
* return array with details for categories and folders for an item
|
2014-07-30 13:23:36 +00:00
|
|
|
*
|
2013-03-27 09:11:40 +00:00
|
|
|
* @param array $item
|
|
|
|
* @return array
|
2014-07-30 13:23:36 +00:00
|
|
|
*
|
2013-03-27 09:11:40 +00:00
|
|
|
* [
|
|
|
|
* [ // categories array
|
2012-09-20 07:46:49 +00:00
|
|
|
* {
|
|
|
|
* 'name': 'category name',
|
2013-03-27 09:11:40 +00:00
|
|
|
* 'removeurl': 'url to remove this category',
|
|
|
|
* 'first': 'is the first in this array? true/false',
|
2012-09-20 07:46:49 +00:00
|
|
|
* 'last': 'is the last in this array? true/false',
|
|
|
|
* } ,
|
|
|
|
* ....
|
|
|
|
* ],
|
2013-03-27 09:11:40 +00:00
|
|
|
* [ //folders array
|
|
|
|
* {
|
2012-09-20 07:46:49 +00:00
|
|
|
* 'name': 'folder name',
|
|
|
|
* 'removeurl': 'url to remove this folder',
|
|
|
|
* 'first': 'is the first in this array? true/false',
|
|
|
|
* 'last': 'is the last in this array? true/false',
|
|
|
|
* } ,
|
2014-07-30 13:23:36 +00:00
|
|
|
* ....
|
2012-09-20 07:46:49 +00:00
|
|
|
* ]
|
2013-03-27 09:11:40 +00:00
|
|
|
* ]
|
2012-09-20 07:46:49 +00:00
|
|
|
*/
|
2018-01-04 02:12:19 +00:00
|
|
|
function get_cats_and_terms($item)
|
|
|
|
{
|
2018-01-15 13:05:12 +00:00
|
|
|
$categories = [];
|
|
|
|
$folders = [];
|
2017-05-22 11:04:30 +00:00
|
|
|
$first = true;
|
2019-05-27 21:17:53 +00:00
|
|
|
|
2019-05-30 11:54:17 +00:00
|
|
|
foreach (FileTag::fileToArray($item['file'] ?? '', 'category') as $savedFolderName) {
|
2019-05-27 21:17:53 +00:00
|
|
|
$categories[] = [
|
|
|
|
'name' => $savedFolderName,
|
|
|
|
'url' => "#",
|
|
|
|
'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&cat=' . rawurlencode($savedFolderName) : ""),
|
|
|
|
'first' => $first,
|
|
|
|
'last' => false
|
|
|
|
];
|
|
|
|
$first = false;
|
2015-11-28 01:56:36 +00:00
|
|
|
}
|
2014-07-30 13:23:36 +00:00
|
|
|
|
2017-05-17 16:28:00 +00:00
|
|
|
if (count($categories)) {
|
|
|
|
$categories[count($categories) - 1]['last'] = true;
|
|
|
|
}
|
2012-09-20 07:46:49 +00:00
|
|
|
|
2017-04-04 17:48:25 +00:00
|
|
|
if (local_user() == $item['uid']) {
|
2019-05-30 11:54:17 +00:00
|
|
|
foreach (FileTag::fileToArray($item['file'] ?? '') as $savedFolderName) {
|
2019-05-27 21:17:53 +00:00
|
|
|
$folders[] = [
|
|
|
|
'name' => $savedFolderName,
|
|
|
|
'url' => "#",
|
|
|
|
'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&term=' . rawurlencode($savedFolderName) : ""),
|
|
|
|
'first' => $first,
|
|
|
|
'last' => false
|
|
|
|
];
|
|
|
|
$first = false;
|
2015-11-28 01:56:36 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-20 07:46:49 +00:00
|
|
|
|
2017-05-17 16:28:00 +00:00
|
|
|
if (count($folders)) {
|
|
|
|
$folders[count($folders) - 1]['last'] = true;
|
|
|
|
}
|
2012-09-24 02:22:48 +00:00
|
|
|
|
2018-01-15 13:05:12 +00:00
|
|
|
return [$categories, $folders];
|
2012-09-20 07:46:49 +00:00
|
|
|
}
|
|
|
|
|
2018-05-13 20:50:09 +00:00
|
|
|
/// @TODO Rewrite this
|
2012-06-12 02:36:04 +00:00
|
|
|
function is_a_date_arg($s) {
|
|
|
|
$i = intval($s);
|
2018-05-13 20:50:09 +00:00
|
|
|
|
2017-04-04 17:48:25 +00:00
|
|
|
if ($i > 1900) {
|
2012-06-12 02:36:04 +00:00
|
|
|
$y = date('Y');
|
2018-05-13 20:50:09 +00:00
|
|
|
|
2017-05-17 16:28:00 +00:00
|
|
|
if ($i <= $y + 1 && strpos($s, '-') == 4) {
|
2017-01-26 15:01:56 +00:00
|
|
|
$m = intval(substr($s, 5));
|
2018-05-13 20:50:09 +00:00
|
|
|
|
2017-07-19 21:16:54 +00:00
|
|
|
if ($m > 0 && $m <= 12) {
|
2012-06-12 02:36:04 +00:00
|
|
|
return true;
|
2017-01-26 15:01:56 +00:00
|
|
|
}
|
2012-06-12 02:36:04 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-13 20:50:09 +00:00
|
|
|
|
2012-06-12 02:36:04 +00:00
|
|
|
return false;
|
|
|
|
}
|