list.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * scientia
  4. *
  5. * Copyright 2022 - 2024 Johannes Keßler
  6. *
  7. * https://www.bananas-playground.net/projekt/scientia/
  8. *
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
  12. *
  13. * You should have received a copy of the
  14. * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
  15. * along with this program. If not, see http://www.sun.com/cddl/cddl.html
  16. */
  17. $TemplateData['entries'] = array();
  18. $queryStr = "SELECT e.ident, e.date, e.words, SUBSTRING(e.body,1,100) AS body FROM `".DB_PREFIX."_entry` AS e";
  19. $queryLimit = " LIMIT 100";
  20. $searchTerm = '';
  21. if(isset($_POST['submitForm']) && isset($_POST['searchInput'])) {
  22. if(Summoner::validate($_POST['searchInput'])) {
  23. $searchTerm = trim($_POST['searchInput']);
  24. }
  25. }
  26. // why?
  27. // mysql knows the dates and validates them. There is no 2020-02-31
  28. // the single date infos come from index.php
  29. $_groupByFormat = $_year;
  30. $breadcrumb = array('Y');
  31. if(!empty($_requestDateProvided)) {
  32. $_intervalStart = '';
  33. $_intervalEnd = '';
  34. if($_requestDateProvided === 'Y-m-d') {
  35. $queryLimit = "";
  36. $_groupByFormat = $_year.'-'.$_month.'-'.$_day;
  37. $_intervalStart = $_groupByFormat;
  38. $_intervalEnd = $_groupByFormat;
  39. $breadcrumb = array('Y','m','d');
  40. }
  41. elseif ($_requestDateProvided === 'Y-m') {
  42. $queryLimit = "";
  43. $_groupByFormat = $_year.'-'.$_month;
  44. $_intervalStart = $_groupByFormat.'-01';
  45. $_tDate = new DateTime( $_intervalStart );
  46. $_monthDays = $_tDate->format( 't' );
  47. $_intervalEnd = $_groupByFormat.'-'.$_monthDays;
  48. $breadcrumb = array('Y','m');
  49. }
  50. elseif ($_requestDateProvided === 'Y') {
  51. $_intervalStart = $_groupByFormat.'-01-01';
  52. $_intervalEnd = $_groupByFormat.'-12-31';
  53. }
  54. if(!empty($_intervalStart) && !empty($_intervalEnd)) {
  55. $queryStr .= " WHERE e.date >= '".$_intervalStart."' AND e.date <= '".$_intervalEnd."'";
  56. if(!empty($searchTerm)) {
  57. $queryStr .= " AND MATCH(e.words) AGAINST('".$DB->real_escape_string($searchTerm)."' IN BOOLEAN MODE)";
  58. }
  59. }
  60. } else {
  61. $_requestDateProvided = 'Y';
  62. if(!empty($searchTerm)) {
  63. $queryStr .= " WHERE MATCH(e.words) AGAINST('".$DB->real_escape_string($searchTerm)."' IN BOOLEAN MODE)";
  64. }
  65. }
  66. $queryStr .= " ORDER BY `created` DESC";
  67. $queryStr .= $queryLimit;
  68. if(QUERY_DEBUG) error_log("[QUERY] query: ".var_export($queryStr,true));
  69. try {
  70. $query = $DB->query($queryStr);
  71. if($query !== false && $query->num_rows > 0) {
  72. while(($result = $query->fetch_assoc()) != false) {
  73. $_d = new DateTime($result['date']);
  74. $_breadcrumb = array();
  75. foreach($breadcrumb as $_b) {
  76. $_breadcrumb[] = $_d->format($_b);
  77. }
  78. $TemplateData['entries'][$_d->format($_requestDateProvided)]['breadcrumb'] = $_breadcrumb;
  79. $TemplateData['entries'][$_d->format($_requestDateProvided)]['e'][$result['ident']] = $result;
  80. $TemplateData['entries'][$_d->format($_requestDateProvided)]['e'][$result['ident']]['link'] = str_replace('-','/',$result['date']).'/'.$result['ident'];
  81. }
  82. }
  83. }
  84. catch(Exception $e) {
  85. error_log("[ERROR] catch: ".$e->getMessage());
  86. }