PageRenderTime 26ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/upload/system/controllers/home.php

https://github.com/essa/sharetronix_ja
PHP | 134 lines | 121 code | 13 blank | 0 comment | 30 complexity | 6238a497b80571e1aa0265b8580202b8 MD5 | raw file
  1. <?php
  2. if( $this->user->is_logged ) {
  3. $this->redirect('dashboard');
  4. }
  5. $this->load_langfile('inside/global.php');
  6. $this->load_langfile('outside/global.php');
  7. $this->load_langfile('inside/dashboard.php');
  8. $this->load_langfile('outside/home.php');
  9. $D->page_title = $this->lang('os_home_page_title', array('#SITE_TITLE#'=>$C->SITE_TITLE));
  10. $filters = array('all', 'videos', 'images', 'links', 'files');
  11. $filter = 'all';
  12. if( $this->param('filter') && in_array($this->param('filter'), $filters) ) {
  13. $filter = $this->param('filter');
  14. }
  15. $at_tmp = array('videos'=>'videoembed', 'images'=>'image', 'links'=>'link', 'files'=>'file');
  16. $not_in_groups = '';
  17. if( !$this->user->is_logged || !$this->user->info->is_network_admin ) {
  18. $not_in_groups = array();
  19. $r = $db2->query('SELECT id FROM groups WHERE is_public=0');
  20. while($obj = $db2->fetch_object($r)) {
  21. $g = $this->network->get_group_by_id($obj->id);
  22. if( ! $g ) {
  23. $not_in_groups[] = $obj->id;
  24. continue;
  25. }
  26. if( $g->is_public == 1 ) {
  27. continue;
  28. }
  29. if( ! $this->user->is_logged ) {
  30. $not_in_groups[] = $obj->id;
  31. continue;
  32. }
  33. $m = $this->network->get_group_members($g->id);
  34. if( ! isset($m[$this->user->id]) ) {
  35. $not_in_groups[] = $obj->id;
  36. }
  37. }
  38. $not_in_groups = count($not_in_groups)>0 ? ('AND p.group_id NOT IN('.implode(', ', $not_in_groups).')') : '';
  39. }
  40. if($filter == 'all') {
  41. $q1 = 'SELECT COUNT(p.id) FROM posts p WHERE p.user_id<>0 AND p.api_id<>2 '.$not_in_groups;
  42. $q2 = 'SELECT p.*, "public" AS `type` FROM posts p WHERE p.user_id<>0 AND p.api_id<>2 '.$not_in_groups.' ORDER BY p.id DESC ';
  43. }
  44. else {
  45. $q1 = 'SELECT COUNT(p.id) FROM posts p, posts_attachments a WHERE p.id=a.post_id AND p.user_id<>0 AND p.api_id<>2 '.$not_in_groups.' AND a.type="'.$at_tmp[$filter].'" ';
  46. $q2 = 'SELECT p.*, "public" AS `type` FROM posts p, posts_attachments a WHERE p.id=a.post_id AND p.user_id<>0 AND p.api_id<>2 '.$not_in_groups.' AND a.type="'.$at_tmp[$filter].'" ORDER BY p.id DESC ';
  47. }
  48. $D->filter = $filter;
  49. $D->num_results = 0;
  50. $D->num_pages = 0;
  51. $D->pg = 1;
  52. $D->posts_html = '';
  53. $D->num_results = $db2->fetch_field($q1);
  54. $D->num_pages = ceil($D->num_results / $C->PAGING_NUM_POSTS);
  55. $D->pg = $this->param('pg') ? intval($this->param('pg')) : 1;
  56. $D->pg = min($D->pg, $D->num_pages);
  57. $D->pg = max($D->pg, 1);
  58. $from = ($D->pg - 1) * $C->PAGING_NUM_POSTS;
  59. $res = $db2->query($q2.'LIMIT '.$from.', '.$C->PAGING_NUM_POSTS);
  60. ob_start();
  61. while($obj = $db2->fetch_object($res)) {
  62. $D->p = new post($obj->type, FALSE, $obj);
  63. if( $D->p->error ) {
  64. continue;
  65. }
  66. if( $this->param('from')=='ajax' && $this->param('onlypost')!="" && $this->param('onlypost')!=$D->p->post_tmp_id ) {
  67. continue;
  68. }
  69. if( $this->param('from')=='ajax' && $this->param('opencomments')!="" && $this->param('opencomments')==$D->p->post_tmp_id ) {
  70. $D->p->comments_open = TRUE;
  71. }
  72. $D->post_show_slow = FALSE;
  73. if( $this->param('from')=='ajax' && isset($_POST['lastpostdate']) && $D->p->post_date>intval($_POST['lastpostdate']) ) {
  74. $D->post_show_slow = TRUE;
  75. }
  76. $D->parsedpost_attlink_maxlen = 52;
  77. $D->parsedpost_attfile_maxlen = 48;
  78. if( isset($D->p->post_attached['image']) ) {
  79. $D->parsedpost_attlink_maxlen -= 10;
  80. $D->parsedpost_attfile_maxlen -= 12;
  81. }
  82. if( isset($D->p->post_attached['videoembed']) ) {
  83. $D->parsedpost_attlink_maxlen -= 10;
  84. $D->parsedpost_attfile_maxlen -= 12;
  85. }
  86. $this->load_template('single_post.php');
  87. }
  88. unset($D->p);
  89. $D->paging_url = $C->SITE_URL.'home/filter:'.$filter.'/pg:';
  90. if( $D->num_pages>1 && !$this->param('onlypost') ) {
  91. $this->load_template('paging_posts.php');
  92. }
  93. $D->posts_html = ob_get_contents();
  94. ob_end_clean();
  95. if( $this->param('from') == 'ajax' )
  96. {
  97. echo 'OK:';
  98. echo $D->posts_html;
  99. exit;
  100. }
  101. $D->last_online = array();
  102. $num = 6;
  103. $time = 5*60;
  104. $r = $db2->query('SELECT id, lastclick_date FROM users WHERE active=1 ORDER BY lastclick_date DESC LIMIT '.($num+1));
  105. while($o = $db2->fetch_object($r)) {
  106. if( $o->lastclick_date < time()-$time ) {
  107. break;
  108. }
  109. $D->last_online[] = $this->network->get_user_by_id($o->id);
  110. }
  111. $D->last_online = array_slice($D->last_online, 0, $num);
  112. $D->post_tags = array();
  113. $not_in_groups = array();
  114. $r = $this->db2->query('SELECT id FROM groups WHERE is_public=0');
  115. while($tmp = $this->db2->fetch_object()) {
  116. $not_in_group[] = $tmp->id;
  117. }
  118. $not_in_groups = count($not_in_groups)>0 ? ('AND group_id NOT IN('.implode(', ', $not_in_groups).')') : '';
  119. $D->post_tags = $this->network->get_recent_posttags($not_in_groups, 10);
  120. $this->load_template('home.php');
  121. ?>