PageRenderTime 25ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/module/news/index.php

https://github.com/ECP-Black/ECP
PHP | 184 lines | 184 code | 0 blank | 0 comment | 24 complexity | ed28a3ed36bb783caf9e38ec9866069d MD5 | raw file
  1. <?php
  2. function news($topicID = 0) {
  3. global $db;
  4. if($topicID) {
  5. $anzahl = $db->result(DB_PRE.'ecp_news', 'COUNT(newsID)', '(lang = "" OR lang LIKE ",%'.LANGUAGE.'%,") AND topicID = '.$topicID.' AND '.DB_PRE.'ecp_news.datum < '.time().' AND (access = "" OR '.$_SESSION['access_search'].')');
  6. $seiten = get_sql_limit($anzahl, LIMIT_NEWS);
  7. $sql = 'SELECT `newsID`, `'.DB_PRE.'ecp_news`.`userID`, `topicID`, `'.DB_PRE.'ecp_news`.`datum`, `headline`, `bodytext`, `extendtext`, `links`, `hits`,
  8. `username`, `topicname`, `topicbild`, `beschreibung`, COUNT(comID) AS comments
  9. FROM '.DB_PRE.'ecp_news
  10. LEFT JOIN '.DB_PRE.'ecp_user ON ('.DB_PRE.'ecp_news.userID = ID)
  11. LEFT JOIN '.DB_PRE.'ecp_topics ON (topicID = tID)
  12. LEFT JOIN '.DB_PRE.'ecp_comments ON (subID = newsID AND bereich = "news")
  13. WHERE (lang = "" OR lang LIKE ",%'.LANGUAGE.'%,") AND topicID = '.$topicID.' AND '.DB_PRE.'ecp_news.datum < '.time().' AND (access = "" OR '.$_SESSION['access_search'].') GROUP BY newsID ORDER BY sticky DESC, datum DESC';
  14. } else {
  15. $anzahl = $db->result(DB_PRE.'ecp_news', 'COUNT(newsID)', '(lang = "" OR lang LIKE ",%'.LANGUAGE.'%,") AND '.DB_PRE.'ecp_news.datum < '.time().' AND (access = "" OR '.$_SESSION['access_search'].')');
  16. $seiten = get_sql_limit($anzahl, LIMIT_NEWS);
  17. $sql = 'SELECT `newsID`, `'.DB_PRE.'ecp_news`.`userID`, `topicID`, `'.DB_PRE.'ecp_news`.`datum`, `headline`, `bodytext`, `extendtext`, `links`, `hits`,
  18. `username`, `topicname`, `topicbild`, `beschreibung`, COUNT(comID) AS comments
  19. FROM '.DB_PRE.'ecp_news
  20. LEFT JOIN '.DB_PRE.'ecp_user ON ('.DB_PRE.'ecp_news.userID = ID)
  21. LEFT JOIN '.DB_PRE.'ecp_topics ON (topicID = tID)
  22. LEFT JOIN '.DB_PRE.'ecp_comments ON (subID = newsID AND bereich = "news")
  23. WHERE (lang = "" OR lang LIKE ",%'.LANGUAGE.'%,") AND '.DB_PRE.'ecp_news.datum < '.time().' AND (access = "" OR '.$_SESSION['access_search'].') GROUP BY newsID ORDER BY sticky DESC, datum DESC';
  24. }
  25. if($anzahl) {
  26. if(!isset($_GET['page'])) $_GET['page'] = 1;
  27. $db->query($sql.' LIMIT '.$seiten[1].','.LIMIT_NEWS);
  28. while($row = $db->fetch_assoc()) {
  29. $tpl = new smarty;
  30. $row['bodytext'] = bb_code($row['bodytext']);
  31. $row['extendtext'] = bb_code($row['extendtext']);
  32. $row['datum'] = date(LONG_DATE, $row['datum']);
  33. $row['links'] = news_links($row['links']);
  34. foreach($row AS $key=>$value)
  35. $tpl->assign($key, $value);
  36. $tpl->assign('pic', (file_exists('templates/'.DESIGN.'/images/topics/'.$row['topicbild']))? 'templates/'.DESIGN.'/images/topics/'.$row['topicbild'] : 'images/topics/'.$row['topicbild']);
  37. ob_start();
  38. $tpl->display(DESIGN.'/tpl/news/news.html');
  39. $content = ob_get_contents();
  40. ob_end_clean();
  41. main_content('<a href="?section=news&amp;action=topic&amp;id='.$row['topicID'].'">'.$row['topicname'].'</a>: '.$row['headline'], $content, '',0);
  42. if($row['extendtext'])
  43. @$slids .= 'news_toogle_'.$row['newsID'].' = new Fx.Slide(\'news_'.$row['newsID'].'\'); news_toogle_'.$row['newsID'].'.hide();';
  44. }
  45. if($seiten[0] > 1)
  46. table(PAGES,'<div style="text-align:center">'.NEWS.': '.$anzahl.' | <a href="?section=news&amp;action=archiv">'.NEWS_ARCHIV.'</a> | '.PAGES.': '.makepagelink('?section=news&action=topic&id='.$topicID, $_GET['page'], $seiten[0]).'</div>');
  47. if(isset($slids)) echo '<script type="text/javascript">window.addEvent(\'domready\', function() { '.@$slids.' } );</script>';
  48. } else {
  49. table(INFO, NO_ENTRIES);
  50. }
  51. }
  52. function news_archiv($topicID = 0) {
  53. global $db;
  54. $topics = array();
  55. $db->query('SELECT tID, topicname FROM '.DB_PRE.'ecp_topics ORDER BY topicname ASC');
  56. while($row = $db->fetch_assoc()) $topics[] = $row;
  57. if($topicID) {
  58. $anzahl = $db->result(DB_PRE.'ecp_news', 'COUNT(newsID)', '(lang = "" OR lang LIKE ",%'.LANGUAGE.'%,") AND topicID = '.$topicID.' AND '.DB_PRE.'ecp_news.datum < '.time().' AND (access = "" OR '.$_SESSION['access_search'].')');
  59. $seiten = get_sql_limit($anzahl, 30);
  60. $sql = 'SELECT `newsID`, `'.DB_PRE.'ecp_news`.`userID`, `topicID`, `'.DB_PRE.'ecp_news`.`datum`, `headline`, `bodytext`, `extendtext`, `links`, `hits`,
  61. `username`, `topicname`, `topicbild`, `beschreibung`, COUNT(comID) AS comments
  62. FROM '.DB_PRE.'ecp_news
  63. LEFT JOIN '.DB_PRE.'ecp_user ON ('.DB_PRE.'ecp_news.userID = ID)
  64. LEFT JOIN '.DB_PRE.'ecp_topics ON (topicID = tID)
  65. LEFT JOIN '.DB_PRE.'ecp_comments ON (subID = newsID AND bereich = "news")
  66. WHERE (lang = "" OR lang LIKE ",%'.LANGUAGE.'%,") AND topicID = '.$topicID.' AND '.DB_PRE.'ecp_news.datum < '.time().' AND (access = "" OR '.$_SESSION['access_search'].') GROUP BY newsID ORDER BY sticky DESC, datum DESC';
  67. } else {
  68. $anzahl = $db->result(DB_PRE.'ecp_news', 'COUNT(newsID)', '(lang = "" OR lang LIKE ",%'.LANGUAGE.'%,") AND '.DB_PRE.'ecp_news.datum < '.time().' AND (access = "" OR '.$_SESSION['access_search'].')');
  69. $seiten = get_sql_limit($anzahl, 30);
  70. $sql = 'SELECT `newsID`, `'.DB_PRE.'ecp_news`.`userID`, `topicID`, `'.DB_PRE.'ecp_news`.`datum`, `headline`, `bodytext`, `extendtext`, `links`, `hits`,
  71. `username`, `topicname`, `topicbild`, `beschreibung`, COUNT(comID) AS comments
  72. FROM '.DB_PRE.'ecp_news
  73. LEFT JOIN '.DB_PRE.'ecp_user ON ('.DB_PRE.'ecp_news.userID = ID)
  74. LEFT JOIN '.DB_PRE.'ecp_topics ON (topicID = tID)
  75. LEFT JOIN '.DB_PRE.'ecp_comments ON (subID = newsID AND bereich = "news")
  76. WHERE (lang = "" OR lang LIKE ",%'.LANGUAGE.'%,") AND '.DB_PRE.'ecp_news.datum < '.time().' AND (access = "" OR '.$_SESSION['access_search'].') GROUP BY newsID ORDER BY sticky DESC, datum DESC';
  77. }
  78. if($anzahl) {
  79. if(!isset($_GET['page'])) $_GET['page'] = 1;
  80. $db->query($sql.' LIMIT '.$seiten[1].', 30');
  81. $news = array();
  82. while($row = $db->fetch_assoc()) {
  83. $row['datum'] = date(LONG_DATE, $row['datum']);
  84. $row['comments'] = format_nr($row['comments']);
  85. $row['hits'] = format_nr($row['hits']);
  86. $news[] = $row;
  87. }
  88. $tpl = new smarty;
  89. $tpl->assign('topics', $topics);
  90. $tpl->assign('news', $news);
  91. ob_start();
  92. $tpl->display(DESIGN.'/tpl/news/news_archiv.html');
  93. $content = ob_get_contents();
  94. ob_end_clean();
  95. main_content(NEWS_ARCHIV, $content, '', 1);
  96. if($seiten[0] > 1)
  97. table(PAGES,'<div style="text-align:center">'.NEWS.': '.$anzahl.' | '.PAGES.': '.makepagelink('?section=news&action=archiv&tid='.$topicID, $_GET['page'], $seiten[0]).'</div>');
  98. } else {
  99. table(INFO, NO_ENTRIES);
  100. }
  101. }
  102. function news_once($id) {
  103. global $db;
  104. $anzahl = $db->result(DB_PRE.'ecp_news', 'COUNT(newsID)', '(lang = "" OR lang LIKE ",%'.LANGUAGE.'%,") AND '.DB_PRE.'ecp_news.datum < '.time().' AND (access = "" OR '.$_SESSION['access_search'].') AND newsID = '.$id);
  105. if(!isset($_SESSION['news'][(int)$_GET['id']])) {
  106. if($db->query('UPDATE '.DB_PRE.'ecp_news SET hits = hits + 1 WHERE newsID = '.(int)$_GET['id'])) {
  107. $_SESSION['news'][(int)$_GET['id']] = true;
  108. }
  109. }
  110. $sql = 'SELECT `newsID`, `'.DB_PRE.'ecp_news`.`userID`, `topicID`, `'.DB_PRE.'ecp_news`.`datum`, `headline`, `bodytext`, `extendtext`, `links`, `hits`,
  111. `username`, `topicname`, `topicbild`, `beschreibung`
  112. FROM '.DB_PRE.'ecp_news
  113. LEFT JOIN '.DB_PRE.'ecp_user ON ('.DB_PRE.'ecp_news.userID = ID)
  114. LEFT JOIN '.DB_PRE.'ecp_topics ON (topicID = tID)
  115. WHERE (lang = "" OR lang LIKE ",%'.LANGUAGE.'%,") AND '.DB_PRE.'ecp_news.datum < '.time().' AND (access = "" OR '.$_SESSION['access_search'].') AND newsID = '.$id.' GROUP BY newsID';
  116. if($anzahl) {
  117. $db->query($sql);
  118. while($row = $db->fetch_assoc()) {
  119. $tpl = new smarty;
  120. $tpl->assign('comment', 1);
  121. $row['bodytext'] = bb_code($row['bodytext']);
  122. $row['extendtext'] = bb_code($row['extendtext']);
  123. $row['datum'] = date(LONG_DATE, $row['datum']);
  124. $row['links'] = news_links($row['links']);
  125. foreach($row AS $key=>$value)
  126. $tpl->assign($key, $value);
  127. $tpl->assign('pic', (file_exists('templates/'.DESIGN.'/images/topics/'.$row['topicbild']))? 'templates/'.DESIGN.'/images/topics/'.$row['topicbild'] : 'images/topics/'.$row['topicbild']);
  128. ob_start();
  129. $tpl->display(DESIGN.'/tpl/news/news.html');
  130. $content = ob_get_contents();
  131. ob_end_clean();
  132. main_content('<a href="?section=news&amp;action=topic&amp;id='.$row['topicID'].'">'.$row['topicname'].'</a>: '.$row['headline'], $content, '',0);
  133. }
  134. } else {
  135. table(INFO, NO_ENTRIES_ID);
  136. }
  137. }
  138. $conditions = array('LIMIT' => LIMIT_COMMENTS,
  139. 'ORDER' => COMMENTS_ORDER,
  140. 'SPAM' => SPAM_NEWS_COMMENTS,
  141. 'section' => 'news');
  142. if(isset($_GET['action'])) {
  143. switch($_GET['action']) {
  144. case 'topic':
  145. news((int)@$_GET['id']);
  146. break;
  147. case 'archiv':
  148. news_archiv((int)@$_GET['tid']);
  149. break;
  150. case 'comments':
  151. if(@$_SESSION['rights']['public']['news']['com_view'] OR @$_SESSION['rights']['superadmin']) {
  152. news_once((int)$_GET['id']);
  153. $conditions['action'] = 'add';
  154. $conditions['link'] = '?section=news&action=comments&id='.(int)$_GET['id'];
  155. comments_get('news', (int)$_GET['id'], $conditions);
  156. } else
  157. echo table(ACCESS_DENIED, NO_ACCESS_RIGHTS);
  158. break;
  159. case 'addcomment':
  160. if(@$_SESSION['rights']['public']['news']['com_add'] OR @$_SESSION['rights']['superadmin']) {
  161. $conditions['action'] = 'add';
  162. $conditions['link'] = '?section=news&action=comments&id='.(int)$_GET['id'];
  163. comments_add('news', (int)$_GET['id'], $conditions);
  164. } else
  165. echo table(ACCESS_DENIED, NO_ACCESS_RIGHTS);
  166. break;
  167. case 'editcomment':
  168. $conditions['action'] = 'edit';
  169. $conditions['link'] = '?section=news&action=comments&id='.(int)$_GET['subid'];
  170. comments_edit('news', (int)$_GET['subid'], (int)$_GET['id'], $conditions);
  171. break;
  172. default:
  173. if(@$_SESSION['rights']['public']['news']['view'] OR @$_SESSION['rights']['superadmin'])
  174. news();
  175. else
  176. echo table(ACCESS_DENIED, NO_ACCESS_RIGHTS);
  177. }
  178. } else {
  179. if(@$_SESSION['rights']['public']['news']['view'] OR @$_SESSION['rights']['superadmin'])
  180. news();
  181. else
  182. echo table(ACCESS_DENIED, NO_ACCESS_RIGHTS);
  183. }
  184. ?>