| 1 |
<?php |
| 2 |
/** |
| 3 |
* Template show list addons of LearnPress |
| 4 |
* |
| 5 |
* @version 1.0.0 |
| 6 |
* @since 4.2.1 |
| 7 |
*/ |
| 8 |
|
| 9 |
use LearnPress\Helpers\Template; |
| 10 |
|
| 11 |
defined( 'ABSPATH' ) || exit(); |
| 12 |
|
| 13 |
if ( ! isset( $addons ) ) { |
| 14 |
return; |
| 15 |
} |
| 16 |
|
| 17 |
include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 18 |
|
| 19 |
$total_addon_free = 0; |
| 20 |
$total_addon_paid = 0; |
| 21 |
$total_addon_installed = 0; |
| 22 |
$total_addon_not_installed = 0; |
| 23 |
$total_addon_activated = 0; |
| 24 |
$total_addon_update = 0; |
| 25 |
$plugins_installed = get_plugins(); |
| 26 |
$plugins_activated = get_option( 'active_plugins', '' ); |
| 27 |
$active_tab = ! empty( $_REQUEST['tab'] ) ? $_REQUEST['tab'] : 'all'; |
| 28 |
$keys_purchase = LP_Settings::get_option( LP_Manager_Addons::instance()->key_purchase_addons, [] ); |
| 29 |
?> |
| 30 |
<div class="lp-addons-wrapper"> |
| 31 |
<div id="lp-addons"> |
| 32 |
<?php |
| 33 |
foreach ( $addons as $slug => $addon ) : |
| 34 |
$addon->slug = $slug; |
| 35 |
$is_installed = false; |
| 36 |
$is_activated = false; |
| 37 |
$is_updated = false; |
| 38 |
$is_free = $addon->is_free; |
| 39 |
$addon_base = $addon->basename; |
| 40 |
$version_latest = $addon->version; |
| 41 |
$version_current = 0; |
| 42 |
$classes_status = []; |
| 43 |
// Addon is free or paid. |
| 44 |
if ( 1 == $addon->is_free ) { |
| 45 |
$total_addon_free ++; |
| 46 |
} else { |
| 47 |
$total_addon_paid ++; |
| 48 |
} |
| 49 |
// Addon is installed |
| 50 |
if ( isset( $plugins_installed[ $addon_base ] ) ) { |
| 51 |
$is_installed = true; |
| 52 |
$classes_status[] = 'installed'; |
| 53 |
$version_current = $plugins_installed[ $addon_base ]['Version']; |
| 54 |
$total_addon_installed ++; |
| 55 |
} else { |
| 56 |
$classes_status[] = 'not_installed'; |
| 57 |
$total_addon_not_installed ++; |
| 58 |
} |
| 59 |
// Addon is activated |
| 60 |
if ( in_array( $addon_base, $plugins_activated ) ) { |
| 61 |
$is_activated = true; |
| 62 |
$classes_status[] = 'activated'; |
| 63 |
$total_addon_activated ++; |
| 64 |
} |
| 65 |
// Addon is has update |
| 66 |
if ( $is_installed && version_compare( $version_current, $version_latest, '<' ) ) { |
| 67 |
$total_addon_update ++; |
| 68 |
$classes_status[] = 'update'; |
| 69 |
$is_updated = true; |
| 70 |
} |
| 71 |
// Addon is paid on Thimpress |
| 72 |
if ( ! $is_free ) { |
| 73 |
$classes_status[] = 'purchase'; |
| 74 |
$purchase_code = $keys_purchase[ $addon->slug ] ?? ''; |
| 75 |
} else { // Addon is free |
| 76 |
$classes_status[] = 'free'; |
| 77 |
} |
| 78 |
// Show addons of tab. |
| 79 |
if ( ! in_array( $active_tab, $classes_status ) && $active_tab != 'all' ) { |
| 80 |
$classes_status[] = 'hide'; |
| 81 |
} |
| 82 |
?> |
| 83 |
<div class="lp-addon-item <?php echo implode( ' ', $classes_status ); ?>" |
| 84 |
data-slug="<?php echo $slug; ?>"> |
| 85 |
<div class="lp-addon-item__content"> |
| 86 |
<img src="<?php echo $addon->image; ?>" alt="<?php echo $addon->name; ?>"/> |
| 87 |
<h3> |
| 88 |
<a href="<?php echo $addon->link; ?>" target="_blank" rel="noopener"> |
| 89 |
<?php echo $addon->name; ?> |
| 90 |
</a> |
| 91 |
</h3> |
| 92 |
<h4> |
| 93 |
<?php |
| 94 |
if ( $version_current ) { |
| 95 |
echo "Version <span class='addon-version-current'>$version_current</span>"; |
| 96 |
} else { |
| 97 |
echo "Version $version_latest"; |
| 98 |
} |
| 99 |
|
| 100 |
if ( isset( $addon->link_doc ) && ! empty( $addon->link_doc ) ) { |
| 101 |
echo " | <a href='{$addon->link_doc}' target='_blank' rel='noopener'>Documentation</a>"; |
| 102 |
} |
| 103 |
?> |
| 104 |
</h4> |
| 105 |
<?php |
| 106 |
echo sprintf( |
| 107 |
'<p>%s on %s</p>', |
| 108 |
$addon->is_free ? __( 'Free', 'learnpress' ) : __( 'Paid', 'learnpress' ), |
| 109 |
$addon->is_org ? __( 'WP.org', 'learnpress' ) : __( 'Thimpress', 'learnpress' ) |
| 110 |
); |
| 111 |
?> |
| 112 |
<?php |
| 113 |
if ( ! $is_free && $is_installed && empty( $purchase_code ) ) { |
| 114 |
echo '<p style="color: red; display: none">Empty key purchase</p>'; |
| 115 |
} |
| 116 |
?> |
| 117 |
<p title="<?php echo $addon->description; ?>"><?php echo $addon->description; ?></p> |
| 118 |
</div> |
| 119 |
<div class="lp-addon-item__actions"> |
| 120 |
<div class="lp-addon-item__actions__left"> |
| 121 |
<?php |
| 122 |
if ( isset( $addon->setting ) && ! empty( $addon->setting ) ) { |
| 123 |
?> |
| 124 |
<a href="<?php echo site_url( $addon->setting ); ?>" target="_blank" rel="noopener"> |
| 125 |
<button data-action="setting"><?php _e( 'Settings', 'learnpress' ); ?></button> |
| 126 |
</a> |
| 127 |
<?php |
| 128 |
} |
| 129 |
?> |
| 130 |
<button class="btn-addon-action" data-action="update" |
| 131 |
title="<?php echo sprintf( '%s %s require LP version %s', $addon->name, $version_latest, $addon->require_lp ); ?>"> |
| 132 |
<span class="dashicons dashicons-update"></span><span class="text">Update</span> |
| 133 |
</button> |
| 134 |
<button class="btn-addon-action" data-action="update-purchase-code" |
| 135 |
title="<?php _e( 'Change Purchase Code', 'learnpress' ); ?>"> |
| 136 |
<span class="dashicons dashicons-ellipsis"></span> |
| 137 |
</button> |
| 138 |
<button class="btn-addon-action" data-action="install" |
| 139 |
<?php echo $is_free && ! $addon->is_org ? 'data-link="' . $addon->link . '"' : ''; ?> |
| 140 |
> |
| 141 |
<span class="dashicons dashicons-update"></span><span class="text"><?php _e( 'Install', 'learnpress' ); ?></span> |
| 142 |
</button> |
| 143 |
<button class="btn-addon-action" data-action="purchase"><?php _e( 'Install', 'learnpress' ); ?></button> |
| 144 |
</div> |
| 145 |
<div class="lp-addon-item__actions__right"> |
| 146 |
<button class="btn-addon-action" data-action="deactivate"> |
| 147 |
<span class="dashicons dashicons-update"></span><span class="text"><?php _e( 'Deactivate', 'learnpress' ); ?></span> |
| 148 |
</button> |
| 149 |
<button class="btn-addon-action" data-action="activate"> |
| 150 |
<span class="dashicons dashicons-update"></span><span class="text"><?php _e( 'Activate', 'learnpress' ); ?></span> |
| 151 |
</button> |
| 152 |
</div> |
| 153 |
</div> |
| 154 |
<div class="lp-addon-item__purchase"> |
| 155 |
<div class="lp-addon-item__purchase__wrapper"> |
| 156 |
<div class="purchase-install"> |
| 157 |
<label> |
| 158 |
<input type="text" class="enter-purchase-code" placeholder="Enter Purchase Code" |
| 159 |
value="<?php echo $purchase_code ?? ''; ?>"> |
| 160 |
</label> |
| 161 |
<button class="btn-addon-action" data-action="install"> |
| 162 |
<span class="dashicons dashicons-update"></span><span class="text"><?php _e( 'Submit', 'learnpress' ); ?></span> |
| 163 |
</button> |
| 164 |
OR |
| 165 |
<button class="btn-addon-action" data-action="buy" data-link="<?php echo $addon->link; ?>">Buy |
| 166 |
Now |
| 167 |
</button> |
| 168 |
<button class="btn-addon-action" data-action="cancel"><?php _e( 'Cancel', 'learnpress' ); ?></button> |
| 169 |
</div> |
| 170 |
<div class="purchase-update"> |
| 171 |
<label> |
| 172 |
<input type="text" class="enter-purchase-code" placeholder="Enter Purchase Code" |
| 173 |
value="<?php echo $purchase_code ?? ''; ?>"> |
| 174 |
</label> |
| 175 |
<button class="btn-addon-action" data-action="update-purchase"> |
| 176 |
<span class="dashicons dashicons-update"></span><span class="text"><?php _e( 'Update', 'learnpress' ); ?></span> |
| 177 |
</button> |
| 178 |
<button class="btn-addon-action" data-action="cancel"><?php _e( 'Cancel', 'learnpress' ); ?></button> |
| 179 |
</div> |
| 180 |
<input type="hidden" name="purchase-code" |
| 181 |
value="<?php echo $purchase_code ?? ''; ?>"> |
| 182 |
</div> |
| 183 |
</div> |
| 184 |
</div> |
| 185 |
<?php |
| 186 |
endforeach; |
| 187 |
?> |
| 188 |
</div> |
| 189 |
<div class="lp-nav-tab-wrapper" style="display: none"> |
| 190 |
<?php |
| 191 |
$tabs = array( |
| 192 |
'all' => sprintf( '%s (<span>%d</span>)', __( 'All', 'learnpress' ), count( (array) $addons ) ), |
| 193 |
'installed' => sprintf( '%s (<span>%d</span>)', __( 'Installed', 'learnpress' ), $total_addon_installed ), |
| 194 |
'purchase' => sprintf( '%s (<span>%d</span>)', __( 'Paid', 'learnpress' ), $total_addon_paid ), |
| 195 |
'free' => sprintf( '%s (<span>%d</span>)', __( 'Free', 'learnpress' ), $total_addon_free ), |
| 196 |
'update' => sprintf( '%s (<span>%d</span>)', __( 'Update', 'learnpress' ), $total_addon_update ), |
| 197 |
'not_installed' => sprintf( '%s (<span>%d</span>)', __( 'Not Installed', 'learnpress' ), $total_addon_not_installed ), |
| 198 |
); |
| 199 |
foreach ( $tabs as $tab => $name ) { |
| 200 |
?> |
| 201 |
<?php |
| 202 |
|
| 203 |
$active_class = ( $tab == $active_tab ) ? ' nav-tab-active' : ''; |
| 204 |
$tab_title = apply_filters( 'learn-press/admin/submenu-heading-tab-title', $name, $tab ); |
| 205 |
?> |
| 206 |
|
| 207 |
<?php if ( $active_class ) { ?> |
| 208 |
<a class="nav-tab<?php echo esc_attr( $active_class ); ?>" |
| 209 |
data-tab="<?php echo esc_attr( $tab ); ?>" href="#"> |
| 210 |
<?php echo wp_kses_post( $tab_title ); ?> |
| 211 |
</a> |
| 212 |
<?php } else { ?> |
| 213 |
<a class="nav-tab" |
| 214 |
data-tab="<?php echo esc_attr( $tab ); ?>" |
| 215 |
href="?page=learn-press-addons&tab=<?php echo esc_attr( $tab ); ?>"> |
| 216 |
<?php echo wp_kses_post( $tab_title ); ?> |
| 217 |
</a> |
| 218 |
<?php } ?> |
| 219 |
<?php } ?> |
| 220 |
<div class="lp-search-addons"> |
| 221 |
<label> |
| 222 |
<input id="lp-search-addons__input" type="text" placeholder="Search name addon" /> |
| 223 |
</label> |
| 224 |
</div> |
| 225 |
</div> |
| 226 |
</div> |
| 227 |
|