Пример #1
0
 /**
  * Compile the css for a platform and a theme just as a preview
  *
  * @param ServiceBase $api
  * @param array $args
  *
  * @return string Plaintext css
  */
 public function previewCSS(ServiceBase $api, array $args)
 {
     // If `preview` is defined, it means that the call was made by the Theme Editor in Studio so we want to return
     // plain text/css
     // Validating arguments
     $platform = isset($args['platform']) ? $args['platform'] : 'base';
     $themeName = isset($args['themeName']) ? $args['themeName'] : 'default';
     $minify = isset($args['min']) ? true : false;
     $theme = new SidecarTheme($platform, $themeName);
     $theme->loadVariables();
     $theme->setVariables($args);
     $theme->setVariable('baseUrl', '"../../styleguide/assets"');
     $api->setHeader('Content-type', 'text/css');
     $css = $theme->previewCss($minify);
     $api->setHeader('Content-Length', strlen($css));
     echo $css;
     return;
 }
Пример #2
0
 /**
  * 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());
 }
Пример #3
0
 /**
  * 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']);
 }
Пример #4
0
 /**
  * Inspects the request to determine if there is a need to decode the file
  * data on PUT requests. This supports legacy SOAP API style file transfers.
  *
  * @param ServiceBase $api A Service object
  * @param array $args The request arguments
  * @return boolean
  */
 protected function isFileEncoded($api, $args)
 {
     if ($api->getRequest()->hasHeader('X_CONTENT_TRANSFER_ENCODING')) {
         return $api->getRequest()->getHeader('X_CONTENT_TRANSFER_ENCODING') === 'base64';
     }
     if (isset($args['content_transfer_encoding'])) {
         return $args['content_transfer_encoding'] === 'base64';
     }
     return false;
 }
Пример #5
0
 /**
  * Given a platform and language, returns the language JSON contents
  *
  * @param ServiceBase $api
  * @param array $args
  */
 public function getLanguage(ServiceBase $api, array $args, $public = false)
 {
     // Get the metadata manager we need first
     $mm = $this->getMetaDataManager($api->platform, $public);
     //Since this is a raw response we need to set the content type ourselves.
     $api->getResponse()->setHeader("Content-Type", "application/json");
     //Cache language files forever as the request includes the hash in the URL
     $api->getResponse()->setHeader("Cache-Control", "max-age=31556940, private");
     $api->getResponse()->setHeader("Pragma", "");
     $api->getResponse()->setHeader('Expires', gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 31556940));
     return $mm->getLanguage($args);
 }
Пример #6
0
 /**
  * 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);
     }
 }
Пример #7
0
 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());
 }
Пример #8
0
 /**
  * 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);
 }