-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgenerate_template.php
52 lines (44 loc) · 2.07 KB
/
generate_template.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace RedcapConHack\Templater;
/** @var Templater $module */
require_once(__DIR__ . "/vendor/autoload.php");
$loader = new \Twig_Loader_Filesystem(__DIR__ . "/templates/");
$twig = new \Twig_Environment($loader);
$twig->addExtension(new \Twig\Extension\StringLoaderExtension());
if ($_POST) {
$user_cache=[];
foreach ($_POST as $k => $v) {
if ($k == "orgName" || $k == "gitOrg" || left($k,7) == "include" || left($k,7) == "authors") $user_cache[$k] = $v;
}
file_put_contents('/var/log/redcap/dump.json', json_encode($user_cache));
$module->setUserSetting('defaults', $user_cache);
$module->generateTemplateFromPost($twig);
} else {
?>
<script>
var timezone = "<?php echo date_default_timezone_get(); ?>";
var timestamp = "<?php echo date("Y-m-d H:i:s"); ?>";
</script>
<?php
$templateConstants = [
"icon_url" => APP_PATH_WEBROOT . "Resources/images/favicon.ico",
"js_link" => APP_PATH_JS . "base.js",
"js_link2" => $module->getUrl('js/functions.js'),
"css_link" => APP_PATH_CSS . "jquery-ui-min.css",
"css_link2" => APP_PATH_CSS . "bootstrap.min.css",
"hooks" => $module::getHookInfo(),
"default_module_version" => $module::DEFAULT_MODULE_VERSION,
"default_framework_version" => \ExternalModules\ExternalModules::getMaxSupportedFrameworkVersion(), // $module::DEFAULT_FRAMEWORK_VERSION,
"framework_doc_url" => APP_PATH_WEBROOT . "Plugins/index.php?page=ext_mods_docs/framework/intro.md",
"user_cache" => json_encode($module->getUserSetting('defaults'))
];
## Checking if on newer version of REDCap that uses webpack for jquery and bootstrap
if (!is_file(APP_PATH_DOCROOT . "Resources/css/jquery-ui.min.css")) {
$templateConstants["js_link"] = APP_PATH_WEBPACK . "js/bundle.js";
$templateConstants["css_link"] = APP_PATH_WEBPACK . "css/bundle.css";
$templateConstants["css_link2"] = false;
}
echo $twig->render("newModule.twig", $templateConstants);
}
// Prevent js errors about missing variables
renderJsVars();