-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.php
111 lines (74 loc) · 2.88 KB
/
post.php
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
<?php
class brafton_post{
public $article_id;
private $name;
private $meta_description;
private $slug;
private $post_body;
private $post_summary;
private $topics;
private $date;
public function __construct($title,$meta_desc,$slug,$body,$summary,$topics = false,$video = false, $date = false){
//creates blog post in draft format, updates it with desired data
//returns article id, so it can be published if desired
//3 step process recommended by hubspot api docs
$this->name = $title;
$this->meta_description = $meta_desc;
$this->slug = $slug;
$this->body = $body;
$this->summary = $summary;
$this->topics = $topics;
$this->date = strtotime($date)*1000;
$article = array(
'name'=>$this->name,
'content_group_id'=>blog_id,
);
$article_json = $this->import_post($article);
$this->article_id = $article_json->id;
$updated_article = array(
'blog_author_id'=>author_id,
'meta_description'=>$this->meta_description,
'slug'=>$this->slug,
'post_body'=>$this->body,
'publish_immediately'=>true,
"post_summary"=> $this->summary,
);
if($topics){
$topics_string = "[";
foreach($topics as $topic){
$topics_string .= $topic . ',';
}
$topics_string .= "]";
$updated_article['topic_ids'] = $topics;
}
if($video){
$updated_article['head_html'] = '<link href="//vjs.zencdn.net/4.3/video-js.css" rel="stylesheet">
<script src="//vjs.zencdn.net/4.3/video.js"></script>';
}
$this->update_post($this->article_id,$updated_article);
}
private function import_post($jsonbody){
$url = 'https://api.hubapi.com/content/api/v2/blog-posts?hapikey=' . hub_apiKey;
$body = json_encode($jsonbody);
return execute_post_request($url, $body,true);
}
private function update_post($article_id,$json_body){
$url = 'https://api.hubapi.com/content/api/v2/blog-posts/' . $article_id . '?hapikey=' . hub_apiKey;
$body = json_encode($json_body);
return execute_put_request($url, $body,true);
}
public function publish_post($article_id,$publish_date = false){
$url = "https://api.hubapi.com/content/api/v2/blog-posts/$article_id/publish-action?portalId=" . portal . "&hapikey=" . hub_apiKey;
//echo $url;
$json_body = array(
'action'=>'schedule-publish',
);
$body = json_encode($json_body);
$a = execute_post_request($url, $body,true);
$updated_article = array(
"publish_date"=> $this->date
);
$this->update_post($this->article_id,$updated_article);
}
}
?>