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.
 
 
 
 
 
 

82 lines
2.2 KiB

  1. <?php
  2. /**
  3. * @brief: Get info header of the scheme
  4. *
  5. * This function parses the header of the schemename.php file for informations like
  6. * Author, Description and Overwrites. Most of the code comes from the Addon::getInfo()
  7. * function. We use this to get the variables which get overwritten through the scheme.
  8. * All color variables which get overwritten through the theme have to be
  9. * listed (comma separated) in the scheme header under Overwrites:
  10. * This seems not to be the best solution. We need to investigate further.
  11. *
  12. * @param string $scheme Name of the scheme
  13. * @return array With theme information
  14. * 'author' => Author Name
  15. * 'description' => Scheme description
  16. * 'version' => Scheme version
  17. * 'overwrites' => Variables which overwriting custom settings
  18. */
  19. use Friendica\DI;
  20. use Friendica\Util\Strings;
  21. function get_scheme_info($scheme)
  22. {
  23. $theme = DI::app()->getCurrentTheme();
  24. $themepath = 'view/theme/' . $theme . '/';
  25. if (empty($scheme)) {
  26. $scheme = DI::pConfig()->get(local_user(), 'frio', 'scheme', DI::pConfig()->get(local_user(), 'frio', 'schema'));
  27. }
  28. $scheme = Strings::sanitizeFilePathItem($scheme);
  29. $info = [
  30. 'name' => $scheme,
  31. 'description' => '',
  32. 'author' => [],
  33. 'version' => '',
  34. 'overwrites' => []
  35. ];
  36. if (!is_file($themepath . 'scheme/' . $scheme . '.php')) return $info;
  37. $f = file_get_contents($themepath . 'scheme/' . $scheme . '.php');
  38. $r = preg_match('|/\*.*\*/|msU', $f, $m);
  39. if ($r) {
  40. $ll = explode("\n", $m[0]);
  41. foreach ($ll as $l) {
  42. $l = trim($l, "\t\n\r */");
  43. if ($l != '') {
  44. $values = array_map('trim', explode(':', $l, 2));
  45. if (count($values) < 2) {
  46. continue;
  47. }
  48. list($k, $v) = $values;
  49. $k = strtolower($k);
  50. if ($k == 'author') {
  51. $r = preg_match('|([^<]+)<([^>]+)>|', $v, $m);
  52. if ($r) {
  53. $info['author'][] = ['name' => $m[1], 'link' => $m[2]];
  54. } else {
  55. $info['author'][] = ['name' => $v];
  56. }
  57. } elseif ($k == 'overwrites') {
  58. $theme_settings = explode(',', str_replace(' ', '', $v));
  59. foreach ($theme_settings as $key => $value) {
  60. $info['overwrites'][$value] = true;
  61. }
  62. } else {
  63. if (array_key_exists($k, $info)) {
  64. $info[$k] = $v;
  65. }
  66. }
  67. }
  68. }
  69. }
  70. return $info;
  71. }