|
| 1 | +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | + |
| 3 | +/* |
| 4 | +Copyright (C) 2016 EllisLab, Inc. |
| 5 | +
|
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +of this software and associated documentation files (the "Software"), to deal |
| 8 | +in the Software without restriction, including without limitation the rights |
| 9 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +copies of the Software, and to permit persons to whom the Software is |
| 11 | +furnished to do so, subject to the following conditions: |
| 12 | +
|
| 13 | +The above copyright notice and this permission notice shall be included in |
| 14 | +all copies or substantial portions of the Software. |
| 15 | +
|
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | +ELLISLAB, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | +
|
| 23 | +Except as contained in this notice, the name of EllisLab, Inc. shall not be |
| 24 | +used in advertising or otherwise to promote the sale, use or other dealings |
| 25 | +in this Software without prior written authorization from EllisLab, Inc. |
| 26 | +*/ |
| 27 | + |
| 28 | +/** |
| 29 | + * EllisLab Cookie plugin |
| 30 | + * |
| 31 | + * @package ExpressionEngine |
| 32 | + * @subpackage Addons |
| 33 | + * @category Plugin |
| 34 | + * @author EllisLab |
| 35 | + * @copyright Copyright (c) 2016, EllisLab, Inc. |
| 36 | + * @link https://github.com/EllisLab/Cookie |
| 37 | + */ |
| 38 | +class Cookie { |
| 39 | + |
| 40 | + /* |
| 41 | + * @var string The plugin return data, not used since this plugin requires a method |
| 42 | + */ |
| 43 | + public $return_data; |
| 44 | + |
| 45 | + /** |
| 46 | + * Constructor |
| 47 | + * |
| 48 | + * @access public |
| 49 | + * @return void |
| 50 | + */ |
| 51 | + public function __construct() |
| 52 | + { |
| 53 | + |
| 54 | + } |
| 55 | + |
| 56 | + // ---------------------------------------------------------------------- |
| 57 | + |
| 58 | + /** |
| 59 | + * Set Cookie value |
| 60 | + * |
| 61 | + * @access public |
| 62 | + * @return void |
| 63 | + */ |
| 64 | + public function set() |
| 65 | + { |
| 66 | + $name = ee()->TMPL->fetch_param('name'); |
| 67 | + $value = ee()->TMPL->fetch_param('value'); |
| 68 | + $expire = ee()->TMPL->fetch_param('expire'); |
| 69 | + |
| 70 | + ee()->input->set_cookie($name, $value, $expire); |
| 71 | + } |
| 72 | + |
| 73 | + // ---------------------------------------------------------------------- |
| 74 | + |
| 75 | + /** |
| 76 | + * Get Cookie value |
| 77 | + * |
| 78 | + * Runs XSS Clean by default, since this value is being output to a template |
| 79 | + * |
| 80 | + * @access public |
| 81 | + * @return string |
| 82 | + */ |
| 83 | + public function get() |
| 84 | + { |
| 85 | + $name = ee()->TMPL->fetch_param('name'); |
| 86 | + $sanitize = (ee()->TMPL->fetch_param('sanitize') == 'no') ? FALSE : TRUE; |
| 87 | + |
| 88 | + $cookie = ee()->input->cookie($name, $sanitize); |
| 89 | + |
| 90 | + if (ee()->TMPL->fetch_param('htmlentities') !== 'no') |
| 91 | + { |
| 92 | + $cookie = htmlentities($cookie, ENT_QUOTES, 'UTF-8'); |
| 93 | + } |
| 94 | + |
| 95 | + return $cookie; |
| 96 | + } |
| 97 | + |
| 98 | + // ---------------------------------------------------------------------- |
| 99 | + |
| 100 | + /** |
| 101 | + * Delete Cookie |
| 102 | + * |
| 103 | + * @access public |
| 104 | + * @return void |
| 105 | + */ |
| 106 | + public function delete() |
| 107 | + { |
| 108 | + $name = ee()->TMPL->fetch_param('name'); |
| 109 | + |
| 110 | + ee()->input->delete_cookie($name); |
| 111 | + } |
| 112 | +} |
| 113 | +// END CLASS |
| 114 | + |
| 115 | +// EOF |
0 commit comments