Advertisement:

Author Topic: [SOLVED]How to change an AD state to BLOCKED just after published  (Read 3440 times)

Nuwan2014

  • Newbie
  • *
  • Posts: 11
[SOLVED]How to change an AD state to BLOCKED just after published
« on: September 10, 2014, 09:55:39 pm »
More edit plugin has some issues with doubling several fields such as Region, Country, etc. So for small sites can't use that plugin,if so users will see the difference between the really published ads and the numbers(count) showing in-front of the Region. So I think it will be better to change the add state to BLOCKED just after published and make it to UNBLOCK after confirmation by the admin.
This is my plan
 01. Change the ad state to block just after published
 02. Alter the Flash message to "Ad will be publish after admin's approval"
 03. Unblock the ad by admin if it is relevant

What I only need to solve is the First step. I tried that and went trough the forum but I didn't find anything. Please help to solve this problem.

My site is: www.phonebank.lk

Thank you




« Last Edit: September 12, 2014, 09:32:11 pm by Nuwan2014 »

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: How to change an AD state to BLOCKED just after published
« Reply #1 on: September 10, 2014, 11:14:36 pm »
Hi,

This should do the trick:

Add this at the very bottom of your theme functions.php (take care not to leave blank lines after this):

Code: [Select]
<?php
function cust_disable_posted_item($item) {

    
$dItem = new ItemActions(false);
    
$dItem->disable($item['pk_i_id']);
}

osc_add_hook('posted_item''cust_disable_posted_item');

function 
cust_admin_approval_message($message) {

    
$message str_replace(_m('Check your inbox to validate your listing'), 'Your ad will be published after admin\'s approval'$message);
    return 
$message;
}

osc_add_filter('flash_message_text''cust_admin_approval_message') ;
?>

You need to get checked "Users have to validate their listings" on your Admin Dashboard.

Regards

Nuwan2014

  • Newbie
  • *
  • Posts: 11
Re: How to change an AD state to BLOCKED just after published
« Reply #2 on: September 11, 2014, 07:22:51 am »
Thank you very much Teseo, It is working as I expected  :-* I am so happy.
I got another issue when publish an ad:

01. Ad blocking is 100% working and thank you very much
02. When UNBLOCK and ACTIVATE the ad it is not sending an email to the Publisher by mentioning the URLS to edit or delete the ad

Can you please give a solution for the second issue too.  :D

Thank you very much
 

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: How to change an AD state to BLOCKED just after published
« Reply #3 on: September 11, 2014, 04:44:44 pm »
Well, the tricky part here is that there is no function to send an email to simply remind the user that he/she has posted an ad, so I guess you'd have to "cannibalize" some other [now] unused function. You might use "email_new_item_non_register_user", locate it on Settings -> Email templates and change it to your liking.

Then add this at the bottom of your theme functions.php:

Code: [Select]
<?php
function cust_approved_item_mail($id) {

    
$eItem Item::newInstance()->findByPrimaryKey($id);
    
View::newInstance()->_exportVariableToView('item'$eItem);

    
fn_email_new_item_non_register_user($eItem);
}

osc_add_hook('enable_item''cust_approved_item_mail');
?>

Regards

Nuwan2014

  • Newbie
  • *
  • Posts: 11
Re: How to change an AD state to BLOCKED just after published
« Reply #4 on: September 11, 2014, 08:32:36 pm »
I placed cust_approved_item_mail() at the bottom of the functions.php. I altered validation email templates for registered users and non-registered users. It works perfect. ;D.. Thank you very much Teseo. When I test I faced another problem this could be the final problem because all other things works very nicely.

Issue is: I want to change the ad state to BLOCKED just after EDITED an ad.

Now it is working only for new ads and I want to set it to EDITED ads too. Can you please help us that too.

Thank you very Much

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: How to change an AD state to BLOCKED just after published
« Reply #5 on: September 11, 2014, 09:10:41 pm »
***CORRECTED***

1.- Blocking:

Replace this line:

Code: [Select]
osc_add_hook('posted_item', 'cust_disable_posted_item');
with

Code: [Select]
osc_add_hook('posted_item', 'cust_disable_posted_item');
osc_add_hook('edited_item', 'cust_disable_posted_item');

2.- Flash message:

Replace:

Code: [Select]
function cust_admin_approval_message($message) {

    $message = str_replace(_m('Check your inbox to validate your listing'), 'Your ad will be published after admin\'s approval', $message);
    return $message;
}

with:

Code: [Select]
function cust_admin_approval_message($message) {

    $message = str_replace(_m('Check your inbox to validate your listing'), 'Your ad will be published after admin\'s approval', $message);
    $message = str_replace(_m("Great! We've just updated your listing"), 'Your updated ad will be visible after admin\'s approval', $message);
    return $message;
}

Now, for the approval mail you'll have to use the same template, so look for a formula suitable for both cases.

Regards
« Last Edit: September 12, 2014, 08:25:24 pm by teseo »

fog

  • Hero Member
  • *****
  • Posts: 1062
Re: How to change an AD state to BLOCKED just after published
« Reply #6 on: September 11, 2014, 10:51:19 pm »
Well, the tricky part here is that there is no function to send an email to simply remind the user that he/she has posted an ad, so I guess you'd have to "cannibalize" some other [now] unused function. You might use "email_new_item_non_register_user", locate it on Settings -> Email templates and change it to your liking.

Then add this at the bottom of your theme functions.php:

Code: [Select]
<?php
function cust_approved_item_mail($id) {

    
$eItem Item::newInstance()->findByPrimaryKey($id);
    
View::newInstance()->_exportVariableToView('item'$eItem);

    
fn_email_new_item_non_register_user($eItem);
}

osc_add_hook('enable_item''cust_approved_item_mail');
?>

Regards

teseo, and marking the ad as spam, what is the correct function for this purpose? I want use the other template: email_item_validation_non_register_user, for this finality. For the user to receive notification that your ad was not approved when edit the ad.

I wanted this feature even when the ad is: active, turn off, locked and unlocked. I mean, when I mark as spam, the user receives the alert that the ad was not approved for some reason.

In my portal only registered users can post ads, and in frontend not exist a link for: report this ad like spam.

(It is in the same context, but just i case: Is better I create a new thread for my help request?)

Thank you very much for your help again, I love your functions  :)

Nuwan2014

  • Newbie
  • *
  • Posts: 11
Re: How to change an AD state to BLOCKED just after published
« Reply #7 on: September 12, 2014, 06:52:36 am »
Thank you very much Teseo...It works as expected but I don't know why the flash message was not displayed correctly. Flash message works correctly for POSTED ad but not for EDITED ad. I have attached a screenshot. I want to tell you Thank you very much for your support it was very helpful   ;D

Thank you very much

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: How to change an AD state to BLOCKED just after published
« Reply #8 on: September 12, 2014, 02:06:52 pm »
@Nuwan, that second message is intended for admin only:

if( osc_is_admin_user_logged_in() ) {
                            osc_add_flash_warning_message( _m("The listing hasn't been enabled. Please enable it in order to make it public") );
                        }

Do the tests with a dummy normal user account.

I can see another problem here, "validate your ad" mail is still being sent to the user. Check this with that new dummy account.

@fog, please open a new thread, this is getting already too complicated as it is... :D

Regards

fog

  • Hero Member
  • *****
  • Posts: 1062
Re: How to change an AD state to BLOCKED just after published
« Reply #9 on: September 12, 2014, 06:00:19 pm »
Thanks Teseo,  :)

I opened the thread here on Development.

Greetings

Nuwan2014

  • Newbie
  • *
  • Posts: 11
Re: How to change an AD state to BLOCKED just after published
« Reply #10 on: September 12, 2014, 07:17:11 pm »
Hi Teseo, this time I used a different browser after clearing the history and cache. ;D

After submit the EDITED ad, it was blocked as expected but it redirect 404 error and not change the FLASH MESSAGE as expected.

I got a FULL screenshot to show what was happened.

Thank you for your help Teseo...

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: How to change an AD state to BLOCKED just after published
« Reply #11 on: September 12, 2014, 07:26:41 pm »
Pleas paste here the code for all your new functions exactly as you have them.

Nuwan2014

  • Newbie
  • *
  • Posts: 11
Re: How to change an AD state to BLOCKED just after published
« Reply #12 on: September 12, 2014, 07:29:31 pm »
This is the code:

<?php
function cust_disable_posted_item($item) {

    $dItem = new ItemActions(false);
    $dItem->disable($item['pk_i_id']);
}

osc_add_hook('posted_item', 'cust_disable_posted_item');
osc_add_hook('edited_item', 'cust_disable_posted_item');

function cust_admin_approval_message($message) {

    $message = str_replace(_m('Check your inbox to validate your listing'), 'Your ad will be published after admin\'s approval', $message);
    return $message;
    $message = str_replace(_m("Great! We've just updated your listing"), 'Your updated ad will be visible after admin\'s approval', $message);
    return $message;
}

osc_add_filter('flash_message_text', 'cust_admin_approval_message') ;
?>
<?php
function cust_approved_item_mail($id) {

    $eItem = Item::newInstance()->findByPrimaryKey($id);
    View::newInstance()->_exportVariableToView('item', $eItem);

    fn_email_new_item_non_register_user($eItem);
}

osc_add_hook('enable_item', 'cust_approved_item_mail');
?>


teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: How to change an AD state to BLOCKED just after published
« Reply #13 on: September 12, 2014, 08:26:43 pm »
My mistake, forgot to delete one return line, this is the correct function cust_admin_approval_message:

Code: [Select]
function cust_admin_approval_message($message) {

    $message = str_replace(_m('Check your inbox to validate your listing'), 'Your ad will be published after admin\'s approval', $message);
    $message = str_replace(_m("Great! We've just updated your listing"), 'Your updated ad will be visible after admin\'s approval', $message);

    return $message;
}

Regards

Nuwan2014

  • Newbie
  • *
  • Posts: 11
Re: How to change an AD state to BLOCKED just after published
« Reply #14 on: September 12, 2014, 08:35:28 pm »
Hi Teseo, Thank you very much,,, ;D
Now it is showing the FLASH MESSAGE correctly but Can't we redirect it to the main page instead of showing 404 page..