2014-03-20 13:51:13 -04:00
|
|
|
<?php
|
|
|
|
|
2018-01-03 21:12:19 -05:00
|
|
|
function create_files_from_item($itemid)
|
|
|
|
{
|
2014-03-20 13:51:13 -04:00
|
|
|
$messages = q("SELECT `guid`, `uid`, `id`, `edited`, `deleted`, `file`, `parent` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid));
|
2018-01-03 21:12:19 -05:00
|
|
|
if (!$messages) {
|
2014-03-20 13:51:13 -04:00
|
|
|
return;
|
2018-01-03 21:12:19 -05:00
|
|
|
}
|
2014-03-20 13:51:13 -04:00
|
|
|
|
|
|
|
$message = $messages[0];
|
|
|
|
|
|
|
|
// Clean up all tags
|
|
|
|
q("DELETE FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)",
|
|
|
|
intval(TERM_OBJ_POST),
|
|
|
|
intval($itemid),
|
|
|
|
intval(TERM_FILE),
|
|
|
|
intval(TERM_CATEGORY));
|
|
|
|
|
|
|
|
if ($message["deleted"])
|
|
|
|
return;
|
|
|
|
|
2018-01-03 21:12:19 -05:00
|
|
|
if (preg_match_all("/\[(.*?)\]/ism", $message["file"], $files)) {
|
|
|
|
foreach ($files[1] as $file) {
|
|
|
|
q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`) VALUES (%d, %d, %d, %d, '%s')",
|
2014-03-20 13:51:13 -04:00
|
|
|
intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_FILE), dbesc($file));
|
2018-01-03 21:12:19 -05:00
|
|
|
}
|
|
|
|
}
|
2014-03-20 13:51:13 -04:00
|
|
|
|
2018-01-03 21:12:19 -05:00
|
|
|
if (preg_match_all("/\<(.*?)\>/ism", $message["file"], $files)) {
|
|
|
|
foreach ($files[1] as $file) {
|
|
|
|
q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`) VALUES (%d, %d, %d, %d, '%s')",
|
2014-03-20 13:51:13 -04:00
|
|
|
intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), dbesc($file));
|
2018-01-03 21:12:19 -05:00
|
|
|
}
|
|
|
|
}
|
2014-03-20 13:51:13 -04:00
|
|
|
}
|
|
|
|
|
2018-01-03 21:12:19 -05:00
|
|
|
function create_files_from_itemuri($itemuri, $uid)
|
|
|
|
{
|
2014-03-20 13:51:13 -04:00
|
|
|
$messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
|
|
|
|
|
2017-04-04 13:47:45 -04:00
|
|
|
if (count($messages)) {
|
2014-03-20 13:51:13 -04:00
|
|
|
foreach ($messages as $message)
|
|
|
|
create_files_from_item($message["id"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-03 21:12:19 -05:00
|
|
|
function update_files_for_items()
|
|
|
|
{
|
2014-03-20 13:51:13 -04:00
|
|
|
$messages = q("SELECT `id` FROM `item` where file !=''");
|
|
|
|
|
|
|
|
foreach ($messages as $message) {
|
2018-01-03 21:12:19 -05:00
|
|
|
echo $message["id"] . "\n";
|
2014-03-20 13:51:13 -04:00
|
|
|
create_files_from_item($message["id"]);
|
|
|
|
}
|
|
|
|
}
|