| 1 |
<?php |
| 2 |
/* |
| 3 |
* License: GPLv3 |
| 4 |
* License URI: https://www.gnu.org/licenses/gpl.txt |
| 5 |
* Copyright 2012-2026 Jean-Sebastien Morisset (https://wpsso.com/) |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
|
| 10 |
die( 'These aren\'t the droids you\'re looking for.' ); |
| 11 |
} |
| 12 |
|
| 13 |
if ( ! class_exists( 'WpssoSubmenuLicenses' ) && class_exists( 'WpssoAdmin' ) ) { |
| 14 |
|
| 15 |
/* |
| 16 |
* Please note that this settings page also requires enqueuing special scripts and styles for the plugin details / install |
| 17 |
* thickbox link. See the WpssoScript and WpssoStyle classes for more info. |
| 18 |
*/ |
| 19 |
class WpssoSubmenuLicenses extends WpssoAdmin { |
| 20 |
|
| 21 |
public function __construct( &$plugin, $id, $name, $lib, $ext ) { |
| 22 |
|
| 23 |
$this->p =& $plugin; |
| 24 |
|
| 25 |
if ( $this->p->debug->enabled ) { |
| 26 |
|
| 27 |
$this->p->debug->mark(); |
| 28 |
} |
| 29 |
|
| 30 |
$this->menu_id = $id; |
| 31 |
$this->menu_name = $name; |
| 32 |
$this->menu_lib = $lib; |
| 33 |
$this->menu_ext = $ext; |
| 34 |
|
| 35 |
$this->menu_metaboxes = array( |
| 36 |
'licenses' => _x( 'Plugin and Add-on Licenses', 'metabox title', 'wpsso' ), |
| 37 |
); |
| 38 |
} |
| 39 |
|
| 40 |
/* |
| 41 |
* Remove the "Change to View" button from this settings page. |
| 42 |
*/ |
| 43 |
protected function add_form_buttons_change_show_options( &$form_button_rows ) { |
| 44 |
} |
| 45 |
|
| 46 |
/* |
| 47 |
* Callback method must be public for add_meta_box() hook. |
| 48 |
* |
| 49 |
* See WpssoAdmin->add_settings_page_metaboxes(). |
| 50 |
*/ |
| 51 |
public function show_metabox_licenses( $obj, $mb ) { |
| 52 |
|
| 53 |
if ( $this->p->debug->enabled ) { |
| 54 |
|
| 55 |
$this->p->debug->mark(); |
| 56 |
} |
| 57 |
|
| 58 |
$args = isset( $mb[ 'args' ] ) ? $mb[ 'args' ] : array(); |
| 59 |
$network = isset( $args[ 'network' ] ) ? $args[ 'network' ] : false; |
| 60 |
|
| 61 |
$ext_sorted = WpssoConfig::get_ext_sorted(); |
| 62 |
|
| 63 |
foreach ( $ext_sorted as $ext => $info ) { |
| 64 |
|
| 65 |
if ( empty( $info[ 'update_auth' ] ) ) { // Only show plugins with Premium packages. |
| 66 |
|
| 67 |
unset( $ext_sorted[ $ext ] ); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
$tabindex = 0; |
| 72 |
$ext_num = 0; |
| 73 |
$ext_total = count( $ext_sorted ); |
| 74 |
$pkg_info = $this->p->util->get_pkg_info(); // Uses a local cache. |
| 75 |
$charset = get_bloginfo( $show = 'charset', $filter = 'raw' ); |
| 76 |
$icon_px = 100; |
| 77 |
|
| 78 |
echo '<table class="sucom-settings wpsso licenses-metabox" style="padding-bottom:10px">' . "\n"; |
| 79 |
echo '<tr><td colspan="3">' . $this->p->msgs->get( 'info-plugin-tid' . ( $network ? '-network' : '' ) ) . '</td></tr>' . "\n"; |
| 80 |
|
| 81 |
foreach ( $ext_sorted as $ext => $info ) { |
| 82 |
|
| 83 |
$ext_num++; |
| 84 |
|
| 85 |
$ext_links = $this->get_ext_action_links( $ext, $info, $tabindex ); |
| 86 |
$ext_name_html = '<h4>' . htmlentities( $pkg_info[ $ext ][ 'name_pro' ], ENT_QUOTES, $charset, $double_encode = false ) . '</h4>'; |
| 87 |
$placeholder = strtoupper( $ext . '-PP-0000000000000000' ); |
| 88 |
$blog_id = get_current_blog_id(); |
| 89 |
$home_url = SucomUtilWP::raw_get_home_url(); |
| 90 |
$home_path = preg_replace( '/^[a-z]+:\/\//i', '', $home_url ); // Remove the protocol prefix. |
| 91 |
$table_rows = array(); |
| 92 |
|
| 93 |
$admin_url = is_multisite() ? network_admin_url( 'site-settings.php?id=' . $blog_id ) : get_admin_url( $blog_id, 'options-general.php' ); |
| 94 |
$edit_link = '(<a href="' . $admin_url . '">' . __( 'Edit', 'wpsso' ) . '</a>)'; |
| 95 |
|
| 96 |
/* |
| 97 |
* Plugin name, description, and action links. |
| 98 |
*/ |
| 99 |
$table_rows[ 'plugin_name' ] = '<td colspan="2" class="ext-info-plugin-name" id="ext-info-plugin-name-' . $ext . '">' . |
| 100 |
'<a class="ext-anchor" id="' . $ext . '"></a>' . $ext_name_html . |
| 101 |
( empty( $ext_links ) ? '' : '<div class="row-actions visible">' . implode( $glue = ' | ', $ext_links ) . '</div>' ) . |
| 102 |
'</td>'; |
| 103 |
|
| 104 |
/* |
| 105 |
* Authentication ID. |
| 106 |
*/ |
| 107 |
$table_rows[ 'plugin_tid' ] = '' . |
| 108 |
$this->form->get_th_html( sprintf( _x( '%s Authentication ID', 'option label', 'wpsso' ), $info[ 'short' ] ), 'medium nowrap' ) . |
| 109 |
'<td width="100%">' . $this->form->get_input( 'plugin_' . $ext . '_tid', $css_class = 'tid mono', $css_id = '', $len = 0, |
| 110 |
$placeholder, $is_disabled = false, ++$tabindex ) . '</td>'; |
| 111 |
|
| 112 |
$table_rows[ 'site_use' ] = self::get_option_site_use( 'plugin_' . $ext . '_tid', $this->form, $network ); |
| 113 |
|
| 114 |
/* |
| 115 |
* License information. |
| 116 |
*/ |
| 117 |
$table_rows[ 'home_url' ] = '' . |
| 118 |
'<th class="medium nowrap">' . _x( 'Current Site Address', 'option label', 'wpsso' ) . '</th>' . |
| 119 |
'<td class="text"><p>' . $home_path . ' ' . $edit_link . '</p></td>'; |
| 120 |
|
| 121 |
if ( ! empty( $this->p->options[ 'plugin_' . $ext . '_tid' ] ) && class_exists( 'SucomUpdate' ) ) { |
| 122 |
|
| 123 |
$show_update_opts = array( |
| 124 |
'exp_date' => _x( 'Support and Updates Expire', 'option label', 'wpsso' ), |
| 125 |
'qty_used' => _x( 'License Information', 'option label', 'wpsso' ), |
| 126 |
); |
| 127 |
|
| 128 |
foreach ( $show_update_opts as $key => $label ) { |
| 129 |
|
| 130 |
$val = SucomUpdate::get_option( $ext, $key ); |
| 131 |
|
| 132 |
if ( empty( $val ) ) { // Add an empty row for empty values. |
| 133 |
|
| 134 |
$val = _x( 'Not available', 'option value', 'wpsso' ); |
| 135 |
|
| 136 |
} elseif ( 'exp_date' === $key ) { |
| 137 |
|
| 138 |
if ( '0000-00-00 00:00:00' === $val ) { |
| 139 |
|
| 140 |
$val = _x( 'Never (Nontransferable Lifetime License)', 'option value', 'wpsso' ); |
| 141 |
} |
| 142 |
|
| 143 |
} elseif ( 'qty_used' === $key ) { |
| 144 |
|
| 145 |
$qty_reg = SucomUpdate::get_option( $ext, 'qty_reg' ); |
| 146 |
$qty_total = SucomUpdate::get_option( $ext, 'qty_total' ); |
| 147 |
|
| 148 |
if ( null !== $qty_reg && null !== $qty_total ) { // Just in case. |
| 149 |
|
| 150 |
$val = sprintf( __( '%d of %d site addresses registered', 'wpsso' ), $qty_reg, $qty_total ); |
| 151 |
|
| 152 |
} else $val = sprintf( __( '%s site addresses registered', 'wpsso' ), $val ); |
| 153 |
|
| 154 |
if ( ! empty( $info[ 'url' ][ 'info' ] ) ) { |
| 155 |
|
| 156 |
$info_url = add_query_arg( array( |
| 157 |
'tid' => $this->p->options[ 'plugin_' . $ext . '_tid' ], |
| 158 |
'user_direction' => is_rtl() ? 'rtl' : 'ltr', |
| 159 |
'user_locale' => SucomUtilWP::get_locale(), |
| 160 |
'TB_iframe' => 'true', |
| 161 |
'width' => $this->p->cf[ 'wp' ][ 'tb_iframe' ][ 'width' ], |
| 162 |
'height' => $this->p->cf[ 'wp' ][ 'tb_iframe' ][ 'height' ], |
| 163 |
), $info[ 'url' ][ 'purchase' ] . 'info/' ); |
| 164 |
|
| 165 |
$val = '<a href="' . $info_url . '" class="thickbox">' . $val . '</a>'; |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
$table_rows[ $key ] = '<th class="medium nowrap">' . $label . '</th><td class="text"><p>' . $val . '</p></td>'; |
| 170 |
} |
| 171 |
|
| 172 |
} else $table_rows[] = '<th class="medium nowrap"> </th><td width="100%"> </td>'; |
| 173 |
|
| 174 |
/* |
| 175 |
* Plugin separator. |
| 176 |
*/ |
| 177 |
if ( $ext_num < $ext_total ) { |
| 178 |
|
| 179 |
$table_rows[ 'dotted_line' ] = '<td colspan="2" class="ext-info-plugin-separator"></td>'; |
| 180 |
|
| 181 |
} else $table_rows[] = '<td></td>'; |
| 182 |
|
| 183 |
/* |
| 184 |
* Show the plugin icon and table rows. |
| 185 |
*/ |
| 186 |
foreach ( $table_rows as $key => $row ) { |
| 187 |
|
| 188 |
if ( ! empty( $row ) ) { |
| 189 |
|
| 190 |
echo '<tr>'; |
| 191 |
|
| 192 |
if ( $key === 'plugin_name' ) { |
| 193 |
|
| 194 |
$span_rows = count( $table_rows ); |
| 195 |
$icon_col_px = $icon_px + 30; |
| 196 |
$icon_style = 'width:' . $icon_col_px . 'px; min-width:' . $icon_col_px . 'px; max-width:' . $icon_col_px . 'px;'; |
| 197 |
|
| 198 |
echo '<td class="ext-info-plugin-icon" id="ext-info-plugin-icon-' . $ext . '" ' . |
| 199 |
'rowspan="' . $span_rows . '" style="' . $icon_style . '" >'; |
| 200 |
|
| 201 |
echo $this->get_ext_img_icon( $ext, $icon_px ); |
| 202 |
|
| 203 |
echo '</td>'; |
| 204 |
} |
| 205 |
|
| 206 |
echo $row . '</tr>' . "\n"; |
| 207 |
} |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
echo '</table>' . "\n"; |
| 212 |
} |
| 213 |
} |
| 214 |
} |
| 215 |
|