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 @@