streams/Zotlabs/Module/Pdledit.php

105 lines
2.5 KiB
PHP
Raw Normal View History

2016-04-19 03:38:38 +00:00
<?php
namespace Zotlabs\Module;
class Pdledit extends \Zotlabs\Web\Controller {
function post() {
if(! local_channel())
return;
if(! $_REQUEST['module'])
return;
if(! feature_enabled(local_channel(),'advanced_theming'))
return;
2016-04-19 03:38:38 +00:00
if(! trim($_REQUEST['content'])) {
del_pconfig(local_channel(),'system','mod_' . $_REQUEST['module'] . '.pdl');
2017-10-10 23:05:10 +00:00
goaway(z_root() . '/pdledit');
2016-04-19 03:38:38 +00:00
}
set_pconfig(local_channel(),'system','mod_' . $_REQUEST['module'] . '.pdl',escape_tags($_REQUEST['content']));
build_sync_packet();
info( t('Layout updated.') . EOL);
goaway(z_root() . '/pdledit/' . $_REQUEST['module']);
}
2016-06-24 09:07:12 +00:00
function get() {
2016-04-19 03:38:38 +00:00
if(! local_channel()) {
notice( t('Permission denied.') . EOL);
return;
}
if(! feature_enabled(local_channel(),'advanced_theming')) {
notice( t('Feature disabled.') . EOL);
return;
}
2017-10-10 23:05:10 +00:00
if(argc() > 2 && argv(2) === 'reset') {
del_pconfig(local_channel(),'system','mod_' . argv(1) . '.pdl');
goaway(z_root() . '/pdledit');
}
2016-04-19 03:38:38 +00:00
if(argc() > 1)
$module = 'mod_' . argv(1) . '.pdl';
else {
$o .= '<div class="generic-content-wrapper-styled">';
$o .= '<h1>' . t('Edit System Page Description') . '</h1>';
2017-10-10 23:05:10 +00:00
$edited = [];
$r = q("select k from pconfig where uid = %d and cat = 'system' and k like '%s' ",
intval(local_channel()),
dbesc('mod_%.pdl')
);
if($r) {
foreach($r as $rv) {
$edited[] = substr(str_replace('.pdl','',$rv['k']),4);
}
}
2016-06-24 09:07:12 +00:00
$files = glob('Zotlabs/Module/*.php');
2016-04-19 03:38:38 +00:00
if($files) {
foreach($files as $f) {
2016-06-24 09:07:12 +00:00
$name = lcfirst(basename($f,'.php'));
2016-04-19 03:38:38 +00:00
$x = theme_include('mod_' . $name . '.pdl');
if($x) {
2017-10-10 23:05:10 +00:00
$o .= '<a href="pdledit/' . $name . '" >' . $name . '</a>' . ((in_array($name,$edited)) ? ' ' . t('(modified)') . ' <a href="pdledit/' . $name . '/reset" >' . t('Reset') . '</a>': '' ) . '<br />';
2016-04-19 03:38:38 +00:00
}
}
}
2016-06-24 09:07:12 +00:00
$o .= '</div>';
2016-04-19 03:38:38 +00:00
// list module pdl files
return $o;
}
$t = get_pconfig(local_channel(),'system',$module);
$s = file_get_contents(theme_include($module));
if(! $t) {
$t = $s;
}
2016-04-19 03:38:38 +00:00
if(! $t) {
notice( t('Layout not found.') . EOL);
return '';
}
$o = replace_macros(get_markup_template('pdledit.tpl'),array(
'$header' => t('Edit System Page Description'),
'$mname' => t('Module Name:'),
'$help' => t('Layout Help'),
2017-10-10 23:05:10 +00:00
'$another' => t('Edit another layout'),
'$original' => t('System layout'),
2016-04-19 03:38:38 +00:00
'$module' => argv(1),
'$src' => $s,
2016-04-19 03:38:38 +00:00
'$content' => htmlspecialchars($t,ENT_COMPAT,'UTF-8'),
'$submit' => t('Submit')
));
return $o;
}
}