protected function generateItem($item) { $name = !empty($item['name_value_list']['name']['value']) ? htmlentities($item['name_value_list']['name']['value']) : ''; $url = $GLOBALS['sugar_config']['site_url'] . htmlentities('/index.php?module=' . $item['module_name'] . '&action=DetailView&record=' . $item['id']); $date = TimeDate::httpTime(TimeDate::getInstance()->fromDb($item['name_value_list']['date_modified']['value'])->getTimestamp()); $description = ''; $displayFieldNames = true; if (count($item['name_value_list']) == 2 && isset($item['name_value_list']['name'])) { $displayFieldNames = false; } foreach ($item['name_value_list'] as $k => $v) { if ($k == 'name' || $k == 'date_modified') { continue; } if ($displayFieldNames) { $description .= '<b>' . htmlentities($k) . ':<b> '; } $description .= htmlentities($v['value']) . "<br>"; } echo <<<EORSS <item> <title>{$name}</title> <link>{$url}</link> <description><![CDATA[{$description}]]></description> <pubDate>{$date} GMT</pubDate> <guid>{$item['id']}</guid> </item> EORSS; }
/** * Utility method to allow for subclasses to do the same export calls * * @param ServiceBase $api * @param string $filename The File name for the export * @param string $content What should be in the exported file * @return mixed */ protected function doExport(ServiceBase $api, $filename, $content) { $api->setHeader("Pragma", "cache"); $api->setHeader("Content-Type", "application/octet-stream; charset=" . $GLOBALS['locale']->getExportCharset()); $api->setHeader("Content-Disposition", "attachment; filename={$filename}.csv"); $api->setHeader("Content-transfer-encoding", "binary"); $api->setHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); $api->setHeader("Last-Modified", TimeDate::httpTime()); $api->setHeader("Cache-Control", "post-check=0, pre-check=0"); return $GLOBALS['locale']->translateCharset($content, 'UTF-8', $GLOBALS['locale']->getExportCharset()); }
function template_handle_export(&$reporter) { ini_set('zlib.output_compression', 'Off'); $reporter->plain_text_output = true; //disable paging so we get all results in one pass $reporter->enable_paging = false; $reporter->run_query(); $reporter->_load_currency(); $header_arr = array(); $header_row = $reporter->get_header_row(); $content = ''; foreach ($header_row as $cell) { array_push($header_arr, $cell); } $header = implode("\"" . getDelimiter() . "\"", array_values($header_arr)); $header = "\"" . $header; $header .= "\"\r\n"; $content .= $header; while (($row = $reporter->get_next_row('result', 'display_columns', false, true)) != 0) { $new_arr = array(); for ($i = 0; $i < count($row['cells']); $i++) { array_push($new_arr, preg_replace("/\"/", "\"\"", from_html($row['cells'][$i]))); } $line = implode("\"" . getDelimiter() . "\"", $new_arr); $line = "\"" . $line; $line .= "\"\r\n"; $content .= $line; } global $locale; $transContent = $GLOBALS['locale']->translateCharset($content, 'UTF-8', $GLOBALS['locale']->getExportCharset()); ob_clean(); header("Pragma: cache"); header("Content-type: application/octet-stream; charset=" . $locale->getExportCharset()); header("Content-Disposition: attachment; filename={$_REQUEST['module']}.csv"); header("Content-transfer-encoding: binary"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . TimeDate::httpTime()); header("Cache-Control: post-check=0, pre-check=0", false); header("Content-Length: " . mb_strlen($transContent, '8bit')); $BOM = ""; print $BOM . $transContent; }
global $current_user, $beanFiles; set_time_limit(3600); $db = DBManagerFactory::getInstance(); if (is_admin($current_user) || isset($from_sync_client) || is_admin_for_any_module($current_user)) { isset($_REQUEST['execute']) ? $execute = $_REQUEST['execute'] : ($execute = false); $export = false; if (sizeof($_POST) && isset($_POST['raction'])) { if (isset($_POST['raction']) && strtolower($_POST['raction']) == "export") { //jc - output buffering is being used. if we do not clean the output buffer //the contents of the buffer up to the length of the repair statement(s) //will be saved in the file... ob_clean(); header("Content-Disposition: attachment; filename=repairSugarDB.sql"); header("Content-Type: text/sql; charset={$app_strings['LBL_CHARSET']}"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . TimeDate::httpTime()); header("Cache-Control: post-check=0, pre-check=0", false); header("Content-Length: " . strlen($_POST['sql'])); //jc:7347 - for whatever reason, html_entity_decode is choking on converting //the html entity ' to a single quote, so we will use str_replace //instead $sql = str_replace(''', "'", $_POST['sql']); //echo html_entity_decode($_POST['sql']); echo $sql; } elseif (isset($_POST['raction']) && strtolower($_POST['raction']) == "execute") { $sql = str_replace(array("\n", '''), array('', "'"), preg_replace('#(/\\*.+?\\*/\\n*)#', '', $_POST['sql'])); foreach (explode(";", $sql) as $stmt) { $stmt = trim($stmt); if (!empty($stmt)) { $db->query($stmt, true, 'Executing repair query: '); }
function build_report_csv() { ini_set('zlib.output_compression', 'Off'); ob_start(); require_once 'include/export_utils.php'; $delimiter = getDelimiter(); $csv = ''; //text/comma-separated-values $sql = "SELECT id FROM aor_fields WHERE aor_report_id = '" . $this->id . "' AND deleted = 0 ORDER BY field_order ASC"; $result = $this->db->query($sql); $fields = array(); $i = 0; while ($row = $this->db->fetchByAssoc($result)) { $field = new AOR_Field(); $field->retrieve($row['id']); $path = unserialize(base64_decode($field->module_path)); $field_module = $this->report_module; if ($path[0] != $this->report_module) { foreach ($path as $rel) { $field_module = getRelatedModule($field_module, $rel); } } $label = str_replace(' ', '_', $field->label) . $i; $fields[$label]['field'] = $field->field; $fields[$label]['display'] = $field->display; $fields[$label]['function'] = $field->field_function; $fields[$label]['module'] = $field_module; if ($field->display) { $csv .= $this->encloseForCSV($field->label); $csv .= $delimiter; } ++$i; } $sql = $this->build_report_query(); $result = $this->db->query($sql); while ($row = $this->db->fetchByAssoc($result)) { $csv .= "\r\n"; foreach ($fields as $name => $att) { if ($att['display']) { if ($att['function'] != '') { $csv .= $this->encloseForCSV($row[$name]); } else { $csv .= $this->encloseForCSV(trim(strip_tags(getModuleField($att['module'], $att['field'], $att['field'], 'DetailView', $row[$name])))); } $csv .= $delimiter; } } } $csv = $GLOBALS['locale']->translateCharset($csv, 'UTF-8', $GLOBALS['locale']->getExportCharset()); ob_clean(); header("Pragma: cache"); header("Content-type: text/comma-separated-values; charset=" . $GLOBALS['locale']->getExportCharset()); header("Content-Disposition: attachment; filename={$this->name}.csv"); header("Content-transfer-encoding: binary"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . TimeDate::httpTime()); header("Cache-Control: post-check=0, pre-check=0", false); header("Content-Length: " . mb_strlen($csv, '8bit')); if (!empty($sugar_config['export_excel_compatible'])) { $csv == chr(255) . chr(254) . mb_convert_encoding($csv, 'UTF-16LE', 'UTF-8'); } print $csv; sugar_cleanup(true); }
/** * GET method handler * * @param void * @returns void */ function http_GET() { // TODO check for invalid stream $options = array(); $options["path"] = $this->path; $this->_get_ranges($options); if (true === ($status = $this->get($options))) { if (!headers_sent()) { $status = "200 OK"; if (!isset($options['mimetype'])) { $options['mimetype'] = "application/octet-stream"; } header("Content-type: {$options['mimetype']}"); if (isset($options['mtime'])) { header("Last-modified: " . TimeDate::httpTime()); } if (isset($options['stream'])) { // GET handler returned a stream if (!empty($options['ranges']) && 0 === fseek($options['stream'], 0, SEEK_SET)) { // partial request and stream is seekable if (count($options['ranges']) === 1) { $range = $options['ranges'][0]; if (isset($range['start'])) { fseek($options['stream'], $range['start'], SEEK_SET); if (feof($options['stream'])) { http_status("416 Requested range not satisfiable"); exit; } if (isset($range['end'])) { $size = $range['end'] - $range['start'] + 1; http_status("206 partial"); header("Content-length: {$size}"); header("Content-range: {$range['start']}-{$range['end']}/" . (isset($options['size']) ? $options['size'] : "*")); while ($size && !feof($options['stream'])) { $buffer = fread($options['stream'], 4096); $size -= strlen($buffer); echo $buffer; } } else { http_status("206 partial"); if (isset($options['size'])) { header("Content-length: " . ($options['size'] - $range['start'])); header("Content-range: {$start}-{$end}/" . (isset($options['size']) ? $options['size'] : "*")); } fpassthru($options['stream']); } } else { header("Content-length: " . $range['last']); fseek($options['stream'], -$range['last'], SEEK_END); fpassthru($options['stream']); } } else { $this->_multipart_byterange_header(); // init multipart foreach ($options['ranges'] as $range) { // TODO what if size unknown? 500? if (isset($range['start'])) { $from = $range['start']; $to = !empty($range['end']) ? $range['end'] : $options['size'] - 1; } else { $from = $options['size'] - $range['last'] - 1; $to = $options['size'] - 1; } $total = isset($options['size']) ? $options['size'] : "*"; $size = $to - $from + 1; $this->_multipart_byterange_header($options['mimetype'], $from, $to, $total); fseek($options['stream'], $start, SEEK_SET); while ($size && !feof($options['stream'])) { $buffer = fread($options['stream'], 4096); $size -= strlen($buffer); echo $buffer; } } $this->_multipart_byterange_header(); // end multipart } } else { // normal request or stream isn't seekable, return full content if (isset($options['size'])) { header("Content-length: " . $options['size']); } fpassthru($options['stream']); return; // no more headers } } elseif (isset($options['data'])) { if (is_array($options['data'])) { // reply to partial request } else { header("Content-length: " . strlen($options['data'])); echo $options['data']; } } } } if (false === $status) { $this->http_status("404 not found"); } $this->http_status("{$status}"); }
if (empty($yui_path[$version])) { continue; } $path = $yui_path[$version] . substr($param, strlen($version)); $extension = substr($path, strrpos($path, "_") + 1); //Only allowed file extensions if (empty($types[$extension])) { continue; } if (empty($contentType)) { $contentType = $types[$extension]; } //Put together the final filepath $path = substr($path, 0, strrpos($path, "_")) . "." . $extension; $contents = ''; if (is_file($path)) { $out .= "/*" . $path . "*/\n"; $contents = file_get_contents($path); $out .= $contents . "\n"; } $path = empty($contents) ? $path : $contents; $allpath .= md5($path); } $etag = '"' . md5($allpath) . '"'; // try to use the content cached locally if it's the same as we have here. header("Cache-Control: private"); header("Pragma: dummy=bogus"); header("Etag: {$etag}"); header('Expires: ' . TimeDate::httpTime(time() + 86400)); header("Content-Type: {$contentType}"); echo $out;
function saveVCard() { global $locale; $content = $this->toString(); if (!defined('SUITE_PHPUNIT_RUNNER')) { header("Content-Disposition: attachment; filename={$this->name}.vcf"); header("Content-Type: text/x-vcard; charset=" . $locale->getExportCharset()); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . TimeDate::httpTime()); header("Cache-Control: max-age=0"); header("Pragma: public"); //bug45856 IIS Doesn't like this to be set and it causes the vCard to not get saved if (preg_match('/iis/i', $_SERVER['SERVER_SOFTWARE']) === 0) { header("Content-Length: " . strlen($content)); } } print $locale->translateCharset($content, 'UTF-8', $locale->getExportCharset()); }
/** * Sends an HTTP response with the contents of the request file for download * * @param boolean $forceDownload true if force to download the file * @param array $info Array containing the file details. * Currently supported: * - content-type - content type for the file * */ public function outputFile($forceDownload, array $info) { if (empty($info['path'])) { throw new SugarApiException('No file name supplied'); } if (!empty($info['doc_type']) && $info['doc_type'] != "Sugar") { $this->api->setHeader("Location", $info['uri']); return; } $this->api->setHeader("Expires", TimeDate::httpTime(time() + 2592000)); if (!$forceDownload) { if (!empty($info['content-type'])) { $this->api->setHeader("Content-Type", $info['content-type']); } else { $this->api->setHeader("Content-Type", "application/octet-stream"); } } else { $this->api->setHeader("Content-Type", "application/force-download"); $this->api->setHeader("Content-type", "application/octet-stream"); if (empty($info['name'])) { $info['name'] = pathinfo($info['path'], PATHINFO_BASENAME); } $this->api->setHeader("Content-Disposition", "attachment; filename=\"" . $info['name'] . "\""); } $this->api->fileResponse($info['path']); }
/** * export * * @param $contents String value of the file contents */ public function export($contents) { global $locale; $filename = $this->getFilename(); header("Content-Disposition: attachment; filename=\"{$filename}\""); header("Content-Type: text/x-csv"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . TimeDate::httpTime()); header("Cache-Control: post-check=0, pre-check=0", false); header("Content-Length: " . mb_strlen($locale->translateCharset($contents, 'UTF-8', $locale->getExportCharset()))); echo $locale->translateCharset($contents, 'UTF-8', $locale->getExportCharset()); }
function action_exportrss() { //Bug 30094, If zlib is enabled, it can break the calls to header() due to output buffering. This will only work php5.2+ ini_set('zlib.output_compression', 'Off'); ob_start(); $tmpfname = tempnam(sys_get_temp_dir(), "kitten"); $zip = new ZipArchive(); $res = $zip->open($tmpfname, ZipArchive::CREATE); if ($res === TRUE) { $bean = BeanFactory::getBean('xeBaySellerLists'); $auction_list = $bean->get_full_list("", "listing_type='Chinese'"); $fixedprice_list = $bean->get_full_list("", "listing_type='FixedPriceItem'"); if (empty($auction_list)) { $auction_list = array(); } if (empty($fixedprice_list)) { $fixedprice_list = array(); } $item_list = array_merge($auction_list, $fixedprice_list); foreach ($item_list as &$item) { if (empty($item->xebaylisting_id)) { continue; } $rss = $item->build_shopwindow_topmost(true); if (!empty($rss)) { $zip->addFromString("{$item->xebaylisting_id}-topmost.xml", $rss); } $rss = $item->build_shopwindow_correlation(true); if (!empty($rss)) { $zip->addFromString("{$item->xebaylisting_id}-correlation.xml", $rss); } $rss = $item->build_shopwindow_random(true); if (!empty($rss)) { $zip->addFromString("{$item->xebaylisting_id}-random.xml", $rss); } } $zip->close(); $zipContent = file_get_contents($tmpfname); unlink($tmpfname); ob_clean(); header("Pragma: cache"); header('Content-Type: application/octet-stream'); header("Content-Disposition: attachment; filename=rss.zip"); header("Content-transfer-encoding: binary"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . TimeDate::httpTime()); header("Cache-Control: post-check=0, pre-check=0", false); header("Content-Length: " . strlen($zipContent)); print $zipContent; } else { echo 'Export RSS failed'; } sugar_cleanup(true); }
function action_exportrss() { //Bug 30094, If zlib is enabled, it can break the calls to header() due to output buffering. This will only work php5.2+ ini_set('zlib.output_compression', 'Off'); date_default_timezone_set("Asia/Shanghai"); $filename = "kittenrss_" . date("YmdHis"); ob_start(); $bean = BeanFactory::getBean('xeBayListings'); //$item_list = $bean->get_full_list("", "(listing_type='Chinese' OR listing_type='FixedPriceItem')"); $item_list = $bean->get_full_list(); if (count($item_list) == 0) { echo "Export RSS failed: No item"; ob_end_flush(); sugar_cleanup(true); } $tmpfname = tempnam(sys_get_temp_dir(), "kitten"); $zip = new ZipArchive(); $res = $zip->open($tmpfname, ZipArchive::CREATE); if ($res === TRUE) { foreach ($item_list as &$item) { // if (empty($item->item_id)) //continue; $rss = $item->build_shopwindow_topmost(true); if (!empty($rss)) { $zip->addFromString("rss/{$item->id}/head.xml", $rss); } $rss = $item->build_shopwindow_correlation(true); if (!empty($rss)) { $zip->addFromString("rss/{$item->id}/correlation.xml", $rss); } $rss = $item->build_shopwindow_random(true); if (!empty($rss)) { $zip->addFromString("rss/{$item->id}/random.xml", $rss); } } $zip->close(); $zipContent = file_get_contents($tmpfname); unlink($tmpfname); ob_clean(); header("Pragma: cache"); header('Content-Type: application/octet-stream'); header("Content-Disposition: attachment; filename={$filename}.zip"); header("Content-transfer-encoding: binary"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . TimeDate::httpTime()); header("Cache-Control: post-check=0, pre-check=0", false); header("Content-Length: " . strlen($zipContent)); print $zipContent; } else { echo 'Export RSS failed: Open zip file'; ob_end_flush(); } sugar_cleanup(true); }
/** * Export a Report As PDF * @param SugarBean $report * @return null */ protected function exportPdf(ServiceBase $api, SugarBean $report) { global $beanList, $beanFiles; global $sugar_config, $current_language; require_once 'modules/Reports/templates/templates_pdf.php'; $report_filename = false; if ($report->id != null) { //Translate pdf to correct language $reporter = new Report(html_entity_decode($report->content), '', ''); $reporter->layout_manager->setAttribute("no_sort", 1); $reporter->fromApi = true; //Translate pdf to correct language $mod_strings = return_module_language($current_language, 'Reports'); //Generate actual pdf $report_filename = template_handle_pdf($reporter, false); $api->setHeader("Content-Type", "application/pdf"); $api->setHeader("Content-Disposition", 'attachment; filename="' . basename($report_filename) . '"'); $api->setHeader("Expires", TimeDate::httpTime(time() + 2592000)); $api->fileResponse($report_filename); } }
public function saveVCardApi(ServiceBase $api) { global $locale; $content = $this->toString(); $api->setHeader("Content-Disposition", "attachment; filename={$this->name}.vcf"); $api->setHeader("Content-Type", "text/x-vcard; charset=" . $locale->getExportCharset()); $api->setHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); $api->setHeader("Last-Modified", TimeDate::httpTime()); $api->setHeader("Cache-Control", "max-age=0"); $api->setHeader("Pragma", "public"); return $locale->translateCharset($content, 'UTF-8', $locale->getExportCharset()); }
/** * Method to download a file exported * @codeCoverageIgnore */ public function exportProject($id, ServiceBase $api) { $projectContent = $this->getProject(array('id' => $id)); //File Name $filename = str_replace(' ', '_', $projectContent['project'][$this->name]) . '.' . $this->extension; $api->setHeader("Content-Disposition", "attachment; filename=" . $filename); $api->setHeader("Content-Type", "application/" . $this->extension); $api->setHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); $api->setHeader("Last-Modified", TimeDate::httpTime()); $api->setHeader("Cache-Control", "max-age=0"); $api->setHeader("Pragma", "public"); return serialize($projectContent); }
function saveVCard() { global $locale; $content = $this->toString(); if (!defined('SUGAR_PHPUNIT_RUNNER')) { header("Content-Disposition: attachment; filename={$this->name}.vcf"); header("Content-Type: text/x-vcard; charset=" . $locale->getExportCharset()); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . TimeDate::httpTime()); header("Cache-Control: max-age=0"); header("Pragma: public"); header("Content-Length: " . strlen($content)); } print $locale->translateCharset($content, 'UTF-8', $locale->getExportCharset()); }