]> _ Git - physioassist-wordpress.git/blob
dcea4c2ccb4e3f0d07a82a0a0172b4e70b72b287
[physioassist-wordpress.git] /
1 <?php
2
3 namespace OTGS\Installer\Templates\Repository;
4
5 class Register {
6
7         public static function render( $model ) {
8                 ?>
9                 <div class="otgs-installer-registered clearfix">
10                         <div class="enter_site_key_wrap_js notice inline otgs-installer-notice otgs-installer-notice-<?php echo $model->repoId; ?>"
11                                  xmlns="http://www.w3.org/1999/html">
12                                 <div class="otgs-installer-notice-content">
13                                         <h2>
14                                                 <?php echo esc_html( sprintf( __( 'Already purchased %s?', 'installer' ), $model->productName ) ); ?>
15                                                 <a class="enter_site_key_js otgs-installer-notice-link-register"
16                                                    href="#"
17                                                         <?php
18                                                         if ( \WP_Installer::get_repository_hardcoded_site_key( $model->repoId ) ): ?>
19                                                                 disabled
20                                                                 title="<?php printf( esc_attr__( "Site-key was set by %s, most likely in wp-config.php. Please remove the constant before attempting to register.", 'installer' ), 'OTGS_INSTALLER_SITE_KEY_' . strtoupper( $model->repoId ) ) ?>"
21                                                         <?php endif; ?>
22                                                 >
23                                                         <?php printf( __( 'Register %s', 'installer' ), $model->productName ); ?>
24                                                 </a>
25                                         </h2>
26                                 </div>
27                         </div>
28                 </div>
29
30                 <form class="otgsi_site_key_form" method="post">
31                         <input type="hidden" name="action" value="save_site_key"/>
32                         <input type="hidden" name="nonce" value="<?php echo $model->saveSiteKeyNonce ?>"/>
33                         <input type="hidden" name="repository_id" value="<?php echo $model->repoId ?>">
34
35                         <?php
36                         $steps = [
37                                 1 => sprintf(
38                                         __( 'Get your site-key for %1$s. If you already have a key, get it from %2$s. Otherwise, %3$s', 'installer' ),
39                                         self::removeScheme( $model->siteUrl ),
40                                         self::getAccountLink( $model ),
41                                         self::getRegisterLink( $model ) ),
42                                 2 => __( 'Insert your key and activate automatic updates:', 'installer' )
43                                      . '<span class="otgs-installer-register-inputs">'
44                                      . '<input type="text" size="20" name="site_key_'
45                                      . $model->repoId
46                                      . '" placeholder="'
47                                      . esc_attr( 'site key' )
48                                      . '" />'
49                                      . '<input class="button-primary" type="submit" value="'
50                                      . esc_attr__( 'OK', 'installer' )
51                                      . '" />'
52                                      . '<input class="button-secondary cancel_site_key_js" type="button" value="'
53                                      . esc_attr__( 'Cancel registration', 'installer' )
54                                      . '" />'
55                                      . '</span>'
56
57                         ];
58
59                         $required_items_count = count( $steps );
60
61                         $filtered_items = apply_filters( 'otgs_installer_repository_registration_steps', $steps, $model->repoId );
62                         if ( ! $filtered_items || ! is_array( $filtered_items ) || $required_items_count < 2 ) {
63                                 $filtered_items = $steps;
64                         }
65
66                         $steps = $filtered_items;
67                         ksort( $steps );
68                         ?>
69                         <ol>
70                                 <?php
71                                 foreach ( $steps as $item ) {
72                                         ?>
73                                         <li>
74                                                 <?php echo $item; ?>
75                                         </li>
76                                         <?php
77                                 }
78                                 ?>
79                         </ol>
80                 </form>
81                 <?php
82         }
83
84         private static function removeScheme( $str ) {
85                 return str_replace( [ 'https://', 'http://' ], '', $str );
86         }
87
88         /**
89          * @param $model
90          *
91          * @return string
92          */
93         private static function getAccountLink( $model ) {
94                 $url = $model->siteKeysManagementUrl . '?add=' . urlencode( $model->siteUrl );
95                 ob_start();
96                 ?>
97                 <a target="_blank" rel="nofollow"
98                    href="<?php echo esc_url( $url ); ?>"><?php esc_html_e( 'your account', 'installer' ); ?></a>
99                 <?php
100                 return trim( ob_get_clean() );
101         }
102
103         /**
104          * @param $model
105          *
106          * @return string
107          */
108         private static function getRegisterLink( $model ) {
109                 $buttonText = sprintf( esc_attr( 'register on %s.', 'installer' ), self::removeScheme( $model->productUrl ) );
110                 ob_start();
111                 ?>
112                 <a target="_blank" rel="nofollow"
113                    href="<?php echo esc_url( $model->productUrl ); ?>"><?php echo $buttonText ?></a>
114                 <?php
115                 return trim( ob_get_clean() );
116         }
117
118 }