Advertisement:

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

tabuausada

  • Jr. Member
  • **
  • Posts: 77
Re: Premium repost not working
« Reply #60 on: September 27, 2014, 03:42:25 pm »
Hi. This is excellent core hack and we´ve been using it for months. 5+ points to the creator!

It also doesn't work in 3.4.2... Can you please indicate OSC version you're using and also if you made any change to the code to make it work?

Thanks a lot in advance!

vinnie

  • Newbie
  • *
  • Posts: 22
Re: How to add RENEW / REFRESH / REPOST feature to OSCLASS
« Reply #61 on: October 21, 2014, 12:25:00 pm »
Hi,

 could someone update the code for the current version of osclass. Entering the current code returns a blank page (doesn't work with the current code). The code for ItemActions.php is the reason for the blank page.

tims

  • Guest
Re: How to add RENEW / REFRESH / REPOST feature to OSCLASS
« Reply #62 on: June 10, 2015, 10:04:10 am »
Yes. Can anyone update this tutorial? Thank you

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: How to add RENEW / REFRESH / REPOST feature to OSCLASS
« Reply #63 on: June 14, 2015, 07:53:03 pm »
I don't think the creator is still doing Osclass so best you can do is move on to the plugin from Cartenega.
Not sure if I spelled his name correct but you get the idea, a good plugin without the need for core changes.

Regards,
Eric

Syed

  • Sr. Member
  • ****
  • Posts: 254
Re: How to add RENEW / REFRESH / REPOST feature to OSCLASS
« Reply #64 on: July 12, 2016, 10:04:03 am »
Thanks for providing great piece of code,

I am trying to make a function so that when I call it providing item id it should renew item.
e.g.
Code: [Select]
renew(4); it should renew item having id 4

I think this should work but it is not working

Code: [Select]
    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;
        }
    }

any body please make it workable

Tim1970

  • Newbie
  • *
  • Posts: 19
Re: How to add RENEW / REFRESH / REPOST feature to OSCLASS
« Reply #65 on: February 23, 2017, 02:17:52 pm »
Hi Guys,

Here is how I did, and works fine:

Added the below to /oc-includes/osclass/classes/EmailVariables.php   "public function init()       {
            $this->variables = array(
"
Line 71 added
                 '{REPUBLISH_URL}' => __('Item republish url'),
just below
                '{ITEM_EXPIRATION_DATE}' => __('Item expiration date'),

Line 298 added to array   'email_warn_expiration' => array('
'{REPUBLISH_URL}',
just below
                    '{ITEM_EXPIRATION_DATE}',

/oc-includes/osclass/email.php

around line 1200 added to function:
    'function fn_email_warn_expiration($aItem) {'

        $republish_url    = osc_base_url() . 'item_republish.php?id=' . $aItem['pk_i_id'] . '&repub=republish&secret=' . $aItem['s_secret'] ;
        $republish_url    = '<a href="' . $republish_url . '" >' . $republish_url . '</a>';

right below

        $admin_email = osc_contact_email();

Around line 1218 changed these:

        $words[] = array(
            '{USER_NAME}',
            '{ITEM_TITLE}',
            '{ITEM_ID}',
            '{ITEM_EXPIRATION_DATE}',
'{REPUBLISH_URL}', //ADDED
            '{ITEM_URL}',
            '{ITEM_LINK}',
            '{SELLER_NAME}',
            '{SELLER_EMAIL}',
            '{CONTACT_NAME}',
            '{CONTACT_EMAIL}'
        );
        $words[] = array(
            $aItem['s_contact_name'],
            $aItem['s_title'],
            $itemId,
            $aItem['dt_expiration'],
$republish_url, //ADDED
            osc_item_url(),
            $itemURL,
            $aItem['s_contact_name'],
            $aItem['s_contact_email'],
            $aItem['s_contact_name'],
            $aItem['s_contact_email']
        );

Uploaded item republish php to my root (same folder as config.php)
Used/altered the code from advanced ad management pluguin.

<?php
      require_once 'oc-load.php';       
               $repub = Params::getParam('repub');   
                 if ($repub == 'republish') {   // repost item
                       $secret = (Params::getParam('secret'))? Params::getParam('secret') : '';
                       $id     = (Params::getParam('id'))? Params::getParam('id') : '';
                       $conn   = getConnection();
                       $item   = $conn->osc_dbFetchResult("SELECT * FROM %st_item WHERE pk_i_id = '%d' AND s_secret = '%s'", DB_TABLE_PREFIX, $id, $secret);
         $user_id = $item['fk_i_user_id'];
   if ($item['dt_expiration'] > date("Y-m-d h:i:s",strtotime("+2days"))) {
                                        osc_add_flash_error_message( __('You already renewed your item.','YOUR_THEME')) ;
                               header("Location: " . osc_base_url(true) . '?page=item&id=' . $id);

   } else {
           if ( $item['pk_i_id'] != 0 && $item['s_secret'] != ''){
            $date  = date("Y-m-d h:i:s",strtotime("+14days"));
            $conn->osc_dbExec("UPDATE %st_item SET dt_expiration = '%s' WHERE pk_i_id = '%d' ", DB_TABLE_PREFIX,$date,$id);
                                osc_add_flash_ok_message( __('Congratulations. Your ad as been republished!','YOUR_THEME') ) ;
                                header("Location: " . osc_base_url(true) . '?page=item&id=' . $id);
                                exit;
                                    } else {

                                        // add a flash message [ITEM NO EXISTE]
                                        osc_add_flash_error_message( __('Sorry, we do not have any items with that ID or the secret key is incorrect.','YOUR_THEME')) ;
                                        if(osc_is_web_user_logged_in()) {
                                           // REDIRECT
                                           header("Location: " . osc_user_list_items_url());                                        
                                        } else {
                                           // REDIRECT
                                            header("Location: " . osc_base_url(true));
                                        }
                                    }

         
          }
}       
?>

Works for me.

By this way, you have a new item {REPUBLISH_URL} in Email templates, warn_expiration_email that you can include into your email template.

Hope it helps.