add themes tab
This commit is contained in:
parent
ff2a17b264
commit
bda80a20b4
2 changed files with 68 additions and 31 deletions
|
@ -1,9 +1,12 @@
|
||||||
tweakStore 0.x.x
|
tweakStore 0.x.x
|
||||||
- create themes tab
|
|
||||||
- create update from external repositories
|
- create update from external repositories
|
||||||
- fix permissions
|
- fix permissions
|
||||||
- fix translation
|
- 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
|
tweakStores 0.0.2 - 2021.08.26
|
||||||
- initial commit
|
- initial commit
|
||||||
- create config page
|
- create config page
|
||||||
|
|
92
_admin.php
92
_admin.php
|
@ -15,47 +15,57 @@ if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# only superadmin
|
||||||
if (!$core->auth->isSuperAdmin()) {
|
if (!$core->auth->isSuperAdmin()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# only if activated
|
||||||
$core->blog->settings->addNamespace('tweakStores');
|
$core->blog->settings->addNamespace('tweakStores');
|
||||||
|
|
||||||
if (!$core->blog->settings->tweakStores->active) {
|
if (!$core->blog->settings->tweakStores->active) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Admin behaviors
|
# admin behaviors
|
||||||
if ($core->blog->settings->tweakStores->packman) {
|
if ($core->blog->settings->tweakStores->packman) {
|
||||||
$core->addBehavior('packmanBeforeCreatePackage', ['tweakStoresBehaviors', 'packmanBeforeCreatePackage']);
|
$core->addBehavior('packmanBeforeCreatePackage', ['tweakStoresBehaviors', 'packmanBeforeCreatePackage']);
|
||||||
}
|
}
|
||||||
$core->addBehavior('pluginsToolsTabs', ['tweakStoresBehaviors', 'pluginsToolsTabs']);
|
$core->addBehavior('pluginsToolsTabs', ['tweakStoresBehaviors', 'pluginsToolsTabs']);
|
||||||
|
$core->addBehavior('themesToolsTabs', ['tweakStoresBehaviors', 'themesToolsTabs']);
|
||||||
|
|
||||||
class tweakStoresBehaviors
|
class tweakStoresBehaviors
|
||||||
{
|
{
|
||||||
|
# create dcstore.xml file on the fly when pack a module
|
||||||
public static function packmanBeforeCreatePackage(dcCore $core, $module)
|
public static function packmanBeforeCreatePackage(dcCore $core, $module)
|
||||||
{
|
{
|
||||||
tweakStores::writeXML($module['id'], $module, $core->blog->settings->tweakStores->file_pattern);
|
tweakStores::writeXML($module['id'], $module, $core->blog->settings->tweakStores->file_pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# admin plugins page tab
|
||||||
public static function pluginsToolsTabs(dcCore $core)
|
public static function pluginsToolsTabs(dcCore $core)
|
||||||
{
|
{
|
||||||
$file_pattern = $core->blog->settings->tweakStores->file_pattern;
|
self::modulesToolsTabs($core, $core->plugins->getModules(), explode(',', DC_DISTRIB_PLUGINS), $core->adminurl->get('admin.plugins').'#tweakStores');
|
||||||
$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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
$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['write_xml'])) {
|
||||||
if (empty($_POST['your_pwd']) || !$core->auth->checkPassword($_POST['your_pwd'])) {
|
if (empty($_POST['your_pwd']) || !$core->auth->checkPassword($_POST['your_pwd'])) {
|
||||||
$core->error->add(__('Password verification failed'));
|
$core->error->add(__('Password verification failed'));
|
||||||
|
@ -69,13 +79,22 @@ class tweakStoresBehaviors
|
||||||
|
|
||||||
echo
|
echo
|
||||||
'<div class="multi-part" id="tweakStores" title="' . __('Tweak stores') . '">' .
|
'<div class="multi-part" id="tweakStores" title="' . __('Tweak stores') . '">' .
|
||||||
'<h3>' . __('Tweak third-party repositories') . '</h3>' .
|
'<h3>' . __('Tweak third-party repositories') . '</h3>';
|
||||||
|
|
||||||
|
if (count($combo) < 2) {
|
||||||
|
echo
|
||||||
|
'<div class="info">' . __('There are no module to tweak') . '</div>' .
|
||||||
|
'</div>';
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
'<form method="post" action="' . $core->adminurl->get('admin.plugins') . '#tweakStores" id="fetchxml" class="fieldset">' .
|
echo
|
||||||
|
'<form method="post" action="' . $page_url . '" id="fetchxml" class="fieldset">' .
|
||||||
'<h4>' . __('Update an existing plugin') . '</h4>' .
|
'<h4>' . __('Update an existing plugin') . '</h4>' .
|
||||||
'<p>' . __('Put URL to a dcstore.xml file for selected plugin to update it.') . '</p>' .
|
'<p>' . __('Put URL to a dcstore.xml file for selected plugin to update it.') . '</p>' .
|
||||||
'<p class="field"><label for="xml_id" class="classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Plugin to update:') . '</label> ' .
|
'<p class="field"><label for="xml_id" class="classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Plugin to update:') . '</label> ' .
|
||||||
form::combo('xml_id', $plugins) .
|
form::combo('xml_id', $combo) .
|
||||||
'</p>' .
|
'</p>' .
|
||||||
'<p class="field"><label for="xml_url" class="classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('XML file URL:') . '</label> ' .
|
'<p class="field"><label for="xml_url" class="classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('XML file URL:') . '</label> ' .
|
||||||
form::field('xml_url', 40, 255, [
|
form::field('xml_url', 40, 255, [
|
||||||
|
@ -91,13 +110,14 @@ class tweakStoresBehaviors
|
||||||
) . '</p>' .
|
) . '</p>' .
|
||||||
'<p><input type="submit" name="fetch_xml" value="' . __('Update') . '" />' .
|
'<p><input type="submit" name="fetch_xml" value="' . __('Update') . '" />' .
|
||||||
$core->formNonce() . '</p>' .
|
$core->formNonce() . '</p>' .
|
||||||
'</form>' .
|
'</form>';
|
||||||
//*/
|
//*/
|
||||||
'<form method="post" action="' . $core->adminurl->get('admin.plugins') . '#tweakStores" id="buildxml" class="fieldset">' .
|
echo
|
||||||
|
'<form method="post" action="' . $page_url . '" id="buildxml" class="fieldset">' .
|
||||||
'<h4>' . __('Generate xml code') . '</h4>' .
|
'<h4>' . __('Generate xml code') . '</h4>' .
|
||||||
'<p>' . __('This help to generate content of dcstore.xml for seleted plugin.') . '</p>' .
|
'<p>' . __('This help to generate content of dcstore.xml for seleted module.') . '</p>' .
|
||||||
'<p class="field"><label for="buildxml_id" class="classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Plugin to parse:') . '</label> ' .
|
'<p class="field"><label for="buildxml_id" class="classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Module to parse:') . '</label> ' .
|
||||||
form::combo('buildxml_id', $plugins, empty($_POST['buildxml_id']) ? '-' : html::escapeHTML($_POST['buildxml_id'])) .
|
form::combo('buildxml_id', $combo, empty($_POST['buildxml_id']) ? '-' : html::escapeHTML($_POST['buildxml_id'])) .
|
||||||
'</p>' .
|
'</p>' .
|
||||||
'<p><input type="submit" name="build_xml" value="' . __('Generate') . '" />' .
|
'<p><input type="submit" name="build_xml" value="' . __('Generate') . '" />' .
|
||||||
$core->formNonce() . '</p>' .
|
$core->formNonce() . '</p>' .
|
||||||
|
@ -105,8 +125,8 @@ class tweakStoresBehaviors
|
||||||
|
|
||||||
if (!empty($_POST['buildxml_id'])) {
|
if (!empty($_POST['buildxml_id'])) {
|
||||||
echo
|
echo
|
||||||
'<form method="post" action="' . $core->adminurl->get('admin.plugins') . '#tweakStores" id="writexml" class="fieldset">' .
|
'<form method="post" action="' . $page_url . '" id="writexml" class="fieldset">' .
|
||||||
'<h5>' . sprintf(__('Generated code for module : %s'), html::escapeHTML($_POST['buildxml_id'])) . '</h5>';
|
'<h4>' . sprintf(__('Generated code for module : %s'), html::escapeHTML($_POST['buildxml_id'])) . '</h4>';
|
||||||
|
|
||||||
if (!empty(tweakStores::$failed)) {
|
if (!empty(tweakStores::$failed)) {
|
||||||
echo sprintf('<div class="warn">' . __('Failed to parse XML code : %s') . '</div>', implode(', ', tweakStores::$failed));
|
echo sprintf('<div class="warn">' . __('Failed to parse XML code : %s') . '</div>', implode(', ', tweakStores::$failed));
|
||||||
|
@ -135,7 +155,7 @@ class tweakStoresBehaviors
|
||||||
'autocomplete' => 'current-password'
|
'autocomplete' => 'current-password'
|
||||||
]
|
]
|
||||||
) . '</p>' .
|
) . '</p>' .
|
||||||
'<p><input type="submit" name="write_xml" value="' . __('Save to plugin directory') . '" />' .
|
'<p><input type="submit" name="write_xml" value="' . __('Save to module directory') . '" />' .
|
||||||
form::hidden('buildxml_id', $_POST['buildxml_id']);
|
form::hidden('buildxml_id', $_POST['buildxml_id']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,12 +163,26 @@ class tweakStoresBehaviors
|
||||||
'<p>' . $core->formNonce() . '</p>' .
|
'<p>' . $core->formNonce() . '</p>' .
|
||||||
'</form>';
|
'</form>';
|
||||||
}
|
}
|
||||||
if (empty($file_pattern)) {
|
|
||||||
echo '<p><a href="' . $core->adminurl->get('admin.plugins', ['module' => 'tweakStores', 'conf' => 1]) .'">' .
|
|
||||||
__('You must configure zip file pattern to complete xml code automaticaly.') . '</a></p>';
|
|
||||||
}
|
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
'<p><a href="' . $core->adminurl->get('admin.plugins', ['module' => 'tweakStores', 'conf' => 1, 'redir' => $page_url]) .'">' .
|
||||||
|
(empty($file_pattern) ?
|
||||||
|
__('You must configure zip file pattern to complete xml code automaticaly.') :
|
||||||
|
__('You can edit zip file pattern from configuration page.')
|
||||||
|
). '</a></p>' .
|
||||||
'</div>';
|
'</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 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;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue