aboutsummaryrefslogtreecommitdiff
path: root/mod/blog/views/default/blog/forms/edit.php
blob: 5da9c3cd15998f95975ebb2af64f4646dc8f3809 (plain)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<?php
/**
 * Edit blog form
 *
 * @package Blog
 */

// input names => defaults
$values = array(
	'title' => NULL,
	'description' => NULL,
	'status' => 'published',
	'publish_date' => NULL,
	'access_id' => ACCESS_DEFAULT,
	'comments_on' => 'On',
	'excerpt' => NULL,
	'tags' => NULL,
	'container_guid' => NULL,
	'guid' => NULL
);

$forward = $_SERVER['HTTP_REFERER'];

$action_buttons = '';
$delete_link = '';
$draft_warning = '';

// if entity is set, we're editing.
if (isset ($vars['entity'])) {
	$blog = $vars['entity'];

	if (elgg_instanceof($blog, 'object', 'blog')) {
		// passed in values override sticky values in input views
		// if in a sticky form, don't send the overrides and let the view figure it out.
		//if (!elgg_is_sticky_form()) {
			foreach (array_keys($values) as $field) {
				$values[$field] = $blog->$field;
			}

			// load the revision annotation if requested
			if (isset($vars['revision']) && $vars['revision'] instanceof ElggAnnotation && $vars['revision']->entity_guid == $blog->getGUID()) {
				$revision = $vars['revision'];
				$values['description'] = $vars['revision']->value;
			}

			// display a notice if there's an autosaved annotation
			// and we're not editing it.
			if ($auto_save_annotations = $blog->getAnnotations('blog_auto_save', 1)) {
				$auto_save = $auto_save_annotations[0];
			} else {
				$auto_save == FALSE;
			}

			if ($auto_save && $auto_save->id != $revision->id) {
				$draft_warning = '<span class="message warning">'
					. elgg_echo('blog:messages:warning:draft')
					. '</span>';
			}

		//}
	} else {
		echo elgg_echo('blog:error:post_not_found');
		return FALSE;
	}

	// add a delete button if editing
	$delete_url = "action/blog/delete?guid={$blog->getGUID()}";
	$delete_link = elgg_view('output/confirmlink', array(
		'href' => $delete_url,
		'text' => elgg_echo('delete'),
		'class' => 'action-button disabled'
	));
}

$save_button = elgg_view('input/submit', array('value' => elgg_echo('save')));
$action_buttons = $save_button . $delete_link;

$title_label = elgg_echo('title');
$title_input = elgg_view('input/text', array(
	'internalname' => 'title',
	'internalid' => 'blog_title',
	'value' => $values['title']
));

$excerpt_label = elgg_echo('blog:excerpt');
$excerpt_input = elgg_view('input/text', array(
	'internalname' => 'excerpt',
	'internalid' => 'blog_excerpt',
	'value' => html_entity_decode($values['excerpt'], ENT_COMPAT, 'UTF-8')
));

$body_label = elgg_echo('blog:body');
$body_input = elgg_view('input/longtext', array(
	'internalname' => 'description',
	'internalid' => 'blog_description',
	'value' => $values['description']
));

$save_status = elgg_echo('blog:save_status');
if ($values['publish_date']) {
	$saved = date('F j, Y @ H:i', $values['publish_date']);
} else {
	$saved = elgg_echo('blog:never');
}

$status_label = elgg_echo('blog:status');
$status_input = elgg_view('input/pulldown', array(
	'internalname' => 'status',
	'internalid' => 'blog_status',
	'value' => $values['status'],
	'options_values' => array(
		'draft' => elgg_echo('blog:status:draft'),
		'published' => elgg_echo('blog:status:published')
	)
));

$comments_label = elgg_echo('comments');
$comments_input = elgg_view('input/pulldown', array(
	'internalname' => 'comments_on',
	'internalid' => 'blog_comments_on',
	'value' => $values['comments_on'],
	'options_values' => array('On' => elgg_echo('on'), 'Off' => elgg_echo('off'))
));

$tags_label = elgg_echo('tags');
$tags_input = elgg_view('input/tags', array(
	'internalname' => 'tags',
	'internalid' => 'blog_tags',
	'value' => $values['tags']
));

$access_label = elgg_echo('access');
$access_input = elgg_view('input/access', array(
	'internalname' => 'access_id',
	'internalid' => 'blog_access_id',
	'value' => $values['access_id']
));

$publish_date_label = elgg_echo('blog:publish_date');
$publish_date_input = elgg_view('input/datetime', array(
	'internalname' => 'publish_date',
	'internalid' => 'blog_publish_date',
	'value' => $values['publish_date']
));

$categories_input = elgg_view('categories', $vars);

// hidden inputs
//$container_guid_input = elgg_view('input/hidden', array('internalname' => 'container_guid', 'value' => $values['container_guid']));
$guid_input = elgg_view('input/hidden', array('internalname' => 'guid', 'value' => $values['guid']));
$forward_input = elgg_view('input/hidden', array('internalname' => 'forward', 'value' => $forward));

// editing or creating.
if (isset($values['guid'])) {
	$page_title = elgg_echo('blog:edit') . ": \"{$values['title']}\"";
} else {
	$page_title = elgg_echo('blog:new');
}

// display notice if editing an old revision
if (isset($vars['revision']) && $vars['revision'] instanceof ElggAnnotation) {
	$page_title .= ' ' . elgg_echo('blog:edit_revision_notice');
}

$form_body = <<<___END
<h2>$page_title</h2>

$draft_warning

<p class="margin_top">
	<label for="blog_title">$title_label</label>
	$title_input
</p>

<p>
	<label for="blog_excerpt">$excerpt_label</label>
$excerpt_input
</p>

<label for="blog_description">$body_label</label>
$body_input
<br />

<p>
	<label for="blog_tags">$tags_label</label>
	$tags_input
</p>

<p>
	<label for="blog_comments_on">$comments_label</label>
	$comments_input
</p>

<p>
	<label for="blog_access_id">$access_label</label>
	$access_input
</p>

<p>
	<label for="blog_status">$status_label</label>
	$status_input
</p>

$categories_input

<div class="divider"></div>
<p class="margin_none margin_top entity_subtext">
	$save_status <span class="blog_save_status_time">$saved</span>
</p>

$guid_input
$container_guid_input
$forward_input

$action_buttons

___END;

echo elgg_view('input/form', array(
	'internalid' => 'blog_post_edit',
	'internalname' => 'blog_post',
	'action' => "action/blog/save",
	'body' => $form_body
));

elgg_clear_sticky_form('blog');

?>

<script type="text/javascript">
	setInterval("blogSaveDraft()", 60000);

	/*
	 * Attempt to save and update the input with the guid.
	 */
	function blogSaveDraftCallback(data, textStatus, XHR) {
		if (textStatus == 'success' && data.success == true) {
			var form = $('form[name=blog_post]');

			// update the guid input element for new posts that now have a guid
			form.find('input[name=guid]').val(data.guid);

			oldDescription = form.find('textarea[name=description]').val();

			var d = new Date();
			var mins = d.getMinutes() + '';
			if (mins.length == 1) mins = '0' + mins;
			$(".blog_save_status_time").html(d.toLocaleDateString() + " @ " + d.getHours() + ":" + mins);
		} else {
			$(".blog_save_status_time").html("<?php echo elgg_echo('error'); ?>");
		}
	}

	function blogSaveDraft() {
		if (typeof(tinyMCE) != 'undefined') {
			tinyMCE.triggerSave();
		}

		// only save on changed content
		var form = $('form[name=blog_post]');
		var description = form.find('textarea[name=description]').val();
		var title = form.find('input[name=title]').val();

		if (!(description && title) || (description == oldDescription)) {
			return false;
		}

		var draftURL = "<?php echo elgg_get_site_url(); ?>action/blog/auto_save_revision";
		var postData = form.serializeArray();

		// force draft status
		$(postData).each(function(i, e) {
			if (e.name == 'status') {
				e.value = 'draft';
			}
		});

		$.post(draftURL, postData, blogSaveDraftCallback, 'json');
	}

	$(document).ready(function() {
		// get a copy of the body to compare for auto save
		oldDescription = $('form[name=blog_post]').find('textarea[name=description]').val();

/* we don't seems to be using the text counter anymore�
		$('#excerpt.excerpt').each(function(){
			var allowed = 200;

			// set the initial value
			$('#countervalue').text(allowed);

			// bind on key up event
			$(this).keyup(function(){
				var counter_value = ((allowed - ($(this).val().length)));

				$("#countervalue").removeClass();

				if ((counter_value > 10)) {
					$("#countervalue").addClass("positive");
				}
				else if ((counter_value <= 10) && (counter_value >= 0)) {
					$("#countervalue").addClass("gettingclose");
				}
				else if ((counter_value < 0)) {
					$("#countervalue").addClass("negative");
				}

				// insert new length
				$('#countervalue').text(counter_value);

			});
		});
*/
	});

</script>