aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module/Pdledit.php
blob: e0bbc31d04e76df66e3ffcc8da7e5b207eb61e0a (plain) (blame)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
namespace Zotlabs\Module;

use App;
use Zotlabs\Web\Controller;
use Zotlabs\Lib\Apps;
use Zotlabs\Lib\Libsync;

class Pdledit extends Controller {

	function post() {
		if(! local_channel())
			return;

		if(! Apps::system_app_installed(local_channel(), 'PDL Editor'))
			return;

		if(! $_REQUEST['module'])
			return;

		if(! trim($_REQUEST['content'])) {
			del_pconfig(local_channel(),'system','mod_' . $_REQUEST['module'] . '.pdl');
			goaway(z_root() . '/pdledit');
		}
		set_pconfig(local_channel(),'system','mod_' . $_REQUEST['module'] . '.pdl',escape_tags($_REQUEST['content']));
		Libsync::build_sync_packet();
		info( t('Layout updated.') . EOL);
		goaway(z_root() . '/pdledit/' . $_REQUEST['module']);
	}


	function get() {

		if(! local_channel()) {
			notice( t('Permission denied.') . EOL);
			return;
		}

		if(! Apps::system_app_installed(local_channel(), 'PDL Editor')) {
			//Do not display any associated widgets at this point
			App::$pdl = '';
			$papp = Apps::get_papp('PDL Editor');
			return Apps::app_render($papp, 'module');
		}

		if(argc() > 2 && argv(2) === 'reset') {
			del_pconfig(local_channel(),'system','mod_' . argv(1) . '.pdl');
			goaway(z_root() . '/pdledit');
 		}

		if(argc() > 1)
			$module = 'mod_' . argv(1) . '.pdl';
		else {
			$o .= '<div class="generic-content-wrapper-styled">';
			$o .= '<h1>' . t('Edit System Page Description') . '</h1>';

			$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);
				}
			}

			$files = glob('Zotlabs/Module/*.php');
			if($files) {
				foreach($files as $f) {
					$name = lcfirst(basename($f,'.php'));
					$x = theme_include('mod_' . $name . '.pdl');
					if($x) {
						$o .= '<a href="pdledit/' . $name . '" >' . $name . '</a>' . ((in_array($name,$edited)) ? ' ' . t('(modified)') . ' <a href="pdledit/' . $name . '/reset" >' . t('Reset') . '</a>': '' ) . '<br />';
					}
				}
			}

			// addons
			$o .= '<h2>Addons</h2>';

			$addons = plugins_installed_list();

			foreach ($addons as $addon) {

				$path = 'addon/' . $addon . '/Mod_' . ucfirst($addon) . '.php';

				if (!file_exists($path))
					continue;

				$o .= '<a href="pdledit/' . $addon . '" >' . $addon . '</a>' . ((in_array($addon, $edited)) ? ' ' . t('(modified)') . ' <a href="pdledit/' . $addon . '/reset" >' . t('Reset') . '</a>': '' ) . '<br />';

			}


			$o .= '</div>';

			// list module pdl files
			return $o;
		}

		$t = get_pconfig(local_channel(),'system',$module);
		$s = '';

		if(!$t) {
			$sys_path = theme_include($module);

			if ($sys_path) {
				$s = file_get_contents($sys_path);
			}
			else {
				$addon_path = 'addon/' . argv(1) . '/' . $module;
				if (file_exists($addon_path)) {
					$s = file_get_contents($addon_path);
				}
			}

			$t = $s;
		}

		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'),
			'$another' => t('Edit another layout'),
			'$original' => t('System layout'),
			'$module' => argv(1),
			'$src' => $s,
			'$content' => htmlspecialchars($t,ENT_COMPAT,'UTF-8'),
			'$submit' => t('Submit')
		));

		return $o;
	}

}