Code Duplication    Length = 37-37 lines in 2 locations

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.

Sources/Display.php 1 location

@@ 682-718 (lines=37) @@
679
		$smcFunc['db_free_result']($request);
680
681
		// If this is a guest we need to do our best to work out if they have voted, and what they voted for.
682
		if ($user_info['is_guest'] && $pollinfo['guest_vote'] && allowedTo('poll_vote'))
683
		{
684
			if (!empty($_COOKIE['guest_poll_vote']) && preg_match('~^[0-9,;]+$~', $_COOKIE['guest_poll_vote']) && strpos($_COOKIE['guest_poll_vote'], ';' . $context['topicinfo']['id_poll'] . ',') !== false)
685
			{
686
				// ;id,timestamp,[vote,vote...]; etc
687
				$guestinfo = explode(';', $_COOKIE['guest_poll_vote']);
688
				// Find the poll we're after.
689
				foreach ($guestinfo as $i => $guestvoted)
690
				{
691
					$guestvoted = explode(',', $guestvoted);
692
					if ($guestvoted[0] == $context['topicinfo']['id_poll'])
693
						break;
694
				}
695
				// Has the poll been reset since guest voted?
696
				if ($pollinfo['reset_poll'] > $guestvoted[1])
697
				{
698
					// Remove the poll info from the cookie to allow guest to vote again
699
					unset($guestinfo[$i]);
700
					if (!empty($guestinfo))
701
						$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
702
					else
703
						unset($_COOKIE['guest_poll_vote']);
704
				}
705
				else
706
				{
707
					// What did they vote for?
708
					unset($guestvoted[0], $guestvoted[1]);
709
					foreach ($pollOptions as $choice => $details)
710
					{
711
						$pollOptions[$choice]['voted_this'] = in_array($choice, $guestvoted) ? 1 : -1;
712
						$pollinfo['has_voted'] |= $pollOptions[$choice]['voted_this'] != -1;
713
					}
714
					unset($choice, $details, $guestvoted);
715
				}
716
				unset($guestinfo, $guestvoted, $i);
717
			}
718
		}
719
720
		// Set up the basic poll information.
721
		$context['poll'] = array(