Boilerplate to use a Directus Instance to Build a Custom Website, Content will be Manage by Directus
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.

145 lines
2.5 KiB

5 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <?php
  2. /**
  3. * fake function for blade @inject
  4. *
  5. * @param string $class
  6. * @return object
  7. */
  8. function app($class)
  9. {
  10. return new $class();
  11. }
  12. /**
  13. * function similar to blade asset
  14. *
  15. * @param $path
  16. * @return string
  17. *
  18. */
  19. function asset($path, $prefix = '/public')
  20. {
  21. // get flight
  22. $app = Flight::app();
  23. // getting basePath
  24. $basePath = $app->get('basePath');
  25. // path to mix-manifest
  26. $file = $app->get('basePath').'mix-manifest.json';
  27. if (file_exists($file)) {
  28. $manifest = file_get_contents($file);
  29. $files = json_decode($manifest, true);
  30. if (isset($files[$prefix.$path])) {
  31. $path = str_replace($prefix, '', $files[$prefix.$path]);
  32. }
  33. }
  34. return $path;
  35. }
  36. /**
  37. * getting name of view as slug
  38. *
  39. * @param array $page
  40. * @return string
  41. *
  42. */
  43. function viewName(array $page)
  44. {
  45. $slugify = new \Cocur\Slugify\Slugify();
  46. return $slugify->slugify($page['data']['view']);
  47. }
  48. /**
  49. * getting name of view as slug
  50. *
  51. * @param array $page
  52. * @return string
  53. *
  54. */
  55. function canonical()
  56. {
  57. if (isset($_SERVER['HTTPS'])) {
  58. $canoncial = 'https';
  59. } else {
  60. $canoncial = 'http';
  61. }
  62. $canoncial .= '://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  63. return $canoncial;
  64. }
  65. /**
  66. * getting title for head
  67. *
  68. * @param array $page
  69. * @param array $site
  70. * @return string
  71. */
  72. function title($page, $site)
  73. {
  74. $title = [];
  75. if ($site['data']['title']) {
  76. $title[] = $site['data']['title'];
  77. }
  78. // if not homepage set page title first
  79. if ($page['data']['slug']) {
  80. array_unshift($title, $page['data']['title']);
  81. } else {
  82. $title[] = $page['data']['title'];
  83. }
  84. return join(' | ', $title);
  85. }
  86. /**
  87. * getting url for assets of directus api
  88. *
  89. * @param string string
  90. * @param array array
  91. * @return string
  92. *
  93. */
  94. function assetsUrl(string $id, array $options = NULL)
  95. {
  96. $query = NULL;
  97. if ($options) {
  98. $query = '?'.http_build_query($options);
  99. }
  100. return $_ENV['DIRECTUS_API_URL'].'/assets/'.$id.$query;
  101. }
  102. /**
  103. *
  104. *
  105. *
  106. */
  107. function isCurrentPage($slug, $class = 'current')
  108. {
  109. // parse current url
  110. $url = parse_url($_SERVER['REQUEST_URI']);
  111. // getting path, remove first "/""
  112. $path = ltrim($url['path'], '/');
  113. // parse empty in NULL
  114. // @TODO bad solution, check for using parent
  115. if (empty($path)) {
  116. $path = NULL;
  117. }
  118. if ($path !== $slug) {
  119. $class = NULL;
  120. }
  121. return $class;
  122. }