function import(&$return_message) { if (FCP_trace::tracing()) { $count_imported_rows = $this->count_imported_rows(); FCP_trace::trace("Log import deleting {$count_imported_rows} rows"); $free_log_info = $this->free_log_info(); FCP_trace::trace(" Free log info: " . print_r($free_log_info, true)); } // delete any rows previously imported $query = "DELETE FROM `#__flexicontact_plus_log` WHERE `imported` = 1"; $result = $this->ladb_execute($query); if ($result === false) { $return_message = $this->ladb_error_text(); return false; } // if Free FlexiContact is still installed, we can get the component parameters // and then get the optional field names $component_params = JComponentHelper::getParams("com_flexicontact"); $params = $component_params->toObject(); $promptname1 = 'Field1'; $promptname2 = 'Field2'; $promptname3 = 'Field3'; $promptname4 = 'Field4'; $promptname5 = 'Field5'; $list_prompt = 'List Choice'; if (isset($params->field_prompt1)) { FCP_trace::trace("Found free component parameters"); $promptname1 = $params->field_prompt1; $promptname2 = $params->field_prompt2; $promptname3 = $params->field_prompt3; $promptname4 = $params->field_prompt4; $promptname5 = $params->field_prompt5; if (isset($params->list_prompt)) { // versions < 5.10 only $list_prompt = $params->list_prompt; } } $query = "SELECT * FROM `#__flexicontact_log` "; $rows = $this->ladb_loadObjectList($query); if ($rows === false) { $return_message = $this->ladb_error_text; return false; } $count = 0; foreach ($rows as $row) { $other_data = ''; if (isset($row->list_choice) and $row->list_choice != '') { $other_data .= $list_prompt . ': ' . $row->list_choice . "\n"; } if ($row->field1 != '') { $other_data .= $promptname1 . ': ' . $row->field1 . "\n"; } if ($row->field2 != '') { $other_data .= $promptname2 . ': ' . $row->field2 . "\n"; } if ($row->field3 != '') { $other_data .= $promptname3 . ': ' . $row->field3 . "\n"; } if ($row->field4 != '') { $other_data .= $promptname4 . ': ' . $row->field4 . "\n"; } if ($row->field5 != '') { $other_data .= $promptname5 . ': ' . $row->field5 . "\n"; } $other_data .= $row->message; $query = 'INSERT INTO `#__flexicontact_plus_log` (`datetime`, `name`, `email`, `admin_email`, `subject`, `message`, `status_main`, `status_copy`, `ip`, `browser_id`, `browser_string`, `imported`) VALUES (' . $this->_db->Quote($row->datetime) . ',' . $this->_db->Quote($row->name) . ',' . $this->_db->Quote($row->email) . ',' . '"",' . $this->_db->Quote($row->subject) . ',' . $this->_db->Quote($other_data) . ',' . $this->_db->Quote($row->status_main) . ',' . $this->_db->Quote($row->status_copy) . ',' . $this->_db->Quote($row->ip) . ',' . $this->_db->Quote($row->browser_id) . ',' . $this->_db->Quote($row->browser_string) . ',' . '1)'; // set imported to 1 FCP_trace::trace(" IMPORTING ROW: " . $row->id . " DATE: " . $row->datetime . " NAME: " . $row->name . " EMAIL: " . $row->email); $result = $this->ladb_execute($query); if ($result === false) { $return_message = $this->ladb_error_text; return false; } $count++; } FCP_trace::trace("Imported {$count} rows"); $return_message = JText::sprintf('COM_FLEXICONTACT_IMPORTED_ROWS', $count); return true; }
function validate_fields($config_data, &$response_array) { $valid = true; foreach ($this->data as $field_id => $field_value) { if (substr($field_id, 0, 5) != 'field') { // we only look at user defined fields here continue; } $field_index = intval(substr($field_id, 5, 3)); // field id's are 'fieldnnn' or 'fieldnnnmm' for multiple checkboxes $field =& $config_data->all_fields[$field_index]; // point to the field configuration $error_id = sprintf('fcp_err%03d', $field_index); if (FCP_trace::tracing()) { if (strlen($field_id) == 8) { $trace_field_id = $field_id; } else { $trace_field_id = substr($field_id, 0, 8) . '-' . substr($field_id, 8); } // multiple checkbox FCP_trace::trace(" validating {$trace_field_id} ({$field->prompt}) => [{$field_value}]"); } // don't validate hidden fields if (!$field->visible) { continue; } // valid unless found otherwise $response = array(); $response['f_valid'] = $field_id; $response['e_valid'] = $error_id; // if the field is mandatory and empty, that's the only error we will report for this field if ($field->mandatory and empty($field_value)) { $response = array(); $response['f_error'] = $field_id; $response['e_error'] = $error_id; $response[$error_id] = $this->make_error($config_data, JText::_('COM_FLEXICONTACT_REQUIRED')); $valid = false; $response_array[] = $response; continue; } // if the field is mandatory and not empty, we must clear its error if ($field->mandatory and !empty($field_value)) { $response_array[] = $response; } // if the field is not mandatory and is empty, we must not validate it and we must clear its error if (!$field->mandatory and empty($field_value)) { $response_array[] = $response; continue; } // checkboxes and radio buttons don't need to be validated if (in_array($field->field_type, array(LAFC_FIELD_CHECKBOX_L, LAFC_FIELD_CHECKBOX_H, LAFC_FIELD_CHECKBOX_R, LAFC_FIELD_CHECKBOX_M, LAFC_FIELD_RADIO_V, LAFC_FIELD_RADIO_H))) { continue; } // now the field type specific validation switch ($field->field_type) { case LAFC_FIELD_SUBJECT: $bad_subject_chars = "|<>`"; // characters we don't allow if (strpbrk($field_value, $bad_subject_chars) === false) { break; } $response = array(); $response['f_error'] = $field_id; $response['e_error'] = $error_id; $response[$error_id] = $this->make_error($config_data, JText::_('COM_FLEXICONTACT_INVALID')); $valid = false; break; case LAFC_FIELD_FROM_ADDRESS: jimport('joomla.mail.helper'); if (JMailHelper::isEmailAddress($field_value)) { break; } $response = array(); $response['f_error'] = $field_id; $response['e_error'] = $error_id; $response[$error_id] = $this->make_error($config_data, JText::_('COM_FLEXICONTACT_BAD_EMAIL')); $valid = false; break; case LAFC_FIELD_TEXT_NUMERIC: if (FCP_Common::is_posint($field_value)) { break; } $response = array(); $response['f_error'] = $field_id; $response['e_error'] = $error_id; $response[$error_id] = $this->make_error($config_data, JText::_('COM_FLEXICONTACT_INVALID')); $valid = false; break; case LAFC_FIELD_DATE: $yyyy_mm_dd = self::reformat_date($field_value, $config_data->date_format); if (!self::validate_date($yyyy_mm_dd)) { $date_string = self::get_date_string($config_data->date_format); $response = array(); $response['f_error'] = $field_id; $response['e_error'] = $error_id; $response[$error_id] = $this->make_error($config_data, JText::_('COM_FLEXICONTACT_INVALID') . ' (' . $date_string . ')'); $valid = false; break; } switch ($field->validation_type) { case VALTYPE_PAST: FCP_trace::trace(" must be in the past"); $today = date('Y-m-d'); if ($yyyy_mm_dd > $today) { $response = array(); $response['f_error'] = $field_id; $response['e_error'] = $error_id; $response[$error_id] = $this->make_error($config_data, JText::_('COM_FLEXICONTACT_DATE_PAST')); $valid = false; FCP_trace::trace(" - invalid, not in the past"); } break; case VALTYPE_FUTURE: FCP_trace::trace(" must be in the future"); $today = date('Y-m-d'); if ($yyyy_mm_dd < $today) { $response = array(); $response['f_error'] = $field_id; $response['e_error'] = $error_id; $response[$error_id] = $this->make_error($config_data, JText::_('COM_FLEXICONTACT_DATE_FUTURE')); $valid = false; FCP_trace::trace(" - invalid, not in the future"); } break; case VALTYPE_GREATER: FCP_trace::trace(" must be greater than the previous field"); if ($field_index == 0) { break; } // no previous field - forget it $previous_field_index = $field_index - 1; // previous field index $previous_field_config =& $config_data->all_fields[$previous_field_index]; if ($previous_field_config->field_type != LAFC_FIELD_DATE) { break; } // not a date field - forget it $previous_field_id = sprintf('field%03d', $previous_field_index); // form the ID of the previous field FCP_trace::trace(" previous field ID:" . $previous_field_id); if (!isset($this->data[$previous_field_id])) { break; } // no value - forget it $previous_field_value = $this->data[$previous_field_id]; $previous_field_yyyy_mm_dd = self::reformat_date($previous_field_value, $config_data->date_format); $previous_field_prompt = $previous_field_config->prompt; FCP_trace::trace(" previous field [" . $previous_field_prompt . '] value: ' . $previous_field_value . ' (current field value: ' . $yyyy_mm_dd . ')'); if ($yyyy_mm_dd <= $previous_field_yyyy_mm_dd) { $response = array(); $response['f_error'] = $field_id; $response['e_error'] = $error_id; $response[$error_id] = $this->make_error($config_data, JText::sprintf('COM_FLEXICONTACT_DATE_GREATER', $previous_field_prompt)); $valid = false; FCP_trace::trace(" - invalid, not greater than previous field"); } break; } break; case LAFC_FIELD_ADVANCED: if (!empty($field->regex)) { FCP_trace::trace(" validate regex: " . $field->regex); if (@preg_match($field->regex, $field_value) == 0) { $response = array(); $response['f_error'] = $field_id; $response['e_error'] = $error_id; if ($field->error_msg == '') { $response[$error_id] = $this->make_error($config_data, JText::_('COM_FLEXICONTACT_INVALID')); } else { $response[$error_id] = $this->make_error($config_data, $field->error_msg); } $valid = false; } } if (!empty($field->sql)) { $escaped_value = $this->_db->escape($field_value); $query = str_replace('%VALUE%', $escaped_value, $field->sql); $result = $this->ladb_loadResult($query); FCP_trace::trace(" validate sql: " . $query); FCP_trace::trace(" sql result: " . $result); if ($result === false) { FCP_trace::trace(" " . $this->ladb_error_text); } if ($result == 0) { $response = array(); $response['f_error'] = $field_id; $response['e_error'] = $error_id; if ($field->error_msg == '') { $response[$error_id] = $this->make_error($config_data, JText::_('COM_FLEXICONTACT_INVALID')); } else { $response[$error_id] = $this->make_error($config_data, $field->error_msg); } $valid = false; } } break; case LAFC_FIELD_ATTACHMENT: FCP_trace::trace(" validate file: " . $field_value); // it's ok, we won't get here if the filename is blank (the field size variable would not be set) ... $file_size_variable_name = sprintf('filesize%03d', $field_index); $jinput = JFactory::getApplication()->input; $file_size = $jinput->get($file_size_variable_name, '0', 'STRING'); $file_extension = pathinfo($field_value, PATHINFO_EXTENSION); FCP_trace::trace(" file_size: " . $file_size . ", extension = " . $file_extension); $white_list_array = explode(',', $config_data->white_list); if (!in_array(strtolower($file_extension), $white_list_array)) { $error_message = JText::sprintf('COM_FLEXICONTACT_FILES_ALLOWED', $config_data->white_list); $response = array(); $response['f_error'] = $field_id; $response['e_error'] = $error_id; $response[$error_id] = $this->make_error($config_data, $error_message); $valid = false; } if ($file_size > $config_data->max_file_size * 1024) { $error_message = JText::sprintf('COM_FLEXICONTACT_FILE_TOO_BIG', $config_data->max_file_size); $response = array(); $response['f_error'] = $field_id; $response['e_error'] = $error_id; $response[$error_id] = $this->make_error($config_data, $error_message); $valid = false; } if ($file_size == 0) { $error_message = JText::_('COM_FLEXICONTACT_FILE_EMPTY'); $response = array(); $response['f_error'] = $field_id; $response['e_error'] = $error_id; $response[$error_id] = $this->make_error($config_data, $error_message); $valid = false; } break; } // end switch $response_array[] = $response; } // end foreach return $valid; }
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; }
<?php /******************************************************************** Product : FlexicontactPlus Date : 24 July 2014 Copyright : Les Arbres Design 2010-2014 Contact : http://www.lesarbresdesign.info Licence : GNU General Public License *********************************************************************/ defined('_JEXEC') or die('Restricted Access'); // Pull in the helper file require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/flexi_common_helper.php'; require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/db_helper.php'; if (file_exists(JPATH_ROOT . '/demo_mode.txt')) { // used on our demo site define("LAFC_DEMO_MODE", "1"); } require_once LAFC_HELPER_PATH . '/trace_helper.php'; FCP_trace::trace_entry_point(true); if (FCP_trace::tracing()) { ini_set("display_errors", "1"); } require_once JPATH_COMPONENT . '/controller.php'; $controller = new FlexicontactplusController(); $jinput = JFactory::getApplication()->input; $task = $jinput->get('task', '', 'STRING'); $controller->execute($task); $controller->redirect();
function sendEmail($config_data) { if (FCP_trace::tracing()) { FCP_trace::trace("=====> Send Email() - Config Data: " . print_r($config_data, true)); FCP_trace::trace("=====> Send Email() - Email Model Data: " . print_r($this->data, true)); } // build the message to be sent to the site admin $body = $this->email_merge($config_data->admin_template, $config_data); jimport('joomla.mail.helper'); $clean_body = JMailHelper::cleanBody($body); $clean_subject = JMailHelper::cleanSubject($this->data->subject); // build the Joomla mail object $mail = JFactory::getMailer(); if ($config_data->email_html) { $mail->IsHTML(true); } else { $clean_body = $this->html2text($clean_body); } if ($config_data->email_from == '') { // v7.01 $email_from = $this->data->from_email; } else { $email_from = $config_data->email_from; } // use FlexiContact Global Configuration if ($config_data->email_from_name == '') { // v7.01 $email_from_name = $this->data->from_name; } else { $email_from_name = $config_data->email_from_name; } // use FlexiContact Global Configuration // 8.00: don't try to send an email with a blank from name or address // this could happen if those fields are non-mandatory on the email form $app = JFactory::getApplication(); if (empty($email_from)) { $email_from = $app->getCfg('mailfrom'); } // use Joomla Global Configuration if (empty($email_from_name)) { $email_from_name = $app->getCfg('fromname'); } // use Joomla Global Configuration $mail->setSender(array($email_from, $email_from_name)); $mail->addRecipient($config_data->email_to); $this->data->admin_email = $config_data->email_to; // store it for the log model if (!empty($config_data->email_cc)) { $addresses = explode(',', $config_data->email_cc); foreach ($addresses as $address) { $mail->addCC($address); } } if (!empty($config_data->email_bcc)) { $addresses = explode(',', $config_data->email_bcc); foreach ($addresses as $address) { $mail->addBCC($address); } } if (!empty($this->data->from_email)) { $mail->addReplyTo(array($this->data->from_email, $this->data->from_name)); } $mail->setSubject($clean_subject); $mail->setBody($clean_body); // add any file attachments foreach ($this->files as $attachment) { FCP_trace::trace("Attaching file {$attachment}"); $mime_type = self::getMimeType($attachment); $mail->addAttachment($attachment, '', 'base64', $mime_type); $this->data->attached_file = 1; // store it for the log model } if (FCP_trace::tracing()) { FCP_trace::trace("=====> Sending admin email: " . print_r($mail, true)); } if (defined('LAFC_DEMO_MODE')) { $ret_main = true; } else { FCP_trace::trace("****> Calling mail->Send()"); $ret_main = $mail->Send(); FCP_trace::trace("****> Back from mail->Send()"); } if ($ret_main === true) { $this->data->status_main = '1'; FCP_trace::trace("=====> Admin email sent ok"); } else { $this->data->status_main = $mail->ErrorInfo; FCP_trace::trace("=====> Admin email send failed: " . $mail->ErrorInfo); } // if we should send the user a copy, send it separately // don't even attempt it if the from_email address is blank if (!empty($this->data->from_email) and ($config_data->show_copy == LAFC_COPYME_ALWAYS or $this->data->show_copy == 1)) { $body = $this->email_merge($config_data->user_template, $config_data); $clean_body = JMailHelper::cleanBody($body); $mail = JFactory::getMailer(); if ($config_data->email_html) { $mail->IsHTML(true); } else { $clean_body = $this->html2text($clean_body); } if ($config_data->email_from == '') { // v7.01 $email_from = $app->getCfg('mailfrom'); } else { $email_from = $config_data->email_from; } // use FlexiContact Global Configuration if ($config_data->email_from_name == '') { // v7.01 $email_from_name = $app->getCfg('fromname'); } else { $email_from_name = $config_data->email_from_name; } // use FlexiContact Global Configuration $mail->setSender(array($email_from, $email_from_name)); $mail->addRecipient($this->data->from_email); $mail->setSubject($clean_subject); $mail->setBody($clean_body); if (FCP_trace::tracing()) { FCP_trace::trace("=====> Sending user email: " . print_r($mail, true)); } if (defined('LAFC_DEMO_MODE')) { $ret_copy = true; } else { $ret_copy = $mail->Send(); } if ($ret_copy === true) { $this->data->status_copy = '1'; FCP_trace::trace("=====> User email sent ok"); } else { $this->data->status_copy = $mail->ErrorInfo; FCP_trace::trace("=====> User email send failed: " . $mail->ErrorInfo); } } else { $this->data->status_copy = '0'; } // copy not requested or no email address provided FCP_trace::trace("=====> SendEmail function returning: " . $this->data->status_main); return $this->data->status_main; // both statuses are logged, but the main status decides what happens next }
static function load_assets($config_data) { $template = JFactory::getApplication()->getTemplate(); if (file_exists(JPATH_ROOT . '/templates/' . $template . '/' . LAFC_COMPONENT . '/assets/' . LAFC_FRONT_CSS_NAME)) { $css_path = 'templates/' . $template . '/' . LAFC_COMPONENT . '/assets/' . LAFC_FRONT_CSS_NAME; } else { $css_path = LAFC_SITE_ASSETS_URL . $config_data->css_file . '?102'; } FCP_trace::trace("Loading css: {$css_path}"); $document = JFactory::getDocument(); $document->addStyleSheet($css_path); // load our Javascript // if there are any file attachment fields, add some reference data foreach ($config_data->all_fields as $field_index => $field) { if ($field->field_type == LAFC_FIELD_ATTACHMENT) { $noup = JText::_('COM_FLEXICONTACT_FILE_UPLOAD_NOT_SUPPORTED'); $js_config_object = "fcp_config = {noup: '" . $noup . "'};"; $document->addScriptDeclaration($js_config_object); break; // only do this once } } // for Joomla 2.5 we need to load jQuery explicitly if (version_compare(JVERSION, "3.0.0", "<")) { $document->addScript('//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js'); $document->addScript('components/com_flexicontactplus/assets/jquery/jquery-noconflict.js'); $document->addScript('components/com_flexicontactplus/assets/js/bootstrap.min.js'); } else { JHtml::_('bootstrap.framework'); } if (FCP_trace::tracing()) { $document->addScript(LAFC_SITE_ASSETS_URL . 'js/uncompressed-fcp_jquery.js?7'); } else { $document->addScript(LAFC_SITE_ASSETS_URL . 'js/fcp_jquery.js?7'); } $js = "\njQuery(document).ready(fcp_setup);\n"; $document->addScriptDeclaration($js); }
static function show_image_captcha($config_data) { $html = ''; // get list of images in images directory $handle = opendir(LAFC_SITE_IMAGES_PATH); if (!$handle) { $html .= "Images directory not found"; return $html; } $image_list = array(); while (($filename = readdir($handle)) != false) { if ($filename == '.' or $filename == '..') { continue; } $imageInfo = @getimagesize(LAFC_SITE_IMAGES_PATH . '/' . $filename); if ($imageInfo === false) { continue; } // not an image if ($imageInfo[3] > 3) { // only support gif, jpg or png continue; } if ($imageInfo[0] > 150) { // if X size > 150 pixels .. continue; } // .. it's too big so skip it $image = array(); $image['filename'] = $filename; $image['width'] = $imageInfo[0]; $image['height'] = $imageInfo[1]; $image['type'] = $imageInfo[2]; $image_list[] = $image; } closedir($handle); if (empty($image_list)) { $html .= "No suitable images in images directory"; return $html; } $imageCount = count($image_list); if ($imageCount < $config_data->num_images) { $html .= 'Not enough images in images directory. Requested: ' . $config_data->num_images . ' Found: ' . $imageCount . '<br />'; return $html; } // choose the images $i = 0; $randoms = array(); while ($i < $config_data->num_images) { $imageNum = rand(0, $imageCount - 1); // get a random number if (in_array($imageNum, $randoms)) { // if already chosen continue; } // try again $randoms[] = $imageNum; // add to random number array $i++; // got one more } // build the captcha information structure $captcha_info = new stdClass(); $captcha_info->num_images = $config_data->num_images; $captcha_info->noise = $config_data->noise; $captcha_info->images = array(); for ($i = 0; $i < $config_data->num_images; $i++) { $j = $randoms[$i]; // index of the next chosen image $image = $image_list[$j]; // point to image info $captcha_info->images[$i] = $image; // copy the image info array into the captcha_info structure } // choose the target image and store it in the captcha_info structure $captcha_info->target = rand(0, $config_data->num_images - 1); $target_filename = $captcha_info->images[$captcha_info->target]['filename']; if (FCP_trace::tracing()) { FCP_trace::trace("Created captcha_info structure: " . print_r($captcha_info, true)); } // store the captcha_info structure in the session $app = JFactory::getApplication(); $app->setUserState(LAFC_COMPONENT . "_captcha_info", $captcha_info); // load the additional language file provided by our image packs $lang = JFactory::getLanguage(); $lang->load('com_flexicontact_captcha', JPATH_SITE); // get the description of the target image and make the user prompt $target_text = JText::_('COM_FLEXICONTACT_IMAGE_' . strtoupper($target_filename)); if (JText::_('COM_FLEXICONTACT_OBJECT_FIRST') == "Yes") { $text = $target_text . ' ' . JText::_('COM_FLEXICONTACT_SELECT_IMAGE'); } else { $text = JText::_('COM_FLEXICONTACT_SELECT_IMAGE') . ' ' . $target_text; } $html .= "\n" . '<label>' . $text . '</label>'; // draw the chosen images // In NOISE_RAW mode we use normal image file <img> tags, which enables us to work with the Joomla system cache plugin enabled // In the other modes we specify that our component will serve the images, which allows us to add noise $html .= "\n" . '<div class="fcp_image_inner">'; foreach ($captcha_info->images as $index => $image) { $img_name = $image['filename']; $image_height = $image['height']; $image_width = $image['width']; self::image_size($config_data, $image_height, $image_width); if ($config_data->noise == NOISE_RAW) { $src = JURI::root() . 'components/com_flexicontactplus/images/' . $img_name; } else { $src = JURI::root() . 'index.php?option=com_flexicontactplus&tmpl=component&format=raw&task=image&n=' . $index . '&r=' . mt_rand(); } $imageHtml = '<img id="i_' . $img_name . '" src="' . $src . '" width="' . $image_width . '" height="' . $image_height . '" alt="" class="fcp_inactive" onclick="fcp_image_select(' . "'i_" . $img_name . "'" . ')" />'; $html .= "\n" . $imageHtml; } $html .= "\n" . '<input type="hidden" name="picselected" value="" />'; $html .= "\n" . '<input type="hidden" name="picrequested" value="' . $target_text . '" />'; $html .= "\n" . '</div><span id="fcp_err_image"></span>'; return $html; }