Commit 0c0afb0f authored by Tino Goratsch's avatar Tino Goratsch

Squashed 'installation/' content from commit f76a8a2

git-subtree-dir: installation
git-subtree-split: f76a8a2fc6f0e298ab647887617dc3281d40ed9b
parents
<?php
namespace ACP3\Installer;
use ACP3\Core;
use ACP3\Installer\Core\FrontController;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;
/**
* Class Application
* @package ACP3\Installer
*/
class Application
{
/**
* @var ContainerBuilder
*/
private $container;
/**
* run() method of the installer
*/
public function run()
{
$this->defineDirConstants();
if (defined('IN_UPDATER') && IN_UPDATER === true) {
$this->startupChecks();
}
$this->includeAutoLoader();
$this->initializeClasses();
$this->outputPage();
}
/**
* Define some path constants
*/
public function defineDirConstants()
{
define('PHP_SELF', htmlentities($_SERVER['SCRIPT_NAME']));
$phpSelf = dirname(PHP_SELF);
define('ROOT_DIR', substr($phpSelf !== '/' ? $phpSelf . '/' : '/', 0, -13));
define('INSTALLER_ROOT_DIR', substr(PHP_SELF, 0, strrpos(PHP_SELF, '/') + 1));
define('ACP3_DIR', ACP3_ROOT_DIR . 'ACP3/');
define('CLASSES_DIR', ACP3_DIR . 'Core/');
define('MODULES_DIR', ACP3_DIR . 'Modules/');
define('LIBRARIES_DIR', ACP3_ROOT_DIR . 'libraries/');
define('VENDOR_DIR', ACP3_ROOT_DIR . 'vendor/');
define('UPLOADS_DIR', ACP3_ROOT_DIR . 'uploads/');
define('CACHE_DIR', UPLOADS_DIR . 'cache/');
define('INSTALLER_ACP3_DIR', realpath(ACP3_DIR . '../installation/') . '/Installer/');
define('INSTALLER_MODULES_DIR', INSTALLER_ACP3_DIR . 'Modules/');
define('INSTALLER_CLASSES_DIR', INSTALLER_ACP3_DIR . 'Core/');
define('INSTALLATION_DIR', ACP3_ROOT_DIR . 'installation/');
// Set theme paths
define('DESIGN_PATH', INSTALLATION_DIR . 'design/');
define('DESIGN_PATH_INTERNAL', INSTALLATION_DIR . 'design/');
}
/**
* Include class autoloader
*/
public function includeAutoLoader()
{
require VENDOR_DIR . 'autoload.php';
}
/**
* Initializes the classes
*/
public function initializeClasses()
{
$this->container = new ContainerBuilder();
$loader = new YamlFileLoader($this->container, new FileLocator(__DIR__));
if (defined('IN_UPDATER') === true) {
$loader->load(INSTALLER_ACP3_DIR . 'config/update.yml');
$excludedDirs = ['.', '..'];
} else {
$loader->load(INSTALLER_ACP3_DIR . 'config/services.yml');
$excludedDirs = ['.', '..', 'Update'];
}
$loader->load(INSTALLER_CLASSES_DIR . 'View/Renderer/Smarty/services.yml');
// Load installer modules services
$installerModules = array_diff(scandir(INSTALLER_MODULES_DIR), $excludedDirs);
foreach ($installerModules as $module) {
$path = INSTALLER_MODULES_DIR . $module . '/config/services.yml';
if (is_file($path) === true) {
$loader->load($path);
}
}
// When in updater context, also include "normal" module services
if (defined('IN_UPDATER') === true) {
$moduleNamespaces = $this->container->get('core.modules')->getModuleNamespaces();
foreach ($moduleNamespaces as $namespace) {
$namespaceModules = array_diff(scandir(MODULES_DIR . $namespace . '/'), ['.', '..']);
foreach ($namespaceModules as $module) {
$path = MODULES_DIR . $namespace . '/' . $module . '/config/services.yml';
if (is_file($path) === true) {
$loader->load($path);
}
}
}
}
$this->container->get('core.view')->setRenderer('smarty', ['compile_id' => 'installer']);
$this->container->compile();
}
/**
* Outputs the requested page
*/
public function outputPage()
{
$request = $this->container->get('core.request');
$redirect = $this->container->get('core.redirect');
$frontController = new FrontController($this->container);
try {
$serviceId = $request->mod . '.controller.install.' . $request->controller;
$frontController->dispatch($serviceId, $request->file);
} catch (Core\Exceptions\ControllerActionNotFound $e) {
$redirect->temporary('errors/index/404');
} catch (\Exception $e) {
Core\Logger::critical('installer', $e->getMessage());
$redirect->temporary('errors/index/500');
}
}
/**
* Checks, whether the config.yml exists
*/
public function startupChecks()
{
// Standardzeitzone festlegen
date_default_timezone_set('UTC');
error_reporting(E_ALL);
if (defined('IN_UPDATER') === true) {
// DB-Config des ACP3 laden
$path = ACP3_DIR . 'config/config.yml';
if (is_file($path) === false || filesize($path) === 0) {
exit('The ACP3 is not correctly installed. Please navigate to the <a href="' . ROOT_DIR . 'installation/">installation wizard</a> and follow its instructions.');
}
}
}
/**
* @return ContainerBuilder
*/
public function getServiceContainer()
{
return $this->container;
}
}
<?php
namespace ACP3\Installer\Core;
/**
* Class Context
* @package ACP3\Core
*/
class Context
{
/**
* @var Lang
*/
protected $lang;
/**
* @var Request
*/
protected $request;
/**
* @var Router
*/
protected $router;
/**
* @var \ACP3\Core\View
*/
protected $view;
/**
* @param Lang $lang
* @param Request $request
* @param Router $router
* @param \ACP3\Core\View $view
*/
public function __construct(
Lang $lang,
Request $request,
Router $router,
\ACP3\Core\View $view)
{
$this->lang = $lang;
$this->request = $request;
$this->router = $router;
$this->view = $view;
}
/**
* @return Lang
*/
public function getLang()
{
return $this->lang;
}
/**
* @return Request
*/
public function getRequest()
{
return $this->request;
}
/**
* @return Router
*/
public function getRouter()
{
return $this->router;
}
/**
* @return \ACP3\Core\View
*/
public function getView()
{
return $this->view;
}
}
<?php
namespace ACP3\Installer\Core;
use ACP3\Core\Helpers\Forms;
/**
* Class Date
* @package ACP3\Installer\Core
*/
class Date extends \ACP3\Core\Date
{
/**
* @param Lang $lang
* @param Forms $formsHelper
* @param \ACP3\Core\Validator\Rules\Date $dateValidator
*/
public function __construct(
Lang $lang,
Forms $formsHelper,
\ACP3\Core\Validator\Rules\Date $dateValidator
) {
$this->lang = $lang;
$this->formsHelper = $formsHelper;
$this->dateValidator = $dateValidator;
$defaultTimeZone = date_default_timezone_get();
$settings = [
'date_format_long' => 'd.m.y, H:i',
'date_format_short' => 'd.m.y',
'time_zone' => !empty($defaultTimeZone) ? $defaultTimeZone : 'UTC',
];
$this->_setFormatAndTimeZone($settings);
}
}
<?php
namespace ACP3\Installer\Core;
use ACP3\Core\Exceptions;
use Symfony\Component\DependencyInjection\Container;
/**
* Class FrontController
* @package ACP3\Installer\Core
*/
class FrontController extends \ACP3\Core\FrontController
{
/**
* @var \Symfony\Component\DependencyInjection\Container
*/
protected $container;
/**
* @param \Symfony\Component\DependencyInjection\Container $container
*/
public function __construct(Container $container)
{
$this->container = $container;
}
/**
* @param string $serviceId
* @param string $action
* @param array $arguments
*
* @throws \ACP3\Core\Exceptions\ControllerActionNotFound
*/
public function dispatch($serviceId = '', $action = '', array $arguments = [])
{
$request = $this->container->get('core.request');
if (empty($serviceId)) {
$serviceId = $request->mod . '.controller.' . $request->area . '.' . $request->controller;
}
if ($this->container->has($serviceId)) {
/** @var Modules\Controller $controller */
$controller = $this->container->get($serviceId);
if (empty($action)) {
$action = $request->file;
}
$action = 'action' . str_replace('_', '', $action);
if (method_exists($controller, $action) === true) {
$controller->setContainer($this->container);
$controller->preDispatch();
$controller->$action();
$controller->display();
} else {
throw new Exceptions\ControllerActionNotFound('Controller action ' . get_class($controller) . '::' . $action . '() was not found!');
}
} else {
throw new Exceptions\ControllerActionNotFound('Service-Id ' . $serviceId . ' was not found!');
}
}
}
<?php
namespace ACP3\Installer\Core\Helpers;
use ACP3\Installer\Core;
/**
* Class Alerts
* @package ACP3\Installer\Core\Helpers
*/
class Alerts extends \ACP3\Core\Helpers\Alerts
{
/**
* Gibt eine Box mit den aufgetretenen Fehlern aus
*
* @param string|array $errors
*
* @return string
*/
public function errorBox($errors)
{
$hasNonIntegerKeys = false;
if (is_string($errors) && ($data = @unserialize($errors)) !== false) {
$errors = $data;
}
if (is_array($errors) === true) {
foreach (array_keys($errors) as $key) {
if (is_numeric($key) === false) {
$hasNonIntegerKeys = true;
break;
}
}
} else {
$errors = (array)$errors;
}
$this->view->assign('error_box', ['non_integer_keys' => $hasNonIntegerKeys, 'errors' => $errors]);
$content = $this->view->fetchTemplate('error_box.tpl');
if ($this->request->getIsAjax() === true) {
$return = [
'success' => false,
'content' => $content,
];
$this->outputHelper->outputJson($return);
}
return $content;
}
}
<?php
namespace ACP3\Installer\Core;
/**
* Class Lang
* @package ACP3\Installer\Core
*/
class Lang extends \ACP3\Core\Lang
{
/**
* @param \ACP3\Core\Auth $lang
*/
public function __construct($lang)
{
$this->lang = $lang;
$this->lang2Characters = substr($this->lang, 0, strpos($this->lang, '_'));
}
/**
* Überprüft, ob das angegebene Sprachpaket existiert
*
* @param string $lang
*
* @return boolean
*/
public static function languagePackExists($lang)
{
return !preg_match('=/=', $lang) && is_file(INSTALLER_MODULES_DIR . 'Install/Languages/' . $lang . '.xml') === true;
}
/**
* Gibt den angeforderten Sprachstring aus
*
* @param string $module
* @param string $key
*
* @return string
*/
public function t($module, $key)
{
if (empty($this->buffer)) {
$this->buffer = $this->getLanguageCache();
}
return isset($this->buffer['keys'][$module][$key]) ? $this->buffer['keys'][$module][$key] : strtoupper('{' . $module . '_' . $key . '}');
}
/**
* Gibt die gecacheten Sprachstrings aus
*
* @return array
*/
protected function getLanguageCache()
{
if (empty($this->buffer) === true) {
$this->buffer = $this->setLanguageCache();
}
return $this->buffer;
}
/**
* Cacht die Sprachfiles, um diese schneller verarbeiten zu können
*/
public function setLanguageCache()
{
$data = [];
$modules = array_diff(scandir(INSTALLER_MODULES_DIR), ['.', '..']);
foreach ($modules as $module) {
$path = INSTALLER_MODULES_DIR . $module . '/Languages/' . $this->lang . '.xml';
if (is_file($path) === true) {
$xml = simplexml_load_file($path);
if (isset($data['info']['direction']) === false) {
$data['info']['direction'] = (string)$xml->info->direction;
}
// Über die einzelnen Sprachstrings iterieren
foreach ($xml->keys->item as $item) {
$data['keys'][strtolower($module)][(string)$item['key']] = trim((string)$item);
}
}
}
return $data;
}
}
<?php
namespace ACP3\Installer\Core\Modules;
use ACP3\Core\Redirect;
use ACP3\Core\XML;
use ACP3\Installer\Core\Context;
use Symfony\Component\DependencyInjection\Container;
/**
* Module Controller of the installer modules
* @package ACP3\Installer\Core\Modules
*/
class Controller
{
/**
* @var Container
*/
protected $container;
/**
* @var \ACP3\Installer\Core\Lang
*/
protected $lang;
/**
* @var \ACP3\Installer\Core\Request
*/
protected $request;
/**
* @var \ACP3\Installer\Core\Router
*/
protected $router;
/**
* @var \ACP3\Core\View
*/
protected $view;
/**
* Nicht ausgeben
*/
protected $noOutput = false;
/**
* Der auszugebende Content-Type der Seite
*
* @var string
*/
protected $contentType = 'Content-Type: text/html; charset=UTF-8';
/**
* Das zuverwendende Template
*
* @var string
*/
protected $template = '';
/**
* Der auszugebende Seiteninhalt
*
* @var string
*/
protected $content = '';
/**
* @var string
*/
protected $contentAppend = '';
public function __construct(Context $context)
{
$this->lang = $context->getLang();
$this->request = $context->getRequest();
$this->router = $context->getRouter();
$this->view = $context->getView();
}
public function preDispatch()
{
if (!empty($_POST['lang'])) {
setcookie('ACP3_INSTALLER_LANG', $_POST['lang'], time() + 3600, '/');
$this->redirect()->temporary($this->request->mod . '/' . $this->request->controller . '/' . $this->request->file);
}
if (defined('LANG') === false) {
if (!empty($_COOKIE['ACP3_INSTALLER_LANG']) && !preg_match('=/=', $_COOKIE['ACP3_INSTALLER_LANG']) &&
is_file(INSTALLER_MODULES_DIR . 'Install/Languages/' . $_COOKIE['ACP3_INSTALLER_LANG'] . '.xml') === true
) {
define('LANG', $_COOKIE['ACP3_INSTALLER_LANG']);
} else {
define('LANG', \ACP3\Core\Lang::parseAcceptLanguage());
}
}
$this->lang->setLanguage(LANG);
// Einige Template Variablen setzen
$this->view->assign('LANGUAGES', $this->_languagesDropdown(LANG));
$this->view->assign('PHP_SELF', PHP_SELF);
$this->view->assign('REQUEST_URI', htmlentities($_SERVER['REQUEST_URI']));
$this->view->assign('ROOT_DIR', ROOT_DIR);
$this->view->assign('INSTALLER_ROOT_DIR', INSTALLER_ROOT_DIR);
$this->view->assign('DESIGN_PATH', DESIGN_PATH);
$this->view->assign('UA_IS_MOBILE', $this->request->isMobileBrowser());
$languageInfo = simplexml_load_file(INSTALLER_MODULES_DIR . 'Install/Languages/' . $this->lang->getLanguage() . '.xml');
$this->view->assign('LANG_DIRECTION', isset($languageInfo->info->direction) ? $languageInfo->info->direction : 'ltr');
$this->view->assign('LANG', $this->lang->getLanguage2Characters());
}
/**
* @return Redirect
*/
public function redirect()
{
return $this->get('core.redirect');
}
/**
* Gets a class from the service container
*
* @param $serviceId
*
* @return mixed
*/
public function get($serviceId)
{
return $this->container->get($serviceId);
}
/**
* Generiert das Dropdown-Menü mit der zur Verfügung stehenden Installersprachen
*
* @param string $selectedLanguage
*
* @return array
*/
private function _languagesDropdown($selectedLanguage)
{
// Dropdown-Menü für die Sprachen
$languages = [];
$path = INSTALLER_MODULES_DIR . 'Install/Languages/';
$files = array_diff(scandir($path), ['.', '..']);
foreach ($files as $row) {
$langInfo = simplexml_load_file($path . $row);
if (!empty($langInfo)) {
$languages[] = [
'language' => substr($row, 0, -4),
'selected' => $selectedLanguage === substr($row, 0, -4) ? ' selected="selected"' : '',
'name' => $langInfo->info->name
];
}
}
return $languages;
}
/**
* @param $container
*
* @return $this
*/
public function setContainer($container)
{
$this->container = $container;
return $this;
}
/**
* Fügt weitere Daten an den Seiteninhalt an
*
* @param string $data
*
* @return $this
*/
public function appendContent($data)
{
$this->contentAppend .= $data;
return $this;
}
public function display()
{
if ($this->getNoOutput() === false) {
// Evtl. gesetzten Content-Type des Servers überschreiben
header($this->getContentType());
if ($this->getContent() == '') {
// Template automatisch setzen
if ($this->getTemplate() === '') {
$this->setTemplate($this->request->mod . '/' . $this->request->controller . '.' . $this->request->file . '.tpl');
}
$this->view->assign('PAGE_TITLE', $this->lang->t('install', 'acp3_installation'));
$this->view->assign('TITLE', $this->lang->t($this->request->mod, $this->request->controller . '_' . $this->request->file));
$this->view->assign('CONTENT', $this->getContentAppend());
$this->view->assign('IS_AJAX', $this->request->getIsAjax());
$this->view->displayTemplate($this->getTemplate());
} else {
echo $this->getContent();
}
}
}
/**
* Gibt das aktuell zugewiesene Template zurück
*
* @return string
*/
public function getTemplate()
{
return $this->template;
}
/**
* Setzt das Template der Seite
*
* @param string $template
*
* @return $this
*/
public function setTemplate($template)
{
$this->template = $template;
return $this;
}
/**
* Gibt zurück, ob die Seitenausgabe mit Hilfe der Bootstraping-Klasse
* erfolgen soll oder die Datei dies selber handelt