当前位置: 首页>>代码示例>>PHP>>正文


PHP cmsUser::setCookie方法代码示例

本文整理汇总了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);
 }
开发者ID:Val-Git,项目名称:icms2,代码行数:56,代码来源:vote.php

示例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;
 }
开发者ID:Val-Git,项目名称:icms2,代码行数:12,代码来源:request.php

示例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;
 }
开发者ID:Val-Git,项目名称:icms2,代码行数:9,代码来源:model.php


注:本文中的cmsUser::setCookie方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。