Просмотр файла forum/includes/functions.php

Размер файла: 5.44Kb
  1. <?php
  2.  
  3.  
  4. $forum = isset ($_GET['forum']) ? abs(intval($_GET['forum'])) : false;
  5. $topic = isset ($_REQUEST['topic']) ? abs(intval($_REQUEST['topic'])) : false;
  6. $post = isset ($_REQUEST['post']) ? abs(intval($_REQUEST['post'])) : false;
  7. $file = isset ($_REQUEST['file']) ? abs(intval($_REQUEST['file'])) : false;
  8.  
  9.  
  10. function forum_counter($num = 0){
  11. global $sql;
  12. if (Core::$user_id){
  13. $total = $sql->query("SELECT COUNT(*) FROM `forum_topics` LEFT JOIN `forum_readed` ON `forum_topics`.`id` = `forum_readed`.`topic` AND `forum_readed`.`user_id` = '".Core::$user_id."' WHERE (`forum_readed`.`topic` Is Null OR `forum_topics`.`time` > `forum_readed`.`time`) ")->result();
  14. if ($num == 1){
  15. return $total;
  16. }elseif($num == 2){
  17. if ($total)
  18. return ' <span class="err"><a href="index.php?act=last&amp;unread">+'.$total.'</a></span>';
  19. else
  20. return false;
  21. }else{
  22. return '<a href="index.php?act=last&amp;unread"><div class="menu_razd">Непрочитанные'.($total ? ' <span class="err">('.$total.')</span>' : '').'</div></a>
  23. <a href="index.php?act=my&amp;journal"><div class="menu_razd">Журнал форума'.(journal_new() ? journal_new() : '').'</div></a>';
  24. }
  25. }
  26. }
  27.  
  28. function quote ($text = ''){
  29. return preg_replace('#\[quote=(.+?)](.+?)\[/quote]#is', '<div class="p_m">$1 писал(а)</div><div class="post">$2</div>', $text);
  30. }
  31.  
  32. function show_file($file = array()){
  33. $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
  34. $fls = round(filesize('../forum/files/attach/'.$file['name']) / 1024, 2);
  35. $out = '<img src="/forum/images/attach.gif" alt="+" /><a href="index.php?act=download&amp;file='.$file['id'].'">'.$file['name'].'</a>';
  36. if ($ext == 'jar')
  37. $out .= ' | <a href="/forum/index.php?act=download&amp;file='.$file['id'].'&amp;jad">jad</a>';
  38. $out .= ' ('.$fls.' кб.) Скачали: '.$file['down'].' раз.';
  39. return $out;
  40. }
  41.  
  42. function show_folder($folder = array()){
  43. global $admin, $sql;
  44. if (file_exists(('../forum/files/icons/'.$folder['id'].'.png')))
  45. $out = '<img src="../files/forum/icons/'.$folder['id'].'.png" alt="" />';
  46. else
  47. $out = '<img src="images/folder.png" alt="-" />';
  48. $out .= ' <a href="index.php?forum='.$folder['id'].'"><strong>'.text::output($folder['name']).'</strong></a>'.($folder['type'] ? ' ('.$folder['count'].')' : '');
  49. if ($admin){
  50. $out .= ' | <a href="javascript:show_hide(\'adm'.$folder['id'].'\');">Адм.</a><span id="adm'.$folder['id'].'" style="display: none; font-size: x-small;"> <a href="index.php?act=moveforum&amp;forum='.$folder['id'].'&amp;up">Вверх</a> <a href="index.php?act=moveforum&amp;forum='.$folder['id'].'&amp;down">Вниз</a> <a href="index.php?act=editforum&amp;forum='.$folder['id'].'">Изменить</a> <a href="index.php?act=delforum&amp;forum='.$folder['id'].'">Удалить</a></span>';
  51. }
  52. if ($folder['text'])
  53. $out .= '<div>'.text::output($folder['text'], 1, 1).'</div>';
  54. return $out;
  55. }
  56.  
  57. function show_topic($res, $sub = 0, $new = 0){
  58. global $sql;
  59. $out = '';
  60. /*
  61. if ($user_id && !$new){
  62. $readed = $sql->query("SELECT COUNT(*) FROM `forum_readed` WHERE `time` >= '".$res['time']."' AND `topic` = '".$res['id']."' AND `user_id` = '".$user_id."' LIMIT 1 ")->result();
  63. $out .= $readed ? '' : '<img src="images/new.png" alt="+" title="Есть новые сообщения" /> ';
  64. }*/
  65. $out .= '<img src="/forum/images/topic.png" alt="-" /> ';
  66. if ($res['close'])
  67. $out .= '<img src="/forum/images/close.png" alt="#" title="Тема закрыта" /> ';
  68. if ($res['sticky'])
  69. $out .= '<img src="/forum/images/sticky.png" alt="^" title="Тема закреплена" /> ';
  70. if ($res['poll_name'])
  71. $out .= '<img src="/forum/images/poll.png" alt="*" title="Голосование" /> ';
  72.  
  73. $out .= '<a href="/forum/index.php?topic='.$res['id'].'"><strong>'.text::output($res['name']).'</strong></a> ('.$res['count'].')';
  74. /*
  75. if ($user_id && (!$readed || $new))
  76. $out .= ' <a href="/forum/index.php?topic='.$res['id'].'&amp;unread">Новые</a>';
  77. */
  78.  
  79. $out .= ' <a href="/forum/index.php?topic='.$res['id'].'&amp;page=end" title="К последней странице"> &gt;&gt;</a>';
  80.  
  81. if ($sub)
  82. $out .= '<div class="sub">'.$sub.'</div>';
  83. return $out;
  84. }
  85.  
  86. function text($text){
  87. return htmlentities($text, ENT_QUOTES, 'UTF-8');
  88. }
  89.  
  90. function title($string){
  91. $out = strtr($string, array('&quot;' => '', '&amp;' => '', '&lt;' => '', '&gt;' => '', '&#039;' => ''));
  92. $out = mb_strlen($string) > 50 ? mb_substr($out, 0, 50).'...' : $out;
  93. return text::output($out);
  94. }
  95.  
  96. function translit($str, $direction = 0){
  97. $ru = array('а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ь','ы','ъ','э','ю','я','А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ь','Ы','Ъ','Э','Ю','Я',' ','ґ','ї','є','Ґ','Ї','Є');
  98. $en = array('a','b','v','g','d','e','yo','zh','z','i','y','k','l','m','n','o','p','r','s','t','u','f','h','c','ch','sh','sh','','y','','e','u','ya','A','B','V','G','D','E','YO','ZH','Z','I','Y','K','L','M','N','O','P','R','S','T','U','F','H','C','CH','SH','SH','','Y','','E','U','YA','_','gg','ji','ye','GG','JI','YE');
  99. if ($direction == 0)
  100. return str_replace($ru, $en, $str);
  101. else
  102. return str_replace($en, $ru, $str);
  103. }