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.
 
 
 
 
 
 

80 lines
2.0 KiB

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