Skip to content

Commit b815900

Browse files
author
Derek Jones
committed
initial commit
1 parent b3775c2 commit b815900

7 files changed

+321
-0
lines changed

.travis.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
language: php
2+
3+
php:
4+
- 5.4
5+
- 5.5
6+
- 5.6
7+
- 7.0
8+
9+
install:
10+
- composer install
11+
12+
script:
13+
- cookie/vendor/bin/parallel-lint --exclude cookie/vendor .
14+
15+
before_deploy:
16+
- composer install --no-dev
17+
- zip -r 'Cookie' cookie
18+
19+
deploy:
20+
provider: releases
21+
api_key:
22+
secure: KxOswvTMfejuugo1wVggRWFMcnFQLJN8ymV7NgORNuJEKxx5fd4VWFvHNGBeg1V5+KX1Jxf4SwbVmaJ3QXU4oS7ONi5+kFo65Izdmf4fbMEiA5eFyorBEzemfFukm7n6gLeWqIkoOJb9M8A3JjRzv4BpkEVhjkyT1HH2ky5yEfILOBFBmcndJVwp/Q6c9YPIo1fGssV07gag+69KsaW/oVGWvsXR95BOW9JxH1umAXv9Oc1WuiN4f+gj2wZ3EwK6hjSeNGYDgGCR+BaE+mgXef2c8NfZwgW7dCB9G69i6N/JJqMV6CFmSXgRT+KfnJLD1ayZ9+Wr8Qd69Ma37dSRFzKDraeQGAzJyAAELPCd5uU8tJMxv5H98Z2WB4uRsIiKnl9xBn1E4/z52wNI0Syv98qYpU6pkC+ftvjkNVjFkMxERHR8f08zBvf5R1dkKfo1ZsitcaHGCWl9Ky1OcUJMzU/gUmmV1sjxC7M2dDI4TtspfCHzPQdIsxbpB1Vy+MsAssgHhQueCRqwI3LpazUMtxUF9rwEcTIxrlN50UzF5V7PmZ5hpPgda5Dt9WEi1v7B6QEyIl/m6TVSBJpypMqWbPUs3/hq61Oj9uRJvc1fHQzBj26nwSiZ0jgdkWFIPoInusE4yL2sRkseOloTPbAh+Kj826VPsf56DYAYfaTzCmY=
23+
file: Cookie.zip
24+
on:
25+
php: 7.0
26+
tags: true
27+
repo: EllisLab/Cookie
28+
condition: $TRAVIS_PULL_REQUEST = false

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cookie/README.md

composer.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"require": {},
3+
"config": {
4+
"vendor-dir": "cookie/vendor"
5+
},
6+
"require-dev": {
7+
"jakub-onderka/php-parallel-lint": "^0.9.2"
8+
}
9+
}

composer.lock

+66
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cookie/README.md

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Cookie
2+
3+
This plugin lets you easily get and set cookies in your ExpressionEngine templates. It automatically respects your ExpressionEngine's cookie preferences so the prefix, domain, and flags are unified with the rest of the application cookies. Since the prefix is handled automatically, just refer to the cookie by its descriptive name, e.g. `example_cookie` instead of `exp_example_cookie`.
4+
5+
6+
## Requirements
7+
8+
- ExpressionEngine 3
9+
- PHP 5.4+
10+
11+
## Installation
12+
13+
1. Download the [latest release](https://github.com/EllisLab/Cookie/releases/latest).
14+
2. Copy the `cookie` folder to your `system/user/addons` folder (you can ignore the rest of this repository's files).
15+
3. In your ExpressionEngine control panel, visit the Add-On Manager and click Install next to "Cookie".
16+
17+
## Usage
18+
19+
### `{exp:cookie:delete}`
20+
21+
#### Example Usage
22+
23+
This is a single tag that deletes a cookie with the given name.
24+
25+
```
26+
{exp:cookie:delete name='ab_test'}
27+
```
28+
29+
#### Parameters
30+
31+
- `name=` (*required*) - The name of the cookie to delete.
32+
33+
### `{exp:cookie:get}`
34+
35+
#### Example Usage
36+
37+
This is a single tag that retreives and outputs the value of a cookie with the given name.
38+
39+
```
40+
{exp:cookie:get name='ab_test'}
41+
```
42+
43+
#### Parameters
44+
45+
- `name=` (*required*) - The name of the cookie to get.
46+
- `sanitize=` - (`yes`/`no`) Whether or not to perform XSS sanitization on the cookie value, default `yes`.
47+
- `htmlentities=` - (`yes`/`no`) Whether or not to convert all applicable characters to HTML entities, default `yes`. You should always leave this enabled when outputting cookie values to HTML tag attributes or ExpressionEngine tags. Since cookies are user input, it's best to be defensive, and this will also prevent HTML in cookie values from being rendered by the browser.
48+
49+
### `{exp:cookie:set}`
50+
51+
#### Example Usage
52+
53+
This is a single tag that stores a cookie with the given content and name.
54+
55+
```
56+
{exp:cookie:set name="recent_article" value="{entry_id}" expire="1209600"}
57+
```
58+
59+
#### Parameters
60+
61+
- `name=` (*required*) - The name of the cookie to set.
62+
- `value=` (*required*) - The content to store in the cookie.
63+
- `expire=` (*required*) - The time in seconds that the cookie should live.
64+
65+
## Change Log
66+
67+
### 1.0.0
68+
69+
- Initial release. Boom!
70+
71+
## Additional Files
72+
73+
You may be wondering what the rest of the files in this package are for. They are solely for development, so if you are forking the GitHub repo, they can be helpful. If you are just using the add-on in your ExpressionEngine installation, you can ignore all of these files.
74+
75+
- **.editorconfig**: [EditorConfig](http://editorconfig.org) helps developers maintain consistent coding styles across files and text editors.
76+
- **.gitignore:** [.gitignore](https://git-scm.com/docs/gitignore) lets you specify files in your working environment that you do not want under source control.
77+
- **.travis.yml:** A [Travis CI](https://travis-ci.org) configuration file for continuous integration (automated testing, releases, etc.).
78+
- **.composer.json:** A [Composer project setup file](https://getcomposer.org/doc/01-basic-usage.md) that manages development dependencies.
79+
- **.composer.lock:** A [list of dependency versions](https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file) that Composer has locked to this project.
80+
81+
## License
82+
83+
Copyright (C) 2016 EllisLab, Inc.
84+
85+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
86+
87+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
88+
89+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ELLISLAB, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
90+
91+
Except as contained in this notice, the name of EllisLab, Inc. shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from EllisLab, Inc.

cookie/addon.setup.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
return array(
4+
'author' => 'EllisLab',
5+
'author_url' => 'https://ellislab.com/',
6+
'name' => 'Cookie',
7+
'description' => 'Lets you easily get and set cookies in your ExpressionEngine templates.',
8+
'version' => '1.0.0',
9+
'namespace' => 'User\Addons\Cookie',
10+
'settings_exist' => FALSE
11+
);

cookie/pi.cookie.php

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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

Comments
 (0)