/** * Display the template * * @param sting $tpl template * * @return void */ public function display($tpl = null) { if (parent::display($tpl) !== false) { if (!$this->app->isAdmin()) { $state = $this->get('State'); $this->params = $state->get('params'); if ($this->params->get('menu-meta_description')) { $this->doc->setDescription($this->params->get('menu-meta_description')); } if ($this->params->get('menu-meta_keywords')) { $this->doc->setMetadata('keywords', $this->params->get('menu-meta_keywords')); } if ($this->params->get('robots')) { $this->doc->setMetadata('robots', $this->params->get('robots')); } } // Set the response to indicate a file download $this->app->setHeader('Content-Type', 'application/vnd.ms-word'); $name = $this->getModel()->getTable()->label; $name = JStringNormalise::toDashSeparated($name); $this->app->setHeader('Content-Disposition', "attachment;filename=\"" . $name . ".doc\""); $this->doc->setMimeEncoding('text/html; charset=Windows-1252', false); $this->output(); } }
/** * Main setup routine for displaying the form/detail view * * @param string $tpl template * * @return void */ public function display($tpl = null) { if (parent::display($tpl) !== false) { $this->output(); $app = JFactory::getApplication(); if (!$app->isAdmin()) { $this->state = $this->get('State'); $this->document = JFactory::getDocument(); $model = $this->getModel(); $this->params = $this->state->get('params'); $row = $model->getData(); $w = new FabrikWorker(); if ($this->params->get('menu-meta_description')) { $desc = $w->parseMessageForPlaceHolder($this->params->get('menu-meta_description'), $row); $this->document->setDescription($desc); } if ($this->params->get('menu-meta_keywords')) { $keywords = $w->parseMessageForPlaceHolder($this->params->get('menu-meta_keywords'), $row); $this->document->setMetadata('keywords', $keywords); } if ($this->params->get('robots')) { $this->document->setMetadata('robots', $this->params->get('robots')); } // Set the response to indicate a file download JResponse::setHeader('Content-Type', 'application/vnd.ms-word'); $name = $this->getModel()->getTable()->label; $name = JStringNormalise::toDashSeparated($name); JResponse::setHeader('Content-Disposition', "attachment;filename=\"" . $name . ".doc\""); $this->document->setMimeEncoding('text/html; charset=Windows-1252', false); } } }
/** * Method to test JStringNormalise::toDashSeparated(). * * @param string $expected The expected value from the method. * @param string $input The input value for the method. * * @return void * * @dataProvider seedToDashSeparated * @since 11.3 */ public function testToDashSeparated($expected, $input) { $this->assertEquals($expected, JStringNormalise::toDashSeparated($input)); }
/** * Helper wrapper method for toDashSeparated * * @param string $input The string input (ASCII only). * * @return string The dash separated string. * * @see JUserHelper::toDashSeparated() * @since 3.4 */ public function toDashSeparated($input) { return JStringNormalise::toDashSeparated($input); }
/** * Attach the details view as a PDF to the email * * @param array &$thisAttachments Attachments * * @throws RuntimeException * * @return void */ protected function pdfAttachement(&$thisAttachments) { $params = $this->getParams(); if ($params->get('attach_pdf', 0) == 0) { return; } $model = $this->getModel(); $document = JFactory::getDocument(); $config = JFactory::getConfig(); $docType = $document->getType(); $document->setType('pdf'); $app = JFactory::getApplication(); $input = $app->input; $orig['details'] = $input->get('view'); $orig['format'] = $input->get('format'); $input->set('view', 'details'); $input->set('format', 'pdf'); // Ensure the package is set to fabrik $prevUserState = $app->getUserState('com_fabrik.package'); $app->setUserState('com_fabrik.package', 'fabrik'); try { // Require files and set up DOM pdf require_once JPATH_SITE . '/components/com_fabrik/helpers/pdf.php'; require_once JPATH_SITE . '/components/com_fabrik/controllers/details.php'; FabrikPDFHelper::iniDomPdf(); $dompdf = new DOMPDF(); $size = strtoupper($params->get('pdf_size', 'A4')); $orientation = $params->get('pdf_orientation', 'portrait'); $dompdf->set_paper($size, $orientation); // Store in output buffer ob_start(); $controller = new FabrikControllerDetails(); $controller->display(); $html = ob_get_contents(); ob_end_clean(); // Load the HTML into DOMPdf and render it. $dompdf->load_html($html); $dompdf->render(); // Store the file in the tmp folder so it can be attached $file = $config->get('tmp_path') . '/' . JStringNormalise::toDashSeparated($model->getForm()->label . '-' . $input->getString('rowid')) . '.pdf'; $pdf = $dompdf->output(); if (JFile::write($file, $pdf)) { $thisAttachments[] = $file; } else { throw new RuntimeException('Could not write PDF file to tmp folder'); } } catch (Exception $e) { $app->enqueueMessage($e->getMessage(), 'error'); } // Set the package back to what it was before rendering the module $app->setUserState('com_fabrik.package', $prevUserState); // Reset input foreach ($orig as $key => $val) { $input->set($key, $val); } // Reset document type $document->setType($docType); }
/** * Attach the details view as a PDF to the email * * @param array &$thisAttachments Attachments * * @throws RuntimeException * * @return void */ protected function pdfAttachment(&$thisAttachments) { $params = $this->getParams(); if ($params->get('attach_pdf', 0) == 0) { return; } /** @var FabrikFEModelForm $model */ $model = $this->getModel(); $document = JFactory::getDocument(); $docType = $document->getType(); $document->setType('pdf'); $input = $this->app->input; $orig['details'] = $input->get('view'); $orig['format'] = $input->get('format'); $input->set('view', 'details'); $input->set('format', 'pdf'); // set editable false so things like getFormCss() pick up the detail, not form, CSS $model->setEditable(false); // Ensure the package is set to fabrik $prevUserState = $this->app->getUserState('com_fabrik.package'); $this->app->setUserState('com_fabrik.package', 'fabrik'); try { $model->getFormCss(); foreach ($document->_styleSheets as $url => $ss) { $url = htmlspecialchars_decode($url); $formCss[] = file_get_contents($url); } // Require files and set up DOM pdf require_once JPATH_SITE . '/components/com_fabrik/helpers/pdf.php'; require_once JPATH_SITE . '/components/com_fabrik/controllers/details.php'; FabrikPDFHelper::iniDomPdf(); $domPdf = new DOMPDF(); $size = strtoupper($params->get('pdf_size', 'A4')); $orientation = $params->get('pdf_orientation', 'portrait'); $domPdf->set_paper($size, $orientation); $controller = new FabrikControllerDetails(); /** * $$$ hugh - stuff our model in there, with already formatted data, so it doesn't get rendered * all over again by the view, with unformatted data. Should probably use a setModel() method * here instead of poking in to the _model, but I don't think there is a setModel for controllers? */ $controller->_model = $model; $controller->_model->data = $this->getProcessData(); // Store in output buffer ob_start(); $controller->display(); $html = ob_get_contents(); ob_end_clean(); if (!empty($formCss)) { $html = "<style>\n" . implode("\n", $formCss) . "</style>\n" . $html; } // Load the HTML into DOMPdf and render it. $domPdf->load_html(utf8_decode($html)); $domPdf->render(); // Store the file in the tmp folder so it can be attached $layout = FabrikHelperHTML::getLayout('form.fabrik-pdf-title'); $displayData = new stdClass(); $displayData->doc = $document; $displayData->model = $model; $fileName = $layout->render($displayData); $file = $this->config->get('tmp_path') . '/' . JStringNormalise::toDashSeparated($fileName) . '.pdf'; $pdf = $domPdf->output(); if (JFile::write($file, $pdf)) { $thisAttachments[] = $file; } else { throw new RuntimeException('Could not write PDF file to tmp folder'); } } catch (Exception $e) { $this->app->enqueueMessage($e->getMessage(), 'error'); } // set back to editable $model->setEditable(true); // Set the package back to what it was before rendering the module $this->app->setUserState('com_fabrik.package', $prevUserState); // Reset input foreach ($orig as $key => $val) { $input->set($key, $val); } // Reset document type $document->setType($docType); }
/** * Method to change the title & alias. * * @param integer $id Article id * @param integer $catId The id of the category. * @param array &$data The row data. * * @return null */ protected function generateNewTitle($id, $catId, &$data) { $table = JTable::getInstance('Content'); $alias = JApplication::stringURLSafe(JStringNormalise::toDashSeparated($data['title'])); $data['alias'] = $alias; $title = $data['title']; $titles = array(); $aliases = array(); // Test even if an existing article, we then remove that article title from the $titles array. // Means that changing an existing Fabrik title to an existing article title // should increment the Joomla article title. while ($table->load(array('alias' => $alias, 'catid' => $catId))) { $title = JString::increment($title); $titles[$table->get('id')] = $title; $alias = JString::increment($alias, 'dash'); $aliases[$table->get('id')] = $alias; } unset($titles[$id]); unset($aliases[$id]); $title = empty($titles) ? $data['title'] : array_pop($titles); $alias = empty($aliases) ? $data['alias'] : array_pop($aliases); // Update the Fabrik record's title if the article alias changes.. if ($title != $data['title']) { /** @var FabrikFEModelForm $formModel */ $formModel = $this->getModel(); $listModel = $formModel->getListModel(); $pkName = $listModel->getPrimaryKey(true); $pk = ArrayHelper::getValue($this->data, $pkName); $titleField = $formModel->getElement($this->getParams()->get('title'), true); $titleField = $titleField->getFullName(false, false); $listModel->updateRows(array($pk), $titleField, $title); } $data['title'] = $title; $data['alias'] = $alias; }