streams/Code/Lib/ThreadListener.php

77 lines
1.9 KiB
PHP
Raw Normal View History

2018-09-10 06:15:59 +00:00
<?php
2022-02-16 04:08:28 +00:00
namespace Code\Lib;
2018-09-10 06:15:59 +00:00
2021-12-03 03:01:39 +00:00
class ThreadListener
{
public static function isEnabled()
{
return Config::Get('system','enable_thread_listener');
}
2021-12-03 03:01:39 +00:00
public static function store($target_id, $portable_id, $ltype = 0)
{
if (!self::isEnabled()) {
return true;
}
2022-08-16 09:07:47 +00:00
$x = self::fetch($target_id, $portable_id, $ltype);
2021-12-03 03:01:39 +00:00
if (! $x) {
2022-08-16 09:07:47 +00:00
return q(
2021-12-03 03:01:39 +00:00
"insert into listeners ( target_id, portable_id, ltype ) values ( '%s', '%s' , %d ) ",
dbesc($target_id),
dbesc($portable_id),
intval($ltype)
);
}
2022-08-16 09:07:47 +00:00
return true;
2021-12-03 03:01:39 +00:00
}
public static function fetch($target_id, $portable_id, $ltype = 0)
{
if (! self::isEnabled()) {
return false;
}
2021-12-03 03:01:39 +00:00
$x = q(
"select * from listeners where target_id = '%s' and portable_id = '%s' and ltype = %d limit 1",
dbesc($target_id),
dbesc($portable_id),
intval($ltype)
);
if ($x) {
return $x[0];
}
return false;
}
public static function fetch_by_target($target_id, $ltype = 0)
{
if (! self::isEnabled()) {
return [];
}
2022-08-16 09:07:47 +00:00
return q(
2021-12-03 03:01:39 +00:00
"select * from listeners where target_id = '%s' and ltype = %d",
dbesc($target_id),
intval($ltype)
);
}
public static function delete_by_target($target_id, $ltype = 0)
{
return q(
"delete from listeners where target_id = '%s' and ltype = %d",
dbesc($target_id),
intval($ltype)
);
}
public static function delete_by_pid($portable_id, $ltype = 0)
{
return q(
"delete from listeners where portable_id = '%s' and ltype = %d",
dbesc($portable_id),
intval($ltype)
);
}
2019-02-12 02:25:38 +00:00
}