Unyson - Version 2.1.10

Version Description

  • Activate theme extensions automatically on theme switch and Unyson plugin activation.
  • Cache Github API responses for one hour on extensions download to prevent the API rate limit exceeded error.
Download this release

Release Info

Developer Unyson
Plugin Icon 128x128 Unyson
Version 2.1.10
Comparing to
See all releases

Code changes from version 2.1.9 to 2.1.10

framework/core/components/extensions.php CHANGED
@@ -81,15 +81,7 @@ final class _FW_Component_Extensions
81
  */
82
  public function _get_db_active_extensions($extension_name = null)
83
  {
84
- try {
85
- $cache_key = 'fw_db_active_extensions';
86
-
87
- $extensions = FW_Cache::get($cache_key);
88
- } catch (FW_Cache_Not_Found_Exception $e) {
89
- $extensions = get_option($this->_get_active_extensions_db_option_name(), array());
90
-
91
- FW_Cache::set($cache_key, $extensions);
92
- }
93
 
94
  if ($extension_name) {
95
  return isset($extensions[$extension_name]);
81
  */
82
  public function _get_db_active_extensions($extension_name = null)
83
  {
84
+ $extensions = get_option($this->_get_active_extensions_db_option_name(), array());
 
 
 
 
 
 
 
 
85
 
86
  if ($extension_name) {
87
  return isset($extensions[$extension_name]);
framework/core/components/extensions/manager/class--fw-extensions-manager.php CHANGED
@@ -48,13 +48,14 @@ final class _FW_Extensions_Manager
48
  add_action('network_admin_menu', array($this, '_action_admin_menu'));
49
  add_action('admin_footer', array($this, '_action_admin_footer'));
50
  add_action('admin_enqueue_scripts', array($this, '_action_enqueue_menu_icon_style'));
 
 
 
51
 
52
  if ($this->can_install()) {
53
  add_action('wp_ajax_fw_extensions_check_direct_fs_access', array($this, '_action_ajax_check_direct_fs_access'));
54
-
55
- // as late as possible, but to be able to make redirects (content not started)
56
- add_action('current_screen', array($this, '_action_check_if_plugin_was_activated'), 100);
57
  }
 
58
  }
59
 
60
  /** Filters */
@@ -229,14 +230,22 @@ final class _FW_Extensions_Manager
229
  delete_option($option_name);
230
  }
231
 
232
- if (!count($this->get_supported_extensions_for_install())) {
233
- return;
234
- }
 
 
 
 
235
 
236
- $link = $this->get_link();
 
 
237
 
238
- wp_redirect($link .'&sub-page=install&supported');
239
- exit;
 
 
240
  }
241
 
242
  /**
@@ -726,21 +735,39 @@ final class _FW_Extensions_Manager
726
  return;
727
  }
728
 
 
 
729
  if (array_key_exists('supported', $_GET)) {
730
  $supported = true;
731
 
 
 
 
 
 
 
 
732
  $install_data = $this->get_install_data(
733
  array_keys($this->get_supported_extensions_for_install())
734
  );
735
  } else {
736
  $supported = false;
737
 
 
 
 
 
 
 
 
 
 
738
  $install_data = $this->get_install_data(
739
- array_map( 'trim', explode( ',', FW_Request::GET( 'extension', '' ) ))
740
  );
741
- }
742
 
743
- unset($extension_names);
 
744
 
745
  if (is_wp_error($install_data)) {
746
  FW_Flash_Messages::add($flash_id, $install_data->get_error_message(), 'error');
@@ -778,7 +805,6 @@ final class _FW_Extensions_Manager
778
  break;
779
  }
780
 
781
- $installed_extensions = $this->get_installed_extensions();
782
  $available_extensions = $this->get_available_extensions();
783
 
784
  $extensions_before_install = array_keys($installed_extensions);
@@ -1708,6 +1734,19 @@ final class _FW_Extensions_Manager
1708
  }
1709
 
1710
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
1711
  $http = new WP_Http();
1712
 
1713
  $response = $http->get('https://api.github.com/repos/'. $source_data['user_repo'] .'/releases');
@@ -1763,6 +1802,15 @@ final class _FW_Extensions_Manager
1763
 
1764
  unset($releases);
1765
 
 
 
 
 
 
 
 
 
 
1766
  $download_link = $release['zipball_url'];
1767
 
1768
  unset($release);
@@ -2253,4 +2301,151 @@ final class _FW_Extensions_Manager
2253
  fw()->manifest->get_version()
2254
  );
2255
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2256
  }
48
  add_action('network_admin_menu', array($this, '_action_admin_menu'));
49
  add_action('admin_footer', array($this, '_action_admin_footer'));
50
  add_action('admin_enqueue_scripts', array($this, '_action_enqueue_menu_icon_style'));
51
+ // as late as possible, but to be able to make redirects (content not started)
52
+ add_action('current_screen', array($this, '_action_check_if_plugin_was_activated'), 100);
53
+ add_action('after_switch_theme', array($this, '_action_theme_switch'));
54
 
55
  if ($this->can_install()) {
56
  add_action('wp_ajax_fw_extensions_check_direct_fs_access', array($this, '_action_ajax_check_direct_fs_access'));
 
 
 
57
  }
58
+
59
  }
60
 
61
  /** Filters */
230
  delete_option($option_name);
231
  }
232
 
233
+ $this->activate_theme_extensions();
234
+ $this->activate_extensions_if_exists(
235
+ array_fill_keys(
236
+ array_keys(fw()->theme->manifest->get('supported_extensions', array())),
237
+ array()
238
+ )
239
+ );
240
 
241
+ if ($this->can_install()) {
242
+ if ($this->get_supported_extensions_for_install()) {
243
+ $link = $this->get_link();
244
 
245
+ wp_redirect($link . '&sub-page=install&supported');
246
+ exit;
247
+ }
248
+ }
249
  }
250
 
251
  /**
735
  return;
736
  }
737
 
738
+ $installed_extensions = $this->get_installed_extensions();
739
+
740
  if (array_key_exists('supported', $_GET)) {
741
  $supported = true;
742
 
743
+ $this->activate_extensions_if_exists(
744
+ array_fill_keys(
745
+ array_keys(fw()->theme->manifest->get('supported_extensions', array())),
746
+ array()
747
+ )
748
+ );
749
+
750
  $install_data = $this->get_install_data(
751
  array_keys($this->get_supported_extensions_for_install())
752
  );
753
  } else {
754
  $supported = false;
755
 
756
+ $extension_names = array_map( 'trim', explode( ',', FW_Request::GET( 'extension', '' ) ));
757
+
758
+ $this->activate_extensions_if_exists(
759
+ array_fill_keys(
760
+ $extension_names,
761
+ array()
762
+ )
763
+ );
764
+
765
  $install_data = $this->get_install_data(
766
+ $extension_names
767
  );
 
768
 
769
+ unset($extension_names);
770
+ }
771
 
772
  if (is_wp_error($install_data)) {
773
  FW_Flash_Messages::add($flash_id, $install_data->get_error_message(), 'error');
805
  break;
806
  }
807
 
 
808
  $available_extensions = $this->get_available_extensions();
809
 
810
  $extensions_before_install = array_keys($installed_extensions);
1734
  }
1735
 
1736
  {
1737
+ $transient_name = 'fw_ext_manager_gh_ext_download';
1738
+ $transient_ttl = HOUR_IN_SECONDS;
1739
+
1740
+ $cache = get_site_transient($transient_name);
1741
+
1742
+ if ($cache === false) {
1743
+ $cache = array();
1744
+ }
1745
+ }
1746
+
1747
+ if (isset($cache[ $source_data['user_repo'] ])) {
1748
+ $download_link = $cache[ $source_data['user_repo'] ]['zipball_url'];
1749
+ } else {
1750
  $http = new WP_Http();
1751
 
1752
  $response = $http->get('https://api.github.com/repos/'. $source_data['user_repo'] .'/releases');
1802
 
1803
  unset($releases);
1804
 
1805
+ {
1806
+ $cache[ $source_data['user_repo'] ] = array(
1807
+ 'zipball_url' => $release['zipball_url'],
1808
+ 'tag_name' => $release['tag_name']
1809
+ );
1810
+
1811
+ set_site_transient($transient_name, $cache, $transient_ttl);
1812
+ }
1813
+
1814
  $download_link = $release['zipball_url'];
1815
 
1816
  unset($release);
2301
  fw()->manifest->get_version()
2302
  );
2303
  }
2304
+
2305
+ private function activate_theme_extensions()
2306
+ {
2307
+ $db_active_extensions = fw()->extensions->_get_db_active_extensions();
2308
+
2309
+ foreach ($this->get_installed_extensions() as $extension_name => $extension) {
2310
+ if ($extension['source'] !== 'framework') {
2311
+ $db_active_extensions[ $extension_name ] = array();
2312
+ }
2313
+ }
2314
+
2315
+ update_option(
2316
+ fw()->extensions->_get_active_extensions_db_option_name(),
2317
+ $db_active_extensions
2318
+ );
2319
+ }
2320
+
2321
+ /**
2322
+ * @internal
2323
+ */
2324
+ public function _action_theme_switch()
2325
+ {
2326
+ $this->activate_theme_extensions();
2327
+ $this->activate_extensions_if_exists(
2328
+ array_fill_keys(
2329
+ array_keys(fw()->theme->manifest->get('supported_extensions', array())),
2330
+ array()
2331
+ )
2332
+ );
2333
+ }
2334
+
2335
+ /**
2336
+ * @param $activate_extensions {'extension_name' => array()}
2337
+ * @return array Errors {'extension_name' => array()}
2338
+ */
2339
+ private function activate_extensions_if_exists($activate_extensions)
2340
+ {
2341
+ $errors = array();
2342
+
2343
+ $installed_extensions = $this->get_installed_extensions();
2344
+ $db_active_extensions = fw()->extensions->_get_db_active_extensions();
2345
+
2346
+ foreach (
2347
+ array_keys(array_intersect_key($activate_extensions, $installed_extensions))
2348
+ as $extension_name
2349
+ ) {
2350
+ $current_extension_activation = array();
2351
+
2352
+ // add extension to activation only if all required extensions are installed
2353
+ {
2354
+ $required_extensions = array();
2355
+ $this->collect_required_extensions($extension_name, $installed_extensions, $required_extensions);
2356
+
2357
+ if ($not_installed_required_extensions = array_diff_key($required_extensions, $installed_extensions)) {
2358
+ // extension requires extensions that are not installed
2359
+ $errors[$extension_name] = array(
2360
+ 'not_installed_required_extensions' => $not_installed_required_extensions
2361
+ );
2362
+ continue;
2363
+ } else {
2364
+ // all required extensions are installed
2365
+ $current_extension_activation[ $extension_name ] = array();
2366
+
2367
+ if (!empty($required_extensions)) {
2368
+ $current_extension_activation = array_merge(
2369
+ $current_extension_activation,
2370
+ array_fill_keys(array_keys($required_extensions), array())
2371
+ );
2372
+ }
2373
+ }
2374
+ }
2375
+
2376
+ // activate parents
2377
+ {
2378
+ $current_parent = $extension_name;
2379
+ while ($current_parent = $installed_extensions[$current_parent]['parent']) {
2380
+ // add extension to activation only if all required extensions are installed
2381
+ {
2382
+ $required_extensions = array();
2383
+ $this->collect_required_extensions($current_parent, $installed_extensions, $required_extensions);
2384
+
2385
+ if ($not_installed_required_extensions = array_diff_key($required_extensions, $installed_extensions)) {
2386
+ // extension requires extensions that are not installed
2387
+ $errors[$current_parent] = array(
2388
+ 'not_installed_required_extensions' => $not_installed_required_extensions
2389
+ );
2390
+ continue 2;
2391
+ } else {
2392
+ // all required extensions are installed
2393
+ $current_extension_activation[ $current_parent ] = array();
2394
+
2395
+ if (!empty($required_extensions)) {
2396
+ $current_extension_activation = array_merge(
2397
+ $current_extension_activation,
2398
+ array_fill_keys(array_keys($required_extensions), array())
2399
+ );
2400
+ }
2401
+ }
2402
+ }
2403
+ }
2404
+ }
2405
+
2406
+ // activate children
2407
+ {
2408
+ foreach (
2409
+ array_keys($this->collect_sub_extensions($extension_name, $installed_extensions))
2410
+ as $sub_extension_name
2411
+ ) {
2412
+ // add extension to activation only if all required extensions are installed
2413
+ {
2414
+ $required_extensions = array();
2415
+ $this->collect_required_extensions($sub_extension_name, $installed_extensions, $required_extensions);
2416
+
2417
+ if ($not_installed_required_extensions = array_diff_key($required_extensions, $installed_extensions)) {
2418
+ // extension requires extensions that are not installed
2419
+ $errors[$sub_extension_name] = array(
2420
+ 'not_installed_required_extensions' => $not_installed_required_extensions
2421
+ );
2422
+ continue 2;
2423
+ } else {
2424
+ // all required extensions are installed
2425
+ $current_extension_activation[ $sub_extension_name ] = array();
2426
+
2427
+ if (!empty($required_extensions)) {
2428
+ $current_extension_activation = array_merge(
2429
+ $current_extension_activation,
2430
+ array_fill_keys(array_keys($required_extensions), array())
2431
+ );
2432
+ }
2433
+ }
2434
+ }
2435
+ }
2436
+
2437
+ $db_active_extensions = array_merge(
2438
+ $db_active_extensions,
2439
+ $current_extension_activation
2440
+ );
2441
+ }
2442
+ }
2443
+
2444
+ update_option(
2445
+ fw()->extensions->_get_active_extensions_db_option_name(),
2446
+ $db_active_extensions
2447
+ );
2448
+
2449
+ return $errors;
2450
+ }
2451
  }
framework/extensions/update/extensions/github-update/class-fw-extension-github-update.php CHANGED
@@ -23,7 +23,7 @@ class FW_Extension_Github_Update extends FW_Ext_Update_Service
23
  * How long to cache server responses
24
  * @var int seconds
25
  */
26
- private $transient_expiration = 86400;
27
 
28
  private $download_timeout = 300;
29
 
23
  * How long to cache server responses
24
  * @var int seconds
25
  */
26
+ private $transient_expiration = DAY_IN_SECONDS;
27
 
28
  private $download_timeout = 300;
29
 
framework/helpers/general.php CHANGED
@@ -219,6 +219,7 @@ function fw_print($value) {
219
  }
220
  div.fw_print_r_group div.fw_print_r {
221
  margin: 9px;
 
222
  }
223
  </style>';
224
  echo str_replace(array(' ', "\n"), '', ob_get_clean());
219
  }
220
  div.fw_print_r_group div.fw_print_r {
221
  margin: 9px;
222
+ border-width: 0;
223
  }
224
  </style>';
225
  echo str_replace(array(' ', "\n"), '', ob_get_clean());
framework/manifest.php CHANGED
@@ -4,4 +4,4 @@ $manifest = array();
4
 
5
  $manifest['name'] = __('Unyson', 'fw');
6
 
7
- $manifest['version'] = '2.1.9';
4
 
5
  $manifest['name'] = __('Unyson', 'fw');
6
 
7
+ $manifest['version'] = '2.1.10';
framework/static/js/fw.js CHANGED
@@ -1168,6 +1168,10 @@ fw.elementEventHasListenerInContainer = function ($element, event, $container) {
1168
  return true;
1169
  }
1170
 
 
 
 
 
1171
  $currentParent = $currentParent.parent();
1172
 
1173
  if (!$currentParent.length) {
1168
  return true;
1169
  }
1170
 
1171
+ if ($currentParent.attr('on'+ event)) {
1172
+ return true;
1173
+ }
1174
+
1175
  $currentParent = $currentParent.parent();
1176
 
1177
  if (!$currentParent.length) {
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: unyson, themefusecom
3
  Tags: page builder, cms, grid, layout, responsive, back up, backup, db backup, dump, migrate, schedule, search engine optimization, seo, media, slideshow, shortcode, slide, slideshare, slideshow, google sitemaps, sitemaps, analytics, google analytics, calendar, event, events, google maps, learning, lessons, sidebars, breadcrumbs, review, portfolio
4
  Requires at least: 4.0.0
5
- Tested up to: 4.0.1
6
- Stable tag: 2.1.9
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -84,6 +84,10 @@ Yes; Unyson will work with any theme.
84
 
85
  == Changelog ==
86
 
 
 
 
 
87
  = 2.1.9 =
88
  * Fixed: Extension is not installing if directory already exists but is empty.
89
 
2
  Contributors: unyson, themefusecom
3
  Tags: page builder, cms, grid, layout, responsive, back up, backup, db backup, dump, migrate, schedule, search engine optimization, seo, media, slideshow, shortcode, slide, slideshare, slideshow, google sitemaps, sitemaps, analytics, google analytics, calendar, event, events, google maps, learning, lessons, sidebars, breadcrumbs, review, portfolio
4
  Requires at least: 4.0.0
5
+ Tested up to: 4.1
6
+ Stable tag: 2.1.10
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
84
 
85
  == Changelog ==
86
 
87
+ = 2.1.10 =
88
+ * Activate theme extensions automatically on theme switch and Unyson plugin activation.
89
+ * Cache Github API responses for one hour on extensions download to prevent the `API rate limit exceeded` error.
90
+
91
  = 2.1.9 =
92
  * Fixed: Extension is not installing if directory already exists but is empty.
93
 
unyson.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Unyson
4
  * Plugin URI: http://unyson.themefuse.com/
5
  * Description: A free drag & drop framework that comes with a bunch of built in extensions that will help you develop premium themes fast & easy.
6
- * Version: 2.1.9
7
  * Author: ThemeFuse
8
  * Author URI: http://themefuse.com
9
  * License: GPL2+
3
  * Plugin Name: Unyson
4
  * Plugin URI: http://unyson.themefuse.com/
5
  * Description: A free drag & drop framework that comes with a bunch of built in extensions that will help you develop premium themes fast & easy.
6
+ * Version: 2.1.10
7
  * Author: ThemeFuse
8
  * Author URI: http://themefuse.com
9
  * License: GPL2+