At ItemAction:
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
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)
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
$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 :
osc_item_renew_url( $item['s_secret'], $item['pk_i_id']);