mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-19 21:55:15 +00:00
lib-block initial
This commit is contained in:
parent
1a57c95106
commit
cc30471192
4 changed files with 102 additions and 1 deletions
78
Zotlabs/Lib/LibBlock.php
Normal file
78
Zotlabs/Lib/LibBlock.php
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace Zotlabs\Lib;
|
||||
|
||||
|
||||
class LibBlock {
|
||||
|
||||
static function store($arr) {
|
||||
|
||||
$arr['block_entity'] = trim($arr['block_entity']);
|
||||
|
||||
if (! $arr['block_entity']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$arr['block_channel_id'] = ((array_key_exists('block_channel_id',$arr)) ? intval($arr['block_channel_id']) : 0);
|
||||
$arr['block_type'] = ((array_key_exists('block_type',$arr)) ? intval($arr['block_type']) : BLOCKTYPE_CHANNEL );
|
||||
$arr['block_comment'] = ((array_key_exists('block_comment',$arr)) ? escape_tags(trim($arr['block_comment'])) ? EMPTY_STR);
|
||||
|
||||
if (! intval($arr['block_id'])) {
|
||||
$r = q("select * from block where block_channel_id = %d and block_entity = '%s' limit 1",
|
||||
intval($arr['block_channel_id']),
|
||||
dbesc($arr['block_entity'])
|
||||
);
|
||||
if ($r) {
|
||||
$arr['block_id'] = $r[0]['block_id'];
|
||||
}
|
||||
}
|
||||
|
||||
if (intval($arr['block_id'])) {
|
||||
return q("UPDATE block set block_channel_id = %d, block_entity = '%s', block_type = %d, block_comment = '%s' where block_id = %d",
|
||||
intval($arr['block_channel_id']),
|
||||
dbesc($arr['block_entity']),
|
||||
intval($arr['block_type']),
|
||||
dbesc($arr['block_comment']),
|
||||
intval($arr['block_id'])
|
||||
)
|
||||
}
|
||||
else {
|
||||
return create_table_from_array('block',$arr);
|
||||
}
|
||||
}
|
||||
|
||||
static function remove($channel_id,$entity) {
|
||||
return q("delete from block where block_channel_id = %d and block_entity = '%s'",
|
||||
intval($block_id),
|
||||
dbesc($entity)
|
||||
);
|
||||
}
|
||||
|
||||
static function fetch_by_id($channel_id,$id) {
|
||||
|
||||
$r = q("select * from block where block_channel_id = %d and block_id = %d ",
|
||||
intval($channel_id)
|
||||
);
|
||||
return (($r) ? array_shift($r) : $r);
|
||||
}
|
||||
|
||||
|
||||
static function fetch_by_entity($channel_id,$entity) {
|
||||
|
||||
$r = q("select * from block where block_channel_id = %d and block_entity = '%s' ",
|
||||
intval($entity)
|
||||
);
|
||||
return (($r) ? array_shift($r) : $r);
|
||||
}
|
||||
|
||||
static function fetch($channel_id,$type = false) {
|
||||
|
||||
$sql_extra = (($type === false) ? EMPTY_STR : " and block_type = " . intval($type));
|
||||
|
||||
$r = q("select * from block where block_channel_id = %d $sql_extra",
|
||||
intval($channel_id)
|
||||
);
|
||||
return $r;
|
||||
}
|
||||
|
||||
}
|
2
boot.php
2
boot.php
|
@ -19,7 +19,7 @@ use Zotlabs\Daemon\Master;
|
|||
define ( 'STD_VERSION', '20.03.13' );
|
||||
define ( 'ZOT_REVISION', '6.0' );
|
||||
|
||||
define ( 'DB_UPDATE_VERSION', 1237 );
|
||||
define ( 'DB_UPDATE_VERSION', 1238 );
|
||||
|
||||
define ( 'PLATFORM_NAME', 'zap' );
|
||||
define ( 'PLATFORM_ARCHITECTURE', 'zap' );
|
||||
|
|
|
@ -216,6 +216,18 @@ CREATE TABLE IF NOT EXISTS `auth_codes` (
|
|||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `block` (
|
||||
`block_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`block_channel_id` int(10) UNSIGNED NOT NULL,
|
||||
`block_entity` text NOT NULL,
|
||||
`block_type` int(11) NOT NULL,
|
||||
`block_comment` mediumtext NOT NULL,
|
||||
PRIMARY KEY (`block_id`),
|
||||
KEY `block_channel_id` (`block_channel_id`),
|
||||
KEY `block_entity` (`block_entity`(191)),
|
||||
KEY `block_type` (`block_type`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `cache` (
|
||||
`k` char(191) NOT NULL DEFAULT '',
|
||||
`v` text NOT NULL,
|
||||
|
|
|
@ -211,6 +211,17 @@ CREATE TABLE "auth_codes" (
|
|||
"auth_scope" varchar(512) NOT NULL,
|
||||
PRIMARY KEY ("id")
|
||||
);
|
||||
CREATE TABLE "block" (
|
||||
block_id serial NOT NULL,
|
||||
block_channel_id int(10) UNSIGNED NOT NULL,
|
||||
block_entity text NOT NULL,
|
||||
block_type int(11) NOT NULL,
|
||||
block_comment text NOT NULL,
|
||||
PRIMARY KEY ("block_id")
|
||||
);
|
||||
create index "block_channel_id_idx" on block ("block_channel_id");
|
||||
create index "block_entity_idx" on block ("block_entity");
|
||||
create index "block_type_idx" on block ("block_type");
|
||||
CREATE TABLE "cache" (
|
||||
"k" text NOT NULL,
|
||||
"v" text NOT NULL,
|
||||
|
|
Loading…
Reference in a new issue