Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 60
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
Client_Portal_Render_Helper
0.00% covered (danger)
0.00%
0 / 59
0.00% covered (danger)
0.00%
0 / 6
272
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 show_single_obj_error_and_die
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 portal_footer
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
 portal_viewing_as_admin_banner
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
6
 admin_message
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
12
 portal_nav
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 1
42
1<?php
2/*
3* Jetpack CRM
4* https://jetpackcrm.com
5*
6* Client Portal Render Helper
7*
8*/
9namespace Automattic\JetpackCRM;
10
11defined( 'ZEROBSCRM_PATH' ) || exit( 0 );
12
13/**
14 *
15 * Client Portal class that helps rendering the Client Portal HTML.
16 */
17class Client_Portal_Render_Helper {
18    public $parent_portal;
19
20    public function __construct( $parent ) {
21        $this->parent_portal = $parent;
22    }
23
24    /**
25     * Shows an object load error and dies.
26     */
27    function show_single_obj_error_and_die() {
28        $err  = '<center>';
29        $err .= '<h3>' . __( 'Error loading object', 'zero-bs-crm' ) . '</h3>';
30        $err .= __( 'Either this object does not exist or you do not have permission to view it.', 'zero-bs-crm' );
31        $err .= '</center>';
32        echo $err;
33        die( 0 );
34    }
35
36    #} MS - can you make this work with templates, couldn't so dumped (dumbly) here for now:
37    function portal_footer() {
38        // won't return ours :/
39        ##WLREMOVE
40        global $zbs;
41        $showpoweredby_public = $zbs->settings->get( 'showpoweredby_public' ) === 1 ? true : false;
42        if ( $showpoweredby_public ) {
43            ?>
44            <div class="zerobs-portal-poweredby" style="font-size:11px;position:absolute;bottom:25px;right:50px;font-size:12px;">
45                <?php echo wp_kses( sprintf( __( 'Client Portal by <a href="%s" target="_blank">Jetpack CRM</a>', 'zero-bs-crm' ), esc_url( $zbs->urls['home'] ) ), $zbs->acceptable_restricted_html ); ?>
46            </div>
47            <?php
48        }
49        ##/WLREMOVE
50    }
51
52    /*
53    * Outputs html which shows 'you are viewing this as an admin' dialog on portal pages
54    */
55    function portal_viewing_as_admin_banner( $admin_message = '' ) {
56
57        global $zbs;
58
59        ?>
60        <div class="jpcrm-client-portal-admin-banner">
61
62            <div class="alert alert-info">
63                <strong><?php esc_html_e( 'You are viewing the Client Portal as an admin.', 'zero-bs-crm' ); ?></strong>
64
65                <?php if ( ! empty( $admin_message ) ) { ?>
66                    <p class="admin-message"><?php echo esc_html( $admin_message ); ?></p>
67                <?php } ?>
68                <?php ##WLREMOVE ?>
69                <p>
70                    <a href="<?php echo esc_url( $zbs->urls['kbclientportal'] ); ?>" target="_blank"><?php esc_html_e( 'Learn more about the Client Portal', 'zero-bs-crm' ); ?></a>
71                </p>
72                <?php ##/WLREMOVE ?>
73
74            </div>
75
76            <?php $this->admin_message(); ?>
77
78
79        </div>
80        <?php
81    }
82
83    // upsell shown to admins across whole portal as they view as admin
84    function admin_message() {
85
86        global $zbs;
87
88        // temp fix
89        if ( current_user_can( 'admin_zerobs_manage_options' ) && ! function_exists( 'zeroBSCRM_cpp_register_endpoints' ) ) {// !zeroBSCRM_isExtensionInstalled('clientportalpro')){
90
91            ##WLREMOVE
92            ?>
93
94        <script type="text/javascript">
95            jQuery(function(){
96                jQuery('#zbs-close-cpp-note').on( 'click', function(){
97                    jQuery('.zbs-client-portal-pro-note').remove();
98                });
99            });
100        </script>
101            <?php
102            ##/WLREMOVE
103
104        }
105
106        return '';
107    }
108
109    function portal_nav( $selected_item = 'dashboard', $do_echo = true ) {
110        global $wp_query;
111
112        $nav_html        = '';
113        $zbsWarn         = '';
114        $dash_link       = zeroBS_portal_link( 'dash' );
115        $portal_root_url = \jpcrm_get_client_portal_root_url();
116        $nav_html       .= '    <ul id="zbs-nav-tabs">';
117
118        foreach ( $this->parent_portal->endpoints as $endpoint ) {
119            if ( $endpoint->hide_from_menu ) {
120                continue;
121            }
122            $link  = $endpoint->slug == 'dashboard' ? esc_url( $portal_root_url ) : esc_url( $portal_root_url . $endpoint->slug );
123            $class = $endpoint->slug == $selected_item ? 'active' : '';
124            // produce the menu from the array of menu items (easier to extend :-) ).
125            // WH: this assumes icon, otehrwise it'll break! :o
126            $nav_html .= "<li class='" . $class . "'><a href='" . $link . "'><i class='fa " . $endpoint->icon . "'></i>" . $endpoint->name . '</a></li>';
127        }
128
129        $zbs_logout_text = __( 'Log out', 'zero-bs-crm' );
130        $zbs_logout_text = apply_filters( 'zbs_portal_logout_text', $zbs_logout_text );
131
132        $zbs_logout_icon = 'fa-sign-out';
133        $zbs_logout_icon = apply_filters( 'zbs_portal_logout_icon', $zbs_logout_icon );
134
135        $nav_html .= "<li><a href='" . wp_logout_url( $dash_link ) . "'><i class='fa " . $zbs_logout_icon . "' aria-hidden='true'></i>" . $zbs_logout_text . '</a></li>';
136        $nav_html .= '</ul>';
137
138        // echo or return nav HTML depending on flag; defaults to echo (legacy support)
139        if ( $do_echo ) {
140            echo $nav_html;
141        } else {
142            return $nav_html;
143        }
144    }
145}