Advertisement
Guest User

pollphp

a guest
Feb 12th, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.85 KB | None | 0 0
  1. <?php
  2. /*======================================================================*\
  3. || #################################################################### ||
  4. || # vBulletin 4.1.8
  5. || # ---------------------------------------------------------------- # ||
  6. || # Copyright ©2000-2011 vBulletin Solutions Inc. All Rights Reserved. ||
  7. || # This file may not be redistributed in whole or significant part. # ||
  8. || # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
  9. || # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
  10. || #################################################################### ||
  11. \*======================================================================*/
  12.  
  13. // ####################### SET PHP ENVIRONMENT ###########################
  14. error_reporting(E_ALL & ~E_NOTICE);
  15.  
  16. // #################### DEFINE IMPORTANT CONSTANTS #######################
  17. define('THIS_SCRIPT', 'poll');
  18. define('CSRF_PROTECTION', true);
  19.  
  20. // ################### PRE-CACHE TEMPLATES AND DATA ######################
  21. // get special phrase groups
  22. $phrasegroups = array('poll', 'posting');
  23.  
  24. // get special data templates from the datastore
  25. $specialtemplates = array(
  26. 'smiliecache',
  27. 'bbcodecache'
  28. );
  29.  
  30. // pre-cache templates used by all actions
  31. $globaltemplates = array(
  32. 'editpoll',
  33. 'forumrules',
  34. 'newpoll',
  35. 'newpost_usernamecode',
  36. 'polleditbit',
  37. 'pollnewbit',
  38. 'pollpreview',
  39. 'pollpreviewbit',
  40. 'pollresult',
  41. 'pollresults',
  42. 'pollresults_table',
  43. );
  44.  
  45. // pre-cache templates used by specific actions
  46. $actiontemplates = array();
  47.  
  48. // ######################### REQUIRE BACK-END ############################
  49. require_once('./global.php');
  50. require_once(DIR . '/includes/class_bbcode_alt.php');
  51.  
  52. // #######################################################################
  53. // ######################## START MAIN SCRIPT ############################
  54. // #######################################################################
  55.  
  56. verify_forum_url();
  57.  
  58. if (empty($_REQUEST['do']))
  59. {
  60. $_REQUEST['do'] = 'newpoll';
  61. }
  62.  
  63. // shortcut function to make the $navbits for the navbar...
  64. function construct_poll_nav($foruminfo, $threadinfo)
  65. {
  66. global $vbulletin, $vbphrase;
  67.  
  68. $navbits = array();
  69. $navbits[fetch_seo_url('forumhome', array())] = $vbphrase['forum'];
  70. $parentlist = array_reverse(explode(',', substr($foruminfo['parentlist'], 0, -3)));
  71.  
  72. foreach ($parentlist AS $forumID)
  73. {
  74. $forumTitle = $vbulletin->forumcache["$forumID"]['title'];
  75. $navbits[fetch_seo_url('forum', array('forumid' => $forumID, 'title' => $forumTitle))] = $forumTitle;
  76. }
  77. $navbits[fetch_seo_url('thread', $threadinfo)] = $threadinfo['prefix_plain_html'] . ' ' . $threadinfo['title'];
  78.  
  79. switch ($_REQUEST['do'])
  80. {
  81. case 'newpoll': $navbits[''] = $vbphrase['post_a_poll']; break;
  82. case 'polledit': $navbits[''] = $vbphrase['edit_poll']; break;
  83. case 'showresults': $navbits[''] = $vbphrase['view_poll_results']; break;
  84. // are there more?
  85. }
  86.  
  87. return construct_navbits($navbits);
  88. }
  89.  
  90. if ($threadinfo['isdeleted'] OR (!$threadinfo['visible'] AND !can_moderate($threadinfo['forumid'], 'canmoderateposts') AND $vbulletin->userinfo['userid'] != $threadinfo['postuserid']))
  91. {
  92. eval(standard_error(fetch_error('invalidid', $vbphrase['thread'], $vbulletin->options['contactuslink'])));
  93. }
  94.  
  95. if (!$foruminfo['forumid'])
  96. {
  97. eval(standard_error(fetch_error('invalidid', $vbphrase['forum'], $vbulletin->options['contactuslink'])));
  98. }
  99.  
  100. // check permissions
  101. $forumperms = fetch_permissions($foruminfo['forumid']);
  102. if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview']))
  103. {
  104. print_no_permission();
  105. }
  106.  
  107. if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads']))
  108. {
  109. if (($_POST['do'] != 'postpoll' AND $_REQUEST['do'] != 'newpoll') OR $threadinfo['postuserid'] != $vbulletin->userinfo['userid'] OR !$vbulletin->userinfo['userid'])
  110. {
  111. print_no_permission();
  112. }
  113. }
  114.  
  115. // check if there is a forum password and if so, ensure the user has it set
  116. verify_forum_password($foruminfo['forumid'], $foruminfo['password']);
  117.  
  118. ($hook = vBulletinHook::fetch_hook('poll_start')) ? eval($hook) : false;
  119.  
  120. // ############################### start post poll ###############################
  121. if ($_POST['do'] == 'postpoll')
  122. {
  123. // Reused in template
  124. $polloptions = $vbulletin->input->clean_gpc('p', 'polloptions', TYPE_UINT);
  125. $question = $vbulletin->input->clean_gpc('p', 'question', TYPE_NOHTML);
  126. $timeout = $vbulletin->input->clean_gpc('p', 'timeout', TYPE_UINT);
  127.  
  128. $vbulletin->input->clean_array_gpc('p', array(
  129. 'preview' => TYPE_STR,
  130. 'updatenumber' => TYPE_STR,
  131. 'public' => TYPE_BOOL,
  132. 'parseurl' => TYPE_BOOL,
  133. 'multiple' => TYPE_BOOL,
  134. 'options' => TYPE_ARRAY_STR
  135. ));
  136.  
  137. ($hook = vBulletinHook::fetch_hook('poll_post_start')) ? eval($hook) : false;
  138.  
  139. if ($threadinfo['pollid'])
  140. {
  141. eval(standard_error(fetch_error('pollalready')));
  142. }
  143.  
  144. if ($vbulletin->userinfo['userid'] != $threadinfo['postuserid'] AND !can_moderate($foruminfo['forumid'], 'caneditpoll'))
  145. {
  146. print_no_permission();
  147. }
  148.  
  149. // check permissions
  150. if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostnew']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostpoll']))
  151. {
  152. print_no_permission();
  153. }
  154.  
  155. if (!can_moderate($threadinfo['forumid'], 'caneditpoll') AND $vbulletin->options['addpolltimeout'] AND TIMENOW - ($vbulletin->options['addpolltimeout'] * 60) > $threadinfo['dateline'])
  156. {
  157. eval(standard_error(fetch_error('polltimeout', $vbulletin->options['addpolltimeout'])));
  158. }
  159.  
  160. if (!$threadinfo['open'])
  161. {
  162. eval(standard_error(fetch_error('threadclosed')));
  163. }
  164.  
  165. if ($vbulletin->options['maxpolloptions'] > 0 AND $polloptions > $vbulletin->options['maxpolloptions'])
  166. {
  167. $polloptions = $vbulletin->options['maxpolloptions'];
  168. }
  169.  
  170. if ($vbulletin->GPC['parseurl'] AND $foruminfo['allowbbcode'])
  171. {
  172. require_once(DIR . '/includes/functions_newpost.php');
  173.  
  174. $counter = 0;
  175. while ($counter++ < $polloptions)
  176. { // 0..Pollnum-1 we want, as arrays start with 0
  177. $vbulletin->GPC['options']["$counter"] = convert_url_to_bbcode($vbulletin->GPC['options']["$counter"]);
  178. }
  179. }
  180.  
  181. // check question and if 2 options or more were given
  182. $counter = 0;
  183. $optioncount = 0;
  184. $badoption = '';
  185. while ($counter++ < $polloptions)
  186. { // 0..Pollnum-1 we want, as arrays start with 0
  187. if ($vbulletin->options['maxpolllength'] AND vbstrlen($vbulletin->GPC['options']["$counter"]) > $vbulletin->options['maxpolllength'])
  188. {
  189. $badoption .= iif($badoption, ', ') . $counter;
  190. }
  191. if (!empty($vbulletin->GPC['options']["$counter"]))
  192. {
  193. $optioncount++;
  194. }
  195. }
  196.  
  197. if ($badoption)
  198. {
  199. eval(standard_error(fetch_error('polloptionlength', $vbulletin->options['maxpolllength'], $badoption)));
  200. }
  201.  
  202. $bbcode_parser = new vB_BbCodeParser($vbulletin, fetch_tag_list());
  203.  
  204. if ($vbulletin->GPC['preview'] != '' OR $vbulletin->GPC['updatenumber'] != '')
  205. {
  206. if ($vbulletin->GPC['preview'] != '')
  207. {
  208. $previewpost = 1;
  209.  
  210. $counter = 0;
  211. $pollpreview = '';
  212. $previewquestion = $bbcode_parser->parse(unhtmlspecialchars($question), $foruminfo['forumid'], $foruminfo['allowsmilies']);
  213. $pollpreviewbits = '';
  214. while ($counter++ < $polloptions)
  215. {
  216. $option = $bbcode_parser->parse($vbulletin->GPC['options']["$counter"], $foruminfo['forumid'], $foruminfo['allowsmilies']);
  217. $templater = vB_Template::create('pollpreviewbit');
  218. $templater->register('option', $option);
  219. $pollpreviewbits .= $templater->render();
  220. }
  221.  
  222. $templater = vB_Template::create('pollpreview');
  223. $templater->register('pollpreviewbits', $pollpreviewbits);
  224. $templater->register('previewquestion', $previewquestion);
  225. $pollpreview = $templater->render();
  226. }
  227.  
  228. $checked = array(
  229. 'multiple' => ($vbulletin->GPC['multiple'] ? 'checked="checked"' : ''),
  230. 'public' => ($vbulletin->GPC['public'] ? 'checked="checked"' : ''),
  231. 'parseurl' => ($vbulletin->GPC['parseurl'] ? 'checked="checked"' : ''),
  232. );
  233.  
  234. $_REQUEST['do'] = 'newpoll';
  235. }
  236. else
  237. {
  238. if ($question == '' OR $optioncount < 2)
  239. {
  240. eval(standard_error(fetch_error('noquestionoption')));
  241. }
  242.  
  243. if (TIMENOW + ($vbulletin->GPC['timeout'] * 86400) >= 2147483647)
  244. { // maximuim size of a 32 bit integer
  245. eval(standard_error(fetch_error('maxpolltimeout')));
  246. }
  247.  
  248. // check max images
  249. if ($vbulletin->options['maximages'])
  250. {
  251. $counter = 0;
  252. while ($counter++ < $polloptions)
  253. { // 0..Pollnum-1 we want, as arrays start with 0
  254. $maximgtest .= $vbulletin->GPC['options']["$counter"];
  255. }
  256.  
  257. $img_parser = new vB_BbCodeParser_ImgCheck($vbulletin, fetch_tag_list());
  258. $parsedmessage = $img_parser->parse($maximgtest . $question, $foruminfo['forumid'], $foruminfo['allowsmilies'], true);
  259.  
  260. require_once(DIR . '/includes/functions_misc.php');
  261. $imagecount = fetch_character_count($parsedmessage, '<img');
  262. if ($imagecount > $vbulletin->options['maximages'])
  263. {
  264. eval(standard_error(fetch_error('toomanyimages', $imagecount, $vbulletin->options['maximages'])));
  265. }
  266. }
  267.  
  268. $question = fetch_censored_text($question);
  269. $counter = 0;
  270. while ($counter++ < $polloptions)
  271. { // 0..Pollnum-1 we want, as arrays start with 0
  272. $vbulletin->GPC['options']["$counter"] = fetch_censored_text($vbulletin->GPC['options']["$counter"]);
  273. }
  274.  
  275. // Add the poll
  276. $poll =& datamanager_init('Poll', $vbulletin, ERRTYPE_STANDARD);
  277.  
  278. $counter = 0;
  279. while ($counter++ < $polloptions)
  280. {
  281. if ($vbulletin->GPC['options']["$counter"] != '')
  282. {
  283. $poll->set_option($vbulletin->GPC['options']["$counter"]);
  284. }
  285. }
  286.  
  287. $poll->set('question', $question);
  288. $poll->set('dateline', TIMENOW);
  289. $poll->set('active', '1');
  290. $poll->set('timeout', $vbulletin->GPC['timeout']);
  291. $poll->set('multiple', $vbulletin->GPC['multiple']);
  292. $poll->set('public', $vbulletin->GPC['public']);
  293.  
  294. ($hook = vBulletinHook::fetch_hook('poll_post_process')) ? eval($hook) : false;
  295.  
  296. $pollid = $poll->save();
  297. //end create new poll
  298.  
  299. // update thread
  300. $threadman =& datamanager_init('Thread', $vbulletin, ERRTYPE_STANDARD, 'threadpost');
  301. $threadman->set_existing($threadinfo);
  302. $threadman->set('pollid', $pollid);
  303. $threadman->save();
  304.  
  305. // update last post icon (if necessary)
  306. cache_ordered_forums(1);
  307.  
  308. if ($vbulletin->forumcache["$threadinfo[forumid]"]['lastthreadid'] == $threadinfo['threadid'])
  309. {
  310. $forumdm =& datamanager_init('Forum', $vbulletin, ERRTYPE_SILENT);
  311. $forumdm->set_existing($vbulletin->forumcache["$threadinfo[forumid]"]);
  312. $forumdm->set('lasticonid', '-1');
  313. $forumdm->save();
  314. unset($forumdm);
  315. }
  316.  
  317. // redirect
  318. if ($threadinfo['visible'] AND $forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads'])
  319. {
  320. $vbulletin->url = fetch_seo_url('thread', $threadinfo);
  321. }
  322. else
  323. {
  324. $vbulletin->url = fetch_seo_url('forum', $foruminfo);
  325. }
  326.  
  327. ($hook = vBulletinHook::fetch_hook('poll_post_complete')) ? eval($hook) : false;
  328.  
  329. if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads']))
  330. {
  331. print_standard_redirect('redirect_postthanks_nopermission');
  332. }
  333. else
  334. {
  335. print_standard_redirect('redirect_postthanks');
  336. }
  337.  
  338. }
  339. }
  340.  
  341. // ############################### start new poll ###############################
  342. if ($_REQUEST['do'] == 'newpoll')
  343. {
  344. // Reused in template.
  345. $polloptions = $vbulletin->input->clean_gpc('r', 'polloptions', TYPE_UINT);
  346.  
  347. ($hook = vBulletinHook::fetch_hook('poll_newform_start')) ? eval($hook) : false;
  348.  
  349. if ($threadinfo['pollid'])
  350. {
  351. eval(standard_error(fetch_error('pollalready')));
  352. }
  353.  
  354. if ($vbulletin->userinfo['userid'] != $threadinfo['postuserid'] AND !can_moderate($foruminfo['forumid'], 'caneditpoll'))
  355. {
  356. print_no_permission();
  357. }
  358.  
  359. // check permissions
  360. if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostnew']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostpoll']))
  361. {
  362. print_no_permission();
  363. }
  364.  
  365. if (!can_moderate($threadinfo['forumid'], 'caneditpoll') AND $vbulletin->options['addpolltimeout'] AND TIMENOW - ($vbulletin->options['addpolltimeout'] * 60) > $threadinfo['dateline'])
  366. {
  367. eval(standard_error(fetch_error('polltimeout', $vbulletin->options['addpolltimeout'])));
  368. }
  369.  
  370. if (!$threadinfo['open'])
  371. {
  372. eval(standard_error(fetch_error('threadclosed')));
  373. }
  374.  
  375. // stop there being too many
  376. if ($vbulletin->options['maxpolloptions'] > 0 AND $polloptions > $vbulletin->options['maxpolloptions'])
  377. {
  378. $polloptions = $vbulletin->options['maxpolloptions'];
  379. }
  380. // stop there being too few
  381. if ($polloptions <= 1)
  382. {
  383. $polloptions = 2;
  384. }
  385.  
  386. $polldate = vbdate($vbulletin->options['dateformat'], TIMENOW);
  387. $polltime = vbdate($vbulletin->options['timeformat'], TIMENOW);
  388.  
  389. $usernamecode = vB_Template::create('newpost_usernamecode')->render();
  390.  
  391. // draw nav bar
  392. $navbits = construct_poll_nav($foruminfo, $threadinfo);
  393. $navbar = render_navbar_template($navbits);
  394.  
  395. require_once(DIR . '/includes/functions_bigthree.php');
  396. construct_forum_rules($foruminfo, $forumperms);
  397.  
  398. $counter = 0;
  399. $option = array();
  400. while ($counter++ < $polloptions)
  401. {
  402. $option['number'] = $counter;
  403. if (is_array($vbulletin->GPC['options']))
  404. {
  405. $option['question'] = htmlspecialchars_uni($vbulletin->GPC['options']["$counter"]);
  406. }
  407. $templater = vB_Template::create('pollnewbit');
  408. $templater->register('option', $option);
  409. $pollnewbits .= $templater->render();
  410. }
  411.  
  412. if (!isset($checked['parseurl']))
  413. {
  414. $checked['parseurl'] = 'checked="checked"';
  415. }
  416.  
  417. $show['parseurl'] = $foruminfo['allowbbcode'];
  418.  
  419. ($hook = vBulletinHook::fetch_hook('poll_newform_complete')) ? eval($hook) : false;
  420.  
  421. $templater = vB_Template::create('newpoll');
  422. $templater->register_page_templates();
  423. $templater->register('checked', $checked);
  424. $templater->register('forumrules', $forumrules);
  425. $templater->register('navbar', $navbar);
  426. $templater->register('polldate', $polldate);
  427. $templater->register('pollnewbits', $pollnewbits);
  428. $templater->register('polloptions', $polloptions);
  429. $templater->register('pollpreview', $pollpreview);
  430. $templater->register('question', $question);
  431. $templater->register('threadid', $threadid);
  432. $templater->register('threadinfo', $threadinfo);
  433. $templater->register('timeout', $timeout);
  434. $templater->register('usernamecode', $usernamecode);
  435. print_output($templater->render());
  436.  
  437. }
  438.  
  439. // ############################### start poll edit ###############################
  440. if ($_REQUEST['do'] == 'polledit')
  441. {
  442. if (!$pollinfo['pollid'])
  443. {
  444. eval(standard_error(fetch_error('invalidid', $vbphrase['poll'], $vbulletin->options['contactuslink'])));
  445. }
  446.  
  447. ($hook = vBulletinHook::fetch_hook('poll_editform_start')) ? eval($hook) : false;
  448.  
  449. // check if user is allowed to do edit
  450. if (!can_moderate($threadinfo['forumid'], 'caneditpoll'))
  451. {
  452. print_no_permission();
  453. }
  454.  
  455. if ($vbulletin->options['maxpolloptions'] > 0 AND $pollinfo['numberoptions'] > $vbulletin->options['maxpolloptions'])
  456. {
  457. $pollinfo['numberoptions'] = $vbulletin->options['maxpolloptions'];
  458. }
  459.  
  460. if (!$pollinfo['active'])
  461. {
  462. $pollinfo['closed'] = 'checked="checked"';
  463. }
  464.  
  465. if($pollinfo['public'])
  466. {
  467. $show['makeprivate'] = true;
  468. $pollinfo['public'] = 'checked="checked"';
  469. }
  470.  
  471. $pollinfo['postdate'] = vbdate($vbulletin->options['dateformat'], $pollinfo['dateline']);
  472. $pollinfo['posttime'] = vbdate($vbulletin->options['timeformat'], $pollinfo['dateline']);
  473.  
  474. // draw nav bar
  475. $navbits = construct_poll_nav($foruminfo, $threadinfo);
  476. $navbar = render_navbar_template($navbits);
  477.  
  478. require_once(DIR . '/includes/functions_bigthree.php');
  479. construct_forum_rules($foruminfo, $forumperms);
  480.  
  481. //get options
  482. $splitoptions = explode('|||', $pollinfo['options']);
  483. $splitoptions = array_map('rtrim', $splitoptions);
  484.  
  485. $splitvotes = explode('|||', $pollinfo['votes']);
  486.  
  487. $counter = 0;
  488. while ($counter++ < $pollinfo['numberoptions'])
  489. {
  490. $pollinfo['numbervotes'] += $splitvotes[$counter - 1];
  491. }
  492.  
  493. $counter = 0;
  494. $pollbits = '';
  495.  
  496. $pollinfo['question'] = $pollinfo['question'];
  497.  
  498. while ($counter++ < $pollinfo['numberoptions'])
  499. {
  500. $option['question'] = htmlspecialchars_uni($splitoptions[$counter - 1]);
  501. $option['votes'] = $splitvotes[$counter - 1]; //get the vote count for the option
  502. $option['number'] = $counter; //number of the option
  503.  
  504. $templater = vB_Template::create('polleditbit');
  505. $templater->register('option', $option);
  506. $pollbits .= $templater->render();
  507. }
  508.  
  509. if ($vbulletin->options['maxpolloptions'] > 0)
  510. {
  511. $show['additional_option1'] = ($pollinfo['numberoptions'] < $vbulletin->options['maxpolloptions']);
  512. $show['additional_option2'] = ($pollinfo['numberoptions'] < ($vbulletin->options['maxpolloptions'] - 1));
  513. }
  514. else
  515. {
  516. $show['additional_option1'] = true;
  517. $show['additional_option2'] = true;
  518. }
  519.  
  520. if (!isset($checked['parseurl']))
  521. {
  522. $checked['parseurl'] = 'checked="checked"';
  523. }
  524.  
  525. $show['parseurl'] = $foruminfo['allowbbcode'];
  526. $usernamecode = vB_Template::create('newpost_usernamecode')->render();
  527.  
  528. ($hook = vBulletinHook::fetch_hook('poll_editform_complete')) ? eval($hook) : false;
  529.  
  530. $templater = vB_Template::create('editpoll');
  531. $templater->register_page_templates();
  532. $templater->register('checked', $checked);
  533. $templater->register('forumrules', $forumrules);
  534. $templater->register('navbar', $navbar);
  535. $templater->register('pollbits', $pollbits);
  536. $templater->register('pollid', $pollid);
  537. $templater->register('pollinfo', $pollinfo);
  538. $templater->register('threadinfo', $threadinfo);
  539. $templater->register('usernamecode', $usernamecode);
  540. print_output($templater->render());
  541. }
  542.  
  543. // ############################### start adding the edit to the db ###############################
  544. if ($_POST['do'] == 'updatepoll')
  545. {
  546. if (!$pollinfo['pollid'])
  547. {
  548. eval(standard_error(fetch_error('invalidid', $vbphrase['poll'], $vbulletin->options['contactuslink'])));
  549. }
  550.  
  551. ($hook = vBulletinHook::fetch_hook('poll_update_start')) ? eval($hook) : false;
  552.  
  553. // check if user is allowed to do edit
  554. if (!can_moderate($threadinfo['forumid'], 'caneditpoll'))
  555. {
  556. print_no_permission();
  557. }
  558.  
  559. $vbulletin->input->clean_array_gpc('p', array(
  560. 'closepoll' => TYPE_BOOL,
  561. 'pollquestion' => TYPE_NOHTML,
  562. 'options' => TYPE_ARRAY_STR,
  563. 'pollvotes' => TYPE_ARRAY_UINT,
  564. 'timeout' => TYPE_UINT,
  565. 'public' => TYPE_BOOL,
  566. 'parseurl' => TYPE_BOOL,
  567. ));
  568.  
  569. $poll =& datamanager_init('Poll', $vbulletin, ERRTYPE_STANDARD);
  570. $poll->set_existing($pollinfo);
  571.  
  572. $optioncount = 0;
  573. require_once(DIR . '/includes/functions_newpost.php');
  574. foreach ($vbulletin->GPC['options'] AS $counter => $optionvalue)
  575. {
  576. if ($optionvalue != '')
  577. {
  578. if ($vbulletin->GPC['parseurl'] AND $foruminfo['allowbbcode'])
  579. {
  580. $optionvalue = convert_url_to_bbcode($optionvalue);
  581. }
  582. $poll->set_option($optionvalue, $counter - 1, intval($vbulletin->GPC['pollvotes']["$counter"]));
  583. $optioncount++;
  584. }
  585. else
  586. {
  587. $poll->set_option('', $counter - 1);
  588. }
  589. }
  590.  
  591. if ($vbulletin->GPC['pollquestion'] == '' OR $optioncount < 2)
  592. {
  593. eval(standard_error(fetch_error('noquestionoption')));
  594. }
  595.  
  596. if (TIMENOW + ($vbulletin->GPC['timeout'] * 86400) >= 2147483647)
  597. { // maximuim size of a 32 bit integer
  598. eval(standard_error(fetch_error('maxpolltimeout')));
  599. }
  600.  
  601. $poll->set('question', $vbulletin->GPC['pollquestion']);
  602. $poll->set('active', $vbulletin->GPC['closepoll'] ? 0 : 1);
  603. $poll->set('timeout', $vbulletin->GPC['timeout']);
  604.  
  605. // only let a poll go from public to private, not the other way about
  606. if ($pollinfo['public'])
  607. {
  608. $poll->set('public', $vbulletin->GPC['public']);
  609. }
  610.  
  611. ($hook = vBulletinHook::fetch_hook('poll_update_process')) ? eval($hook) : false;
  612.  
  613. $poll->save();
  614.  
  615. $pollinfo['threadid'] = $threadinfo['threadid'];
  616. require_once(DIR . '/includes/functions_log_error.php');
  617. log_moderator_action($pollinfo, 'poll_edited');
  618.  
  619. ($hook = vBulletinHook::fetch_hook('poll_update_complete')) ? eval($hook) : false;
  620.  
  621. $vbulletin->url = fetch_seo_url('thread', $threadinfo);
  622. print_standard_redirect('redirect_editthanks');
  623. }
  624.  
  625. // ############################### start show results without vote ###############################
  626. if ($_REQUEST['do'] == 'showresults')
  627. {
  628. if (!$pollinfo['pollid'])
  629. {
  630. eval(standard_error(fetch_error('invalidid', $vbphrase['poll'], $vbulletin->options['contactuslink'])));
  631. }
  632.  
  633. ($hook = vBulletinHook::fetch_hook('poll_results_start')) ? eval($hook) : false;
  634.  
  635. $counter = 1;
  636. $pollbits = '';
  637.  
  638. $bbcode_parser = new vB_BbCodeParser($vbulletin, fetch_tag_list());
  639.  
  640. $pollinfo['question'] = $bbcode_parser->parse(unhtmlspecialchars($pollinfo['question']), $foruminfo['forumid'], 1);
  641.  
  642. $splitoptions = explode('|||', $pollinfo['options']);
  643. $splitoptions = array_map('rtrim', $splitoptions);
  644.  
  645. $splitvotes = explode('|||', $pollinfo['votes']);
  646.  
  647. $pollinfo['numbervotes'] = array_sum($splitvotes);
  648.  
  649. if ($vbulletin->userinfo['userid'] > 0)
  650. {
  651. $pollvotes = $db->query_read_slave("
  652. SELECT voteoption
  653. FROM " . TABLE_PREFIX . "pollvote
  654. WHERE userid = " . $vbulletin->userinfo['userid'] . " AND
  655. pollid = $pollid
  656. ");
  657. $uservote = array();
  658. while ($pollvote = $db->fetch_array($pollvotes))
  659. {
  660. $uservote["$pollvote[voteoption]"] = 1;
  661. }
  662. }
  663.  
  664. if ($pollinfo['public'])
  665. {
  666. $public = $db->query_read_slave("
  667. SELECT user.userid, user.usergroupid, user.displaygroupid, user.username, voteoption, user.infractiongroupid
  668. FROM " . TABLE_PREFIX . "pollvote AS pollvote
  669. INNER JOIN " . TABLE_PREFIX . "user AS user ON (pollvote.userid = user.userid)
  670. WHERE pollid = $pollinfo[pollid]
  671. ORDER BY username ASC
  672. ");
  673.  
  674. $clc = 0;
  675. $last = array();
  676. $allnames = array();
  677. while ($name = $db->fetch_array($public))
  678. {
  679. $clc++;
  680. fetch_musername($name);
  681. $last[$name['voteoption']] = $clc;
  682. $name['comma'] = $vbphrase['comma_space'];
  683. $allnames[$name['voteoption']][$clc] = $name;
  684. }
  685. }
  686.  
  687. // Last elements
  688. foreach ($last AS $voteoption => $value)
  689. {
  690. $allnames[$voteoption][$value]['comma'] = '';
  691. }
  692.  
  693. foreach ($splitvotes AS $index => $value)
  694. {
  695. $option['uservote'] = iif($uservote[$index + 1], '*');
  696. $option['question'] = $bbcode_parser->parse($splitoptions["$index"], $foruminfo['forumid'], true);
  697. $option['votes'] = $value; //get the vote count for the option
  698.  
  699. if ($option['votes'] <= 0)
  700. {
  701. $option['percentraw'] = 0;
  702. }
  703. else if ($pollinfo['multiple'])
  704. {
  705. $option['percentraw'] = ($option['votes'] < $pollinfo['voters']) ? $option['votes'] / $pollinfo['voters'] * 100 : 100;
  706. }
  707. else
  708. {
  709. $option['percentraw'] = ($options['votes'] < $pollinfo['numbervotes']) ? $option['votes'] / $pollinfo['numbervotes'] * 100 : 100;
  710. }
  711. $option['percent'] = vb_number_format($option['percentraw'], 2);
  712.  
  713. $option['graphicnumber'] = $counter % 6 + 1;
  714. $option['barnumber'] = round($option['percent']) * 2;
  715. $option['remainder'] = 201 - $option['barnumber'];
  716. $option['votes'] = vb_number_format($option['votes']);
  717.  
  718. $left = vB_Template_Runtime::fetchStyleVar('left');
  719. $right = vB_Template_Runtime::fetchStyleVar('right');
  720. $option['open'] = $left[0];
  721. $option['close'] = $right[0];
  722.  
  723. $show['pollvoters'] = false;
  724. if ($pollinfo['public'] AND $value)
  725. {
  726. $names = $allnames[($index+1)];
  727. unset($allnames[($index+1)]);
  728. if (!empty($names))
  729. {
  730. $show['pollvoters'] = true;
  731. }
  732. }
  733.  
  734. ($hook = vBulletinHook::fetch_hook('poll_results_bit')) ? eval($hook) : false;
  735.  
  736. $templater = vB_Template::create('pollresult');
  737. $templater->register('names', $names);
  738. $templater->register('option', $option);
  739. $pollbits .= $templater->render();
  740. $counter++;
  741. }
  742.  
  743. if ($pollinfo['multiple'])
  744. {
  745. $pollinfo['numbervotes'] = $pollinfo['voters'];
  746. $show['multiple'] = true;
  747. }
  748.  
  749. if (can_moderate($threadinfo['forumid'], 'caneditpoll'))
  750. {
  751. $show['editpoll'] = true;
  752. }
  753. else
  754. {
  755. $show['editpoll'] = false;
  756. }
  757.  
  758. if ($pollinfo['timeout'])
  759. {
  760. $pollendtime = vbdate($vbulletin->options['timeformat'], $pollinfo['dateline'] + ($pollinfo['timeout'] * 86400));
  761. $pollenddate = vbdate($vbulletin->options['dateformat'], $pollinfo['dateline'] + ($pollinfo['timeout'] * 86400));
  762. $show['pollenddate'] = true;
  763. }
  764. else
  765. {
  766. $show['pollenddate'] = false;
  767. }
  768.  
  769. // Phrase parts below
  770. if ($nopermission)
  771. {
  772. $pollstatus = $vbphrase['you_may_not_vote_on_this_poll'];
  773. }
  774. else if ($showresults)
  775. {
  776. $pollstatus = $vbphrase['this_poll_is_closed'];
  777. }
  778. else if ($uservoted)
  779. {
  780. $pollstatus = $vbphrase['you_have_already_voted_on_this_poll'];
  781. }
  782.  
  783. // draw nav bar
  784. $navbits = construct_poll_nav($foruminfo, $threadinfo);
  785. $navbar = render_navbar_template($navbits);
  786.  
  787. ($hook = vBulletinHook::fetch_hook('poll_results_complete')) ? eval($hook) : false;
  788.  
  789. $templater = vB_Template::create('pollresults_table');
  790. $templater->register('pollbits', $pollbits);
  791. $templater->register('pollenddate', $pollenddate);
  792. $templater->register('pollendtime', $pollendtime);
  793. $templater->register('pollinfo', $pollinfo);
  794. $templater->register('pollstatus', $pollstatus);
  795. $pollresults = $templater->render();
  796. $templater = vB_Template::create('pollresults');
  797. $templater->register_page_templates();
  798. $templater->register('navbar', $navbar);
  799. $templater->register('pollresults', $pollresults);
  800. $templater->register('threadinfo', $threadinfo);
  801. print_output($templater->render());
  802. }
  803.  
  804.  
  805. // ############################### start vote on poll ###############################
  806. if ($_POST['do'] == 'pollvote')
  807. {
  808. if (!$pollinfo['pollid'])
  809. {
  810. eval(standard_error(fetch_error('invalidid', $vbphrase['poll'], $vbulletin->options['contactuslink'])));
  811. }
  812.  
  813. if ($pollinfo['multiple'])
  814. {
  815. $vbulletin->input->clean_array_gpc('p', array(
  816. 'optionnumber' => TYPE_ARRAY_BOOL,
  817. ));
  818. }
  819. else
  820. {
  821. $vbulletin->input->clean_array_gpc('p', array(
  822. 'optionnumber' => TYPE_UINT
  823. ));
  824. }
  825.  
  826. ($hook = vBulletinHook::fetch_hook('poll_vote_start')) ? eval($hook) : false;
  827.  
  828. if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canvote']))
  829. {
  830. print_no_permission();
  831. }
  832.  
  833. //check if poll is closed
  834. if (!$pollinfo['active'] OR !$threadinfo['open'] OR ($pollinfo['dateline'] + ($pollinfo['timeout'] * 86400) < TIMENOW AND $pollinfo['timeout'] != 0))
  835. { //poll closed
  836. eval(standard_error(fetch_error('pollclosed')));
  837. }
  838.  
  839. //check if an option was selected
  840. if (!empty($vbulletin->GPC['optionnumber']))
  841. {
  842. if (!$vbulletin->userinfo['userid'])
  843. {
  844. $voted = intval(fetch_bbarray_cookie('poll_voted', $pollid));
  845. if ($voted)
  846. {
  847. //the user has voted before
  848. eval(standard_error(fetch_error('useralreadyvote')));
  849. }
  850. else
  851. {
  852. set_bbarray_cookie('poll_voted', $pollid, 1, 1);
  853. }
  854. }
  855. // Query master to reduce the chance of multiple poll votes
  856. else if ($uservoteinfo = $db->query_first("
  857. SELECT userid
  858. FROM " . TABLE_PREFIX . "pollvote
  859. WHERE userid = " . $vbulletin->userinfo['userid'] . "
  860. AND pollid = $pollid
  861. "))
  862. {
  863. //the user has voted before
  864. eval(standard_error(fetch_error('useralreadyvote')));
  865. }
  866.  
  867. $totaloptions = substr_count($pollinfo['options'], '|||') + 1;
  868.  
  869. //Error checking complete, lets get the options
  870. if ($pollinfo['multiple'])
  871. {
  872. $insertsql = '';
  873. $skip_voters = false;
  874. foreach ($vbulletin->GPC['optionnumber'] AS $val => $vote)
  875. {
  876. $val = intval($val);
  877. if ($vote AND $val > 0 AND $val <= $totaloptions)
  878. {
  879. $pollvote =& datamanager_init('PollVote', $vbulletin, ERRTYPE_STANDARD);
  880. $pollvote->set_info('skip_voters', $skip_voters);
  881. $pollvote->set('pollid', $pollid);
  882. $pollvote->set('votedate', TIMENOW);
  883. $pollvote->set('voteoption', $val);
  884. if (!$vbulletin->userinfo['userid'])
  885. {
  886. $pollvote->set('userid', NULL, false);
  887. }
  888. else
  889. {
  890. $pollvote->set('userid', $vbulletin->userinfo['userid']);
  891. }
  892. $pollvote->set('votetype', $val);
  893. if (!$pollvote->save(true, false, false, false, true))
  894. {
  895. $vbulletin->url = fetch_seo_url('thread', $threadinfo);
  896. print_standard_redirect('redirect_pollvoteduplicate');
  897. }
  898.  
  899. $skip_voters = true;
  900. }
  901. }
  902. }
  903. else if ($vbulletin->GPC['optionnumber'] > 0 AND $vbulletin->GPC['optionnumber'] <= $totaloptions)
  904. {
  905. $pollvote =& datamanager_init('PollVote', $vbulletin, ERRTYPE_STANDARD);
  906. $pollvote->set('pollid', $pollid);
  907. $pollvote->set('votedate', TIMENOW);
  908. $pollvote->set('voteoption', $vbulletin->GPC['optionnumber']);
  909. if (!$vbulletin->userinfo['userid'])
  910. {
  911. $pollvote->set('userid', NULL, false);
  912. }
  913. else
  914. {
  915. $pollvote->set('userid', $vbulletin->userinfo['userid']);
  916. }
  917. $pollvote->set('votetype', 0);
  918. if (!$pollvote->save(true, false, false, false, true))
  919. {
  920. $vbulletin->url = fetch_seo_url('thread', $threadinfo);
  921. print_standard_redirect('redirect_pollvoteduplicate');
  922. }
  923. }
  924.  
  925. // make last reply date == last vote date
  926. if ($vbulletin->options['updatelastpost'])
  927. {
  928. // option selected in CP
  929. $threadman =& datamanager_init('Thread', $vbulletin, ERRTYPE_SILENT, 'threadpost');
  930. $threadman->set_existing($threadinfo);
  931. $threadman->set('lastpost', TIMENOW);
  932. $threadman->save();
  933. }
  934.  
  935. ($hook = vBulletinHook::fetch_hook('poll_vote_complete')) ? eval($hook) : false;
  936.  
  937. // redirect
  938. $vbulletin->url = fetch_seo_url('thread', $threadinfo);
  939. print_standard_redirect('redirect_pollvotethanks');
  940. }
  941. else
  942. {
  943. ($hook = vBulletinHook::fetch_hook('poll_vote_complete')) ? eval($hook) : false;
  944.  
  945. eval(standard_error(fetch_error('nopolloptionselected')));
  946. }
  947. }
  948.  
  949. /*======================================================================*\
  950. || ####################################################################
  951. || #
  952. || # CVS: $RCSfile$ - $Revision: 53471 $
  953. || ####################################################################
  954. \*======================================================================*/
  955. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement