thread_poll.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: thread_poll.php 36284 2016-12-12 00:47:50Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $polloptions = array();
  12. $votersuid = '';
  13. if($count = C::t('forum_polloption')->fetch_count_by_tid($_G['tid'])) {
  14. $options = C::t('forum_poll')->fetch($_G['tid']);
  15. if($options['isimage']) {
  16. $pollimages = C::t('forum_polloption_image')->fetch_all_by_tid($_G['tid']);
  17. require_once libfile('function/home');
  18. }
  19. $isimagepoll = $options['isimage'] ? true : false;
  20. $multiple = $options['multiple'];
  21. $visible = $options['visible'];
  22. $maxchoices = $options['maxchoices'];
  23. $expiration = $options['expiration'];
  24. $overt = $options['overt'];
  25. $voterscount = $options['voters'];
  26. $query = C::t('forum_polloption')->fetch_all_by_tid($_G['tid'], 1);
  27. $colors = array('E92725', 'F27B21', 'F2A61F', '5AAF4A', '42C4F5', '0099CC', '3365AE', '2A3591', '592D8E', 'DB3191');
  28. $voterids = $polloptionpreview = '';
  29. $ci = 0;
  30. $opts = 1;
  31. foreach($query as $options) {
  32. $viewvoteruid[] = $options['voterids'];
  33. $voterids .= "\t".$options['voterids'];
  34. $option = preg_replace("/\[url=(https?){1}:\/\/([^\[\"']+?)\](.+?)\[\/url\]/i", "<a href=\"\\1://\\2\" target=\"_blank\">\\3</a>", $options['polloption']);
  35. $attach = array();
  36. if($isimagepoll && $pollimages[$options['polloptionid']]) {
  37. $attach = $pollimages[$options['polloptionid']];
  38. $attach['small'] = pic_get($attach['attachment'], 'forum', $attach['thumb'], $attach['remote']);
  39. $attach['big'] = pic_get($attach['attachment'], 'forum', 0, $attach['remote']);
  40. }
  41. $polloptions[$opts++] = array
  42. (
  43. 'polloptionid' => $options['polloptionid'],
  44. 'polloption' => $option,
  45. 'votes' => $options['votes'],
  46. 'width' => $options['votes'] > 0 ? (@round($options['votes'] * 100 / $count['total'])).'%' : '8px',
  47. 'percent' => $count['total'] ? sprintf("%01.2f", $options['votes'] * 100 / $count['total']) : 0,
  48. 'color' => $colors[$ci],
  49. 'imginfo' => $attach
  50. );
  51. if($ci < 2) {
  52. $polloptionpreview .= $option."\t";
  53. }
  54. $ci++;
  55. if($ci == count($colors)) {
  56. $ci = 0;
  57. }
  58. }
  59. $voterids = explode("\t", $voterids);
  60. $voters = array_unique($voterids);
  61. array_shift($voters);
  62. if(!$expiration) {
  63. $expirations = TIMESTAMP + 86400;
  64. } else {
  65. $expirations = $expiration;
  66. if($expirations > TIMESTAMP) {
  67. $_G['forum_thread']['remaintime'] = remaintime($expirations - TIMESTAMP);
  68. }
  69. }
  70. $allwvoteusergroup = $_G['group']['allowvote'];
  71. $allowvotepolled = !in_array(($_G['uid'] ? $_G['uid'] : $_G['clientip']), $voters);
  72. $allowvotethread = ($_G['forum_thread']['isgroup'] || !$_G['forum_thread']['closed'] && !checkautoclose($_G['forum_thread']) || $_G['group']['alloweditpoll']) && TIMESTAMP < $expirations && $expirations > 0;
  73. $_G['group']['allowvote'] = $allwvoteusergroup && $allowvotepolled && $allowvotethread;
  74. $optiontype = $multiple ? 'checkbox' : 'radio';
  75. $visiblepoll = $visible || $_G['forum']['ismoderator'] || ($_G['uid'] && $_G['uid'] == $_G['forum_thread']['authorid']) || ($expirations >= TIMESTAMP && in_array(($_G['uid'] ? $_G['uid'] : $_G['clientip']), $voters)) || $expirations < TIMESTAMP ? 0 : 1;
  76. }
  77. ?>