I have not be able to get it fully working, as I had moved this one to the back burner temporarily as I have other upgrades, etc. to make before going live.
Adding the
Code:
global $zco_notifier;
fixed that error, but then I found some other issues...
I now having it working, except for the error message when you do not check the "I'm not a robot" box,
It will currently show the "Please fill in the required information and submit it again. Thank you." error, then when you check the box it sends properly.
Almost there...
This is what I have in the class.faq_request.php file:
Code:
<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce |
// +----------------------------------------------------------------------+
// | Copyright (c) 2007-2008 Numinix Technology http://www.numinix.com |
// | |
// | Portions Copyright (c) 2003-2006 Zen Cart Development Team |
// | http://www.zen-cart.com/index.php |
// | |
// | Portions Copyright (c) 2003 osCommerce |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.zen-cart.com/license/2_0.txt. |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to |
// | [email protected] so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// $Id: class.store_credit.php 12 2010-09-03 20:44:47Z numinix $
//
/**
* Observer class used to handle reward points in an order
*
*/
class faqRequest extends base
{
function faqRequest() {
global $zco_notifier;
$zco_notifier->attach($this, array('NOTIFY_HEADER_END_PRODUCT_INFO'));
}
function update(&$class, $eventID, $paramsArray) {
global $messageStack;
//bof google recaptcha
global $zco_notifier, $error;
$error = false;
$zco_notifier->notify('NOTIFY_FAQ_CAPTCHA_CHECK');
//eof google rcaptcha
$fullname = zen_db_prepare_input($_POST['fullname']);
$email_address = zen_db_prepare_input($_POST['email_address']);
$subject = zen_db_prepare_input($_POST['subject']);
$message = zen_db_prepare_input($_POST['message']);
//$captcha = (int)zen_db_prepare_input($_POST['captcha']);
$extra_info = email_collect_extra_info($name, $email_address, $customer_name, $customer_email);
if(isset($_GET['action']) && $_GET['action'] == 'faq_request') {
if(isset($_POST['email_address']) && !empty($_POST['email_address']) && isset($_POST['fullname']) && !empty($_POST['fullname']) && isset($_POST['message']) && !empty($_POST['message']) && $error==false) {
// captcha
//if($captcha !== (int)$_SESSION['simpleCaptcha']) {
// echo json_encode(array('status' => 'error', 'message' => 'You have entered a wrong code. Please edit it and try again!'));
// exit();
//}
//bof google recaptcha
//$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if (!$resp->is_valid) {
// set the error code so that we can display it
//$messageStack->add($event_array[$eventID], $resp->getErrors());
$error = true;
//echo json_encode(array('status' => 'error', 'message' => 'Please confirm you are not a robot.'));
//exit();
}
//eof google recaptcha
$sql_data_array = array(
'products_id' => (int)$_GET['products_id'],
'products_model' => zen_get_products_model ((int)$_GET['products_id']),
'products_name' => zen_get_products_name((int)$_GET['products_id']),
'fullname' => $fullname,
'email_address' => $email_address,
'subject' => $subject,
'message' => $message,
'date_created' => 'now()'
);
zen_db_perform(DB_PREFIX . 'faq_questions', $sql_data_array);
$subject = sprintf('You have a new question about the %s', zen_get_products_name((int)$_GET['products_id'], $_SESSION['languages_id']));
$textmsg = $message . "\n\n" . $extra_info['TEXT'];
// Prepare HTML-portion of message
$html_msg['EMAIL_MESSAGE_HTML'] = $message;
$html_msg['CONTACT_US_OFFICE_FROM'] = '';
$html_msg['EXTRA_INFO'] = $extra_info['HTML'];
zen_mail(STORE_NAME, EMAIL_FROM, $subject, $textmsg, $fullname, $email_address, $html_msg, 'contact_us');
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
echo json_encode(array('status' => 'success', 'message' => 'We have received your question. We will respond to you as quickly as possible. Thank you for asking.'));
} else {
$messageStack->add_session('product_info', 'Your question has been sent, we will reply as soon as possible. Thank you!', 'success');
zen_redirect(zen_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . (int)$_GET['products_id']));
}
} else {
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
echo json_encode(array('status' => 'error', 'message' => 'Please fill in the required information and submit it again. Thank you.'));
} else {
$messageStack->add_session('product_info', 'Please fill in all information and try again!', 'warning');
zen_redirect(zen_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . (int)$_GET['products_id']));
}
}
exit();
}
}
}
and these are the changes I made to the class.google_recaptcha.php file:
Code:
<?php
/**
*
* @package plugins
* @copyright Copyright 2003-2012 Zen Cart Development Team
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
*
* Designed for v1.5.4
* Observer class for Google reCaptcha
*/
class google_recaptcha extends base {
/**
* @var array
*/
private $pages_to_checkcheck = array();
function __construct() {
//comment out any pages you do NOT want to check
$pages_to_check[] = 'NOTIFY_CONTACT_US_CAPTCHA_CHECK';
$pages_to_check[] = 'NOTIFY_CREATE_ACCOUNT_CAPTCHA_CHECK';
//$pages_to_check[] = 'NOTIFY_REVIEWS_WRITE_CAPTCHA_CHECK';
$pages_to_check[] = 'NOTIFY_FAQ_CAPTCHA_CHECK';
$pages_to_check[] = 'NOTIFY_FAQ_PAGE_CAPTCHA_CHECK';
$this->attach($this,$pages_to_check);
}
function update(&$class, $eventID, $paramsArray = array()) {
global $messageStack, $error, $privatekey;
require_once __DIR__ . '/google/autoload.php';
$recaptcha = new \ReCaptcha\ReCaptcha($privatekey);
// If file_get_contents() is locked down on your PHP installation to disallow
// its use with URLs, then you can use the alternative request method instead.
// This makes use of fsockopen() instead.
//$recaptcha = new \ReCaptcha\ReCaptcha($privatekey, new \ReCaptcha\RequestMethod\SocketPost());
// This makes use of curl instead
//$recaptcha = new \ReCaptcha\ReCaptcha($privatekey, new \ReCaptcha\RequestMethod\Curl());
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if (!$resp->isSuccess()) {
$event_array = array('NOTIFY_CONTACT_US_CAPTCHA_CHECK' => 'contact', 'NOTIFY_CREATE_ACCOUNT_CAPTCHA_CHECK' => 'create_account', 'NOTIFY_REVIEWS_WRITE_CAPTCHA_CHECK' => 'review_text',);
$messageStack->add($event_array[$eventID], $resp->getErrors());
$error = true;
}
return $error;
}
}
Bookmarks