Example #1
0
 /**
  * Returns the DocBook XML export
  * 
  * @param integer $nCatid     Number of categories
  * @param boolean $bDownwards Downwards
  * @param string  $lang       Language
  * 
  * @return string
  */
 public static function getDocBookExport($nCatid = 0, $bDownwards = true, $lang = "")
 {
     // TODO: remove the need of pre-generating a file to be read
     //generateDocBookExport();
     PMF_Export::_generateDocBookExport2();
     $filename = "xml/docbook/docbook.xml";
     $filename = dirname(dirname(__FILE__)) . "/" . $filename;
     return PMF_Export::_getFileContents($filename);
 }
Example #2
0
    $protocol = 'http';
    if (isset($_SERVER['HTTPS']) && strtoupper($_SERVER['HTTPS']) === 'ON') {
        $protocol = 'https';
    }
    header('Location: ' . $protocol . '://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']));
    exit;
}
//
// GET Parameters Syntax:
//   export.file.php?
//          type={pdf|xhtml|xml}
//      [&dispos={inline|attachment}], default: attachment
//       [&catid=NN[&downwards=1]], default: all, downwards
//
$categoryId = PMF_Filter::filterInput(INPUT_POST, 'catid', FILTER_VALIDATE_INT);
$downwards = PMF_Filter::filterInput(INPUT_POST, 'downwards', FILTER_VALIDATE_BOOLEAN, false);
$inlineDisposition = PMF_Filter::filterInput(INPUT_POST, 'dispos', FILTER_SANITIZE_STRING);
$type = PMF_Filter::filterInput(INPUT_POST, 'type', FILTER_SANITIZE_STRING, 'none');
$faq = new PMF_Faq($faqConfig);
$category = new PMF_Category($faqConfig);
$category->buildTree();
$tags = new PMF_Tags($faqConfig);
$export = PMF_Export::create($faq, $category, $faqConfig, $type);
$content = $export->generate($categoryId, $downwards);
// Stream the file content
$oHttpStreamer = new PMF_HttpStreamer(Response::create(), $type, $content);
if ('inline' == $inlineDisposition) {
    $oHttpStreamer->send(PMF_HttpStreamer::HTTP_CONTENT_DISPOSITION_INLINE);
} else {
    $oHttpStreamer->send(PMF_HttpStreamer::HTTP_CONTENT_DISPOSITION_ATTACHMENT);
}
Example #3
0
 /**
  * Sends HTTP Headers
  *
  * @return void
  */
 private function _setHttpHeaders()
 {
     $filename = "";
     $description = "";
     $mimeType = "";
     // Evaluate data upon export type request
     switch ($this->type) {
         case EXPORT_TYPE_DOCBOOK:
             $filename = "phpmyfaq_docbook.xml";
             $description = "phpMyFaq DocBook export file";
             // http://www.docbook.org/specs/wd-docbook-docbook-4.5CR1.html#a.mimetype
             $mimeType = "application/docbook+xml";
             break;
         case EXPORT_TYPE_PDF:
             $filename = "phpmyfaq.pdf";
             $description = "phpMyFaq PDF export file";
             $mimeType = "application/pdf";
             break;
         case EXPORT_TYPE_XHTML:
             $filename = "phpmyfaq.xhtml";
             $description = "phpMyFaq XHTML export file";
             $mimeType = "text/html";
             // Why not: text/html or text/xml?
             // See e.g.: http://www.hixie.ch/advocacy/xhtml
             // Unfortunaltelly IE doesn't handle it correctly :(
             // so currenctly we must use text/html as default.
             // See e.g.: http://keystonewebsites.com/articles/mime_type.php
             if (isset($_SERVER["HTTP_ACCEPT"]) && !(strpos($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml") === false)) {
                 $mimeType = "application/xhtml+xml";
             }
             break;
         case EXPORT_TYPE_XML:
             $filename = "phpmyfaq.xml";
             $description = "phpMyFaq XML export file";
             $mimeType = "text/xml";
             break;
             // In this case no default statement is required:
             // the one above is just for clean coding style
         // In this case no default statement is required:
         // the one above is just for clean coding style
         default:
             $filename = "phpmyfaq.pmf";
             $description = "Generic file";
             $mimeType = "application/octet-stream";
             break;
     }
     // Set the correct HTTP headers:
     // 1. Prevent proxies&browsers caching
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header("Expires: 0");
     header("Cache-Control: private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
     header("Pragma: no-cache");
     // 2. Set the correct values for file streaming
     header("Content-Type: " . $mimeType);
     if ($this->disposition == self::HTTP_CONTENT_DISPOSITION_ATTACHMENT && isset($_SERVER["HTTP_USER_AGENT"]) && !(strpos($_SERVER["HTTP_USER_AGENT"], "MSIE") === false)) {
         header("Content-Type: application/force-download");
     }
     // RFC2616, �19.5.1: $filename must be a quoted-string
     header("Content-Disposition: " . $this->disposition . "; filename=\"" . PMF_Export::getExportTimestamp() . "_" . $filename . "\"");
     if (!empty($description)) {
         header("Content-Description: " . $description);
     }
     header("Content-Transfer-Encoding: binary");
     // Deny partial downloads (opposite to: "Accept-Ranges: bytes")
     header("Accept-Ranges: none");
     header("Content-Length: " . $this->size);
 }
Example #4
0
 /**
  * Sends HTTP Headers
  *
  * @return void
  */
 private function _setHttpHeaders()
 {
     $filename = $description = $mimeType = '';
     // Evaluate data upon export type request
     switch ($this->type) {
         case 'pdf':
             $filename = "phpmyfaq.pdf";
             $description = "phpMyFaq PDF export file";
             $mimeType = "application/pdf";
             break;
         case 'xhtml':
             $filename = "phpmyfaq.xhtml";
             $description = "phpMyFaq XHTML export file";
             $mimeType = "text/html";
             // Why not: text/html or text/xml?
             // See e.g.: http://www.hixie.ch/advocacy/xhtml
             // Unfortunaltelly IE doesn't handle it correctly :(
             // so currenctly we must use text/html as default.
             // See e.g.: http://keystonewebsites.com/articles/mime_type.php
             if (isset($_SERVER["HTTP_ACCEPT"]) && !(strpos($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml") === false)) {
                 $mimeType = "application/xhtml+xml";
             }
             break;
         case 'xml':
             $filename = "phpmyfaq.xml";
             $description = "phpMyFaq XML export file";
             $mimeType = "text/xml";
             break;
         case 'csv':
             $filename = "phpmyfaq.csv";
             $description = "phpMyFaq CSV export file";
             $mimeType = "text/csv";
             break;
             // In this case no default statement is required:
             // the one above is just for clean coding style
         // In this case no default statement is required:
         // the one above is just for clean coding style
         default:
             $filename = "phpmyfaq.pmf";
             $description = "Generic file";
             $mimeType = "application/octet-stream";
             break;
     }
     // Set the correct HTTP headers:
     // 1. Prevent proxies&browsers caching
     $this->response->headers->set("Last-Modified", gmdate("D, d M Y H:i:s") . " GMT");
     $this->response->headers->set("Expires", "0");
     $this->response->headers->set("Cache-Control", "private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
     $this->response->headers->set("Pragma", "no-cache");
     // 2. Set the correct values for file streaming
     if ($this->disposition == self::HTTP_CONTENT_DISPOSITION_ATTACHMENT && isset($_SERVER["HTTP_USER_AGENT"]) && !(strpos($_SERVER["HTTP_USER_AGENT"], "MSIE") === false)) {
         $this->response->headers->set("Content-Type", "application/force-download");
     } else {
         $this->response->headers->set("Content-Type", $mimeType);
     }
     // RFC2616, �19.5.1: $filename must be a quoted-string
     $this->response->headers->set("Content-Disposition", $this->disposition . "; filename=\"" . PMF_Export::getExportTimestamp() . "_" . $filename . "\"");
     if (!empty($description)) {
         $this->response->headers->set("Content-Description", $description);
     }
     $this->response->headers->set("Content-Transfer-Encoding", "binary");
     $this->response->headers->set("Accept-Ranges", "none");
     $this->response->headers->set("Content-Length", $this->size);
 }
Example #5
0
$downwards = PMF_Filter::filterInput(INPUT_POST, 'downwards', FILTER_VALIDATE_BOOLEAN, false);
$inlineDisposition = PMF_Filter::filterInput(INPUT_POST, 'dispos', FILTER_VALIDATE_BOOLEAN, false);
$type = PMF_Filter::filterInput(INPUT_POST, 'type', FILTER_SANITIZE_STRING, EXPORT_TYPE_NONE);
// Prepare the file content to be streamed
switch ($type) {
    case EXPORT_TYPE_DOCBOOK:
        $content = PMF_Export::getDocBookExport($catid, $downwards);
        break;
    case EXPORT_TYPE_PDF:
        $content = PMF_Export::getPDFExport($catid, $downwards);
        break;
    case EXPORT_TYPE_XHTML:
        $content = PMF_Export::getXHTMLExport($catid, $downwards);
        break;
    case EXPORT_TYPE_XML:
        $content = PMF_Export::getXMLExport($catid, $downwards);
        break;
        // In this case no default statement is required:
        // the one above is just for clean coding style
    // In this case no default statement is required:
    // the one above is just for clean coding style
    default:
        break;
}
// Stream the file content
$oHttpStreamer = new PMF_HttpStreamer($type, $content);
if ($inlineDisposition) {
    $oHttpStreamer->send(PMF_HttpStreamer::HTTP_CONTENT_DISPOSITION_INLINE);
} else {
    $oHttpStreamer->send(PMF_HttpStreamer::HTTP_CONTENT_DISPOSITION_ATTACHMENT);
}