2018-01-10 11:46:05 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @file src/Model/Term
|
|
|
|
*/
|
|
|
|
namespace Friendica\Model;
|
|
|
|
|
2018-02-03 22:42:31 -05:00
|
|
|
use Friendica\Database\DBM;
|
2018-01-10 12:05:20 -05:00
|
|
|
use dba;
|
|
|
|
|
2018-01-10 12:51:51 -05:00
|
|
|
require_once "include/dba.php";
|
|
|
|
|
2018-01-10 11:46:05 -05:00
|
|
|
class Term
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param integer $itemid item id
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-02-03 22:42:31 -05:00
|
|
|
public static function insertFromItemFileById($itemid)
|
2018-01-10 11:46:05 -05:00
|
|
|
{
|
2018-01-10 13:04:00 -05:00
|
|
|
$message = dba::selectFirst('item', ['uid', 'deleted', 'file'], ['id' => $itemid]);
|
2018-02-03 22:42:31 -05:00
|
|
|
if (!DBM::is_result($message)) {
|
2018-01-10 11:46:05 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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));
|
|
|
|
|
2018-01-10 13:04:00 -05:00
|
|
|
if ($message["deleted"]) {
|
2018-01-10 11:46:05 -05:00
|
|
|
return;
|
2018-01-10 13:04:00 -05:00
|
|
|
}
|
2018-01-10 11:46:05 -05:00
|
|
|
|
|
|
|
if (preg_match_all("/\[(.*?)\]/ism", $message["file"], $files)) {
|
|
|
|
foreach ($files[1] as $file) {
|
2018-01-10 13:04:00 -05:00
|
|
|
dba::insert('term', [
|
|
|
|
'uid' => $message["uid"],
|
|
|
|
'oid' => $itemid,
|
|
|
|
'otype' => TERM_OBJ_POST,
|
|
|
|
'type' => TERM_FILE,
|
|
|
|
'term' => $file
|
|
|
|
]);
|
2018-01-10 11:46:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (preg_match_all("/\<(.*?)\>/ism", $message["file"], $files)) {
|
|
|
|
foreach ($files[1] as $file) {
|
2018-01-10 13:04:00 -05:00
|
|
|
dba::insert('term', [
|
|
|
|
'uid' => $message["uid"],
|
|
|
|
'oid' => $itemid,
|
|
|
|
'otype' => TERM_OBJ_POST,
|
|
|
|
'type' => TERM_CATEGORY,
|
|
|
|
'term' => $file
|
|
|
|
]);
|
2018-01-10 11:46:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $itemuri item uri
|
|
|
|
* @param integer $uid uid
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-02-03 22:42:31 -05:00
|
|
|
public static function insertFromItemFileByUri($itemuri, $uid)
|
2018-01-10 11:46:05 -05:00
|
|
|
{
|
|
|
|
$messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
|
|
|
|
|
|
|
|
if (count($messages)) {
|
2018-01-10 12:51:51 -05:00
|
|
|
foreach ($messages as $message) {
|
2018-02-03 22:42:31 -05:00
|
|
|
self::insertFromItemFileById($message["id"]);
|
2018-01-10 12:51:51 -05:00
|
|
|
}
|
2018-01-10 11:46:05 -05:00
|
|
|
}
|
|
|
|
}
|
2018-01-10 12:51:51 -05:00
|
|
|
}
|