Code Duplication    Length = 37-37 lines in 2 locations

Sources/Display.php 1 location

@@ 654-690 (lines=37) @@
651
		$smcFunc['db_free_result']($request);
652
653
		// If this is a guest we need to do our best to work out if they have voted, and what they voted for.
654
		if ($user_info['is_guest'] && $pollinfo['guest_vote'] && allowedTo('poll_vote'))
655
		{
656
			if (!empty($_COOKIE['guest_poll_vote']) && preg_match('~^[0-9,;]+$~', $_COOKIE['guest_poll_vote']) && strpos($_COOKIE['guest_poll_vote'], ';' . $context['topicinfo']['id_poll'] . ',') !== false)
657
			{
658
				// ;id,timestamp,[vote,vote...]; etc
659
				$guestinfo = explode(';', $_COOKIE['guest_poll_vote']);
660
				// Find the poll we're after.
661
				foreach ($guestinfo as $i => $guestvoted)
662
				{
663
					$guestvoted = explode(',', $guestvoted);
664
					if ($guestvoted[0] == $context['topicinfo']['id_poll'])
665
						break;
666
				}
667
				// Has the poll been reset since guest voted?
668
				if ($pollinfo['reset_poll'] > $guestvoted[1])
669
				{
670
					// Remove the poll info from the cookie to allow guest to vote again
671
					unset($guestinfo[$i]);
672
					if (!empty($guestinfo))
673
						$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
674
					else
675
						unset($_COOKIE['guest_poll_vote']);
676
				}
677
				else
678
				{
679
					// What did they vote for?
680
					unset($guestvoted[0], $guestvoted[1]);
681
					foreach ($pollOptions as $choice => $details)
682
					{
683
						$pollOptions[$choice]['voted_this'] = in_array($choice, $guestvoted) ? 1 : -1;
684
						$pollinfo['has_voted'] |= $pollOptions[$choice]['voted_this'] != -1;
685
					}
686
					unset($choice, $details, $guestvoted);
687
				}
688
				unset($guestinfo, $guestvoted, $i);
689
			}
690
		}
691
692
		// Set up the basic poll information.
693
		$context['poll'] = array(

Sources/Printpage.php 1 location

@@ 127-163 (lines=37) @@
124
		$smcFunc['db_free_result']($request);
125
126
		// If this is a guest we need to do our best to work out if they have voted, and what they voted for.
127
		if ($user_info['is_guest'] && $pollinfo['guest_vote'] && allowedTo('poll_vote'))
128
		{
129
			if (!empty($_COOKIE['guest_poll_vote']) && preg_match('~^[0-9,;]+$~', $_COOKIE['guest_poll_vote']) && strpos($_COOKIE['guest_poll_vote'], ';' . $row['id_poll'] . ',') !== false)
130
			{
131
				// ;id,timestamp,[vote,vote...]; etc
132
				$guestinfo = explode(';', $_COOKIE['guest_poll_vote']);
133
				// Find the poll we're after.
134
				foreach ($guestinfo as $i => $guestvoted)
135
				{
136
					$guestvoted = explode(',', $guestvoted);
137
					if ($guestvoted[0] == $row['id_poll'])
138
						break;
139
				}
140
				// Has the poll been reset since guest voted?
141
				if ($pollinfo['reset_poll'] > $guestvoted[1])
142
				{
143
					// Remove the poll info from the cookie to allow guest to vote again
144
					unset($guestinfo[$i]);
145
					if (!empty($guestinfo))
146
						$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
147
					else
148
						unset($_COOKIE['guest_poll_vote']);
149
				}
150
				else
151
				{
152
					// What did they vote for?
153
					unset($guestvoted[0], $guestvoted[1]);
154
					foreach ($pollOptions as $choice => $details)
155
					{
156
						$pollOptions[$choice]['voted_this'] = in_array($choice, $guestvoted) ? 1 : -1;
157
						$pollinfo['has_voted'] |= $pollOptions[$choice]['voted_this'] != -1;
158
					}
159
					unset($choice, $details, $guestvoted);
160
				}
161
				unset($guestinfo, $guestvoted, $i);
162
			}
163
		}
164
165
		$context['user']['started'] = $user_info['id'] == $row['id_member'] && !$user_info['is_guest'];
166
		// Set up the basic poll information.