Browse Source

Initial commit

master
Chimo 5 years ago
commit
3862cfd40d
6 changed files with 144 additions and 0 deletions
  1. +2
    -0
      .gitignore
  2. +11
    -0
      config.dist.php
  3. BIN
      images/ch-c.png
  4. BIN
      images/gmg-c.png
  5. BIN
      images/gs-c.png
  6. +131
    -0
      index.php

+ 2
- 0
.gitignore View File

@ -0,0 +1,2 @@
config.php

+ 11
- 0
config.dist.php View File

@ -0,0 +1,11 @@
<?php
$config = array(
"db" => array(
"name" => "lifestream",
"user" => "lifestream",
"password" => "",
"host" => "localhost"
)
);

BIN
images/ch-c.png View File

Before After
Width: 48  |  Height: 48  |  Size: 1.5 KiB

BIN
images/gmg-c.png View File

Before After
Width: 48  |  Height: 48  |  Size: 1.9 KiB

BIN
images/gs-c.png View File

Before After
Width: 48  |  Height: 48  |  Size: 2.2 KiB

+ 131
- 0
index.php View File

@ -0,0 +1,131 @@
<!DOCTYPE html>
<html>
<head>
<title>ls</title>
<style>
.gnusocial {
background-image: url("images/gs-c.png");
}
.mediagoblin {
background-image: url("images/gmg-c.png");
}
.blog {
background-image: url("images/ch-c.png");
}
li {
background-repeat: no-repeat;
background-position: left 20px;
padding-left: 50px;
}
#list {
list-style-type: none;
}
#list li {
margin-bottom: 12px;
}
figure {
box-shadow: -8px 8px 10px 0px rgba(204,204,204,0.47);
padding: 10px;
}
figcaption {
font-weight: bold;
}
</style>
</head>
<body>
<?php
require_once('config.php');
$dsn = 'mysql:dbname=' . $config['db']['name'] . ';host=' . $config['db']['host'];
$user = $config['db']['user'];
$password = $config['db']['password'];
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
die('Connection failed: ' . $e->getMessage());
}
$sql = 'SELECT title, content, published, foreign_url, subscription.type FROM event INNER JOIN subscription ON event.subscription_id = subscription.id ORDER BY published DESC';
$res = $dbh->query($sql);
$html = '<ol id="list">';
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
$html .= '<li class="' . $row['type'] . '"><figure><figcaption>';
$html .= $row['title'];
$html .= '</figcaption>';
$html .= '<blockquote cite="' . $row['foreign_url'] . '">' . $row['content'] . '</blockquote>';
$html .= '<footer><a href="' . $row['foreign_url'] . '">' . $row['published'] . '</a></footer>';
$html .= '</figure></li>';
}
$html .= '</ol>';
echo $html;
?>
<script>
if ("WebSocket" in window ) {
var ws = new WebSocket( window.location.origin.replace( /https?/, "ws" ) + ":8090" ),
formatDate;
formatDate = function( date ) {
var d = new Date( date );
// Fallback to "now" if date is invalid
if ( isNaN( d.getTime() ) ) {
d = new Date();
}
return d.toISOString().slice( 0, -5 ).replace( "T", " " );
};
ws.onopen = function( event ) {
console.log( 'connection established' );
};
ws.onerror = function ( event ) {
console.log( 'error' );
console.log( event );
};
ws.onclose = function (event) {
console.log('closed');
console.log(event);
}
ws.onmessage = function( event ) {
console.log(JSON.parse(event.data).published);
var item = document.createElement( 'li' ),
list = document.getElementById( 'list' ),
event = JSON.parse( event.data );
item.innerHTML = "<figure>" +
"<figcaption>" + event.title + "</figcaption>" +
"<blockquote cite='" + event.source + "'>" + event.content + "</blockquote>" +
"<footer><a href='" + event.source + "'>" + formatDate( event.published ) + "</a></footer>" +
"</figure>";
list.insertBefore( item, list.firstChild );
};
}
</script>
</body>
</html>

Loading…
Cancel
Save