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.

56 lines
1.4 KiB

  1. <?php
  2. function ajax_customCategory ($param) {
  3. global $db;
  4. if (!$db) {
  5. return null;
  6. }
  7. if ($param['id']) {
  8. $stmt = $db->prepare("select content from customCategory where id=:id");
  9. $stmt->bindValue(':id', $param['id'], PDO::PARAM_STR);
  10. if ($stmt->execute()) {
  11. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  12. $result = $row['content'];
  13. $stmt->closeCursor();
  14. customCategoryUpdateAccess($param['id']);
  15. return $result;
  16. }
  17. return false;
  18. }
  19. if ($param['content']) {
  20. $id = md5($param['content']);
  21. $stmt = $db->prepare("insert or ignore into customCategory (id, content) values (:id, :content)");
  22. $stmt->bindValue(':id', $id, PDO::PARAM_STR);
  23. $stmt->bindValue(':content', $param['content'], PDO::PARAM_STR);
  24. $result = $stmt->execute();
  25. customCategoryUpdateAccess($id);
  26. return $result;
  27. }
  28. }
  29. function customCategoryUpdateAccess ($id) {
  30. global $db;
  31. if (!isset($_SESSION['customCategoryAccess'])) {
  32. $_SESSION['customCategoryAccess'] = [];
  33. }
  34. // update access per session only once a day
  35. if (array_key_exists($id, $_SESSION['customCategoryAccess']) && $_SESSION['customCategoryAccess'][$id] > time() - 86400) {
  36. return;
  37. }
  38. $_SESSION['customCategoryAccess'][$id] = time();
  39. $stmt = $db->prepare("insert into customCategoryAccess (id) values (:id)");
  40. $stmt->bindValue(':id', $id);
  41. $stmt->execute();
  42. }