/var/www/html_uk/wp-content/plugins/automatewoo/admin/controllers/preview.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
// phpcs:ignoreFile

namespace AutomateWoo\Admin\Controllers;

if ( ! 
defined'ABSPATH' ) ) exit;

use 
AutomateWoo\Admin;
use 
AutomateWoo\Clean;
use 
AutomateWoo\Exceptions\InvalidPreviewData;
use 
AutomateWoo\Preview_Data;

/**
 * @class Preview
 */
class Preview extends Base {


    function 
handle() {
        switch( 
$this->get_current_action() ) {
            case 
'loading':
                
$this->output_loader();
                break;
            case 
'preview-ui':
                
$this->output_preview_ui();
                break;
        }
    }


    function 
output_loader() {
        
Admin::get_view'email-preview-loader' );
    }


    function 
output_preview_ui() {

        
$type Clean::stringaw_request('type') );
        
$args Clean::recursiveaw_request('args') );

        
$iframe_url add_query_arg([
            
'action' => 'aw_email_preview_iframe',
            
'type' => $type,
            
'args' => $args
        
], admin_url'admin-ajax.php' ) );


        switch ( 
$type ) {
            case 
'workflow_action':
                try {
                    
$action Preview_Data::generate_preview_action$args['workflow_id'], $args['action_number'] );
                } catch ( 
InvalidPreviewData $e ) {
                    return 
wp_die$e->getMessage() );
                }

                
$email_subject $action->get_option('subject'true );
                
$template $action->get_option'template' );
                break;

            default:
                
$email_subject '';
                
$template '';
        }

        
$email_subject apply_filters'automatewoo/email_preview/subject'$email_subject$type$args );
        
$template apply_filters'automatewoo/email_preview/template'$template$type$args );

        
Admin::get_view('email-preview-ui', [
            
'iframe_url' => $iframe_url,
            
'type' => $type,
            
'args' => $args,
            
'email_subject' => $email_subject,
            
'template' => $template
        
]);

    }


}

return new 
Preview();