2011-08-02 01:51:01 +02:00
|
|
|
<?php
|
2017-12-04 14:33:49 +01:00
|
|
|
/**
|
|
|
|
* @file include/text.php
|
|
|
|
*/
|
2018-01-25 03:08:45 +01:00
|
|
|
|
2018-02-15 03:33:55 +01:00
|
|
|
use Friendica\Content\Text\BBCode;
|
2018-10-30 19:51:21 +01:00
|
|
|
use Friendica\Model\FileTag;
|
2011-08-02 01:51:01 +02:00
|
|
|
|
2013-03-27 10:11:40 +01:00
|
|
|
/**
|
|
|
|
* Compare activity uri. Knows about activity namespace.
|
2014-07-30 15:23:36 +02:00
|
|
|
*
|
2013-03-27 10:11:40 +01:00
|
|
|
* @param string $haystack
|
|
|
|
* @param string $needle
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2011-08-02 01:51:01 +02:00
|
|
|
function activity_match($haystack,$needle) {
|
2017-05-17 18:28:00 +02:00
|
|
|
return (($haystack === $needle) || ((basename($needle) === $haystack) && strstr($needle, NAMESPACE_ACTIVITY_SCHEMA)));
|
2017-11-11 07:42:39 +01:00
|
|
|
}
|
2011-08-02 01:51:01 +02:00
|
|
|
|
2012-09-20 09:46:49 +02:00
|
|
|
/**
|
2013-03-27 10:11:40 +01:00
|
|
|
* return array with details for categories and folders for an item
|
2014-07-30 15:23:36 +02:00
|
|
|
*
|
2013-03-27 10:11:40 +01:00
|
|
|
* @param array $item
|
|
|
|
* @return array
|
2014-07-30 15:23:36 +02:00
|
|
|
*
|
2013-03-27 10:11:40 +01:00
|
|
|
* [
|
|
|
|
* [ // categories array
|
2012-09-20 09:46:49 +02:00
|
|
|
* {
|
|
|
|
* 'name': 'category name',
|
2013-03-27 10:11:40 +01:00
|
|
|
* 'removeurl': 'url to remove this category',
|
|
|
|
* 'first': 'is the first in this array? true/false',
|
2012-09-20 09:46:49 +02:00
|
|
|
* 'last': 'is the last in this array? true/false',
|
|
|
|
* } ,
|
|
|
|
* ....
|
|
|
|
* ],
|
2013-03-27 10:11:40 +01:00
|
|
|
* [ //folders array
|
|
|
|
* {
|
2012-09-20 09:46:49 +02: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 15:23:36 +02:00
|
|
|
* ....
|
2012-09-20 09:46:49 +02:00
|
|
|
* ]
|
2013-03-27 10:11:40 +01:00
|
|
|
* ]
|
2012-09-20 09:46:49 +02:00
|
|
|
*/
|
2018-01-04 03:12:19 +01:00
|
|
|
function get_cats_and_terms($item)
|
|
|
|
{
|
2018-01-15 14:05:12 +01:00
|
|
|
$categories = [];
|
|
|
|
$folders = [];
|
2017-05-22 13:04:30 +02:00
|
|
|
$first = true;
|
2019-05-27 23:17:53 +02:00
|
|
|
|
2019-05-30 13:54:17 +02:00
|
|
|
foreach (FileTag::fileToArray($item['file'] ?? '', 'category') as $savedFolderName) {
|
2019-05-27 23:17:53 +02: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 02:56:36 +01:00
|
|
|
}
|
2014-07-30 15:23:36 +02:00
|
|
|
|
2017-05-17 18:28:00 +02:00
|
|
|
if (count($categories)) {
|
|
|
|
$categories[count($categories) - 1]['last'] = true;
|
|
|
|
}
|
2012-09-20 09:46:49 +02:00
|
|
|
|
2017-04-04 19:48:25 +02:00
|
|
|
if (local_user() == $item['uid']) {
|
2019-05-30 13:54:17 +02:00
|
|
|
foreach (FileTag::fileToArray($item['file'] ?? '') as $savedFolderName) {
|
2019-05-27 23:17:53 +02: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 02:56:36 +01:00
|
|
|
}
|
|
|
|
}
|
2012-09-20 09:46:49 +02:00
|
|
|
|
2017-05-17 18:28:00 +02:00
|
|
|
if (count($folders)) {
|
|
|
|
$folders[count($folders) - 1]['last'] = true;
|
|
|
|
}
|
2012-09-24 04:22:48 +02:00
|
|
|
|
2018-01-15 14:05:12 +01:00
|
|
|
return [$categories, $folders];
|
2012-09-20 09:46:49 +02:00
|
|
|
}
|
|
|
|
|
2018-05-13 22:50:09 +02:00
|
|
|
/// @TODO Rewrite this
|
2012-06-12 04:36:04 +02:00
|
|
|
function is_a_date_arg($s) {
|
|
|
|
$i = intval($s);
|
2018-05-13 22:50:09 +02:00
|
|
|
|
2017-04-04 19:48:25 +02:00
|
|
|
if ($i > 1900) {
|
2012-06-12 04:36:04 +02:00
|
|
|
$y = date('Y');
|
2018-05-13 22:50:09 +02:00
|
|
|
|
2017-05-17 18:28:00 +02:00
|
|
|
if ($i <= $y + 1 && strpos($s, '-') == 4) {
|
2017-01-26 16:01:56 +01:00
|
|
|
$m = intval(substr($s, 5));
|
2018-05-13 22:50:09 +02:00
|
|
|
|
2017-07-19 23:16:54 +02:00
|
|
|
if ($m > 0 && $m <= 12) {
|
2012-06-12 04:36:04 +02:00
|
|
|
return true;
|
2017-01-26 16:01:56 +01:00
|
|
|
}
|
2012-06-12 04:36:04 +02:00
|
|
|
}
|
|
|
|
}
|
2018-05-13 22:50:09 +02:00
|
|
|
|
2012-06-12 04:36:04 +02:00
|
|
|
return false;
|
|
|
|
}
|