public function addView()
{
# Check if view exists
if ($this->limit_views_per_ip) {
$views = Laralum::postViews('post_id', $this->id);
foreach ($views as $view) {
if ($view->ip == Laralum::getIP()) {
return false;
}
}
}
$view = Laralum::newPostView();
$view->post_id = $this->id;
$view->ip = Laralum::getIP();
$view->url = Laralum::currentURL();
$view->ref = Laralum::previousURL();
if ($this->blog->views_location) {
try {
$view->country_code = Location::get($view->ip)->countryCode;
#it takes some time to check the api...
} catch (Exception $e) {
$view->country_code = "FF";
#FF will be translated into nothing later
}
} else {
$view->country_code = "FF";
#FF will be translated into nothing later
}
$view->save();
return true;
}