Ejemplo n.º 1
0
 /**
  * Generates the export
  *
  * @param integer $categoryId Category Id
  * @param boolean $downwards  If true, downwards, otherwise upward ordering
  * @param string  $language   Language
  *
  * @return string
  */
 public function generate($categoryId = 0, $downwards = true, $language = '')
 {
     global $PMF_LANG;
     // Set PDF options
     $this->pdf->enableBookmarks = true;
     $this->pdf->isFullExport = true;
     $filename = 'FAQs.pdf';
     // Initialize categories
     $this->category->transform($categoryId);
     $this->pdf->setCategory($categoryId);
     $this->pdf->setCategories($this->category->categoryName);
     $this->pdf->SetCreator($this->_config->get('main.titleFAQ') . ' - powered by phpMyFAQ ' . $this->_config->get('main.currentVersion'));
     $faqdata = $this->faq->get(FAQ_QUERY_TYPE_EXPORT_XML, $categoryId, $downwards, $language);
     $categories = $this->category->catTree;
     $categoryGroup = 0;
     $this->pdf->AddPage();
     foreach ($categories as $category) {
         if ($category['id'] !== $categoryGroup) {
             $this->pdf->Bookmark(html_entity_decode($this->category->categoryName[$category['id']]['name'], ENT_QUOTES, 'utf-8'), $category['level'], 0);
             $categoryGroup = $category['id'];
         }
         foreach ($faqdata as $faq) {
             if ($faq['category_id'] === $category['id']) {
                 $this->pdf->AddPage();
                 $this->pdf->setCategory($category['id']);
                 $this->pdf->Bookmark(html_entity_decode($faq['topic'], ENT_QUOTES, 'utf-8'), $category['level'] + 1, 0);
                 if ($this->tags instanceof PMF_Tags) {
                     $tags = $this->tags->getAllTagsById($faq['id']);
                 }
                 $this->pdf->WriteHTML('<h2 align="center">' . $faq['topic'] . '</h2>', true);
                 $this->pdf->Ln(10);
                 $this->pdf->SetFont($this->pdf->getCurrentFont(), '', 12);
                 $this->pdf->WriteHTML(trim($faq['content']));
                 $this->pdf->Ln(10);
                 if (!empty($faq['keywords'])) {
                     $this->pdf->Ln();
                     $this->pdf->Write(5, $PMF_LANG['msgNewContentKeywords'] . ' ' . $faq['keywords']);
                 }
                 if (isset($tags) && 0 !== count($tags)) {
                     $this->pdf->Ln();
                     $this->pdf->Write(5, $PMF_LANG['ad_entry_tags'] . ': ' . implode(', ', $tags));
                 }
                 $this->pdf->Ln();
                 $this->pdf->Ln();
                 $this->pdf->Write(5, $PMF_LANG['msgLastUpdateArticle'] . PMF_Date::createIsoDate($faq['lastmodified']));
             }
         }
     }
     // remove default header/footer
     $this->pdf->setPrintHeader(false);
     $this->pdf->addFaqToc();
     return $this->pdf->Output($filename);
 }