function list_bsf_products_updates() { $brainstrom_products = get_option('brainstrom_products') ? get_option('brainstrom_products') : array(); $brainstrom_bundled_products = get_option('brainstrom_bundled_products') ? get_option('brainstrom_bundled_products') : array(); $mix_products = $update_ready = $bsf_product_plugins = $bsf_product_themes = $temp_bundled = array(); if (!empty($brainstrom_products)) { $bsf_product_plugins = isset($brainstrom_products['plugins']) ? $brainstrom_products['plugins'] : array(); $bsf_product_themes = isset($brainstrom_products['themes']) ? $brainstrom_products['themes'] : array(); } $mix_products = array_merge($bsf_product_plugins, $bsf_product_themes); foreach ($mix_products as $product) { $is_bundled = false; if (!isset($product['id'])) { continue; } $id = $product['id']; $bundled_key = array(); $bundled_wrapper = array(); if (!empty($brainstrom_bundled_products)) { foreach ($brainstrom_bundled_products as $bkeys => $bps) { if (strlen($bkeys) > 1) { foreach ($bps as $bkey => $bp) { /*echo '<pre>'; print_r($bp); echo '</pre>['.$bp->id.' '.$id.']';*/ if (!isset($bp->id) || $bp->id == '') { continue; } if ($id === $bp->id) { $is_bundled = true; $bprd = $brainstrom_bundled_products[$bkeys]; $version = isset($bprd[$bkey]->version) ? $bprd[$bkey]->version : ''; $remote = isset($bprd[$bkey]->remote) ? $bprd[$bkey]->remote : ''; $template = isset($bprd[$bkey]->init) ? $bprd[$bkey]->init : ''; $type = isset($bprd[$bkey]->type) ? $bprd[$bkey]->type : ''; $bundled_key = $bkey; if (version_compare($remote, $version, '>')) { $temp = (array) $bprd[$bundled_key]; $temp['bundled'] = true; array_push($temp_bundled, $temp['id']); array_push($update_ready, $temp); } break; } } } else { if (!isset($bps->id) || $bps->id == '') { continue; } if ($id === $bps->id) { $is_bundled = true; $bundled_key = $bkeys; break; } } } } if ($is_bundled) { //echo '['.$bundled_key.']'; // $version = (isset($brainstrom_bundled_products[$bundled_key]->version)) ? $brainstrom_bundled_products[$bundled_key]->version : ''; // $remote = (isset($brainstrom_bundled_products[$bundled_key]->remote)) ? $brainstrom_bundled_products[$bundled_key]->remote : ''; // $template = (isset($brainstrom_bundled_products[$bundled_key]->init)) ? $brainstrom_bundled_products[$bundled_key]->init : ''; // $type = (isset($brainstrom_bundled_products[$bundled_key]->type)) ? $brainstrom_bundled_products[$bundled_key]->type : 'plugin'; } else { $version = isset($product['version']) ? $product['version'] : ''; $remote = isset($product['remote']) ? $product['remote'] : ''; $template = isset($product['template']) ? $product['template'] : ''; $type = isset($product['type']) ? $product['type'] : ''; } if ($type === 'theme') { $product_abs_path = WP_CONTENT_DIR . '/themes/' . $template; if (!is_dir($product_abs_path)) { continue; } } else { $product_abs_path = WP_PLUGIN_DIR . '/' . $template; if (!is_file($product_abs_path)) { continue; } } if (version_compare($remote, $version, '>')) { if ($is_bundled) { // $temp = (array)$brainstrom_bundled_products[$bundled_key]; // $temp['bundled'] = true; // array_push($temp_bundled, $temp['id']); // array_push($update_ready, $temp); } else { $product['bundled'] = false; array_push($update_ready, $product); } } } /*echo '<pre>'; print_r($brainstrom_bundled_products); echo '</pre>';*/ foreach ($brainstrom_bundled_products as $bkeys => $bps) { if (strlen($bkeys) > 1) { foreach ($bps as $bkey => $bp) { if (!isset($bp->id) || $bp->id == '') { continue; } $plugin_abs_path = WP_PLUGIN_DIR . '/' . $bp->init; if (!is_file($plugin_abs_path)) { continue; } if (!isset($bp->remote)) { continue; } $temp = array(); if (!in_array($bp->id, $temp_bundled)) { if (version_compare($bp->remote, $bp->version, '>')) { $is_wp = isset($bp->in_house) && $bp->in_house === 'wp' ? true : false; if ($is_wp) { break; } $temp = (array) $bp; $temp['bundled'] = true; array_push($update_ready, $temp); } } } } else { if (!isset($bps->id) || $bps->id == '') { continue; } $plugin_abs_path = WP_PLUGIN_DIR . '/' . $bps->init; if (!is_file($plugin_abs_path)) { continue; } if (!isset($bps->remote)) { continue; } $temp = array(); if (!in_array($bps->id, $temp_bundled)) { if (version_compare($bps->remote, $bps->version, '>')) { $is_wp = isset($bps->in_house) && $bps->in_house === 'wp' ? true : false; if ($is_wp) { break; } $temp = (array) $bps; $temp['bundled'] = true; array_push($update_ready, $temp); } } } } $update_ready = bsf_array_unique($update_ready); echo '<h3 id="brainstormforce-products">Brainstorm Force - ' . __('Products', 'bsf') . '</h3>'; if (!empty($update_ready)) { echo '<p>' . __('The following plugins from Brainstorm Force have new versions available.', 'bsf') . '</p>'; ?> <table class="widefat" cellspacing="0" id="update-plugins-table"> <thead> <tr> <th scope="col" class="manage-column"><label><?php _e('Name', 'bsf'); ?> </label></th> <th scope="col" class="manage-column"><label><?php _e('Installed Version', 'bsf'); ?> </label></th> <th scope="col" class="manage-column"><label><?php _e('Latest Version', 'bsf'); ?> </label></th> <th scope="col" class="manage-column"><label><?php _e('Actions', 'bsf'); ?> </label></th> </tr> </thead> <tfoot> <tr> <th scope="col" class="manage-column"><label><?php _e('Name', 'bsf'); ?> </label></th> <th scope="col" class="manage-column"><label><?php _e('Installed Version', 'bsf'); ?> </label></th> <th scope="col" class="manage-column"><label><?php _e('Latest Version', 'bsf'); ?> </label></th> <th scope="col" class="manage-column"><label><?php _e('Actions', 'bsf'); ?> </label></th> </tr> </tfoot> <tbody class="plugins"> <?php foreach ($update_ready as $key => $product) { $is_bundled = $product['bundled']; if ($is_bundled) { if (!isset($product['init'])) { continue; } if (trim($product['init']) === '' || $product['init'] === false) { continue; } } else { if (!isset($product['template'])) { continue; } if (trim($product['template']) === '' || $product['template'] === false) { continue; } } $upgradeLink = get_bsf_product_upgrade_link($product); ?> <tr class='active' id="bsf-row-<?php echo $key; ?> "> <td class='plugin-title'><strong><?php echo $product['bundled'] ? $product['name'] : $product['product_name']; ?> </strong> <span><?php _e('You have version ' . $product['version'] . ' installed. Update to ' . $product['remote'], 'bsf'); ?> </span></td> <td style='vertical-align:middle'><strong><?php echo __($product['version'], 'bsf'); ?> </strong></td> <td style='vertical-align:middle'><strong><?php echo __($product['remote'], 'bsf'); ?> </strong></td> <td style='vertical-align:middle'><?php echo $upgradeLink; ?> </td> </tr> <?php } ?> </tbody> </table> <?php if (!isset($_GET['noajax'])) { ?> <script type="text/javascript"> (function($){ $(document).ready(function(){ $('tbody.plugins').on('click', '.bsf-update-product-button', function(e) { e.preventDefault(); var $tr = $(this).parents('tr:first'); var product_id = $(this).attr('data-pid'); var bundled_id = $(this).attr('data-bid'); var action = 'bsf_upgrade'; var bundled = $(this).attr('data-bundled'); var is_product_upgraded = false; var $link = $(this).attr('href'); $tr.addClass('bsf-product-updating'); $tr.find('.bsf-update-spinner').addClass('show'); var data = { 'action': action, 'product_id': product_id, 'bundled' : bundled, 'bundled_id' : bundled_id }; // We can also pass the url value separately from ajaxurl for front end AJAX implementations jQuery.post(ajaxurl, data, function(response) { // log response for debugging in client sites. console.log( response ); var is_ftp = false; $tr.find('td:nth-child(4)').find('.error_message').remove(); $tr.find('td:nth-child(4)').find('br').remove(); var productName = $tr.find('td:nth-child(4)').text(); productName = productName.replace('Update ', ''); productName = productName.replace('.', ''); var html = $tr.find('td:nth-child(4)').html(); html = html + '<br><span class="error_message">There was some problem updating <strong>'+ productName +'</strong>, Please try again.</span>'; var plugin_status = response.split('|'); if(/Connection Type/i.test(response)) { is_ftp = true; response = 'FTP protected, redirecting to traditional installer.'; } $.each(plugin_status, function(i,res){ if(res === 'bsf-product-upgraded') { is_product_upgraded = true; } }); if(is_product_upgraded) { $tr.addClass('bsf-product-upgraded').removeClass('active'); var remote_version = $tr.find('td:nth-child(3)').html(); $tr.find('td:nth-child(4)').html('Updated successfully! <i class="dashicons dashicons-yes"></i>'); $tr.find('td:nth-child(2)').html(remote_version); $tr.find('td:nth-child(1)').find('span').remove(); } else { $tr.find('td:nth-child(4)').html(response); setTimeout(function(){ window.location.assign($link); },2000); } if ( response == '' ) { $tr.find('td:nth-child(4)').html(html); $tr.find('td:nth-child(4)').find('span').removeClass('show'); //$tr.find('td:nth-child(4)').append('</br><span>There was some problem updating <strong>'+ val +'</strong>, Please try again.</span>'); } }); }); }); })(jQuery); </script> <?php } ?> <?php } else { echo '<p>' . __('Your plugins from Brainstorm Force are all up to date.', 'bsf') . '</p>'; } }
function list_bsf_products_updates() { $brainstrom_products = get_option('brainstrom_products') ? get_option('brainstrom_products') : array(); $brainstrom_bundled_products = get_option('brainstrom_bundled_products') ? get_option('brainstrom_bundled_products') : array(); $mix_products = $update_ready = $bsf_product_plugins = $bsf_product_themes = $temp_bundled = array(); if (!empty($brainstrom_products)) { $bsf_product_plugins = isset($brainstrom_products['plugins']) ? $brainstrom_products['plugins'] : array(); $bsf_product_themes = isset($brainstrom_products['themes']) ? $brainstrom_products['themes'] : array(); } $mix_products = array_merge($bsf_product_plugins, $bsf_product_themes); foreach ($mix_products as $product) { $is_bundled = false; $id = $product['id']; $bundled_key = ''; if (!empty($brainstrom_bundled_products)) { foreach ($brainstrom_bundled_products as $bkey => $bp) { if ($id === $bp->id) { $is_bundled = true; $bundled_key = $bkey; break; } } } if ($is_bundled) { //echo '['.$bundled_key.']'; $version = isset($brainstrom_bundled_products[$bundled_key]->version) ? $brainstrom_bundled_products[$bundled_key]->version : ''; $remote = isset($brainstrom_bundled_products[$bundled_key]->remote) ? $brainstrom_bundled_products[$bundled_key]->remote : ''; $template = isset($brainstrom_bundled_products[$bundled_key]->init) ? $brainstrom_bundled_products[$bundled_key]->init : ''; $type = isset($brainstrom_bundled_products[$bundled_key]->type) ? $brainstrom_bundled_products[$bundled_key]->type : 'plugin'; } else { $version = isset($product['version']) ? $product['version'] : ''; $remote = isset($product['remote']) ? $product['remote'] : ''; $template = isset($product['template']) ? $product['template'] : ''; $type = isset($product['type']) ? $product['type'] : ''; } if ($type === 'theme') { $product_abs_path = WP_CONTENT_DIR . '/themes/' . $template; if (!is_dir($product_abs_path)) { continue; } } else { $product_abs_path = WP_PLUGIN_DIR . '/' . $template; if (!is_file($product_abs_path)) { continue; } } if (version_compare($remote, $version, '>')) { if ($is_bundled) { $temp = (array) $brainstrom_bundled_products[$bundled_key]; $temp['bundled'] = true; array_push($temp_bundled, $temp['id']); array_push($update_ready, $temp); } else { $product['bundled'] = false; array_push($update_ready, $product); } } } foreach ($brainstrom_bundled_products as $bkey => $bp) { $plugin_abs_path = WP_PLUGIN_DIR . '/' . $bp->init; if (!is_file($plugin_abs_path)) { continue; } if (!isset($bp->remote)) { continue; } $temp = array(); if (!in_array($bp->id, $temp_bundled)) { if (version_compare($bp->remote, $bp->version, '>')) { $temp = (array) $bp; $temp['bundled'] = true; array_push($update_ready, $temp); } } } //die(); echo '<h3 id="brainstormforce-products">Brainstorm Force - ' . __('Products', 'bsf') . '</h3>'; if (!empty($update_ready)) { echo '<p>' . __('The following plugins from Brainstorm Force have new versions available.', 'bsf') . '</p>'; ?> <table class="widefat" cellspacing="0" id="update-plugins-table"> <thead> <tr> <th scope="col" class="manage-column"><label><?php _e('Name', 'bsf'); ?> </label></th> <th scope="col" class="manage-column"><label><?php _e('Installed Version', 'bsf'); ?> </label></th> <th scope="col" class="manage-column"><label><?php _e('Latest Version', 'bsf'); ?> </label></th> <th scope="col" class="manage-column"><label><?php _e('Actions', 'bsf'); ?> </label></th> </tr> </thead> <tfoot> <tr> <th scope="col" class="manage-column"><label><?php _e('Name', 'bsf'); ?> </label></th> <th scope="col" class="manage-column"><label><?php _e('Installed Version', 'bsf'); ?> </label></th> <th scope="col" class="manage-column"><label><?php _e('Latest Version', 'bsf'); ?> </label></th> <th scope="col" class="manage-column"><label><?php _e('Actions', 'bsf'); ?> </label></th> </tr> </tfoot> <tbody class="plugins"> <?php foreach ($update_ready as $key => $product) { $is_bundled = $product['bundled']; if ($is_bundled) { if (!isset($product['init'])) { continue; } if (trim($product['init']) === '' || $product['init'] === false) { continue; } } else { if (!isset($product['template'])) { continue; } if (trim($product['template']) === '' || $product['template'] === false) { continue; } } $upgradeLink = get_bsf_product_upgrade_link($product); ?> <tr class='active' id="bsf-row-<?php echo $key; ?> "> <td class='plugin-title'><strong><?php echo $product['bundled'] ? $product['name'] : $product['product_name']; ?> </strong> <span><?php _e('You have version ' . $product['version'] . ' installed. Update to ' . $product['remote'], 'bsf'); ?> </span></td> <td style='vertical-align:middle'><strong><?php echo __($product['version'], 'bsf'); ?> </strong></td> <td style='vertical-align:middle'><strong><?php echo __($product['remote'], 'bsf'); ?> </strong></td> <td style='vertical-align:middle'><?php echo $upgradeLink; ?> </td> </tr> <?php } ?> </tbody> </table> <?php if (!isset($_GET['noajax'])) { ?> <script type="text/javascript"> (function($){ $(document).ready(function(){ $('.bsf-update-product-button').click(function(e){ e.preventDefault(); var $tr = $(this).parents('tr:first'); var product_id = $(this).attr('data-pid'); var bundled_id = $(this).attr('data-bid'); var action = 'bsf_upgrade'; var bundled = $(this).attr('data-bundled'); var is_product_upgraded = false; $tr.addClass('bsf-product-updating'); $tr.find('.bsf-update-spinner').addClass('show'); var data = { 'action': action, 'product_id': product_id, 'bundled' : bundled, 'bundled_id' : bundled_id }; // We can also pass the url value separately from ajaxurl for front end AJAX implementations jQuery.post(ajaxurl, data, function(response) { var plugin_status = response.split('|'); $.each(plugin_status, function(i,res){ if(res === 'bsf-product-upgraded') { is_product_upgraded = true; } }); if(is_product_upgraded) { $tr.addClass('bsf-product-upgraded').removeClass('active'); var remote_version = $tr.find('td:nth-child(3)').html(); $tr.find('td:nth-child(4)').html('Updated successfully! <i class="dashicons dashicons-yes"></i>'); $tr.find('td:nth-child(2)').html(remote_version); $tr.find('td:nth-child(1)').find('span').remove(); } else { $tr.find('td:nth-child(4)').html(response); } }); }); }); })(jQuery); </script> <?php } ?> <?php } else { echo '<p>' . __('Your plugins from Brainstorm Force are all up to date.', 'bsf') . '</p>'; } }
function list_bsf_products_updates() { $brainstrom_products = get_option('brainstrom_products') ? get_option('brainstrom_products') : array(); $brainstrom_bundled_products = get_option('brainstrom_bundled_products') ? get_option('brainstrom_bundled_products') : array(); $mix_products = $update_ready = $bsf_product_plugins = $bsf_product_themes = $temp_bundled = array(); if (!empty($brainstrom_products)) { $bsf_product_plugins = isset($brainstrom_products['plugins']) ? $brainstrom_products['plugins'] : array(); $bsf_product_themes = isset($brainstrom_products['themes']) ? $brainstrom_products['themes'] : array(); } $mix_products = array_merge($bsf_product_plugins, $bsf_product_themes); foreach ($mix_products as $product) { $is_bundled = false; $id = $product['id']; $bundled_key = ''; if (!empty($brainstrom_bundled_products)) { foreach ($brainstrom_bundled_products as $bkey => $bp) { if ($id === $bp->id) { $is_bundled = true; $bundled_key = $bkey; break; } } } if ($is_bundled) { //echo '['.$bundled_key.']'; $version = isset($brainstrom_bundled_products[$bundled_key]->version) ? $brainstrom_bundled_products[$bundled_key]->version : ''; $remote = isset($brainstrom_bundled_products[$bundled_key]->remote) ? $brainstrom_bundled_products[$bundled_key]->remote : ''; $template = isset($brainstrom_bundled_products[$bundled_key]->init) ? $brainstrom_bundled_products[$bundled_key]->init : ''; $type = isset($brainstrom_bundled_products[$bundled_key]->type) ? $brainstrom_bundled_products[$bundled_key]->type : 'plugin'; } else { $version = isset($product['version']) ? $product['version'] : ''; $remote = isset($product['remote']) ? $product['remote'] : ''; $template = isset($product['template']) ? $product['template'] : ''; $type = isset($product['type']) ? $product['type'] : ''; } if ($type === 'theme') { $product_abs_path = WP_CONTENT_DIR . '/themes/' . $template; if (!is_dir($product_abs_path)) { continue; } } else { $product_abs_path = WP_PLUGIN_DIR . '/' . $template; if (!is_file($product_abs_path)) { continue; } } if (version_compare($remote, $version, '>')) { if ($is_bundled) { $temp = (array) $brainstrom_bundled_products[$bundled_key]; $temp['bundled'] = true; array_push($temp_bundled, $temp['id']); array_push($update_ready, $temp); } else { $product['bundled'] = false; array_push($update_ready, $product); } } } foreach ($brainstrom_bundled_products as $bkey => $bp) { $plugin_abs_path = WP_PLUGIN_DIR . '/' . $bp->init; if (!is_file($plugin_abs_path)) { continue; } if (!isset($bp->remote)) { continue; } $temp = array(); if (!in_array($bp->id, $temp_bundled)) { if (version_compare($bp->remote, $bp->version, '>')) { $temp = (array) $bp; $temp['bundled'] = true; array_push($update_ready, $temp); } } } //die(); echo '<h3 id="brainstormforce-products">Brainstorm Force - ' . __('Products', 'bsf') . '</h3>'; if (!empty($update_ready)) { echo '<p>' . __('The following plugins from Brainstorm Force have new versions available.', 'bsf') . '</p>'; ?> <table class="widefat" cellspacing="0" id="update-plugins-table"> <thead> <tr> <th scope="col" class="manage-column"><label><?php _e('Name', 'bsf'); ?> </label></th> <th scope="col" class="manage-column"><label><?php _e('Installed Version', 'bsf'); ?> </label></th> <th scope="col" class="manage-column"><label><?php _e('Latest Version', 'bsf'); ?> </label></th> <th scope="col" class="manage-column"><label><?php _e('Actions', 'bsf'); ?> </label></th> </tr> </thead> <tfoot> <tr> <th scope="col" class="manage-column"><label><?php _e('Name', 'bsf'); ?> </label></th> <th scope="col" class="manage-column"><label><?php _e('Installed Version', 'bsf'); ?> </label></th> <th scope="col" class="manage-column"><label><?php _e('Latest Version', 'bsf'); ?> </label></th> <th scope="col" class="manage-column"><label><?php _e('Actions', 'bsf'); ?> </label></th> </tr> </tfoot> <tbody class="plugins"> <?php foreach ($update_ready as $product) { $is_bundled = $product['bundled']; if ($is_bundled) { if (!isset($product['init'])) { continue; } if (trim($product['init']) === '' || $product['init'] === false) { continue; } } else { if (!isset($product['template'])) { continue; } if (trim($product['template']) === '' || $product['template'] === false) { continue; } } $upgradeLink = get_bsf_product_upgrade_link($product); ?> <tr class='active'> <td class='plugin-title'><strong><?php echo $product['bundled'] ? $product['name'] : $product['product_name']; ?> </strong><?php _e('You have version ' . $product['version'] . ' installed. Update to ' . $product['remote'], 'bsf'); ?> </td> <td style='vertical-align:middle'><strong><?php echo __($product['version'], 'bsf'); ?> </strong></td> <td style='vertical-align:middle'><strong><?php echo __($product['remote'], 'bsf'); ?> </strong></td> <td style='vertical-align:middle'><?php echo $upgradeLink; ?> </td> </tr> <?php } ?> </tbody> </table> <?php } else { echo '<p>' . __('Your plugins from Brainstorm Force are all up to date.', 'bsf') . '</p>'; } }