function captcha() { require_once LAFC_HELPER_PATH . '/secure_captcha.php'; Secure_captcha::show_image(); }
function validate_all($config_data, &$response_array) { FCP_trace::trace("validate_all"); $valid = true; $jinput = JFactory::getApplication()->input; // check the session token, but we don't want a redirect happening here so don't use JRequest::checkToken() if (version_compare(JVERSION, "3.0.0", "<")) { // if < 3.0 $token = JUtility::getToken(); } else { $token = JSession::getFormToken(); } // get token from session if (!$jinput->get($token, '', 'STRING')) { FCP_trace::trace(" Token incorrect or session expired"); $response = array(); $response['fcp_wrapper'] = '<div style="padding:20px">' . JText::_('COM_FLEXICONTACT_SESSION') . '</div>'; $response_array = array(); // clear out any other responses $response_array[] = $response; return -1; // tell the controller to kill the session } // Do we check the Captcha? $user = JFactory::getUser(); if ($config_data->show_captcha == 1) { $check_captcha = true; } else { if ($user->guest) { $check_captcha = true; } else { $check_captcha = false; } } // for image captcha, validate that the correct image was chosen // if the user gets it wrong more than 5 times, tell the controller to kill the session if ($check_captcha and $config_data->num_images > 0) { require_once LAFC_HELPER_PATH . '/flexi_captcha.php'; $pic_selected = $jinput->get('picselected', '', 'STRING'); $pic_selected = substr($pic_selected, 2); // strip off the i_ $resp = Flexi_captcha::check($pic_selected); switch ($resp) { case 0: FCP_trace::trace(" validating image captcha [{$pic_selected}] => pass"); $response = array(); $response['e_valid'] = 'fcp_err_image'; $response_array[] = $response; break; case 1: FCP_trace::trace(" validating image captcha [{$pic_selected}] => fail"); $response = array(); $response['fcp_image_outer'] = Flexi_captcha::show_image_captcha($config_data); $response['e_error'] = 'fcp_err_image'; $response['fcp_err_image'] = $this->make_error($config_data, JText::_('COM_FLEXICONTACT_WRONG_PICTURE')); $response_array[] = $response; $valid = false; break; case 2: FCP_trace::trace(" validating image captcha failed more than 5 times"); $response = array(); $response['fcp_wrapper'] = '<div style="padding:20px">' . JText::_('COM_FLEXICONTACT_TOO_MANY') . '</div>'; $response_array = array(); // clear out any other responses $response_array[] = $response; return -1; // tell the controller to kill the session } } // if using SecureImage captcha, validate the entry // if it passes, we will not re-validate in this session if ($check_captcha and $config_data->secure_captcha) { $app = JFactory::getApplication(); $secure_captcha_passed = $app->getUserState(LAFC_COMPONENT . "_secure_captcha_passed", 'N'); if ($secure_captcha_passed == 'N') { require_once LAFC_HELPER_PATH . '/secure_captcha.php'; $captcha_code = $jinput->get('fcp_captcha_code', '', 'STRING'); if (Secure_captcha::check($captcha_code)) { FCP_trace::trace(" validating SecureImage [{$captcha_code}] => pass"); $response = array(); $response['e_valid'] = 'fcp_err_captcha'; $response['f_valid'] = 'fcp_captcha_code'; $response_array[] = $response; $app->setUserState(LAFC_COMPONENT . "_secure_captcha_passed", "Y"); } else { FCP_trace::trace(" validating SecureImage [{$captcha_code}] => fail"); $response = array(); $response['e_error'] = 'fcp_err_captcha'; $response['f_error'] = 'fcp_captcha_code'; $response['fcp_err_captcha'] = $this->make_error($config_data, JText::_('COM_FLEXICONTACT_CAPTCHA_INVALID')); $response_array[] = $response; $valid = false; } } } // if using ReCaptcha, validate it // if it passes, we will not re-validate in this session // if it doesn't pass, tell the Javascript to re-load a different challenge because each challenge can only be used once if ($check_captcha and $config_data->recaptcha_theme > 0) { $app = JFactory::getApplication(); $recaptcha_passed = $app->getUserState(LAFC_COMPONENT . "_recaptcha_passed", 'N'); if ($recaptcha_passed == 'N') { require_once LAFC_HELPER_PATH . '/recaptchalib.php'; $recaptcha_challenge_field = $jinput->get('recaptcha_challenge_field', '', 'STRING'); $recaptcha_response_field = $jinput->get('recaptcha_response_field', '', 'STRING'); $remote_addr = $_SERVER["REMOTE_ADDR"]; $resp = recaptcha_check_answer($config_data->recaptcha_private_key, $remote_addr, $recaptcha_challenge_field, $recaptcha_response_field); if ($resp->is_valid) { FCP_trace::trace(" validating ReCaptcha [{$recaptcha_response_field}] => pass"); $response = array(); $response['e_valid'] = 'fcp_err_recap'; $response_array[] = $response; $app->setUserState(LAFC_COMPONENT . "_recaptcha_passed", "Y"); } else { FCP_trace::trace(" validating ReCaptcha [{$recaptcha_response_field}] => " . $resp->error); $response = array(); $response['e_error'] = 'fcp_err_recap'; $response['fcp_err_recap'] = $this->make_error($config_data, JText::_('COM_FLEXICONTACT_CAPTCHA_INVALID')); $response['reloadcaptcha'] = 'Yes'; $response_array[] = $response; $valid = false; } } } // if using magic word, validate the word if ($check_captcha and $config_data->magic_word != '') { $magic_word = $jinput->get('fcp_magic', '', 'STRING'); if (strcasecmp($magic_word, $config_data->magic_word) == 0) { FCP_trace::trace(" validating magic word [{$magic_word}] vs [{$config_data->magic_word}] => pass"); $response = array(); $response['e_valid'] = 'fcp_err_magic'; $response['f_valid'] = 'fcp_magic'; $response_array[] = $response; } else { FCP_trace::trace(" validating magic word [{$magic_word}] vs [{$config_data->magic_word}] => fail"); $response = array(); $response['e_error'] = 'fcp_err_magic'; $response['f_error'] = 'fcp_magic'; $response['fcp_err_magic'] = $this->make_error($config_data, JText::_('COM_FLEXICONTACT_WRONG_MAGIC_WORD')); $response_array[] = $response; $valid = false; } } // validate all the user defined fields $fields_valid = $this->validate_fields($config_data, $response_array); return $valid and $fields_valid; // if both valid return true, else false }
static function draw_page($config_data, $data) { // load our css FCP_Common::load_assets($config_data); // Are we going to show Captcha or not? $user = JFactory::getUser(); if ($config_data->show_captcha == 0) { if ($user->guest) { $config_data->show_captcha = 1; } else { $config_data->show_captcha = 0; } } // display the input form $html = "\n" . '<div id="fcp_wrapper" class="fcp_wrapper">'; $html .= "\n" . '<span id="fcp_err_top"></span>'; // start the form - we don't care about the action url because we never submit the form $html .= "\n" . '<form name="fcp_form" id="fcp_form" class="fcp_form" action="#" method="post" >'; $html .= "\n" . '<input type="hidden" name="config_id" id="config_id" value="' . $config_data->id . '" />'; $html .= "\n" . JHTML::_('form.token'); // display the user defined fields $div_open = false; $fieldset_open = false; foreach ($config_data->all_fields as $field_index => $field) { $field->id = sprintf('field%03d', $field_index); $field->div_id = sprintf('fcp_div%03d', $field_index); $field->error_id = sprintf('fcp_err%03d', $field_index); // if the line div is open and we are about to draw a field that is not a horizontal checkbox, close the div if ($div_open and $field->field_type != LAFC_FIELD_CHECKBOX_H) { $html .= "\n" . '</div>'; $div_open = false; } // fixed texts will leave the line div open if ($field->field_type == LAFC_FIELD_FIXED_TEXT) { $div_open = true; } // is it a fieldset? if ($field->field_type == LAFC_FIELD_FIELDSET_START) { if ($fieldset_open) { // if a fieldset was already open $html .= "\n" . '</fieldset>'; } // close it $fieldset_open = true; } if ($field->field_type == LAFC_FIELD_FIELDSET_END) { $fieldset_open = false; } $html .= self::draw_field($field, $data, $config_data); } if ($div_open) { $html .= "\n" . '</div>'; $div_open = false; } // the "send me a copy" checkbox if ($config_data->show_copy == LAFC_COPYME_CHECKBOX) { $html .= "\n" . '<div class="fcp_line fcp_copy_me fcp_checkbox fcp_checkbox_l">'; $html .= "\n" . '<input type="checkbox" class="fcp_lcb" name="show_copy" id="show_copy" value="1" />'; $html .= "\n" . '<label for="show_copy" class="fcp_lcb">' . JText::_('COM_FLEXICONTACT_COPY_ME') . '</label>'; $html .= "\n" . '</div>'; } // the agreement required checkbox $send_button_state = ''; if ($config_data->agreement_prompt != '') { $send_button_state = 'disabled="disabled"'; $onclick = ' onclick="if(this.checked==true){form.fcp_send_button.disabled=false;}else{form.fcp_send_button.disabled=true;}"'; $checkbox = '<input type="checkbox" class="fcp_lcb" name="agreement_check" id="agreement_check" value="1" ' . $onclick . '/>'; if ($config_data->agreement_name != '' and $config_data->agreement_link != '') { $popup = 'onclick="window.open(' . "'" . $config_data->agreement_link . "', 'fcagreement', 'width=640,height=480,scrollbars=1,location=0,menubar=0,resizable=1'); return false;" . '"'; $link_text = $config_data->agreement_prompt . ' ' . JHTML::link($config_data->agreement_link, $config_data->agreement_name, 'target="_blank" ' . $popup); } else { $link_text = $config_data->agreement_prompt; } $html .= "\n" . '<div class="fcp_line fcp_agreement fcp_checkbox fcp_checkbox_l">'; $html .= "\n" . $checkbox; $html .= "\n" . '<label for="agreement_check" class="fcp_lcb">' . $link_text . '</label>'; $html .= "\n" . '</div>'; } // the magic word if ($config_data->show_captcha == 1 and $config_data->magic_word != '') { $html .= "\n" . '<div class="fcp_line fcp_magic">'; $html .= "\n" . '<label><span class="fcp_mandatory">' . $config_data->magic_word_prompt . '</span></label>'; $html .= "\n" . '<input type="text" name="fcp_magic" id="fcp_magic" value="" />'; $html .= "\n" . '<span id="fcp_err_magic"></span>'; $html .= "\n" . '</div>'; } // the image captcha if ($config_data->show_captcha == 1 and $config_data->num_images > 0) { require_once LAFC_HELPER_PATH . '/flexi_captcha.php'; $html .= "\n" . '<div class="fcp_line fcp_image_outer" id="fcp_image_outer" >'; $html .= Flexi_captcha::show_image_captcha($config_data); $html .= "\n" . '</div>'; } // the SecureImage captcha if ($config_data->show_captcha == 1 and $config_data->secure_captcha > 0) { require_once LAFC_HELPER_PATH . '/secure_captcha.php'; $html .= Secure_captcha::show_secure_captcha($config_data); } // reCAPTCHA if ($config_data->show_captcha == 1 and $config_data->recaptcha_theme > 0) { switch ($config_data->recaptcha_theme) { case RECAPTCHA_RED: $theme_name = 'red'; break; case RECAPTCHA_WHITE: $theme_name = 'white'; break; case RECAPTCHA_BLACKGLASS: $theme_name = 'blackglass'; break; case RECAPTCHA_CLEAN: $theme_name = 'clean'; break; } $html .= '<script type="text/javascript">var RecaptchaOptions = {theme:' . "'" . $theme_name . "'" . '};</script>'; require_once LAFC_HELPER_PATH . '/recaptchalib.php'; $uri = JURI::getInstance(); $ssl = strtolower($uri->getScheme()) == 'https'; $html .= "\n" . '<div class="fcp_line fcp_recaptcha">'; $html .= "\n" . '<label> </label>'; $html .= "\n" . recaptcha_get_html($config_data->recaptcha_public_key, null, $ssl, $config_data->recaptcha_language); $html .= "\n" . '<span id="fcp_err_recap"></span>'; $html .= "\n" . '</div>'; } // the send button $js = "if (!window.jQuery) alert('" . JText::_('COM_FLEXICONTACT_JQUERY_NOT') . "');"; if ($config_data->send_text == '') { $send_text = JText::_('COM_FLEXICONTACT_SEND_BUTTON'); } else { $send_text = $config_data->send_text; } $html .= "\n" . '<div class="fcp_line fcp_sendrow">'; $html .= "\n" . '<input type="submit" class="button" id="fcp_send_button" name="fcp_send_button" ' . $send_button_state . ' value="' . $send_text . '" onclick="' . $js . '" />'; $html .= "\n" . '<div id="fcp_spinner" style="display:inline-block"></div>'; $html .= "\n" . '<div id="fcp_smsg" style="display:inline-block"></div>'; $html .= "\n</div>"; // fcp_sendrow // if a fieldset is left open at the end of the user defined fields, we close it here if ($fieldset_open) { $html .= "\n" . '</fieldset>'; $fieldset_open = false; } $html .= "\n</form>"; // form $html .= "\n" . '<div style="clear:both"></div>'; $html .= "\n</div>"; // fcp_wrapper if (FCP_trace::tracing()) { FCP_trace::trace("Generated Html:\n---------------\n" . $html); } return $html; }