forked from wordpress-mobile/WordPress-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Post.java
453 lines (371 loc) · 11.8 KB
/
Post.java
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
package org.wordpress.android.models;
import java.util.List;
import java.util.Vector;
import org.json.JSONArray;
import org.json.JSONException;
import org.wordpress.android.WordPress;
public class Post {
private long id;
private int blogID;
private String categories;
private String custom_fields;
private long dateCreated;
private long date_created_gmt;
private String description;
private String link;
private boolean mt_allow_comments;
private boolean mt_allow_pings;
private String mt_excerpt;
private String mt_keywords;
private String mt_text_more;
private String permaLink;
private String post_status;
private String postid;
private String title;
private String userid;
private String wp_author_display_name;
private String wp_author_id;
private String wp_password;
private String wp_post_format;
private String wp_slug;
private boolean localDraft;
private boolean uploaded;
private double latitude;
private double longitude;
private boolean isPage;
private boolean isLocalChange;
private String mediaPaths;
private String quickPostType;
private Blog blog;
public List<String> imageUrl = new Vector<String>();
List<String> selectedCategories = new Vector<String>();
public Post(int blog_id, long post_id, boolean isPage) {
// load an existing post
List<Object> postVals = WordPress.wpDB.loadPost(blog_id, isPage, post_id);
if (postVals != null) {
try {
this.blog = new Blog(blog_id);
} catch (Exception e) {
}
this.id = (Long) postVals.get(0);
this.blogID = blog_id;
if (postVals.get(2) != null)
this.postid = postVals.get(2).toString();
this.title = postVals.get(3).toString();
this.dateCreated = (Long) postVals.get(4);
this.date_created_gmt = (Long) postVals.get(5);
this.categories = postVals.get(6).toString();
this.custom_fields = postVals.get(7).toString();
this.description = postVals.get(8).toString();
this.link = postVals.get(9).toString();
this.mt_allow_comments = (Integer) postVals.get(10) > 0;
this.mt_allow_pings = (Integer) postVals.get(11) > 0;
this.mt_excerpt = postVals.get(12).toString();
this.mt_keywords = postVals.get(13).toString();
if (postVals.get(14) != null)
this.mt_text_more = postVals.get(14).toString();
else
this.mt_text_more = "";
this.permaLink = postVals.get(15).toString();
this.post_status = postVals.get(16).toString();
this.userid = postVals.get(17).toString();
this.wp_author_display_name = postVals.get(18).toString();
this.wp_author_id = postVals.get(19).toString();
this.wp_password = postVals.get(20).toString();
this.wp_post_format = postVals.get(21).toString();
this.wp_slug = postVals.get(22).toString();
this.mediaPaths = postVals.get(23).toString();
this.latitude = (Double) postVals.get(24);
this.longitude = (Double) postVals.get(25);
this.localDraft = (Integer) postVals.get(26) > 0;
this.uploaded = (Integer) postVals.get(27) > 0;
this.isPage = (Integer) postVals.get(28) > 0;
this.isLocalChange = (Integer) postVals.get(29) > 0;
} else {
this.id = -1;
}
}
public Post(int blog_id, String title, String content, String picturePaths, long date, String categories, String tags, String status,
String password, double latitude, double longitude, boolean isPage, String postFormat,
boolean createBlogReference, boolean isLocalChange) {
// create a new post
if (createBlogReference) {
try {
this.blog = new Blog(blog_id);
} catch (Exception e) {
e.printStackTrace();
}
}
this.blogID = blog_id;
this.title = title;
this.description = content;
this.mediaPaths = picturePaths;
this.date_created_gmt = date;
this.categories = categories;
this.mt_keywords = tags;
this.post_status = status;
this.wp_password = password;
this.isPage = isPage;
this.wp_post_format = postFormat;
this.latitude = latitude;
this.longitude = longitude;
this.isLocalChange = isLocalChange;
}
public Post(int blog_id, String title, String content, String excerpt, String picturePaths, long date, String categories, String tags, String status,
String password, double latitude, double longitude, boolean isPage, String postFormat,
boolean createBlogReference, boolean isLocalChange) {
// create a new post
if (createBlogReference) {
try {
this.blog = new Blog(blog_id);
} catch (Exception e) {
e.printStackTrace();
}
}
this.blogID = blog_id;
this.title = title;
this.description = content;
this.mt_excerpt = excerpt;
this.mediaPaths = picturePaths;
this.date_created_gmt = date;
this.categories = categories;
this.mt_keywords = tags;
this.post_status = status;
this.wp_password = password;
this.isPage = isPage;
this.wp_post_format = postFormat;
this.latitude = latitude;
this.longitude = longitude;
this.isLocalChange = isLocalChange;
}
public long getId() {
return id;
}
public long getDateCreated() {
return dateCreated;
}
public void setDateCreated(long dateCreated) {
this.dateCreated = dateCreated;
}
public long getDate_created_gmt() {
return date_created_gmt;
}
public void setDate_created_gmt(long dateCreatedGmt) {
date_created_gmt = dateCreatedGmt;
}
public int getBlogID() {
return blogID;
}
public void setBlogID(int blogID) {
this.blogID = blogID;
}
public boolean isLocalDraft() {
return localDraft;
}
public void setLocalDraft(boolean localDraft) {
this.localDraft = localDraft;
}
public JSONArray getJSONCategories() {
JSONArray jArray = null;
if (categories == null)
categories = "";
try {
jArray = new JSONArray(categories);
} catch (JSONException e) {
}
return jArray;
}
public void setJSONCategories(JSONArray categories) {
this.categories = categories.toString();
}
public JSONArray getCustom_fields() {
JSONArray jArray = null;
try {
jArray = new JSONArray(custom_fields);
} catch (JSONException e) {
e.printStackTrace();
}
return jArray;
}
public void setCustom_fields(JSONArray customFields) {
custom_fields = customFields.toString();
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public boolean isMt_allow_comments() {
return mt_allow_comments;
}
public void setMt_allow_comments(boolean mtAllowComments) {
mt_allow_comments = mtAllowComments;
}
public boolean isMt_allow_pings() {
return mt_allow_pings;
}
public void setMt_allow_pings(boolean mtAllowPings) {
mt_allow_pings = mtAllowPings;
}
public String getMt_excerpt() {
return mt_excerpt;
}
public void setMt_excerpt(String mtExcerpt) {
mt_excerpt = mtExcerpt;
}
public String getMt_keywords() {
if (mt_keywords == null)
return "";
else
return mt_keywords;
}
public void setMt_keywords(String mtKeywords) {
mt_keywords = mtKeywords;
}
public String getMt_text_more() {
if (mt_text_more == null)
return "";
else
return mt_text_more;
}
public void setMt_text_more(String mtTextMore) {
mt_text_more = mtTextMore;
}
public String getPermaLink() {
return permaLink;
}
public void setPermaLink(String permaLink) {
this.permaLink = permaLink;
}
public String getPost_status() {
return post_status;
}
public void setPost_status(String postStatus) {
post_status = postStatus;
}
public String getPostid() {
return postid;
}
public void setPostid(String postid) {
this.postid = postid;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
public String getWP_author_display_name() {
return wp_author_display_name;
}
public void setWP_author_display_name(String wpAuthorDisplayName) {
wp_author_display_name = wpAuthorDisplayName;
}
public String getWP_author_id() {
return wp_author_id;
}
public void setWP_author_id(String wpAuthorId) {
wp_author_id = wpAuthorId;
}
public String getWP_password() {
return wp_password;
}
public void setWP_password(String wpPassword) {
wp_password = wpPassword;
}
public String getWP_post_format() {
return wp_post_format;
}
public void setWP_post_form(String wpPostForm) {
wp_post_format = wpPostForm;
}
public String getWP_slug() {
return wp_slug;
}
public void setWP_slug(String wpSlug) {
wp_slug = wpSlug;
}
public String getMediaPaths() {
return mediaPaths;
}
public void setMediaPaths(String mediaPaths) {
this.mediaPaths = mediaPaths;
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public boolean isPage() {
return isPage;
}
public void setPage(boolean isPage) {
this.isPage = isPage;
}
public boolean isUploaded() {
return uploaded;
}
public void setUploaded(boolean uploaded) {
this.uploaded = uploaded;
}
public boolean isLocalChange() {
return isLocalChange;
}
public void setLocalChange(boolean isLocalChange) {
this.isLocalChange = isLocalChange;
}
public boolean save() {
long newPostID = WordPress.wpDB.savePost(this, this.blogID);
if (newPostID >= 0 && this.isLocalDraft() && !this.isUploaded()) {
this.id = newPostID;
return true;
}
return false;
}
public boolean update() {
int success = WordPress.wpDB.updatePost(this, this.blogID);
return success > 0;
}
public void delete() {
// deletes a post/page draft
WordPress.wpDB.deletePost(this);
}
public void deleteMediaFiles() {
WordPress.wpDB.deleteMediaFilesForPost(this);
}
public void setId(long id) {
this.id = id;
}
public void setQuickPostType(String type) {
this.quickPostType = type;
}
public Blog getBlog() {
return blog;
}
public void setBlog(Blog blog) {
this.blog = blog;
}
public String getQuickPostType() {
return quickPostType;
}
}