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

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