JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
/admin_pages: listing sorts, missing image doesn't bork ckeditor
[wfpl-cms.git] / admin_pages.html
1 <!DOCTYPE html>
2
3 <html>
4 <head>
5         <title><!--~$title show {~-->~$host~ Admin: <!--~listing {~-->Manage Pages<!--~}~--><!--~form {~--><!--~id unset {~-->Add a new page<!--~}~--><!--~id {~-->Edit page "~title html~"<!--~}~--><!--~}~--><!--~}~--></title>
6         <!--~$head {~-->
7         <script src="inc/ckeditor/ckeditor.js?t=F0RD"></script>
8         <style>
9                 /* icon in cke buttons */
10                 .cke_button_icon.cke_button__wfpl_images_icon {
11                         background-image: url(/inc/ckeditor/plugins/icons.png?t=F0RD);
12                         background-position: 0 -936px;
13                 }
14                 .cke_wfpl_images_dialog * {
15                         white-space: normal !important;
16                 }
17                 .cke_wfpl_images_dialog h3 {
18                         margin-top: 10px;
19                         font-weight: bold;
20                         font-size: 18px;
21                 }
22                 .cke_wfpl_images_dialog strong {
23                         color: inherit;
24                 }
25                 .cke_wfpl_images_dialog p {
26                         font-size: 12px;
27                         line-height: 16px;
28                 }
29                 .cke_wfpl_images_dialog * + p {
30                         padding-top: 5px;
31                 }
32                 .cke_wfpl_images_dialog * a {
33                         text-decoration: underline;
34                         color: blue;
35                 }
36                 .cke_wfpl_images_dialog .cke_wfpl_thumbs {
37                         height: 270px;
38                         overflow-y: scroll;
39                 }
40                 .cke_wfpl_thumbs .cke_wfpl_thumb {
41                         width: 50px;
42                         height: 50px;
43                         padding: 10px;
44                         color: transparent;
45                         font-size: 10px;
46                         font-weight: bold;
47                         display: inline-block;
48                         overflow: hidden;
49                         text-align: center;
50                         background-position: 50% 50%;
51                         background-repeat: no-repeat;
52                         background-color: transparent;
53                         border: 2px solid white;
54                 }
55                 .cke_wfpl_thumbs .cke_wfpl_thumb:hover, .cke_wfpl_thumbs .cke_wfpl_thumb.selected {
56                         color: white;
57                         text-shadow: 1px 1px 2px #000;
58                         box-shadow: 1px 1px 6px #444;
59                         border: 2px solid #444;
60                 }
61         </style>
62         <script>
63                 window.cke_wfpl_images = {
64                         images: ~wfpl_images_json~,
65                         next_id: 0,
66                         selected: [],
67                         editors: []
68                 };
69                 var enc_html = function(str) {
70                         return str.replace(/[<>&]/g, function(i) { return '&#' + i.charCodeAt(0) + ';'; });
71                 };
72                 function cke_wfpl_images_thumb_click(plugin_id, element, image_id) {
73                         var thumbs = element.parentNode.children;
74                         var i, thumb;
75                         for (i = 0; i < thumbs.length; i++) {
76                                 thumb = thumbs[i];
77                                 if (thumb === element) {
78                                         if (thumb.className.substr(0, 9) !== 'selected ') {
79                                                 thumb.className = 'selected ' + thumb.className;
80                                         }
81                                 } else {
82                                         if (thumb.className.substr(0, 9) === 'selected ') {
83                                                 thumb.className = thumb.className.substr(9);
84                                         }
85                                 }
86                         }
87                         window.cke_wfpl_images.selected[plugin_id] = image_id;
88                 }
89                 function cke_wfpl_images_insert_click(plugin_id, align) {
90                         var selected = window.cke_wfpl_images.selected[plugin_id];
91                         var editor = window.cke_wfpl_images.editors[plugin_id];
92                         var image;
93                         var code, width, height, src, size, caption;
94                         if (selected == null) {
95                                 CKEDITOR.dialog.getCurrent().hide();
96                                 return;
97                         }
98                         image = window.cke_wfpl_images.images[selected];
99                         switch(align) {
100                                 case 'left':
101                                         code = '<span class="wfpl_ifl"'
102                                 break;
103                                 case 'right':
104                                         code = '<span class="wfpl_ifr"'
105                                 break;
106                                 case 'centered': case 'full':
107                                         code = '<div class="wfpl_ic"'
108                                 break;
109                         }
110                         size = image.sizes.replace(/^\s+|\s+$/g, '').split(/\s\+/)[0];
111                         width = image.image_width;
112                         height = image.image_height;
113                         src = image.image;
114                         if (image.caption == '') {
115                                 caption = '&nbsp;';
116                         } else {
117                                 caption = enc_html(image.caption);
118                         }
119                         if (align != 'full') {
120                                 var wh = size.split('x');
121                                 wh[0] = parseInt(wh[0]);
122                                 wh[1] = parseInt(wh[1]);
123                                 if (width / height > wh[0] / wh[1]) {
124                                         height = Math.round(height * wh[0] / width);
125                                         width = wh[0];
126                                 } else {
127                                         width = Math.round(width * wh[1] / height);
128                                         height = wh[1];
129                                 }
130                                 size = '' + wh[0] + '-' + wh[1]; // dash instead of x
131                                 src = src.substr(0, src.length - 4) + '-' + size + src.substr(src.length - 4);
132                         }
133                         height += 4;
134                         code += ' style="background-image: url(/' + src + ');';
135                         code += ' width: ' + width + 'px;';
136                         code += ' padding-top: ' + height + 'px;';
137                         code += '">' + caption;
138                         switch(align) {
139                                 case 'left': case 'right':
140                                         code += '</span>'
141                                 break;
142                                 case 'centered': case 'full':
143                                         code += '</div>'
144                                 break;
145                         }
146                         CKEDITOR.dialog.getCurrent().hide();
147                         CKEDITOR.currentInstance.insertElement(CKEDITOR.dom.element.createFromHtml(code));
148                 }
149                 CKEDITOR.plugins.add('wfpl_images', {
150                         init: function (editor) {
151                                 var plugin_id = window.cke_wfpl_images.editors.length;
152                                 window.cke_wfpl_images.editors.push(editor);
153                                 window.cke_wfpl_images.selected.push(window.cke_wfpl_images.images.length > 0 ? 0 : null);
154
155                                 editor.addCommand('wfpl_images', new CKEDITOR.dialogCommand('wfpl_images_dialog'));
156                                 editor.ui.addButton('wfpl_images', {
157                                         label: 'Insert Image',
158                                         command: 'wfpl_images',
159                                         toolbar: 'insert'
160                                 });
161                                 CKEDITOR.dialog.add('wfpl_images_dialog', function (api) {
162                                         var i, im, selected, thumbs;
163                                         selected = 'selected ';
164                                         thumbs = '<div class="cke_wfpl_thumbs">'
165                                         for (i in window.cke_wfpl_images.images) {
166                                                 im = window.cke_wfpl_images.images[i];
167                                                 thumbs += '<div class="'+selected+'cke_wfpl_thumb" onclick="return window.cke_wfpl_images_thumb_click('+plugin_id+', this, '+im.id+')" style="background-image: url('+im.thumb+')">'+ enc_html(im.name.length > 0 ? im.name : im.caption) + '</div>';
168                                                 selected = '';
169                                         }
170                                         thumbs += '</div>'
171                                         return {
172                                                 title: 'Insert Image',
173                                                 minWidth: 700,
174                                                 minHeight: 350,
175                                                 contents: [
176                                                         {
177                                                                 expand: true,
178                                                                 padding: 0,
179                                                                 elements: [
180                                                                         {
181                                                                                 type: 'html',
182                                                                                 html: '<div class="cke_wfpl_images_dialog">'
183                                                                                         + '<h3>Step 1: Choose an image to insert:</h3>'
184                                                                                         + thumbs
185                                                                                 + '<p>If you\'d like to insert an image not shown above, you can <a href="admin_images?new=1" target="_blank">upload it here</a>. Sorry, it won\'t appear here until you reload this editor page (hit Save below, then "edit this page" again.)</p>'
186                                                                                 + '</div>'
187                                                                         }
188                                                                 ]
189                                                         }
190                                                 ],
191                                                 buttons: [
192                                                         {
193                                                                 type: 'button',
194                                                                 label: 'Insert on Left',
195                                                                 className: 'cke_dialog_ui_button_ok',
196                                                                 onClick: function() {
197                                                                         cke_wfpl_images_insert_click(plugin_id, 'left');
198                                                                 }
199                                                         },
200                                                         {
201                                                                 type: 'button',
202                                                                 label: 'Insert Centered',
203                                                                 className: 'cke_dialog_ui_button_ok',
204                                                                 onClick: function() {
205                                                                         cke_wfpl_images_insert_click(plugin_id, 'centered');
206                                                                 }
207                                                         },
208                                                         {
209                                                                 type: 'button',
210                                                                 label: 'Insert on Right',
211                                                                 className: 'cke_dialog_ui_button_ok',
212                                                                 onClick: function() {
213                                                                         cke_wfpl_images_insert_click(plugin_id, 'right');
214                                                                 }
215                                                         },
216                                                         {
217                                                                 type: 'button',
218                                                                 label: 'Insert BIG',
219                                                                 className: 'cke_dialog_ui_button_ok',
220                                                                 onClick: function() {
221                                                                         cke_wfpl_images_insert_click(plugin_id, 'full');
222                                                                 }
223                                                         },
224                                                         CKEDITOR.dialog.cancelButton
225                                                 ]
226                                         };
227                                 });
228                         }
229                 });
230                 function make_wysiwyg(name) {
231                         CKEDITOR.replace(name, {
232                                 'contentsCss': 'style.css?m=~style.css mtime~',
233                                 'allowedContent': true,
234                                 bodyId: '~$basename~' + '_wysiwyg_' + name,
235                                 'stylesSet': [
236                                         { name: 'Paragraph', element: 'p'},
237                                         { name: 'Page Headline', element: 'h1'},
238                                         { name: 'Section Headline', element: 'h2'},
239                                         { name: 'Subsection Headline', element: 'h3'},
240                                         { name: 'Tagline (under headline)', element: 'h4', attributes: { class: 'tagline'}},
241                                         { name: 'Quote', element: 'p', attributes: { class: 'quote'}},
242                                         { name: 'Quote Author', element: 'p', attributes: { class: 'attrib'}},
243                                         { name: 'div (generic box)', element: 'div'}
244                                 ],
245                                 'uiColor': '#ccccff',
246                                 'removePlugins': 'forms,templates,smiley,pagebreak,save,newpage,preview,print',
247                                 'extraPlugins': 'wfpl_images',
248                                 'height': '300px',
249                                 'toolbar': [
250                                         ['Source'],
251                                         ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'SpellChecker', 'Scayt'],
252                                         ['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'],
253                                         '/',
254                                         ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript'],
255                                         ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'],
256                                         ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
257                                         ['Link', 'Unlink', 'Anchor'],
258                                         ['wfpl_images', 'Table', 'HorizontalRule', 'SpecialChar', 'PageBreak'],
259                                         '/',
260                                         ['Styles', 'Font', 'FontSize'],
261                                         ['TextColor', 'BGColor'],
262                                         ['Maximize', 'ShowBlocks']
263                                 ]
264                         });
265                 }
266         </script>
267         <!--~}~-->
268
269 </head>
270
271 <body>
272 <!--~$body show {~-->
273
274         <!--~form {~-->
275                 <h1>~$host~ Admin Control Panel</h1>
276
277                 <h2><!--~id unset {~-->Add a new page<!--~}~--><!--~id {~-->Edit page "~title html~"<!--~}~--></h2>
278
279                 <form action="admin_pages" method="post"><!--~id {~--><div style="display: none"><input type="hidden" name="edit_id" value="~id attr~"></div><!--~}~-->
280
281                         <div class="caption">Title</div>
282                         <div class="field_notes">(This appears at the top of the page, in the window title-bar (by the close button) and as the headline/link of search engine results.)</div>
283                         <div class="field"><input type="text" name="title" value="~title attr~" class="wide_field"></div>
284
285                         <div class="caption">Filename</div>
286                         <div class="field_notes">(<!--~editing {~-->Careful: if you change this, be sure to update all links to this page<!--~}~--><!--~editing unset {~-->Please use only a-z, 0-9 and _ (underscore) in your filename. Please, no capitals, punctuation or spaces.<!--~}~-->)</div>
287                         <div class="field"><input type="text" name="filename" value="~filename attr~"></div>
288
289                         <div class="caption">Show in site-wide navigation links (optional)</div>
290                         <div class="field"><select name="navbar"><!--~navbar options~--></select></div>
291
292                         <div class="caption">Navigation Link Text</div>
293                         <div class="field_notes">(If you'd like this page to appear in the navigation with a shorter title.)</div>
294                         <div class="field"><input type="text" name="nav_title" value="~nav_title attr~"></div>
295
296                         <div class="caption">Page Contents</div>
297                         <div class="field_notes">
298                                 <ul class="first">
299                                         <li style="color: red; list-style: none">Please read these instructions in full:</li>
300                                         <li>If you don't see an editor below (with buttons in it) then please try this page in <a href="http://getfirefox.com">Mozilla FireFox</a> or <a href="http://www.google.com/chrome/">Google Chrome</a>.</li>
301                                         <li>If you're pasting from Microsoft Word, please use the "paste from word" button (looks like a clipboard with a "W").</li>
302                                         <li>To make a link, type the text to be clicked, select it, click the "Link" button (looks like a short chain) and paste the web address (where the link should point to) into the "URL" field. Exception: If you're making a link to another page on this site, please remove the "http://~$host~/" from the beginning of the "URL" field and set the "Protocol" to &lt;other&gt;.</li>
303                                         <li>To insert an image: place the cursor at the beginning of a line and click the "insert image" button in the editor. Note that you will only be able to insert images that you have already uploaded on the <a href="admin_images" target="_blank">manage images</a> page.</li>
304                                 </ul>
305                         </div>
306                         <div class="field"><textarea class="html_editor" rows="20" cols="50" id="content" name="content">~content html~</textarea><script>make_wysiwyg('content');</script></div>
307
308                         <!--
309                         <div class="caption">Description</div>
310                         <div class="field_notes">(Hidden description of this page, primarily for search engines.)</div>
311                         <div class="field"><textarea rows="9" cols="22" name="description">~description html~</textarea></div>
312
313                         <div class="caption">Keywords</div>
314                         <div class="field_notes">(Hidden words (up to 30) with commas between them for search engines)</div>
315                         <div class="field"><textarea rows="9" cols="22" name="keywords">~keywords html~</textarea></div>
316                         -->
317
318                         <div class="caption">&nbsp;</div>
319                         <div class="field"><input type="submit" name="save" value="Save"></div>
320
321                 </form>
322
323                 <div class="caption">&nbsp;</div>
324                 <div class="field"><a href="~filename nonempty {~~filename attr~~}~~filename empty {~admin_pages~id {~?id=~id~~}~~}~">Cancel</a></div>
325         <!--~}~-->
326
327         <!--~listing {~-->
328                 <h1>~$host~ Admin Control Panel</h1>
329                 <h2>Manage Pages</h2>
330
331                 <!--~rows once_if {~-->
332                         <p><a href="admin_pages?new=1">[Add a new page]</a></p>
333
334                         <table cellspacing="0" cellpadding="4" border="0" summary="" class="evenodd">
335                                 <tr>
336                                         <th><a href="?sort=~sorting-by-filename~filename">Filename</a></th>
337                                         <th><a href="?sort=~sorting-by-title~title">Title</a></th>
338                                         <th>&nbsp;</th>
339                                 </tr><!--~rows {~-->
340                                 <tr>
341                                         <td class="listing"><a href="admin_pages?edit_id=~id~">~filename html~<!--~filename empty {~--><em>(offline)</em><!--~}~--></a></td>
342                                         <td class="listing"><a href="admin_pages?edit_id=~id~">~title html~<!--~title empty {~--><em>(untitled)</em><!--~}~--></a></td>
343                                         <td><a href="admin_pages?admin_pages_delete_id=~id~" onclick="return confirm('Permanently delete?')">[delete]</a></td>
344                                 </tr><!--~}~-->
345
346                         </table>
347                 <!--~}~-->
348                 <!--~rows once_else {~-->
349                         <p>No pages in database.</p>
350                 <!--~}~-->
351
352                 <p><a href="admin_pages?new=1">[Add a new page]</a></p>
353         <!--~}~-->
354 <!--~}~-->
355 </body>
356 </html>