\n"; exit(1); } $outpath = $argv[1]; mkdir($outpath); mkdir("${outpath}/data/"); $db = new PDO("mysql:host=localhost;dbname=ponepaste_beta;charset=utf8mb4", PP_USER, PP_PASS, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_NUM, PDO::ATTR_EMULATE_PREPARES => false ]); $outfile = fopen("${outpath}/pastes.csv", 'w'); $resp = $db->query("SELECT pastes.id, title, pastes.encrypt, pastes.content, pastes.created_at, pastes.updated_at, users.username FROM pastes INNER JOIN users ON users.id = pastes.user_id WHERE pastes.visible = '0'"); while ($row = $resp->fetch()) { list($paste_id, $paste_title, $paste_is_encrypted, $paste_content, $paste_created_at, $paste_updated_at, $paste_author) = $row; if ($paste_is_encrypted == '1') { $paste_content = openssl_decrypt($paste_content, 'AES-256-CBC', PP_ENCRYPTION_KEY); } else { $paste_content = base64_decode($paste_content); } $encoding = mb_detect_encoding($paste_content); if (!$encoding) { $encoding = 'UTF-8'; } $paste_content = mb_convert_encoding($paste_content, 'UTF-8', $encoding); $paste_content = html_entity_decode($paste_content); $paste_content = str_replace("\r\n", "\n", $paste_content); fputcsv($outfile, [$paste_id, $paste_title, $paste_created_at, $paste_updated_at, $paste_author]); $pastefile = fopen("${outpath}/data/${paste_id}", 'w'); fwrite($pastefile, $paste_content); fclose($pastefile); } fclose($outfile);