Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

75 lines
1.8 KiB

  1. <?php
  2. /**
  3. * @file include/text.php
  4. */
  5. use Friendica\Model\FileTag;
  6. /**
  7. * return array with details for categories and folders for an item
  8. *
  9. * @param array $item
  10. * @return array
  11. *
  12. * [
  13. * [ // categories array
  14. * {
  15. * 'name': 'category name',
  16. * 'removeurl': 'url to remove this category',
  17. * 'first': 'is the first in this array? true/false',
  18. * 'last': 'is the last in this array? true/false',
  19. * } ,
  20. * ....
  21. * ],
  22. * [ //folders array
  23. * {
  24. * 'name': 'folder name',
  25. * 'removeurl': 'url to remove this folder',
  26. * 'first': 'is the first in this array? true/false',
  27. * 'last': 'is the last in this array? true/false',
  28. * } ,
  29. * ....
  30. * ]
  31. * ]
  32. */
  33. function get_cats_and_terms($item)
  34. {
  35. $categories = [];
  36. $folders = [];
  37. $first = true;
  38. foreach (FileTag::fileToArray($item['file'] ?? '', 'category') as $savedFolderName) {
  39. $categories[] = [
  40. 'name' => $savedFolderName,
  41. 'url' => "#",
  42. 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&cat=' . rawurlencode($savedFolderName) : ""),
  43. 'first' => $first,
  44. 'last' => false
  45. ];
  46. $first = false;
  47. }
  48. if (count($categories)) {
  49. $categories[count($categories) - 1]['last'] = true;
  50. }
  51. if (local_user() == $item['uid']) {
  52. foreach (FileTag::fileToArray($item['file'] ?? '') as $savedFolderName) {
  53. $folders[] = [
  54. 'name' => $savedFolderName,
  55. 'url' => "#",
  56. 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&term=' . rawurlencode($savedFolderName) : ""),
  57. 'first' => $first,
  58. 'last' => false
  59. ];
  60. $first = false;
  61. }
  62. }
  63. if (count($folders)) {
  64. $folders[count($folders) - 1]['last'] = true;
  65. }
  66. return [$categories, $folders];
  67. }