From 3133a4dd2446cfb7fe986e180dab0cd60e98ec57 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Sun, 7 Jul 2024 15:01:30 +0200 Subject: [PATCH] add get mp cookie refactor form --- epub.php | 65 ++++++++++++++++++++++++++++++++++++--------- settings.php.sample | 4 ++- 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/epub.php b/epub.php index 76396f5..d16984f 100644 --- a/epub.php +++ b/epub.php @@ -17,6 +17,37 @@ require 'settings.php'; require 'TPEpubCreator.php'; + function get_mp_cookie() + { + global $mp_user; + global $mp_password; + + $url = 'https://www.mediapart.fr/login_check'; + $postfields = 'email=' . $mp_user . '&password=' . $mp_password . '&submitButton=&_target_path=https%3A%2F%2Fwww.mediapart.fr%2F'; + + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_AUTOREFERER, false); + + curl_setopt($ch, CURLOPT_HEADER, 1); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); + + $result = curl_exec($ch); + $sessid = ''; + + preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $result, $matches); + foreach($matches[1] as $item) + { + if (str_starts_with($item, 'MPSESSID=')) + { + $sessid = str_replace('MPSESSID=', '', $item); + } + } + return $sessid; + } + function write_epub($epub) { if (file_exists($epub->epub_file)) @@ -180,6 +211,12 @@ // Mediapart if (isset($_POST['mediapart']) && $_POST['mediapart']) { + if (isset($_POST['forcempcookies']) && $_POST['forcempcookies']) + { + $mp_sessionid = get_mp_cookie(); + // todo save in settings + } + $feedurl = 'https://www.mediapart.fr/articles/feed'; $opts = [ 'http' => [ @@ -422,31 +459,33 @@

Generate epub

- - Parameters: + Le Monde
- GetPublicationContentItems url:
+ + +

- Newspapers: + Mediapart
- - -
- - +
+ + +

+ + The New York Times +
- +
- - -
+ +

diff --git a/settings.php.sample b/settings.php.sample index 0908a6b..59f18c5 100644 --- a/settings.php.sample +++ b/settings.php.sample @@ -1,4 +1,6 @@ \ No newline at end of file