You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
4.9 KiB

  1. <?php
  2. use Respect\Validation\Validator;
  3. include_once WIDGETS_PATH.'Post/Post.php';
  4. class Blog extends WidgetBase {
  5. public $_paging = 10;
  6. private $_from;
  7. private $_node;
  8. private $_item;
  9. private $_id;
  10. private $_contact;
  11. private $_messages;
  12. private $_page;
  13. private $_mode;
  14. private $_tag;
  15. function load()
  16. {
  17. if($this->_view == 'node') {
  18. $this->_from = $this->get('s');
  19. $this->_node = $this->get('n');
  20. if(!$this->validateServerNode($this->_from, $this->_node)) return;
  21. $pd = new \Modl\ItemDAO;
  22. $this->_item = $pd->getItem($this->_from, $this->_node);
  23. $this->_mode = 'group';
  24. $this->url = Route::urlize('node', array($this->_from, $this->_node));
  25. } elseif($this->_view == 'tag' && $this->validateTag($this->get('t'))) {
  26. $this->_mode = 'tag';
  27. $this->_tag = $this->get('t');
  28. $this->title = '#'.$this->_tag;
  29. } else {
  30. $this->_from = $this->get('f');
  31. $cd = new \modl\ContactDAO();
  32. $this->_contact = $cd->get($this->_from, true);
  33. if(filter_var($this->_from, FILTER_VALIDATE_EMAIL)) {
  34. $this->_node = 'urn:xmpp:microblog:0';
  35. } else {
  36. return;
  37. }
  38. $this->_mode = 'blog';
  39. $this->url = Route::urlize('blog', $this->_from);
  40. }
  41. $pd = new \modl\PostnDAO();
  42. if($this->_id = $this->get('i')) {
  43. if(Validator::int()->between(0, 100)->validate($this->_id)) {
  44. if(isset($this->_tag)) {
  45. $this->_messages = $pd->getPublicTag($this->get('t'), $this->_id * $this->_paging, $this->_paging + 1);
  46. } else {
  47. $this->_messages = $pd->getNodeUnfiltered($this->_from, $this->_node, $this->_id * $this->_paging, $this->_paging + 1);
  48. }
  49. $this->_page = $this->_id + 1;
  50. } elseif(Validator::stringType()->length(5, 100)->validate($this->_id)) {
  51. $this->_messages = $pd->getPublicItem($this->_from, $this->_node, $this->_id);
  52. if(is_object($this->_messages[0])) {
  53. $this->title = $this->_messages[0]->title;
  54. $description = stripTags($this->_messages[0]->contentcleaned);
  55. if(!empty($description)) {
  56. $this->description = $description;
  57. }
  58. $attachements = $this->_messages[0]->getAttachements();
  59. if($attachements && array_key_exists('pictures', $attachements)) {
  60. $this->image = urldecode($attachements['pictures'][0]['href']);
  61. }
  62. }
  63. if($this->_view == 'node') {
  64. $this->url = Route::urlize('node', array($this->_from, $this->_node, $this->_id));
  65. } else {
  66. $this->url = Route::urlize('blog', array($this->_from, $this->_id));
  67. }
  68. }
  69. } else {
  70. $this->_page = 1;
  71. if(isset($this->_tag)) {
  72. $this->_messages = $pd->getPublicTag($this->get('t'), 0, $this->_paging + 1);
  73. } else {
  74. $this->_messages = $pd->getNodeUnfiltered($this->_from, $this->_node, 0, $this->_paging + 1);
  75. }
  76. }
  77. if(count($this->_messages) == $this->_paging + 1) {
  78. array_pop($this->_messages);
  79. }
  80. $this->user = new User($this->_from);
  81. $cssurl = $this->user->getDumpedConfig('cssurl');
  82. if(isset($cssurl)
  83. && $cssurl != ''
  84. && Validator::url()->validate($cssurl)) {
  85. $this->addrawcss($cssurl);
  86. }
  87. }
  88. public function preparePost($p) {
  89. $pw = new Post;
  90. return $pw->preparePost($p, true, true);
  91. }
  92. function display()
  93. {
  94. $this->view->assign('server', $this->_from);
  95. $this->view->assign('node', $this->_node);
  96. $this->view->assign('item', $this->_item);
  97. $this->view->assign('contact', $this->_contact);
  98. $this->view->assign('mode', $this->_mode);
  99. $this->view->assign('more', $this->_page);
  100. $this->view->assign('posts', $this->_messages);
  101. $this->view->assign('tag', $this->_tag);
  102. }
  103. private function validateServerNode($server, $node)
  104. {
  105. $validate_server = Validator::stringType()->noWhitespace()->length(6, 40);
  106. $validate_node = Validator::stringType()->length(3, 100);
  107. if(!$validate_server->validate($server)
  108. || !$validate_node->validate($node)
  109. ) return false;
  110. else return true;
  111. }
  112. private function validateTag($tag)
  113. {
  114. return Validator::stringType()->notEmpty()->alnum()->validate($tag);
  115. }
  116. function getComments($post)
  117. {
  118. $pd = new \Modl\PostnDAO();
  119. return $pd->getComments($post);
  120. }
  121. }