Skip to content

Commit

Permalink
generic WIP - UI & package type update, add dummy generic bash
Browse files Browse the repository at this point in the history
  • Loading branch information
froger-me committed Jan 8, 2024
1 parent 6470d5b commit 9df8d9d
Show file tree
Hide file tree
Showing 10 changed files with 290 additions and 30 deletions.
4 changes: 2 additions & 2 deletions inc/class-wppus-webhook-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct( $init_hooks = false ) {

public function add_endpoints() {
add_rewrite_rule( '^wppus-webhook$', 'index.php?__wppus_webhook=1&', 'top' );
add_rewrite_rule( '^wppus-webhook/(plugin|theme)/(.+)?$', 'index.php?type=$matches[1]&package_id=$matches[2]&__wppus_webhook=1&', 'top' );
add_rewrite_rule( '^wppus-webhook/(plugin|theme|generic)/(.+)?$', 'index.php?type=$matches[1]&package_id=$matches[2]&__wppus_webhook=1&', 'top' );
}

public function parse_request() {
Expand Down Expand Up @@ -98,7 +98,7 @@ public function wppus_webhook_process_request( $process, $payload ) {

if (
( isset( $payload['object_kind'] ) && 'push' === $payload['object_kind'] ) ||
( isset( $_SERVER['X_GITHUB_EVENT'] ) && 'push' === $_SERVER['X_GITHUB_EVENT'] )
( isset( $_SERVER['HTTP_X_GITHUB_EVENT'] ) && 'push' === $_SERVER['HTTP_X_GITHUB_EVENT'] )
) {
$branch = str_replace( 'refs/heads/', '', $payload['ref'] );
} elseif ( isset( $payload['push'], $payload['push']['changes'] ) ) {
Expand Down
37 changes: 17 additions & 20 deletions inc/templates/admin/plugin-help-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<p>
<?php
printf(
// translators: %1$s is <code>functions.php</code>, %2$s is <code>lib</code>
esc_html__( 'To link your packages to WP Packages Update Server, and optionally to prevent webmasters from getting updates of your plugins and themes without a license, your plugins and themes need to include some extra code. It is a simple matter of adding a few lines in the main plugin file (for plugins) or in the %1$s file (for themes), and provide the necessary libraries in a %2$s directory at the root of the package.', 'wppus' ),
// translators: %1$s is <code>functions.php</code>, %2$s is <code>lib</code>, %3$s is <code>main file</code>
esc_html__( 'To link your packages, whether they are WordPress plugins, WordPress themes, or generic packages, to the WP Packages Update Server, and optionally to prevent users from getting updates of your packages without a license, your packages need to include some extra code. For WordPress packages, it is a simple matter of adding a few lines in the main plugin file (for plugins), or in the %1$s file (for themes), and provide the necessary libraries in a %2$s directory at the root of the package.', 'wppus' ),
'<code>functions.php</code>',
'<code>lib</code>'
'<code>lib</code>',
);
?>
</p>
Expand All @@ -24,11 +24,21 @@
);
?>
</p>
<p>
<?php
printf(
// translators: %1$s is <code>integration/dummy-generic</code>, %2$s is a "here" link to the documentation
esc_html__( 'See %1$s for an example of generic package written in bash. The API calls made by generic packages to the license API and Update API are the same, but because they are language-agnostic, there is no library provided. You may refer to the documentation found %2$s.', 'wppus' ),
'<a target="_blank" href="' . esc_url( 'https://github.com/froger-me/wp-packages-update-server/blob/main/integration/docs/generic.md' ) . '">' . esc_html__( 'here', 'wppus' ) . '</a>',
'<code>' . esc_html( WPPUS_PLUGIN_PATH ) . 'integration/dummy-generic</code>',
);
?>
</p>
<p>
<?php
printf(
// translators: %1$s is <code>packages_dir</code>, %2$s is <code>package-slug.zip</code>, %3$s is <code>package-slug.php</code>
esc_html__( 'Unless "Use Remote Repository Service" is checked in "Remote Sources", you need to manually upload the packages zip archives (and subsequent updates) in %1$s. Packages need to be valid WordPress plugin or theme packages, and in the case of a plugin the main plugin file must have the same name as the zip archive. For example, the main plugin file in %2$s would be %3$s.', 'wppus' ),
esc_html__( 'Unless "Use Remote Repository Service" is checked in "Remote Sources", you need to manually upload the packages zip archives (and subsequent updates) in %1$s. A packages need to a valid generic package, or a valid WordPress plugin or theme package, and in the case of a plugin the main plugin file must have the same name as the zip archive. For example, the main plugin file in %2$s would be %3$s.', 'wppus' ),
'<code>' . esc_html( $packages_dir ) . '</code>',
'<code>package-slug.zip</code>',
'<code>package-slug.php</code>',
Expand All @@ -41,7 +51,7 @@
<?php
printf(
// translators: %s is <code>parse_request</code>
esc_html__( "When the remote clients where your plugins and themes are installed send a request to check for updates, download a package or check or change license status, the current server's WordPress installation is loaded, with its own plugins and themes. This is not optimised if left untouched because unnecessary action and filter hooks that execute before %s action hook are also triggered, even though the request is not designed to produce any on-screen output or further computation.", 'wppus' ),
esc_html__( "When the remote clients where your plugins, themes, or generic packages are installed send a request to check for updates, download a package or check or change license status, the current server's WordPress installation is loaded, with its own plugins and themes. This is not optimised if left untouched because unnecessary action and filter hooks that execute before %s action hook are also triggered, even though the request is not designed to produce any on-screen output or further computation.", 'wppus' ),
'<code>parse_request</code>',
);
?>
Expand All @@ -56,19 +66,6 @@
);
?>
</p>
<p>
<?php
printf(
// translators: %1$s is <code>$wppus_always_active_plugins</code>, %2$s is <code>$wppus_bypass_themes</code>, %3$s is <code>false</code>, %4$s is <code>functions.php</code>, %5$s is <code>wppus-endpoint-optimiser.php.backup</code>
esc_html__( 'See %1$s for an example of plugin, and %2$ss for an example of theme. They are fully functionnal and can be used to test all the features of the server with a test client installation of WordPress.', 'wppus' ),
'<code>$wppus_always_active_plugins</code>',
'<code>$wppus_bypass_themes</code>',
'<code>false</code>',
'<code>functions.php</code>',
'<code>' . esc_html( dirname( dirname( WPPUS_PLUGIN_PATH ) ) . '/mu-plugins/wppus-endpoint-optimiser.php.backup' ) . '</code>',
);
?>
</p>
<p>
<?php
printf(
Expand All @@ -89,7 +86,7 @@
<?php
printf(
// translators: %s is a link to the documentation
esc_html__( 'The full documentation can be found %s, with more details for developers on how to integrate WP Plugin Server with their own plugins and themes.', 'wppus' ),
esc_html__( 'The full documentation can be found %s, with more details for developers on how to integrate WP Plugin Server with their own plugins, themes, and generic packages.', 'wppus' ),
'<a target="_blank" href="https://github.com/froger-me/wp-packages-update-server/blob/master/README.md">' . esc_html__( 'here', 'wppus' ) . '</a>',
);
?>
Expand All @@ -98,7 +95,7 @@
<?php
printf(
// translators: %1$s is a link to opening an issue, %2$s is a contact email
esc_html__( 'After reading the documentation, for more help on how to use WP Packages Update Server, please %1$s - bugfixes are welcome via pull requests, detailed bug reports with accurate pointers as to where and how they occur in the code will be addressed in a timely manner, and a fee will apply for any other request if they are addressed. If and only if you found a security issue, please contact %2$s with full details for responsible disclosure.', 'wppus' ),
esc_html__( 'After reading the documentation, for more help on how to use WP Packages Update Server, please %1$s - bugfixes are welcome via pull requests, detailed bug reports with accurate pointers as to where and how they occur in the code will be addressed in a timely manner, and a fee will apply for any other request (if they are addressed). If and only if you found a security issue, please contact %2$s with full details for responsible disclosure.', 'wppus' ),
'<a target="_blank" href="https://github.com/froger-me/wp-packages-update-server/issues">' . esc_html__( 'open an issue on Github', 'wppus' ) . '</a>',
'<a href="mailto:[email protected]">[email protected]</a>',
);
Expand Down
6 changes: 3 additions & 3 deletions inc/templates/admin/plugin-licenses-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<select id="wppus_license_package_type">
<option value="plugin"><?php esc_html_e( 'Plugin' ); ?></option>
<option value="theme"><?php esc_html_e( 'Theme' ); ?></option>
<option value="theme"><?php esc_html_e( 'Generic' ); ?></option>
<option value="generic"><?php esc_html_e( 'Generic' ); ?></option>
</select>
</td>
</tr>
Expand All @@ -40,7 +40,7 @@
<td>
<input type="text" id="wppus_license_package_slug" name="wppus_license_package_slug" class="no-submit" value="" size="30">
<p class="description">
<?php esc_html_e( 'The plugin or theme slug. Only alphanumeric characters and dashes are allowed.', 'wppus' ); ?>
<?php esc_html_e( 'The plugin, theme, or generic package slug. Only alphanumeric characters and dashes are allowed.', 'wppus' ); ?>
<br/>
<?php esc_html_e( 'Example of valid value: package-slug', 'wppus' ); ?>
</p>
Expand Down Expand Up @@ -186,7 +186,7 @@
<td>
<input type="checkbox" id="wppus_use_licenses" name="wppus_use_licenses" value="1" <?php checked( get_option( 'wppus_use_licenses', 0 ), 1 ); ?>>
<p class="description">
<?php esc_html_e( 'Check to activate license-enabled plugins and themes packages delivery.', 'wppus' ); ?>
<?php esc_html_e( 'Check to activate license-enabled plugin, theme, and generic packages delivery.', 'wppus' ); ?>
<br>
<strong><?php esc_html_e( 'It affects all the packages with a "Requires License" license status delivered by this installation of WP Packages Update Server.', 'wppus' ); ?></strong>
</p>
Expand Down
2 changes: 1 addition & 1 deletion inc/templates/admin/plugin-packages-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<?php
printf(
// translators: %s is <code>$packages_dir</code>
esc_html__( 'Add a package zip archive to the %s directory. The archive needs to be a valid WordPress plugin or theme package.', 'wppus' ),
esc_html__( 'Add a package zip archive to the %s directory. The archive needs to be a valid generic package, or a valid WordPress plugin or theme package.', 'wppus' ),
'<code>' . esc_html( $packages_dir ) . '</code>',
);
?>
Expand Down
2 changes: 1 addition & 1 deletion inc/templates/admin/plugin-remote-sources-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<td>
<input type="checkbox" id="wppus_use_remote_repository" name="wppus_use_remote_repository" value="1" <?php checked( get_option( 'wppus_use_remote_repository', 0 ), 1 ); ?>>
<p class="description">
<?php esc_html_e( 'Enables this server to download plugins and themes from a Remote Repository before delivering updates.', 'wppus' ); ?>
<?php esc_html_e( 'Enables this server to download plugins, themes and generic packages from a Remote Repository before delivering updates.', 'wppus' ); ?>
<br>
<?php esc_html_e( 'Supports Bitbucket, Github and Gitlab.', 'wppus' ); ?>
<br>
Expand Down
5 changes: 3 additions & 2 deletions inc/templates/admin/remote-webhook-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
<br/>
<?php
printf(
// translators: %1$s is the webhook URL, %2$s is <code>package-type</code>, %3$s is <code>plugin</code>, %4$s is <code>theme</code>, %5$s is <code>package-slug</code>
esc_html__( 'Webhook URL: %1$s - where %2$s is the package type ( %3$s or %4$s ) and %5$s is the slug of the package needing updates.', 'wppus' ),
// translators: %1$s is the webhook URL, %2$s is <code>package-type</code>, %3$s is <code>plugin</code>, %4$s is <code>theme</code>, %5$s is <code>generic</code>, %6$s is <code>package-slug</code>
esc_html__( 'Webhook URL: %1$s - where %2$s is the package type ( %3$s or %4$s or %5$s ) and %6$s is the slug of the package needing updates.', 'wppus' ),
'<code>' . esc_url( home_url( '/wppus-webhook/package-type/package-slug' ) ) . '</code>',
'<code>package-type</code>',
'<code>plugin</code>',
'<code>theme</code>',
'<code>generic</code>',
'<code>package-slug</code>'
);
?>
Expand Down
2 changes: 1 addition & 1 deletion integration/docs/generic.md
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ except requests.exceptions.HTTPError as err:
```bash
#!/bin/bash

url="https://server.domain.tld/wppus-update-api/"
url="https://server.domain.tld/wppus-license-api/"
args=(
"action=activate"
"license_key=41ec1eba0f17d47f76827a33c7daab2c"
Expand Down
23 changes: 23 additions & 0 deletions integration/dummy-generic/dummy-generic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
version="1.4.14"

# get_version function
function get_version() {
echo "$version"
}

if [ "$1" == "get_version" ]; then
# install the package
get_version
# halt the script
exit 0
fi

### INSTALLING THE PACKAGE IF NECESSARY ###

if [ "$(bash "$(dirname "$0")/wppus-api.sh" is_installed)" == "false" ]; then
bash "$(dirname "$0")/wppus-api.sh" install
fi

### PACKAGE EXECUTION ###
echo "Hello"
Loading

0 comments on commit 9df8d9d

Please sign in to comment.