Skip to content

Commit cd49841

Browse files
committed
Version 2.1
2 parents b960160 + d4c9486 commit cd49841

6 files changed

Lines changed: 88 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# (MODX)EvolutionCMS.snippets.ddMakeHttpRequest changelog
22

33

4+
## Version 2.1 (2020-02-15)
5+
* \+ Cookie can be used (see the `useCookie` parameter).
6+
7+
48
## Version 2.0 (2019-09-23)
59
* \* **Attention!** Backward compatibility is broken. If you want send raw JSON in `postData` you must set `sendRawPostData` equal to `1`.
610
* \+ `postData` can be set as a JSON object.

CHANGELOG_ru.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# (MODX)EvolutionCMS.snippets.ddMakeHttpRequest changelog
22

33

4+
## Version 2.1 (2020-02-15)
5+
* \+ Добавлена возможность использовать cookie (см. параметр `useCookie`).
6+
7+
48
## Version 2.0 (2019-09-23)
59
* \* **Внимание!** Обратная совместимость нарушена. Если вы хотите отправить сырой JSON в `postData`, выставьте параметр `sendRawPostData` в `1`.
610
* \+ Параметр `postData` может быть задан, как JSON-объект.

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Makes HTTP request to a given URL.
1515
Elements → Snippets: Create a new snippet with the following data:
1616

1717
1. Snippet name: `ddMakeHttpRequest`.
18-
2. Description: `<b>2.0</b> Makes HTTP request to a given URL.`.
18+
2. Description: `<b>2.1</b> Makes HTTP request to a given URL.`.
1919
3. Category: `Core`.
2020
4. Parse DocBlock: `no`.
2121
5. Snippet code (php): Insert content of the `ddMakeHttpRequest_snippet` file from the archive.
@@ -73,6 +73,13 @@ Elements → Snippets: Create a new snippet with the following data:
7373
* Desctription: Proxy server in format `[+protocol+]://[+user+]:[+password+]@[+ip+]:[+port+]`. E. g. `http://asan:gd324ukl@11.22.33.44:5555` or `socks5://asan:gd324ukl@11.22.33.44:5555`.
7474
* Valid values: `string`
7575
* Default value: —
76+
77+
* `useCookie`
78+
* Desctription: Enagle cookies. The `assets/cache/ddMakeHttpRequest_cookie.txt` file is used.
79+
* Valid values:
80+
* `0`
81+
* `1`
82+
* Default value: `0`
7683

7784

7885
### ## Examples

README_ru.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
Элементы → Сниппеты: Создать новый сниппет со следующими параметрами:
1616

1717
1. Название сниппета: `ddMakeHttpRequest`.
18-
2. Описание: `<b>2.0</b> Makes HTTP request to a given URL.`.
18+
2. Описание: `<b>2.1</b> Makes HTTP request to a given URL.`.
1919
3. Категория: `Core`.
2020
4. Анализировать DocBlock: `no`.
2121
5. Код сниппета (php): Вставьте содержимое файла `ddMakeHttpRequest_snippet` из архива.
@@ -73,6 +73,13 @@
7373
* Описание: Прокси сервер в формате `[+protocol+]://[+user+]:[+password+]@[+ip+]:[+port+]`. Пример: `http://asan:gd324ukl@11.22.33.44:5555`, `socks5://asan:gd324ukl@11.22.33.44:5555`.
7474
* Допустимые значения: `string`
7575
* Значение по умолчанию: —
76+
77+
* `useCookie`
78+
* Desctription: Использовать cookie? Используется файл `assets/cache/ddMakeHttpRequest_cookie.txt`.
79+
* Valid values:
80+
* `0`
81+
* `1`
82+
* Default value: `0`
7683

7784

7885
### ## Примеры

composer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "dd/evolutioncms-snippets-ddmakehttprequest",
3+
"type": "modxevo-snippet",
4+
"version": "2.1.0",
5+
"description": "Makes HTTP request to a given URL.",
6+
"keywords": [
7+
"modx",
8+
"modx evo",
9+
"modx evolution",
10+
"evo",
11+
"evo cms",
12+
"evolutioncms",
13+
"evolution cms",
14+
"ddmakehttprequest",
15+
"makehttprequest",
16+
"httprequest",
17+
"curl"
18+
],
19+
"require": {
20+
"php": ">=5.4.0",
21+
"dd/modxevo-library-ddtools": ">=0.23.0"
22+
}
23+
}

ddMakeHttpRequest_snippet.php

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
<?php
22
/**
33
* ddMakeHttpRequest
4-
* @version 2.0 (2019-09-23)
4+
* @version 2.1 (2020-02-15)
55
*
66
* @see README.md
77
*
88
* @link https://code.divandesign.biz/modx/ddmakehttprequest
99
*
10-
* @copyright 2011–2019 DivanDesign {@link http://www.DivanDesign.biz }
10+
* @copyright 2011–2020 DivanDesign {@link http://www.DivanDesign.biz }
1111
*/
1212

1313
//Include (MODX)EvolutionCMS.libraries.ddTools
14-
require_once($modx->getConfig('base_path') . 'assets/libs/ddTools/modx.ddtools.class.php');
14+
require_once(
15+
$modx->getConfig('base_path') .
16+
'assets/libs/ddTools/modx.ddtools.class.php'
17+
);
1518

1619
//The snippet must return an empty string even if result is absent
1720
$snippetResult = '';
1821

1922
//Для обратной совместимости
20-
extract(ddTools::verifyRenamedParams(
23+
extract(\ddTools::verifyRenamedParams(
2124
$params,
2225
[
2326
'method' => 'metod',
2427
'userAgent' => 'uagent',
25-
'postData' => 'post'
28+
'postData' => 'post',
29+
'useCookie' => 'cookie'
2630
]
2731
));
2832

@@ -43,7 +47,7 @@
4347
isset($headers) &&
4448
!is_array($headers)
4549
){
46-
$headers = ddTools::encodedStringToArray($headers);
50+
$headers = \ddTools::encodedStringToArray($headers);
4751
}
4852

4953
$timeout =
@@ -169,7 +173,7 @@
169173
//И обрабатывать её можно
170174
!$sendRawPostData
171175
){
172-
$postData = ddTools::encodedStringToArray($postData);
176+
$postData = \ddTools::encodedStringToArray($postData);
173177
}
174178

175179
//Если он массив — делаем query string
@@ -178,9 +182,14 @@
178182
//Сформируем массив для отправки, предварительно перекодировав
179183
foreach (
180184
$postData as
181-
$key => $value
185+
$key =>
186+
$value
182187
){
183-
$postData_mas[] = $key . '=' . urlencode($value);
188+
$postData_mas[] =
189+
$key .
190+
'=' .
191+
urlencode($value)
192+
;
184193
}
185194
$postData = implode(
186195
'&',
@@ -213,6 +222,29 @@
213222
);
214223
}
215224

225+
//Если задано использование печенек
226+
if (
227+
isset($useCookie) &&
228+
$useCookie == '1'
229+
){
230+
curl_setopt(
231+
$ch,
232+
CURLOPT_COOKIEFILE,
233+
(
234+
$modx->getConfig('base_path') .
235+
'assets/cache/ddMakeHttpRequest_cookie.txt'
236+
)
237+
);
238+
curl_setopt(
239+
$ch,
240+
CURLOPT_COOKIEJAR,
241+
(
242+
$modx->getConfig('base_path') .
243+
'assets/cache/ddMakeHttpRequest_cookie.txt'
244+
)
245+
);
246+
}
247+
216248
//Если задан прокси-сервер
217249
if(!empty($proxy)){
218250
curl_setopt(

0 commit comments

Comments
 (0)