function pm_export_messages($message_array, ZipArchive $zip, $options_array = array()) { if (!is_array($message_array)) { return false; } if (sizeof($message_array) < 1) { return false; } if (!isset($_SESSION['LOGON']) || strlen(trim($_SESSION['LOGON'])) == 0) { return false; } if (!is_array($options_array)) { $options_array = array(); } if (!isset($options_array['PM_EXPORT_TYPE'])) { if (isset($_SESSION['PM_EXPORT_TYPE']) && in_array($_SESSION['PM_EXPORT_TYPE'], array(PM_EXPORT_HTML, PM_EXPORT_XML))) { $options_array['PM_EXPORT_TYPE'] = $_SESSION['PM_EXPORT_TYPE']; } else { $options_array['PM_EXPORT_TYPE'] = PM_EXPORT_HTML; } } if (!isset($options_array['PM_EXPORT_ATTACHMENTS'])) { if (isset($_SESSION['PM_EXPORT_ATTACHMENTS']) && in_array($_SESSION['PM_EXPORT_ATTACHMENTS'], array('Y', 'N'))) { $options_array['PM_EXPORT_ATTACHMENTS'] = $_SESSION['PM_EXPORT_ATTACHMENTS']; } else { $options_array['PM_EXPORT_ATTACHMENTS'] = 'Y'; } } switch ($options_array['PM_EXPORT_TYPE']) { case PM_EXPORT_HTML: if (!pm_export_html($message_array, $zip, $options_array)) { return false; } break; case PM_EXPORT_XML: if (!pm_export_xml($message_array, $zip, $options_array)) { return false; } break; } if ($options_array['PM_EXPORT_ATTACHMENTS'] == "Y") { pm_export_attachments($message_array, $zip); } return true; }
function pm_export_csv($messages_array, &$zip_file, $options_array = array()) { if (!is_array($messages_array)) { return false; } if (!is_object($zip_file)) { return false; } if (!is_array($options_array)) { $options_array = array(); } if (!isset($options_array['PM_EXPORT_FILE'])) { $options_array['PM_EXPORT_FILE'] = session::get_value('PM_EXPORT_FILE'); } if (!isset($options_array['PM_EXPORT_ATTACHMENTS'])) { $options_array['PM_EXPORT_ATTACHMENTS'] = session::get_value('PM_EXPORT_ATTACHMENTS'); } if (!isset($options_array['PM_EXPORT_WORDFILTER'])) { $options_array['PM_EXPORT_WORDFILTER'] = session::get_value('PM_EXPORT_WORDFILTER'); } if (sizeof($messages_array) == 0) { return false; } $pm_csv_export = fopen('php://temp', 'w'); $pm_csv_header = array('MID', 'TYPE', 'FROM_UID', 'TO_UID', 'SUBJECT', 'RECIPIENTS', 'CREATED', 'FLOGON', 'TLOGON', 'FNICK', 'TNICK', 'FOLDER', 'CONTENT'); if (!fputcsv($pm_csv_export, $pm_csv_header)) { return false; } foreach ($messages_array as $mid) { if (!($message = pm_message_get($mid))) { return false; } if (isset($message['AID']) && $options_array['PM_EXPORT_ATTACHMENTS'] == 'Y') { pm_export_attachments($message['AID'], $message['FROM_UID'], $zip_file); } $message['FOLDER'] = pm_message_get_folder($message['MID']); $message['CONTENT'] = preg_replace("[\r\n|\r|\n]", '\\n', pm_get_content($message['MID'])); $message['CREATED'] = date('Y-m-d H:i:s', $message['CREATED']); if ($options_array['PM_EXPORT_WORDFILTER'] == 'Y') { $message = array_map('pm_export_word_filter_apply', $message); } unset($message['AID']); if (!fputcsv($pm_csv_export, $message)) { return false; } if ($options_array['PM_EXPORT_FILE'] == PM_EXPORT_MANY) { rewind($pm_csv_export); $pm_csv_contents = ''; while (!feof($pm_csv_export)) { $pm_csv_contents .= fgets($pm_csv_export); } $zip_file->add_file($pm_csv_contents, sprintf("message_%s.csv", $message['MID'])); fclose($pm_csv_export); $pm_csv_export = fopen('php://temp', 'r+'); if (!fputcsv($pm_csv_export, $pm_csv_header)) { return false; } } } if ($options_array['PM_EXPORT_FILE'] == PM_EXPORT_SINGLE) { rewind($pm_csv_export); $pm_csv_contents = ''; while (!feof($pm_csv_export)) { $pm_csv_contents .= fgets($pm_csv_export); } $zip_file->add_file($pm_csv_contents, 'messages.csv'); } fclose($pm_csv_export); return true; }