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.

75 lines
1.3 KiB

5 years ago
4 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. }