49 lines
1.6 KiB
PHP
49 lines
1.6 KiB
PHP
<?php
|
|
|
|
class UrlRedirect extends ObjectModel
|
|
{
|
|
|
|
public $id_x13linkrewrite;
|
|
public $active = true;
|
|
public $redirect_type = 301;
|
|
public $old_url;
|
|
public $new_url;
|
|
public $redirect_count;
|
|
public $date_add;
|
|
public $date_upd;
|
|
|
|
public static $definition = array(
|
|
'table' => 'x13linkrewrite',
|
|
'primary' => 'id_x13linkrewrite',
|
|
'multilang' => false,
|
|
'multilang_shop' => false,
|
|
'fields' => array(
|
|
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
|
'redirect_type' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
|
'redirect_count' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
|
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat'),
|
|
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat'),
|
|
'old_url' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'size' => 255),
|
|
'new_url' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'size' => 255),
|
|
)
|
|
);
|
|
|
|
public static function existURL($url, $type = 'old_url', $active = true)
|
|
{
|
|
return (int)Db::getInstance()->getValue('SELECT id_x13linkrewrite FROM '._DB_PREFIX_.'x13linkrewrite WHERE '.($active ? 'active = 1 AND' : '').' old_url = \''.pSQL($url).'\'');
|
|
}
|
|
|
|
public static function getRedirects()
|
|
{
|
|
return Db::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'x13linkrewrite ORDER BY date_add DESC');
|
|
}
|
|
|
|
public function increment()
|
|
{
|
|
$data = array(
|
|
'redirect_count' => $this->redirect_count + 1
|
|
);
|
|
|
|
return Db::getInstance()->update('x13linkrewrite', $data, 'id_x13linkrewrite = '.(int)$this->id);
|
|
}
|
|
} |