'core/language/'.LANG.'/', ); foreach (modules() as $module) $lang_folders[$module] = 'modules/'.$module.'/language/'.LANG.'/'; return $lang_folders; } function lang_files($lang_folders=null) { if ($lang_folders === null) $lang_folders = lang_folders(); $lang_files = array(); foreach ($lang_folders as $module=>$lang_folder) { if (file_exists($lang_folder)) { $lang_files[$module] = array( 'folder' => $lang_folder, 'files' => array(), ); foreach (array_diff(scandir($lang_folder), array('..', '.')) as $lang_file) { if (!is_file($lang_folder.$lang_file) || substr($lang_file, -4) !== '.php') continue; $lang_files[$module]['files'][] = $lang_file; } } } return $lang_files; } function lang_strings($lang_files=null) { if ($lang_files === null) $lang_files = lang_files(); $LANG = array(); foreach ($lang_files as $module=>$lang_folder) { foreach ($lang_folder['files'] as $lang_file) { $lang = include_once($lang_folder['folder'].$lang_file); if (is_array($lang)) { if (!isset($LANG[$module])) $LANG[$module] = $lang; else $LANG[$module] = array_merge($LANG[$module], $lang); } } } return $LANG; } function lang_js_cache() { $js_lang_file = 'core/assets/js/lang/'.LANG.'.js'; $js_lang_file_time = null; $cache = true; if (file_exists($js_lang_file)) { $js_lang_file_time = filemtime($js_lang_file); $cache = false; } if (!$cache) { foreach (lang_files() as $module=>$lang_folder) { foreach ($lang_folder['files'] as $lang_file) { if (filemtime($lang_folder['folder'].$lang_file) > $js_lang_file_time) { $cache = true; break 2; } } } } if ($cache) { $dir = explode('/', $js_lang_file); $dir = implode('/', array_slice($dir, 0, count($dir)-1)); if (!file_exists($dir)) mkdir($dir, 0755, true); file_put_contents($js_lang_file, 'LANG='.json_encode(lang_strings())); } return $js_lang_file; } function e($var) { if (is_object($var) || is_array($var)) $var = json_encode($var); elseif (!is_int($var) && is_float($var)) $var = number_format($var, 2); return htmlspecialchars($var); } function modules() { $modules = array(); foreach (array_diff(scandir('modules/'), array('..', '.')) as $module_folder) { $module_name = explode('.', $module_folder, 2); $module_name = $module_name[count($module_name) == 2 ? 1 : 0]; $modules[$module_name] = $module_folder; } return $modules; } function __autoload($class_name) { $filename = 'core/classes/'.$class_name.'.php'; if (file_exists($filename)) require_once $filename; foreach(modules() as $module) { $filename = 'modules/'.$module.'/classes/'.$class_name.'.php'; if (file_exists($filename)) require_once $filename; } } // handle ajax request if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { require_once 'core/ajax.php'; Ajax::load()->output(); } function indices($module_folder) { $indices = array(); $module_folder = 'modules/'.$module_folder.'/'; if (file_exists($module_folder)) { foreach (array_diff(scandir($module_folder), array('..', '.')) as $index_file) { if (substr($index_file, -4) !== '.php') continue; $index_name = str_replace('.php', '', $index_file); $index_name = explode('.', $index_name, 2); $index_name = $index_name[count($index_name) == 2 ? 1 : 0]; $indices[ucfirst($index_name)] = $index_file; } } return $indices; } foreach(modules() as $module_name=>$module_folder) { foreach(indices($module_folder) as $index_class=>$index_file) { require_once 'modules/'.$module_folder.'/'.$index_file; if ($index_class::should_load()) { define('MODULE', $module_name); define('INDEX', $index_class); $index_class::load()->output(); exit; } } } Index::load()->output(); ?>