prefix . 'eci_results';
$eci_post_id = $post->ID;
$eci_user_time='';
// post form
if (isset($_POST['eci_submit_time']) && check_admin_referer('eci_submit_time_submit_random_string')) {
$eci_error = '';
// we won't post if the error field has anything in it, so run through some checks and grab post data
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$eci_error = 'ERROR: Database connection not available. Please try again later. If problem persists, please contact the site owner.';
}
if (function_exists('esc_html')) { // only posts with WordPress 2.8 and above
if (esc_html($_POST['eci_user_name']) != '') {
$eci_user_name = esc_html($_POST['eci_user_name']);
}
else {
$eci_error = 'ERROR: You must enter your name.';
}
}
else {
$eci_error = 'ERROR: Eclipse Crossword Integration does not work with this version of WordPress.';
}
if (is_email($_POST['eci_user_email'])) {
$eci_user_email = $_POST['eci_user_email'];
}
else {
$eci_error = 'ERROR: You must enter a valid email address.';
}
$eci_user_url = apply_filters('pre_comment_author_url', trim($_POST['eci_user_url']));
$eci_user_IP = addslashes($_SERVER['REMOTE_ADDR']);
if (esc_html($_POST['eci_time']) != '' || esc_html($_POST['eci_time']) != '0:00:00' ) {
$eci_user_time = esc_html($_POST['eci_time']);
}
else {
$eci_error = 'ERROR: No time recorded';
}
// check whether this user has posted this time, which would most likely be a duplicate submit
$eci_this_time_posted = $wpdb->get_var("SELECT COUNT(*) FROM $table_name WHERE user_email = '$eci_user_email' AND time = '$eci_user_time'");
if ($eci_this_time_posted > 0) {
$eci_error = 'ERROR: You have already posted an entry with this time.';
}
// save only if we haven't had an error
if ($eci_error != '') {
echo '
');
$body = substr($result,$start,$end-$start);
// move message section to the top.
$start = strpos($body,'
')+5;
$welcome_message = substr($body,$start,$end-$start);
$body = str_replace($welcome_message, '',$body);
$body = str_replace('',''.$welcome_message.' |
| ',$body);
// add call to the eciSwitchKeys function
$body = str_replace('CellAt(x + i, y).className = CellAt(x + i, y).className.replace(IsSelected ? "_unsel" : "_sel", IsSelected ? "_sel" : "_unsel");', '{
CellAt(x + i, y).className = CellAt(x + i, y).className.replace(IsSelected ? "_unsel" : "_sel", IsSelected ? "_sel" : "_unsel");
eciSwitchKeys(CellAt(x + i , y),IsSelected);
}',$body);
$body = str_replace('CellAt(x, y + i).className = CellAt(x, y + i).className.replace(IsSelected ? "_unsel" : "_sel", IsSelected ? "_sel" : "_unsel");', '{
CellAt(x, y + i).className = CellAt(x, y + i).className.replace(IsSelected ? "_unsel" : "_sel", IsSelected ? "_sel" : "_unsel");
eciSwitchKeys(CellAt(x, y + i),IsSelected);
}',$body);
// add link to plugin home page
$body = str_replace("from Green Eclipse—it's free!", "from Green Eclipse—it's free! WordPress Integration by Eclipse Crossword Integration.",$body);
$body = str_replace("EclipseCrossword © 2000-2007", "EclipseCrossword © 2000-2007 WordPress Integration by Eclipse Crossword Integration ",$body);
// add timer
$body = str_replace('', ' 0:00:00',$body);
// start timer
$body = str_replace('var CrosswordFinished, Initialized;', "var CrosswordFinished, Initialized;\n var eciStarted = 0;",$body);
// stop timer
$body = str_replace('document.getElementById("congratulations").style.display = "block";', "eciStartStop();\n".'document.getElementById("congratulations").style.display = "block";'."\n".' document.getElementById("eci-your-time").innerHTML = "("+document.eci_submit_time.eci_time.value+")";',$body);
// add form to save time
global $user_ID;
$eci_user_info = get_userdata($user_ID);
if (isset($eci_user_info->display_name) && $eci_user_name == '') {
$eci_user_name = $eci_user_info->display_name;
}
if (isset($eci_user_info->user_email) && $eci_user_email == '') {
$eci_user_email = $eci_user_info->user_email;
}
if (isset($eci_user_info->user_url) && $eci_user_url == '') {
$eci_user_url = $eci_user_info->user_url;
}
$body = str_replace('crossword puzzle.', 'crossword puzzle. Record your time - the top '. $eci_options['users_to_show'] .' times are listed on this post:
',$body);
// strip out inline style that hides the link on pages with black text.
$body = str_replace(' style="color: black; text-decoration:none;"', '', $body);
// get the clues
$start = strpos($body, 'Clue = new Array(')+18;
$end = strpos($body, ');', $start);
$question_string = substr($body,$start,$end-$start);
//$question_string = str_replace('"', '', $question_string);
$question_array = explode('",' , $question_string);
// work out if Across or Down
$start = strpos($result,'LastHorizontalWord = ') + 21;
$end = strpos($result, ';', $start);
$last_across = trim(substr($result,$start,$end-$start));
// work out how many words
$start = strpos($result,'Words = ') + 8;
$end = strpos($result, ';', $start);
$num_of_words = trim(substr($result,$start,$end-$start));
// append them to the end of the body
$body .= "\n Questions\n Across\n \n";
$i = 0;
foreach ($question_array as $value) {
$body .= '- ' . ($i + 1) . '. ' . str_replace('"', '', stripslashes($value)) . "
\n";
if ($i == $last_across) {
$body .= " \n Down\n \n";
}
$i++;
}
$body .= " \n";
// Add top X users to body
$body .= ' Top Times';
$number_to_show = $eci_options['users_to_show'];
$top_x_array = $wpdb->get_results("SELECT user_name, user_url, date, time FROM $table_name WHERE postid = '$eci_post_id' ORDER BY time LIMIT $number_to_show", ARRAY_A);
if (count($top_x_array) > 0) {
$body .= "\n \n";
foreach ($top_x_array as $value) {
$body .= '- Time: ' . $value['time'] . ' by on ' . substr($value['date'],0,10) . "
\n";
}
$body .= " \n";
}
else {
$body .= ' ';
}
// call JavaScript function to draw the numbers in
$body .= ''."\n";
?>
|