PHP
<?php
class Tops
{
private $imager;
private $config;
private $connection;
public function __construct($config, $connection, $url)
{
$this->imager = new Imager($config, $connection);
$this->config = $config;
$this->connection = $connection;
}
public function getCredits()
{
$query = $this->connection->prepare('SELECT username, credits FROM users ORDER BY credits DESC LIMIT 5');
$query->execute();
if($query->rowCount()) {
while($r = $query->fetchObject()) {
echo '<li>
<div class="avatar">
' . $this->imager->Generate('user=' . $r->username) . '
</div>
<div class="info">
<div class="name">' . $r->username . '</div>
<div class="amount">' . $r->credits . '</div>
</div>
</li>';
}
}
}
public function getDuckets()
{
$query = $this->connection->prepare('SELECT username, activity_points FROM users ORDER BY activity_points DESC LIMIT 5');
$query->execute();
if($query->rowCount()) {
while($r = $query->fetchObject()) {
echo '<li>
<div class="avatar">
' . $this->imager->Generate('user=' . $r->username) . '
</div>
<div class="info">
<div class="name">' . $r->username . '</div>
<div class="amount">' . $r->activity_points . '</div>
</div>
</li>';
}
}
}
public function getDiamonds()
{
$query = $this->connection->prepare('SELECT username, seasonal_currency FROM users ORDER BY seasonal_currency DESC LIMIT 5');
$query->execute();
if($query->rowCount()) {
while($r = $query->fetchObject()) {
echo '<li>
<div class="avatar">
' . $this->imager->Generate('user=' . $r->username) . '
</div>
<div class="info">
<div class="name">' . $r->username . '</div>
<div class="amount">' . $r->seasonal_currency . '</div>
</div>
</li>';
}
}
}
public function __destruct()
{
$this->imager = null;
$this->config = null;
$this->connection = null;
}
}
?>
Alles anzeigen
PHP
<?php
class Articles
{
public $err = '';
public $data;
public $success = false;
private $url;
private $user;
private $imager;
private $config;
private $connection;
public function __construct($config, $connection, $url)
{
$this->url = explode('-', $url[2]);
$this->user = new User($config, $connection);
$this->imager = new Imager($config, $connection);
$this->config = $config;
$this->connection = $connection;
$this->getVoting();
$this->CreateArticle();
}
public function Comment($comment)
{
if(empty($comment)) {
$this->err = 'Gib dein Kommentar ein.';
} elseif(strlen($comment) < 5) {
$this->err = 'Der Kommentar muss mindestens 5 Zeichen lang sein.';
} elseif(strlen($comment) > 50) {
$this->err = 'Der Kommentar darf maximal 50 Zeichen lang sein.';
} else {
$query = $this->connection->prepare('INSERT INTO sync_articles_comments (id, article, comment) VALUES (:id, :article, :comment)');
$query->execute([
':id' => $this->user->data['id'],
':article' => $this->url[0],
':comment' => $comment
]);
$this->success = true;
}
}
public function getComments()
{
$query = $this->connection->prepare('SELECT * FROM sync_articles_comments WHERE article = :article');
$query->execute([':article' => $this->url[0]]);
if($query->rowCount()) {
$flag = 0;
while($r = $query->fetchObject()) {
$user = $this->connection->prepare('SELECT username FROM users WHERE id = :id LIMIT 1');
$user->execute([':id' => $r->id]);
$row = $user->fetchObject();
if($flag == 0) {
echo '<div class="comment-box">
<div class="avatar">
' . $this->imager->Generate('direction=2/head_direction=2/user=' . $row->username) . '
</div>
<div class="comment left">
<div class="title">Kommentar von ' . $row->username . ':</div>
<div class="content">' . $r->comment . '</div>
</div>
</div>';
$flag = 1;
} else {
echo '<div class="comment-box">
<div class="avatar float-right">
' . $this->imager->Generate('direction=4/head_direction=4/user=' . $row->username) . '
</div>
<div class="comment right">
<div class="title">Kommentar von ' . $row->username . ':</div>
<div class="content">' . $r->comment . '</div>
</div>
</div>';
$flag = 0;
}
}
}
}
public function getArticles()
{
$query = $this->connection->prepare('SELECT id, title FROM sync_articles ORDER BY id DESC');
$query->execute();
if($query->rowCount()) {
while($r = $query->fetchObject()) {
if($this->url[0] === $r->id) {
echo '<li class="active">' . $r->title . '</li>';
} else {
echo '<li><a href="' . $this->config['website']['url'] . '/community/articles/' . $r->id . '-' . str_replace(' ', '-', strtolower($r->title)) . '">' . $r->title . '</a></li>';
}
}
}
}
public function getVoting()
{
$query = $this->connection->prepare('SELECT voting FROM sync_articles_voting WHERE article = :article AND voting = :voting');
$query->execute([
':article' => $this->url[0],
':voting' => 'like'
]);
$this->data['likes'] = $query->rowCount();
$query = $this->connection->prepare('SELECT voting FROM sync_articles_voting WHERE article = :article AND voting = :voting');
$query->execute([
':article' => $this->url[0],
':voting' => 'dislike'
]);
$this->data['dislikes'] = $query->rowCount();
}
public function CheckVoting()
{
$query = $this->connection->prepare('SELECT id FROM sync_articles_voting WHERE article = :article AND id = :id LIMIT 1');
$query->execute([
':article' => $this->url[0],
':id' => $this->user->data['id']
]);
if($query->rowCount()) {
return false;
} else {
return true;
}
}
public function Like()
{
$query = $this->connection->prepare('INSERT INTO sync_articles_voting (id, article, voting) VALUES (:id, :article, :voting)');
$query->execute([
':id' => $this->user->data['id'],
':article' => $this->url[0],
':voting' => 'like'
]);
}
public function Dislike()
{
$query = $this->connection->prepare('INSERT INTO sync_articles_voting (id, article, voting) VALUES (:id, :article, :voting)');
$query->execute([
':id' => $this->user->data['id'],
':article' => $this->url[0],
':voting' => 'dislike'
]);
}
public function CreateArticle()
{
$query = $this->connection->prepare('SELECT * FROM sync_articles WHERE id = :id LIMIT 1');
$query->execute([':id' => $this->url[0]]);
if($query->rowCount()) {
$r = $query->fetchObject();
foreach($r as $key => $value) {
$this->data[$key] = $value;
}
}
}
public function __destruct()
{
$this->url = null;
$this->data = null;
$this->config = null;
$this->connection = null;
}
}
?>
Alles anzeigen
Hab das Limit erreicht lol