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