-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtranscribe.php
More file actions
132 lines (114 loc) · 4.17 KB
/
transcribe.php
File metadata and controls
132 lines (114 loc) · 4.17 KB
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
<?php
if (!isset($_REQUEST['TranscriptionStatus'])) {
echo "Must specify transcription status";
exit;
}
if (!isset($_REQUEST['RecordingUrl'])) {
echo "Must specify recording url";
exit;
}
require_once '../../../wp-load.php';
require './twilio.php';
$settings = get_option('phonoblogsettings');
if($_REQUEST['type'] == 'title'){
// find post by sid
$sid = $_REQUEST['CallSid'];
// get transcription status and text
$transcription_status = (strtolower($_REQUEST['TranscriptionStatus']) == 'completed') ? 'completed' : 'error';
$transcription_text = $_REQUEST['TranscriptionText'] ? $_REQUEST['TranscriptionText'] : 'Error Transcribing Title';
$posts = get_posts(array(
'meta_query' => array(
array(
'key' => 'phonoblog_sid',
'value' => $sid,
)
),
'post_status' => 'any',
));
// if the post doesn't exist create one
// and add the post_status meta but leave
// it as a draft since none of the other
// content is in place
if(empty($posts)){
$post = wp_insert_post(array(
'post_title' => $transcription_text,
'post_content' => 'Pending',
'post_author' => $settings['user'],
'post_status' => 'draft',
));
add_post_meta($post, 'phonoblog_title_status', $transcription_status);
add_post_meta($post, 'phonoblog_title_recording', $_REQUEST['RecordingUrl']);
add_post_meta($post, 'phonoblog_sid', $sid);
}else{
// if the post exists then get the status
// of the title and content transcriptions
$post = get_object_vars($posts[0]);
$post_status = get_post_meta($post['ID'], 'phonoblog_post_status', true);
$content_status = get_post_meta($post['ID'], 'phonoblog_content_status', true);
// if everything is ready publish the post
if(($post_status && $content_status) && $post_status == 'publish' && $content_status == 'completed'){
$post['post_status'] = $post_status;
$post['post_title'] = $transcription_text;
wp_insert_post($post);
}else{
$post['post_title'] = $transcription_text;
wp_insert_post($post);
}
// if not add the post status meta so that it can be
// published when everything is ready
add_post_meta($post['ID'], 'phonoblog_title_status', $transcription_status);
add_post_meta($post['ID'], 'phonoblog_title_recording', $_REQUEST['RecordingUrl']);
}
}elseif($_REQUEST['type'] == 'content'){
// find post by sid
$sid = $_REQUEST['CallSid'];
// get transcription status and text
$transcription_status = (strtolower($_REQUEST['TranscriptionStatus']) == 'completed') ? 'completed' : 'error';
$transcription_text = $_REQUEST['TranscriptionText'] ? $_REQUEST['TranscriptionText'] : 'Error Transcribing Title';
$posts = get_posts(array(
'meta_query' => array(
array(
'key' => 'phonoblog_sid',
'value' => $sid,
)
),
'post_status' => 'any',
));
// if the post doesn't exist create one
// and add the post_status meta but leave
// it as a draft since none of the other
// content is in place
if(empty($posts)){
$post = wp_insert_post(array(
'post_title' => 'Pending',
'post_content' => $transcription_text,
'post_author' => $settings['user'],
'post_status' => 'draft',
));
add_post_meta($post, 'phonoblog_content_status', $transcription_status);
add_post_meta($post, 'phonoblog_content_recording', $_REQUEST['RecordingUrl']);
add_post_meta($post, 'phonoblog_sid', $sid);
}else{
// if the post exists then get the status
// of the title and content transcriptions
$post = get_object_vars($posts[0]);
$post_status = get_post_meta($post['ID'], 'phonoblog_post_status', true);
$title_status = get_post_meta($post['ID'], 'phonoblog_title_status', true);
// if everything is ready publish the post
if(($post_status && $title_status) && $post_status == 'publish' && $title_status == 'completed'){
$post['post_status'] = $post_status;
$post['post_content'] = $transcription_text;
wp_insert_post($post);
}else{
$post['post_content'] = $transcription_text;
wp_insert_post($post);
}
// if not add the post status meta so that it can be
// published when everything is ready
add_post_meta($post['ID'], 'phonoblog_content_status', $transcription_status);
add_post_meta($post['ID'], 'phonoblog_content_recording', $_REQUEST['RecordingUrl']);
}
}else{
exit;
}
?>