include(PATH.'/core/ajax/ajax_core.php'); if (!$inUser->id) { cmsCore::halt(); } $target = $inCore->request('target', 'str'); $item_id = $inCore->request('item_id', 'int'); $opt = $inCore->request('opt', 'str'); if(!$target || !$item_id || !$opt) { cmsCore::halt(); } if (!preg_match('/^([a-zA-Z0-9\_]+)$/iu', $target)) { cmsCore::halt(); } cmsCore::loadLib('karma'); if ($opt=='plus'){ cmsSubmitKarma($target, $item_id, 1); } if ($opt=='minus'){ cmsSubmitKarma($target, $item_id, -1); } $postkarma = cmsKarma($target, $item_id); $points = cmsKarmaFormat($postkarma['points']); echo $points; cmsCore::halt(); ?>
function cmsKarmaButtonsText($target, $target_id, $points = 0, $is_author = false){ $html = ''; if (!$points) { $postkarma = cmsKarma($target, $target_id); $points = cmsKarmaFormat($postkarma['points']); } else { $points = $points; } $control = ''; //PREPARE RATING FORM if (cmsCore::c('user')->id && !$is_author){ if(!cmsAlreadyKarmed($target, $target_id, cmsCore::c('user')->id)){ cmsCore::c('page')->addHeadJS('core/js/karma.js'); $control .= '<span>'; $control .= '<a href="javascript:void(0);" onclick="plusKarma(\''.$target.'\', '.$target_id.');" style="color:green">Нравится</a> ↑ '; $control .= '<a href="javascript:void(0);" onclick="minusKarma(\''.$target.'\', '.$target_id.');" style="color:red">Не нравится</a> ↓'; $control .= '</span>'; $html .= '<span class="karma_buttons">'; $html .= '<span id="karmactrl">'.$control.'</span>'; $html .= '</span>'; } } return $html; }
function cmsKarmaForm($target, $target_id, $points, $is_author = false) { $inUser = cmsUser::getInstance(); $inPage = cmsPage::getInstance(); global $_LANG; $postkarma = cmsKarma($target, $target_id); $points = cmsKarmaFormat($postkarma['points']); $control = ''; if ($inUser->id && !$is_author) { if (!cmsAlreadyKarmed($target, $target_id, $inUser->id)) { $inPage->addHeadJS('core/js/karma.js'); $control .= '<div class="ratings_control">'; $control .= '<a class="color_green color_transition" href="#" onclick="return plusKarma(\'' . $target . '\', \'' . $target_id . '\')" title="' . $_LANG['LIKE'] . '"><i class="fa fa-thumbs-up fa-lg"></i></a> '; $control .= '<a class="color_red color_transition" href="#" onclick="return minusKarma(\'' . $target . '\', \'' . $target_id . '\')" title="' . $_LANG['UNLIKE'] . '"><i class="fa fa-thumbs-down fa-lg"></i></a>'; $control .= '</div>'; } } return '<div class="karma_form">' . '<div id="karmapoints">' . $points . '</div>' . '<div id="karmavotes">' . $_LANG['RATING_VOTES_COUNT'] . ': ' . $postkarma['votes'] . '</div>' . '<div id="karmactrl">' . $control . '</div></div>'; }