public function run($profile_id) { if (!cmsUser::isLogged()) { cmsCore::error404(); } if (!$this->request->isAjax()) { cmsCore::error404(); } $user = cmsUser::getInstance(); $direction = $this->request->get('direction'); $comment = $this->request->get('comment'); // // Проверяем валидность // $is_valid = $user->is_logged && cmsUser::isAllowed('users', 'vote_karma') && is_numeric($profile_id) && $user->id != $profile_id && in_array($direction, array('up', 'down')) && (!$this->options['is_karma_comments'] || $comment); if (!$is_valid) { $result = array('error' => true, 'message' => LANG_ERROR); cmsTemplate::getInstance()->renderJSON($result); } $profile = $this->model->getUser($profile_id); if (!$profile || !$this->model->isUserCanVoteKarma($user->id, $profile_id, $this->options['karma_time'])) { $result = array('error' => true, 'message' => LANG_ERROR); cmsTemplate::getInstance()->renderJSON($result); } // // Сохраняем оценку // $vote = array('user_id' => $user->id, 'profile_id' => $profile_id, 'points' => $direction == 'up' ? 1 : -1, 'comment' => $comment); $vote_id = $this->model->addKarmaVote($vote); $value = $profile['karma'] + $vote['points']; $result = array('error' => $vote_id ? false : true, 'value' => html_signed_num($value), 'css_class' => html_signed_class($value)); cmsTemplate::getInstance()->renderJSON($result); }
function grid_comments_list($controller) { $options = array('is_sortable' => true, 'is_filter' => true, 'is_pagination' => true, 'is_draggable' => false, 'order_by' => 'date_pub', 'order_to' => 'desc', 'show_id' => true); $columns = array('id' => array('title' => 'id', 'width' => 30), 'date_pub' => array('title' => LANG_DATE, 'width' => 110, 'handler' => function ($value, $item) { return html_date($value, true); }, 'filter' => 'date'), 'target_id' => array('title' => LANG_COMMENTS_TEXT, 'handler' => function ($value, $row) use($controller) { return '<a title="' . LANG_COMMENTS_EDIT_TEXT . '" class="ajax-modal comment_text_edit" href="' . href_to($controller->root_url, 'text_edit', array($row['id'])) . '">' . string_short($row['content_html'], 350) . '</a>'; }), 'user_id' => array('title' => LANG_AUTHOR, 'width' => 180, 'handler' => function ($value, $row) { if ($row['user_id']) { $v = '<a target="_blank" href="' . href_to('users', $row['user_id']) . '">' . $row['user_nickname'] . '</a>'; } else { $v = '<span class="guest_name">' . $row['author_name'] . '</span>'; if (!empty($row['author_email'])) { $v .= '<span>, ' . $row['author_email'] . '</span>'; } } return $v; }), 'author_url' => array('title' => LANG_COMMENTS_IP, 'width' => 120, 'filter' => 'like', 'handler' => function ($value) { if ($value) { return '<a href="#" class="ajaxlink filter_ip tooltip" title="' . LANG_CP_USER_FIND_BYIP . '">' . $value . '</a> <a class="view_target tooltip" href="https://apps.db.ripe.net/search/query.html?searchtext=' . $value . '#resultsAnchor" target="_blank" title="' . LANG_CP_USER_RIPE_SEARCH . '"></a>'; } return ''; }), 'rating' => array('title' => LANG_RATING, 'width' => 50, 'handler' => function ($value, $row) { return '<span class="' . html_signed_class($value) . '">' . html_signed_num($value) . '</span>'; }, 'filter' => 'exact'), 'is_deleted' => array('title' => LANG_COMMENTS_IS_DELETED, 'flag' => 'flag_lock', 'flag_toggle' => href_to($controller->root_url, 'toggle_item', array('{id}', 'comments', 'is_deleted')), 'width' => 50, 'filter' => 'exact'), 'is_approved' => array('title' => LANG_MODERATION, 'flag' => true, 'width' => 50, 'filter' => 'exact', 'handler' => function ($value, $item) { if (!$item['is_approved']) { return '<div class="flag_trigger flag_off"><span><a class="approve_comment" title="' . LANG_COMMENTS_APPROVE . '" href="#" data-approve-url="' . href_to('comments', 'approve') . '?id=' . $item['id'] . '"></a></span></div>'; } return '<div class="flag_trigger flag_on"></div>'; }), 'is_private' => array('title' => LANG_COMMENTS_IS_PRIVATE, 'flag' => true, 'width' => 50, 'filter' => 'exact')); $actions = array(array('title' => LANG_COMMENTS_VIEW, 'class' => 'view tooltip', 'href' => href_to('{target_url}', '#comment_{id}')), array('title' => LANG_DELETE, 'class' => 'delete', 'href' => href_to($controller->root_url, 'comments_delete', array('{id}')), 'confirm' => LANG_COMMENTS_DELETE_CONFIRM)); return array('options' => $options, 'columns' => $columns, 'actions' => $actions); }
public function run() { if (!$this->request->isAjax()) { cmsCore::error404(); } // включено ли голосование от гостей? if (empty($this->options['allow_guest_vote']) && !$this->cms_user->is_logged) { return $this->cms_template->renderJSON(array('success' => false, 'message' => LANG_ERROR)); } // Получаем параметры $direction = $this->request->get('direction', ''); $target_controller = $this->request->get('controller', ''); $target_subject = $this->request->get('subject', ''); $target_id = $this->request->get('id', 0); $is_valid = $this->validate_sysname($target_controller) === true && $this->validate_sysname($target_subject) === true && is_numeric($target_id) && in_array($direction, array('up', 'down')); if (!$is_valid) { return $this->cms_template->renderJSON(array('success' => false, 'message' => LANG_ERROR)); } // Объединяем всю информацию о голосе $vote = array('user_id' => $this->cms_user->id ? $this->cms_user->id : null, 'target_controller' => $target_controller, 'target_subject' => $target_subject, 'target_id' => $target_id, 'score' => $direction == 'up' ? 1 : -1, 'ip' => sprintf('%u', ip2long(cmsUser::getIp()))); $cookie_key = $target_subject . $target_id . $target_controller; // Этот голос уже учитывался? $is_voted = $this->model->isUserVoted($vote, $this->cms_user->is_logged); if ($is_voted) { // если куки нет, ставим if (!empty($this->options['is_hidden']) && !cmsUser::getCookie($cookie_key)) { cmsUser::setCookie($cookie_key, 1, 2628000); // год } return $this->cms_template->renderJSON(array('success' => false, 'message' => LANG_RATING_VOTED)); } $target_model = cmsCore::getModel($target_controller); $target = $target_model->getRatingTarget($target_subject, $target_id); if (!empty($target['user_id'])) { if ($this->cms_user->is_logged) { if ($target['user_id'] == $this->cms_user->id || !cmsUser::isAllowed($target_subject, 'rate')) { return $this->cms_template->renderJSON(array('success' => false, 'message' => LANG_RATING_DISABLED)); } } } // Добавляем голос в лог $this->model->addVote($vote); // Обновляем суммарный рейтинг цели $rating = (int) $target['rating'] + $vote['score']; $target_model->updateRating($target_subject, $target_id, $rating); // Оповещаем всех об изменении рейтинга cmsEventsManager::hook('rating_vote', array('subject' => $target_subject, 'id' => $target_id, 'target' => $target, 'vote' => $vote, 'rating' => $rating)); // Собираем результат $result = array('success' => true, 'rating' => html_signed_num($rating), 'css_class' => html_signed_class($rating) . ($this->options['is_show'] ? ' clickable' : ''), 'message' => LANG_RATING_VOTED); // запоминаем в куках if (!empty($this->options['is_hidden'])) { cmsUser::setCookie($cookie_key, 1, 2628000); // год } return $this->cms_template->renderJSON($result); }
function grid_users($controller) { $options = array('is_auto_init' => false, 'is_sortable' => true, 'is_filter' => true, 'is_pagination' => true, 'is_draggable' => false, 'order_by' => 'id', 'order_to' => 'asc', 'show_id' => true); $columns = array('id' => array('title' => 'id', 'width' => 30, 'filter' => 'exact'), 'nickname' => array('title' => LANG_NICKNAME, 'href' => href_to($controller->name, 'users', array('edit', '{id}')), 'filter' => 'like'), 'email' => array('title' => LANG_EMAIL, 'filter' => 'like'), 'date_reg' => array('title' => LANG_REGISTRATION, 'width' => 100, 'filter' => 'like', 'handler' => function ($date) { return date('Y-m-d', strtotime($date)); }), 'karma' => array('title' => LANG_KARMA, 'width' => 60, 'filter' => 'exact', 'handler' => function ($value) { return '<span class="' . html_signed_class($value) . '">' . html_signed_num($value) . '</span>'; }), 'rating' => array('title' => LANG_RATING, 'width' => 60, 'filter' => 'exact'), 'is_locked' => array('title' => LANG_CP_USER_LOCKED, 'flag' => 'flag_lock', 'width' => 24)); $actions = array(array('title' => LANG_PROFILE, 'class' => 'view', 'href' => href_to('users', '{id}')), array('title' => LANG_EDIT, 'class' => 'edit', 'href' => href_to($controller->name, 'users', array('edit', '{id}'))), array('title' => LANG_DELETE, 'class' => 'delete', 'href' => href_to($controller->name, 'users', array('delete', '{id}')), 'confirm' => LANG_CP_USER_DELETE_CONFIRM)); return array('options' => $options, 'columns' => $columns, 'actions' => $actions); }
public function run() { if (!$this->request->isAjax()) { cmsCore::error404(); } // Получаем параметры $direction = $this->request->get('direction'); $target_controller = $this->request->get('controller'); $target_subject = $this->request->get('subject'); $target_id = $this->request->get('id'); $template = cmsTemplate::getInstance(); $is_valid = $this->validate_sysname($target_controller) === true && $this->validate_sysname($target_subject) === true && is_numeric($target_id) && in_array($direction, array('up', 'down')); if (!$is_valid) { $template->renderJSON(array('success' => false)); } $user = cmsUser::getInstance(); // Объединяем всю информацию о голосе $vote = array('user_id' => $user->id, 'target_controller' => $target_controller, 'target_subject' => $target_subject, 'target_id' => $target_id, 'score' => $direction == 'up' ? 1 : -1); // Этот голос уже учитывался? $is_voted = $this->model->isUserVoted($vote); if ($is_voted) { $template->renderJSON(array('success' => false)); } $target_model = cmsCore::getModel($target_controller); $target = $target_model->getRatingTarget($target_subject, $target_id); if (!empty($target['user_id'])) { if ($target['user_id'] == $user->id) { $template->renderJSON(array('success' => false)); } } // Добавляем голос в лог $this->model->addVote($vote); // Обновляем суммарный рейтинг цели $rating = (int) $target['rating'] + $vote['score']; $target_model->updateRating($target_subject, $target_id, $rating); // Оповещаем всех об изменении рейтинга cmsEventsManager::hook('rating_vote', array('subject' => $target_subject, 'id' => $target_id, 'target' => $target, 'vote' => $vote, 'rating' => $rating)); // Собираем результат $result = array('success' => true, 'rating' => html_signed_num($rating), 'css_class' => html_signed_class($rating) . ($this->options['is_show'] ? ' clickable' : ''), 'message' => LANG_RATING_VOTED); $template->renderJSON($result); }
function grid_users($controller) { $options = array('is_auto_init' => false, 'is_sortable' => true, 'is_filter' => true, 'is_pagination' => true, 'is_draggable' => false, 'order_by' => 'id', 'order_to' => 'asc', 'show_id' => true); $columns = array('id' => array('title' => 'id', 'width' => 30, 'filter' => 'exact'), 'nickname' => array('title' => LANG_NICKNAME, 'href' => href_to($controller->name, 'users', array('edit', '{id}')), 'filter' => 'like', 'handler' => function ($nickname, $user) { if ($user['is_admin']) { $nickname = '<b class="tooltip" title="' . LANG_USER_IS_ADMIN . '">' . $nickname . '</b>'; } return $nickname; }), 'email' => array('title' => LANG_EMAIL, 'width' => 200, 'filter' => 'like'), 'ip' => array('title' => LANG_USERS_PROFILE_LAST_IP, 'width' => 120, 'filter' => 'like', 'handler' => function ($value) { return '<a href="#" class="ajaxlink filter_ip tooltip" title="' . LANG_CP_USER_FIND_BYIP . '">' . $value . '</a> <a class="view_target tooltip" href="https://apps.db.ripe.net/search/query.html?searchtext=' . $value . '#resultsAnchor" target="_blank" title="' . LANG_CP_USER_RIPE_SEARCH . '"></a>'; }), 'date_reg' => array('title' => LANG_REGISTRATION, 'width' => 80, 'filter' => 'like', 'handler' => function ($date, $user) { $ld = $user['is_online'] ? LANG_ONLINE : LANG_USERS_PROFILE_LOGDATE . ' ' . string_date_age_max($user['date_log'], true); return '<span class="tooltip" title="' . $ld . '">' . html_date($date) . '</span>'; }), 'karma' => array('title' => LANG_KARMA, 'width' => 60, 'filter' => 'exact', 'handler' => function ($value) { return '<span class="' . html_signed_class($value) . '">' . html_signed_num($value) . '</span>'; }), 'rating' => array('title' => LANG_RATING, 'width' => 60, 'filter' => 'exact'), 'is_locked' => array('title' => LANG_CP_USER_LOCKED, 'flag' => 'flag_lock', 'width' => 24, 'handler' => function ($value, $user) { $title = $user['is_locked'] ? $user['lock_reason'] ? $user['lock_reason'] : LANG_TO . ' ' . strip_tags(html_date($user['lock_until'])) : ''; return '<div class="tooltip" title="' . $title . '">' . $value . '</div>'; })); $actions = array(array('title' => LANG_PROFILE, 'class' => 'view tooltip', 'href' => href_to('users', '{id}')), array('title' => LANG_EDIT, 'class' => 'edit tooltip', 'href' => href_to($controller->name, 'users', array('edit', '{id}'))), array('title' => LANG_DELETE, 'class' => 'delete tooltip', 'href' => href_to($controller->name, 'users', array('delete', '{id}')), 'confirm' => LANG_CP_USER_DELETE_CONFIRM)); return array('options' => $options, 'columns' => $columns, 'actions' => $actions); }
if ($options['is_hidden'] && !$is_voted && ($is_enabled || $is_guest)) { ?> <span>—</span> <?php } else { ?> <span class="<?php echo html_signed_class($current_rating); if ($options['is_show']) { ?> clickable<?php } ?> "> <?php echo html_signed_num($current_rating); ?> </span> <?php } ?> </div> <div class="arrow down"> <?php if ($is_enabled) { ?> <a href="#vote-down" class="vote-down" title="<?php echo LANG_RATING_VOTE_DOWN; ?> "></a>
echo LANG_DELETE; ?> " data-id="<?php echo $photo['id']; ?> "></a> </div> <?php } ?> <div class="rating <?php echo html_signed_class($photo['rating']); ?> "> <?php echo html_signed_num($photo['rating']); ?> </div> <div class="comments"> <span><?php echo $photo['comments']; ?> </span> </div> </div> </div> <?php } ?> <?php
<a href="#vote-up" onclick="return icms.users.karmaUp()" class="thumb thumb_up" title="<?php echo LANG_KARMA_UP; ?> "></a> <?php } ?> <span class="value <?php echo html_signed_class($profile['karma']); ?> " title="<?php echo LANG_KARMA; ?> "> <?php echo html_signed_num($profile['karma']); ?> </span> <?php if ($profile['is_can_vote_karma']) { ?> <a href="#vote-down" onclick="return icms.users.karmaDown()" class="thumb thumb_down" title="<?php echo LANG_KARMA_DOWN; ?> "></a> <?php } ?> </div> <?php if ($this->controller->options['is_karma_comments']) {
<div class="item"> <div class="icon"> <?php echo html_avatar_image($entry['user']['avatar'], 'micro', $entry['user']['nickname']); ?> </div> <div class="value <?php echo html_signed_class($entry['points']); ?> "> <span> <?php echo html_signed_num($entry['points']); ?> </span> </div> <div class="title<?php if ($entry['comment']) { ?> -multiline<?php } ?> "> <a href="<?php echo $this->href_to($entry['user']['id']); ?>
} ?> <a href="#down" class="scroll-down" onclick="return icms.comments.down(this)" title="<?php echo html(LANG_COMMENT_SHOW_CHILD); ?> ">↓</a> </div> <div class="rating <?php echo $no_approved_class; ?> "> <span class="value <?php echo html_signed_class($entry['rating']); ?> "><?php echo $entry['rating'] ? html_signed_num($entry['rating']) : ''; ?> </span> <?php if ($is_can_rate && $entry['user_id'] != $user->id && !$entry['is_rated']) { ?> <div class="buttons"> <a href="#rate-up" class="rate-up" title="<?php echo html(LANG_COMMENT_RATE_UP); ?> " data-id="<?php echo $entry['id']; ?> "></a> <a href="#rate-down" class="rate-down" title="<?php echo html(LANG_COMMENT_RATE_DOWN);
<?php } else { ?> <span><?php html($vote['user']['nickname']); ?> </span> <?php } ?> <?php if ($user->is_admin) { ?> <span> [<?php html($vote['ip']); ?> ]</span> <?php } ?> <span class="score <?php echo html_signed_class($vote['score']); ?> "><?php echo html_signed_num($vote['score']); ?> </span> </div> <?php }