Skip to content

Instantly share code, notes, and snippets.

@Septdir
Last active May 28, 2024 19:16
Show Gist options
  • Save Septdir/cd09ea48c0aa22f19de34a2594864e24 to your computer and use it in GitHub Desktop.
Save Septdir/cd09ea48c0aa22f19de34a2594864e24 to your computer and use it in GitHub Desktop.
Joomla - Cleanup after install

Joomla - Очистка после установки

Скрипт отключает не нужные разширения.

Как использовать

  1. Залейте файл cleanup.php в папку administation
  2. Перейдите по адресу https://www.example.com/administrator/cleanup.php
  3. Выберите те раширение которые надо отключить
  4. Нажмите Cleanup
  5. Удалите файл cleanup.php

Joomla - Cleanup after install

Script for disable extensions after install Joomla

How to use

  1. Upload cleanup.php to administation folder
  2. Go to https://www.example.com/administrator/cleanup.php
  3. Check which exntensions nedd disable
  4. Click Cleanup
  5. Remove cleanup.php file
<?php
/**
* @package Joomla cleanup after instalation
* @version 1.0.0
* @author Igor Berdicheskiy - septdir.ru
* @copyright Copyright (c) 2013 - 2019 Igor Berdicheskiy. All rights reserved.
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
* @link https://septdir.ru
*/
define('_JEXEC', 1);
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Load the administrator application's path constants
if (file_exists(__DIR__ . '/defines.php'))
{
include_once __DIR__ . '/defines.php';
}
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', __DIR__);
require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_BASE . '/includes/framework.php';
require_once JPATH_BASE . '/includes/helper.php';
use Joomla\CMS\Factory;
$components = array(
4 => 'Banners',
8 => 'Contacts',
17 => 'News Feeds',
19 => 'Search',
27 => 'Smart Search',
30 => 'Content History',
33 => 'Fields',
34 => 'Multilingual Associations',
);
$modules = array(
'Site' => array(
200 => 'Articles - Archived',
201 => 'Articles - Latest',
202 => 'Articles - Most Read',
203 => 'Banners',
206 => 'Feed Display',
207 => 'Footer',
210 => 'Articles - Newsflash',
211 => 'Random Image',
212 => 'Articles - Related',
213 => 'Search',
214 => 'Statistics',
216 => 'Latest Users',
218 => 'Who\'s Online',
219 => 'Wrapper',
220 => 'Articles - Category',
221 => 'Articles - Categories',
223 => 'Smart Search',
316 => 'Tags - Popular',
317 => 'Tags - Similar',
),
'Admin' => array(
301 => 'Feed Display',
302 => 'Articles - Latest',
303 => 'Logged-in Users',
305 => 'Administrator Menu',
307 => 'Popular Articles',
309 => 'User Status',
310 => 'Administrator Sub-Menu',
311 => 'Title',
313 => 'Multilingual Status',
314 => 'Joomla! Version Information',
315 => 'Statistics',
318 => 'Sample Data',
319 => 'Action Logs - Latest',
320 => 'Privacy Dashboard',
)
);
$plugins = array(
'Action Log' => array(
484 => 'Action Log - Joomla',
),
'Authentication' => array(
449 => 'Authentication - Joomla',
),
'Content' => array(
403 => 'Content - Contact',
404 => 'Content - Email Cloaking',
406 => 'Content - Load Modules',
407 => 'Content - Page Break',
408 => 'Content - Page Navigation',
435 => 'Content - Joomla',
477 => 'Content - Fields',
),
'Editors' => array(
412 => 'Editor - TinyMCE',
),
'Button' => array(
413 => 'Button - Article',
414 => 'Button - Image',
415 => 'Button - Page Break',
416 => 'Button - Readmore',
453 => 'Button - Module',
459 => 'Button - Menu',
460 => 'Button - Contact',
478 => 'Button - Field',
),
'Fields' => array(
462 => 'Fields - Calendar',
463 => 'Fields - Checkboxes',
464 => 'Fields - Colour',
465 => 'Fields - Editor',
466 => 'Fields - Imagelist',
467 => 'Fields - Integer',
468 => 'Fields - List',
469 => 'Fields - Media',
470 => 'Fields - Radio',
471 => 'Fields - SQL',
472 => 'Fields - Text',
473 => 'Fields - Textarea',
474 => 'Fields - URL',
475 => 'Fields - User',
476 => 'Fields - Usergrouplist',
481 => 'Fields - Repeatable',
),
'Smart Search' => array(
442 => 'Smart Search - Categories',
443 => 'Smart Search - Contacts',
444 => 'Smart Search - Content',
445 => 'Smart Search - News Feeds',
447 => 'Smart Search - Tags',
),
'Privacy' => array(
487 => 'Privacy - User Accounts',
490 => 'Privacy - Contacts',
491 => 'Privacy - Content',
492 => 'Privacy - User Messages',
493 => 'Privacy - Action Logs',
495 => 'Privacy - Consents',
),
'Quick Icon' => array(
488 => 'Quick Icon - Joomla! Privacy Requests Notification',
),
'Sample Data' => array(
479 => 'Sample Data - Blog',
),
'Search' => array(
417 => 'Search - Categories',
418 => 'Search - Contacts',
419 => 'Search - Content',
420 => 'Search - News Feeds',
451 => 'Search - Tags',
),
'System' => array(
425 => 'System - Debug',
429 => 'System - SEF',
440 => 'System - Highlight',
452 => 'System - Joomla! Update Notification',
454 => 'System - Joomla! Statistics',
461 => 'System - Fields',
480 => 'System - Session Data Purge',
483 => 'System - User Actions Log',
486 => 'System - Log Rotation',
),
'User' => array(
432 => 'User - Joomla!',
),
);
$templates = array(
'Site' => array(
503 => 'Beez3',
506 => 'Protostar',
),
'Admin' => array(
504 => 'Hathor',
507 => 'Isis',
),
);
$notChecked = array(
// Modules - Admin
303, 305, 309, 310, 311, 314, 315,
// Plugins - Authentication
449,
// Plugins - Content
406, 435,
// Plugins - Editors
412,
// Plugins - Button
414, 416, 453,
// Plugins - System
425, 429, 480, 486,
// Plugins - User
432,
// Templates - Site
506,
// Templates - Admin
507,
);
$disable = array();
$error = false;
if (!empty($_POST['disable']))
{
try
{
$db = Factory::getDbo();
$disable = $_POST['disable'];
// Disable extensions
$query = $db->getQuery(true)
->select('*')
->update($db->quoteName('#__extensions'))
->set('enabled = 0')
->where($db->quoteName('extension_id') . ' IN (' . implode(',', $disable) . ')');
if (!$db->setQuery($query)->execute())
{
throw new Exception('Disable extensions error');
}
// Remove modules
$removeModules = array();
$modulesIds = array_keys($modules['Site']) + array_keys($modules['Admin']);
foreach ($disable as $value)
{
if (in_array($value, $modulesIds))
{
$removeModules[] = $value;
}
}
if ($removeModules)
{
$query = $db->getQuery(true)
->select('element')
->from($db->quoteName('#__extensions'))
->where($db->quoteName('extension_id') . ' IN (' . implode(',', $removeModules) . ')');
$modElements = $db->setQuery($query)->loadColumn();
foreach ($modElements as &$element)
{
$element = $db->quote($element);
}
if ($modElements)
{
$query = $db->getQuery(true)
->select('*')
->delete($db->quoteName('#__modules'))
->where($db->quoteName('module') . ' IN (' . implode(',', $modElements) . ')');
if (!$db->setQuery($query)->execute())
{
throw new Exception('Remove modules error');
}
}
}
}
catch (Exception $e)
{
$error = $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Joomla - Cleanup after install</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.1.4/css/uikit.min.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.1.4/js/uikit.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.1.4/js/uikit-icons.min.js"></script>
<script>
function massAction(element) {
let type = element.getAttribute('data-type');
document.querySelectorAll('[name="disable[]"]').forEach(function (checkbox) {
if (type === 'select') {
checkbox.setAttribute('checked', '');
} else if (type === 'unselect') {
checkbox.removeAttribute('checked');
}
});
}
</script>
</head>
<body>
<form class="uk-container uk-form uk-card uk-card-body uk-card-default uk-margin-top" method="post">
<div class="uk-flex uk-flex-middle uk-flex-between uk-margin-bottom">
<h1 class="uk-margin-remove">Joomla - Cleanup after install</h1>
<div>
<button type="submit" class="uk-button uk-button-primary">Cleanup</button>
</div>
</div>
<?php if ($error): ?>
<div class="uk-alert uk-alert-danger uk-margin">
<p><?php echo $error; ?></p>
</div>
<?php endif; ?>
<?php if ($disable && !$error): ?>
<div class="uk-alert uk-alert-success uk-margin">
<p><strong><?php echo count($disable); ?></strong> was disabled</p>
</div>
<?php endif; ?>
<div class="uk-alert uk-alert-warning uk-margin">
<p>Don't forget delete this file</p>
</div>
<div class="uk-alert uk-alert-primary uk-margin">
<p>Please select which extensions <span class="uk-text-danger">was disabled</span></p>
</div>
<div class="uk-text-right">
<a onclick="massAction(this);" data-type="select" class="uk-button uk-button-default uk-button-small">
Select All
</a>
<a onclick="massAction(this);" data-type="unselect" class="uk-button uk-button-default uk-button-small">
Unselect All
</a>
</div>
<h2 class="uk-margin-remove-top uk-margin-small-bottom">Components</h2>
<div class="uk-child-width-1-3@m uk-grid-small uk-margin-remove-vertical" uk-grid>
<div>
<?php foreach ($components as $extension_id => $title):
if (empty($disable) && !in_array($extension_id, $notChecked))
{
$checked = true;
}
elseif (!empty($disable) && in_array($extension_id, $disable))
{
$checked = true;
}
else
{
$checked = false;
}
?>
<div>
<label for="disable-<?php echo $extension_id; ?>">
<input id="disable-<?php echo $extension_id; ?>" class="uk-checkbox" type="checkbox"
name="disable[]" value="<?php echo $extension_id; ?>"
<?php echo ($checked) ? ' checked' : ''; ?>>
<?php echo $title; ?>
</label>
</div>
<?php endforeach; ?>
</div>
</div>
<hr>
<h2 class="uk-margin-remove-top uk-margin-small-bottom">Modules</h2>
<div class="uk-child-width-1-3@m uk-grid-small uk-margin-remove-vertical" uk-grid>
<?php foreach ($modules as $client => $extensions):
if (empty($disable) && !in_array($extension_id, $notChecked))
{
$checked = true;
}
elseif (!empty($disable) && in_array($extension_id, $disable))
{
$checked = true;
}
else
{
$checked = false;
}
?>
<div>
<h3 class="uk-margin-small-bottom"><?php echo $client; ?></h3>
<?php foreach ($extensions as $extension_id => $title):
if (empty($disable) && !in_array($extension_id, $notChecked))
{
$checked = true;
}
elseif (!empty($disable) && in_array($extension_id, $disable))
{
$checked = true;
}
else
{
$checked = false;
}
?>
<div>
<label for="disable-<?php echo $extension_id; ?>">
<input id="disable-<?php echo $extension_id; ?>" class="uk-checkbox" type="checkbox"
name="disable[]" value="<?php echo $extension_id; ?>"
<?php echo ($checked) ? ' checked' : ''; ?>>
<?php echo $title; ?>
</label>
</div>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
</div>
<hr>
<h2 class="uk-margin-remove-top uk-margin-small-bottom">Plugins</h2>
<div class="uk-child-width-1-3@m uk-grid-small uk-margin-remove-vertical" uk-grid>
<?php foreach ($plugins as $folder => $extensions) : ?>
<div>
<h3 class="uk-margin-small-bottom"><?php echo $folder; ?></h3>
<?php foreach ($extensions as $extension_id => $title):
if (empty($disable) && !in_array($extension_id, $notChecked))
{
$checked = true;
}
elseif (!empty($disable) && in_array($extension_id, $disable))
{
$checked = true;
}
else
{
$checked = false;
}
?>
<div>
<label for="disable-<?php echo $extension_id; ?>">
<input id="disable-<?php echo $extension_id; ?>" class="uk-checkbox" type="checkbox"
name="disable[]" value="<?php echo $extension_id; ?>"
<?php echo ($checked) ? ' checked' : ''; ?>>
<?php echo $title; ?>
</label>
</div>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
</div>
<hr>
<h2 class="uk-margin-remove-top uk-margin-small-bottom">Templates</h2>
<div class="uk-child-width-1-3@m uk-grid-small uk-margin-remove-vertical" uk-grid>
<?php foreach ($templates as $client => $extensions):
if (empty($disable) && !in_array($extension_id, $notChecked))
{
$checked = true;
}
elseif (!empty($disable) && in_array($extension_id, $disable))
{
$checked = true;
}
else
{
$checked = false;
}
?>
<div>
<h3 class="uk-margin-small-bottom"><?php echo $client; ?></h3>
<?php foreach ($extensions as $extension_id => $title):
if (empty($disable) && !in_array($extension_id, $notChecked))
{
$checked = true;
}
elseif (!empty($disable) && in_array($extension_id, $disable))
{
$checked = true;
}
else
{
$checked = false;
}
?>
<div>
<label for="disable-<?php echo $extension_id; ?>">
<input id="disable-<?php echo $extension_id; ?>" class="uk-checkbox" type="checkbox"
name="disable[]" value="<?php echo $extension_id; ?>"
<?php echo ($checked) ? ' checked' : ''; ?>>
<?php echo $title; ?>
</label>
</div>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
</div>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment