WHERE `users`.`uid` = `node`.`uid`
AND `content_type_stream_channel`.`nid`=`node`.`nid`
AND `node`.`status` = 1
ORDER BY `node`.`changed` DESC LIMIT 100';
$queryPrimeTimeStreamNoRubric = 'SELECT `node`.`nid` AS `stream_id`,
`node`.`title` AS `stream_title`
FROM `content_type_prime_stream`, `node`, `users`
WHERE `users`.`uid` = `node`.`uid`
AND `content_type_prime_stream`.`nid`=`node`.`nid`
AND NOW() >`content_type_prime_stream`.`field_prime_time_value`
AND `node`.`status` = 1
AND `content_type_prime_stream`.`field_prime_rubric_value` = 0
ORDER BY `node`.`created` DESC LIMIT 20';
$data[] = array('channelId' => '0', 'channelTitle' => 'main');
$data[] = array('channelId' => PRIME_TIME_CHANNEL_ID, 'channelTitle' => PRIME_TIME_CHANNEL_TITLE);
$data = array_merge($data, GetDataByQuery($queryStreamChannel), GetDataByQuery($queryPrimeTimeStreamNoRubric));
$dataJson = json_encode(array('channel' => $data));
$channelsFile = CHAT_MEMFS_DIR . '/channels_history.json';
file_put_contents($channelsFile, $dataJson);
function GetDataByQuery($queryString)
{
    global $db;
    $queryResult = $db->Query($queryString);
    if ($queryResult === false) {
        return false;
    }
    $data = array();
    $maxLength = 100;
    while ($channel = $queryResult->fetch_assoc()) {
        if (mb_strlen($channel['stream_title']) > $maxLength) {
            $channel['stream_title'] = mb_substr($channel['stream_title'], 0, $maxLength) . '...';
	UNIX_TIMESTAMP(`content_type_prime_stream`.`field_prime_time_value`) +
	`content_type_prime_stream`.`field_prime_time_offset`
)
AND `node`.`status` = 1
ORDER BY `timeCreated` DESC';
$queryStreamChannel = 'SELECT `node`.`nid` AS `stream_id`,
`node`.`title` AS `stream_title`,
`node`.`created` AS `timeCreated`,
`users`.`name` as `streamer_name`
FROM `content_type_stream_channel`, `node`, `users`
WHERE `content_type_stream_channel`.`field_stream_channel_status_value`=1
AND `users`.`uid` = `node`.`uid`
AND `content_type_stream_channel`.`nid`=`node`.`nid`
ORDER BY `timeCreated` DESC';
$data[] = array('channelId' => '0', 'channelTitle' => 'main');
$data = array_merge($data, GetDataByQuery($queryPrimeTimeStream, $isPrimeTimeQuery = TRUE), GetDataByQuery($queryStreamChannel));
$dataJson = json_encode(array('channel' => $data));
$channelsFile = CHAT_MEMFS_DIR . '/channels.json';
file_put_contents($channelsFile, $dataJson);
function GetDataByQuery($queryString, $isPrimeTimeQuery = FALSE)
{
    global $db;
    $queryResult = $db->Query($queryString);
    if ($queryResult === false) {
        return false;
    }
    $data = array();
    $maxLength = 100;
    $primeTimeStreamsCount = 0;
    while ($channel = $queryResult->fetch_assoc()) {
        if (mb_strlen($channel['stream_title']) > $maxLength) {