diff --git a/CHANGELOG.md b/CHANGELOG.md index fad8549..dc08564 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,12 @@ tweakStore 0.x.x -- create themes tab - create update from external repositories - fix permissions - fix translation +tweakStores 0.0.x - 2021.08.xx +- add write dcstore.xml for modules tab +- create themes tab + tweakStores 0.0.2 - 2021.08.26 - initial commit - create config page diff --git a/_admin.php b/_admin.php index 328feb3..3eb26fd 100644 --- a/_admin.php +++ b/_admin.php @@ -15,47 +15,57 @@ if (!defined('DC_CONTEXT_ADMIN')) { return null; } +# only superadmin if (!$core->auth->isSuperAdmin()) { return null; } +# only if activated $core->blog->settings->addNamespace('tweakStores'); - if (!$core->blog->settings->tweakStores->active) { return null; } -# Admin behaviors +# admin behaviors if ($core->blog->settings->tweakStores->packman) { $core->addBehavior('packmanBeforeCreatePackage', ['tweakStoresBehaviors', 'packmanBeforeCreatePackage']); } $core->addBehavior('pluginsToolsTabs', ['tweakStoresBehaviors', 'pluginsToolsTabs']); +$core->addBehavior('themesToolsTabs', ['tweakStoresBehaviors', 'themesToolsTabs']); class tweakStoresBehaviors { + # create dcstore.xml file on the fly when pack a module public static function packmanBeforeCreatePackage(dcCore $core, $module) { tweakStores::writeXML($module['id'], $module, $core->blog->settings->tweakStores->file_pattern); } + # admin plugins page tab public static function pluginsToolsTabs(dcCore $core) { - $file_pattern = $core->blog->settings->tweakStores->file_pattern; - $distributed_modules = explode(',', DC_DISTRIB_PLUGINS); - $plugins = [ __('Select a plugin') => '0']; - $modules = $core->plugins->getModules(); - foreach ($modules as $id => $module) { - if (is_array($distributed_modules) && in_array($id, $distributed_modules)) { - unset($modules[$id]); - continue; - } - $plugins[$module['name'] . ' '. $module['version']] = $id; - } + self::modulesToolsTabs($core, $core->plugins->getModules(), explode(',', DC_DISTRIB_PLUGINS), $core->adminurl->get('admin.plugins').'#tweakStores'); + } - if (!empty($_POST['buildxml_id']) && in_array($_POST['buildxml_id'], $plugins)) { + # admin themes page tab + public static function themesToolsTabs(dcCore $core) + { + self::modulesToolsTabs($core, $core->themes->getModules(), explode(',', DC_DISTRIB_THEMES), $core->adminurl->get('admin.blog.theme').'#tweakStores'); + } + + # generic page tab + protected static function modulesToolsTabs(dcCore $core, $modules, $excludes, $page_url) + { + $file_pattern = $core->blog->settings->tweakStores->file_pattern; + $modules = new ArrayObject($modules); + $combo = self::comboModules($modules, $excludes); + + # generate xml code + if (!empty($_POST['buildxml_id']) && $modules->offsetExists($_POST['buildxml_id'])) { $xml_content = tweakStores::generateXML($_POST['buildxml_id'], $modules[$_POST['buildxml_id']], $file_pattern); } + # write dcstore.xml file if (!empty($_POST['write_xml'])) { if (empty($_POST['your_pwd']) || !$core->auth->checkPassword($_POST['your_pwd'])) { $core->error->add(__('Password verification failed')); @@ -69,13 +79,22 @@ class tweakStoresBehaviors echo '
' . - __('You must configure zip file pattern to complete xml code automaticaly.') . '
'; - } - echo + '' . ''; } + + # create list of module for combo and remove official modules + protected static function comboModules(arrayObject $modules, $excludes) + { + $combo = [ __('Select a module') => '0']; + foreach ($modules as $id => $module) { + if (is_array($excludes) && in_array($id, $excludes)) { + $modules->offsetUnset($id); + continue; + } + $combo[$module['name'] . ' '. $module['version']] = $id; + } + return $combo; + } } \ No newline at end of file