Manfre / xpattern (http://xpattern.net)

xPattern CMS

Clone this repository (size: 1.9 MB): HTTPS / SSH
$ hg clone http://bitbucket.org/Manfre/xpattern/
commit 1357: 1d46d1383789
parent 1356: 2ca3c82199a2
branch: default
Corrected Javascript page. Works&Saves as it should. Implemented default JS page.
Eric
6 months ago

Changed (Δ756 bytes):

raw changeset »

textpattern/include/txp_javascript.php (84 lines added, 80 lines removed)

textpattern/lang/en-gb.txt (5 lines added, 7 lines removed)

textpattern/setup/txpsql.php (1 lines added, 1 lines removed)

textpattern/styles/cp/reno.css (3 lines added, 3 lines removed)

Up to file-list textpattern/include/txp_javascript.php:

10
10
	if ($event == 'javascript') {
11
11
		require_privs('javascript');
12
12
13
		if ($step == '')
14
			$step = 'create';
15
16
13
		switch ($step) {
17
			case 'create': javascript_edit();	            break;
18
			case 'save': javascript_save();               break;
19
			case 'copy': javascript_copy();               break;
20
			case 'save_as': javascript_save_as();         break;
21
			case 'delete': javascript_delete();           break;
22
			case 'edit': javascript_edit();               break;
14
			case '': javascript_edit(); break;
15
			case 'pour': javascript_edit();	               break;
16
			case 'javascript_save': javascript_save();               break;
17
			case 'javascript_copy': javascript_copy();               break;
18
			case 'javascript_save_as': javascript_save_as();         break;
19
//			case 'javascript_delete': javascript_delete();           break;
20
			case 'javascript_edit': javascript_edit();               break;
23
21
		}
24
22
	}
25
23
26
24
//-------------------------------------------------------------
27
25
28
26
	function javascript_list($current, $default) {
29
		$out[] = startTable('list', 'left');
30
27
31
28
		$rs = safe_rows_start('theme, name', 'blurb', "type='javascript' order by theme, name");
32
29
36
33
			while ($a = nextRow($rs)) {
37
34
				if ($theme != $a['theme'])
38
35
				{
39
					$out[] = tr('<td colspan="2">'.htmlspecialchars($theme).'</td>');
36
					$out[] = htmlspecialchars($theme);
40
37
				}
41
38
				extract($a);
42
			
43
				$edit = ($current != $name) ?	eLink('javascript', 'edit', 'name', $name, $name, 'theme', $theme) : $name;
44
				$delete = ($name != $default) ? dLink('javascript', 'delete', 'name', $name, '', 'theme', $theme) : '';
45
39
46
				$out[] = tr(td($edit).td($delete));
40
				$delete = ($name != $default) ? finput('checkbox','javascript_delete[]',$name) : '';
41
42
				$edit = ($current != $name) ?	eLink('javascript', '', 'name', $name, $name, 'theme', $theme) : $name;
43
44
				$out[] = t3.tag(
45
							'<span class="action">'.$delete.'</span>'.
46
							'<span class="item">'.$edit.'</span>'
47
							,'li');
47
48
			}
48
49
49
			$out[] =  endTable();
50
51
			return join('', $out);
50
			return t2.tag(join('', $out).t2,'ul','class="item-list"').n.t;
52
51
		}
53
52
	}
54
53
55
54
//-------------------------------------------------------------
56
55
57
56
	function javascript_edit($message='') {
58
		pagetop(gTxt("edit_javascript"),$message);
57
59
58
		global $step,$prefs;
60
61
		$name = gps('name');
62
		$theme = gps('theme');
63
59
		
64
		if ($step == 'delete')
65
		{
66
			$step = 'create';
67
			$name = '';
68
			$theme = 'default';
69
		}
70
		else if (!$name)
71
		{
72
			$name = gps('newname');
73
			$theme = gps('newtheme');
60
		$name		= gps('name');
61
		$theme 		= gps('theme');
62
		$editArray	= gps('javascript_delete');
63
		// go button
64
		$action		= gps('javascript_multi_edit');
65
		// select field
66
		$selected 	= gps('edit_method');
67
		
68
		$theme = empty($theme) ? 'default' : $theme;
69
		
70
		if(strlen($action) > 0 && $selected == 'delete') {
71
			$message = javascript_delete($editArray,$theme);
72
			$name = (!in_array($name,$editArray)) ? $name : '';
74
73
		}
75
74
		
76
		$theme = empty($theme) ? 'default' : $theme;
75
		$name = (!$name or $step == 'javascript_delete') ? 'default' : $name;
77
76
78
77
		if (gps('copy') && trim(preg_replace('/[<>&"\']/', '', gps('newname'))) )
79
78
			$name = gps('newname');
80
79
81
		if ($step=='create')
80
		if ($step=='pour')
82
81
		{
83
82
			$buttons =
84
			gTxt('name_for_this_script').': '
83
			gTxt('name_for_this_style').': '
85
84
			.fInput('text','newname','','edit','','',20).
86
85
			hInput('savenew','savenew');
87
			$thejs = '';
86
			$thejavascript = '';
88
87
89
88
		} else {
90
89
			$buttons = '';
91
90
			$blurb = get_blurb($name, 'javascript', $theme);
92
			$thejs = !empty($blurb) ? $blurb['content'] : '';
91
			$thejavascript = !empty($blurb) ? $blurb['content'] : '';
93
92
		}
94
93
95
		if ($step!='create') {
94
		if ($step!='pour') {
96
95
			
97
			$left = graf(gTxt('you_are_editing').br.strong($name)).
98
				graf(sLink('javascript', 'create', gTxt('create_new')));
99
96
			$right = graf(sLink('javascript', 'pour', gTxt('bulkload_existing_js')));
100
97
			
101
			$copy = gTxt('copy_as').sp.fInput('text', 'newname', '', 'edit').sp.
98
			$copy = gTxt('copy_js_as').sp.fInput('text', 'newname', '', 'edit').sp.
102
99
				fInput('submit', 'copy', gTxt('copy'), 'smallerbox');
103
100
		} else {
104
			$left = ' ';
101
			$right = ' ';
105
102
			$copy = '';
106
103
		}
107
104
108
		$right = hed(gTxt('all_javascript'),2).
109
			javascript_list($name, '');
105
		$right .=	hed(gTxt('all_javascript'),2).
106
					javascript_list($name, 'default');
107
			
108
		$multiedit = selectInput('edit_method', array('delete'=>gTxt('delete')), '', 1) . 
109
					 gTxt('selected') .
110
					 t3.fInput('submit', 'javascript_multi_edit', gTxt('go'));
111
			
112
		echo pagetop(gTxt("edit_javascript"),$message).
113
			 n.t.'<div id="content" class="clearfix">'.n.
114
			   t.'<h1>'.gTxt('tab_javascript').'</h1>'.n;
110
115
111
		echo div(
112
			div($left, '', 'left').
113
			div(
114
				form(
115
					graf($buttons).
116
					'<textarea id="content" class="code" name="content" rows="32">'.htmlspecialchars($thejs).'</textarea>'.br.
117
					fInput('submit','',gTxt('save'),'publish').
118
					eInput('javascript').sInput('save').
119
					hInput('name',$name)
116
		echo
117
			form(
118
				div(	   
119
					t4.graf($buttons).
120
					graf(gTxt('you_are_editing_js').sp.strong($name)).
121
					'<textarea id="javascript" class="code" name="javascript">'.htmlspecialchars($thejavascript).'</textarea>'.br.
122
					t4.hInput('name',$name)
120
123
					.$copy
121
				), '', 'center').
122
			div($right, '','right'), 
123
124
			'', 'container'	);
124
				,'','col-1').
125
				div(
126
					n.t.div(fInput('submit','save',gTxt('save'),"publish", '', '', '', 4,'publish-button'),'','publish').
127
					t4.eInput('javascript').t4.sInput('javascript_save').
128
					div(
129
						$right.
130
						$multiedit,
131
						'list'
132
						)
133
				,'','col-2')
134
			).
135
			 '</div>';
125
136
	}
126
137
127
138
// -------------------------------------------------------------
138
149
			$newname = sanitizeForUrl($newname);
139
150
	
140
151
			set_blurb($newname, 'javascript', $newtheme, $blurb['content'], $blurb['mime_type']);
141
			
152
	
142
153
			javascript_edit(
143
154
				gTxt('javascript_created', array('{name}' => $newname))
144
155
			);
156
167
157
168
	function javascript_save()
158
169
	{
159
		extract(gpsa(array('name','theme','content','savenew','newname','copy')));
170
		extract(gpsa(array('name','theme','javascript','savenew','newname','copy')));
160
171
161
172
		if ($savenew or $copy)
162
173
		{
171
182
172
183
			elseif ($newname)
173
184
			{
174
				set_blurb($newname, 'javascript', $theme, $content, 'text/javascript');
175
				
185
				set_blurb($newname, 'javascript', $theme, $javascript, 'text/javascript');
186
176
187
				// update site last mod time
177
188
				update_lastmod();
178
189
191
202
		{
192
203
			$name = sanitizeForUrl($name);
193
204
194
			set_blurb($name, 'javascript', $theme, $content, 'text/javascript');
195
			
205
			set_blurb($name, 'javascript', $theme, $javascript, 'text/javascript');
206
196
207
			// update site last mod time
197
208
			update_lastmod();
198
209
204
215
205
216
//-------------------------------------------------------------
206
217
207
	function javascript_delete()
218
	function javascript_delete($editArray,$theme)
208
219
	{
209
		$name  = ps('name');
210
		$theme = ps('theme');
211
220
212
		$count = safe_count('txp_section', "css = '".doSlash($name)."'");
221
		foreach($editArray as $name) {
222
			
223
			delete_blurb($name, 'javascript', $theme);				
224
	
225
			$message[] = $name;
213
226
214
		if ($count)
215
		{
216
			$message = gTxt('javascript_used_by_section', array('{name}' => $name, '{count}' => $count));
217
227
		}
218
219
		else
220
		{
221
			delete_blurb($name, 'javascript', $theme);
222
			
223
			$message = gTxt('javascript_deleted', array('{name}' => $name));
224
		}
225
226
		javascript_edit($message);
228
		
229
		$name = join(' and ', $message);
230
		return gTxt('javascript_deleted', array('{name}' => $name));
227
231
	}
228
232
229
233
?>

Up to file-list textpattern/lang/en-gb.txt:

@@ -273,8 +273,7 @@ cannot_delete_default_css => Style <stro
273
273
deleted.
274
274
copy_css_as => …or copy style as
275
275
copy_js_as =>  …or copy javascript as
276
create_new_css => Create new 
277
style
276
create_new_css => Create new style
278
277
css_already_exists => Stylesheet <strong>{name}</strong> already 
279
278
exists.
280
279
css_created => Style <strong>{name}</strong> created.
@@ -598,11 +597,10 @@ txp_import => Import content from other
598
597
publishing tools
599
598
#@javascript
600
599
all_javascript => All Scripts
601
copy_as => copy 
602
as
603
name_for_this_script => Name for this script:
604
you_are_editing => You are 
605
editing
600
copy_as => copy as
601
name_for_this_script => Name for this script :
602
you_are_editing_js => You are editing script :
603
bulkload_existing_js => Create or load 
606
604
#@link
607
605
edit_links => Links
608
606
linkcategory => Link Categories

Up to file-list textpattern/setup/txpsql.php:

@@ -150,7 +150,7 @@ UNIQUE `hash` ( `name` , `type` , `theme
150
150
151
151
152
152
$create_sql[] = "INSERT INTO `".PFX."blurb` (`name`, `type`, `mime_type`, `content`) VALUES ('default', 'css', 'text/css', '".doSlash(base64_decode('LyogYmFzZQ0KLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gKi8NCg0KYm9keSB7DQoJbWFyZ2luOiAwOw0KCXBhZGRpbmc6IDA7DQoJZm9udC1mYW1pbHk6IFZlcmRhbmEsICJMdWNpZGEgR3JhbmRlIiwgVGFob21hLCBIZWx2ZXRpY2EsIHNhbnMtc2VyaWY7DQoJY29sb3I6ICMwMDA7DQoJYmFja2dyb3VuZC1jb2xvcjogI2ZmZjsNCn0NCg0KYmxvY2txdW90ZSwgaDMsIHAsIGxpIHsNCglwYWRkaW5nLXJpZ2h0OiAxMHB4Ow0KCXBhZGRpbmctbGVmdDogM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Rob3Igew0KCWZvbnQtc3R5bGU6IG5vcm1hbDsNCglmb250LXNpemU6IDAuOGVtOw0KfQ0KDQoucHVibGlzaGVkIHsNCglmb250LXNpemU6IDAuOGVtOw0KfQ0KDQovKiBjb21tZW50cw0KLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gKi8NCg0KLmNvbW1lbnRzX2Vycm9yIHsNCgljb2xvcjogIzAwMDsNCgliYWNrZ3JvdW5kLWNvbG9yOiAjZmZmNGY0Ow0KfQ0KDQp1bC5jb21tZW50c19lcnJvciB7DQoJcGFkZGluZyA6IDAuM2VtOw0KCWxpc3Qtc3R5bGUtdHlwZTogY2lyY2xlOw0KCWxpc3Qtc3R5bGUtcG9zaXRpb246IGluc2lkZTsNCglib3JkZXI6IDJweCBzb2xpZCAjZmRkOw0KfQ0KDQpkaXYjY3ByZXZpZXcgew0KCWNvbG9yOiAjMDAwOw0KCWJhY2tncm91bmQtY29sb3I6ICNmMWYxZjE7DQoJYm9yZGVyOiAycHggc29saWQgI2RkZDsNCn0NCg0KZm9ybSN0eHBDb21tZW50SW5wdXRGb3JtIHRkIHsNCgl2ZXJ0aWNhbC1hbGlnbjogdG9wOw0KfQ0KDQojY29tbWVudHMtaGVscCB7DQoJbWFyZ2luOiAycHggMCAxNXB4IDA7DQoJZm9udC1zaXplOiAwLjdlbTsNCn0NCg0KLyogZXJyb3IgcGFnZQ0KLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0gKi8NCg0KLmVycm9yLXN0YXR1cyB7DQoJZm9udDogMS4zZW0gR2VvcmdpYSwgVGltZXMsIHNlcmlmOw0KfQ=='))."')";
153
153
$create_sql[] = "INSERT INTO `".PFX."blurb` (`name`, `type`, `mime_type`, `content`) VALUES ('default', 'css', 'text/css', ' ')";
154
154
$create_sql[] = "INSERT INTO `".PFX."blurb` (`name`, `type`, `content`) VALUES ('links', 'form', '<p><txp:link /><br />\n<txp:link_description /></p>')";
155
155
$create_sql[] = "INSERT INTO `".PFX."blurb` (`name`, `type`, `content`) VALUES ('lofi', 'form', '<h3 class=\"entry-title\"><txp:title /> <txp:permlink>#</txp:permlink></h3>\n\n<p class=\"published\"><txp:posted /></p>\n\n<div class=\"entry-content\">\n<txp:body />\n</div>\n\n<hr />\n\n')";
156
156
$create_sql[] = "INSERT INTO `".PFX."blurb` (`name`, `type`, `content`) VALUES ('single', 'form', '<h3 class=\"entry-title\"><txp:permlink><txp:title /></txp:permlink></h3>\n\t<p class=\"published\"><txp:posted /></p>\n\n<div class=\"entry-content\">\n<txp:body />\n</div>\n\n')";

Up to file-list textpattern/styles/cp/reno.css:

@@ -375,7 +375,7 @@ input#time, input#expiry-time {
375
375
	width: 55px;
376
376
}
377
377
378
textarea#body, textarea#html, textarea#css, textarea#js-code {
378
textarea#body, textarea#html, textarea#css, textarea#javascript {
379
379
	font-size: 12px;
380
380
	padding: 5px;
381
381
	width: 99%;
@@ -526,10 +526,10 @@ p.pref {
526
526
	text-align: 0 auto;
527
527
	}
528
528
	
529
/* CSS 
529
/* CSS && Javascript
530
530
---------------------------------------------- */
531
531
532
.css-list LI, .css-list UL
532
.item-list LI, .item-list UL
533
533
	{
534
534
	list-style: none;
535
535
	clear: both;