1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/movim_ynh.git synced 2024-09-03 19:46:19 +02:00
movim_ynh/sources/app/widgets/Blog/Blog.php

149 lines
4.9 KiB
PHP
Raw Normal View History

<?php
use Respect\Validation\Validator;
2015-12-15 11:54:49 +01:00
include_once WIDGETS_PATH.'Post/Post.php';
class Blog extends WidgetBase {
public $_paging = 10;
2015-12-15 11:54:49 +01:00
private $_from;
private $_node;
private $_item;
private $_id;
private $_contact;
private $_messages;
private $_page;
private $_mode;
private $_tag;
2015-12-15 11:54:49 +01:00
function load()
{
2015-12-15 11:54:49 +01:00
if($this->_view == 'node') {
$this->_from = $this->get('s');
$this->_node = $this->get('n');
2015-12-15 11:54:49 +01:00
if(!$this->validateServerNode($this->_from, $this->_node)) return;
2015-08-19 11:28:28 +02:00
$pd = new \Modl\ItemDAO;
2015-12-15 11:54:49 +01:00
$this->_item = $pd->getItem($this->_from, $this->_node);
$this->_mode = 'group';
$this->url = Route::urlize('node', array($this->_from, $this->_node));
} elseif($this->_view == 'tag' && $this->validateTag($this->get('t'))) {
$this->_mode = 'tag';
$this->_tag = $this->get('t');
$this->title = '#'.$this->_tag;
} else {
2015-12-15 11:54:49 +01:00
$this->_from = $this->get('f');
2015-08-19 11:28:28 +02:00
$cd = new \modl\ContactDAO();
2015-12-15 11:54:49 +01:00
$this->_contact = $cd->get($this->_from, true);
if(filter_var($this->_from, FILTER_VALIDATE_EMAIL)) {
$this->_node = 'urn:xmpp:microblog:0';
2015-08-19 11:28:28 +02:00
} else {
return;
}
2015-12-15 11:54:49 +01:00
$this->_mode = 'blog';
2015-12-15 11:54:49 +01:00
$this->url = Route::urlize('blog', $this->_from);
}
2015-12-15 11:54:49 +01:00
$pd = new \modl\PostnDAO();
if($this->_id = $this->get('i')) {
2015-12-24 14:21:18 +01:00
if(Validator::intType()->between(1, 100)->validate((int)$this->_id)) {
2015-12-15 11:54:49 +01:00
if(isset($this->_tag)) {
$this->_messages = $pd->getPublicTag($this->get('t'), $this->_id * $this->_paging, $this->_paging + 1);
} else {
$this->_messages = $pd->getNodeUnfiltered($this->_from, $this->_node, $this->_id * $this->_paging, $this->_paging + 1);
}
$this->_page = $this->_id + 1;
} elseif(Validator::stringType()->length(5, 100)->validate($this->_id)) {
$this->_messages = $pd->getPublicItem($this->_from, $this->_node, $this->_id);
if(is_object($this->_messages[0])) {
$this->title = $this->_messages[0]->title;
$description = stripTags($this->_messages[0]->contentcleaned);
if(!empty($description)) {
$this->description = $description;
}
$attachements = $this->_messages[0]->getAttachements();
if($attachements && array_key_exists('pictures', $attachements)) {
$this->image = urldecode($attachements['pictures'][0]['href']);
}
}
if($this->_view == 'node') {
$this->url = Route::urlize('node', array($this->_from, $this->_node, $this->_id));
} else {
$this->url = Route::urlize('blog', array($this->_from, $this->_id));
}
}
} else {
2015-12-15 11:54:49 +01:00
$this->_page = 1;
if(isset($this->_tag)) {
$this->_messages = $pd->getPublicTag($this->get('t'), 0, $this->_paging + 1);
} else {
$this->_messages = $pd->getNodeUnfiltered($this->_from, $this->_node, 0, $this->_paging + 1);
}
}
2015-12-15 11:54:49 +01:00
if(count($this->_messages) == $this->_paging + 1) {
array_pop($this->_messages);
}
2015-12-15 11:54:49 +01:00
$this->user = new User($this->_from);
$cssurl = $this->user->getDumpedConfig('cssurl');
if(isset($cssurl)
&& $cssurl != ''
&& Validator::url()->validate($cssurl)) {
$this->addrawcss($cssurl);
}
}
public function preparePost($p) {
$pw = new Post;
return $pw->preparePost($p, true, true);
}
function display()
{
$this->view->assign('server', $this->_from);
$this->view->assign('node', $this->_node);
$this->view->assign('item', $this->_item);
$this->view->assign('contact', $this->_contact);
$this->view->assign('mode', $this->_mode);
$this->view->assign('more', $this->_page);
$this->view->assign('posts', $this->_messages);
$this->view->assign('tag', $this->_tag);
}
private function validateServerNode($server, $node)
{
2015-12-15 11:54:49 +01:00
$validate_server = Validator::stringType()->noWhitespace()->length(6, 40);
$validate_node = Validator::stringType()->length(3, 100);
if(!$validate_server->validate($server)
|| !$validate_node->validate($node)
) return false;
else return true;
}
2015-12-15 11:54:49 +01:00
private function validateTag($tag)
{
return Validator::stringType()->notEmpty()->alnum()->validate($tag);
}
function getComments($post)
{
$pd = new \Modl\PostnDAO();
return $pd->getComments($post);
}
}