本文整理汇总了PHP中cmsUser::setCookie方法的典型用法代码示例。如果您正苦于以下问题:PHP cmsUser::setCookie方法的具体用法?PHP cmsUser::setCookie怎么用?PHP cmsUser::setCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cmsUser
的用法示例。
在下文中一共展示了cmsUser::setCookie方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
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);
}
示例2: loadDeviceType
private static function loadDeviceType()
{
$device_type = (string) cmsUser::getCookie('device_type');
if (!$device_type || !in_array($device_type, self::$device_types, true)) {
cmsCore::loadLib('mobile_detect.class');
$detect = new Mobile_Detect();
$device_type = $detect->isMobile() ? $detect->isTablet() ? 'tablet' : 'mobile' : 'desktop';
cmsUser::setCookie('device_type', $device_type, 31536000);
// на 1 год
}
self::$device_type = $device_type;
}
示例3: incrementCounter
public function incrementCounter($id, $field = 'hits_count')
{
if (cmsUser::hasCookie($field . $id)) {
return false;
}
$this->filterEqual('id', $id)->increment('photos', $field);
cmsUser::setCookie($field . $id, 1, 2592000);
return true;
}