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.
 
 
 
 
 
 

50 line
1.5 KiB

  1. <?php
  2. function create_files_from_item($itemid) {
  3. $a = get_app();
  4. $messages = q("SELECT `guid`, `uid`, `id`, `edited`, `deleted`, `file`, `parent` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid));
  5. if (!$messages)
  6. return;
  7. $message = $messages[0];
  8. // Clean up all tags
  9. q("DELETE FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)",
  10. intval(TERM_OBJ_POST),
  11. intval($itemid),
  12. intval(TERM_FILE),
  13. intval(TERM_CATEGORY));
  14. if ($message["deleted"])
  15. return;
  16. if (preg_match_all("/\[(.*?)\]/ism", $message["file"], $files))
  17. foreach ($files[1] as $file)
  18. $r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`) VALUES (%d, %d, %d, %d, '%s')",
  19. intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_FILE), dbesc($file));
  20. if (preg_match_all("/\<(.*?)\>/ism", $message["file"], $files))
  21. foreach ($files[1] as $file)
  22. $r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`) VALUES (%d, %d, %d, %d, '%s')",
  23. intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), dbesc($file));
  24. }
  25. function create_files_from_itemuri($itemuri, $uid) {
  26. $messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
  27. if (count($messages)) {
  28. foreach ($messages as $message)
  29. create_files_from_item($message["id"]);
  30. }
  31. }
  32. function update_files_for_items() {
  33. $messages = q("SELECT `id` FROM `item` where file !=''");
  34. foreach ($messages as $message) {
  35. echo $message["id"]."\n";
  36. create_files_from_item($message["id"]);
  37. }
  38. }