friendica/include/text.php

129 lines
2.9 KiB
PHP
Raw Normal View History

<?php
/**
* @file include/text.php
*/
use Friendica\Content\Text\BBCode;
use Friendica\Model\FileTag;
2013-03-27 09:11:40 +00:00
/**
* Compare activity uri. Knows about activity namespace.
*
2013-03-27 09:11:40 +00:00
* @param string $haystack
* @param string $needle
* @return boolean
*/
function activity_match($haystack,$needle) {
return (($haystack === $needle) || ((basename($needle) === $haystack) && strstr($needle, NAMESPACE_ACTIVITY_SCHEMA)));
}
2013-03-27 09:11:40 +00:00
/**
* quick and dirty quoted_printable encoding
*
2013-03-27 09:11:40 +00:00
* @param string $s
* @return string
*/
function qp($s) {
return str_replace("%", "=", rawurlencode($s));
}
2013-03-27 09:11:40 +00:00
/**
* @brief Given a text string, convert from bbcode to html and add smilie icons.
*
* @param string $text String with bbcode.
2019-06-20 23:31:47 +00:00
* @return string Formatted HTML
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
2013-03-27 09:11:40 +00:00
*/
function prepare_text($text)
{
$s = BBCode::convert($text);
return trim($s);
}
2013-03-27 09:11:40 +00:00
/**
2013-03-27 09:11:40 +00:00
* return array with details for categories and folders for an item
*
2013-03-27 09:11:40 +00:00
* @param array $item
* @return array
*
2013-03-27 09:11:40 +00:00
* [
* [ // categories array
* {
* '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',
* 'last': 'is the last in this array? true/false',
* } ,
* ....
* ],
2013-03-27 09:11:40 +00:00
* [ //folders array
* {
* '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',
* } ,
* ....
* ]
2013-03-27 09:11:40 +00:00
* ]
*/
function get_cats_and_terms($item)
{
$categories = [];
$folders = [];
$first = true;
2019-05-30 11:54:17 +00:00
foreach (FileTag::fileToArray($item['file'] ?? '', 'category') as $savedFolderName) {
$categories[] = [
'name' => $savedFolderName,
'url' => "#",
'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&cat=' . rawurlencode($savedFolderName) : ""),
'first' => $first,
'last' => false
];
$first = false;
}
if (count($categories)) {
$categories[count($categories) - 1]['last'] = true;
}
if (local_user() == $item['uid']) {
2019-05-30 11:54:17 +00:00
foreach (FileTag::fileToArray($item['file'] ?? '') as $savedFolderName) {
$folders[] = [
'name' => $savedFolderName,
'url' => "#",
'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&term=' . rawurlencode($savedFolderName) : ""),
'first' => $first,
'last' => false
];
$first = false;
}
}
if (count($folders)) {
$folders[count($folders) - 1]['last'] = true;
}
return [$categories, $folders];
}
/// @TODO Rewrite this
function is_a_date_arg($s) {
$i = intval($s);
if ($i > 1900) {
$y = date('Y');
if ($i <= $y + 1 && strpos($s, '-') == 4) {
$m = intval(substr($s, 5));
if ($m > 0 && $m <= 12) {
return true;
}
}
}
return false;
}