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 bsf_update_counter() { $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 = $temp_theme_update_ready = 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); foreach ($mix_products as $product) { $is_bundled = false; if (!isset($product['id']) || empty($product['id'])) { continue; } $id = $product['id']; $constant = strtoupper(str_replace('-', '_', $product['id'])); $constant = 'BSF_' . $constant . '_CHECK_UPDATES'; if (defined($constant) && (constant($constant) === 'false' || constant($constant) === false)) { continue; } $bundled_key = ''; if (!empty($brainstrom_bundled_products)) { foreach ($brainstrom_bundled_products as $bkeys => $bps) { if (strlen($bkeys) > 1) { foreach ($bps as $bkey => $bp) { if (!isset($bp->id) || $bp->id === '') { continue; } if ($id === $bp->id) { $is_bundled = true; if (is_object($brainstrom_bundled_products)) { $brainstrom_bundled_products = (array) $brainstrom_bundled_products; } $bprd = isset($brainstrom_bundled_products[$bkeys]) ? $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 : ''; } else { $version = isset($product['version']) ? $product['version'] : ''; $remote = isset($product['remote']) ? $product['remote'] : ''; $template = isset($product['template']) ? $product['template'] : ''; } $plugin_abs_path = WP_PLUGIN_DIR . '/' . $template; if (!is_file($plugin_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 $bkeys => $bps) { if (strlen($bkeys) > 1) { foreach ($bps as $bkey => $bp) { $plugin_abs_path = WP_PLUGIN_DIR . '/' . $bp->init; if (!is_file($plugin_abs_path)) { continue; } $temp = array(); if (!in_array($bp->id, $temp_bundled)) { if (!isset($bp->remote)) { break; } if (version_compare($bp->remote, $bp->version, '>')) { $temp = (array) $bp; $temp['bundled'] = true; array_push($update_ready, $temp); } } } } else { $plugin_abs_path = WP_PLUGIN_DIR . '/' . $bps->init; if (!is_file($plugin_abs_path)) { continue; } $temp = array(); if (!in_array($bps->id, $temp_bundled)) { if (!isset($bps->remote)) { break; } $is_wp = isset($bps->in_house) && $bps->in_house === 'wp' ? true : false; if ($is_wp) { break; } if (version_compare($bps->remote, $bps->version, '>')) { $temp = (array) $bps; $temp['bundled'] = true; array_push($update_ready, $temp); } } } } // for theme check if (!empty($bsf_product_themes)) { foreach ($bsf_product_themes as $key => $theme) { $version = isset($theme['version']) ? $theme['version'] : ''; $remote = isset($theme['remote']) ? $theme['remote'] : ''; if (version_compare($remote, $version, '>')) { array_push($temp_theme_update_ready, $theme); } } } $theme_update_ready_counter = count($temp_theme_update_ready); $update_ready_counter = count($update_ready); $update_ready = bsf_array_unique($update_ready); ?> <script type="text/javascript"> (function($) { $(window).load(function(e) { var update = $('#menu-plugins').find(".update-plugins"); var plugin_counter = parseInt(update.find(".plugin-count").html()); var plugin_update_ready_counter = parseInt(<?php echo $update_ready_counter; ?> ); plugin_counter = plugin_counter+plugin_update_ready_counter; $("#menu-dashboard").find(".plugin-count").html(plugin_counter); update.removeClass("count-0").addClass("count-"+plugin_counter); update.find(".update-count").html(plugin_counter); $("#wp-admin-bar-updates").find(".ab-label").html(plugin_counter); <?php global $pagenow; if ('plugins.php' === $pagenow) { foreach ($update_ready as $ur) { ?> <?php $message_changelog = ''; $template = isset($ur['bundled']) && $ur['bundled'] === true ? $ur["init"] : $ur['template']; $plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $template); $plugin_main_name = $plugin_data['Name']; $changelog_url = isset($ur['changelog_url']) ? $ur['changelog_url'] : ''; if ($changelog_url !== '') { $message_changelog = 'or view <a href="' . $changelog_url . '" target="_blank">Changelog here</a>'; } if ($ur['bundled']) { $id = str_replace(' ', '-', strtolower($plugin_main_name)); $id = str_replace('---', '-', strtolower($id)); $name = $ur['name']; $parent_name = ''; foreach ($bsf_product_themes as $key => $bsf_p) { if ($bsf_p['id'] === $ur['parent']) { $parent_name = $bsf_p['product_name']; break; } } foreach ($mix_products as $key => $bsf_p) { if ($bsf_p['id'] === $ur['parent']) { $parent_name = $bsf_p['product_name']; break; } } $message = 'There is a new version of ' . $name . ', bundled with <strong>' . $parent_name . '</strong>.'; } else { $id = str_replace(' ', '-', strtolower($plugin_main_name)); $name = $ur['product_name']; $message = 'There is a new version of ' . $name . '.'; } ?> if($("#<?php echo $id; ?> ").find('.plugin-update-tr') !== true) { $("#<?php echo $id; ?> ").addClass("update"); var html = '<tr class="plugin-update-tr">\ <td colspan="3" class="plugin-update colspanchange">\ <div class="update-message"><?php echo $message; ?> \ <a href="update-core.php#brainstormforce-products">Check <?php echo $ur["remote"]; ?> update details</a>\ <?php echo $message_changelog; ?> </div>\ </td>\ </tr>'; $(html).insertAfter("#<?php echo $id; ?> "); } <?php } ?> <?php } ?> <?php if ('themes.php' === $pagenow) { ?> <?php foreach ($temp_theme_update_ready as $key => $theme) { ?> <?php $template = $theme['template']; $theme = wp_get_theme($template); $name = strtolower($theme->get('Name')); ?> var $theme_wrapper = $('#<?php echo $name; ?> -name').parents('.theme:first'); if($theme_wrapper.find('.theme-update') !== true) { $theme_wrapper.append('<div class="theme-update">Update Available</div>'); $theme_wrapper.click(function(){ $('.theme-overlay').find('.theme-author').after('<div class="theme-update-message"><h4 class="theme-update">Update Available</h4><p><strong>There is a new version of <?php echo $theme->get('Name'); ?> available. <a href="update-core.php#brainstormforce-products" title="<?php echo $name; ?> ">Check update details</a> </strong></p></div>'); }); } <?php } ?> <?php } ?> <?php if (is_multisite()) { ?> $main_menu_dashboard = $('#menu-update'); <?php } else { ?> $main_menu_dashboard = $('#menu-dashboard'); <?php } ?> var theme_update_ready_counter = parseInt(<?php echo $theme_update_ready_counter; ?> ); var all_counter = parseInt($main_menu_dashboard.find('.update-plugins').find('.update-count').html()); all_counter = all_counter+theme_update_ready_counter+plugin_update_ready_counter; $main_menu_dashboard.find('.update-plugins').find('.update-count').html(all_counter); var title = $main_menu_dashboard.find('.update-plugins').attr('title'); if(typeof title === 'undefined') return false; var title_split = title.split(','); var title_plugins = title_themes = 0; if(typeof title_split[0] !== 'undefined') { if (/Plugin/i.test(title_split[0])) title_plugins = parseInt(title_split[0].replace ( /[^\d.]/g, '' )); else title_themes = parseInt(title_split[0].replace ( /[^\d.]/g, '' )); } if(typeof title_split[1] !== 'undefined') { if (/Plugin/i.test(title_split[1])) title_plugins = parseInt(title_split[1].replace ( /[^\d.]/g, '' )); else title_themes = parseInt(title_split[1].replace ( /[^\d.]/g, '' )); } title_plugins += plugin_update_ready_counter; title_themes += theme_update_ready_counter; var temp_title = ''; if(title_plugins !== '' && title_plugins !== 0) temp_title = title_plugins+' Plugin Update'; if(title_themes !== '' && title_themes !== 0) { if(temp_title != '') temp_title += ', '; temp_title += title_themes+' Theme Update'; } $main_menu_dashboard.find('.update-plugins').attr('title',temp_title); }); })(jQuery); </script> <?php }