This commit is contained in:
+24
-4
@@ -34,6 +34,7 @@ use \Settings;
|
||||
class Livetrail extends Main {
|
||||
//Database
|
||||
public const POST_TABLE = 'posts';
|
||||
private const REF_TYPES = ['post', 'media', 'message'];
|
||||
|
||||
private const FEED_CHUNK_SIZE = 15;
|
||||
private const MAIL_CHUNK_SIZE = 5;
|
||||
@@ -87,7 +88,7 @@ class Livetrail extends Main {
|
||||
Feed::FEED_TABLE => ['ref_feed_id', Db::getId(Feed::SPOT_TABLE), Db::getId(Project::PROJ_TABLE), 'name', 'description', 'status', 'last_update'],
|
||||
Feed::SPOT_TABLE => ['ref_spot_id', 'name', 'model'],
|
||||
Project::PROJ_TABLE => ['name', 'codename', 'active_from', 'active_to'],
|
||||
self::POST_TABLE => [Db::getId(Project::PROJ_TABLE), Db::getId(User::USER_TABLE), 'name', 'content', 'site_time', 'timezone'],
|
||||
self::POST_TABLE => [Db::getId(Project::PROJ_TABLE), Db::getId(User::USER_TABLE), 'name', 'content', 'site_time', 'timezone', 'ref_id', 'ref_type'],
|
||||
Media::MEDIA_TABLE => [Db::getId(Project::PROJ_TABLE), 'filename', 'type', 'taken_on', 'posted_on', 'timezone', 'latitude', 'longitude', 'altitude', 'width', 'height', 'rotate', 'comment'],
|
||||
User::USER_TABLE => ['name', 'email', 'password', 'token', 'token_exp', 'gravatar', 'language', 'timezone', 'subscribed', 'clearance'],
|
||||
Map::MAP_TABLE => ['codename', 'pattern', 'token', 'tile_size', 'min_zoom', 'max_zoom', 'attribution'],
|
||||
@@ -119,6 +120,8 @@ class Livetrail extends Main {
|
||||
'ref_feed_id' => 'VARCHAR(40)',
|
||||
'ref_msg_id' => 'VARCHAR(15)',
|
||||
'ref_spot_id' => 'VARCHAR(10)',
|
||||
'ref_id' => 'INT UNSIGNED',
|
||||
'ref_type' => 'VARCHAR(20)',
|
||||
'rotate' => 'SMALLINT',
|
||||
'site_time' => 'TIMESTAMP DEFAULT 0', //DEFAULT 0 removes auto-set to current time
|
||||
'status' => 'VARCHAR(10)',
|
||||
@@ -469,7 +472,7 @@ class Livetrail extends Main {
|
||||
return $asMedias;
|
||||
}
|
||||
|
||||
private function getPosts($asPostIds=[]) {
|
||||
private function getPosts($asPostIds=[], $bResolveRef=true) {
|
||||
$asInfo = [
|
||||
'select' => [Db::getFullColumnName(self::POST_TABLE, '*'), 'gravatar'],
|
||||
'from' => self::POST_TABLE,
|
||||
@@ -489,6 +492,20 @@ class Livetrail extends Main {
|
||||
unset($asPost[Db::getId(User::USER_TABLE)]);
|
||||
|
||||
$this->addTimeStamp($asPost, $iUnixTimeStamp, $asPost['timezone']);
|
||||
|
||||
if($bResolveRef && !empty($asPost['ref_type']) && !empty($asPost['ref_id'])) {
|
||||
switch($asPost['ref_type']) {
|
||||
case 'post': $asRefs = $this->getPosts([$asPost['ref_id']], false); break;
|
||||
case 'media': $asRefs = $this->getMedias('posted_on', [$asPost['ref_id']]); break;
|
||||
case 'message': $asRefs = $this->getSpotMessages([$asPost['ref_id']]); break;
|
||||
default: $asRefs = [];
|
||||
}
|
||||
$asPost['ref_item'] = reset($asRefs);
|
||||
$asPost['ref_item']['type'] = $asPost['ref_type'];
|
||||
$asPost['ref_item']['id'] = $asPost['ref_id'];
|
||||
}
|
||||
unset($asPost['ref_id']);
|
||||
unset($asPost['ref_type']);
|
||||
}
|
||||
|
||||
return $asPosts;
|
||||
@@ -658,17 +675,20 @@ class Livetrail extends Main {
|
||||
return ['ref_id_last'=>$iRefIdLast, 'ref_id_first'=>$iRefIdFirst, 'sort'=>$sSort, 'feed'=>$asItems];
|
||||
}
|
||||
|
||||
public function addPost($sName, $sPost) {
|
||||
public function addPost($sName, $sPost, $sRefType='', $iRefId=0) {
|
||||
$iPostId = 0;
|
||||
$sLangId = '';
|
||||
|
||||
if($this->oProject->isEditable()) {
|
||||
$bHasRef = ($iRefId > 0) && in_array($sRefType, self::REF_TYPES, true);
|
||||
$asData = [
|
||||
Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId(),
|
||||
'name' => mb_strtolower(trim($sName)),
|
||||
'content' => trim($sPost),
|
||||
'site_time' => date(Db::TIMESTAMP_FORMAT), //Now in Site Time
|
||||
'timezone' => date_default_timezone_get() //Site Time Zone
|
||||
'timezone' => date_default_timezone_get(), //Site Time Zone
|
||||
'ref_id' => $bHasRef?$iRefId:'NULL',
|
||||
'ref_type' => $bHasRef?$sRefType:'NULL'
|
||||
];
|
||||
if($this->oUser->getUserId() > 0) $asData[Db::getId(User::USER_TABLE)] = $this->oUser->getUserId();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user