You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
173 lines
6.6 KiB
173 lines
6.6 KiB
<?php
|
|
|
|
function includeFilesFromFolder($folder) {
|
|
// Проверяем, существует ли папка
|
|
if (is_dir($folder)) {
|
|
// Открываем директорию
|
|
$files = scandir($folder);
|
|
|
|
// Перебираем файлы в директории
|
|
foreach ($files as $file) {
|
|
// Пропускаем текущую и родительскую директории
|
|
if ($file !== '.' && $file !== '..') {
|
|
// Формируем полный путь к файлу
|
|
$filePath = $folder . DIRECTORY_SEPARATOR . $file;
|
|
|
|
// Проверяем, является ли это файлом и имеет ли нужное расширение (например, .php)
|
|
if (is_file($filePath) && pathinfo($filePath, PATHINFO_EXTENSION) === 'php') {
|
|
include_once $filePath; // Подключаем файл
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
throw new Exception("Директория не найдена: $folder");
|
|
}
|
|
}
|
|
|
|
// function enqueue_css($directory) {
|
|
// // Check if the directory exists
|
|
// if (!is_dir($directory)) {
|
|
// return; // Exit if the directory doesn't exist
|
|
// }
|
|
// // Get all CSS files in the specified directory
|
|
// $css_files = glob($directory . '/*.css');
|
|
// // Enqueue each CSS file
|
|
// foreach ($css_files as $css_file) {
|
|
// // Get the file name without the directory
|
|
// $file_name = basename($css_file);
|
|
// // Enqueue the CSS file
|
|
// wp_enqueue_style($file_name, get_template_directory_uri() . '/' . $directory . '/' . $file_name);
|
|
// }
|
|
// }
|
|
|
|
|
|
function include_module($module_name) {
|
|
// Убедитесь, что имя модуля не пустое
|
|
if (empty($module_name)) {
|
|
return;
|
|
}
|
|
|
|
// Получаем путь к каталогу модуля
|
|
$module_dir = get_template_directory() . '/modules/' . $module_name;
|
|
|
|
// Регистрируем стили и скрипты
|
|
add_action('wp_enqueue_scripts', function() use ($module_name, $module_dir) {
|
|
// Подключаем стили
|
|
$css_dir = $module_dir . '/assets/css';
|
|
if (is_dir($css_dir)) {
|
|
$css_files = scandir($css_dir);
|
|
foreach ($css_files as $css_file) {
|
|
if (pathinfo($css_file, PATHINFO_EXTENSION) === 'css' && $css_file !== '.' && $css_file !== '..') {
|
|
wp_enqueue_style(
|
|
$module_name . '-' . pathinfo($css_file, PATHINFO_FILENAME),
|
|
get_template_directory_uri() . '/modules/' . $module_name . '/assets/css/' . $css_file
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Подключаем скрипты
|
|
$js_dir = $module_dir . '/assets/js';
|
|
if (is_dir($js_dir)) {
|
|
$js_files = scandir($js_dir);
|
|
foreach ($js_files as $js_file) {
|
|
if (pathinfo($js_file, PATHINFO_EXTENSION) === 'js' && $js_file !== '.' && $js_file !== '..') {
|
|
wp_enqueue_script(
|
|
$module_name . '-' . pathinfo($js_file, PATHINFO_FILENAME),
|
|
get_template_directory_uri() . '/modules/' . $module_name . '/assets/js/' . $js_file,
|
|
array('jquery'),
|
|
null,
|
|
true
|
|
);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
// Подключаем контроллер модуля
|
|
$module_controller = $module_dir . '/module-controller.php';
|
|
if (file_exists($module_controller)) {
|
|
include $module_controller;
|
|
}
|
|
|
|
// Подключаем AJAX контроллер модуля
|
|
$module_ajax_controller = $module_dir . '/module-ajax-controller.php';
|
|
if (file_exists($module_ajax_controller)) {
|
|
include $module_ajax_controller;
|
|
}
|
|
}
|
|
|
|
function include_component($module_name, $component_name) {
|
|
// Убедитесь, что имя модуля и компонента не пустые
|
|
if (empty($module_name) || empty($component_name)) {
|
|
return;
|
|
}
|
|
|
|
// Получаем путь к каталогу модуля
|
|
$component_dir = get_template_directory() . '/modules/' . $module_name . '/components/' . $component_name;
|
|
|
|
// Регистрируем стили и скрипты
|
|
add_action('wp_enqueue_scripts', function() use ($module_name, $component_name, $component_dir) {
|
|
// Подключаем стили
|
|
$css_dir = $component_dir . '/assets/css';
|
|
if (is_dir($css_dir)) {
|
|
$css_files = scandir($css_dir);
|
|
|
|
foreach ($css_files as $css_file) {
|
|
if (pathinfo($css_file, PATHINFO_EXTENSION) === 'css' && $css_file !== '.' && $css_file !== '..') {
|
|
|
|
|
|
wp_enqueue_style($module_name . '-' . $component_name . '-' . pathinfo($css_file, PATHINFO_FILENAME), get_template_directory_uri() . '/modules/' . $module_name . '/components/' . $component_name . '/assets/css/' . $css_file);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Подключаем скрипты
|
|
$js_dir = $component_dir . '/assets/js';
|
|
if (is_dir($js_dir)) {
|
|
$js_files = scandir($js_dir);
|
|
foreach ($js_files as $js_file) {
|
|
|
|
if (pathinfo($js_file, PATHINFO_EXTENSION) === 'js' && $js_file !== '.' && $js_file !== '..') {
|
|
wp_enqueue_script($module_name . '-' . $component_name . '-' . pathinfo($js_file, PATHINFO_FILENAME), get_template_directory_uri() . '/modules/' . $module_name . '/components/' . $component_name . '/assets/js/' . $js_file, array('jquery'), null, true);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
$component_controller = $component_dir . '/component-controller.php';
|
|
if (file_exists($component_controller)) {
|
|
include $component_controller;
|
|
}
|
|
|
|
|
|
$component_ajax_controller = $component_dir . '/component-ajax-controller.php';
|
|
if (file_exists($component_ajax_controller)) {
|
|
include $component_ajax_controller;
|
|
}
|
|
}
|
|
|
|
require_once __DIR__ . '/vendor/autoload.php';
|
|
|
|
// Initialize Timber.
|
|
Timber\Timber::init();
|
|
|
|
Timber::$dirname = [
|
|
[
|
|
'modules',
|
|
],
|
|
];
|
|
|
|
includeFilesFromFolder(get_template_directory() . '/global-functions');
|
|
|
|
// Add the function to the Timber context
|
|
add_filter('timber/context', function($context) {
|
|
$context['template_path'] = get_template_directory_uri();
|
|
return $context;
|
|
});
|
|
|
|
|
|
|
|
include_module('layout'); |