mostly filebased Content Presentation System
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

tableofcontents.php 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. namespace Modules;
  3. class TableOfContents {
  4. private $selector;
  5. private $folder;
  6. private $caller_dir;
  7. private $body;
  8. private $elements = array();
  9. function __construct($configuration,$caller_dir,$body) {
  10. $f3 = \Base::instance();
  11. //var_dump($configuration);echo "<br>";
  12. if(is_array($configuration)) {
  13. $this->selector = array_shift($configuration);
  14. $folder = array_shift($configuration);
  15. $this->folder = strncmp("/",$folder,1)
  16. ? $caller_dir.$folder
  17. : $f3->get('CONTENT').substr($folder,1);
  18. if (substr_compare($this->folder,"/",-1,1)) {
  19. $this->folder .= "/";
  20. }
  21. }
  22. $this->caller_dir = $caller_dir;
  23. $this->body = is_array($body) ? $body : array($body);
  24. if(!$this->body) {
  25. $this->body = null;
  26. }
  27. $this->prepare_elements();
  28. }
  29. // function __toString() {
  30. // return $this->selector.":".$this->folder."\n".implode("\n",$this->body);
  31. //}
  32. function prepare_elements() {
  33. if(is_dir($this->folder)) {
  34. $ls=scandir($this->folder);
  35. if (count($this->body)) {
  36. foreach ($this->body as $f) {
  37. if (in_array($f,$ls)
  38. && is_dir($this->folder.$f)) {
  39. $this->elements[$this->folder.$f."/"] = true;
  40. }
  41. }
  42. } else {
  43. foreach($ls as $k=>$f) {
  44. if (!strncmp($f,'.',1)) continue;
  45. if (!is_dir($this->folder.$f)) continue;
  46. $this->elements[$this->folder.$f."/"] = true;
  47. }
  48. }
  49. }
  50. foreach ($this->elements as $key=>$value) {
  51. $folder = new FilesInFolders($key);
  52. $folder->prepare_files();
  53. $this->elements[$key] = $folder->read_config();
  54. }
  55. }
  56. function dispatch() {
  57. switch ($this->selector) {
  58. case 'event_view':
  59. $this->event_list();
  60. break;
  61. case 'locations_view':
  62. $this->location_list();
  63. break;
  64. }
  65. }
  66. function get_location_large() {
  67. foreach($this->elements as $key=>$e) {
  68. $this->elements[$key] = self::location_large($e,$key);
  69. }
  70. return array_shift($this->elements);
  71. }
  72. function get_location_medium() {
  73. foreach($this->elements as $key=>$e) {
  74. $this->elements[$key] = self::location_medium($e,$key);
  75. }
  76. return array_shift($this->elements);
  77. }
  78. function get_location_small() {
  79. foreach($this->elements as $key=>$e) {
  80. $this->elements[$key] = self::location_small($e,$key);
  81. }
  82. return array_shift($this->elements);
  83. }
  84. function location_list() {
  85. foreach($this->elements as $key=>$e) {
  86. $this->elements[$key] = self::location_large($e,$key);
  87. }
  88. }
  89. function location_large($e,$key) {
  90. $f3 = \Base::instance();
  91. $town = $e['TOWN'];
  92. $name = $e['NAME'];
  93. $href = $f3->get('SITE_URL').str_replace($f3->get('CONTENT'),"",$key);
  94. return sprintf("<div class=\"location\">"
  95. ."<a href=\"/$href\"><h3 class=\"venue-name\">$name</h3></a>"
  96. ."<span class\"address\">$town</span>"
  97. ."</div>");
  98. }
  99. function location_medium($e,$key) {
  100. $f3 = \Base::instance();
  101. $town = $e['TOWN'];
  102. $name = $e['NAME'];
  103. $href = $f3->get('SITE_URL').str_replace($f3->get('CONTENT'),"",$key);
  104. return sprintf("<div class=\"location\">"
  105. ."<a href=\"/$href\"><span class=\"town\">$town</span><br>"
  106. ."<span class\"venue-name\">$name</span></a>"
  107. ."</div>");
  108. }
  109. function location_small($e,$key) {
  110. $f3 = \Base::instance();
  111. $town = $e['TOWN'];
  112. $name = $e['NAME'];
  113. $href = $f3->get('SITE_URL').str_replace($f3->get('CONTENT'),"",$key);
  114. return sprintf("<div class=\"location\">"
  115. ."<a href=\"/$href\"><span class=\"town\">$town</span>"
  116. ."<span class\"venue-name\">$name</span></a>"
  117. ."</div>");
  118. }
  119. function event_list() {
  120. $f3 = \Base::instance();
  121. foreach ($this->elements as $key=>$entry) {
  122. $DATE = strtotime($entry['DATE']);
  123. $date = sprintf("<span class=\"month\">%s</span><br>"
  124. ."<span class=\"day-of-month\">%s</span>",
  125. date('M',$DATE),
  126. date('d',$DATE));
  127. $href = $f3->get('SITE_URL').str_replace($f3->get('CONTENT'),"",$key);
  128. $title = $entry['TITLE'];
  129. $description = $entry['DESCRIPTION'];
  130. $time = sprintf("<span class=\"weekday\">%s</span>, <span class=\"time\">%s</span>",
  131. date('l',$DATE),
  132. $entry['TIME']);
  133. $loc = $entry['LOCATION'];
  134. $loc->set_layout("humble_two_liner");
  135. $location = $loc;#is_object($loc) ? $loc->get_location_medium() : $loc;
  136. $this->elements[$key] = sprintf("<tr><td class=\"date\">%s</td><td>%s</td><td>%s</td></tr>",
  137. $date,
  138. sprintf("<h3>%s</h3><span>%s</span><footer>%s</footer>",
  139. sprintf("<a href=\"/%s\">%s</a>",
  140. $href,
  141. $title
  142. ),
  143. $description,
  144. $time
  145. ),
  146. $location
  147. );
  148. }
  149. }
  150. function as_string() {
  151. return sprintf("<table class=\"TOC\">%s</table>", implode("\n",$this->elements));
  152. }
  153. }