Просмотр файла modules/share/file.php

Размер файла: 4.8Kb
  1. <?php
  2. /**********************************
  3. * @package: PerfCMS *
  4. * @year: 2012 *
  5. * @author: Artas *
  6. * @link: http://perfcms.ru *
  7. **********************************/
  8. $locate = 'in_share';
  9. if(!isset($_GET['id'])) { go('/share/'); }
  10. $id = abs(intval($_GET['id']));
  11. if($db->query("SELECT * FROM `share_files` WHERE `id` = '". $id ."'")->rowCount() == 0) {
  12. $title = $lang->word('share');
  13. require_once(SYS.'/view/header.php');
  14. $tpl->div('menu', $lang->word('file_not_exists'));
  15. $tpl->div('block', NAV.' <a href="/share/">'. $lang->word('share') .'</a><br/>' . HICO .' <a href="/">'. $lang->word('home') .'</a>');
  16. require_once(SYS.'/view/footer.php');
  17. exit;
  18. }
  19. $file_a = $db->query("SELECT * FROM `share_files` WHERE `id` = '". $id ."'")->fetch();
  20. $file_ra = $db->query("SELECT * FROM `share_rating` WHERE `file_id` = '". $id ."' ORDER BY rating DESC")->fetch();
  21. $file_ar = $db->query("SELECT * FROM `share_rating` WHERE `file_id` = '". $id ."'")->rowCount();
  22. if(isset($_GET['act']) && $_GET['act'] == 'rate') {
  23. $rates = abs(intval($_POST['rate']));
  24. $rate = ($rates < 1 ? 1 : ($rates > 5 ? 5 : $rates));
  25. $db->query("INSERT INTO `share_rating` SET `rating` = '". ($file_ra['rating']+$rate)."', `rated` = '". ($file_ra['rated']+1) ."', `user_id` = '". $user['id'] ."', `file_id` = '". $id."'");
  26. header('location: /share/file/'.$file_a['id'].'/');
  27. exit;
  28. }
  29. if(isset($_GET['delete_screen']) && file_exists(ROOT.'/files/preview/'.$file_a['path_name'].'.png') && ($user['id'] == $file_a['user_id'] || $user['level'] >= 4))
  30. {
  31. unlink(ROOT.'/files/preview/'.$file_a['path_name'].'.png');
  32. header('location: /share/file/'.$file_a['id']);
  33. exit;
  34. }
  35. $title = $file_a['name'] .' | '. $lang->word('share');
  36. require_once(SYS .'/view/header.php');
  37. $tpl->div('title', $file_a['name']);
  38. $file_q = $db->query("SELECT * FROM `share_files` WHERE `id` = '". $id ."'");
  39.  
  40. while($file = $file_q->fetch()) {
  41. if($file_ra['rating'] != 0) {
  42. $rating = ($file_ra['rating']/$file_ra['rated']);
  43. }
  44. else {
  45. $rating = 0;
  46. }
  47. echo '<div class="menu">
  48. '.(preg_match('/jpeg|jpg|gif|png|bmp/i', $file['ext']) ? '<img style="border: 1px solid #000;" weight="80" height="60" src="/files/share/'. $file['path_name'] .'" alt="Screen" /><br/>'."\n" : (file_exists(ROOT.'/files/preview/'.$file['path_name'].'.png') ? '<a href="/files/preview/'.$file['path_name'].'.png"><img style="border: 1px solid #000;" weight="100" height="80" src="/files/preview/'.$file['path_name'].'.png" alt="Screen" /></a><br/>'."\n" : NULL)) .'
  49. '. output($file['text']) .'
  50. </div>
  51. <div class="post">
  52. '.img('download.png').' <a href="/share/download/'. $file['id'] .'/">'. $lang->word('download') .' '.strtoupper($file['ext']).'</a> ('.size($file['size']).')<br/>
  53. '. NAV . $lang->word('uploader').': <a href="/user/'.$file['user_id'].'">'. tnick($file['user_id']) .'</a> ('.rtime($file['time']).')<br/>
  54. '. img('globe.png') . $lang->word('downloaded').': '.$file['dload_times'].'<br/>
  55. '.($user['id'] == $file['user_id'] || $user['level'] == 4 || $user['level'] >=6 ? img('delete.png') .' <a href="/share/delete_file/?file_id='. $file['id'] .'">'. $lang->word('delete').'</a><br/>
  56. '.img('edit.png').' <a href="/share/edit_file/'. $file['id'].'/">'. $lang->word('edit') .'</a><br/>' : NULL).'
  57. '.($user['id'] == $file['user_id'] || $user['level'] == 4 || $user['level'] >=6 ? (file_exists(ROOT.'/files/preview/'.$file['path_name'].'.png') ? img('image.png').' <a href="/share/file/'.$file['id'].'?delete_screen">'. $lang->word('screenshot_delete').'</a><br/>' : img('image.png').' <a href="/share/add_screen?file_id='.$file['id'].'">'. $lang->word('screenshot_add').'</a><br/>') : NULL) .'
  58. </div>
  59. <div class="post">
  60. '.$lang->word('rating').': <b>'. round($rating, 1) .'</b><br/>
  61. '.($db->query("SELECT * FROM `share_rating` WHERE `user_id` = '". $user['id'] ."' AND `file_id` = '". $file['id'] ."'")->rowCount() == 0 ?
  62. '<form action="/share/file/'.$file['id'].'/?act=rate" method="post">
  63. <select name="rate">
  64. <option value="1">1</option>
  65. <option value="2">2</option>
  66. <option value="3">3</option>
  67. <option value="4">4</option>
  68. <option value="5">5</option>
  69. </select>
  70. <input type="submit" value="'.$lang->word('vote').'" />
  71. </form>' : NULL).'
  72. </div>
  73. ';
  74. }
  75. $tpl->div('block', NAV.' <a href="/share/'. $file_a['id'] .'/comments/">'. $lang->word('comments') .'</a> ('. $db->query("SELECT * FROM `share_comms` WHERE `share_id` = '". $file_a['id'] ."'")->rowCount().')<br/>' . NAV.'<a href="/share/folder/'. $file_a['cat_id'] .'/">'. $db->query("SELECT name FROM `share_c` WHERE `id` = '". $file_a['cat_id'] ."'")->fetchColumn() .'</a><br/>' . NAV .'<a href="/share/">'. $lang->word('share') .'</a><br/>' . HICO .'<a href="/">'. $lang->word('home') .'</a>');
  76. require_once(SYS .'/view/footer.php');
  77. ?>