├── .github ├── logo.png ├── FUNDING.yml └── logo.svg ├── CHANGELOG.md ├── .gitignore ├── src ├── Exception │ ├── MissingExtraException.php │ ├── MissingEnvException.php │ └── MissingAuthException.php ├── RemoteFilesystem.php └── Plugin.php ├── composer.json ├── LICENSE ├── CONTRIBUTING.md └── README.md /.github/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lubusIN/composer-edd-plugin/HEAD/.github/logo.png -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | #github: lubusin 4 | patreon: lubus 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | **Change Log** 2 | -------------- 3 | 4 | All notable changes to "Composer EDD Plugin" will be documented here 5 | 6 | ***1.0.0*** 7 | 8 | Released on [TODO] 9 | 10 | - Initial plugin release 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | composer.phar 2 | composer.lock 3 | /vendor/ 4 | 5 | # Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control 6 | # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file 7 | # composer.lock 8 | -------------------------------------------------------------------------------- /src/Exception/MissingExtraException.php: -------------------------------------------------------------------------------- 1 | fileUrl = $fileUrl; 44 | parent::__construct( $io, $config, $options, $disableTls ); 45 | } 46 | 47 | /** 48 | * Copy the remote file to local. 49 | * 50 | * @param string $originUrl The origin URL 51 | * @param string $fileUrl The file URL (ignored) 52 | * @param string $fileName the local filename 53 | * @param bool $progress Display the progression 54 | * @param array $options Additional context options 55 | * @return bool true 56 | */ 57 | public function copy( 58 | $originUrl, 59 | $fileUrl, 60 | $fileName, 61 | $progress = true, 62 | $options = [] 63 | ) { 64 | return parent::copy( 65 | $originUrl, 66 | $this->fileUrl, 67 | $fileName, 68 | $progress, 69 | $options 70 | ); 71 | } 72 | } -------------------------------------------------------------------------------- /.github/logo.svg: -------------------------------------------------------------------------------- 1 | ComposerEDD Plugin -------------------------------------------------------------------------------- /src/Plugin.php: -------------------------------------------------------------------------------- 1 | composer = $composer; 36 | $this->io = $io; 37 | 38 | if ( file_exists( getcwd() . DIRECTORY_SEPARATOR . '.env' ) ) { 39 | $dotenv = Dotenv::createImmutable( getcwd() ); 40 | $dotenv->load(); 41 | } 42 | } 43 | 44 | /** 45 | * Set subscribed events. 46 | * 47 | * @return array 48 | */ 49 | public static function getSubscribedEvents() { 50 | return array( 51 | PackageEvents::PRE_PACKAGE_INSTALL => 'getDownloadUrl', 52 | PackageEvents::PRE_PACKAGE_UPDATE => 'getDownloadUrl', 53 | PluginEvents::PRE_FILE_DOWNLOAD => 'onPreFileDownload', 54 | ); 55 | } 56 | 57 | /** 58 | * Get package from operation. 59 | * 60 | * @param OperationInterface $operation 61 | * @return mixed 62 | */ 63 | protected function getPackageFromOperation( OperationInterface $operation ) { 64 | if ( 'update' === $operation->getJobType() ) { 65 | return $operation->getTargetPackage(); 66 | } 67 | return $operation->getPackage(); 68 | } 69 | 70 | /** 71 | * Get download URL for our plugins. 72 | * 73 | * @param PackageEvent $event 74 | */ 75 | public function getDownloadUrl( PackageEvent $event ) { 76 | $this->downloadUrl = ''; 77 | $package = $this->getPackageFromOperation( $event->getOperation() ); 78 | $package_version = $package->getPrettyVersion(); 79 | $package_dist_url = $package->getDistUrl(); 80 | $package_extra = $package->getExtra(); 81 | 82 | if (!empty( $package_extra['edd_installer'])) { 83 | if (empty($package_extra['item_name'])) { 84 | throw new MissingExtraException('item_name'); 85 | } 86 | 87 | if (empty($package_extra['license'])) { 88 | throw new MissingExtraException('license'); 89 | } 90 | else { 91 | if (!getenv($package_extra['license'])) { 92 | throw new MissingEnvException('license'); 93 | } 94 | } 95 | 96 | if (empty($package_extra['url'])) { 97 | throw new MissingExtraException('url'); 98 | } else { 99 | if (!getenv($package_extra['url'])) { 100 | throw new MissingEnvException('url'); 101 | } 102 | } 103 | 104 | if ( file_exists( getcwd() . DIRECTORY_SEPARATOR . 'auth.json' ) ) { 105 | $auth_file = getcwd() . DIRECTORY_SEPARATOR . 'auth.json'; 106 | $auth_data = json_decode(file_get_contents($auth_file), true); 107 | $package = parse_url($package_dist_url); 108 | 109 | print $package['host']; 110 | 111 | if (!array_key_exists($package['host'], $auth_data['http-basic'])) { 112 | throw new MissingAuthException('Auth credentials missing for ' . $package['host']); 113 | } 114 | } else { 115 | throw new MissingAuthException('Auth file auth.json missing'); 116 | } 117 | 118 | $package_details = [ 119 | 'edd_action' => 'get_version', 120 | 'license' => getenv( $package_extra['license'] ), 121 | 'item_name' => $package_extra['item_name'], 122 | 'url' => getenv( $package_extra['url'] ), 123 | 'version' => $package_version, 124 | ]; 125 | 126 | $context = stream_context_create([ 127 | "http" => [ 128 | "method" => "POST", 129 | 'header' =>"Content-Type: application/json; charset=utf-8", 130 | "timeout" => 30, 131 | ], 132 | ]); 133 | 134 | $edd_response = file_get_contents($package_dist_url . '?' . http_build_query($package_details), false, $context); 135 | 136 | if( !$edd_response) { 137 | throw new Exception('Unable to connect to ' . $package_dist_url); 138 | } 139 | 140 | $edd_data = json_decode($edd_response, true); 141 | 142 | if( !empty($edd_data['download_link'])) { 143 | $this->downloadUrl = $edd_data['download_link']; 144 | } 145 | 146 | } 147 | } 148 | 149 | /** 150 | * Process our plugin downloads. 151 | * 152 | * @param PreFileDownloadEvent $event 153 | */ 154 | public function onPreFileDownload( PreFileDownloadEvent $event ) { 155 | if ( empty( $this->downloadUrl ) ) { 156 | return; 157 | } 158 | 159 | $RemoteFileSystem = $event->getRemoteFilesystem(); 160 | $EddStore = new RemoteFilesystem( 161 | $this->downloadUrl, 162 | $this->io, 163 | $this->composer->getConfig(), 164 | $RemoteFileSystem->getOptions(), 165 | $RemoteFileSystem->isTlsDisabled() 166 | ); 167 | $event->setRemoteFilesystem( $EddStore ); 168 | } 169 | 170 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | Composer EDD Plugin 3 |

4 |

5 | Latest Stable Version 6 | Total Downloads 7 | License 8 | PRs 9 |

10 | 11 | ## Introduction 12 | 13 | Composer EDD Plugin enable installing and managing WordPress pro offerings powered by [EasyDigitalDownloads](https://easydigitaldownloads.com/) and [software licensing add-on](https://easydigitaldownloads.com/downloads/software-licensing/) via composer. Works with any plugin or theme delivered via EasyDigitalDownloads and software licensing for distribution. 14 | 15 | ## Installation 16 | 17 | Install the composer plugin to enable composer package via EDD Software licencing. 18 | 19 | ``` bash 20 | composer require lubusin/composer-edd-plugin 21 | ``` 22 | 23 | ## Usage 24 | 25 | ### Step 1 26 | 27 | Add the desired WordPress premium offering(s) as package to the repositories field in composer.json. Find more about composer repositories in the [composer documentation](https://getcomposer.org/doc/05-repositories.md#package-2) 28 | 29 | ``` json 30 | { 31 | "type": "package", 32 | "package": { 33 | "name": "namespace/edd-product-name", 34 | "version": "version-number", 35 | "type": "wordpress-plugin", 36 | "dist": { 37 | "type": "zip", 38 | "url": "https://www.productwebsite.com" 39 | }, 40 | "extra": { 41 | "edd_installer": true, 42 | "item_name": "Product Name", 43 | "license": "PRODUCT_LICENSE", 44 | "url": "PRODUCT_ACTIVATION_URL" 45 | } 46 | } 47 | } 48 | ``` 49 | 50 | Above package details hold important info to connect and download zip from product store: 51 | 52 | **Important** 53 | 54 | - `name` this can be customized as per your need, it's the package name used for `composer require namespace/edd-product-name` later 55 | - `version` used to get the zip, check account for version number 56 | - `type` use wordpress-plugin or wordpress-theme, 57 | 58 | - `url` product website url (include https) 59 | - `edd_installer` enable package via edd powered store 60 | - `item_name` name of product, can be found under account info 61 | - `license` name of env variable to get the license key *(do not add your actual key here)* 62 | - `url` name of env variable to get the website url associated with the license. *(do not add your actual website url here)* 63 | 64 | **Note:** 65 | 66 | - Add multiple package enteris to add more then one product 67 | - Most EDD products only allow getting the latest versions of their product, even if you specifically ask for a version. 68 | - Make sure license is already activated for the url. 69 | 70 | ### Step 2 71 | 72 | Create `.env` and add the varaible names mentioned in the above step. Find more about .env [here](https://github.com/vlucas/phpdotenv) 73 | 74 | ``` 75 | PRODUCT_LICENSE=product-license-key 76 | PRODUCT_ACTIVATION_URL=product-activation-url 77 | ``` 78 | 79 | ### Step 3 80 | 81 | Create the `auth.json` and Add the store access credentials. Find more about http-basic-authentication in the [composer documentation](https://getcomposer.org/doc/articles/http-basic-authentication.md) 82 | 83 | ``` json 84 | { 85 | "http-basic": { 86 | "www.productwebsite.com": { 87 | "username": "your-username", 88 | "password": "your-password" 89 | } 90 | } 91 | } 92 | ``` 93 | 94 | **Important** 95 | 96 | - `www.productwebsite.com` product website host name 97 | - `username` login username for product website 98 | - `password` login password for product website 99 | 100 | **Note** 101 | 102 | To add credentials for more than one product stores add multiple credentials under `http-basic` 103 | 104 | ### Step 4 105 | 106 | Install the plugin 107 | 108 | ``` bash 109 | composer require namespace/edd-product-name 110 | ``` 111 | 112 | ## Troubleshooting 113 | 114 | ``` 115 | [Composer\Downloader\TransportException] 116 | Your configuration does not allow connections to http://www.productwebsite.com See https://getcomposer.org/doc/06-config.md#sec 117 | ure-http for details. 118 | ``` 119 | you will get above error if edd store deliver file over `http` instead of `https`. To fix this config composer to allow non secure url by setting `secure-http` to false. Find more about secure-http in the [composer documentation](https://getcomposer.org/doc/06-config.md#secure-http) 120 | 121 | **Note** 122 | - Use the name set in step 1 123 | - To install multiple products add them seperating with space. 124 | 125 | ## Changelog 126 | 127 | Please see the [Changelog](CHANGELOG.md) 128 | 129 | ## Feedback / Suggestions 130 | 131 | If you have any suggestions/feature request that you would like to see in the upcoming releases, feel free to let us know in the [issues section](https://github.com/lubusIN/composer-edd-plugin/issues) 132 | 133 | ## Contributing 134 | 135 | Thank you in advance if you wish to contribute to the `Composer EDD Plugin`. You can read the contribution guidelines [here](CONTRIBUTING.md) 136 | 137 | Check the development tasklist [here](https://github.com/lubusIN/composer-edd-plugin/projects/1), if something interests you or want to suggest something click [here](https://github.com/lubusIN/composer-edd-plugin/issues) 138 | 139 | ## Security 140 | 141 | If you discover any security related issues, please email to [info@lubus.in](mailto:info@lubus.com) instead of using the issue tracker. 142 | 143 | ## Credits 144 | 145 | [Ajit Bohra](http://https://twitter.com/ajitbohra) 146 | 147 | ## Special Mentions 148 | 149 | - Inspiration https://github.com/polylang/polylang/issues/3 150 | - Motivation [@szepeviktor](https://github.com/szepeviktor) | https://github.com/polylang/polylang/issues/3#issuecomment-636411477 151 | - Beta testing [@nirbhay](https://twitter.com/Nirbhay_18) & [@ideabox](https://twitter.com/helloideabox) 152 | - Logo icon credits [prosymbols](https://thenounproject.com/prosymbols) 153 | - Code inspiration 154 | - https://github.com/ffraenz/private-composer-installer/ 155 | - https://github.com/junaidbhura/composer-wp-pro-plugins/ 156 | - https://github.com/szepeviktor/composer-envato 157 | - https://github.com/mautic/composer-plugin/ 158 | 159 | ## Support Us 160 | 161 | 162 | Become A Patron 163 | 164 | 165 | [LUBUS](http://lubus.in) is a web design agency based in Mumbai, India. 166 | 167 | You can pledge on [patreon](https://www.patreon.com/lubus) to support the development & maintenance of various [opensource](https://github.com/lubusIN/) stuffs we are building. 168 | 169 | ## License 170 | 171 | Composer EDD Plugin is open-sourced software licensed under the [MIT license](LICENSE) 172 | --------------------------------------------------------------------------------