Post body and title are auto-saved
This commit is contained in:
parent
aca719ac74
commit
a5aff7d0c9
37
Zotlabs/Module/Autosavetext.php
Normal file
37
Zotlabs/Module/Autosavetext.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
namespace Zotlabs\Module; /** @file */
|
||||||
|
|
||||||
|
|
||||||
|
class Autosavetext extends \Zotlabs\Web\Controller {
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
|
||||||
|
if(! local_channel())
|
||||||
|
return;
|
||||||
|
|
||||||
|
$ret = array('success' => true);
|
||||||
|
if(array_key_exists('body',$_REQUEST) && array_key_exists('type',$_REQUEST)) {
|
||||||
|
$body = escape_tags($_REQUEST['body']);
|
||||||
|
$title = (array_key_exists('title',$_REQUEST) ? escape_tags($_REQUEST['title']) : '');
|
||||||
|
$type = $_REQUEST['type'];
|
||||||
|
|
||||||
|
if($body && $type === 'post') {
|
||||||
|
set_pconfig(local_channel(),'autosavetext_post','body',$body);
|
||||||
|
set_pconfig(local_channel(),'autosavetext_post','title',$title);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger('post saved.', LOGGER_DEBUG);
|
||||||
|
}
|
||||||
|
|
||||||
|
// // push updates to channel clones
|
||||||
|
//
|
||||||
|
// if((argc() > 1) && (argv(1) === 'sync')) {
|
||||||
|
// require_once('include/zot.php');
|
||||||
|
// build_sync_packet();
|
||||||
|
// }
|
||||||
|
|
||||||
|
json_return_and_die($ret);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1050,6 +1050,10 @@ class Item extends \Zotlabs\Web\Controller {
|
|||||||
|
|
||||||
logger('post_complete');
|
logger('post_complete');
|
||||||
|
|
||||||
|
// Remove auto-saved post text if the post was successfully posted
|
||||||
|
del_pconfig(local_channel(),'autosavetext_post','body');
|
||||||
|
del_pconfig(local_channel(),'autosavetext_post','title');
|
||||||
|
|
||||||
if($moderated) {
|
if($moderated) {
|
||||||
info(t('Your comment is awaiting approval.') . EOL);
|
info(t('Your comment is awaiting approval.') . EOL);
|
||||||
}
|
}
|
||||||
|
@ -1361,6 +1361,14 @@ function status_editor($a, $x, $popup = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sharebutton = (x($x,'button') ? $x['button'] : t('Share'));
|
$sharebutton = (x($x,'button') ? $x['button'] : t('Share'));
|
||||||
|
$content = ((x($x,'body')) ? htmlspecialchars($x['body'], ENT_COMPAT,'UTF-8') : '');
|
||||||
|
if(!$content) {
|
||||||
|
$content = get_pconfig(local_channel(),'autosavetext_post','body');
|
||||||
|
}
|
||||||
|
$title = ((x($x, 'title')) ? htmlspecialchars($x['title'], ENT_COMPAT,'UTF-8') : '');
|
||||||
|
if(!$title) {
|
||||||
|
$title = get_pconfig(local_channel(),'autosavetext_post','title');
|
||||||
|
}
|
||||||
$placeholdtext = (x($x,'content_label') ? $x['content_label'] : $sharebutton);
|
$placeholdtext = (x($x,'content_label') ? $x['content_label'] : $sharebutton);
|
||||||
|
|
||||||
$o .= replace_macros($tpl, array(
|
$o .= replace_macros($tpl, array(
|
||||||
@ -1394,14 +1402,14 @@ function status_editor($a, $x, $popup = false) {
|
|||||||
'$feature_nocomment' => $feature_nocomment,
|
'$feature_nocomment' => $feature_nocomment,
|
||||||
'$nocomment' => ((array_key_exists('item',$x)) ? $x['item']['item_nocomment'] : 0),
|
'$nocomment' => ((array_key_exists('item',$x)) ? $x['item']['item_nocomment'] : 0),
|
||||||
'$clearloc' => $clearloc,
|
'$clearloc' => $clearloc,
|
||||||
'$title' => ((x($x, 'title')) ? htmlspecialchars($x['title'], ENT_COMPAT,'UTF-8') : ''),
|
'$title' => $title,
|
||||||
'$placeholdertitle' => ((x($x, 'placeholdertitle')) ? $x['placeholdertitle'] : t('Title (optional)')),
|
'$placeholdertitle' => ((x($x, 'placeholdertitle')) ? $x['placeholdertitle'] : t('Title (optional)')),
|
||||||
'$catsenabled' => $catsenabled,
|
'$catsenabled' => $catsenabled,
|
||||||
'$category' => ((x($x, 'category')) ? $x['category'] : ''),
|
'$category' => ((x($x, 'category')) ? $x['category'] : ''),
|
||||||
'$placeholdercategory' => t('Categories (optional, comma-separated list)'),
|
'$placeholdercategory' => t('Categories (optional, comma-separated list)'),
|
||||||
'$permset' => t('Permission settings'),
|
'$permset' => t('Permission settings'),
|
||||||
'$ptyp' => ((x($x, 'ptyp')) ? $x['ptyp'] : ''),
|
'$ptyp' => ((x($x, 'ptyp')) ? $x['ptyp'] : ''),
|
||||||
'$content' => ((x($x,'body')) ? htmlspecialchars($x['body'], ENT_COMPAT,'UTF-8') : ''),
|
'$content' => $content,
|
||||||
'$attachment' => ((x($x, 'attachment')) ? $x['attachment'] : ''),
|
'$attachment' => ((x($x, 'attachment')) ? $x['attachment'] : ''),
|
||||||
'$post_id' => ((x($x, 'post_id')) ? $x['post_id'] : ''),
|
'$post_id' => ((x($x, 'post_id')) ? $x['post_id'] : ''),
|
||||||
'$defloc' => $x['default_location'],
|
'$defloc' => $x['default_location'],
|
||||||
|
@ -40,6 +40,38 @@
|
|||||||
<input name="category" id="jot-category" type="text" placeholder="{{$placeholdercategory}}" value="{{$category}}" data-role="cat-tagsinput">
|
<input name="category" id="jot-category" type="text" placeholder="{{$placeholdercategory}}" value="{{$category}}" data-role="cat-tagsinput">
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
var postSaveTimer = null;
|
||||||
|
|
||||||
|
$(document).on('focusout',"#profile-jot-text",function(e){
|
||||||
|
if(postSaveTimer)
|
||||||
|
clearTimeout(postSaveTimer);
|
||||||
|
postSaveChanges(true);
|
||||||
|
postSaveTimer = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on('focusin',"#profile-jot-text",function(e){
|
||||||
|
postSaveTimer = setTimeout(function () {
|
||||||
|
postSaveChanges(false);
|
||||||
|
},10000);
|
||||||
|
});
|
||||||
|
|
||||||
|
function postSaveChanges(isFinal = false, type) {
|
||||||
|
$.post('autosavetext',
|
||||||
|
{
|
||||||
|
'type' : 'post',
|
||||||
|
'body' : $("#profile-jot-text").val(),
|
||||||
|
'title': $("#jot-title").val()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if( !isFinal) {
|
||||||
|
postSaveTimer = setTimeout(postSaveChanges,10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
</script>
|
||||||
<div id="jot-text-wrap">
|
<div id="jot-text-wrap">
|
||||||
<textarea class="profile-jot-text" id="profile-jot-text" name="body" tabindex="2" placeholder="{{$placeholdtext}}" >{{$content}}</textarea>
|
<textarea class="profile-jot-text" id="profile-jot-text" name="body" tabindex="2" placeholder="{{$placeholdtext}}" >{{$content}}</textarea>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user