Add voice recorder button when sending a msg in the chamilo inbox

See BT#14453
pull/2573/head
Julio 8 years ago
parent 6eb782a7a6
commit 0a345a939a
  1. 1
      main/document/record_audio.php
  2. 116
      main/inc/ajax/record_audio_rtc.ajax.php
  3. 192
      main/inc/ajax/record_audio_wami.ajax.php
  4. 22
      main/inc/lib/api.lib.php
  5. 13
      main/inc/lib/javascript/record_audio/record_audio.js
  6. 72
      main/inc/lib/message.lib.php
  7. 76
      main/messages/new_message.php
  8. 24
      main/messages/record_audio.php
  9. 4
      main/messages/view_message.php
  10. 4
      main/template/default/document/record_audio.tpl
  11. 72
      main/template/default/message/record_audio.tpl

@ -153,6 +153,7 @@ $actions = Display::toolbarButton(
$template = new Template($nameTools);
$template->assign('directory', $wamidir);
$template->assign('user_id', api_get_user_id());
$template->assign('reload_page', 1);
$layout = $template->get_template('document/record_audio.tpl');
$content = $template->fetch($layout);

@ -6,12 +6,17 @@ use ChamiloSession as Session;
require_once __DIR__.'/../global.inc.php';
// Add security from Chamilo
api_protect_course_script();
api_block_anonymous_users();
$courseInfo = api_get_course_info();
/** @var string $tool document or exercise */
$tool = isset($_REQUEST['tool']) ? $_REQUEST['tool'] : '';
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'document'; // can be document or message
if ($type == 'document') {
api_protect_course_script();
}
$userId = api_get_user_id();
if (!isset($_FILES['audio_blob'], $_REQUEST['audio_dir'])) {
@ -33,57 +38,64 @@ if (!isset($_FILES['audio_blob'], $_REQUEST['audio_dir'])) {
}
$file = isset($_FILES['audio_blob']) ? $_FILES['audio_blob'] : [];
$audioDir = Security::remove_XSS($_REQUEST['audio_dir']);
$dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document';
$saveDir = $dirBaseDocuments.$audioDir;
if (!is_dir($saveDir)) {
mkdir($saveDir, api_get_permissions_for_new_directories(), true);
}
$file['file'] = $file;
$audioDir = Security::remove_XSS($_REQUEST['audio_dir']);
$uploadedDocument = DocumentManager::upload_document(
$file,
$audioDir,
$file['name'],
null,
0,
'overwrite',
false,
in_array($tool, ['document', 'exercise'])
);
$error = empty($uploadedDocument) || !is_array($uploadedDocument);
if (!$error) {
$newDocId = $uploadedDocument['id'];
$courseId = $uploadedDocument['c_id'];
/** @var learnpath $lp */
$lp = Session::read('oLP');
$lpItemId = isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id']) ? $_REQUEST['lp_item_id'] : null;
if (!empty($lp) && empty($lpItemId)) {
$lp->set_modified_on();
$lpItem = new learnpathItem($lpItemId);
$lpItem->add_audio_from_documents($newDocId);
}
$data = DocumentManager::get_document_data_by_id($newDocId, $courseInfo['code']);
if ($tool === 'exercise') {
header('Content-Type: application/json');
echo json_encode([
'error' => $error,
'message' => Display::getFlashToString(),
'fileUrl' => $data['document_url'],
]);
Display::cleanFlashMessages();
exit;
}
echo $data['document_url'];
switch ($type) {
case 'document':
$dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document';
$saveDir = $dirBaseDocuments.$audioDir;
if (!is_dir($saveDir)) {
mkdir($saveDir, api_get_permissions_for_new_directories(), true);
}
$uploadedDocument = DocumentManager::upload_document(
$file,
$audioDir,
$file['name'],
null,
0,
'overwrite',
false,
in_array($tool, ['document', 'exercise'])
);
$error = empty($uploadedDocument) || !is_array($uploadedDocument);
if (!$error) {
$newDocId = $uploadedDocument['id'];
$courseId = $uploadedDocument['c_id'];
/** @var learnpath $lp */
$lp = Session::read('oLP');
$lpItemId = isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id']) ? $_REQUEST['lp_item_id'] : null;
if (!empty($lp) && empty($lpItemId)) {
$lp->set_modified_on();
$lpItem = new learnpathItem($lpItemId);
$lpItem->add_audio_from_documents($newDocId);
}
$data = DocumentManager::get_document_data_by_id($newDocId, $courseInfo['code']);
if ($tool === 'exercise') {
header('Content-Type: application/json');
echo json_encode([
'error' => $error,
'message' => Display::getFlashToString(),
'fileUrl' => $data['document_url'],
]);
Display::cleanFlashMessages();
exit;
}
echo $data['document_url'];
}
break;
case 'message':
Session::write('current_audio_id', $file['name']);
api_upload_file('audio_message', $file, api_get_user_id());
break;
}

@ -6,7 +6,6 @@ use ChamiloSession as Session;
require_once __DIR__.'/../global.inc.php';
// Add security from Chamilo
api_protect_course_script();
api_block_anonymous_users();
$_course = api_get_course_info();
@ -28,6 +27,12 @@ if (empty($wamiuserid)) {
die();
}
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'document'; // can be document or message
if ($type === 'document') {
api_protect_course_script();
}
// Clean
$waminame = Security::remove_XSS($waminame);
$waminame = Database::escape_string($waminame);
@ -47,95 +52,106 @@ if ($ext != 'wav') {
die();
}
// Do not use here check Fileinfo method because return: text/plain
switch ($type) {
case 'document':
// Do not use here check Fileinfo method because return: text/plain
$dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
$saveDir = $dirBaseDocuments.$wamidir;
$dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
$saveDir = $dirBaseDocuments.$wamidir;
if (!is_dir($saveDir)) {
DocumentManager::createDefaultAudioFolder($_course);
}
if (!is_dir($saveDir)) {
DocumentManager::createDefaultAudioFolder($_course);
}
//avoid duplicates
$waminame_to_save = $waminame;
//$waminame_noex = basename($waminame, ".wav");
//if (file_exists($saveDir.'/'.$waminame_noex.'.'.$ext)) {
// $i = 1;
// while (file_exists($saveDir.'/'.$waminame_noex.'_'.$i.'.'.$ext)) {
// $i++;
// }
// $waminame_to_save = $waminame_noex.'_'.$i.'.'.$ext;
//}
$documentPath = $saveDir.'/'.$waminame_to_save;
// Add to disk
$fh = fopen($documentPath, 'w') or die("can't open file");
fwrite($fh, $content);
fclose($fh);
$fileInfo = pathinfo($documentPath);
$courseInfo = api_get_course_info();
$file = [
'file' => [
'name' => $fileInfo['basename'],
'tmp_name' => $documentPath,
'size' => filesize($documentPath),
'type' => 'audio/wav',
'from_file' => true,
],
];
$output = true;
ob_start();
// Strangely the file path changes with a double extension
copy($documentPath, $documentPath.'.wav');
$documentData = DocumentManager::upload_document(
$file,
$wamidir,
$fileInfo['basename'],
'wav',
0,
'overwrite',
false,
$output
);
$contents = ob_get_contents();
if (!empty($documentData)) {
$newDocId = $documentData['id'];
$documentData['comment'] = 'mp3';
$newMp3DocumentId = DocumentManager::addAndConvertWavToMp3(
$documentData,
$courseInfo,
api_get_session_id(),
api_get_user_id(),
'overwrite',
true
);
if ($newMp3DocumentId) {
$newDocId = $newMp3DocumentId;
}
if (isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id'])) {
$lpItemId = $_REQUEST['lp_item_id'];
/** @var learnpath $lp */
$lp = Session::read('oLP');
if (!empty($lp)) {
$lp->set_modified_on();
$lpItem = new learnpathItem($lpItemId);
$lpItem->add_audio_from_documents($newDocId);
echo Display::return_message(get_lang('Updated'), 'info');
// Avoid duplicates
$waminame_to_save = $waminame;
$documentPath = $saveDir.'/'.$waminame_to_save;
// Add to disk
$fh = fopen($documentPath, 'w') or die("can't open file");
fwrite($fh, $content);
fclose($fh);
$fileInfo = pathinfo($documentPath);
$courseInfo = api_get_course_info();
$file = [
'file' => [
'name' => $fileInfo['basename'],
'tmp_name' => $documentPath,
'size' => filesize($documentPath),
'type' => 'audio/wav',
'from_file' => true,
],
];
$output = true;
ob_start();
// Strangely the file path changes with a double extension
copy($documentPath, $documentPath.'.wav');
$documentData = DocumentManager::upload_document(
$file,
$wamidir,
$fileInfo['basename'],
'wav',
0,
'overwrite',
false,
$output
);
$contents = ob_get_contents();
if (!empty($documentData)) {
$newDocId = $documentData['id'];
$documentData['comment'] = 'mp3';
$newMp3DocumentId = DocumentManager::addAndConvertWavToMp3(
$documentData,
$courseInfo,
api_get_session_id(),
api_get_user_id(),
'overwrite',
true
);
if ($newMp3DocumentId) {
$newDocId = $newMp3DocumentId;
}
if (isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id'])) {
$lpItemId = $_REQUEST['lp_item_id'];
/** @var learnpath $lp */
$lp = Session::read('oLP');
if (!empty($lp)) {
$lp->set_modified_on();
$lpItem = new learnpathItem($lpItemId);
$lpItem->add_audio_from_documents($newDocId);
echo Display::return_message(get_lang('Updated'), 'info');
}
}
// Strangely the file path changes with a double extension
// Remove file with one extension
unlink($documentPath);
} else {
echo $contents;
}
}
// Strangely the file path changes with a double extension
// Remove file with one extension
unlink($documentPath);
} else {
echo $contents;
break;
case 'message':
$tempFile = api_get_path(SYS_ARCHIVE_PATH).$waminame;
file_put_contents($tempFile, $content);
Session::write('current_audio_id', $waminame);
$file = [
'name' => basename($tempFile),
'tmp_name' => $tempFile,
'size' => filesize($tempFile),
'type' => 'audio/wav',
'move_file' => true,
];
api_upload_file('audio_message', $file, api_get_user_id());
break;
}

@ -8979,8 +8979,8 @@ function api_upload_file($type, $file, $itemId, $cropParameters = '')
}
$pathToSave = $path.$name;
$result = moveUploadedFile($file, $pathToSave);
$result = move_uploaded_file($file['tmp_name'], $pathToSave);
if ($result) {
if (!empty($cropParameters)) {
$image = new Image($pathToSave);
@ -9063,6 +9063,26 @@ function api_remove_uploaded_file($type, $file)
}
}
/**
* @param string $type
* @param int $itemId
* @param string $file
*
* @return bool
*/
function api_remove_uploaded_file_by_id($type, $itemId, $file)
{
$file = api_get_uploaded_file($type, $itemId, $file, false);
$typePath = api_get_path(SYS_UPLOAD_PATH).$type;
if (Security::check_abs_path($file, $typePath) && file_exists($file) && is_file($file)) {
unlink($file);
return true;
}
return false;
}
/**
* Converts string value to float value.
*

@ -13,7 +13,7 @@ window.RecordAudio = (function () {
btnSave = rtcInfo.btnSaveId ? $(rtcInfo.btnSaveId) : null,
tagAudio = $(rtcInfo.plyrPreviewId);
function saveAudio () {
function saveAudio() {
var recordedBlob = recordRTC.getBlob();
if (!recordedBlob) {
@ -28,7 +28,7 @@ window.RecordAudio = (function () {
formData.append('audio_dir', rtcInfo.directory);
$.ajax({
url: _p.web_ajax + 'record_audio_rtc.ajax.php?tool=' + (!!txtName.length ? 'document' : 'exercise'),
url: _p.web_ajax + 'record_audio_rtc.ajax.php?type='+rtcInfo.type+'&tool=' + (!!txtName.length ? 'document' : 'exercise'),
data: formData,
processData: false,
contentType: false,
@ -44,8 +44,10 @@ window.RecordAudio = (function () {
}
}).done(function (response) {
if (!!txtName.length) {
window.location.reload();
return;
if (rtcInfo.reload_page == 1) {
window.location.reload();
return;
}
}
$(response.message).insertAfter($(rtcInfo.blockId).find('.well'));
@ -194,7 +196,8 @@ window.RecordAudio = (function () {
recordUrl: _p.web_ajax + 'record_audio_wami.ajax.php?' + $.param({
waminame: fileName + '.wav',
wamidir: wamiInfo.directory,
wamiuserid: wamiInfo.userId
wamiuserid: wamiInfo.userId,
type: wamiInfo.type
}),
buttonUrl: _p.web_lib + 'wami-recorder/buttons.png',
buttonNoUrl: _p.web_img + 'blank.gif'

@ -302,16 +302,17 @@ class MessageManager
* @param int $receiver_user_id
* @param string $subject
* @param string $content
* @param array $attachments files array($_FILES) (optional)
* @param array $fileCommentList about attachment files (optional)
* @param int $group_id (optional)
* @param int $parent_id (optional)
* @param int $editMessageId id for updating the message (optional)
* @param int $topic_id (optional) the default value is the current user_id
* @param array $attachments files array($_FILES) (optional)
* @param array $fileCommentList about attachment files (optional)
* @param int $group_id (optional)
* @param int $parent_id (optional)
* @param int $editMessageId id for updating the message (optional)
* @param int $topic_id (optional) the default value is the current user_id
* @param int $sender_id
* @param bool $directMessage
* @param int $forwardId
* @param array $smsParameters
* @param bool $checkCurrentAudioId
*
* @return bool
*/
@ -328,7 +329,8 @@ class MessageManager
$sender_id = 0,
$directMessage = false,
$forwardId = 0,
$smsParameters = []
$smsParameters = [],
$checkCurrentAudioId = false
) {
$table = Database::get_main_table(TABLE_MESSAGE);
$group_id = (int) $group_id;
@ -372,6 +374,27 @@ class MessageManager
}
}
if ($checkCurrentAudioId) {
// Add the audio file as an attachment
$audioId = Session::read('current_audio_id');
if (!empty($audioId)) {
$file = api_get_uploaded_file('audio_message', api_get_user_id(), $audioId);
if (!empty($file)) {
$audioAttachment = [
'name' => basename($file),
'comment' => 'audio_message',
'size' => filesize($file),
'tmp_name' => $file,
'error' => 0,
'type' => DocumentManager::file_get_mime_type(basename($file)),
];
// create attachment from audio message
$attachmentList[] = $audioAttachment;
}
}
}
// Validating fields
if (empty($subject) && empty($group_id)) {
Display::addFlash(
@ -423,7 +446,7 @@ class MessageManager
// Forward also message attachments
if (!empty($forwardId)) {
$attachments = MessageManager::getAttachmentList($forwardId);
$attachments = self::getAttachmentList($forwardId);
foreach ($attachments as $attachment) {
if (!empty($attachment['file_source'])) {
$file = [
@ -1211,14 +1234,14 @@ class MessageManager
public static function showMessageBox($messageId, $source = 'inbox')
{
$table = Database::get_main_table(TABLE_MESSAGE);
$messageId = intval($messageId);
$messageId = (int) $messageId;
if ($source == 'outbox') {
if (isset($messageId) && is_numeric($messageId)) {
$query = "SELECT * FROM $table
WHERE
user_sender_id = ".api_get_user_id()." AND
id = ".$messageId." AND
id = $messageId AND
msg_status = ".MESSAGE_STATUS_OUTBOX;
$result = Database::query($query);
}
@ -1890,16 +1913,23 @@ class MessageManager
// get file attachments by message id
$list = [];
if ($files) {
$attach_icon = Display::return_icon('attachment.gif', '');
$attachIcon = Display::return_icon('attachment.gif', '');
$archiveURL = api_get_path(WEB_CODE_PATH).'messages/download.php?type='.$type.'&file=';
foreach ($files as $row_file) {
$archiveFile = $row_file['path'];
$filename = $row_file['filename'];
$filesize = format_file_size($row_file['size']);
$filecomment = Security::remove_XSS($row_file['comment']);
$size = format_file_size($row_file['size']);
$comment = Security::remove_XSS($row_file['comment']);
$filename = Security::remove_XSS($filename);
$list[] = $attach_icon.'&nbsp;<a href="'.$archiveURL.$archiveFile.'">'.$filename.'</a>
&nbsp;('.$filesize.')'.(!empty($filecomment) ? '&nbsp;-&nbsp;<i>'.$filecomment.'</i>' : '');
$link = Display::url($filename, $archiveURL.$archiveFile);
$comment = !empty($comment) ? '&nbsp;-&nbsp;<i>'.$comment.'</i>' : '';
$attachmentLine = $attachIcon.'&nbsp;'.$link.'&nbsp;('.$size.')'.$comment;
if ($row_file['comment'] == 'audio_message') {
$attachmentLine = '<audio src="'.$archiveURL.$archiveFile.'"/>';
}
$list[] = $attachmentLine;
}
}
@ -2522,4 +2552,16 @@ class MessageManager
return $row['count'];
}
/**
* Clean audio messages already added in the message tool
*/
public static function cleanAudioMessage()
{
$audioId = Session::read('current_audio_id');
if (!empty($audioId)) {
api_remove_uploaded_file_by_id('audio_message', api_get_user_id(), $audioId);
Session::erase('current_audio_id');
}
}
}

@ -23,7 +23,6 @@ if (api_get_setting('allow_message_tool') !== 'true') {
}
$allowSocial = api_get_setting('allow_social_tool') == 'true';
$nameTools = api_xml_http_response_encode(get_lang('Messages'));
$htmlHeadXtra[] = '<script>
@ -52,24 +51,28 @@ function add_image_form() {
</script>';
$nameTools = get_lang('ComposeMessage');
$tpl = new Template(get_lang('ComposeMessage'));
/**
* Shows the compose area + a list of users to select from.
*/
function show_compose_to_any($user_id)
function show_compose_to_any($tpl)
{
$default['user_list'] = 0;
$online_user_list = null;
$html = manageForm($default, $online_user_list);
$html = manageForm($default, null, null, $tpl);
return $html;
}
function show_compose_reply_to_message($message_id, $receiver_id)
function show_compose_reply_to_message($message_id, $receiver_id, $tpl)
{
$table = Database::get_main_table(TABLE_MESSAGE);
$receiver_id = (int) $receiver_id;
$message_id = (int) $message_id;
$query = "SELECT user_sender_id
FROM $table
WHERE user_receiver_id = ".intval($receiver_id)." AND id = ".intval($message_id);
WHERE user_receiver_id = ".$receiver_id." AND id = ".$message_id;
$result = Database::query($query);
$row = Database::fetch_array($result, 'ASSOC');
$userInfo = api_get_user_info($row['user_sender_id']);
@ -80,33 +83,34 @@ function show_compose_reply_to_message($message_id, $receiver_id)
}
$default['users'] = [$row['user_sender_id']];
$html = manageForm($default, null, $userInfo['complete_name_with_username']);
$html = manageForm($default, null, $userInfo['complete_name_with_username'], $tpl);
return $html;
}
function show_compose_to_user($receiver_id)
function show_compose_to_user($receiver_id, $tpl)
{
$userInfo = api_get_user_info($receiver_id);
$html = get_lang('To').':&nbsp;<strong>'.$userInfo['complete_name'].'</strong>';
$default['title'] = api_xml_http_response_encode(get_lang('EnterTitle'));
$default['users'] = [$receiver_id];
$html .= manageForm($default);
$html .= manageForm($default, null, '', $tpl);
return $html;
}
/**
* @param $default
* @param null $select_from_user_list
* @param string $sent_to
* @param $default
* @param null $select_from_user_list
* @param string $sent_to
* @param Template $tpl
*
* @return string
*/
function manageForm($default, $select_from_user_list = null, $sent_to = '')
function manageForm($default, $select_from_user_list = null, $sent_to = '', $tpl = null)
{
$group_id = isset($_REQUEST['group_id']) ? intval($_REQUEST['group_id']) : null;
$message_id = isset($_GET['message_id']) ? intval($_GET['message_id']) : null;
$group_id = isset($_REQUEST['group_id']) ? (int) $_REQUEST['group_id'] : null;
$message_id = isset($_GET['message_id']) ? (int) $_GET['message_id'] : null;
$form = new FormValidator(
'compose_message',
@ -115,6 +119,7 @@ function manageForm($default, $select_from_user_list = null, $sent_to = '')
null,
['enctype' => 'multipart/form-data']
);
if (empty($group_id)) {
if (isset($select_from_user_list)) {
$form->addText(
@ -170,8 +175,8 @@ function manageForm($default, $select_from_user_list = null, $sent_to = '')
if (isset($_GET['re_id'])) {
$message_reply_info = MessageManager::get_message_by_id($_GET['re_id']);
$default['title'] = get_lang('MailSubjectReplyShort')." ".$message_reply_info['title'];
$form->addHidden('re_id', intval($_GET['re_id']));
$default['title'] = get_lang('MailSubjectReplyShort').' '.$message_reply_info['title'];
$form->addHidden('re_id', (int) $_GET['re_id']);
$form->addHidden('save_form', 'save_form');
// Adding reply mail
@ -204,8 +209,7 @@ function manageForm($default, $select_from_user_list = null, $sent_to = '')
}
if (empty($group_id)) {
$form->addElement(
'label',
$form->addLabel(
'',
'<div id="file_uploads"><div id="filepath_1">
<div id="filepaths" class="form-horizontal">
@ -221,13 +225,12 @@ function manageForm($default, $select_from_user_list = null, $sent_to = '')
</div>
</div>
</div>
</div>
'
</div>'
);
$form->addLabel(
'',
'<span id="link-more-attach"><a href="javascript://" onclick="return add_image_form()">'.
'<span id="link-more-attach"><a class="btn btn-default" href="javascript://" onclick="return add_image_form()">'.
get_lang('AddOneMoreFile').'</a></span>&nbsp;('.
sprintf(
get_lang('MaximunFileSizeX'),
@ -236,6 +239,13 @@ function manageForm($default, $select_from_user_list = null, $sent_to = '')
);
}
$form->addLabel(
'',
'<iframe
frameborder="0" height="200" width="100%" scrolling="no"
src="'.api_get_path(WEB_CODE_PATH).'messages/record_audio.php"></iframe>'
);
$form->addButtonSend(get_lang('SendMessage'), 'compose');
$form->setRequiredNote('<span class="form_required">*</span> <small>'.get_lang('ThisFieldIsRequired').'</small>');
@ -262,7 +272,7 @@ function manageForm($default, $select_from_user_list = null, $sent_to = '')
$forwardId = isset($_POST['forward_id']) ? $_POST['forward_id'] : false;
if (is_array($user_list) && count($user_list) > 0) {
//all is well, send the message
// All is well, send the message
foreach ($user_list as $userId) {
$res = MessageManager::send_message(
$userId,
@ -276,7 +286,9 @@ function manageForm($default, $select_from_user_list = null, $sent_to = '')
0,
null,
false,
$forwardId
$forwardId,
[],
true
);
if ($res) {
@ -288,6 +300,7 @@ function manageForm($default, $select_from_user_list = null, $sent_to = '')
));
}
}
MessageManager::cleanAudioMessage();
} else {
Display::addFlash(Display::return_message('ErrorSendingMessage', 'error'));
}
@ -369,12 +382,13 @@ if (!isset($_POST['compose'])) {
if (isset($_GET['re_id'])) {
$social_right_content .= show_compose_reply_to_message(
$_GET['re_id'],
api_get_user_id()
api_get_user_id(),
$tpl
);
} elseif (isset($_GET['send_to_user'])) {
$social_right_content .= show_compose_to_user($_GET['send_to_user']);
$social_right_content .= show_compose_to_user($_GET['send_to_user'], $tpl);
} else {
$social_right_content .= show_compose_to_any(api_get_user_id());
$social_right_content .= show_compose_to_any($tpl);
}
} else {
$restrict = false;
@ -391,19 +405,19 @@ if (!isset($_POST['compose'])) {
// comes from a reply button
if (isset($_GET['re_id']) || isset($_GET['forward_id'])) {
$social_right_content .= manageForm($default);
$social_right_content .= manageForm($default, null, null, $tpl);
} else {
// post
if ($restrict) {
if (!isset($_POST['group_id'])) {
$default['users'] = isset($_POST['users']) ? $_POST['users'] : null;
} else {
$default['group_id'] = $_POST['group_id'];
$default['group_id'] = (int) $_POST['group_id'];
}
if (isset($_POST['hidden_user'])) {
$default['users'] = [$_POST['hidden_user']];
}
$social_right_content .= manageForm($default);
$social_right_content .= manageForm($default, null, null, $tpl);
} else {
$social_right_content .= Display::return_message(get_lang('ErrorSendingMessage'), 'error');
}
@ -415,10 +429,10 @@ if ($allowSocial) {
$social_right_content .= '</div>';
}
$tpl = new Template(get_lang('ComposeMessage'));
// Block Social Avatar
SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'messages');
MessageManager::cleanAudioMessage();
if ($allowSocial) {
$tpl->assign('social_menu_block', $social_menu_block);
$tpl->assign('social_right_content', $social_right_content);

@ -0,0 +1,24 @@
<?php
/* For licensing terms, see /license.txt */
require_once __DIR__.'/../inc/global.inc.php';
api_block_anonymous_users();
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'rtc/RecordRTC.js"></script>';
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'wami-recorder/recorder.js"></script>';
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'wami-recorder/gui.js"></script>';
$htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'swfobject/swfobject.js"></script>';
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'swfobject/swfobject.js"></script>';
$htmlHeadXtra[] = api_get_js('record_audio/record_audio.js');
$tpl = new Template(get_lang('ComposeMessage'), false, false, false, true);
$record = $tpl->get_template('message/record_audio.tpl');
$tpl->assign('user_id', api_get_user_id());
$tpl->assign('audio_title', api_get_unique_id());
$tpl->assign('reload_page', 0);
$tpl->assign('content', $tpl->fetch($record));
$tpl->display_no_layout_template();
exit;

@ -12,8 +12,8 @@ if (api_get_setting('allow_message_tool') != 'true') {
api_not_allowed(true);
}
$allowSocial = api_get_setting('allow_social_tool') == 'true';
$allowMessage = api_get_setting('allow_message_tool') == 'true';
$allowSocial = api_get_setting('allow_social_tool') === 'true';
$allowMessage = api_get_setting('allow_message_tool') === 'true';
if ($allowSocial) {
$this_section = SECTION_SOCIAL;

@ -65,7 +65,9 @@
btnStopId: '#btn-stop-record',
btnSaveId: '#btn-save-record',
plyrPreviewId: '#record-preview',
directory: '{{ directory }}'
directory: '{{ directory }}',
reload_page: 1,
type : 'document'
},
{
blockId: '#record-audio-wami',

@ -0,0 +1,72 @@
<div id="record-audio-recordrtc" class="row text-center">
<form>
<div class="row">
<div class="col-sm-4 col-sm-offset-4">
<div class="form-group">
<span class="fa fa-microphone fa-5x fa-fw" aria-hidden="true"></span>
<span class="sr-only">{{ 'RecordAudio'|get_lang }}</span>
</div>
<input type="hidden" name="audio_title" id="audio-title-rtc" value="{{ audio_title }}">
</div>
</div>
<div class="text-center">
<div class="form-group">
<button class="btn btn-default" type="button" id="btn-start-record">
<span class="fa fa-circle fa-fw" aria-hidden="true"></span> {{ 'StartRecordingAudio'|get_lang }}
</button>
<button class="btn btn-danger hidden" type="button" id="btn-stop-record" disabled>
<span class="fa fa-square fa-fw" aria-hidden="true"></span> {{ 'StopRecordingAudio'|get_lang }}
</button>
</div>
<div class="form-group">
<audio class="skip hidden center-block" controls id="record-preview"></audio>
</div>
</div>
</form>
</div>
<div class="row" id="record-audio-wami">
<div class="col-sm-3 col-sm-offset-3">
<br>
<form>
<div class="form-group">
<input type="hidden" name="audio_title" id="audio-title-wami" value="{{ audio_title }}">
</div>
<div class="form-group text-center">
<button class="btn btn-default" type="button" id="btn-activate-wami">
<span class="fa fa-check fa-fw" aria-hidden=""></span> {{ 'Activate'|get_lang }}
</button>
</div>
</form>
</div>
<div class="col-sm-3">
<div id="record-audio-wami-container" class="wami-container"></div>
</div>
</div>
<script>
$(document).on('ready', function () {
RecordAudio.init(
{
blockId: '#record-audio-recordrtc',
btnStartId: '#btn-start-record',
btnPauseId: '#btn-pause-record',
btnPlayId: '#btn-play-record',
btnStopId: '#btn-stop-record',
btnSaveId: '',
plyrPreviewId: '#record-preview',
directory: '{{ directory }}',
reload_page: '{{ reload_page }}',
type: 'message',
},
{
blockId: '#record-audio-wami',
containerId: 'record-audio-wami-container',
directory: '{{ directory }}',
userId: {{ user_id }},
type: 'message'
},
null
);
});
</script>
Loading…
Cancel
Save