Advertisement:

Author Topic: How to add RENEW / REFRESH / REPOST feature to OSCLASS  (Read 20670 times)

byteGator

  • Osclass Hero
  • Sr. Member
  • *
  • Posts: 346
  • Simple Mind is a Beautiful Mind
How to add RENEW / REFRESH / REPOST feature to OSCLASS
« on: December 26, 2013, 03:58:29 pm »
At ItemAction:

Code: [Select]
        public function renew( $id, $secret = NULL )
        {
            $aWhere = array();
            if( $secret == NULL ) {
                $item[0] = $this->manager->findByPrimaryKey( $id );
                $aWhere = array('pk_i_id' => $id);
            } else {
                $item = $this->manager->listWhere("i.s_secret = '%s' AND i.pk_i_id = '%s' ", $secret, $id);
                $aWhere = array('s_secret' => $secret, 'pk_i_id' => $id);
            }
            if( count($item) == 0 ) {
                return false;
            }
            if($item[0]['b_enabled']==0 || $item[0]['b_active']==0 || $item[0]['b_spam']!=0) {
                return false;
            }
            osc_run_hook('pre_item_renew', $item[0]);
            $_category = Category::newInstance()->findByPrimaryKey($item[0]['fk_i_category_id']);
            $expdate = date('Y-m-d H:i:s', time() + 86400*$_category['i_expiration_days']);

                $result = $this->manager->update(
                    array('dt_pub_date' => date('Y-m-d H:i:s'), 'dt_expiration' => $expdate),
                    $aWhere
                );

            // updated correctly
            if($result == 1) {
                $_locale = reset($item[0]['locale']);
                $locale_code = $_locale['fk_c_locale_code'];
                $item[0]['s_title'] = bg_sanitize_title($item[0]['s_title']);
                $this->manager->updateLocaleForce($item[0]['pk_i_id'] , $locale_code, $item[0]['s_title'], $item[0]['s_description']);
                osc_run_hook('item_renewed', $item[0]);
                if (osc_isExpired($item[0]['dt_expiration'])) {
                    if($item[0]['fk_i_user_id']!=null) {
                        User::newInstance()->increaseNumItems($item[0]['fk_i_user_id']);
                    }
                    CategoryStats::newInstance()->increaseNumItems($item[0]['fk_i_category_id']);
                    CountryStats::newInstance()->increaseNumItems($item[0]['fk_c_country_code']);
                    RegionStats::newInstance()->increaseNumItems($item[0]['fk_i_region_id']);
                    CityStats::newInstance()->increaseNumItems($item[0]['fk_i_city_id']);
                }   
                return true;
            }
        }

at osclass/controller/item.php


Code: [Select]
                case 'item_renew':
                    $secret = Params::getParam('secret');
                    $id     = Params::getParam('id');
                    if (osc_is_admin_user_logged_in()) {
                        $item    = $this->itemManager->listWhere("i.pk_i_id = '%s'", addslashes($id));
                        if( count($item) == 0 ) {
                            $this->do404();
                            return;
                        }
                    } else {   
                        $item   = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s') OR (i.fk_i_user_id = '%d'))", addslashes($id), addslashes($secret), addslashes($this->userId));

                        // item doesn't exist
                        if( count($item) == 0 ) {
                            $this->do404();
                            return;
                        }
                        $datenow = new DateTime('NOW');
                        $itemdate = new DateTime(substr($item[0]['dt_pub_date'],0,10));
                        $ddate = date_diff($itemdate,$datenow)->days;

                        // TODO: SET PREF. NUMBER OF DAYS BEFORE ITEM CAN BE RENEWED.
                       //wait 2 days before item can be renewed
                        if ($ddate < 2) {
                            osc_add_flash_warning_message( _m("Can't renew this item yet") );
                            $this->redirectTo(osc_user_list_items_url());
                        }
                    }   
                    $mItems = new ItemActions(false);
                    $success = $mItems->renew( $item[0]['pk_i_id'], $item[0]['s_secret']);
                    if( $success ) {
                        osc_run_hook('item_renewed', $item[0]);
                        osc_add_flash_ok_message( _m('The listing has been renewed') );
                    } else {
                        osc_add_flash_error_message( _m("The listing can't be renewed") );
                    }
                    if (osc_is_admin_user_logged_in()) {
                        $this->redirectTo(osc_get_http_referer());
                    } else {
                        $this->redirectTo(osc_user_list_items_url());
                    }   
                break;

Renew URL: (better put it at oc-includes/osclass/helper/hDefine.php)

Code: [Select]
    function osc_item_renew_url($secret = '', $id = '') {
        if ($id == '') { $id = osc_item_id(); };
            return osc_base_url(true) . '?page=item&action=item_renew&id=' . $id . ($secret != '' ? '&secret=' . $secret : '');
    }


Link example at Loop-single.php

Code: [Select]
                                        $datenow = new DateTime('NOW');
                                        $itemdate = new DateTime(substr(osc_item_field('dt_pub_date'),0,10));
                                        $ddate = date_diff($itemdate,$datenow);

                                        //wait 2 days before item can be renewed
                                        if ($ddate->days >= 2) { ?> 
                                            <a href="<?php echo osc_item_renew_url(); ?>" rel="nofollow"><?php _e('ReNew''bender'); ?></a>
                                            <span>|</span>
                                        <?php 

If you want to put renew link at email then you have to put secret and id :

Code: [Select]
osc_item_renew_url( $item['s_secret'], $item['pk_i_id']);

« Last Edit: April 23, 2014, 06:28:49 pm by byteGator »

Aficionado

  • Guest
Re: How to add RENEW / REFRESH / REPOST feature to OSCLASS
« Reply #1 on: December 26, 2013, 04:14:18 pm »
Thanks for your work. We appreciate it.

One question: the Renew option appears where exactly ? And what is needed in the themes code ?



byteGator

  • Osclass Hero
  • Sr. Member
  • *
  • Posts: 346
  • Simple Mind is a Beautiful Mind
Re: How to add RENEW / REFRESH / REPOST feature to OSCLASS
« Reply #2 on: December 26, 2013, 04:38:45 pm »
Hi...

I put renew link at oc-content/themes/bender/loop-single.php.

Regards.

Aficionado

  • Guest
Re: How to add RENEW / REFRESH / REPOST feature to OSCLASS
« Reply #3 on: December 26, 2013, 04:52:09 pm »
Hi...

I put renew link at oc-content/themes/bender/loop-single.php.

Regards.

Hmmm... 

Any ideas where to put that if we use the Modern there ? What is the equivelent file we need to edit ?


serjuc11111

  • Hero Member
  • *****
  • Posts: 814
Re: How to add RENEW / REFRESH / REPOST feature to OSCLASS
« Reply #4 on: December 26, 2013, 04:55:19 pm »
link u can put in user-dabsoard!
how can u make a email notification when the ad expired included that link inside??
thx
i send u the location of files where to modify

byteGator

  • Osclass Hero
  • Sr. Member
  • *
  • Posts: 346
  • Simple Mind is a Beautiful Mind
Re: How to add RENEW / REFRESH / REPOST feature to OSCLASS
« Reply #5 on: December 26, 2013, 04:58:01 pm »
Hi...

I put renew link at oc-content/themes/bender/loop-single.php.

Regards.

Hmmm... 

Any ideas where to put that if we use the Modern there ? What is the equivelent file we need to edit ?

I never play with Modern themes.
But maybe something like item.php or user-item.php ???

hint: search for EDIT link at your themes, and put RENEW link there.

byteGator

  • Osclass Hero
  • Sr. Member
  • *
  • Posts: 346
  • Simple Mind is a Beautiful Mind
Re: How to add RENEW / REFRESH / REPOST feature to OSCLASS
« Reply #6 on: December 26, 2013, 05:01:03 pm »
link u can put in user-dabsoard!
how can u make a email notification when the ad expired included that link inside??
thx
i send u the location of files where to modify

To put link at your email. just add secret key ( you can look at activate / edit link ).

Aficionado

  • Guest
Re: How to add RENEW / REFRESH / REPOST feature to OSCLASS
« Reply #7 on: December 26, 2013, 05:01:33 pm »


hint: search for EDIT link at your themes, and put RENEW link there.

I will do that, thanks for the hint. Could work.

Is ANYTHING else in your changes dependant to bender theme ?

serjuc11111

  • Hero Member
  • *****
  • Posts: 814
Re: How to add RENEW / REFRESH / REPOST feature to OSCLASS
« Reply #8 on: December 26, 2013, 05:02:39 pm »
1.oc-include/osclass/itemaction.php
2.oc-include/osclass/controller/item.php
3.modern-theme/user-dashboard.php(near edit line)

byteGator

  • Osclass Hero
  • Sr. Member
  • *
  • Posts: 346
  • Simple Mind is a Beautiful Mind
Re: How to add RENEW / REFRESH / REPOST feature to OSCLASS
« Reply #9 on: December 26, 2013, 05:05:13 pm »


hint: search for EDIT link at your themes, and put RENEW link there.

I will do that, thanks for the hint. Could work.

Is ANYTHING else in your changes dependant to bender theme ?

Nothing else.

Please try it at your localhost first. I use this code at mysite (with some more modification), but I am affraid I miss something because at my site the code is a little bit different. And please report your result here.

Regards

byteGator

  • Osclass Hero
  • Sr. Member
  • *
  • Posts: 346
  • Simple Mind is a Beautiful Mind
Re: How to add RENEW / REFRESH / REPOST feature to OSCLASS
« Reply #10 on: December 26, 2013, 05:12:07 pm »
1.oc-include/osclass/itemaction.php
2.oc-include/osclass/controller/item.php
3.modern-theme/user-dashboard.php(near edit line)

And it is better to put osc_item_renew_url at oc-includes/osclass/helper/hDefine.php

serjuc11111

  • Hero Member
  • *****
  • Posts: 814
Re: How to add RENEW / REFRESH / REPOST feature to OSCLASS
« Reply #11 on: December 26, 2013, 06:20:22 pm »
it's working!:)
nice!thx sir!

where can we find "email templates" when ads expired to edit this or to add the link which allows user to repost respective ads by one click on that link?
thx

serjuc11111

  • Hero Member
  • *****
  • Posts: 814
Re: How to add RENEW / REFRESH / REPOST feature to OSCLASS
« Reply #12 on: December 26, 2013, 06:47:03 pm »
it is ok to put this link in email templates

 <a href="<?php echo osc_item_renew_url(); ?>"><?php _e('Repost ads', 'modern'); ?></a>

??
in email teplates i have 2 templates:
email_ad_expire ({CONTACT_NAME} {REPUBLISH_URL}) keywords accepted
email_ad_expired ({CONTACT_NAME} {REPUBLISH_URL}) keywords accepted
thx
                                         
« Last Edit: December 26, 2013, 06:49:36 pm by serjuc11111 »

Aficionado

  • Guest
Re: How to add RENEW / REFRESH / REPOST feature to OSCLASS
« Reply #13 on: December 27, 2013, 01:59:37 am »
1.oc-include/osclass/itemaction.php
2.oc-include/osclass/controller/item.php
3.modern-theme/user-dashboard.php(near edit line)

Could you share this file from your changed working files ?

3.modern-theme/user-dashboard.php(near edit line)

Thanks

design

  • Hero Member
  • *****
  • Posts: 2619
  • Osclass 3.5 MAC/PC w/ Modern Browsers
Re: How to add RENEW / REFRESH / REPOST feature to OSCLASS
« Reply #14 on: December 27, 2013, 02:08:33 am »
so many core files to change, will _conejo add this to a new version? It seems like it is something a lot of people want.