Merge pull request #5510 from woothemes/fix-addons-page
Addons page, reference new json API endpoint
This commit is contained in:
commit
e3b71ab3fc
|
@ -22,37 +22,18 @@ class WC_Admin_Addons {
|
|||
*/
|
||||
public function output() {
|
||||
|
||||
$view = isset( $_GET['view'] ) ? sanitize_text_field( $_GET['view'] ) : '';
|
||||
|
||||
if ( false === ( $addons = get_transient( 'woocommerce_addons_html_' . $view ) ) ) {
|
||||
|
||||
$raw_addons = wp_remote_get( 'http://www.woothemes.com/product-category/woocommerce-extensions/' . $view . '?orderby=popularity', array(
|
||||
'user-agent' => 'woocommerce-addons-page',
|
||||
'timeout' => 3
|
||||
) );
|
||||
|
||||
if ( ! is_wp_error( $raw_addons ) ) {
|
||||
|
||||
$raw_addons = wp_remote_retrieve_body( $raw_addons );
|
||||
|
||||
// Get Products
|
||||
$dom = new DOMDocument();
|
||||
libxml_use_internal_errors(true);
|
||||
$dom->loadHTML( $raw_addons );
|
||||
|
||||
$addons = '';
|
||||
$xpath = new DOMXPath( $dom );
|
||||
$tags = $xpath->query('//ul[@class="products"]');
|
||||
foreach ( $tags as $tag ) {
|
||||
$addons = $tag->ownerDocument->saveXML( $tag );
|
||||
break;
|
||||
if ( false === ( $addons = get_transient( 'woocommerce_addons_data' ) ) ) {
|
||||
$addons_json = wp_remote_get( 'http://d3t0oesq8995hv.cloudfront.net/woocommerce-addons.json', array( 'user-agent' => 'WooCommerce Addons Page' ) );
|
||||
if ( ! is_wp_error( $addons_json ) ) {
|
||||
$addons = json_decode( wp_remote_retrieve_body( $addons_json ) );
|
||||
if ( $addons ) {
|
||||
set_transient( 'woocommerce_addons_data', $addons, 60*60*24*7 ); // 1 Week
|
||||
}
|
||||
|
||||
if ( $addons )
|
||||
set_transient( 'woocommerce_addons_html_' . $view, wp_kses_post( $addons ), 60*60*24*7 ); // Cached for a week
|
||||
}
|
||||
}
|
||||
|
||||
$view = isset( $_GET['view'] ) ? sanitize_text_field( $_GET['view'] ) : '';
|
||||
|
||||
include_once( 'views/html-admin-page-addons.php' );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,9 @@
|
|||
'import-export-extensions' => __( 'Import/export', 'woocommerce' ),
|
||||
'product-extensions' => __( 'Products', 'woocommerce' ),
|
||||
'marketing-extensions' => __( 'Marketing', 'woocommerce' ),
|
||||
'free-extensions' => __( 'Free', 'woocommerce' )
|
||||
'accounting-extensions' => __( 'Acounting', 'woocommerce' ),
|
||||
'free-extensions' => __( 'Free', 'woocommerce' ),
|
||||
'third-party-extensions' => __( 'Third-party', 'woocommerce' ),
|
||||
);
|
||||
|
||||
$i = 0;
|
||||
|
@ -27,7 +29,53 @@
|
|||
?>
|
||||
</ul>
|
||||
<br class="clear" />
|
||||
<?php echo $addons; ?>
|
||||
<ul class="products">
|
||||
<?php
|
||||
switch ( $view ) {
|
||||
case '':
|
||||
$addons = $addons->popular;
|
||||
break;
|
||||
case 'payment-gateways':
|
||||
$addons = $addons->{'payment-gateways'};
|
||||
break;
|
||||
case 'shipping-methods':
|
||||
$addons = $addons->{'shipping-methods'};
|
||||
break;
|
||||
case 'import-export-extensions':
|
||||
$addons = $addons->{'import-export'};
|
||||
break;
|
||||
case 'product-extensions':
|
||||
$addons = $addons->product;
|
||||
break;
|
||||
case 'marketing-extensions':
|
||||
$addons = $addons->marketing;
|
||||
break;
|
||||
case 'accounting-extensions':
|
||||
$addons = $addons->accounting;
|
||||
break;
|
||||
case 'free-extensions':
|
||||
$addons = $addons->free;
|
||||
break;
|
||||
case 'third-party-extensions':
|
||||
$addons = $addons->{'third-party'};
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ( $addons as $addon ) {
|
||||
echo '<li class="product">';
|
||||
echo '<a href="' . $addon->link . '">';
|
||||
if ( ! empty( $addon->image ) ) {
|
||||
echo '<img src="' . $addon->image . '"/>';
|
||||
} else {
|
||||
echo '<h3>' . $addon->title . '</h3>';
|
||||
}
|
||||
echo '<span class="price">' . $addon->price . '</span>';
|
||||
echo '<p>' . $addon->excerpt . '</p>';
|
||||
echo '</a>';
|
||||
echo '</li>';
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
<?php else : ?>
|
||||
|
||||
<p><?php printf( __( 'Our catalog of WooCommerce Extensions can be found on WooThemes.com here: <a href="%s">WooCommerce Extensions Catalog</a>', 'woocommerce' ), 'http://www.woothemes.com/product-category/woocommerce-extensions/' ); ?></p>
|
||||
|
|
Loading…
Reference in New Issue