News Flash:
New Version of ShopClass theme 1.4.0 is Released on 13 JUNE 2018, Please upgrade your installation.

reCaptcha Topic is solved

If you are having general problems with ShopClass theme, post your questions here. This is not the place for customization or feature requests
User avatar
tuffadmin
Site Admin
Posts: 1236
Joined: Tue Jan 29, 2013 7:31 pm
Has thanked: 33 times
Been thanked: 111 times

Re: reCaptcha

Post by tuffadmin » Tue Aug 30, 2016 10:52 am

sunnysunnet wrote:
Mon Aug 29, 2016 7:44 am
we cant do anything Without disable location required plugin ? Because this plugin is importuned.
You have added this line in head.php file
<script type="text/javascript" async="" src="https://www.gstatic.com/recaptcha/api2/ ... "></script>
Which is not needed, we have already added all required js in our theme.

Also your theme folder is using unsafe 777 permissions make it to 755 or Osclass editor function in our theme will not work for security reasons.
Location required plugin is also not needed because we already check this in our theme. By enabling it you just increasing page-load time.
No support for unnecessary PM, use forum for support queries.
Please give us good review if you bought our theme from Osclass Market

sunnysunnet
Beginner
Posts: 18
Joined: Fri Aug 26, 2016 5:21 pm

Re: reCaptcha

Post by sunnysunnet » Tue Aug 30, 2016 11:10 am

I change permission 777 to 755, But I not understand what is this.

""You have added this line in head.php file
<script type="text/javascript" async="" src="https://www.gstatic.com/recaptcha/api2/ ... "></script>
Which is not needed, we have already added all required js in our theme.""

I check my head.php file. i not find anything. I not add any file , Can you clear me..

User avatar
tuffadmin
Site Admin
Posts: 1236
Joined: Tue Jan 29, 2013 7:31 pm
Has thanked: 33 times
Been thanked: 111 times

Re: reCaptcha

Post by tuffadmin » Tue Aug 30, 2016 12:17 pm

Ok my fault, overlooked the main issue that hooks are not running in UI. Can you check your error logs?
No support for unnecessary PM, use forum for support queries.
Please give us good review if you bought our theme from Osclass Market

sunnysunnet
Beginner
Posts: 18
Joined: Fri Aug 26, 2016 5:21 pm

Re: reCaptcha

Post by sunnysunnet » Tue Aug 30, 2016 1:16 pm

Helo,
I dont know these things, I am a beginner. I check on my control panel error log. But there is nothing. Blank screen

User avatar
tuffadmin
Site Admin
Posts: 1236
Joined: Tue Jan 29, 2013 7:31 pm
Has thanked: 33 times
Been thanked: 111 times

Re: reCaptcha

Post by tuffadmin » Wed Aug 31, 2016 4:19 am

I am working on it.
No support for unnecessary PM, use forum for support queries.
Please give us good review if you bought our theme from Osclass Market

User avatar
tuffadmin
Site Admin
Posts: 1236
Joined: Tue Jan 29, 2013 7:31 pm
Has thanked: 33 times
Been thanked: 111 times

Re: reCaptcha

Post by tuffadmin » Wed Aug 31, 2016 5:39 am

Made some changes in your site and it is working now, we will include these changes in our next update.
For others who are having same issue, please follow these step.
1. open spam-security.php and replace all content with this.

Code: Select all

<?php
	function tfc_dup_create_table() {
	        $path = WebThemes::newInstance()->getCurrentThemePath().'sql/duplicate-struct.sql' ;
            $sql  = file_get_contents( $path ) ;
            $conn = DBConnectionClass::newInstance();
    		$c_db = $conn->getOsclassDb();
    		$comm = new DBCommandClass($c_db);
    		$imported = $comm->importSQL($sql);
    		return $imported;
	} 
	//Duplicate removel helper functions
	
	function tfc_item_posted_duplicate($item) {
	
	 $itemId = $item['pk_i_id'];
	 $conn = getConnection();
	   $item_d = $item['s_description'];
	       	$item_t = $item['s_title'];
	     
	     $result_dup_title = $conn->osc_dbFetchResults("SELECT fk_i_item_id FROM %st_item_dup WHERE dup_title= '%s'", DB_TABLE_PREFIX, md5($item_t));
	     $result_dup_desc =  $conn->osc_dbFetchResults("SELECT fk_i_item_id FROM %st_item_dup WHERE dup_desc= '%s'", DB_TABLE_PREFIX, md5($item_d));
	 if (tfc_getPref('duplicate_method') == 1){
	 	 $result_dup_desc = 0;
	 }
	 if (tfc_getPref('duplicate_method') == 2){
	 	 $result_dup_title = 0;
	 }
	 if (count($result_dup_title) > 0 || count($result_dup_desc) > 0) {
	    
	     	//Adding $itemId will mark current ad as spam
	          $conn->osc_dbExec("UPDATE %st_item SET b_enabled = 0 WHERE pk_i_id = %d", DB_TABLE_PREFIX, $itemId);
	          
	          //mark as duplicate
	          $column = 'i_num_repeated';
	          $id = $dupItem['fk_i_item_id'];
	          ItemStats::newInstance()->increase( $column, $id );
	     
	}
	 
	 else{
	 $same_emails_id = $conn->osc_dbFetchResults("SELECT pk_i_id FROM %st_item WHERE s_contact_email= '%s' ", DB_TABLE_PREFIX, $item['s_contact_email']);
	
	 foreach ($same_emails_id as $same_email_id) {
	    if($itemId != $same_email_id['pk_i_id']) {
	       $result_des_tit = $conn->osc_dbFetchResult("SELECT * FROM %st_item_description WHERE fk_i_item_id= %d", DB_TABLE_PREFIX, $same_email_id['pk_i_id']);
	       $same_desc  = $result_des_tit['s_description'];
	       $same_title = $result_des_tit['s_title'];
	
	 	if ( md5($item_t) == md5($same_title) || md5($same_desc) == md5($item_d)) {
	          //Replace $itemId with $same_email_id['pk_i_id'] to mark all old ad as spam
	          //Adding $itemId will mark current ad as spam
	          $conn->osc_dbExec("UPDATE %st_item SET b_enabled = 0 WHERE pk_i_id = %d", DB_TABLE_PREFIX, $itemId);
	          
	          //mark as duplicate
	          $column = 'i_num_repeated';
	          $id = $itemId;
	          ItemStats::newInstance()->increase( $column, $id );           
	   	}
	   	
	 }
	}
	}
	
	}
	function tfc_item_edited_duplicate($item) {
	
	 $itemId = $item['pk_i_id'];
	 $conn = getConnection();
	 		$item_d = $item['s_description'];
	       	$item_t = $item['s_title'];
	     
	     $result_dup_title = $conn->osc_dbFetchResults("SELECT fk_i_item_id FROM %st_item_dup WHERE dup_title= '%s' AND fk_i_item_id <> %s", DB_TABLE_PREFIX, md5($item_t),$itemId);
	     $result_dup_desc =  $conn->osc_dbFetchResults("SELECT fk_i_item_id FROM %st_item_dup WHERE dup_desc= '%s' AND fk_i_item_id <> %s", DB_TABLE_PREFIX, md5($item_d),$itemId);
	 if (count($result_dup_title) > 0 && !(tfc_getPref('duplicate_method') == 2)) {
	     foreach( $result_dup_title as $dupItem){
	     	//Adding $itemId will mark current ad as spam
	          $conn->osc_dbExec("UPDATE %st_item SET b_enabled = 0 WHERE pk_i_id = %d", DB_TABLE_PREFIX, $dupItem['fk_i_item_id']);
	          
	          //mark as duplicate
	          $column = 'i_num_repeated';
	          $id = $dupItem['fk_i_item_id'];
	          ItemStats::newInstance()->increase( $column, $id );
	     
	 	}
	}
	elseif (count($result_dup_desc) > 0 && !(tfc_getPref('duplicate_method') == 1)) {
	     foreach( $result_dup_desc as $dupItem){
	     	//Adding $itemId will mark current ad as spam
	          $conn->osc_dbExec("UPDATE %st_item SET b_enabled = 0 WHERE pk_i_id = %d", DB_TABLE_PREFIX, $dupItem['fk_i_item_id']);
	          
	          //mark as duplicate
	          $column = 'i_num_repeated';
	          $id = $dupItem['fk_i_item_id'];
	          ItemStats::newInstance()->increase( $column, $id );
	     
	 	}
	}
	 
	 else{
	 $same_emails_id = $conn->osc_dbFetchResults("SELECT pk_i_id FROM %st_item WHERE s_contact_email= '%s' ", DB_TABLE_PREFIX, $item['s_contact_email']);
	
	 foreach ($same_emails_id as $same_email_id) {
	    if($itemId != $same_email_id['pk_i_id']) {
	       $result_des_tit = $conn->osc_dbFetchResult("SELECT * FROM %st_item_description WHERE fk_i_item_id= %d", DB_TABLE_PREFIX, $same_email_id['pk_i_id']);
	       $same_desc  = $result_des_tit['s_description'];
	       $same_title = $result_des_tit['s_title'];
	
	
	
	     if ( md5($item_t) == md5($same_title) || md5($same_desc) == md5($item_d)) {
	          //Replace $itemId with $same_email_id['pk_i_id'] to mark all old ad as spam
	          //Adding $itemId will mark current ad as spam
	          $conn->osc_dbExec("UPDATE %st_item SET b_enabled = 0 WHERE pk_i_id = %d", DB_TABLE_PREFIX, $itemId);
	          
	          //mark as duplicate
	          $column = 'i_num_repeated';
	          $id = $itemId;
	          ItemStats::newInstance()->increase( $column, $id );           
	   	}
	   	
	 }
	}
	}
	
	}
	
	if (osc_get_preference('duplicate_helper','shopclass_theme') ==1) {
	osc_add_hook('posted_item', 'tfc_item_posted_duplicate');
	osc_add_hook('edited_item', 'tfc_item_edited_duplicate');
	}
//noCaptcha Recaptcha

function tfc_recaptcha_show(){
	echo '<div id="recaptcha1" class="g-recaptcha"></div>';
}
function tfc_recaptcha_comment(){
	echo '<div id="recaptcha2" class="g-recaptcha form-group"></div>';
}
function tfc_recaptcha_validation($aItem = NULL){

		$secret_key 	= tfc_getpref('tfc_recaptcha_secret_key'); 
		$response = Params::getParam('g-recaptcha-response');

		$valid = false;
		if ( !$secret_key ) //if $secre_key is not set
			$valid = true;
		
		if ( !$response )
			$valid = false;
			
		$request = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secret_key."&response=".$response);
		$result = json_decode( $request, true );
        if ( true == $result['success'] ){
			$valid= true;
		}
		if ($valid == false) {
	  	// the recaptcha code found incorrect
	  	// Now handling the error so that the form processor doesn't continue
	  	$location = Rewrite::newInstance()->get_location();
	    $section  = Rewrite::newInstance()->get_section();
	    switch ($location) {
	        case ('item'):
	            switch ($section) {
	            	case 'item_add_post':
	    osc_add_flash_error_message(__('Something wrong with reCaptcha code', 'shopclass'));
						osc_redirect_to(osc_item_post_url());
				 	break;
	            	case 'item_edit_post':
	            	    $secret = Params::getParam('secret');
	        			$id     = Params::getParam('id');
	
	    osc_add_flash_error_message(__('Something wrong with reCaptcha code', 'shopclass'));
						osc_redirect_to(osc_item_edit_url($secret, $id) );
					break;
					case 'send_friend_post':
	    osc_add_flash_error_message(__('Something wrong with reCaptcha code', 'shopclass'));
						osc_redirect_to(osc_item_send_friend_url() );
					break;
					case 'add_comment':
					Session::newInstance()->_setForm('commentAuthorName', $authorName);
	                Session::newInstance()->_setForm('commentTitle', $title);
	                Session::newInstance()->_setForm('commentAuthorEmail', $authorEmail);
	                Session::newInstance()->_setForm('commentBody', $body);
	    			osc_add_flash_error_message(__('Something wrong with reCaptcha code', 'shopclass'));
					osc_redirect_to(osc_item_url());
					break;
					default:
	    				osc_add_flash_error_message(__('Something wrong with reCaptcha code', 'shopclass'));
						osc_redirect_to(osc_item_url());
					break;
				}
			break;
			case ('register'):
	    osc_add_flash_error_message(__('Something wrong with reCaptcha code', 'shopclass'));
				osc_redirect_to(osc_register_account_url() );
			break;
			case ('contact'):
	    osc_add_flash_error_message(__('Something wrong with reCaptcha code', 'shopclass'));
				osc_redirect_to(osc_contact_url() );
			break;
			case ('user'):
				switch($section){
					case ('profile'):
	    			osc_add_flash_error_message(__('Something wrong with reCaptcha code', 'shopclass'));
					osc_redirect_to(osc_user_public_profile_url());
				}
			break;
			case ('ajax'):
					global $status_num;
					$status_num = 10;
			break;	 		
	
		}
	  		
		}
	
}	
function tfc_recaptcha_js(){
?>
<script>
      var recaptcha1;
      var option = {
      	'sitekey' : '<?php echo tfc_getpref('tfc_recaptcha_site_key');?>', //Replace this with your Site key
        'theme' : 'light'}
      var tfcCallBack = function() {
        //Render the recaptcha1 on the element with ID "recaptcha1"
        recaptcha1 = grecaptcha.render('recaptcha1', option);
      };
</script>
<script src="https://www.google.com/recaptcha/api.js?onload=tfcCallBack&render=explicit" async defer></script>
<?php
}
function tfc_recaptcha_js_loader(){	
osc_add_hook('footer_scripts_loaded','tfc_recaptcha_js');
}
	function tfc_honeypot_show() {

	echo 	'<div class="donotdisturb">
		<input type="text" name="donotdisturb" size="10" maxlength="6" />
		</div>';
 }
	function tfc_honeypot_validation() {
		
		$honeypot = Params::getParam('donotdisturb');
	    
		if (!(empty($honeypot))) {
	  	// the captcha code found incorrect
	  	// Now handling the error so that the form processor doesn't continue
	  	$location = Rewrite::newInstance()->get_location();
	    $section  = Rewrite::newInstance()->get_section();
	    osc_add_flash_error_message(__('Something is wrong please try again or contact us', 'shopclass'));
	    switch ($location) {
	        case ('item'):
	            switch ($section) {
	            	case 'item_add_post':
						osc_redirect_to(osc_item_post_url());
				 	break;
	            	case 'item_edit_post':
	            	    $secret = Params::getParam('secret');
	        			$id     = Params::getParam('id');
	
						osc_redirect_to(osc_item_edit_url($secret, $id) );
					break;
					case 'send_friend_post':
						osc_redirect_to(osc_item_send_friend_url() );
					break;
					case 'add_comment':
						osc_redirect_to(osc_item_url());
					break;
					default:
						osc_redirect_to(osc_item_url());
					break;
						          }
			break;
			case ('register'):
				osc_redirect_to(osc_register_account_url() );
			break;
			case ('contact'):
				osc_redirect_to(osc_contact_url() );
			break;
			case ('user'):
				osc_redirect_to(osc_user_public_profile_url());
			break;	 		
	
		}
	  		
		}
	}
	
	//Duplicate helper functions
	define( 'DUP_TABLE', DB_TABLE_PREFIX . 't_item_dup' ) ;
	    if( !function_exists( 'tfc_dup_form_post' ) ) {
	       function tfc_dup_form_post($item)  {
	
	           $itemID = $item['pk_i_id'];
	           $itemTitle = $item['s_title'];
	           $itemDesc = $item['s_description'];
	           if( empty($itemTitle) ) return false ;
	           if( empty($itemDesc) ) return false;
	

	
	           $values = array(
	               'fk_i_item_id' => $itemID,
	               'dup_title'    => md5($itemTitle),
	               'dup_desc'    => md5($itemDesc),
	           ) ;
	           $dao = New DAO;
	           $dao->dao->insert( DUP_TABLE, $values ) ;
	       }
	   }
	
	
	   if( !function_exists( 'tfc_dup_item_edit_post' ) ) {
	       function tfc_dup_item_edit_post( $item ) {
	
	           $itemID = $item['pk_i_id'];
	           $itemTitle = $item['s_title'];
	           $itemDesc = $item['s_description'];
	
	
	           $values = array(
	               'fk_i_item_id' => $itemID,
	               'dup_title'    => md5($itemTitle),
	               'dup_desc'    => md5($itemDesc),
	           ) ;
	           $dao = New DAO;
	           $dao->dao->replace( DUP_TABLE, $values ) ;
	       }
	   }
	
	   if( !function_exists( 'tfc_dup_delete_item' ) ) {
	       function tfc_dup_delete_item($itemID) {

				
	           $where = array(
	               'fk_i_item_id' => $itemID
	           ) ;
	           $dao = New DAO;
	           $dao->dao->delete( DUP_TABLE, $where ) ;
	       }
	   }
	
	   // insert title, description md5 hash
	   osc_add_hook( 'posted_item', 'tfc_dup_form_post' ) ;
	
	   // update duplicate hash after edit POST
	   osc_add_hook( 'edited_item', 'tfc_dup_item_edit_post' ) ;
	
	   // delete duplicate hash of the deleted item
	   osc_add_hook( 'delete_item', 'tfc_dup_delete_item' ) ;
	
	if (osc_get_preference('enable_honeypot','shopclass_theme') ==1) {
		osc_add_hook('hook_email_contact_user','tfc_honeypot_validation',1);//checked
		osc_add_hook('tf_after_comment_form','tfc_honeypot_show');//checked
		osc_add_hook('tf_after_form','tfc_honeypot_show');//checked
		osc_add_hook('pre_item_add','tfc_honeypot_validation');//checked
		osc_add_hook('pre_item_edit','tfc_honeypot_validation');//checked
		osc_add_hook('before_add_comment','tfc_honeypot_validation');//checked
		osc_add_hook('pre_user_post','tfc_honeypot_validation');//checked
		osc_add_hook('pre_contact_post','tfc_honeypot_validation');//checked
		osc_add_hook('pre_item_send_friend_post','tfc_honeypot_validation');//checked
		osc_add_hook('pre_item_contact_post','tfc_honeypot_validation');//checked
	}
	

	if (osc_get_preference('enable_recaptcha','shopclass_theme') ==1) {
		osc_add_hook('hook_email_contact_user','tfc_recaptcha_validation',1);//checked
		osc_add_hook('tf_after_comment_form','tfc_recaptcha_comment');//checked
		osc_add_hook('tf_after_form','tfc_recaptcha_show');//checked
		osc_add_hook('pre_item_add','tfc_recaptcha_validation');//checked
		osc_add_hook('pre_item_edit','tfc_recaptcha_validation');//checked
		osc_add_hook('before_add_comment','tfc_recaptcha_validation');//checked
		osc_add_hook('pre_user_post','tfc_recaptcha_validation');//checked
		osc_add_hook('pre_contact_post','tfc_recaptcha_validation');//checked
		osc_add_hook('pre_item_send_friend_post','tfc_recaptcha_validation');//checked
		osc_add_hook('pre_item_contact_post','tfc_recaptcha_validation');//checked
	}
	if (osc_get_preference('enable_recaptcha','shopclass_theme') ==1) {
		if (osc_is_ad_page()){
		$recaptcha_item_js = function(){ ?>
							<script>
      							var recaptcha1;
      							var recaptcha2;
      							var option = {
      								'sitekey' : '<?php echo tfc_getpref('tfc_recaptcha_site_key');?>', //Replace this with your Site key
        							'theme' : 'light'}
      							var tfcCallBack = function() {
      							<?php if( !osc_item_is_expired () ) { ?>
        						<?php if( !( ( osc_logged_user_id() == osc_item_user_id() ) && osc_logged_user_id() != 0 ) ) { ?>
        						<?php if(osc_reg_user_can_contact() && osc_is_web_user_logged_in() || !osc_reg_user_can_contact() ) { ?>
        						recaptcha1 = grecaptcha.render('recaptcha1', option);
        						<?php }}} ?>
        						<?php if( osc_reg_user_post_comments () && osc_is_web_user_logged_in() && !tfc_getpref('enable_disqus') || !osc_reg_user_post_comments() ) { ?>
        						recaptcha2 = grecaptcha.render('recaptcha2', option);
        						<?php } ?>	
      						 };
							</script>
							<script src="https://www.google.com/recaptcha/api.js?onload=tfcCallBack&render=explicit" async defer></script> 
							<?php };
							osc_add_hook('footer_scripts_loaded',$recaptcha_item_js);
		}
		else {
		osc_add_hook('hook_email_contact_user','tfc_recaptcha_js_loader');//checked
		osc_add_hook('tf_after_form','tfc_recaptcha_js_loader');//checked
		}
	}
?>


2. Remove this line from head.php

Code: Select all

	<script src="https://www.google.com/recaptcha/api.js?onload=tfcCallBack&render=explicit" async defer></script>
Please post a reply if you encounter any bug in this code.
No support for unnecessary PM, use forum for support queries.
Please give us good review if you bought our theme from Osclass Market

reuel1089
Starter
Posts: 28
Joined: Sun Aug 28, 2016 2:01 am

Re: reCaptcha

Post by reuel1089 » Wed Aug 31, 2016 6:03 am

Good job it works

sunnysunnet
Beginner
Posts: 18
Joined: Fri Aug 26, 2016 5:21 pm

Re: reCaptcha  Topic is solved

Post by sunnysunnet » Wed Aug 31, 2016 6:33 am

Good Job, Working well. Thank you admin.

Jeannine
Noob
Posts: 1
Joined: Wed Jan 31, 2018 3:16 pm

Re: reCaptcha

Post by Jeannine » Thu Feb 01, 2018 7:10 am

Hi, I don`t know this things, I am a beginner.

User avatar
tuffadmin
Site Admin
Posts: 1236
Joined: Tue Jan 29, 2013 7:31 pm
Has thanked: 33 times
Been thanked: 111 times

Re: reCaptcha

Post by tuffadmin » Sat Feb 17, 2018 3:45 am

Jeannine wrote:
Thu Feb 01, 2018 7:10 am
Hi, I don`t know this things, I am a beginner.
It is not needed for new version.
No support for unnecessary PM, use forum for support queries.
Please give us good review if you bought our theme from Osclass Market

Post Reply