function hicaliber_doc_handler()
{
    global $wp;
    if (strpos($wp->request, DocHandler::REQUEST_URL) !== false && isset($_GET[DocHandler::GET_ID])) {
        $filename = $_GET[DocHandler::GET_ID];
        if (!is_user_logged_in()) {
            wp_redirect(home_url('members/login?file=' . $filename));
        }
        $fileparts = explode('.', $filename);
        if (sizeof($fileparts) !== 2) {
            die('Invalid File');
        }
        $ext = strtolower($fileparts[1]);
        switch ($ext) {
            case 'pdf':
                $file = DocHandler::pdf_upload_dir($filename);
                if (!file_exists($file)) {
                    die('File not found');
                }
                header('Content-type: application/pdf');
                header('Content-Disposition: inline; filename="' . $filename . '"');
                header('Content-Transfer-Encoding: binary');
                header('Accept-Ranges: bytes');
                @readfile($file);
                break;
            default:
                # code...
                break;
        }
    }
}
Ejemplo n.º 2
0
 public static function generate_pdf($params, $view, $save = true)
 {
     ob_start();
     include plugin_dir_path(__FILE__) . '../templates/' . $view . '.php';
     $html = ob_get_contents();
     ob_end_clean();
     $mpdf = new \mPDF();
     $mpdf->useOnlyCoreFonts = true;
     $mpdf->WriteHTML($html);
     $filename = time() . '.pdf';
     if (strlen($view) > 3) {
         $filename = strtoupper(substr($view, 0, 3)) . $filename;
     } else {
         $filename = $view . $filename;
     }
     if ($save) {
         $mpdf->Output(DocHandler::pdf_upload_dir($filename), 'F');
         return $filename;
     } else {
         $mpdf->Output();
     }
     exit;
 }
    private function send_email($template_name, $subject, $to, $recipient_name, $content=array(), $pdf=null)
    {
        //FOR TESTING
        $amachome = 'http://hicalibertest.com.au/amac/'; //home_url();
        $amaclogo = $amachome.'/wp-content/themes/amac/assets/images/logo.png'; //home_url('/wp-content/themes/amac/assets/images/logo.png');

        $message = array(
            'subject' => $subject,
            'to' => array(
                array(
                    'email' => $to,
                    'name' => $recipient_name,
                    'type' => 'to'
                )
            ),
            'html' => array(
                array( 'name'=>'amachome', 'content'=> "<a href='$amachome'>www.amac.org.au</a>" ),
                array( 'name'=>'amaclogo', 'content'=> "<img style='width:100%;' src='$amaclogo'></img>" ),
            )
        );

        foreach ($content as $key => $value) 
        {
            $message['html'][] = array('name'=>$key, 'content'=>$value);
        }

        if(!empty($pdf))
        {
            $message['attachments'] =  DocHandler::pdf_upload_dir($pdf);
        }
        
        wpMandrill::sendEmail($message, null ,$template_name);
    }