72 lines
1.7 KiB
PHP
72 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* 2024 Anvanto
|
|
*
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This source file is subject to the Academic Free License (AFL 3.0)
|
|
*
|
|
* @author Anvanto <anvantoco@gmail.com>
|
|
* @copyright 2024 Anvanto
|
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
|
*/
|
|
|
|
if (!defined('_PS_VERSION_')) {
|
|
exit;
|
|
}
|
|
|
|
include_once _PS_MODULE_DIR_.'anblog/loader.php';
|
|
|
|
class anbloglikesModuleFrontController extends ModuleFrontController
|
|
{
|
|
public function initContent()
|
|
{
|
|
$result = [];
|
|
if (Tools::isSubmit('action')) {
|
|
|
|
if (Tools::getValue('token') != Tools::getToken(false)){
|
|
Tools::redirect('index.php?controller=404');
|
|
}
|
|
|
|
$actionName = Tools::getValue('action', '') . 'Action';
|
|
if (method_exists($this, $actionName)) {
|
|
$result = $this->$actionName();
|
|
}
|
|
}
|
|
|
|
die(json_encode($result));
|
|
}
|
|
|
|
public function toggleLikeAction()
|
|
{
|
|
$return = [
|
|
'status' => '',
|
|
'countLikes' => '',
|
|
];
|
|
|
|
$idPost = (int) Tools::getValue('id_post');
|
|
|
|
if (Context::getContext()->customer->isLogged()) {
|
|
$idCustomerGuest = (int) Context::getContext()->customer->id;
|
|
} else {
|
|
$idCustomerGuest = $this->module->getIdGuest();
|
|
}
|
|
|
|
|
|
$idLike = anBlogLikes::getIdLike($idCustomerGuest, $idPost);
|
|
|
|
|
|
|
|
if (!$idLike) {
|
|
anBlogLikes::addLike($idCustomerGuest, $idPost);
|
|
$return['status'] = 1;
|
|
} else {
|
|
anBlogLikes::deleteLike($idLike, $idPost);
|
|
$return['status'] = 0;
|
|
}
|
|
|
|
$return['countLikes'] = anBlogLikes::getCountLikes($idPost);
|
|
|
|
$this->ajaxDie(json_encode($return));
|
|
}
|
|
} |