2015-08-03 11:35:01 +02:00
|
|
|
<?php
|
|
|
|
|
2015-11-13 13:37:39 +01:00
|
|
|
use Respect\Validation\Validator;
|
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
class Blog extends WidgetBase {
|
2015-11-13 13:37:39 +01:00
|
|
|
public $_paging = 10;
|
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
function load()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function display()
|
|
|
|
{
|
2015-08-19 11:28:28 +02:00
|
|
|
if($this->_view == 'grouppublic') {
|
|
|
|
$from = $this->get('s');
|
|
|
|
$node = $this->get('n');
|
2015-11-13 13:37:39 +01:00
|
|
|
|
|
|
|
if(!$this->validateServerNode($from, $node)) return;
|
|
|
|
|
2015-08-19 11:28:28 +02:00
|
|
|
$this->view->assign('mode', 'group');
|
|
|
|
$this->view->assign('server', $from);
|
|
|
|
$this->view->assign('node', $node);
|
2015-08-03 11:35:01 +02:00
|
|
|
|
2015-08-19 11:28:28 +02:00
|
|
|
$pd = new \Modl\ItemDAO;
|
|
|
|
$this->view->assign('item', $pd->getItem($from, $node));
|
2015-08-03 11:35:01 +02:00
|
|
|
} else {
|
2015-08-19 11:28:28 +02:00
|
|
|
$from = $this->get('f');
|
|
|
|
|
|
|
|
$cd = new \modl\ContactDAO();
|
|
|
|
$c = $cd->get($from, true);
|
|
|
|
$this->view->assign('contact', $c);
|
|
|
|
if(filter_var($from, FILTER_VALIDATE_EMAIL)) {
|
|
|
|
$node = 'urn:xmpp:microblog:0';
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->view->assign('mode', 'blog');
|
2015-08-03 11:35:01 +02:00
|
|
|
}
|
|
|
|
|
2015-11-13 13:37:39 +01:00
|
|
|
$pd = new \modl\PostnDAO();
|
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
if($id = $this->get('i')) {
|
2015-11-13 13:37:39 +01:00
|
|
|
if(Validator::int()->between(0, 100)->validate($id)) {
|
|
|
|
$messages = $pd->getNodeUnfiltered($from, $node, $id * $this->_paging, $this->_paging + 1);
|
|
|
|
$page = $id + 1;
|
|
|
|
} elseif(Validator::string()->length(5, 100)->validate($id)) {
|
|
|
|
$messages = $pd->getPublicItem($from, $node, $id);
|
|
|
|
}
|
2015-08-03 11:35:01 +02:00
|
|
|
} else {
|
2015-11-13 13:37:39 +01:00
|
|
|
$page = 1;
|
|
|
|
$messages = $pd->getNodeUnfiltered($from, $node, 0, $this->_paging + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(count($messages) == $this->_paging + 1) {
|
|
|
|
array_pop($messages);
|
|
|
|
$this->view->assign('more', $page);
|
2015-08-03 11:35:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->view->assign('posts', $messages);
|
|
|
|
}
|
|
|
|
|
2015-11-13 13:37:39 +01:00
|
|
|
private function validateServerNode($server, $node)
|
|
|
|
{
|
|
|
|
$validate_server = Validator::string()->noWhitespace()->length(6, 40);
|
|
|
|
$validate_node = Validator::string()->length(3, 100);
|
|
|
|
|
|
|
|
if(!$validate_server->validate($server)
|
|
|
|
|| !$validate_node->validate($node)
|
|
|
|
) return false;
|
|
|
|
else return true;
|
|
|
|
}
|
|
|
|
|
2015-08-03 11:35:01 +02:00
|
|
|
function getComments($post)
|
|
|
|
{
|
|
|
|
$pd = new \Modl\PostnDAO();
|
|
|
|
return $pd->getComments($post);
|
|
|
|
}
|
|
|
|
}
|