diff --git a/_admin.php b/_admin.php index e0aae8f..ace60c8 100644 --- a/_admin.php +++ b/_admin.php @@ -17,10 +17,11 @@ $core->addBehavior('adminDashboardFavorites', ['ImproveBehaviors', 'adminDashboa $core->addBehavior('improveAddAction', ['ImproveActionDcstore', 'create']); $core->addBehavior('improveAddAction', ['ImproveActionEndoffile', 'create']); +$core->addBehavior('improveAddAction', ['ImproveActionGitshields', 'create']); +$core->addBehavior('improveAddAction', ['ImproveActionLicensefile', 'create']); //$core->addBehavior('improveAddAction', ['ImproveActionLicense', 'create']); $core->addBehavior('improveAddAction', ['ImproveActionNewline', 'create']); $core->addBehavior('improveAddAction', ['ImproveActionPhpheader', 'create']); -$core->addBehavior('improveAddAction', ['ImproveActionGitshields', 'create']); $core->addBehavior('improveAddAction', ['ImproveActionTab', 'create']); $core->addBehavior('improveAddAction', ['ImproveActionZip', 'create']); diff --git a/_prepend.php b/_prepend.php index be80fe9..4785a56 100644 --- a/_prepend.php +++ b/_prepend.php @@ -21,10 +21,10 @@ $__autoload['ImproveAction'] = $d . 'class.improve.action.php'; $__autoload['ImproveActionDcstore'] = $d . 'lib.improve.action.dcstore.php'; $__autoload['ImproveActionEndoffile'] = $d . 'lib.improve.action.php'; -//$__autoload['ImproveActionLicense'] = $d . 'lib.improve.action.license.php'; +$__autoload['ImproveActionGitshields'] = $d . 'lib.improve.action.gitshields.php'; +$__autoload['ImproveActionLicensefile'] = $d . 'lib.improve.action.licensefile.php'; $__autoload['ImproveActionNewline'] = $d . 'lib.improve.action.php'; $__autoload['ImproveActionPhpheader'] = $d . 'lib.improve.action.phpheader.php'; -$__autoload['ImproveActionGitshields'] = $d . 'lib.improve.action.gitshields.php'; $__autoload['ImproveActionTab'] = $d . 'lib.improve.action.php'; $__autoload['ImproveActionZip'] = $d . 'lib.improve.action.zip.php'; $__autoload['ImproveZipFileZip'] = $d . 'lib.improve.action.zip.php'; \ No newline at end of file diff --git a/inc/lib.improve.action.license.php b/inc/lib.improve.action.license.php deleted file mode 100644 index b47fda3..0000000 --- a/inc/lib.improve.action.license.php +++ /dev/null @@ -1,331 +0,0 @@ -setProperties([ - 'id' => 'license', - 'name' => __('Fix license'), - 'desc' => __('Add or remove license bloc at the begining of file and full license file to module root'), - 'priority' => 320, - 'config' => true, - 'types' => ['plugin', 'theme'] - ]); - - $this->action_version = [ - __('no version selected') => '', - __('gpl2 - GNU General Public License v2') => 'gpl2', - __('gpl3 - GNU General Public License v3') => 'gpl3', - __('lgpl3 - GNU Lesser General Public License v3') => 'lgpl3', - __('Massachusetts Institute of Technolog mit') => 'mit' - ]; - $this->action_full = [ - __('Do nothing') => 0, - __('Add file if it does not exist') => 'create', - __('Add file even if it exists') => 'overwrite', - __('Remove license file') => 'remove' - ]; - $this->action_bloc = [ - __('Do nothing') => 0, - __('Add bloc if it does not exist') => 'create', - __('Add bloc even if it exists') => 'overwrite' , - __('Remove old style bloc') => 'remove' - ]; - - return true; - } - - public function isConfigured(): bool - { - return true; - } - - public function configure($url): ?string - { - if (!empty($_POST['save'])) { - $this->setPreferences([ - 'action_version' => !empty($_POST['action_version']) ? $_POST['action_version'] : '', - 'action_full' => !empty($_POST['action_full']) ? $_POST['action_full'] : '', - 'action_php' => !empty($_POST['action_php']) ? $_POST['action_php'] : '', - 'action_js' => !empty($_POST['action_js']) ? $_POST['action_js'] : '', - 'exclude_locales' => !empty($_POST['lb_exclude_locales']), - 'use_custom_bloc' => !empty($_POST['lb_use_custom_bloc']), - 'custom_bloc' => !empty($_POST['lb_custom_bloc']) ? $_POST['lb_custom_bloc'] : '' - ]); - $this->redirect($url); - } - - return ' -
' . __('This manages old style bloc, it is better to use modern phpDdoc style.') . '
-' . - form::combo('action_version', $this->action_version, $this->getPreference('action_version')) . ' -
- -' . - form::combo('action_full', $this->action_full, $this->getPreference('action_full')) . ' -
- -' . - form::combo('action_php', $this->action_bloc, $this->getPreference('action_php')) . ' -
- -' . - form::combo('action_js', $this->action_bloc, $this->getPreference('action_js')) . ' -
- - - - - -' . - form::textarea('lb_custom_bloc', 50, 10, html::escapeHTML($this->getPreference('custom_bloc'))) . ' -
' .
- sprintf(
- __('You can use wildcards %s') ,
- '%year%, %module_id%, %module_name%, %module_author%, %module_type%, %user_cn%, %user_name%, %user_email%, %user_url%'
- ) . '
' . __('Do not put structural elements to the begining of lines.') . '
' . + form::combo('action_version', $this->action_version, $this->getPreference('action_version')) . ' +
+ +' . + form::combo('action_full', $this->action_full, $this->getPreference('action_full')) . + '
'; + } + + public function openModule(string $module_type, array $module_info): ?bool + { + $this->type = $module_type; + $this->module = $module_info; + + if (in_array($this->getPreference('action_full'), ['remove', 'full','overwrite'])) { + $this->deleteFullLicense(($this->getPreference('action_full') == 'overwrite')); + } + if (in_array($this->getPreference('action_full'), ['create', 'overwrite', 'full'])) { + if (empty($this->getPreference('action_version'))) { + self::notice(__('no full license type selected'), false); + } else { + $this->writeFullLicense(); + } + } + return null; + } + + private function writeFullLicense() + { + try { + $full = file_get_contents(dirname(__FILE__) . '/license/' . $this->getPreference('action_version') . '.full.txt'); + if (empty($full)) { + self::notice(__('failed to load full license')); + + return null; + } + files::putContent($this->module['root'] . '/LICENSE', str_replace("\r\n","\n",$full)); + } catch (Exception $e) { + self::notice(__('failed to write full license')); + + return null; + } + return true; + } + + private function deleteFullLicense($only_one = false) + { + foreach(self::fileExists($this->module['root']) as $file) { + if ($only_one && $file != 'license') { + continue; + } + if (!files::isDeletable($this->module['root'] . '/' . $file)) { + self::notice(sprintf(__('full license is not deletable (%s)'), $file), false); + } + if (!@unlink($this->module['root'] . '/' . $file)) { + self::notice(sprintf(__('failed to delete full license (%s)'), $file), false); + } + } + return true; + } + + private static function fileExists($root) + { + $existing = []; + foreach(self::$license_filenames as $file) { + if (file_exists($root . '/' . strtolower($file))) { + $existing[] = strtolower($file); + } + } + return $existing; + } +} \ No newline at end of file diff --git a/inc/license/gpl2.head.txt b/inc/license/gpl2.head.txt deleted file mode 100644 index 996c417..0000000 --- a/inc/license/gpl2.head.txt +++ /dev/null @@ -1,8 +0,0 @@ -This file is part of %module_id%, a %module_type% for Dotclear 2. - -Copyright (c) %year% %user_cn% and contributors -%user_email% - -Licensed under the GPL version 2.0 license. -A copy of this license is available in LICENSE file or at -http://www.gnu.org/licenses/old-licenses/gpl-2.0.html \ No newline at end of file diff --git a/inc/license/gpl3.head.txt b/inc/license/gpl3.head.txt deleted file mode 100644 index 9136ec9..0000000 --- a/inc/license/gpl3.head.txt +++ /dev/null @@ -1,8 +0,0 @@ -This file is part of %module_id%, a %module_type% for Dotclear 2. - -Copyright (c) %year% %user_cn% and contributors -%user_email% - -Licensed under the GPL version 3.0 license. -A copy of this license is available in LICENSE file or at -http://www.gnu.org/licenses/gpl-3.0.html \ No newline at end of file diff --git a/inc/license/lgpl3.head.txt b/inc/license/lgpl3.head.txt deleted file mode 100644 index c897daf..0000000 --- a/inc/license/lgpl3.head.txt +++ /dev/null @@ -1,8 +0,0 @@ -This file is part of %module_id%, a %module_type% for Dotclear 2. - -Copyright (c) %year% %user_cn% and contributors -%user_email% - -Licensed under the LGPL version 3.0 license. -A copy of this license is available in LICENSE file or at -http://www.gnu.org/licenses/lgpl-3.0.html \ No newline at end of file diff --git a/inc/license/mit.head.txt b/inc/license/mit.head.txt deleted file mode 100644 index dbc4224..0000000 --- a/inc/license/mit.head.txt +++ /dev/null @@ -1,7 +0,0 @@ -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. \ No newline at end of file