function doEmailDelivery($email, $doc_id, $order_id, $key) { @ini_set('memory_limit', '1024M'); $database = JFactory::getDBO(); @($x = explode(",", $doc_id)); if (is_array($x) == false) { $x[] = $doc_id; $mode = 'single'; } else { $mode = 'cart'; } $mail = JFactory::getMailer(); $mail->IsHTML(true); $app = JFactory::getApplication(); //$conf = JFactory::getConfig(); $emailBody = $this->cfg['emailDeliveryBody']; $maxEmailDeliverySize = $this->cfg['emailDeliveryMaxSizeInMB'] * 1024 * 1024; $downloadLink = JURI::base() . "index.php?option=com_docmanpaypal&task=doc_download&gid=" . $doc_id . "&order_id={$order_id}&key={$key}&mode={$mode}&Itemid=" . (int) JRequest::getVar('Itemid'); foreach ($x as $doc_id) { $database->setQuery("select storage_path from #__docman_documents where docman_document_id = {$doc_id} limit 1"); $dmfilename = $database->loadResult(); $attachment = $this->docman_path . DS . $dmfilename; //3.2.2 Encrypted PDF files if ($this->cfg['encryptPDF'] == 1 && pathinfo($attachment, PATHINFO_EXTENSION) == 'pdf') { //password for the pdf file (I suggest using the email adress of the purchaser) $password = $email; //name of the original file (unprotected) $origFile = $attachment; //name of the destination file (password protected and printing rights removed) $destFile = dirname($attachment) . DS . basename($attachment, '.pdf') . "_protected.pdf"; @unlink($destFile); require_once 'fpdi' . DS . 'FPDI_Protection.php'; $pdf = new FPDI_Protection(); if ($this->cfg['pdfOrientation'] == 'portrait') { $pdf->FPDF('P', 'in', array('8', '11')); } else { $pdf->FPDF('P', 'in', array('11', '8')); } $pagecount = $pdf->setSourceFile($attachment); for ($loop = 1; $loop <= $pagecount; $loop++) { $tplidx = $pdf->importPage($loop); $pdf->addPage(); $pdf->useTemplate($tplidx); } $pdf->SetProtection(array(), $password); $pdf->Output($destFile, 'F'); //pdfEncrypt($origFile, $password, $destFile ); $attachment = $destFile; //mail('*****@*****.**','DEbug',"$attachment, $origFile, $destFile"); } if ($maxEmailDeliverySize > filesize($attachment)) { $mail->addAttachment($attachment); } else { $theFileIsLarge = true; } } if ($this->cfg['emailDeliveryDownloadLink'] == 0) { $emailBody = str_replace('%downloadlink%', '', $emailBody); } if ($this->cfg['emailDeliveryDownloadLink'] == 1) { $emailBody = str_replace('%downloadlink%', $downloadLink, $emailBody); } if ($this->cfg['emailDeliveryDownloadLink'] == 2) { if ($theFileIsLarge) { $emailBody = str_replace('%downloadlink%', $downloadLink, $emailBody); } else { $emailBody = str_replace('%downloadlink%', '', $emailBody); } } if ($this->cfg['emailDeliveryToAdmin'] == 1) { $database->setQuery("SELECT #__users.email, #__usergroups.title from #__users left join #__user_usergroup_map on #__users.id = #__user_usergroup_map.user_id left join #__usergroups on #__usergroups.id = #__user_usergroup_map.group_id where #__usergroups.title = 'Super Users';"); $result = $database->loadAssocList(); foreach ($result as $row) { $mail->addRecipient($row['email']); } } $mail->setBody($emailBody); $mail->setSubject($this->cfg['emailDeliverySubject']); if ($app->getCfg('mailer') == 'smtp') { $mail->useSMTP($app->getCfg('smtpauth'), $app->getCfg('smtphost'), $app->getCfg('smtpuser'), $app->getCfg('smtppass'), $app->getCfg('smtpsecure'), $app->getCfg('smtpport')); } $mail->setSender(array($app->getCfg('mailfrom'), $app->getCfg('fromname'))); $mail->addRecipient($email); $mail->Send(); }
$database = &JFactory::getDBO(); $document = &JFactory::getDocument(); $doc = &JDocument::getInstance('raw'); $document = $doc; require_once(JPATH_ADMINISTRATOR . DS .'components' . DS. 'com_docmanpaypal' . DS . 'fpdi' . DS . 'FPDI_Protection.php'); $pdf = new FPDI_Protection(); if ($dm->cfg['pdfOrientation'] == 'portrait') { $pdf->FPDF('P', 'in', array('8.267','11.692')); } else { $pdf->FPDF('P', 'in', array('11.692','8.267')); } $sourceFile = $dm->docman_path . DS . $row->storage_path; $pdfPreviewPath = dirname($sourceFile) . DS . basename($sourceFile,'.pdf') . "_preview.pdf"; //die($pdfPreviewPath); if (file_exists($pdfPreviewPath)) { $sourceFile = $pdfPreviewPath; } $pagecount = $pdf->setSourceFile($sourceFile); for ($loop = 1; $loop <= $dm->cfg['pdfPreviewPages']; $loop++) { $tplidx = $pdf->importPage($loop); $pdf->addPage(); $pdf->useTemplate($tplidx); } $pdf->Output('preview.pdf','D'); break; } ?>
/** * Merge PDF files together in the order they were entered to the $files array. * * @return string|bool * @see http://stackoverflow.com/questions/19855712/merge-multiple-pdf-files-into-one-in-php#answer-19856524 * @uses FPDI_Protection::setSourceFile() * @uses FPDI_Protection::importPage() * @uses FPDI_Protection::addPage() * @uses FPDI_Protection::useTemplate() * @uses FPDI_Protection::SetAuthor() * @uses FPDI_Protection::SetCreator() * @uses FPDI_Protection::SetTitle() * @uses FPDI_Protection::SetSubject() * @uses FPDI_Protection::SetKeywords() * @uses FPDI_Protection::Output() */ public function merge() { $this->Log->write(__METHOD__, Log::LOG_LEVEL_SYSTEM_INFORMATION); // input validation if (!Helpers::is_array_ne($this->files)) { $this->Log->write('Files is not an array. Enter at least 1 file before attempting to combine.', Log::LOG_LEVEL_WARNING); return false; } try { $pdf = new \FPDI_Protection(); foreach ($this->files as $file) { $page_count = $pdf->setSourceFile($this->directory . $file); for ($j = 0; $j < $page_count; $j++) { $template_index = $pdf->importPage($j + 1, '/MediaBox'); $pdf->addPage($this->orientation, $this->paper_size); $pdf->useTemplate($template_index, 0, 0, 0, 0, true); } // CAUTION: Delete the PDF input file if not debugging. if (!$this->debug) { unlink($file); } } $pdf->SetAuthor($this->author); $pdf->SetCreator($this->creator); $pdf->SetTitle($this->title); $pdf->SetSubject($this->subject); $pdf->SetKeywords(implode(', ', $this->keywords)); if (Helpers::is_string_ne($this->user_password)) { $pdf->SetProtection(array('print', 'copy'), $this->user_password, $this->owner_password); } $output_path = $this->directory . $this->output_file; $this->Log->write('output file path', Log::LOG_LEVEL_USER, $output_path); $output = $pdf->Output('F', $output_path); if ($output === '') { // file was created return $output_path; } else { $this->Log->write('Error writing file to output', Log::LOG_LEVEL_WARNING, $output); return $output; } } catch (\Exception $ex) { $this->Log->exception($ex); return false; } }