, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
--------------------------------------------------------------------------------
/README.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Beaver Brewer
8 |
9 | Contributors: rbenhase
10 | Tags: Beaver Builder, custom modules
11 | Requires at least: 4.3
12 | Tested up to: 4.5
13 |
14 |
15 |
16 | Homebrew for Beaver Builder
17 |
18 | Beaver Brewer extends the Beaver Builder plugin by giving admins the ability to easily install “homebrew” modules. It also enables developers to release their modules in an a la carte fashion (no plugin wrapper needed) and even offer automatic updates to their modules through the Wordpress dashboard. You can download the plugin and download some modules right away to get started.
19 |
20 | Beaver Brewer is in active development and should be considered a Beta at this stage. For this reason, you should be cautious about using it on a Production site. When more features are added to the plugin, an automatic update will appear in your Wordpress plugin admin page.
21 |
22 |
23 |
24 | Overview
25 |
26 | Beaver Builder is a fantastic page builder plugin, and its support for custom modules gives it nearly limitless potential. But as the number of Beaver Builder modules increases, they can become a bit difficult for users (and developers) to manage. Beaver Brewer strives to change all that.
27 |
28 | Many modules. Many developers. One plugin.
29 |
30 | Instead of installing a different Wordpress plugin for every set of Beaver Builder modules you want to use, you can now install a single, lightweight plugin that handles them all. This means that a module developer doesn’t necessarily need to build out an entire plugin wrapper for his/her project, and this translates into lower overhead and fewer plugins to maintain on your site.
31 |
32 | Pick and choose what you want.
33 |
34 | Why install a plugin that contains 30 modules if you’re already certain that you’re only going to need one of them? Beaver Brewer lets you install individual modules a la carte.
35 |
36 | Keep things up-to-date.
37 |
38 | Module developers can use our handy module.config file to enable easy, one-click updates for their module from the Wordpress admin area! All you need is a place to host your latest module zipball (GitHub and Bitbucket work great, but hosting it on your own site works too!).
39 |
40 | Brew your own.
41 |
42 | Whether you’re a developer who needs to crank out a module post haste, or just someone who wants to experiment a little, Beaver Brewer makes it quicker and easier to develop new modules from scratch.
43 |
44 |
45 |
46 | Downloads
47 |
48 | You can download the latest version of Beaver Brewer here. Keep in mind that Beaver Brewer is still considered to be in the Beta stage; be careful about using it on a production site (and keep regular backups just in case).
49 |
50 | Installation
51 |
52 |
53 | - Upload the beaver-brewer folder to the /wp-content/plugins/ directory.
54 | - Activate the Beaver Brewer plugin through the ‘Plugins’ menu in WordPress.
55 | - Install and activate modules under the ‘Beaver Brewer’ menu in the Wordpress admin.
56 |
57 |
58 | Feedback
59 |
60 | Please submit all bugs and/or feedback to ryan@beaverbrewer.com.
61 |
62 |
63 |
64 | Frequently Asked Questions
65 |
66 | Is this plugin compatible with the free/lite version of Beaver Builder?
67 |
68 | No, this plugin requires Beaver Builder Premium. But believe me, it’s worth the investment!
69 |
70 | Will this plugin work with any Beaver Builder module?
71 |
72 | Not necessarily. Some modules are dependent on a parent plugin in order to work. In order to ensure that your module is compatible with Beaver Brewer, please follow our compatibility requirements below.
73 |
74 | Can I still (separately) use Beaver Lodge or other plugins that contain Beaver Builder modules?
75 |
76 | Yes, absolutely– especially if those developers don’t offer individual module updates (e.g. making use of a module.config file).
77 |
78 | A module I’m using doesn’t contain a module.config file. Why?
79 |
80 | The module.config file is just something I’ve come up with to enable simple, one-click updates. Not all developers will take advantage of this feature (especially until Beaver Brewer becomes popular). This means that your module will need to be updated manually if/when the developer releases a new version, but it does not prevent the module from being used with Beaver Brewer.
81 |
82 | I don’t want to use the Beaver Brewer admin (or am having file permissions issues). How can I manually add modules?
83 |
84 | Simply drop your module folder into your wp-content/bb-modules directory. If the bb-modules directory does not exist (e.g., because of a permissions issue), you will have to create it.
85 |
86 |
87 |
88 | Troubleshooting
89 |
90 | General file/directory permissions issues
91 |
92 | File/folder permissions issues are the most likely problem you might experience with this plugin. As a general rule, you should use 644 permissions for files and 755 permissions for directories within your Wordpress installation (note that some files, such as your wp-config.php file, should be stricter than this). If the user that Wordpress uses on your server is not the owner of the files/folders in your Wordpress installation, it must be the group owner (and bumping permissions up to 664 for files, 775 for folders will be necessary). Do not use 777 permissions for anything that is accessible over the internet. For more, visit https://codex.wordpress.org/Changing_File_Permissions.
93 |
94 | A certain module is not showing up in the page builder
95 |
96 | Assuming that you’ve installed the module correctly, you may want to ensure that it meets the Beaver Brewer compatibility requirements (see below).
97 |
98 | A module is missing from the list on the Beaver Brewer admin page
99 |
100 | Check that your module folder’s file permissions allow it to be readable by the webserver. Also check that you’ve installed it correctly; there should be a folder (e.g., the name of the module) inside the wp-content/bb-modules directory, and inside that folder is where your individual module files should live. If there is no PHP file inside your module folder, Beaver Brewer will not recognize it as a valid module.
101 |
102 | Automatic updates are not available for one or more modules
103 |
104 | Modules that do not contain a module.config file will not be able to provide automatic/one-click updates. This is up to the module developer. While not having a module.config file does not prevent modules from being used with Beaver Brewer, any updates will need to be downloaded and applied manually.
105 |
106 | My plugin could not be activated because it triggered a fatal error.
107 |
108 | See your error log for more information.
109 |
110 | “Fatal error: Cannot redeclare class” issues
111 |
112 | This is when you try to activate two modules that contain identical class names (or a two copies of the same module). You must remove one of the modules, or else rename one of the classes causing the issue.
113 |
114 |
115 |
116 | Compatibility Requirements
117 |
118 | I plan on releasing complete online documentation for this plugin before it’s released into the wild, but the general rule for making your module compatible with Beaver Brewer is that you should avoid making it dependent on a parent plugin. If you follow the Beaver Builder custom module documentation (see this page), only skipping the very first part (about creating a plugin wrapper), you should be fine. The MY_MODULES_DIR and MY_MODULES_URL constants are defined by Beaver Brewer, and the init hook to load your module is already taken care of. You can see and download my plugin boilerplate if you’re having trouble getting started.
119 |
120 | To enable automatic updates for your module, you can utilize the module.config file. See http://beaverbrewer.com/module-config/ for more info.
121 |
122 | To Do
123 |
124 | There’s a lot more I’d like to do with this module in future versions. Here’s a few things:
125 |
126 |
127 | - Add a search / filter modules function on the Beaver Brewer admin page.
128 | - Detect any compatibility issues and warn the user on the admin page.
129 | - Create centralized Beaver Brewer module repository for community use (similar to the Wordpress plugin repository).
130 | - Improve README and provide full online documentation for making modules compatible with Beaver Brewer.
131 | - Improve automatic updates (use a true update server instead of relying on Bitbucket)
132 | - Create simple module boilerplate & generator app (which builds your module.config file, etc. for you).
133 | - Maybe make the Beaver Brewer admin page more closely resemble the Wordpress plugins admin page.
134 | - Invent a machine that warps spacetime just enough to achieve 30 hours’s worth of work in just one 8-hour day.
135 |
136 |
137 |
138 |
139 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Beaver Brewer #
2 | Contributors: rbenhase
3 | Tags: Beaver Builder, custom modules
4 | Requires at least: 4.3
5 | Tested up to: 4.5
6 |
7 | ***
8 |
9 | ## Homebrew for Beaver Builder ##
10 | Beaver Brewer extends the Beaver Builder plugin by giving admins the ability to easily install "homebrew" modules. It also enables developers to release their modules in an a la carte fashion (no plugin wrapper needed) and even offer automatic updates to their modules through the Wordpress dashboard. You can [download the plugin](http://beaverbrewer.com/downloads) and [download some modules](http://beaverbrewer.com/modules) right away to get started.
11 |
12 | Beaver Brewer is in active development and should be considered a Beta at this stage. For this reason, you should be cautious about using it on a Production site. When more features are added to the plugin, an automatic update will appear in your Wordpress plugin admin page.
13 |
14 | ***
15 |
16 | ## Overview ##
17 | Beaver Builder is a fantastic page builder plugin, and its support for custom modules gives it nearly limitless potential. But as the number of Beaver Builder modules increases, they can become a bit difficult for users (and developers) to manage. Beaver Brewer strives to change all that.
18 |
19 | #### Many modules. Many developers. One plugin. ####
20 | Instead of installing a different Wordpress plugin for every set of Beaver Builder modules you want to use, you can now install a single, lightweight plugin that handles them all. This means that a module developer doesn't necessarily need to build out an entire plugin wrapper for his/her project, and this translates into lower overhead and fewer plugins to maintain on your site.
21 |
22 | #### Pick and choose what you want. ####
23 | Why install a plugin that contains 30 modules if you're already certain that you're only going to need one of them? Beaver Brewer lets you install individual modules a la carte.
24 |
25 | #### Keep things up-to-date. ####
26 | Module developers can use our handy module.config file to enable easy, one-click updates for their module from the Wordpress admin area! All you need is a place to host your latest module zipball (GitHub and Bitbucket work great, but hosting it on your own site works too!).
27 |
28 | #### Brew your own. ####
29 | Whether you're a developer who needs to crank out a module post haste, or just someone who wants to experiment a little, Beaver Brewer makes it quicker and easier to develop new modules from scratch.
30 |
31 | ***
32 |
33 | ## Downloads ##
34 | You can [download the latest version of Beaver Brewer here](http://beaverbrewer.com/downloads). Keep in mind that Beaver Brewer is still considered to be in the Beta stage; be careful about using it on a production site (and keep regular backups just in case).
35 |
36 | ## Installation ##
37 | 1. Upload the beaver-brewer folder to the /wp-content/plugins/ directory.
38 | 2. Activate the Beaver Brewer plugin through the 'Plugins' menu in WordPress.
39 | 3. Install and activate modules under the 'Beaver Brewer' menu in the Wordpress admin.
40 |
41 | ## Feedback ##
42 | Please submit all bugs and/or feedback to ryan@beaverbrewer.com.
43 |
44 | ***
45 |
46 | ## Frequently Asked Questions ##
47 |
48 | #### Is this plugin compatible with the free/lite version of Beaver Builder? ####
49 | No, this plugin requires Beaver Builder Premium. But believe me, it's worth the investment!
50 |
51 | #### Will this plugin work with any Beaver Builder module? ####
52 | Not necessarily. Some modules are dependent on a parent plugin in order to work. In order to ensure that your module is compatible with Beaver Brewer, please follow our compatibility requirements below.
53 |
54 | #### Can I still (separately) use Beaver Lodge or other plugins that contain Beaver Builder modules? ####
55 | Yes, absolutely-- especially if those developers don't offer individual module updates (e.g. making use of a module.config file).
56 |
57 | #### A module I'm using doesn't contain a module.config file. Why? ####
58 | The module.config file is just something I've come up with to enable simple, one-click updates. Not all developers will take advantage of this feature (especially until Beaver Brewer becomes popular). This means that your module will need to be updated manually if/when the developer releases a new version, but it does not prevent the module from being used with Beaver Brewer.
59 |
60 | #### I don't want to use the Beaver Brewer admin (or am having file permissions issues). How can I manually add modules? ####
61 | Simply drop your module folder into your wp-content/bb-modules directory. If the bb-modules directory does not exist (e.g., because of a permissions issue), you will have to create it.
62 |
63 | ***
64 |
65 | ## Troubleshooting ##
66 |
67 | #### General file/directory permissions issues ####
68 | File/folder permissions issues are the most likely problem you might experience with this plugin. As a general rule, you should use 644 permissions for files and 755 permissions for directories within your Wordpress installation (note that some files, such as your wp-config.php file, should be stricter than this). If the user that Wordpress uses on your server is not the owner of the files/folders in your Wordpress installation, it must be the group owner (and bumping permissions up to 664 for files, 775 for folders will be necessary). Do not use 777 permissions for anything that is accessible over the internet. For more, visit [https://codex.wordpress.org/Changing_File_Permissions](https://codex.wordpress.org/Changing_File_Permissions).
69 |
70 | #### A certain module is not showing up in the page builder ####
71 | Assuming that you've installed the module correctly, you may want to ensure that it meets the Beaver Brewer compatibility requirements (see below).
72 |
73 | #### A module is missing from the list on the Beaver Brewer admin page ####
74 | Check that your module folder's file permissions allow it to be readable by the webserver. Also check that you've installed it correctly; there should be a folder (e.g., the name of the module) inside the wp-content/bb-modules directory, and inside that folder is where your individual module files should live. If there is no PHP file inside your module folder, Beaver Brewer will not recognize it as a valid module.
75 |
76 | #### Automatic updates are not available for one or more modules ####
77 | Modules that do not contain a module.config file will not be able to provide automatic/one-click updates. This is up to the module developer. While not having a module.config file does not prevent modules from being used with Beaver Brewer, any updates will need to be downloaded and applied manually.
78 |
79 | #### My plugin could not be activated because it triggered a fatal error. ####
80 | See your error log for more information.
81 |
82 | #### "Fatal error: Cannot redeclare class" issues ####
83 | This is when you try to activate two modules that contain identical class names (or a two copies of the same module). You must remove one of the modules, or else rename one of the classes causing the issue.
84 |
85 | ***
86 |
87 | ## Compatibility Requirements ##
88 | I plan on releasing complete online documentation for this plugin before it's released into the wild, but the general rule for making your module compatible with Beaver Brewer is that you should avoid making it dependent on a parent plugin. If you follow the Beaver Builder custom module documentation (see [this page](https://www.wpbeaverbuilder.com/custom-module-documentation/)), only skipping the very first part (about creating a plugin wrapper), you should be fine. The MY_MODULES_DIR and MY_MODULES_URL constants are defined by Beaver Brewer, and the init hook to load your module is already taken care of. You can see and download [my plugin boilerplate](http://beaverbrewer.com/downloads) if you're having trouble getting started.
89 |
90 | To enable automatic updates for your module, you can utilize the module.config file. See [http://beaverbrewer.com/module-config/](http://beaverbrewer.com/module-config/) for more info.
91 |
92 | ## To Do ##
93 | There's a lot more I'd like to do with this module in future versions. Here's a few things:
94 |
95 | - Add a search / filter modules function on the Beaver Brewer admin page.
96 | - Detect any compatibility issues and warn the user on the admin page.
97 | - Create centralized Beaver Brewer module repository for community use (similar to the Wordpress plugin repository).
98 | - Improve README and provide full online documentation for making modules compatible with Beaver Brewer.
99 | - Improve automatic updates (use a true update server instead of relying on Bitbucket)
100 | - Create simple module boilerplate & generator app (which builds your module.config file, etc. for you).
101 | - Maybe make the Beaver Brewer admin page more closely resemble the Wordpress plugins admin page.
102 | - Invent a machine that warps spacetime just enough to achieve 30 hours's worth of work in just one 8-hour day.
--------------------------------------------------------------------------------
/README.txt:
--------------------------------------------------------------------------------
1 | === Beaver Brewer ===
2 | Contributors: rbenhase
3 | Tags: Beaver Builder, custom modules
4 | Donate link: http://beaverbrewer.com/donate
5 | Requires at least: 4.0
6 | Tested up to: 4.5
7 |
8 | Extends the Beaver Builder plugin by giving admins the ability to easily install "homebrew" modules in an a la carte fashion.
9 |
10 | == Description ==
11 | Beaver Builder is a fantastic page builder plugin, and its support for custom modules gives it nearly limitless potential. But as the number of Beaver Builder modules increases, they can become a bit difficult for users (and developers) to manage. Beaver Brewer strives to change all that.
12 |
13 | = Many modules. Many developers. One plugin. =
14 | Instead of installing a different Wordpress plugin for every set of Beaver Builder modules you want to use, you can now install a single, lightweight plugin that handles them all. This means that a module developer doesn't necessarily need to build out an entire plugin wrapper for his/her project, and this translates into lower overhead and fewer plugins to maintain on your site.
15 |
16 | = Pick and choose what you want. =
17 | Why install a plugin that contains 30 modules if you're already certain that you're only going to need one of them? Beaver Brewer lets you install individual modules a la carte.
18 |
19 | = Keep things up-to-date. =
20 | Module developers can use our handy module.config file to enable easy, one-click updates for their module from the Wordpress admin area! All you need is a place to host your latest module zipball (GitHub and Bitbucket work great, but hosting it on your own site works too!).
21 |
22 | = Brew your own. =
23 | Whether you're a developer who needs to crank out a module post haste, or just someone who wants to experiment a little, Beaver Brewer makes it quicker and easier to develop new modules from scratch.
24 |
25 | == Installation ==
26 | 1. Upload the beaver-brewer folder to the /wp-content/plugins/ directory.
27 | 2. Activate the Beaver Brewer plugin through the 'Plugins' menu in WordPress.
28 | 3. Install and activate modules under the 'Beaver Brewer' menu in the Wordpress admin.
29 |
30 | == Frequently Asked Questions ==
31 | = Is this plugin compatible with the free/lite version of Beaver Builder? =
32 | No, this plugin requires Beaver Builder Premium. But believe me, it's worth the investment!
33 |
34 | = Will this plugin work with any Beaver Builder module? =
35 | Not necessarily. Some modules are dependent on a parent plugin in order to work. In order to ensure that your module is compatible with Beaver Brewer, please follow our compatibility requirements below.
36 |
37 | = Can I still (separately) use Beaver Lodge or other plugins that contain Beaver Builder modules? =
38 | Yes, absolutely-- especially if those developers don't offer individual module updates (e.g. making use of a module.config file).
39 |
40 | = A module I'm using doesn't contain a module.config file. Why? =
41 | The module.config file is just something I've come up with to enable simple, one-click updates. Not all developers will take advantage of this feature (especially until Beaver Brewer becomes popular). This means that your module will need to be updated manually if/when the developer releases a new version.
42 |
43 | = I don't want to use the Beaver Brewer admin (or am having file permissions issues). How can I manually add modules? =
44 | Simply drop your module folder into your wp-content/bb-modules directory. If the bb-modules directory does not exist (e.g., because of a permissions issue), you will have to create it.
45 |
46 | == Troubleshooting ==
47 |
48 | = General file/directory permissions issues =
49 | File/folder permissions issues are the most likely problem you might experience with this plugin. As a general rule, you should use 644 permissions for folders and 755 permissions for files within your Wordpress installation (note that some files, such as your wp-config.php file, should be stricter than this). If the user that Wordpress uses on your server is not the owner of the files/folders in your Wordpress installation, it must be the group owner (and bumping permissions up to 664 for folders, 775 for files will be necessary). Do not use 777 permissions for anything that is accessible over the internet. For more, visit https://codex.wordpress.org/Changing_File_Permissions.
50 |
51 | = A certain module is not showing up in the page builder =
52 | Assuming that you've installed the module correctly, you may want to ensure that it meets the Beaver Brewer compatibility requirements (see below).
53 |
54 | = A module is missing from the list on the Beaver Brewer admin page =
55 | Check that your module folder's file permissions allow it to be readable by the webserver. Also check that you've installed it correctly; there should be a folder (e.g., the name of the module) inside the wp-content/bb-modules directory, and inside that folder is where your individual module files should live. If there is no PHP file inside your module folder, Beaver Brewer will not recognize it as a valid module.
56 |
57 | = My plugin could not be activated because it triggered a fatal error. =
58 | See your error log for more information.
59 |
60 | = "Fatal error: Cannot redeclare class" issues =
61 | This is when you try to activate two modules that contain identical class names (or a two copies of the same module). You must remove one of the modules, or else rename one of the classes causing the issue.
62 |
63 | == Compatibility Requirements ==
64 | I plan on releasing complete online documentation for this plugin before it's released into the wild, but the general rule for making your module compatible with Beaver Brewer is that you should avoid making it dependent on a parent plugin. If you follow the Beaver Builder custom module documentation (see https://www.wpbeaverbuilder.com/custom-module-documentation/), only skipping the very first part (about creating a plugin wrapper), you should be fine. The MY_MODULES_DIR and MY_MODULES_URL constants are defined by Beaver Brewer, and the init hook to load your module is already taken care of. You can see and download my plugin boilerplate at http://beaverbrewer.com/downloads if you're having trouble getting started.
65 |
66 | To enable automatic updates for your module, you can utilize the module.config file. See http://beaverbrewer.com/module-config/ for more info.
67 |
68 | == To Do ==
69 | There's a lot more I'd like to do with this module in future versions. Here's a few things:
70 |
71 | - Add a search / filter modules function on the Beaver Brewer admin page.
72 | - Detect any compatibility issues and warn the user on the admin page.
73 | - Create centralized Beaver Brewer module repository for community use (similar to the Wordpress plugin repository).
74 | - Improve README and provide full online documentation for making modules compatible with Beaver Brewer.
75 | - Improve automatic updates (use a true update server instead of relying on Bitbucket)
76 | - Create simple module boilerplate & generator app (which builds your module.config file, etc. for you).
77 | - Maybe make the Beaver Brewer admin page more closely resemble the Wordpress plugins admin page.
78 | - Invent a machine that warps spacetime just enough to achieve 30 hours's worth of work in just one 8-hour day.
--------------------------------------------------------------------------------
/admin/class-beaver-brewer-admin.php:
--------------------------------------------------------------------------------
1 |
22 | */
23 | class Beaver_Brewer_Admin {
24 |
25 | /**
26 | * The ID of this plugin.
27 | *
28 | * @since 0.1.0
29 | * @access private
30 | * @var string $plugin_name The ID of this plugin.
31 | */
32 | private $plugin_name;
33 |
34 | /**
35 | * The version of this plugin.
36 | *
37 | * @since 0.1.0
38 | * @access private
39 | * @var string $version The current version of this plugin.
40 | */
41 | private $version;
42 |
43 | /**
44 | * All modules and their relevant data.
45 | *
46 | * @since 0.1.0
47 | * @access private
48 | * @var array $modules All recognized modules.
49 | */
50 | private $modules;
51 |
52 |
53 | /**
54 | * Initialize the class and set its properties.
55 | *
56 | * @since 0.1.0
57 | * @param string $plugin_name The name of this plugin.
58 | * @param string $version The version of this plugin.
59 | * @param Beaver_Brewer $brewer An instance of the main Beaver Brewer class.
60 | */
61 | public function __construct( $plugin_name, $version, $modules ) {
62 |
63 | $this->plugin_name = $plugin_name;
64 | $this->version = $version;
65 | $this->modules = $modules;
66 | }
67 |
68 |
69 | /**
70 | * Add the Beaver Brewer menu item.
71 | *
72 | * @since 0.1.0
73 | */
74 | public function add_menu_page() {
75 |
76 | // Count updates (retrieve cached value in DB if available)
77 | $update_count = get_transient( "beaver-brewer-updates" );
78 | if ( $update_count === false )
79 | $update_count = $this->count_updates();
80 |
81 | $update_title = $update_count . __( "Updates" );
82 |
83 | // If there are module updates waiting
84 | if ( $update_count > 0 ) {
85 | $menu_label = sprintf(
86 | __( "Beaver Brewer %s" ),
87 | "" . number_format_i18n($update_count) . ""
88 | );
89 |
90 | } else {
91 | $menu_label = __( "Beaver Brewer" );
92 | }
93 |
94 | add_menu_page(
95 | __( 'Beaver Brewer', $this->plugin_name ),
96 | $menu_label,
97 | 'manage_options',
98 | 'beaver-brewer',
99 | array( $this, 'render_admin' ),
100 | 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9InN2ZzIiIGlua3NjYXBlOnZlcnNpb249IjAuNDguMiByOTgxOSIgc29kaXBvZGk6ZG9jbmFtZT0iYm90dGxlX2xvbmduZWNrLnN2ZyIgeG1sbnM6Y2M9Imh0dHA6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL25zIyIgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIiB4bWxuczppbmtzY2FwZT0iaHR0cDovL3d3dy5pbmtzY2FwZS5vcmcvbmFtZXNwYWNlcy9pbmtzY2FwZSIgeG1sbnM6bnMxPSJodHRwOi8vc296aS5iYWllcm91Z2UuZnIiIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyIgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG9kaS5zb3VyY2Vmb3JnZS5uZXQvRFREL3NvZGlwb2RpLTAuZHRkIiB4bWxuczpzdmc9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCIgdmlld0JveD0iMCAwIDc0NC4xIDEwNTIuNCIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgNzQ0LjEgMTA1Mi40OyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHNvZGlwb2RpOm5hbWVkdmlldyAgYm9yZGVyY29sb3I9IiM2NjY2NjYiIGJvcmRlcm9wYWNpdHk9IjEuMCIgaWQ9ImJhc2UiIGlua3NjYXBlOmN1cnJlbnQtbGF5ZXI9ImxheWVyMSIgaW5rc2NhcGU6Y3g9IjE0Ni4wMTMyMyIgaW5rc2NhcGU6Y3k9IjU1NC43NTY4OCIgaW5rc2NhcGU6ZG9jdW1lbnQtdW5pdHM9InB4IiBpbmtzY2FwZTpwYWdlb3BhY2l0eT0iMC4wIiBpbmtzY2FwZTpwYWdlc2hhZG93PSIyIiBpbmtzY2FwZTp3aW5kb3ctaGVpZ2h0PSIxMDI2IiBpbmtzY2FwZTp3aW5kb3ctbWF4aW1pemVkPSIxIiBpbmtzY2FwZTp3aW5kb3ctd2lkdGg9IjE2ODAiIGlua3NjYXBlOndpbmRvdy14PSIwIiBpbmtzY2FwZTp3aW5kb3cteT0iMjQiIGlua3NjYXBlOnpvb209IjAuNDk0OTc0NzUiIHBhZ2Vjb2xvcj0iI2ZmZmZmZiIgc2hvd2dyaWQ9ImZhbHNlIj48L3NvZGlwb2RpOm5hbWVkdmlldz48Zz48cGF0aCBkPSJNMjU3LDU1My43bC05LjQtOC4ybC0xNy4xLDE5LjZsOS40LDguMmM5LjUsOC4zLDE3LjEsOS4xLDIyLjgsMi42QzI2OC40LDU2OS40LDI2Ni41LDU2MiwyNTcsNTUzLjd6Ii8+PHBhdGggZD0iTTM2MS41LDYxOC44YzMuNCwwLjgsNi43LTAuNiw5LjktNC4zYzMuMi0zLjcsNC4xLTcuMiwyLjctMTAuNWMtMS40LTMuMy00LjYtNy4yLTkuOC0xMS43bC00LjktNC4ybC0xNiwxOC40bDUsNC4zQzM1My44LDYxNS4zLDM1OC4xLDYxOCwzNjEuNSw2MTguOHoiLz48cGF0aCBkPSJNMzQxLjgsNjI3LjRsLTkuNC04LjJsLTE3LjEsMTkuNmw5LjQsOC4yYzkuNSw4LjMsMTcuMSw5LjEsMjIuOCwyLjZDMzUzLjIsNjQzLjEsMzUxLjMsNjM1LjcsMzQxLjgsNjI3LjR6Ii8+PHBhdGggZD0iTTQ1OC41LDU3MS4xYzMxLjktMzkuMSwxNy05MC40LDM2LjctMTE1LjRMNjIxLDI4Ny41YzE5LjEsNS45LDI2LjUtMjQsMzAuMS0zMi45YzE4LjgtNSwxMC44LTEzLjksMTAuNS0xNy41Yy0yMi44LTIzLjgtMzQuNy0zMy41LTYzLjgtNTQuOGMwLDAtMTcuNy0wLjYtMTIuNywxNC40Yy0xLjMsNi4yLTQwLjgsMTEuMi0yOS4zLDM0LjVsLTE1MSwxNDljLTI3LDIzLjktNjgsMTQtMTAxLjEsNDYuNkwzMC44LDc0NS4xYzAsMC0xMi45LDE0LjgtMTIuOSwyMi43bDAsMGMxLjUsMzQsMTIzLjcsMTM1LjUsMTQzLjcsMTI2LjhjMTQuNiwwLjcsMzIuOS0yNC4zLDMyLjktMjQuM0w0NTguNSw1NzEuMXogTTI2NC42LDYwN2MtNy45LDAtMTYtMy41LTI0LjEtMTAuNUwxOTYuMiw1NThsNjYuNi03Ni42bDM3LDMyLjJjNC44LDQuMiw4LjYsOC4zLDExLjMsMTIuM2MyLjgsNCw0LjUsNy44LDUuMywxMS4zYzAuOCwzLjUsMC44LDYuOC0wLjEsOS45Yy0wLjgsMy4xLTIuNCw1LjktNC42LDguNWMtMi40LDIuOC01LjIsNC45LTguNCw2LjNjLTMuMiwxLjQtNi4yLDIuMi05LjIsMi4zYy0zLDAuMS01LjYtMC4zLTcuOC0xLjFjMy40LDYuNiw1LjIsMTIuNyw1LjIsMTguMmMwLDUuNS0yLjIsMTAuOC02LjUsMTUuOEMyNzkuNCw2MDMuNywyNzIuNSw2MDcsMjY0LjYsNjA3eiBNMzQ5LjQsNjgwLjdjLTcuOSwwLTE2LTMuNS0yNC4xLTEwLjVMMjgxLDYzMS43bDY2LjYtNzYuNmwzNywzMi4yYzQuOCw0LjIsOC42LDguMywxMS4zLDEyLjNjMi44LDQsNC41LDcuOCw1LjMsMTEuM2MwLjgsMy41LDAuOCw2LjgtMC4xLDkuOWMtMC44LDMuMS0yLjQsNS45LTQuNiw4LjVjLTIuNCwyLjgtNS4yLDQuOS04LjQsNi4zYy0zLjIsMS40LTYuMiwyLjItOS4yLDIuM2MtMywwLjEtNS42LTAuMy03LjgtMS4xYzMuNCw2LjYsNS4yLDEyLjcsNS4yLDE4LjJjMCw1LjUtMi4yLDEwLjgtNi41LDE1LjhDMzY0LjEsNjc3LjQsMzU3LjMsNjgwLjcsMzQ5LjQsNjgwLjd6Ii8+PHBhdGggZD0iTTI3Ni44LDU0NS4xYzMuNCwwLjgsNi43LTAuNiw5LjktNC4zYzMuMi0zLjcsNC4xLTcuMiwyLjctMTAuNWMtMS40LTMuMy00LjYtNy4yLTkuOC0xMS43bC00LjktNC4ybC0xNiwxOC40bDUsNC4zQzI2OSw1NDEuNiwyNzMuNCw1NDQuMywyNzYuOCw1NDUuMXoiLz48L2c+PC9zdmc+',
101 | 60
102 | );
103 |
104 | }
105 |
106 | /**
107 | * Render the Beaver Brewer admin page.
108 | *
109 | * @since 0.1.0
110 | */
111 | public function render_admin() {
112 |
113 | // See if we are supposed to activate any modules and update their status accordinly.
114 | if ( !empty( $_GET['activate'] ) && wp_verify_nonce( $_GET['activate_module_nonce'], 'activate_module' ) ) {
115 | $result = $this->activate_module( $_GET['activate'] );
116 | if ( $result ) {
117 | foreach ( $this->modules as $k => $module ) {
118 | if ( $module['name'] == $_GET['activate'] ) {
119 | $this->modules[$k]['active'] = true;
120 | $this->print_message(
121 | __( "Module Activated", $this->plugin_name ),
122 | sprintf( __( "Successfully activated the %s module.", $this->plugin_name ), ( !empty( $this->modules[$k]['nicename'] ) ? $this->modules[$k]['nicename'] : $this->modules[$k]['name'] ) )
123 | );
124 | }
125 | }
126 | }
127 | }
128 |
129 | $update_count = 0;
130 |
131 | include_once( 'partials/beaver-brewer-admin-display.php' );
132 |
133 | // If updates are available, update the cached value
134 | if ( $update_count > 0 )
135 | set_transient( "beaver-brewer-updates", $update_count, 12 * HOUR_IN_SECONDS );
136 | }
137 |
138 |
139 | /**
140 | * Render the admin page tab navigation.
141 | *
142 | * @since 0.3.0
143 | * @return Int $current The current active tab
144 | */
145 | public function get_admin_page_tabs() {
146 | $tabs = array(
147 | "my-modules" => __( "My Modules", $this->plugin_name ),
148 | "find-more" => __( "Find More Modules", $this->plugin_name )
149 | );
150 |
151 | $current = ( isset( $_REQUEST['tab'] ) ? $_REQUEST['tab'] : 'my-modules' );
152 |
153 | echo '';
154 | foreach( $tabs as $tab => $name ){
155 | $class = ( $tab == $current ) ? ' nav-tab-active' : '';
156 | echo "$name";
157 | }
158 | echo '
';
159 | return $current;
160 | }
161 |
162 |
163 | /**
164 | * Render the module results on the "Find Modules" page.
165 | *
166 | * @since 0.3.0
167 | */
168 | public function prepare_module_results() {
169 |
170 | $result_page = ( isset( $_REQUEST['result_page'] ) ? $_REQUEST['result_page'] : 1 );
171 |
172 | echo '';
173 | if ( isset( $_REQUEST['search'] ) ) {
174 | $response = wp_remote_get( 'http://beaverbrewer.com/wp-json/brewer/v2/modules-search/' . urlencode( $_REQUEST['search'] ) . '/' . $result_page );
175 | _e( "Search Results: ", $this->plugin_name );
176 | echo $_REQUEST['search'];
177 | } else if ( isset( $_REQUEST['orderby'] ) && $_REQUEST['orderby'] == 'name' ) {
178 | $response = wp_remote_get( 'http://beaverbrewer.com/wp-json/brewer/v2/modules-alphabetical/' . ( !empty( $_REQUEST['filter'] ) ? urlencode( $_REQUEST['filter'] ) : 'none' ) . '/' . $result_page );
179 | _e( "Modules - Alphabetical", $this->plugin_name );
180 | } else if ( isset( $_REQUEST['orderby'] ) && $_REQUEST['orderby'] == 'date_asc' ) {
181 | $response = wp_remote_get( 'http://beaverbrewer.com/wp-json/brewer/v2/modules-oldest/' . ( !empty( $_REQUEST['filter'] ) ? urlencode( $_REQUEST['filter'] ) : 'none' ) . '/' . $result_page );
182 | _e( "Oldest Added Modules", $this->plugin_name );
183 | } else {
184 | $response = wp_remote_get( 'http://beaverbrewer.com/wp-json/brewer/v2/modules-latest/' . ( !empty( $_REQUEST['filter'] ) ? urlencode( $_REQUEST['filter'] ) : 'none' ) . '/' . $result_page );
185 | _e( "Recently Added Modules", $this->plugin_name );
186 | }
187 | echo '
';
188 |
189 | $this->render_module_results( $response );
190 |
191 | }
192 |
193 | /**
194 | * Render the module results on the "Find Modules" page.
195 | *
196 | * @since 0.3.0
197 | * @param Object $response The response from the BB Module API.
198 | */
199 | public function render_module_results( $response ) {
200 | ?>
201 |
202 |
275 |
276 |
319 |
320 |
321 |
plugin_name ); ?>
322 |
323 |
324 |
325 | "Module Version"
343 | )
344 | );
345 |
346 | if ( !empty( $data['ModuleVersion'] ) )
347 | return $data['ModuleVersion'];
348 |
349 | return false;
350 | }
351 |
352 | /**
353 | * Check for updates to each module and return a total number of updates available.
354 | *
355 | * @since 0.1.0
356 | * @return Int $count The number of available module updates
357 | */
358 | private function count_updates() {
359 |
360 | $count = 0;
361 |
362 | // Loop through modules and check each for updates
363 | foreach( $this->modules as $module ) {
364 | if ( $this->check_updates( $module ) === true ) {
365 | $count++;
366 | }
367 | }
368 |
369 | // Cache update count for 12 hours.
370 | set_transient( "beaver-brewer-updates", $count, 12 * HOUR_IN_SECONDS );
371 |
372 | return $count;
373 | }
374 |
375 | /**
376 | * Check for updates to a module.
377 | *
378 | * @since 0.1.0
379 | * @param Array $module The module configuration settings to use
380 | */
381 | private function check_updates( $module ) {
382 |
383 | if ( empty( $module['version'] ) )
384 | return -1;
385 |
386 | if ( empty( $module['updates'] ) ) {
387 | error_log(
388 | __( "Beaver Brewer Error: Some of the data in your module.config file appears to be missing or invalid. Automatic updates will not work." )
389 | . ( !empty( $module['name'] ) ? __( " Check module: " ) . $module['name'] : '' )
390 | );
391 | return -1;
392 | }
393 |
394 | $latest = $this->get_latest( $module['updates'] );
395 |
396 | return version_compare( $module['version'], $latest, '<' );
397 | }
398 |
399 |
400 | /**
401 | * Echo a failure notice as a JSON-encoded string (e.g., as a response to an AJAX call).
402 | *
403 | * @since 0.1.0
404 | * @param String $message The (untranslated) message to use
405 | */
406 | private function trigger_ajax_failure( $message ) {
407 | echo json_encode(
408 | array(
409 | "success" => 0,
410 | "message" => __( $message, $this->plugin_name )
411 | )
412 | );
413 | exit;
414 | }
415 |
416 | /**
417 | * Delete a Directory.
418 | *
419 | * @access public
420 | * @param String $dir The directory to delete
421 | * @return Boolean False on failure, true on success
422 | */
423 | private function delete_directory( $dir ) {
424 |
425 | if (! is_dir( $dir ) ) {
426 | return false;
427 | }
428 | if ( substr( $dir, strlen( $dir ) - 1, 1 ) != '/' ) {
429 | $dir .= '/';
430 | }
431 | $files = glob( $dir . '*', GLOB_MARK );
432 | foreach ( $files as $file ) {
433 | if ( is_dir($file ) ) {
434 | $this->delete_directory( $file );
435 | } else {
436 | $result = @unlink( $file );
437 | if ( $result === false )
438 | return false;
439 | }
440 | }
441 | return @rmdir( $dir );
442 | }
443 |
444 |
445 | /**
446 | * Update a module via Ajax.
447 | *
448 | * Echoes a JSON-encoded response.
449 | *
450 | * @since 0.1.0
451 | */
452 | public function auto_update_ajax() {
453 |
454 | // Verify AJAX request
455 | check_ajax_referer( 'beaver-brewer-admin', '_ajax_nonce' );
456 |
457 | header( "Content-Type:application/json" );
458 |
459 | // Make sure all data we need are present
460 | if ( !isset( $_POST['module'] ) ) {
461 | $this->trigger_ajax_failure( "No module path specified." );
462 | }
463 | if ( !isset( $_POST['update'] ) ) {
464 | $this->trigger_ajax_failure( "No remote module config specified." );
465 | }
466 | if ( !is_dir( MY_MODULES_DIR . $_POST['module'] ) ) {
467 | $this->trigger_ajax_failure( "Could not find module directory." );
468 | }
469 |
470 | //Prepare temporary file for writing
471 | $tmp = tempnam( sys_get_temp_dir(), 'beaver-brewer-' );
472 | $handle = fopen( $tmp, "w" );
473 |
474 | if ( !$handle ) {
475 | $this->trigger_ajax_failure( "Could not open temporary file for writing." );
476 | }
477 |
478 | $data = get_file_data(
479 | $_POST['update'],
480 | array(
481 | "DownloadZIP" => "Download ZIP"
482 | )
483 | );
484 |
485 | if ( empty( $data["DownloadZIP"] ) )
486 | $this->trigger_ajax_failure( "Update Failed: Could not read from remote module config." );
487 |
488 | $download_url = $data["DownloadZIP"];
489 |
490 | //Download update via cURL
491 | $ch = curl_init();
492 | curl_setopt( $ch, CURLOPT_URL, $download_url );
493 | curl_setopt( $ch, CURLOPT_RETURNTRANSFER, false );
494 | curl_setopt( $ch, CURLOPT_BINARYTRANSFER, true );
495 | curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
496 | curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
497 | curl_setopt( $ch, CURLOPT_POSTREDIR, 3);
498 | curl_setopt( $ch, CURLOPT_MAXREDIRS, 25 );
499 | curl_setopt( $ch, CURLOPT_TIMEOUT, 60 );
500 | curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 10 );
501 | curl_setopt( $ch, CURLOPT_FILE, $handle );
502 |
503 | $result = curl_exec( $ch );
504 |
505 | curl_close( $ch );
506 |
507 | // Handle download failed errors
508 | if ( !$result ) {
509 |
510 | $response_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
511 | $this->trigger_ajax_failure( "Update Failed: Could not download update." . ( !empty( $response_code ) ? " HTTP Response Code $response_code." : '' ) );
512 |
513 | }
514 |
515 | // Close temp file
516 | fclose( $handle );
517 |
518 | // Prepare ZIP archive
519 | $zip = new ZipArchive;
520 |
521 | if ( $zip->open( $tmp, ZIPARCHIVE::CREATE ) != "true" ) {
522 | $this->trigger_ajax_failure( "Update Failed: Could not open ZIP. Error Code " . $zip->open( $tmp, ZIPARCHIVE::CREATE ) );
523 | }
524 |
525 | // Delete any old backups to make way for our new one
526 | if ( is_dir( MY_MODULES_DIR . '.backup/' . $_POST['module'] ) ){
527 | $rm = $this->delete_directory( MY_MODULES_DIR . '.backup/' . $_POST['module'] );
528 | if ( !$rm )
529 | $this->trigger_ajax_failure( "Update Failed: Could not delete old backup of module. Check your file permissions." );
530 | }
531 |
532 | // Ensure we have a backup of the existing module before proceeding
533 | if( !is_dir( MY_MODULES_DIR . '.backup' ) && mkdir( MY_MODULES_DIR . '.backup', 0775 ) === false ||
534 | !rename( MY_MODULES_DIR . $_POST['module'], MY_MODULES_DIR . '.backup/' . $_POST['module'] ) ) {
535 |
536 | $zip->close();
537 | $this->trigger_ajax_failure( "Update Failed: Could not create temporary backup of existing module. Check your file permissions." );
538 | }
539 | // Create blank index.php file to prevent inadvertantly listing directory contents
540 | @file_put_contents( MY_MODULES_DIR . '.backup/index.php', "extractTo( rtrim( MY_MODULES_DIR, '/' ) );
554 | } catch ( ErrorException $e ) {
555 | $extracted = false;
556 | }
557 |
558 | // Restore default error handler
559 | restore_error_handler();
560 |
561 | // If extraction failed
562 | if ( $extracted == false ) {
563 | $zip->close();
564 | $this->trigger_ajax_failure( "Update Failed: Could not extract ZIP contents of update. Check your file permissions." );
565 | }
566 |
567 | // Attempt to get module directory name from extracted ZIP
568 | $dir = trim( $zip->getNameIndex(0), '/' );
569 | if ( $dir === false ) {
570 | $this->trigger_ajax_failure( "Update Failed: Could not find module folder within extracted files." );
571 | }
572 |
573 | // If directory inside ZIP does not match module name (e.g. Bitbucket ZIP files), rename accordingly.
574 | if ( !is_dir( MY_MODULES_DIR . $_POST['module'] ) ){
575 | $r = rename( MY_MODULES_DIR . $dir, MY_MODULES_DIR . $_POST['module'] );
576 | if ( !$r )
577 | $this->trigger_ajax_failure( "Update Error: Could not rename module directory. Check your bb-modules folder. " . MY_MODULES_DIR . $dir . ' != ' . MY_MODULES_DIR . $_POST['module']);
578 | }
579 |
580 | // Update was successful; remove transient to force count to be updated
581 | delete_transient( "beaver-brewer-updates" );
582 |
583 | // Attempt to remove old module
584 | if ( !$this->delete_directory( MY_MODULES_DIR . '.backup/' . $_POST['module'] ) ) {
585 | echo json_encode(
586 | array(
587 | "success" => 1,
588 | "message" => __("Updated successfully, but could not completely remove the old module. It has been moved to the hidden wp-content/bb-modules/.backup folder instead, where you can manually delete it if desired.", $this->plugin_name )
589 | )
590 | );
591 | $zip->close();
592 |
593 | } else {
594 | // Everything worked perfectly!
595 |
596 | echo json_encode(
597 | array(
598 | "success" => 1,
599 | "message" => __("Updated successfully.", $this->plugin_name )
600 | )
601 | );
602 | $zip->close();
603 | }
604 | exit;
605 | }
606 |
607 |
608 |
609 | /**
610 | * Activate a module.
611 | *
612 | * @since 0.1.0
613 | * @param String $module The module to activate
614 | * @return Boolean True on success, False on failure.
615 | */
616 | public function activate_module( $module ) {
617 |
618 | // First load other modules to check for compatibility issues
619 | $active_modules = Beaver_Brewer::get_modules_active();
620 |
621 | foreach ( $active_modules as $active_module ) {
622 |
623 | // Require all PHP files in main directory
624 | $path = MY_MODULES_DIR . $active_module;
625 | $files = glob( $path . '/*.php' );
626 | if ( !empty( $files ) ) foreach ( $files as $file_path ){
627 | require_once( $file_path );
628 | }
629 | }
630 |
631 | // Now Load New Module
632 | $path = MY_MODULES_DIR . $module;
633 | $files = glob( $path . '/*.php' );
634 |
635 | if ( !empty( $files ) ) foreach ( $files as $file_path ){
636 | require_once( $file_path );
637 | } else {
638 | return false;
639 | }
640 |
641 | // If module is not already listed as active, activate it in DB
642 | if ( !in_array( $module, $active_modules ) )
643 | array_push( $active_modules, $module );
644 |
645 | // Update DB
646 | update_option( "bb-modules-active", $active_modules );
647 | return true;
648 | }
649 |
650 |
651 | /**
652 | * Dectivate a module.
653 | *
654 | * @since 0.1.0
655 | * @param String $module The module to deactivate
656 | * @return Boolean True on success, False if module is not found in active list
657 | */
658 | public function deactivate_module( $module ) {
659 |
660 | // Get active modules, search for specified module, and unset.
661 | $active_modules = Beaver_Brewer::get_modules_active();
662 | $key = array_search( $module, $active_modules, true );
663 |
664 | if ( $key !== false ) {
665 | unset( $active_modules[$key] );
666 | update_option( "bb-modules-active", $active_modules );
667 | return true;
668 | }
669 | return false;
670 | }
671 |
672 |
673 |
674 | /**
675 | * Delete a module.
676 | *
677 | * @since 0.1.0
678 | * @param String $module The module to delete
679 | */
680 | public function delete_module( $module ) {
681 |
682 | // First deactivate module
683 | $this->deactivate_module( $module );
684 |
685 | // Attempt to delete folder
686 | return $this->delete_directory( MY_MODULES_DIR . $module );
687 | }
688 |
689 |
690 | /**
691 | * Deactivate a module via Ajax.
692 | *
693 | * Echoes a JSON-encoded response.
694 | *
695 | * @since 0.1.0
696 | */
697 | public function activate_ajax() {
698 |
699 | check_ajax_referer( 'beaver-brewer-admin', '_ajax_nonce' );
700 |
701 | header( "Content-Type:application/json" );
702 |
703 | /*
704 | * Make sure all data we need are present
705 | */
706 | if ( !isset( $_POST['module'] ) ) {
707 | echo json_encode(
708 | array(
709 | "success" => 0,
710 | "message" => __( "No module specified.", $this->plugin_name )
711 | )
712 | );
713 | exit;
714 | }
715 |
716 | $module = $_POST['module'];
717 |
718 | ob_start();
719 |
720 | $success = $this->activate_module( $module );
721 |
722 | if ( $success && ob_get_length() > 0 ) {
723 |
724 | echo json_encode(
725 | array(
726 | "success" => 1,
727 | "message" => __( "The module was activated, but it generated some unexpected output. If you experience any \"headers already sent\" errors, try deactivating the module.", $this->plugin_name )
728 | )
729 | );
730 | exit;
731 | } elseif ( !$success ) {
732 | $this->trigger_ajax_failure( "This module could not be activated because it does not appear to contain any valid PHP files." );
733 | }
734 | ob_end_clean();
735 |
736 |
737 | // Check to see that activation succeeded
738 | if ( !Beaver_Brewer::is_module_active( $module ) ) {
739 | $this->trigger_ajax_failure( "The module failed to activate for an unknown reason." );
740 | } else {
741 | echo json_encode(
742 | array(
743 | "success" => 1,
744 | "message" => __( "The module is now active.", $this->plugin_name )
745 | )
746 | );
747 | }
748 |
749 | exit;
750 |
751 | }
752 |
753 |
754 | /**
755 | * Deactivate a module via Ajax.
756 | *
757 | * Echoes a JSON-encoded response.
758 | *
759 | * @since 0.1.0
760 | */
761 | public function deactivate_ajax() {
762 |
763 | check_ajax_referer( 'beaver-brewer-admin', '_ajax_nonce' );
764 |
765 | header( "Content-Type:application/json" );
766 |
767 | /*
768 | * Make sure all data we need are present
769 | */
770 | if ( !isset( $_POST['module'] ) ) {
771 | $this->trigger_ajax_failure( "No module specified." );
772 | }
773 |
774 | $module = $_POST['module'];
775 | $this->deactivate_module( $module );
776 |
777 | // Check to see that deactivation succeeded
778 | if ( Beaver_Brewer::is_module_active( $module ) ) {
779 | $this->trigger_ajax_failure( "The module failed to deactivate for an unknown (and, quite frankly, upsetting) reason." );
780 | } else {
781 | echo json_encode(
782 | array(
783 | "success" => 1,
784 | "message" => __( "The module is no longer active.", $this->plugin_name )
785 | )
786 | );
787 | }
788 |
789 | exit;
790 | }
791 |
792 |
793 | /**
794 | * Deletes a module via Ajax.
795 | *
796 | * Echoes a JSON-encoded response.
797 | *
798 | * @since 0.1.0
799 | */
800 | public function delete_ajax() {
801 |
802 | check_ajax_referer( 'beaver-brewer-admin', '_ajax_nonce' );
803 |
804 | header( "Content-Type:application/json" );
805 |
806 | /*
807 | * Make sure all data we need are present
808 | */
809 | if ( !isset( $_POST['module'] ) ) {
810 | $this->trigger_ajax_failure( "No module specified." );
811 | }
812 |
813 | $module = $_POST['module'];
814 | $result = $this->delete_module( $module );
815 |
816 | // Check to see that deletion succeeded
817 | if ( $result !== true ) {
818 | $this->trigger_ajax_failure( "Failed to delete the module (this is probably a permissions issue). You will need to delete it manually." );
819 | } else {
820 | echo json_encode(
821 | array(
822 | "success" => 1,
823 | "message" => __( "The module has been deleted.", $this->plugin_name )
824 | )
825 | );
826 | }
827 |
828 | exit;
829 | }
830 |
831 | /**
832 | * Get a list of all installed modules
833 | *
834 | * Note that this does not translate strings (so that you can pass HTML in your message if desired).
835 | * You will therefore need to translate your title/message BEFORE passing it to this function.
836 | *
837 | * @since 0.1.0
838 | * @param String $title The title of the message, if any (appears before message, inside tags)
839 | * @param String $message The message itself
840 | * @param String $type The type of message ('error' or 'updated') which will become the container div class.
841 | */
842 | public function print_message( $title = '', $message = '', $type = 'updated' ) {
843 |
844 | echo "";
845 | echo '
';
846 | echo "$title: $message";
847 | echo '
';
848 | echo '
';
849 |
850 | }
851 |
852 |
853 | /**
854 | * Checks if the bb-modules directory has been created. If not, attempts to create it.
855 | *
856 | * @since 0.1.0
857 | * @return Boolean true if the directory exists or is successfully created; otherwise false.
858 | */
859 | public function check_directory() {
860 |
861 | if ( !is_dir( WP_CONTENT_DIR . '/bb-modules' ) ) {
862 |
863 | $result = mkdir( WP_CONTENT_DIR . '/bb-modules', 0775 );
864 |
865 | if ( $result ){
866 |
867 | $this->print_message(
868 | __( "Beaver Brewer Ready", $this->plugin_name ),
869 | __( "Automatically created the bb-modules directory inside your Wordpress 'wp-content' directory. You're all set!", $this->plugin_name )
870 | );
871 |
872 | return true;
873 |
874 | } else {
875 |
876 | $this->print_message(
877 | __( "Beaver Brewer Warning", $this->plugin_name ),
878 | __( "Could not automatically create bb-modules directory. This is probably a permissions issue. In order for Beaver Brewer to work, you will need to manually create a directory called 'bb-modules' inside your Wordpress 'wp-content' directory.", $this->plugin_name ),
879 | 'error'
880 | );
881 |
882 | return false;
883 |
884 | }
885 |
886 | }
887 | return true;
888 | }
889 |
890 |
891 | /**
892 | * Handle uploaded files.
893 | *
894 | * @since 0.1.0
895 | */
896 | public function upload_ajax() {
897 |
898 | header("Content-Type: application/json");
899 |
900 | check_ajax_referer( "module-upload" );
901 |
902 | $file = $_FILES['async-upload'];
903 | $status = wp_handle_upload( $file, array( 'test_form'=>true, 'action' => 'beaver_brewer_upload' ) );
904 |
905 |
906 | if ( empty( $status['file'] ) ) {
907 | $this->trigger_ajax_failure( "The file upload failed. Check your error log for more info." );
908 | } else {
909 |
910 | // Prepare ZIP archive
911 | $zip = new ZipArchive;
912 |
913 | if ( $zip->open( $status['file'] ) != "true" ) {
914 | $this->trigger_ajax_failure( "Failed to read from ZIP. Make sure your archive isn't corrupt." );
915 | }
916 |
917 | // Set temporary error handler
918 | set_error_handler( function( $errno, $errstr, $errfile, $errline ) {
919 |
920 | // error was suppressed with the @-operator
921 | if ( 0 === error_reporting() ) {
922 | return false;
923 | }
924 |
925 | throw new ErrorException( $errstr, 0, $errno, $errfile, $errline );
926 | });
927 |
928 | try {
929 | $extracted = $zip->extractTo( rtrim( MY_MODULES_DIR, '/' ) );
930 | } catch ( ErrorException $e ) {
931 | $extracted = false;
932 | }
933 |
934 | // Restore default error handler
935 | restore_error_handler();
936 |
937 | // If extraction failed
938 | if ( $extracted == false ) {
939 | $zip->close();
940 | $this->trigger_ajax_failure( "Failed to extract ZIP contents of update. Check your file permissions." );
941 | }
942 |
943 | $zip->close();
944 | echo json_encode(
945 | array(
946 | "success" => 1,
947 | "message" => __( "The module was successfully installed.", $this->plugin_name )
948 | )
949 | );
950 |
951 | exit;
952 | }
953 | }
954 |
955 |
956 |
957 | /**
958 | * Install module in one click.
959 | *
960 | * @since 0.4.0
961 | * @param String $source An encoded URL from which to retrieve the module package.
962 | * @return Boolean Whether or not installation succeeded.
963 | */
964 | public function install_module( $source ) {
965 |
966 | $temp_file = download_url( urldecode( $source ), 300 );
967 |
968 | if ( is_wp_error( $temp_file ) ) {
969 | _e( "Installation Failed: Could not download package. Check your error log for more info.", $this->plugin_name );
970 | return false;
971 | } else {
972 |
973 | // Prepare ZIP archive
974 | $zip = new ZipArchive;
975 |
976 | if ( $zip->open( $temp_file ) != "true" ) {
977 | _e( "Installation Failed: Cannot read from package.", $this->plugin_name );
978 | return false;
979 | }
980 |
981 | // Set temporary error handler
982 | set_error_handler( function( $errno, $errstr, $errfile, $errline ) {
983 |
984 | // error was suppressed with the @-operator
985 | if ( 0 === error_reporting() ) {
986 | return false;
987 | }
988 |
989 | throw new ErrorException( $errstr, 0, $errno, $errfile, $errline );
990 | });
991 |
992 | try {
993 | $extracted = $zip->extractTo( rtrim( MY_MODULES_DIR, '/' ) );
994 | } catch ( ErrorException $e ) {
995 | $extracted = false;
996 | }
997 |
998 | // Restore default error handler
999 | restore_error_handler();
1000 |
1001 | // If extraction failed
1002 | if ( $extracted == false ) {
1003 | $zip->close();
1004 | _e( "Installation Failed: Could not extract update. Check your file permissions.", $this->plugin_name );
1005 | return false;
1006 | }
1007 |
1008 | $zip->close();
1009 | _e( "Success! The module has been installed.", $this->plugin_name );
1010 | return true;
1011 | }
1012 | }
1013 |
1014 |
1015 |
1016 | /**
1017 | * Register the stylesheets for the admin area.
1018 | *
1019 | * @since 0.1.0
1020 | */
1021 | public function enqueue_styles() {
1022 |
1023 | wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/beaver-brewer-admin.css', array(), $this->version, 'all' );
1024 |
1025 | }
1026 |
1027 | /**
1028 | * Register the JavaScript for the admin area.
1029 | *
1030 | * @since 0.1.0
1031 | */
1032 | public function enqueue_scripts( $hook ) {
1033 |
1034 | if ( $hook == "toplevel_page_beaver-brewer" ){
1035 |
1036 | wp_register_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/beaver-brewer-admin.js', array( 'jquery', 'plupload-all' ), $this->version, false );
1037 |
1038 | // Get plupload config for file uploads
1039 | $plupload_config = array(
1040 | 'runtimes' => 'html5,silverlight,flash,html4',
1041 | 'browse_button' => 'module-install-button',
1042 | 'container' => 'installed-modules',
1043 | 'drop_element' => 'module-list',
1044 | 'file_data_name' => 'async-upload',
1045 | 'multiple_queues' => true,
1046 | 'max_file_size' => wp_max_upload_size().'b',
1047 | 'url' => admin_url('admin-ajax.php'),
1048 | 'flash_photos_url' => includes_url('js/plupload/plupload.flash.swf'),
1049 | 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'),
1050 | 'filters' => array(array('title' => __('Allowed Files'), 'extensions' => 'zip')),
1051 | 'multipart' => true,
1052 | 'urlstream_upload' => true,
1053 |
1054 | // Additional post data to send to the ajax hook
1055 | 'multipart_params' => array(
1056 | '_ajax_nonce' => wp_create_nonce( 'module-upload' ),
1057 | 'action' => 'beaver_brewer_upload', // the ajax action name
1058 | ),
1059 | );
1060 |
1061 | $plupload_init = apply_filters( 'plupload_init', $plupload_config );
1062 |
1063 | // Localize some configuration options / translated strings
1064 | $bb_config = array(
1065 | "pluploadConfig" => $plupload_config,
1066 | "ajaxNonce" => wp_create_nonce( "beaver-brewer-admin" ),
1067 | "activationFatalError" => __( "The module could not be activated because it triggered a fatal error. Check your error log for more info." ),
1068 | "moduleDeleteConfirm" => __( "Warning: You are about to delete a module, which will result in all of its files being removed. You cannot undo this action, so it's recommended that you have a backup handy. \n\nAre you sure you want to continue?" ),
1069 | "moduleUpdateError" => __( "Failed to update module. Check your file permissions and your error log for more info." ),
1070 | "installedModulesText" => __( "Installed Modules" ),
1071 | "dropToUploadText" => __( "Install Module: Drop File to Begin Upload" )
1072 | );
1073 |
1074 | wp_localize_script( $this->plugin_name, "BeaverBrewer", $bb_config );
1075 |
1076 | wp_enqueue_script( $this->plugin_name );
1077 | }
1078 | }
1079 | }
1080 |
--------------------------------------------------------------------------------
/admin/css/beaver-brewer-admin.css:
--------------------------------------------------------------------------------
1 | /**
2 | * All of the CSS for your admin-specific functionality should be
3 | * included in this file.
4 | */
5 |
6 | .clearfix:after {
7 | content: "";
8 | display: table;
9 | clear: both;
10 | }
11 |
12 | #installed-modules,
13 | #find-more-modules {
14 | background-color:#ffffff;
15 | padding:2em;
16 | border:1px solid #ddd;
17 | }
18 |
19 | .drag-drop .drag-drop-inside {
20 | width:100%;
21 | text-align:left;
22 | margin:20px 0 0;
23 | }
24 |
25 | .drag-drop .drag-drop-inside p {
26 | text-align:left;
27 | }
28 |
29 | #installed-modules.drag-over {
30 | background:#00a0d2;
31 | border-color: #008EC2;
32 | }
33 |
34 | #installed-modules.drag-over h2 {
35 | color:#ffffff;
36 | }
37 |
38 | #installed-modules.drag-over #module-install-button {
39 | display:none;
40 | }
41 |
42 | #installed-modules.drag-over #module-list {
43 | opacity:0;
44 | }
45 |
46 | #module-list .single-module {
47 | margin:1em 5px 1em 0;
48 | padding: 1em 1em 2em;
49 | background:#f4f4f4;
50 | max-width:680px;
51 | border:1px solid #eee;
52 | border-left:4px solid #ccc;
53 | }
54 |
55 | #module-list .single-module.module-active {
56 | background-color:#f7fcfe;
57 | border-left: 4px solid #00a0d2;
58 | }
59 |
60 | #module-list .single-module.module-failed {
61 | background-color:#fff2f5;
62 | border-left: 4px solid #bb0000;
63 | }
64 |
65 | #module-list .single-module.update-available {
66 | background-color:#fef7f1;
67 | border-left: 4px solid #d54e21;
68 | }
69 |
70 | #module-list .single-module .module-name {
71 | font-weight:700;
72 | }
73 |
74 | #module-list .single-module .module-version {
75 | font-style:italic;
76 | color:#555;
77 | }
78 |
79 | #module-list .single-module .module-actions {
80 | margin:.5em 0;
81 | }
82 |
83 | #module-list .single-module .module-url {
84 | margin: 0 0 1em 0;
85 | }
86 |
87 | #module-list .single-module .module-url a {
88 | text-decoration:none;
89 | }
90 |
91 | #module-list .single-module .module-url a:hover {
92 | text-decoration:underline;
93 | }
94 |
95 | #module-list .single-module .module-updates {
96 | padding:1em;
97 | background:rgba(255,255,255,.7);
98 | border:1px solid rgba(50,50,50,.3);
99 | margin:1em 0;
100 | }
101 |
102 | #module-list .single-module .module-messages {
103 | margin:1.5em 0 0;
104 | padding:.25em .5em;
105 | display:none;
106 | }
107 |
108 | #module-list .single-module .module-messages.success:before {
109 | color: #00bb00;
110 | font-family:dashicons;
111 | font-size:1.5em;
112 | margin-right:5px;
113 | line-height:1em;
114 | vertical-align:middle;
115 | content: "\f147";
116 | }
117 |
118 | #module-list .single-module .module-messages.failure:before {
119 | color: #bb0000;
120 | font-family:dashicons;
121 | font-size:1.5em;
122 | margin-right:5px;
123 | line-height:1em;
124 | vertical-align:middle;
125 | content: "\f158";
126 | }
127 |
128 | #find-more-modules a {
129 | text-decoration:none;
130 | }
131 |
132 | #find-more-modules .module-directory-toolbar a {
133 | margin: 0 0 15px 0;
134 | display:block;
135 | }
136 |
137 | #find-more-modules .module-directory-toolbar strong {
138 | margin: 5px 5px 15px 0;
139 | }
140 |
141 | #find-more-modules .module-directory-toolbar .toolbar-section {
142 | margin: 0 30px 15px 0;
143 | display:inline-block;
144 | }
145 |
146 |
147 | #find-more-modules .module-directory-toolbar form {
148 | display:block;
149 | margin: 0 auto 30px;
150 | }
151 |
152 | #find-more-modules .module-directory-toolbar .active-orderby,
153 | #find-more-modules .module-directory-toolbar .active-filter {
154 | background:#009FFD;
155 | border-right:1px solid #009FFD;
156 | border-left: 1px solid #009FFD;
157 | color:#fff;
158 | }
159 |
160 | #find-more-modules #filter-module-results {
161 | margin: 0 20px 10px;
162 | display:inline-block;
163 | vertical-align:top;
164 | display:none;
165 | }
166 |
167 | @media screen and (min-width: 783px) {
168 | #find-more-modules .module-directory-toolbar form {
169 | float:right;
170 | margin: 0 15px 15px 0;
171 | }
172 | #find-more-modules .module-directory-toolbar a {
173 | margin: 5px 0 15px;
174 | padding: 0 8px;
175 | border-right:1px solid #999;
176 | border-left:1px solid transparent;
177 | float:left;
178 | }
179 |
180 | #find-more-modules .module-directory-toolbar strong {
181 | float:left;
182 | }
183 |
184 |
185 | #find-more-modules .module-directory-toolbar a:last-child {
186 | border-right:1px solid transparent;
187 | }
188 | }
189 |
190 | #module-results > ul {
191 | flex-wrap:wrap;
192 | align-items:stretch;
193 | flex-direction: row;
194 | display: -webkit-flex;
195 | display: -ms-flexbox;
196 | display: flex;
197 | overflow: hidden;
198 | }
199 |
200 | #module-results .single-module {
201 | padding:1em;
202 | background-color:#eee;
203 | border:1px solid #ccc;
204 | margin:0 1em 1em 0;
205 | display:block;
206 | width:280px;
207 | min-width:250px;
208 | vertical-align:top;
209 | flex:1;
210 | }
211 |
212 | #module-results .single-module span.paid {
213 | color: #f0c030;
214 | }
215 |
216 | #module-results .single-module .install-now {
217 | margin: 15px 0;
218 | }
219 |
220 | #module-results .pagination {
221 | clear:both;
222 | padding:15px 0 0;
223 | color:#777;
224 | }
225 |
226 | #module-results .pagination .pagination-links {
227 | margin:15px 0;
228 | }
229 |
230 | #module-results .pagination .pagination-links li {
231 | display:inline-block;
232 | margin: 5px 2px;
233 | }
234 |
235 | #module-results .pagination .pagination-links li a {
236 | padding:4px 8px;
237 | border:1px solid #ccc;
238 | text-decoration:none;
239 | }
240 |
241 | #install-result .button-primary,
242 | #install-result .button-secondary {
243 | margin: 5px 0;
244 | }
245 |
246 | @media screen and ( max-width:782px ) {
247 | .module-directory-toolbar input[type=submit] {
248 | padding: 6px 10px;
249 | height:36px;
250 | }
251 | }
--------------------------------------------------------------------------------
/admin/index.php:
--------------------------------------------------------------------------------
1 | Uploading ' + file.name + '...').hide().slideDown(300);
210 | });
211 |
212 | up.refresh();
213 | up.start();
214 | });
215 |
216 | // File uploaded
217 | uploader.bind('FileUploaded', function(up, file, response) {
218 | var response = $.parseJSON(response.response);
219 | window.location.reload();
220 | });
221 |
222 | });
223 |
224 |
225 | })( jQuery );
226 |
--------------------------------------------------------------------------------
/admin/partials/beaver-brewer-admin-display.php:
--------------------------------------------------------------------------------
1 |
15 |
16 |
17 |
18 |
plugin_name ); ?>
19 |
20 | check_directory(); ?>
21 |
22 |
23 |
24 | get_admin_page_tabs(); ?>
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
plugin_name ); ?>
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | plugin_name ); ?>
52 | plugin_name ); ?>
53 |
54 |
--------------------------------------------------------------------------------
/admin/partials/beaver-brewer-tab-find-more.php:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
plugin_name ); ?>
20 |
21 |
22 |
55 |
56 |
57 | prepare_module_results(); ?>
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/admin/partials/beaver-brewer-tab-install.php:
--------------------------------------------------------------------------------
1 |
13 |
14 |
15 |
plugin_name ); ?>
16 |
41 |
42 |
--------------------------------------------------------------------------------
/admin/partials/beaver-brewer-tab-my-modules.php:
--------------------------------------------------------------------------------
1 |
13 |
14 |
15 |
plugin_name ); ?>
16 |
plugin_name ); ?>
17 |
18 |
19 |
20 | modules ) ): ?>
21 |
22 | modules as $module ): ?>
23 |
24 | check_updates( $module ); ?>
25 |
26 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | Version .
38 |
39 |
40 |
41 | ' . $module['description'] . '' : '' ); ?>
42 |
43 |
44 |
45 | → More Information' : '' ); ?>
46 |
47 |
48 | get_latest( $module['updates'] ) : false ); ?>
49 |
74 |
75 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
plugin_name ); ?>
101 |
102 |
103 | plugin_name ); ?>
104 | plugin_name ); ?>
105 |
106 |
107 |
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/beaver-brewer.php:
--------------------------------------------------------------------------------
1 | run();
77 |
78 | }
79 | run_beaver_brewer();
80 |
--------------------------------------------------------------------------------
/includes/class-beaver-brewer-activator.php:
--------------------------------------------------------------------------------
1 |
22 | */
23 | class Beaver_Brewer_Activator {
24 |
25 | /**
26 | * Short Description. (use period)
27 | *
28 | * Long Description.
29 | *
30 | * @since 0.1.0
31 | */
32 | public static function activate() {
33 |
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/includes/class-beaver-brewer-deactivator.php:
--------------------------------------------------------------------------------
1 |
22 | */
23 | class Beaver_Brewer_Deactivator {
24 |
25 | /**
26 | * Short Description. (use period)
27 | *
28 | * Long Description.
29 | *
30 | * @since 0.1.0
31 | */
32 | public static function deactivate() {
33 |
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/includes/class-beaver-brewer-i18n.php:
--------------------------------------------------------------------------------
1 |
26 | */
27 | class Beaver_Brewer_i18n {
28 |
29 |
30 | /**
31 | * Load the plugin text domain for translation.
32 | *
33 | * @since 0.1.0
34 | */
35 | public function load_plugin_textdomain() {
36 |
37 | load_plugin_textdomain(
38 | 'beaver-brewer',
39 | false,
40 | dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
41 | );
42 |
43 | }
44 |
45 |
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/includes/class-beaver-brewer-loader.php:
--------------------------------------------------------------------------------
1 |
23 | */
24 | class Beaver_Brewer_Loader {
25 |
26 | /**
27 | * The array of actions registered with WordPress.
28 | *
29 | * @since 0.1.0
30 | * @access protected
31 | * @var array $actions The actions registered with WordPress to fire when the plugin loads.
32 | */
33 | protected $actions;
34 |
35 | /**
36 | * The array of filters registered with WordPress.
37 | *
38 | * @since 0.1.0
39 | * @access protected
40 | * @var array $filters The filters registered with WordPress to fire when the plugin loads.
41 | */
42 | protected $filters;
43 |
44 | /**
45 | * Initialize the collections used to maintain the actions and filters.
46 | *
47 | * @since 0.1.0
48 | */
49 | public function __construct() {
50 |
51 | $this->actions = array();
52 | $this->filters = array();
53 |
54 | }
55 |
56 | /**
57 | * Add a new action to the collection to be registered with WordPress.
58 | *
59 | * @since 0.1.0
60 | * @param string $hook The name of the WordPress action that is being registered.
61 | * @param object $component A reference to the instance of the object on which the action is defined.
62 | * @param string $callback The name of the function definition on the $component.
63 | * @param int $priority Optional. he priority at which the function should be fired. Default is 10.
64 | * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
65 | */
66 | public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
67 | $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
68 | }
69 |
70 | /**
71 | * Add a new filter to the collection to be registered with WordPress.
72 | *
73 | * @since 0.1.0
74 | * @param string $hook The name of the WordPress filter that is being registered.
75 | * @param object $component A reference to the instance of the object on which the filter is defined.
76 | * @param string $callback The name of the function definition on the $component.
77 | * @param int $priority Optional. he priority at which the function should be fired. Default is 10.
78 | * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
79 | */
80 | public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
81 | $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
82 | }
83 |
84 | /**
85 | * A utility function that is used to register the actions and hooks into a single
86 | * collection.
87 | *
88 | * @since 0.1.0
89 | * @access private
90 | * @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
91 | * @param string $hook The name of the WordPress filter that is being registered.
92 | * @param object $component A reference to the instance of the object on which the filter is defined.
93 | * @param string $callback The name of the function definition on the $component.
94 | * @param int $priority The priority at which the function should be fired.
95 | * @param int $accepted_args The number of arguments that should be passed to the $callback.
96 | * @return array The collection of actions and filters registered with WordPress.
97 | */
98 | private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
99 |
100 | $hooks[] = array(
101 | 'hook' => $hook,
102 | 'component' => $component,
103 | 'callback' => $callback,
104 | 'priority' => $priority,
105 | 'accepted_args' => $accepted_args
106 | );
107 |
108 | return $hooks;
109 |
110 | }
111 |
112 | /**
113 | * Register the filters and actions with WordPress.
114 | *
115 | * @since 0.1.0
116 | */
117 | public function run() {
118 |
119 | foreach ( $this->filters as $hook ) {
120 | add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
121 | }
122 |
123 | foreach ( $this->actions as $hook ) {
124 | add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
125 | }
126 |
127 | }
128 |
129 | }
130 |
--------------------------------------------------------------------------------
/includes/class-beaver-brewer.php:
--------------------------------------------------------------------------------
1 |
29 | */
30 | class Beaver_Brewer {
31 |
32 | /**
33 | * The loader that's responsible for maintaining and registering all hooks that power
34 | * the plugin.
35 | *
36 | * @since 0.1.0
37 | * @access protected
38 | * @var Beaver_Brewer_Loader $loader Maintains and registers all hooks for the plugin.
39 | */
40 | protected $loader;
41 |
42 | /**
43 | * The unique identifier of this plugin.
44 | *
45 | * @since 0.1.0
46 | * @access protected
47 | * @var string $plugin_name The string used to uniquely identify this plugin.
48 | */
49 | protected $plugin_name;
50 |
51 | /**
52 | * The basename of the plugin (path to plugin file relative to plugins directory).
53 | *
54 | * @since 0.1.0
55 | * @access protected
56 | * @var string $plugin_basenamename The basename of this plugin.
57 | */
58 | protected $plugin_basename;
59 |
60 | /**
61 | * The current version of the plugin.
62 | *
63 | * @since 0.1.0
64 | * @access protected
65 | * @var string $version The current version of the plugin.
66 | */
67 | protected $version;
68 |
69 | /**
70 | * Define the core functionality of the plugin.
71 | *
72 | * Set the plugin name and the plugin version that can be used throughout the plugin.
73 | * Load the dependencies, define the locale, and set the hooks for the admin area and
74 | * the public-facing side of the site.
75 | *
76 | * @since 0.1.0
77 | * @param $basename The plugin basename
78 | */
79 | public function __construct( $basename ) {
80 |
81 | $this->plugin_name = 'beaver-brewer';
82 | $this->version = '0.1.0';
83 | $this->plugin_basename = $basename;
84 |
85 | $this->load_dependencies();
86 |
87 | /**
88 | * Check for external dependencies.
89 | */
90 | $this->loader = new Beaver_Brewer_Loader();
91 | $this->loader->add_action( 'plugins_loaded', $this, 'dependency_check' );
92 |
93 | $this->set_locale();
94 | $this->updater_init();
95 | $this->define_admin_hooks();
96 | $this->define_public_hooks();
97 |
98 | define( 'MY_MODULES_DIR', WP_CONTENT_DIR . '/bb-modules/' );
99 | define( 'MY_MODULES_URL', WP_CONTENT_URL . '/bb-modules/' );
100 | }
101 |
102 | /**
103 | * Load the required dependencies for this plugin.
104 | *
105 | * Include the following files that make up the plugin:
106 | *
107 | * - Beaver_Brewer_Loader. Orchestrates the hooks of the plugin.
108 | * - Beaver_Brewer_i18n. Defines internationalization functionality.
109 | * - Beaver_Brewer_Admin. Defines all hooks for the admin area.
110 | *
111 | * Create an instance of the loader which will be used to register the hooks
112 | * with WordPress.
113 | *
114 | * @since 0.1.0
115 | * @access private
116 | */
117 | private function load_dependencies() {
118 |
119 | /**
120 | * The class responsible for orchestrating the actions and filters of the
121 | * core plugin.
122 | */
123 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-beaver-brewer-loader.php';
124 |
125 | /**
126 | * The class responsible for defining internationalization functionality
127 | * of the plugin.
128 | */
129 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-beaver-brewer-i18n.php';
130 |
131 | /**
132 | * The class responsible for defining all actions that occur in the admin area.
133 | */
134 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-beaver-brewer-admin.php';
135 |
136 | /**
137 | * The class responsible for defining all actions that occur on the public side of the site.
138 | */
139 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-beaver-brewer-public.php';
140 |
141 | /**
142 | * The script responsible for updating the plugin.
143 | */
144 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/plugin-update-checker/plugin-update-checker.php';
145 |
146 | }
147 |
148 | /**
149 | * Define the locale for this plugin for internationalization.
150 | *
151 | * Uses the Beaver_Brewer_i18n class in order to set the domain and to register the hook
152 | * with WordPress.
153 | *
154 | * @since 0.1.0
155 | * @access private
156 | */
157 | private function set_locale() {
158 |
159 | $plugin_i18n = new Beaver_Brewer_i18n();
160 | $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
161 |
162 | }
163 |
164 | /**
165 | * Initialize the plugin updater class
166 | *
167 | * @since 0.1.0
168 | * @access private
169 | */
170 | private function updater_init() {
171 |
172 | $className = PucFactory::getLatestClassVersion( 'PucGitHubChecker' );
173 | $myUpdateChecker = new $className(
174 | 'https://github.com/rbenhase/beaver-brewer/',
175 | PLUGIN_MAIN,
176 | 'master'
177 | );
178 |
179 | }
180 |
181 | /**
182 | * Register all of the hooks related to the admin area functionality.
183 | *
184 | * @since 0.1.0
185 | * @access private
186 | */
187 | private function define_admin_hooks() {
188 |
189 | $plugin_admin = new Beaver_Brewer_Admin( $this->get_plugin_name(), $this->get_version(), self::get_modules() );
190 |
191 | $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
192 | $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
193 | $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_menu_page' );
194 | $this->loader->add_action( 'wp_ajax_beaver_brewer_auto_update', $plugin_admin, 'auto_update_ajax' );
195 | $this->loader->add_action( 'wp_ajax_beaver_brewer_activate', $plugin_admin, 'activate_ajax' );
196 | $this->loader->add_action( 'wp_ajax_beaver_brewer_deactivate', $plugin_admin, 'deactivate_ajax' );
197 | $this->loader->add_action( 'wp_ajax_beaver_brewer_delete', $plugin_admin, 'delete_ajax' );
198 | $this->loader->add_action( 'wp_ajax_beaver_brewer_upload', $plugin_admin, 'upload_ajax' );
199 | }
200 |
201 | /**
202 | * Register all of the hooks related to the public/front-facing functionality.
203 | *
204 | * @since 0.1.0
205 | * @access private
206 | */
207 | private function define_public_hooks() {
208 |
209 | if( !is_admin() ) {
210 | $plugin_public = new Beaver_Brewer_Public( $this->get_plugin_name(), $this->get_version(), self::get_modules() );
211 | $this->loader->add_action( 'init', $plugin_public, 'register_modules' );
212 | }
213 | }
214 |
215 |
216 | /**
217 | * Run the loader to execute all of the hooks with WordPress.
218 | *
219 | * @since 0.1.0
220 | */
221 | public function run() {
222 | $this->loader->run();
223 | }
224 |
225 | /**
226 | * The name of the plugin used to uniquely identify it within the context of
227 | * WordPress and to define internationalization functionality.
228 | *
229 | * @since 0.1.0
230 | * @return string The name of the plugin.
231 | */
232 | public function get_plugin_name() {
233 | return $this->plugin_name;
234 | }
235 |
236 | /**
237 | * The reference to the class that orchestrates the hooks with the plugin.
238 | *
239 | * @since 0.1.0
240 | * @return Beaver_Brewer_Loader Orchestrates the hooks of the plugin.
241 | */
242 | public function get_loader() {
243 | return $this->loader;
244 | }
245 |
246 | /**
247 | * Retrieve the version number of the plugin.
248 | *
249 | * @since 0.1.0
250 | * @return string The version number of the plugin.
251 | */
252 | public function get_version() {
253 | return $this->version;
254 | }
255 |
256 |
257 | /**
258 | * Get installed modules
259 | *
260 | * @since 0.1.0
261 | * @return Array $modules All installed modules
262 | */
263 | public static function get_modules() {
264 |
265 | $modules = array();
266 |
267 | // Get directory listing
268 | $directory_contents = glob( WP_CONTENT_DIR . '/bb-modules/*' );
269 |
270 | // Make sure each subdirectory at least contains a PHP file
271 | foreach ( $directory_contents as $subdirectory ) {
272 |
273 | $module_settings = array();
274 | $glob = glob( $subdirectory . '/*.php' );
275 |
276 | if ( is_dir( $subdirectory ) && basename( $subdirectory ) != '.backup' && !empty ( $glob ) ) {
277 | $module_settings['path'] = $subdirectory;
278 | $module_settings['name'] = basename( $subdirectory );
279 |
280 | // Set default nicename if no module.config file exists
281 | $module_settings['nicename'] = basename( $subdirectory );
282 |
283 | // Attempt to get real nicename from config file
284 | if ( file_exists( $subdirectory . '/module.config' ) ) {
285 |
286 | $data = get_file_data(
287 | $subdirectory . '/module.config',
288 | array(
289 | "ModuleName" => "Module Name",
290 | "ModuleSlug" => "Module Slug",
291 | "ModuleVersion" => "Module Version",
292 | "ShortDescription" => "Short Description",
293 | "AuthorName" => "Author Name",
294 | "AuthorURL" => "Author URL",
295 | "UpdateURL" => "Update URL",
296 | "DownloadZIP" => "Download ZIP",
297 | "MoreInfo" => "More Info URL"
298 | )
299 | );
300 |
301 | if ( !empty( $data['ModuleName'] ) )
302 | $module_settings['nicename'] = $data['ModuleName'];
303 |
304 | if ( !empty( $data['ModuleVersion'] ) )
305 | $module_settings['version'] = $data['ModuleVersion'];
306 |
307 | if ( !empty( $data['ModuleSlug'] ) )
308 | $module_settings['slug'] = $data['ModuleSlug'];
309 |
310 | if ( !empty( $data['ShortDescription'] ) )
311 | $module_settings['description'] = $data['ShortDescription'];
312 |
313 | if ( !empty( $data['AuthorName'] ) )
314 | $module_settings['author'] = $data['AuthorName'];
315 |
316 | if ( !empty( $data['AuthorURL'] ) )
317 | $module_settings['author-url'] = $data['AuthorURL'];
318 |
319 | if ( !empty( $data['UpdateURL'] ) )
320 | $module_settings['updates'] = $data['UpdateURL'];
321 |
322 | if ( !empty( $data['DownloadZIP'] ) )
323 | $module_settings['download'] = $data['DownloadZIP'];
324 |
325 | if ( !empty( $data['MoreInfo'] ) )
326 | $module_settings['more-url'] = $data['MoreInfo'];
327 | }
328 |
329 | if ( self::is_module_active( $module_settings['name'] ) )
330 | $module_settings['active'] = true;
331 |
332 | $modules[] = $module_settings;
333 | }
334 | }
335 |
336 | return $modules;
337 | }
338 |
339 |
340 | /**
341 | * Get active modules.
342 | *
343 | * @since 0.3.0
344 | * @param String $module_slug The machine-readable module slug
345 | * @return Boolean Whether or not the module is installed
346 | */
347 | public static function module_exists( $module_slug ) {
348 |
349 | $modules = self::get_modules();
350 |
351 | foreach ( $modules as $module ) {
352 | if ( $module['name'] == $module_slug )
353 | return true;
354 | }
355 | return false;
356 | }
357 |
358 |
359 |
360 | /**
361 | * Get active modules.
362 | *
363 | * @since 0.1.0
364 | * @return Array $active_modules All active modules
365 | */
366 | public static function get_modules_active() {
367 |
368 | // Get list of modules from DB.
369 | $active_modules = get_option( "bb-modules-active" );
370 |
371 | // If we are not working with an array (e.g. option value is false), fix that.
372 | if ( !is_array( $active_modules ) )
373 | $active_modules = array();
374 |
375 | return $active_modules;
376 | }
377 |
378 |
379 | /**
380 | * See if module is active.
381 | *
382 | * @since 0.1.0
383 | * @param String $module Module to check
384 | * @return Boolean True if active, false if not.
385 | */
386 | public static function is_module_active( $module ) {
387 |
388 | $active_modules = self::get_modules_active();
389 |
390 | if ( in_array( $module, $active_modules ) )
391 | return true;
392 |
393 | return false;
394 | }
395 |
396 |
397 |
398 |
399 | /**
400 | * Check to ensure that all dependencies (e.g. the Beaver Builder plugin) are
401 | * active, and disable this plugin if they aren't.
402 | *
403 | *
404 | * @since 0.1.0
405 | */
406 | public function dependency_check() {
407 | if ( !class_exists( "FLBuilderModule" ) ) {
408 | add_action( 'admin_notices', array( $this, 'deactivation_notice' ) );
409 | add_action( 'admin_init', array( $this, 'deactivate_plugin' ) );
410 | }
411 | }
412 |
413 | /**
414 | * Deactivate plugin.
415 | *
416 | *
417 | * @since 0.1.0
418 | */
419 | public function deactivate_plugin() {
420 | deactivate_plugins( $this->plugin_basename );
421 | }
422 |
423 | /**
424 | * Display a notice to the user, stating that the Beaver Builder plugin is not
425 | * active and that this plugin has therefore been disabled (since it's required).
426 | *
427 | *
428 | * @since 0.1.0
429 | */
430 | public function deactivation_notice() {
431 |
432 | echo '';
433 | echo '
';
434 |
435 | echo '';
436 | _e( "Beaver Brewer Deactivated: ");
437 | echo '';
438 |
439 | _e( "The Beaver Brewer plugin requires Beaver Builder Premium in order to work. Since Beaver Builder was not found, Beaver Brewer has been deactivated.", $this->plugin_name );
440 |
441 | echo '
';
442 | echo '
';
443 | }
444 |
445 | }
446 |
--------------------------------------------------------------------------------
/includes/index.php:
--------------------------------------------------------------------------------
1 | setAccessToken('your-token-here');
70 | ```
71 |
72 | The GitHub version of the library will pull update details from the following parts of a release/tag/branch:
73 |
74 | - Changelog
75 | - The "Changelog" section of `readme.txt`.
76 | - One of the following files:
77 | CHANGES.md, CHANGELOG.md, changes.md, changelog.md
78 | - Release notes.
79 | - Version number
80 | - The "Version" plugin header.
81 | - The latest release or tag name.
82 | - Required and tested WordPress versions
83 | - The "Requires at least" and "Tested up to" fields in `readme.txt`.
84 | - The following plugin headers:
85 | `Required WP`, `Tested WP`, `Requires at least`, `Tested up to`
86 | - "Last updated" timestamp
87 | - The creation timestamp of the latest release.
88 | - The latest commit of the selected tag or branch that changed the main plugin file.
89 | - Number of downloads
90 | - The `download_count` statistic of the latest release.
91 | - If you're not using GitHub releases, there will be no download stats.
92 | - Other plugin details - author, homepage URL, description
93 | - The "Description" section of `readme.txt`.
94 | - Remote plugin headers (i.e. the latest version on GitHub).
95 | - Local plugin headers (i.e. the currently installed version).
96 | - Ratings, banners, screenshots
97 | - Not supported.
98 |
99 | Resources
100 | ---------
101 |
102 | - [Theme Update Checker](http://w-shadow.com/blog/2011/06/02/automatic-updates-for-commercial-themes/)
103 | - [Debug Bar](https://wordpress.org/plugins/debug-bar/) - useful for testing and debugging the update checker.
104 | - [Securing download links](http://w-shadow.com/blog/2013/03/19/plugin-updates-securing-download-links/) - a general overview.
105 | - [A GUI for entering download credentials](http://open-tools.net/documentation/tutorial-automatic-updates.html#wordpress)
--------------------------------------------------------------------------------
/includes/plugin-update-checker/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "yahnis-elsts/plugin-update-checker",
3 | "type": "library",
4 | "description": "A custom update checker for WordPress plugins. Useful if you can't host your plugin in the official WP plugin repository but still want it to support automatic plugin updates.",
5 | "keywords": ["wordpress", "plugin updates", "automatic updates"],
6 | "homepage": "https://github.com/YahnisElsts/plugin-update-checker/",
7 | "license": "MIT",
8 | "authors": [
9 | {
10 | "name": "Yahnis Elsts",
11 | "email": "whiteshadow@w-shadow.com",
12 | "homepage": "http://w-shadow.com/",
13 | "role": "Developer"
14 | }
15 | ],
16 | "require": {
17 | "php": ">=5.2.0"
18 | }
19 | }
--------------------------------------------------------------------------------
/includes/plugin-update-checker/css/puc-debug-bar.css:
--------------------------------------------------------------------------------
1 | .puc-debug-bar-panel pre {
2 | margin-top: 0;
3 | }
4 |
5 | /* Style the debug data table to match "widefat" table style used by WordPress. */
6 | table.puc-debug-data {
7 | width: 100%;
8 | clear: both;
9 | margin: 0;
10 |
11 | border-spacing: 0;
12 | background-color: #f9f9f9;
13 |
14 | border-radius: 3px;
15 | border: 1px solid #dfdfdf;
16 | border-collapse: separate;
17 | }
18 |
19 | table.puc-debug-data * {
20 | word-wrap: break-word;
21 | }
22 |
23 | table.puc-debug-data th {
24 | width: 11em;
25 | padding: 7px 7px 8px;
26 | text-align: left;
27 |
28 | font-family: "Georgia", "Times New Roman", "Bitstream Charter", "Times", serif;
29 | font-weight: 400;
30 | font-size: 14px;
31 | line-height: 1.3em;
32 | text-shadow: rgba(255, 255, 255, 0.804) 0 1px 0;
33 | }
34 |
35 | table.puc-debug-data td, table.puc-debug-data th {
36 | border-width: 1px 0;
37 | border-style: solid;
38 |
39 | border-top-color: #fff;
40 | border-bottom-color: #dfdfdf;
41 |
42 | text-transform: none;
43 | }
44 |
45 | table.puc-debug-data td {
46 | color: #555;
47 | font-size: 12px;
48 | padding: 4px 7px 2px;
49 | vertical-align: top;
50 | }
51 |
52 | .puc-ajax-response {
53 | border: 1px solid #dfdfdf;
54 | border-radius: 3px;
55 | padding: 0.5em;
56 | margin: 5px 0;
57 | background-color: white;
58 | }
59 |
60 | .puc-ajax-nonce {
61 | display: none;
62 | }
--------------------------------------------------------------------------------
/includes/plugin-update-checker/debug-bar-panel.php:
--------------------------------------------------------------------------------
1 | ';
13 |
14 | public function __construct($updateChecker) {
15 | $this->updateChecker = $updateChecker;
16 | $title = sprintf(
17 | '',
18 | esc_attr($this->updateChecker->slug),
19 | $this->updateChecker->slug
20 | );
21 | parent::Debug_Bar_Panel($title);
22 | }
23 |
24 | public function render() {
25 | printf(
26 | '',
27 | esc_attr($this->updateChecker->slug),
28 | esc_attr(wp_create_nonce('puc-ajax'))
29 | );
30 |
31 | $this->displayConfiguration();
32 | $this->displayStatus();
33 | $this->displayCurrentUpdate();
34 |
35 | echo '
';
36 | }
37 |
38 | private function displayConfiguration() {
39 | echo 'Configuration
';
40 | echo '';
41 | $this->row('Plugin file', htmlentities($this->updateChecker->pluginFile));
42 | $this->row('Slug', htmlentities($this->updateChecker->slug));
43 | $this->row('DB option', htmlentities($this->updateChecker->optionName));
44 |
45 | $requestInfoButton = '';
46 | if ( function_exists('get_submit_button') ) {
47 | $requestInfoButton = get_submit_button('Request Info', 'secondary', 'puc-request-info-button', false, array('id' => 'puc-request-info-button-' . $this->updateChecker->slug));
48 | }
49 | $this->row('Metadata URL', htmlentities($this->updateChecker->metadataUrl) . ' ' . $requestInfoButton . $this->responseBox);
50 |
51 | $scheduler = $this->updateChecker->scheduler;
52 | if ( $scheduler->checkPeriod > 0 ) {
53 | $this->row('Automatic checks', 'Every ' . $scheduler->checkPeriod . ' hours');
54 | } else {
55 | $this->row('Automatic checks', 'Disabled');
56 | }
57 |
58 | if ( isset($scheduler->throttleRedundantChecks) ) {
59 | if ( $scheduler->throttleRedundantChecks && ($scheduler->checkPeriod > 0) ) {
60 | $this->row(
61 | 'Throttling',
62 | sprintf(
63 | 'Enabled. If an update is already available, check for updates every %1$d hours instead of every %2$d hours.',
64 | $scheduler->throttledCheckPeriod,
65 | $scheduler->checkPeriod
66 | )
67 | );
68 | } else {
69 | $this->row('Throttling', 'Disabled');
70 | }
71 | }
72 | echo '
';
73 | }
74 |
75 | private function displayStatus() {
76 | echo 'Status
';
77 | echo '';
78 | $state = $this->updateChecker->getUpdateState();
79 | $checkNowButton = '';
80 | if ( function_exists('get_submit_button') ) {
81 | $checkNowButton = get_submit_button('Check Now', 'secondary', 'puc-check-now-button', false, array('id' => 'puc-check-now-button-' . $this->updateChecker->slug));
82 | }
83 |
84 | if ( isset($state, $state->lastCheck) ) {
85 | $this->row('Last check', $this->formatTimeWithDelta($state->lastCheck) . ' ' . $checkNowButton . $this->responseBox);
86 | } else {
87 | $this->row('Last check', 'Never');
88 | }
89 |
90 | $nextCheck = wp_next_scheduled($this->updateChecker->scheduler->getCronHookName());
91 | $this->row('Next automatic check', $this->formatTimeWithDelta($nextCheck));
92 |
93 | if ( isset($state, $state->checkedVersion) ) {
94 | $this->row('Checked version', htmlentities($state->checkedVersion));
95 | $this->row('Cached update', $state->update);
96 | }
97 | $this->row('Update checker class', htmlentities(get_class($this->updateChecker)));
98 | echo '
';
99 | }
100 |
101 | private function displayCurrentUpdate() {
102 | $update = $this->updateChecker->getUpdate();
103 | if ( $update !== null ) {
104 | echo 'An Update Is Available
';
105 | echo '';
106 | $fields = array('version', 'download_url', 'slug', 'homepage', 'upgrade_notice');
107 | foreach($fields as $field) {
108 | $this->row(ucwords(str_replace('_', ' ', $field)), htmlentities($update->$field));
109 | }
110 | echo '
';
111 | } else {
112 | echo 'No updates currently available
';
113 | }
114 | }
115 |
116 | private function formatTimeWithDelta($unixTime) {
117 | if ( empty($unixTime) ) {
118 | return 'Never';
119 | }
120 |
121 | $delta = time() - $unixTime;
122 | $result = human_time_diff(time(), $unixTime);
123 | if ( $delta < 0 ) {
124 | $result = 'after ' . $result;
125 | } else {
126 | $result = $result . ' ago';
127 | }
128 | $result .= ' (' . $this->formatTimestamp($unixTime) . ')';
129 | return $result;
130 | }
131 |
132 | private function formatTimestamp($unixTime) {
133 | return gmdate('Y-m-d H:i:s', $unixTime + (get_option('gmt_offset') * 3600));
134 | }
135 |
136 | private function row($name, $value) {
137 | if ( is_object($value) || is_array($value) ) {
138 | $value = '' . htmlentities(print_r($value, true)) . '
';
139 | } else if ($value === null) {
140 | $value = 'null
';
141 | }
142 | printf('%1$s | %2$s |
', $name, $value);
143 | }
144 | }
145 |
146 | }
147 |
--------------------------------------------------------------------------------
/includes/plugin-update-checker/debug-bar-plugin.php:
--------------------------------------------------------------------------------
1 | updateChecker = $updateChecker;
10 |
11 | add_filter('debug_bar_panels', array($this, 'addDebugBarPanel'));
12 | add_action('debug_bar_enqueue_scripts', array($this, 'enqueuePanelDependencies'));
13 |
14 | add_action('wp_ajax_puc_debug_check_now', array($this, 'ajaxCheckNow'));
15 | add_action('wp_ajax_puc_debug_request_info', array($this, 'ajaxRequestInfo'));
16 | }
17 |
18 | /**
19 | * Register the PUC Debug Bar panel.
20 | *
21 | * @param array $panels
22 | * @return array
23 | */
24 | public function addDebugBarPanel($panels) {
25 | require_once dirname(__FILE__) . '/debug-bar-panel.php';
26 | if ( current_user_can('update_plugins') && class_exists('PluginUpdateCheckerPanel_3_1', false) ) {
27 | $panels[] = new PluginUpdateCheckerPanel_3_1($this->updateChecker);
28 | }
29 | return $panels;
30 | }
31 |
32 | /**
33 | * Enqueue our Debug Bar scripts and styles.
34 | */
35 | public function enqueuePanelDependencies() {
36 | wp_enqueue_style(
37 | 'puc-debug-bar-style',
38 | plugins_url( "/css/puc-debug-bar.css", __FILE__ ),
39 | array('debug-bar'),
40 | '20130927'
41 | );
42 |
43 | wp_enqueue_script(
44 | 'puc-debug-bar-js',
45 | plugins_url( "/js/debug-bar.js", __FILE__ ),
46 | array('jquery'),
47 | '20121026'
48 | );
49 | }
50 |
51 | /**
52 | * Run an update check and output the result. Useful for making sure that
53 | * the update checking process works as expected.
54 | */
55 | public function ajaxCheckNow() {
56 | if ( $_POST['slug'] !== $this->updateChecker->slug ) {
57 | return;
58 | }
59 | $this->preAjaxReqest();
60 | $update = $this->updateChecker->checkForUpdates();
61 | if ( $update !== null ) {
62 | echo "An update is available:";
63 | echo '', htmlentities(print_r($update, true)), '
';
64 | } else {
65 | echo 'No updates found.';
66 | }
67 | exit;
68 | }
69 |
70 | /**
71 | * Request plugin info and output it.
72 | */
73 | public function ajaxRequestInfo() {
74 | if ( $_POST['slug'] !== $this->updateChecker->slug ) {
75 | return;
76 | }
77 | $this->preAjaxReqest();
78 | $info = $this->updateChecker->requestInfo();
79 | if ( $info !== null ) {
80 | echo 'Successfully retrieved plugin info from the metadata URL:';
81 | echo '', htmlentities(print_r($info, true)), '
';
82 | } else {
83 | echo 'Failed to retrieve plugin info from the metadata URL.';
84 | }
85 | exit;
86 | }
87 |
88 | /**
89 | * Check access permissions and enable error display (for debugging).
90 | */
91 | private function preAjaxReqest() {
92 | if ( !current_user_can('update_plugins') ) {
93 | die('Access denied');
94 | }
95 | check_ajax_referer('puc-ajax');
96 |
97 | error_reporting(E_ALL);
98 | @ini_set('display_errors','On');
99 | }
100 | }
101 |
102 | }
--------------------------------------------------------------------------------
/includes/plugin-update-checker/github-checker.php:
--------------------------------------------------------------------------------
1 | repositoryUrl = $repositoryUrl;
40 | $this->branch = empty($branch) ? 'master' : $branch;
41 |
42 | $path = @parse_url($repositoryUrl, PHP_URL_PATH);
43 | if ( preg_match('@^/?(?P[^/]+?)/(?P[^/#?&]+?)/?$@', $path, $matches) ) {
44 | $this->userName = $matches['username'];
45 | $this->repositoryName = $matches['repository'];
46 | } else {
47 | throw new InvalidArgumentException('Invalid GitHub repository URL: "' . $repositoryUrl . '"');
48 | }
49 |
50 | parent::__construct($repositoryUrl, $pluginFile, '', $checkPeriod, $optionName, $muPluginFile);
51 | }
52 |
53 | /**
54 | * Retrieve details about the latest plugin version from GitHub.
55 | *
56 | * @param array $unusedQueryArgs Unused.
57 | * @return PluginInfo_3_1
58 | */
59 | public function requestInfo($unusedQueryArgs = array()) {
60 | $info = new PluginInfo_3_1();
61 | $info->filename = $this->pluginFile;
62 | $info->slug = $this->slug;
63 |
64 | $this->setInfoFromHeader($this->getPluginHeader(), $info);
65 |
66 | //Figure out which reference (tag or branch) we'll use to get the latest version of the plugin.
67 | $ref = $this->branch;
68 | if ( $this->branch === 'master' ) {
69 | //Use the latest release.
70 | $release = $this->getLatestRelease();
71 | if ( $release !== null ) {
72 | $ref = $release->tag_name;
73 | $info->version = ltrim($release->tag_name, 'v'); //Remove the "v" prefix from "v1.2.3".
74 | $info->last_updated = $release->created_at;
75 | $info->download_url = $release->zipball_url;
76 |
77 | if ( !empty($release->body) ) {
78 | $info->sections['changelog'] = $this->parseMarkdown($release->body);
79 | }
80 | if ( isset($release->assets[0]) ) {
81 | $info->downloaded = $release->assets[0]->download_count;
82 | }
83 | } else {
84 | //Failing that, use the tag with the highest version number.
85 | $tag = $this->getLatestTag();
86 | if ( $tag !== null ) {
87 | $ref = $tag->name;
88 | $info->version = $tag->name;
89 | $info->download_url = $tag->zipball_url;
90 | }
91 | }
92 | }
93 |
94 | if ( empty($info->download_url) ) {
95 | $info->download_url = $this->buildArchiveDownloadUrl($ref);
96 | } else if ( !empty($this->accessToken) ) {
97 | $info->download_url = add_query_arg('access_token', $this->accessToken, $info->download_url);
98 | }
99 |
100 | //Get headers from the main plugin file in this branch/tag. Its "Version" header and other metadata
101 | //are what the WordPress install will actually see after upgrading, so they take precedence over releases/tags.
102 | $mainPluginFile = basename($this->pluginFile);
103 | $remotePlugin = $this->getRemoteFile($mainPluginFile, $ref);
104 | if ( !empty($remotePlugin) ) {
105 | $remoteHeader = $this->getFileHeader($remotePlugin);
106 | $this->setInfoFromHeader($remoteHeader, $info);
107 | }
108 |
109 | //Try parsing readme.txt. If it's formatted according to WordPress.org standards, it will contain
110 | //a lot of useful information like the required/tested WP version, changelog, and so on.
111 | if ( $this->readmeTxtExistsLocally() ) {
112 | $this->setInfoFromRemoteReadme($ref, $info);
113 | }
114 |
115 | //The changelog might be in a separate file.
116 | if ( empty($info->sections['changelog']) ) {
117 | $info->sections['changelog'] = $this->getRemoteChangelog($ref);
118 | if ( empty($info->sections['changelog']) ) {
119 | $info->sections['changelog'] = __('There is no changelog available.', 'plugin-update-checker');
120 | }
121 | }
122 |
123 | if ( empty($info->last_updated) ) {
124 | //Fetch the latest commit that changed the main plugin file and use it as the "last_updated" date.
125 | //It's reasonable to assume that every update will change the version number in that file.
126 | $latestCommit = $this->getLatestCommit($mainPluginFile, $ref);
127 | if ( $latestCommit !== null ) {
128 | $info->last_updated = $latestCommit->commit->author->date;
129 | }
130 | }
131 |
132 | $info = apply_filters('puc_request_info_result-' . $this->slug, $info, null);
133 | return $info;
134 | }
135 |
136 | /**
137 | * Get the latest release from GitHub.
138 | *
139 | * @return StdClass|null
140 | */
141 | protected function getLatestRelease() {
142 | $releases = $this->api('/repos/:user/:repo/releases');
143 | if ( is_wp_error($releases) || !is_array($releases) || !isset($releases[0]) ) {
144 | return null;
145 | }
146 |
147 | $latestRelease = $releases[0];
148 | return $latestRelease;
149 | }
150 |
151 | /**
152 | * Get the tag that looks like the highest version number.
153 | *
154 | * @return StdClass|null
155 | */
156 | protected function getLatestTag() {
157 | $tags = $this->api('/repos/:user/:repo/tags');
158 |
159 | if ( is_wp_error($tags) || empty($tags) || !is_array($tags) ) {
160 | return null;
161 | }
162 |
163 | usort($tags, array($this, 'compareTagNames')); //Sort from highest to lowest.
164 | return $tags[0];
165 | }
166 |
167 | /**
168 | * Compare two GitHub tags as if they were version number.
169 | *
170 | * @param string $tag1
171 | * @param string $tag2
172 | * @return int
173 | */
174 | protected function compareTagNames($tag1, $tag2) {
175 | if ( !isset($tag1->name) ) {
176 | return 1;
177 | }
178 | if ( !isset($tag2->name) ) {
179 | return -1;
180 | }
181 | return -version_compare($tag1->name, $tag2->name);
182 | }
183 |
184 | /**
185 | * Get the latest commit that changed the specified file.
186 | *
187 | * @param string $filename
188 | * @param string $ref Reference name (e.g. branch or tag).
189 | * @return StdClass|null
190 | */
191 | protected function getLatestCommit($filename, $ref = 'master') {
192 | $commits = $this->api(
193 | '/repos/:user/:repo/commits',
194 | array(
195 | 'path' => $filename,
196 | 'sha' => $ref,
197 | )
198 | );
199 | if ( !is_wp_error($commits) && is_array($commits) && isset($commits[0]) ) {
200 | return $commits[0];
201 | }
202 | return null;
203 | }
204 |
205 | protected function getRemoteChangelog($ref = '') {
206 | $filename = $this->getChangelogFilename();
207 | if ( empty($filename) ) {
208 | return null;
209 | }
210 |
211 | $changelog = $this->getRemoteFile($filename, $ref);
212 | if ( $changelog === null ) {
213 | return null;
214 | }
215 | return $this->parseMarkdown($changelog);
216 | }
217 |
218 | protected function getChangelogFilename() {
219 | $pluginDirectory = dirname($this->pluginAbsolutePath);
220 | if ( empty($this->pluginAbsolutePath) || !is_dir($pluginDirectory) || ($pluginDirectory === '.') ) {
221 | return null;
222 | }
223 |
224 | $possibleNames = array('CHANGES.md', 'CHANGELOG.md', 'changes.md', 'changelog.md');
225 | $files = scandir($pluginDirectory);
226 | $foundNames = array_intersect($possibleNames, $files);
227 |
228 | if ( !empty($foundNames) ) {
229 | return reset($foundNames);
230 | }
231 | return null;
232 | }
233 |
234 | /**
235 | * Convert Markdown to HTML.
236 | *
237 | * @param string $markdown
238 | * @return string
239 | */
240 | protected function parseMarkdown($markdown) {
241 | if ( !class_exists('Parsedown', false) ) {
242 | require_once(dirname(__FILE__) . '/vendor/Parsedown' . (version_compare(PHP_VERSION, '5.3.0', '>=') ? '' : 'Legacy') . '.php');
243 | }
244 |
245 | $instance = Parsedown::instance();
246 | return $instance->text($markdown);
247 | }
248 |
249 | /**
250 | * Perform a GitHub API request.
251 | *
252 | * @param string $url
253 | * @param array $queryParams
254 | * @return mixed|WP_Error
255 | */
256 | protected function api($url, $queryParams = array()) {
257 | $variables = array(
258 | 'user' => $this->userName,
259 | 'repo' => $this->repositoryName,
260 | );
261 | foreach ($variables as $name => $value) {
262 | $url = str_replace('/:' . $name, '/' . urlencode($value), $url);
263 | }
264 | $url = 'https://api.github.com' . $url;
265 |
266 | if ( !empty($this->accessToken) ) {
267 | $queryParams['access_token'] = $this->accessToken;
268 | }
269 | if ( !empty($queryParams) ) {
270 | $url = add_query_arg($queryParams, $url);
271 | }
272 |
273 | $response = wp_remote_get($url, array('timeout' => 10));
274 | if ( is_wp_error($response) ) {
275 | return $response;
276 | }
277 |
278 | $code = wp_remote_retrieve_response_code($response);
279 | $body = wp_remote_retrieve_body($response);
280 | if ( $code === 200 ) {
281 | $document = json_decode($body);
282 | return $document;
283 | }
284 |
285 | return new WP_Error(
286 | 'puc-github-http-error',
287 | 'GitHub API error. HTTP status: ' . $code
288 | );
289 | }
290 |
291 | /**
292 | * Set the access token that will be used to make authenticated GitHub API requests.
293 | *
294 | * @param string $accessToken
295 | */
296 | public function setAccessToken($accessToken) {
297 | $this->accessToken = $accessToken;
298 | }
299 |
300 | /**
301 | * Get the contents of a file from a specific branch or tag.
302 | *
303 | * @param string $path File name.
304 | * @param string $ref
305 | * @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
306 | */
307 | protected function getRemoteFile($path, $ref = 'master') {
308 | $apiUrl = '/repos/:user/:repo/contents/' . $path;
309 | $response = $this->api($apiUrl, array('ref' => $ref));
310 |
311 | if ( is_wp_error($response) || !isset($response->content) || ($response->encoding !== 'base64') ) {
312 | return null;
313 | }
314 | return base64_decode($response->content);
315 | }
316 |
317 | /**
318 | * Parse plugin metadata from the header comment.
319 | * This is basically a simplified version of the get_file_data() function from /wp-includes/functions.php.
320 | *
321 | * @param $content
322 | * @return array
323 | */
324 | protected function getFileHeader($content) {
325 | $headers = array(
326 | 'Name' => 'Plugin Name',
327 | 'PluginURI' => 'Plugin URI',
328 | 'Version' => 'Version',
329 | 'Description' => 'Description',
330 | 'Author' => 'Author',
331 | 'AuthorURI' => 'Author URI',
332 | 'TextDomain' => 'Text Domain',
333 | 'DomainPath' => 'Domain Path',
334 | 'Network' => 'Network',
335 |
336 | //The newest WordPress version that this plugin requires or has been tested with.
337 | //We support several different formats for compatibility with other libraries.
338 | 'Tested WP' => 'Tested WP',
339 | 'Requires WP' => 'Requires WP',
340 | 'Tested up to' => 'Tested up to',
341 | 'Requires at least' => 'Requires at least',
342 | );
343 |
344 | $content = str_replace("\r", "\n", $content); //Normalize line endings.
345 | $results = array();
346 | foreach ($headers as $field => $name) {
347 | $success = preg_match('/^[ \t\/*#@]*' . preg_quote($name, '/') . ':(.*)$/mi', $content, $matches);
348 | if ( ($success === 1) && $matches[1] ) {
349 | $results[$field] = _cleanup_header_comment($matches[1]);
350 | } else {
351 | $results[$field] = '';
352 | }
353 | }
354 |
355 | return $results;
356 | }
357 |
358 | /**
359 | * Copy plugin metadata from a file header to a PluginInfo object.
360 | *
361 | * @param array $fileHeader
362 | * @param PluginInfo_3_1 $pluginInfo
363 | */
364 | protected function setInfoFromHeader($fileHeader, $pluginInfo) {
365 | $headerToPropertyMap = array(
366 | 'Version' => 'version',
367 | 'Name' => 'name',
368 | 'PluginURI' => 'homepage',
369 | 'Author' => 'author',
370 | 'AuthorName' => 'author',
371 | 'AuthorURI' => 'author_homepage',
372 |
373 | 'Requires WP' => 'requires',
374 | 'Tested WP' => 'tested',
375 | 'Requires at least' => 'requires',
376 | 'Tested up to' => 'tested',
377 | );
378 | foreach ($headerToPropertyMap as $headerName => $property) {
379 | if ( isset($fileHeader[$headerName]) && !empty($fileHeader[$headerName]) ) {
380 | $pluginInfo->$property = $fileHeader[$headerName];
381 | }
382 | }
383 |
384 | if ( !empty($fileHeader['Description']) ) {
385 | $pluginInfo->sections['description'] = $fileHeader['Description'];
386 | }
387 | }
388 |
389 | /**
390 | * Copy plugin metadata from the remote readme.txt file.
391 | *
392 | * @param string $ref GitHub tag or branch where to look for the readme.
393 | * @param PluginInfo_3_1 $pluginInfo
394 | */
395 | protected function setInfoFromRemoteReadme($ref, $pluginInfo) {
396 | $readmeTxt = $this->getRemoteFile('readme.txt', $ref);
397 | if ( empty($readmeTxt) ) {
398 | return;
399 | }
400 |
401 | $readme = $this->parseReadme($readmeTxt);
402 |
403 | if ( isset($readme['sections']) ) {
404 | $pluginInfo->sections = array_merge($pluginInfo->sections, $readme['sections']);
405 | }
406 | if ( !empty($readme['tested_up_to']) ) {
407 | $pluginInfo->tested = $readme['tested_up_to'];
408 | }
409 | if ( !empty($readme['requires_at_least']) ) {
410 | $pluginInfo->requires = $readme['requires_at_least'];
411 | }
412 |
413 | if ( isset($readme['upgrade_notice'], $readme['upgrade_notice'][$pluginInfo->version]) ) {
414 | $pluginInfo->upgrade_notice = $readme['upgrade_notice'][$pluginInfo->version];
415 | }
416 | }
417 |
418 | protected function parseReadme($content) {
419 | if ( !class_exists('PucReadmeParser', false) ) {
420 | require_once(dirname(__FILE__) . '/vendor/readme-parser.php');
421 | }
422 | $parser = new PucReadmeParser();
423 | return $parser->parse_readme_contents($content);
424 | }
425 |
426 | /**
427 | * Check if the currently installed version has a readme.txt file.
428 | *
429 | * @return bool
430 | */
431 | protected function readmeTxtExistsLocally() {
432 | $pluginDirectory = dirname($this->pluginAbsolutePath);
433 | if ( empty($this->pluginAbsolutePath) || !is_dir($pluginDirectory) || ($pluginDirectory === '.') ) {
434 | return false;
435 | }
436 | return is_file($pluginDirectory . '/readme.txt');
437 | }
438 |
439 | /**
440 | * Generate a URL to download a ZIP archive of the specified branch/tag/etc.
441 | *
442 | * @param string $ref
443 | * @return string
444 | */
445 | protected function buildArchiveDownloadUrl($ref = 'master') {
446 | $url = sprintf(
447 | 'https://api.github.com/repos/%1$s/%2$s/zipball/%3$s',
448 | urlencode($this->userName),
449 | urlencode($this->repositoryName),
450 | urlencode($ref)
451 | );
452 | if ( !empty($this->accessToken) ) {
453 | $url = add_query_arg('access_token', $this->accessToken, $url);
454 | }
455 | return $url;
456 | }
457 | }
458 |
459 | endif;
--------------------------------------------------------------------------------
/includes/plugin-update-checker/js/debug-bar.js:
--------------------------------------------------------------------------------
1 | jQuery(function($) {
2 |
3 | function runAjaxAction(button, action) {
4 | button = $(button);
5 | var panel = button.closest('.puc-debug-bar-panel');
6 | var responseBox = button.closest('td').find('.puc-ajax-response');
7 |
8 | responseBox.text('Processing...').show();
9 | $.post(
10 | ajaxurl,
11 | {
12 | action : action,
13 | slug : panel.data('slug'),
14 | _wpnonce: panel.data('nonce')
15 | },
16 | function(data) {
17 | responseBox.html(data);
18 | },
19 | 'html'
20 | );
21 | }
22 |
23 | $('.puc-debug-bar-panel input[name="puc-check-now-button"]').click(function() {
24 | runAjaxAction(this, 'puc_debug_check_now');
25 | return false;
26 | });
27 |
28 | $('.puc-debug-bar-panel input[name="puc-request-info-button"]').click(function() {
29 | runAjaxAction(this, 'puc_debug_request_info');
30 | return false;
31 | });
32 |
33 |
34 | // Debug Bar uses the panel class name as part of its link and container IDs. This means we can
35 | // end up with multiple identical IDs if more than one plugin uses the update checker library.
36 | // Fix it by replacing the class name with the plugin slug.
37 | var panels = $('#debug-menu-targets').find('.puc-debug-bar-panel');
38 | panels.each(function(index) {
39 | var panel = $(this);
40 | var slug = panel.data('slug');
41 | var target = panel.closest('.debug-menu-target');
42 |
43 | //Change the panel wrapper ID.
44 | target.attr('id', 'debug-menu-target-puc-' + slug);
45 |
46 | //Change the menu link ID as well and point it at the new target ID.
47 | $('#puc-debug-menu-link-' + panel.data('slug'))
48 | .closest('.debug-menu-link')
49 | .attr('id', 'debug-menu-link-puc-' + slug)
50 | .attr('href', '#' + target.attr('id'));
51 | });
52 | });
--------------------------------------------------------------------------------
/includes/plugin-update-checker/languages/plugin-update-checker-fr_FR.mo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rbenhase/beaver-brewer/574c03137ac04cb3cdb619d17ecd412d61d0faca/includes/plugin-update-checker/languages/plugin-update-checker-fr_FR.mo
--------------------------------------------------------------------------------
/includes/plugin-update-checker/languages/plugin-update-checker-fr_FR.po:
--------------------------------------------------------------------------------
1 | msgid ""
2 | msgstr ""
3 | "Project-Id-Version: plugin-update-checker\n"
4 | "POT-Creation-Date: 2016-02-17 14:21+0100\n"
5 | "PO-Revision-Date: 2016-02-17 14:22+0100\n"
6 | "Last-Translator: studio RVOLA \n"
7 | "Language-Team: studio RVOLA \n"
8 | "Language: fr_FR\n"
9 | "MIME-Version: 1.0\n"
10 | "Content-Type: text/plain; charset=UTF-8\n"
11 | "Content-Transfer-Encoding: 8bit\n"
12 | "X-Generator: Poedit 1.8.7\n"
13 | "X-Poedit-Basepath: ..\n"
14 | "Plural-Forms: nplurals=2; plural=(n > 1);\n"
15 | "X-Poedit-SourceCharset: UTF-8\n"
16 | "X-Poedit-KeywordsList: __;_e\n"
17 | "X-Poedit-SearchPath-0: .\n"
18 |
19 | #: github-checker.php:120
20 | msgid "There is no changelog available."
21 | msgstr "Il n’y a aucun changelog disponible."
22 |
23 | #: plugin-update-checker.php:637
24 | msgid "Check for updates"
25 | msgstr "Vérifier les mises à jour"
26 |
27 | #: plugin-update-checker.php:681
28 | msgid "This plugin is up to date."
29 | msgstr "Ce plugin est à jour."
30 |
31 | #: plugin-update-checker.php:683
32 | msgid "A new version of this plugin is available."
33 | msgstr "Une nouvelle version de ce plugin est disponible."
34 |
35 | #: plugin-update-checker.php:685
36 | #, php-format
37 | msgid "Unknown update checker status \"%s\""
38 | msgstr "Un problème inconnu est survenu \"%s\""
39 |
--------------------------------------------------------------------------------
/includes/plugin-update-checker/languages/plugin-update-checker-hu_HU.mo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rbenhase/beaver-brewer/574c03137ac04cb3cdb619d17ecd412d61d0faca/includes/plugin-update-checker/languages/plugin-update-checker-hu_HU.mo
--------------------------------------------------------------------------------
/includes/plugin-update-checker/languages/plugin-update-checker-hu_HU.po:
--------------------------------------------------------------------------------
1 | msgid ""
2 | msgstr ""
3 | "Project-Id-Version: plugin-update-checker\n"
4 | "POT-Creation-Date: 2016-01-11 21:23+0100\n"
5 | "PO-Revision-Date: 2016-01-11 21:25+0100\n"
6 | "Last-Translator: Tamás András Horváth \n"
7 | "Language-Team: \n"
8 | "Language: hu_HU\n"
9 | "MIME-Version: 1.0\n"
10 | "Content-Type: text/plain; charset=UTF-8\n"
11 | "Content-Transfer-Encoding: 8bit\n"
12 | "X-Generator: Poedit 1.8.6\n"
13 | "X-Poedit-Basepath: ..\n"
14 | "Plural-Forms: nplurals=2; plural=(n != 1);\n"
15 | "X-Poedit-SourceCharset: UTF-8\n"
16 | "X-Poedit-KeywordsList: __;_e\n"
17 | "X-Poedit-SearchPath-0: .\n"
18 |
19 | #: github-checker.php:137
20 | msgid "There is no changelog available."
21 | msgstr "Nem érhető el a changelog."
22 |
23 | #: plugin-update-checker.php:852
24 | msgid "Check for updates"
25 | msgstr "Frissítés ellenőrzése"
26 |
27 | #: plugin-update-checker.php:896
28 | msgid "This plugin is up to date."
29 | msgstr "Ez a plugin naprakész."
30 |
31 | #: plugin-update-checker.php:898
32 | msgid "A new version of this plugin is available."
33 | msgstr "Új verzió érhető el a kiegészítőhöz"
34 |
35 | #: plugin-update-checker.php:900
36 | #, php-format
37 | msgid "Unknown update checker status \"%s\""
38 | msgstr "Ismeretlen a frissítés ellenőrző státusza \"%s\""
39 |
40 | #~ msgid "Every %d hours"
41 | #~ msgstr "Minden %d órában"
42 |
--------------------------------------------------------------------------------
/includes/plugin-update-checker/languages/plugin-update-checker.pot:
--------------------------------------------------------------------------------
1 | #, fuzzy
2 | msgid ""
3 | msgstr ""
4 | "Project-Id-Version: plugin-update-checker\n"
5 | "POT-Creation-Date: 2016-01-11 21:22+0100\n"
6 | "PO-Revision-Date: 2016-01-10 20:59+0100\n"
7 | "Last-Translator: Tamás András Horváth \n"
8 | "Language-Team: \n"
9 | "Language: en_US\n"
10 | "MIME-Version: 1.0\n"
11 | "Content-Type: text/plain; charset=UTF-8\n"
12 | "Content-Transfer-Encoding: 8bit\n"
13 | "X-Generator: Poedit 1.8.6\n"
14 | "X-Poedit-Basepath: ..\n"
15 | "Plural-Forms: nplurals=2; plural=(n != 1);\n"
16 | "X-Poedit-SourceCharset: UTF-8\n"
17 | "X-Poedit-KeywordsList: __;_e\n"
18 | "X-Poedit-SearchPath-0: .\n"
19 |
20 | #: github-checker.php:137
21 | msgid "There is no changelog available."
22 | msgstr ""
23 |
24 | #: plugin-update-checker.php:852
25 | msgid "Check for updates"
26 | msgstr ""
27 |
28 | #: plugin-update-checker.php:896
29 | msgid "This plugin is up to date."
30 | msgstr ""
31 |
32 | #: plugin-update-checker.php:898
33 | msgid "A new version of this plugin is available."
34 | msgstr ""
35 |
36 | #: plugin-update-checker.php:900
37 | #, php-format
38 | msgid "Unknown update checker status \"%s\""
39 | msgstr ""
40 |
--------------------------------------------------------------------------------
/includes/plugin-update-checker/license.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014 Jānis Elsts
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/includes/plugin-update-checker/vendor/readme-parser.php:
--------------------------------------------------------------------------------
1 | parse_readme_contents( $file_contents );
17 | }
18 |
19 | function parse_readme_contents( $file_contents ) {
20 | $file_contents = str_replace(array("\r\n", "\r"), "\n", $file_contents);
21 | $file_contents = trim($file_contents);
22 | if ( 0 === strpos( $file_contents, "\xEF\xBB\xBF" ) )
23 | $file_contents = substr( $file_contents, 3 );
24 |
25 | // Markdown transformations
26 | $file_contents = preg_replace( "|^###([^#]+)#*?\s*?\n|im", '=$1='."\n", $file_contents );
27 | $file_contents = preg_replace( "|^##([^#]+)#*?\s*?\n|im", '==$1=='."\n", $file_contents );
28 | $file_contents = preg_replace( "|^#([^#]+)#*?\s*?\n|im", '===$1==='."\n", $file_contents );
29 |
30 | // === Plugin Name ===
31 | // Must be the very first thing.
32 | if ( !preg_match('|^===(.*)===|', $file_contents, $_name) )
33 | return array(); // require a name
34 | $name = trim($_name[1], '=');
35 | $name = $this->sanitize_text( $name );
36 |
37 | $file_contents = $this->chop_string( $file_contents, $_name[0] );
38 |
39 |
40 | // Requires at least: 1.5
41 | if ( preg_match('|Requires at least:(.*)|i', $file_contents, $_requires_at_least) )
42 | $requires_at_least = $this->sanitize_text($_requires_at_least[1]);
43 | else
44 | $requires_at_least = NULL;
45 |
46 |
47 | // Tested up to: 2.1
48 | if ( preg_match('|Tested up to:(.*)|i', $file_contents, $_tested_up_to) )
49 | $tested_up_to = $this->sanitize_text( $_tested_up_to[1] );
50 | else
51 | $tested_up_to = NULL;
52 |
53 |
54 | // Stable tag: 10.4-ride-the-fire-eagle-danger-day
55 | if ( preg_match('|Stable tag:(.*)|i', $file_contents, $_stable_tag) )
56 | $stable_tag = $this->sanitize_text( $_stable_tag[1] );
57 | else
58 | $stable_tag = NULL; // we assume trunk, but don't set it here to tell the difference between specified trunk and default trunk
59 |
60 |
61 | // Tags: some tag, another tag, we like tags
62 | if ( preg_match('|Tags:(.*)|i', $file_contents, $_tags) ) {
63 | $tags = preg_split('|,[\s]*?|', trim($_tags[1]));
64 | foreach ( array_keys($tags) as $t )
65 | $tags[$t] = $this->sanitize_text( $tags[$t] );
66 | } else {
67 | $tags = array();
68 | }
69 |
70 |
71 | // Contributors: markjaquith, mdawaffe, zefrank
72 | $contributors = array();
73 | if ( preg_match('|Contributors:(.*)|i', $file_contents, $_contributors) ) {
74 | $temp_contributors = preg_split('|,[\s]*|', trim($_contributors[1]));
75 | foreach ( array_keys($temp_contributors) as $c ) {
76 | $tmp_sanitized = $this->user_sanitize( $temp_contributors[$c] );
77 | if ( strlen(trim($tmp_sanitized)) > 0 )
78 | $contributors[$c] = $tmp_sanitized;
79 | unset($tmp_sanitized);
80 | }
81 | }
82 |
83 |
84 | // Donate Link: URL
85 | if ( preg_match('|Donate link:(.*)|i', $file_contents, $_donate_link) )
86 | $donate_link = esc_url( $_donate_link[1] );
87 | else
88 | $donate_link = NULL;
89 |
90 |
91 | // togs, conts, etc are optional and order shouldn't matter. So we chop them only after we've grabbed their values.
92 | foreach ( array('tags', 'contributors', 'requires_at_least', 'tested_up_to', 'stable_tag', 'donate_link') as $chop ) {
93 | if ( $$chop ) {
94 | $_chop = '_' . $chop;
95 | $file_contents = $this->chop_string( $file_contents, ${$_chop}[0] );
96 | }
97 | }
98 |
99 | $file_contents = trim($file_contents);
100 |
101 |
102 | // short-description fu
103 | if ( !preg_match('/(^(.*?))^[\s]*=+?[\s]*.+?[\s]*=+?/ms', $file_contents, $_short_description) )
104 | $_short_description = array( 1 => &$file_contents, 2 => &$file_contents );
105 | $short_desc_filtered = $this->sanitize_text( $_short_description[2] );
106 | $short_desc_length = strlen($short_desc_filtered);
107 | $short_description = substr($short_desc_filtered, 0, 150);
108 | if ( $short_desc_length > strlen($short_description) )
109 | $truncated = true;
110 | else
111 | $truncated = false;
112 | if ( $_short_description[1] )
113 | $file_contents = $this->chop_string( $file_contents, $_short_description[1] ); // yes, the [1] is intentional
114 |
115 | // == Section ==
116 | // Break into sections
117 | // $_sections[0] will be the title of the first section, $_sections[1] will be the content of the first section
118 | // the array alternates from there: title2, content2, title3, content3... and so forth
119 | $_sections = preg_split('/^[\s]*==[\s]*(.+?)[\s]*==/m', $file_contents, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
120 |
121 | $sections = array();
122 | for ( $i=1; $i <= count($_sections); $i +=2 ) {
123 | $_sections[$i] = preg_replace('/^[\s]*=[\s]+(.+?)[\s]+=/m', '$1
', $_sections[$i]);
124 | $_sections[$i] = $this->filter_text( $_sections[$i], true );
125 | $title = $this->sanitize_text( $_sections[$i-1] );
126 | $sections[str_replace(' ', '_', strtolower($title))] = array('title' => $title, 'content' => $_sections[$i]);
127 | }
128 |
129 |
130 | // Special sections
131 | // This is where we nab our special sections, so we can enforce their order and treat them differently, if needed
132 | // upgrade_notice is not a section, but parse it like it is for now
133 | $final_sections = array();
134 | foreach ( array('description', 'installation', 'frequently_asked_questions', 'screenshots', 'changelog', 'change_log', 'upgrade_notice') as $special_section ) {
135 | if ( isset($sections[$special_section]) ) {
136 | $final_sections[$special_section] = $sections[$special_section]['content'];
137 | unset($sections[$special_section]);
138 | }
139 | }
140 | if ( isset($final_sections['change_log']) && empty($final_sections['changelog']) )
141 | $final_sections['changelog'] = $final_sections['change_log'];
142 |
143 |
144 | $final_screenshots = array();
145 | if ( isset($final_sections['screenshots']) ) {
146 | preg_match_all('|(.*?)|s', $final_sections['screenshots'], $screenshots, PREG_SET_ORDER);
147 | if ( $screenshots ) {
148 | foreach ( (array) $screenshots as $ss )
149 | $final_screenshots[] = $ss[1];
150 | }
151 | }
152 |
153 | // Parse the upgrade_notice section specially:
154 | // 1.0 => blah, 1.1 => fnord
155 | $upgrade_notice = array();
156 | if ( isset($final_sections['upgrade_notice']) ) {
157 | $split = preg_split( '#(.*?)
#', $final_sections['upgrade_notice'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
158 | for ( $i = 0; $i < count( $split ); $i += 2 )
159 | $upgrade_notice[$this->sanitize_text( $split[$i] )] = substr( $this->sanitize_text( $split[$i + 1] ), 0, 300 );
160 | unset( $final_sections['upgrade_notice'] );
161 | }
162 |
163 | // No description?
164 | // No problem... we'll just fall back to the old style of description
165 | // We'll even let you use markup this time!
166 | $excerpt = false;
167 | if ( !isset($final_sections['description']) ) {
168 | $final_sections = array_merge(array('description' => $this->filter_text( $_short_description[2], true )), $final_sections);
169 | $excerpt = true;
170 | }
171 |
172 |
173 | // dump the non-special sections into $remaining_content
174 | // their order will be determined by their original order in the readme.txt
175 | $remaining_content = '';
176 | foreach ( $sections as $s_name => $s_data ) {
177 | $remaining_content .= "\n{$s_data['title']}
\n{$s_data['content']}";
178 | }
179 | $remaining_content = trim($remaining_content);
180 |
181 |
182 | // All done!
183 | // $r['tags'] and $r['contributors'] are simple arrays
184 | // $r['sections'] is an array with named elements
185 | $r = array(
186 | 'name' => $name,
187 | 'tags' => $tags,
188 | 'requires_at_least' => $requires_at_least,
189 | 'tested_up_to' => $tested_up_to,
190 | 'stable_tag' => $stable_tag,
191 | 'contributors' => $contributors,
192 | 'donate_link' => $donate_link,
193 | 'short_description' => $short_description,
194 | 'screenshots' => $final_screenshots,
195 | 'is_excerpt' => $excerpt,
196 | 'is_truncated' => $truncated,
197 | 'sections' => $final_sections,
198 | 'remaining_content' => $remaining_content,
199 | 'upgrade_notice' => $upgrade_notice
200 | );
201 |
202 | return $r;
203 | }
204 |
205 | function chop_string( $string, $chop ) { // chop a "prefix" from a string: Agressive! uses strstr not 0 === strpos
206 | if ( $_string = strstr($string, $chop) ) {
207 | $_string = substr($_string, strlen($chop));
208 | return trim($_string);
209 | } else {
210 | return trim($string);
211 | }
212 | }
213 |
214 | function user_sanitize( $text, $strict = false ) { // whitelisted chars
215 | if ( function_exists('user_sanitize') ) // bbPress native
216 | return user_sanitize( $text, $strict );
217 |
218 | if ( $strict ) {
219 | $text = preg_replace('/[^a-z0-9-]/i', '', $text);
220 | $text = preg_replace('|-+|', '-', $text);
221 | } else {
222 | $text = preg_replace('/[^a-z0-9_-]/i', '', $text);
223 | }
224 | return $text;
225 | }
226 |
227 | function sanitize_text( $text ) { // not fancy
228 | $text = strip_tags($text);
229 | $text = esc_html($text);
230 | $text = trim($text);
231 | return $text;
232 | }
233 |
234 | function filter_text( $text, $markdown = false ) { // fancy, Markdown
235 | $text = trim($text);
236 |
237 | $text = call_user_func( array( __CLASS__, 'code_trick' ), $text, $markdown ); // A better parser than Markdown's for: backticks -> CODE
238 |
239 | if ( $markdown ) { // Parse markdown.
240 | if ( !class_exists('Parsedown', false) ) {
241 | require_once(dirname(__FILE__) . '/Parsedown' . (version_compare(PHP_VERSION, '5.3.0', '>=') ? '' : 'Legacy') . '.php');
242 | }
243 | $instance = Parsedown::instance();
244 | $text = $instance->text($text);
245 | }
246 |
247 | $allowed = array(
248 | 'a' => array(
249 | 'href' => array(),
250 | 'title' => array(),
251 | 'rel' => array()),
252 | 'blockquote' => array('cite' => array()),
253 | 'br' => array(),
254 | 'p' => array(),
255 | 'code' => array(),
256 | 'pre' => array(),
257 | 'em' => array(),
258 | 'strong' => array(),
259 | 'ul' => array(),
260 | 'ol' => array(),
261 | 'li' => array(),
262 | 'h3' => array(),
263 | 'h4' => array()
264 | );
265 |
266 | $text = balanceTags($text);
267 |
268 | $text = wp_kses( $text, $allowed );
269 | $text = trim($text);
270 | return $text;
271 | }
272 |
273 | function code_trick( $text, $markdown ) { // Don't use bbPress native function - it's incompatible with Markdown
274 | // If doing markdown, first take any user formatted code blocks and turn them into backticks so that
275 | // markdown will preserve things like underscores in code blocks
276 | if ( $markdown )
277 | $text = preg_replace_callback("!(|)(.*?)(
|)!s", array( __CLASS__,'decodeit'), $text);
278 |
279 | $text = str_replace(array("\r\n", "\r"), "\n", $text);
280 | if ( !$markdown ) {
281 | // This gets the "inline" code blocks, but can't be used with Markdown.
282 | $text = preg_replace_callback("|(`)(.*?)`|", array( __CLASS__, 'encodeit'), $text);
283 | // This gets the "block level" code blocks and converts them to PRE CODE
284 | $text = preg_replace_callback("!(^|\n)`(.*?)`!s", array( __CLASS__, 'encodeit'), $text);
285 | } else {
286 | // Markdown can do inline code, we convert bbPress style block level code to Markdown style
287 | $text = preg_replace_callback("!(^|\n)([ \t]*?)`(.*?)`!s", array( __CLASS__, 'indent'), $text);
288 | }
289 | return $text;
290 | }
291 |
292 | function indent( $matches ) {
293 | $text = $matches[3];
294 | $text = preg_replace('|^|m', $matches[2] . ' ', $text);
295 | return $matches[1] . $text;
296 | }
297 |
298 | function encodeit( $matches ) {
299 | if ( function_exists('encodeit') ) // bbPress native
300 | return encodeit( $matches );
301 |
302 | $text = trim($matches[2]);
303 | $text = htmlspecialchars($text, ENT_QUOTES);
304 | $text = str_replace(array("\r\n", "\r"), "\n", $text);
305 | $text = preg_replace("|\n\n\n+|", "\n\n", $text);
306 | $text = str_replace('<', '<', $text);
307 | $text = str_replace('>', '>', $text);
308 | $text = "$text
";
309 | if ( "`" != $matches[1] )
310 | $text = "$text
";
311 | return $text;
312 | }
313 |
314 | function decodeit( $matches ) {
315 | if ( function_exists('decodeit') ) // bbPress native
316 | return decodeit( $matches );
317 |
318 | $text = $matches[2];
319 | $trans_table = array_flip(get_html_translation_table(HTML_ENTITIES));
320 | $text = strtr($text, $trans_table);
321 | $text = str_replace('
', '', $text);
322 | $text = str_replace('&', '&', $text);
323 | $text = str_replace(''', "'", $text);
324 | if ( '' == $matches[1] )
325 | $text = "\n$text\n";
326 | return "`$text`";
327 | }
328 |
329 | } // end class
330 |
331 | Class Automattic_Readme extends PucReadmeParser {}
332 |
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 |
22 | */
23 | class Beaver_Brewer_Public {
24 |
25 | /**
26 | * The ID of this plugin.
27 | *
28 | * @since 0.1.0
29 | * @access private
30 | * @var string $plugin_name The ID of this plugin.
31 | */
32 | private $plugin_name;
33 |
34 | /**
35 | * The version of this plugin.
36 | *
37 | * @since 0.1.0
38 | * @access private
39 | * @var string $version The current version of this plugin.
40 | */
41 | private $version;
42 |
43 | /**
44 | * All modules and their relevant data.
45 | *
46 | * @since 0.1.0
47 | * @access private
48 | * @var array $modules All recognized modules.
49 | */
50 | private $modules;
51 |
52 |
53 | /**
54 | * Initialize the class and set its properties.
55 | *
56 | * @since 0.1.0
57 | * @param string $plugin_name The name of this plugin.
58 | * @param string $version The version of this plugin.
59 | * @param Beaver_Brewer $brewer An instance of the main Beaver Brewer class.
60 | */
61 | public function __construct( $plugin_name, $version, $modules ) {
62 |
63 | $this->plugin_name = $plugin_name;
64 | $this->version = $version;
65 | $this->modules = $modules;
66 | }
67 |
68 |
69 | /**
70 | * Register modules so they can be used in Beaver Builder.
71 | *
72 | * @since 0.1.0
73 | */
74 | public function register_modules() {
75 |
76 | // Ensure required Beaver Builder class exists
77 | if ( class_exists( 'FLBuilder' ) && isset( $this->modules ) ) {
78 |
79 | // First load other modules to check for compatibility issues
80 | $active_modules = Beaver_Brewer::get_modules_active();
81 |
82 | foreach ( $active_modules as $active_module ) {
83 |
84 | // Require all PHP files in main directory
85 | $path = MY_MODULES_DIR . $active_module;
86 | $files = glob( $path . '/*.php' );
87 | if ( !empty( $files ) ) foreach ( $files as $file_path ){
88 | require_once( $file_path );
89 | }
90 | }
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/public/index.php:
--------------------------------------------------------------------------------
1 |